Java Code Examples for junit.framework.Assert

The following are top voted examples for showing how to use junit.framework.Assert. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: jentrata-msh   File: OutgoingMessageProcessorTest.java View source code 6 votes vote down vote up
@Test
	public void testPlainMessageMIC() throws Exception{
	//Prepare Data
	InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
	ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));

	partnershipDVO.setIsReceiptSignRequired(true);
	partnershipDVO.setIsReceiptRequired(true);
	
	String mid = RANDOM.toString();
	AS2Message as2Msg = TARGET.storeOutgoingMessage(
			mid, //MessageID
			"xml", 
			partnershipDVO,
			new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG),
			null);
	
	//Verify MIC value
	ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
	bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
	byte[] content = new byte[bIns.available()];
	bIns.read(content);
	bIns.close();
	String mic = calculateMIC(content);
	
	MessageDVO msgDVO = getStoredMessage(mid);
	Assert.assertEquals( "MIC value is not valid", mic, msgDVO.getMicValue());
}
 
Example 2
Project: jentrata-msh   File: OutgoingMessageProcessorTest.java View source code 6 votes vote down vote up
@Test
public void testSignedAS2Message() throws Exception{
	InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
	ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));

	partnershipDVO.setIsOutboundSignRequired(true);
	String mid = RANDOM.toString();
	
	AS2Message as2Msg = TARGET.storeOutgoingMessage(
			mid, //MessageID
			"xml", 
			partnershipDVO,
			new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
	
	//Verify As2Signing Message
	try{
		SMIMESigned signed = new SMIMESigned((MimeMultipart)as2Msg.getBodyPart().getContent());
		SignerInformationStore  signers = signed.getSignerInfos();
		Iterator signerInfos = signers.getSigners().iterator();
		while (signerInfos.hasNext()) {
			SignerInformation   signerInfo = (SignerInformation)signerInfos.next();
			if (!signerInfo.verify(partnershipDVO.getEffectiveVerifyCertificate(), "BC")) {
				Assert.fail("Signature Verfifcation Failed");
			}
		}
		
		//Assert the filename value
		MimeBodyPart signedPart = signed.getContent();
        String filenameHdr = signedPart.getHeader("Content-Disposition")[0];
        Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
        
        
        // Verify MIC Value
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        signedPart.writeTo(baos);
           byte[] content = (baos.toByteArray());
           String mic = calculateMIC(content);
           
           MessageDVO msgDVO = getStoredMessage(mid);
           Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
        
	}catch(Exception exp){
		Assert.fail("Signature Verfifcation Failed");
	}
       Assert.assertTrue(true);
	}
 
Example 3
Project: jentrata-msh   File: IncomingMessageProcessorTest.java View source code 6 votes vote down vote up
@Test
public void testDecryption() throws Exception{
	try{
	// Caculate MIC value
	String expectedMIC = calculateMIC(as2Message.getBodyPart());
	
	//Sign message
	as2Message.setBodyPart(encrypt(as2Message.getBodyPart()));
	
	//Update the Partnership Record in Database
	partnershipDVO.setIsInboundEncryptRequired(true);
	PartnershipDAO partnershioDAO = (PartnershipDAO) TARGET.getDAOFactory().createDAO(PartnershipDAO.class);
	partnershioDAO.persist(partnershipDVO);
	
	// Insert Message Record to Database
	AS2DAOHandler daoHandler = new AS2DAOHandler(TARGET.getDAOFactory());
       RepositoryDVO requestRepositoryDVO = daoHandler.createRepositoryDVO(as2Message, true);
       MessageDVO requestMessageDVO = daoHandler.createMessageDVO(as2Message, true);
       requestMessageDVO.setStatus(MessageDVO.STATUS_RECEIVED);
       daoHandler.createMessageStore().storeMessage(requestMessageDVO, requestRepositoryDVO);
       
	// Invoke Target Method
	Method m = TARGET.getClass().getDeclaredMethod("processReceivedMessage", AS2Message.class);
	m.setAccessible(true);
	AS2Message responseMsg = (AS2Message)m.invoke(TARGET, as2Message);
	
	// check if the response message has been generated
	Assert.assertNotNull(responseMsg);
	
	//Assert the content of the reply
	DispositionNotification dn = responseMsg.getDispositionNotification();
	Assert.assertEquals(msgId, dn.getOriginalMessageID());		
	Assert.assertNull(dn.getDisposition().getDescription());
	Assert.assertNull(dn.getDisposition().getModifier());
	Assert.assertEquals(expectedMIC, dn.getReceivedContentMIC());
	}catch(Exception exp){
		exp.printStackTrace();
		Assert.fail();
	}
	
}
 
