mil.dod.th.ose.core.integration/src/mil/dod/th/ose/core/integration/TestTransportLayer.java
public final void testReceiveEventConnectionOriented() 
        throws CCommException, InterruptedException, IllegalArgumentException, FactoryException,
        PersistenceFailedException, IOException
    {
        CustomCommsService customCommsService = ServiceUtils.getService(m_Context, CustomCommsService.class);
        AddressManagerService addressMgrSvc = ServiceUtils.getService(m_Context, AddressManagerService.class);
        
        PhysicalLink pLink = customCommsService.createPhysicalLink(PhysicalLinkTypeEnum.I_2_C);
        LinkLayer linkLayer = customCommsService.createLinkLayer(ExampleLinkLayer.class.getName(), pLink.getName());
        TransportLayer transport = customCommsService.createTransportLayer(ConnectionOrientedTransport.class.getName(), 
                "test-connection-transport", linkLayer.getName());
                
        Address address = addressMgrSvc.getOrCreateAddress("Example:3000");
        
        // handler called when the event is posted
        EventHandler handler = new EventHandler()
        {
            @Override
            public void handleEvent(Event event)
            {
                // just keep track of event for later inspection
                m_LastEvent = event;
            }
        };
        
        // setup to wait for the package received event
        EventHandlerSyncer syncer = new EventHandlerSyncer(m_Context, TransportLayer.TOPIC_PACKET_RECEIVED,
                String.format("(%s=%s)", FactoryDescriptor.EVENT_PROP_OBJ_NAME, "test-connection-transport"),
                handler);
        
        transport.connect(address);
        assertTrue(transport.isAvailable(address));
        
        // send a message, example code will call the protected post event method
        transport.send(ByteBuffer.wrap("test message".getBytes()));
        
        // no wait for event
        syncer.waitForEvent(2);
        
        // verify event props are correct
        assertThat(((TransportPacket)m_LastEvent.getProperty(TransportLayer.EVENT_PROP_PACKET)).getPayload().array(),
                is("test message".getBytes()));
        // source should not be filled out
        assertThat((Address)m_LastEvent.getProperty(Address.EVENT_PROP_SOURCE_ADDRESS_PREFIX
                + Address.EVENT_PROP_ADDRESS_SUFFIX), is(nullValue()));
        assertThat((Address)m_LastEvent.getProperty(Address.EVENT_PROP_DEST_ADDRESS_PREFIX 
                + Address.EVENT_PROP_ADDRESS_SUFFIX), is(nullValue()));

        transport.disconnect();
        assertFalse(transport.isAvailable(address));
    }
/**
     * Verify a connection oriented transport can use the built in post event method to post an event 
     * for a received packet.
     */
Verify a connection oriented transport can use the built in post event method to post an event
for a received packet.
Verify a connection oriented transport can use the built in post event method to post an event for a received packet .
public final void testReceiveEventConnectionOriented() 
        throws CCommException, InterruptedException, IllegalArgumentException, FactoryException,
        PersistenceFailedException, IOException
    {
        CustomCommsService customCommsService = ServiceUtils.getService(m_Context, CustomCommsService.class);
        AddressManagerService addressMgrSvc = ServiceUtils.getService(m_Context, AddressManagerService.class);
        PhysicalLink pLink = customCommsService.createPhysicalLink(PhysicalLinkTypeEnum.I_2_C);
        LinkLayer linkLayer = customCommsService.createLinkLayer(ExampleLinkLayer.class.getName(), pLink.getName());
        TransportLayer transport = customCommsService.createTransportLayer(ConnectionOrientedTransport.class.getName(), 
                "test-connection-transport", linkLayer.getName());
        Address address = addressMgrSvc.getOrCreateAddress("Example:3000");
        EventHandler handler = new EventHandler()
        {
            @Override
            public void handleEvent(Event event)
            {
                m_LastEvent = event;
            }
        };
        EventHandlerSyncer syncer = new EventHandlerSyncer(m_Context, TransportLayer.TOPIC_PACKET_RECEIVED,
                String.format("(%s=%s)", FactoryDescriptor.EVENT_PROP_OBJ_NAME, "test-connection-transport"),
                handler);
        transport.connect(address);
        assertTrue(transport.isAvailable(address));
        transport.send(ByteBuffer.wrap("test message".getBytes()));
        syncer.waitForEvent(2);
        assertThat(((TransportPacket)m_LastEvent.getProperty(TransportLayer.EVENT_PROP_PACKET)).getPayload().array(),
                is("test message".getBytes()));
        assertThat((Address)m_LastEvent.getProperty(Address.EVENT_PROP_SOURCE_ADDRESS_PREFIX
                + Address.EVENT_PROP_ADDRESS_SUFFIX), is(nullValue()));
        assertThat((Address)m_LastEvent.getProperty(Address.EVENT_PROP_DEST_ADDRESS_PREFIX 
                + Address.EVENT_PROP_ADDRESS_SUFFIX), is(nullValue()));
        transport.disconnect();
        assertFalse(transport.isAvailable(address));
    }