Example 4
Project: media-fragments-uri   File: TemporalFunctionTest.java View source code 6 votes vote down vote up
@Test
public void testBefore() throws NotComparableException {

    Instant is1 = new Instant(10);
    Instant is2 = new Instant(30);
    Interval iv1 = new Interval(0D,20D);
    Interval iv2 = new Interval(40D,50D);

    Assert.assertTrue(TemporalFunction.precedes(is1, is2));
    Assert.assertTrue(TemporalFunction.precedes(is1, iv2));
    Assert.assertTrue(TemporalFunction.precedes(iv1, iv2));
    Assert.assertTrue(TemporalFunction.precedes(is2, iv2));

    Assert.assertFalse(TemporalFunction.precedes(is2, is1));
    Assert.assertFalse(TemporalFunction.precedes(is2, iv1));
    Assert.assertFalse(TemporalFunction.precedes(iv2, iv1));
    Assert.assertFalse(TemporalFunction.precedes(iv2, is1));
}
 
Example 5
Project: Dempsy   File: TestRouterInstantiation.java View source code 6 votes vote down vote up
@Test
public void testGetMessages() throws Throwable
{
   ApplicationDefinition app = new ApplicationDefinition("test");
   Router router = new Router(app);

   List<Object> messages = new ArrayList<Object>();
   Object first = new Object();
   router.getMessages(first, messages);
   Assert.assertEquals(1, messages.size());
   Assert.assertSame(first, messages.get(0));
}
 
Example 6
Project: JAME   File: AbstractConfigurableExtensionConfigElementTest.java View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void testSerialization() {
	configElement.setReference(getSecondReference());
	try {
		final ByteArrayOutputStream os = new ByteArrayOutputStream();
		final ObjectOutputStream oos = new ObjectOutputStream(os);
		oos.writeObject(configElement);
		oos.close();
		final ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
		final ObjectInputStream ois = new ObjectInputStream(is);
		final ConfigurableExtensionReferenceElement<V> deserializedConfigElement = (ConfigurableExtensionReferenceElement<V>) ois.readObject();
		ois.close();
		Assert.assertNotSame(deserializedConfigElement, configElement);
		Assert.assertEquals(deserializedConfigElement, configElement);
	}
	catch (final Exception e) {
		Assert.fail(e.getMessage());
	}
}
 
Example 7
Project: jxta   File: NettyTestUtils.java View source code 6 votes vote down vote up
public static void assertEquals(ChannelBuffer expected, ChannelBuffer actual) {
    if(expected.readableBytes() != actual.readableBytes()) {
        Assert.failNotEquals("channel buffers have differing readable sizes", expected.readableBytes(), actual.readableBytes());
    }
    
    int startPositionExpected = expected.readerIndex();
    int startPositionActual = actual.readerIndex();
    int position = 0;
    while(expected.readable()) {
        byte expectedByte = expected.readByte();
        byte actualByte = actual.readByte(); 
        if(expectedByte != actualByte) {
            Assert.failNotEquals("channel buffers differ at position " + position, expectedByte, actualByte);
        }
        
        position++;
    }
    
    expected.readerIndex(startPositionExpected);
    actual.readerIndex(startPositionActual);
}