public final void testReceiveEventConnectionOriented ( ) throws CCommException , InterruptedException , IllegalArgumentException , FactoryException , PersistenceFailedException , IOException { CustomCommsService customCommsService = ServiceUtils . getService ( m_Context , CustomCommsService . class ) ; AddressManagerService addressMgrSvc = ServiceUtils . getService ( m_Context , AddressManagerService . class ) ; PhysicalLink pLink = customCommsService . createPhysicalLink ( PhysicalLinkTypeEnum . I_2_C ) ; LinkLayer linkLayer = customCommsService . createLinkLayer ( ExampleLinkLayer . class . getName ( ) , pLink . getName ( ) ) ; TransportLayer transport = customCommsService . createTransportLayer ( ConnectionOrientedTransport . class . getName ( ) , "test-connection-transport" , linkLayer . getName ( ) ) ; Address address = addressMgrSvc . getOrCreateAddress ( "Example:3000" ) ; EventHandler handler = new EventHandler ( ) { @ Override public void handleEvent ( Event event ) { m_LastEvent = event ; } } ; EventHandlerSyncer syncer = new EventHandlerSyncer ( m_Context , TransportLayer . TOPIC_PACKET_RECEIVED , String . format ( "(%s=%s)" , FactoryDescriptor . EVENT_PROP_OBJ_NAME , "test-connection-transport" ) , handler ) ; transport . connect ( address ) ; assertTrue ( transport . isAvailable ( address ) ) ; transport . send ( ByteBuffer . wrap ( "test message" . getBytes ( ) ) ) ; syncer . waitForEvent ( 2 ) ; assertThat ( ( ( TransportPacket ) m_LastEvent . getProperty ( TransportLayer . EVENT_PROP_PACKET ) ) . getPayload ( ) . array ( ) , is ( "test message" . getBytes ( ) ) ) ; assertThat ( ( Address ) m_LastEvent . getProperty ( Address . EVENT_PROP_SOURCE_ADDRESS_PREFIX + Address . EVENT_PROP_ADDRESS_SUFFIX ) , is ( nullValue ( ) ) ) ; assertThat ( ( Address ) m_LastEvent . getProperty ( Address . EVENT_PROP_DEST_ADDRESS_PREFIX + Address . EVENT_PROP_ADDRESS_SUFFIX ) , is ( nullValue ( ) ) ) ; transport . disconnect ( ) ; assertFalse ( transport . isAvailable ( address ) ) ; }
Verify a connection oriented transport can use the built in post event method to post an event
 for a received packet.
Verify a connection oriented transport can use the built in post event method to post an event for a received packet .
// handler called when the event is posted // just keep track of event for later inspection // setup to wait for the package received event // send a message, example code will call the protected post event method // no wait for event // verify event props are correct // source should not be filled out