mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/ccomm/transport/TestTransportLayerImpl.java
@Test
    public void testPostDataRecieved() 
        throws IllegalArgumentException, IllegalStateException, FactoryException, 
        IOException, ConfigurationException, AssetException
    {
        initTransportLayer(false);

        final String AddressType = Address.class.toString();       
        
        Address sourceAddress = mock(Address.class);
        Map<String, Object> addressEventProps = new HashMap<String, Object>();
        addressEventProps.put("source." + Address.EVENT_PROP_ADDRESS_SUFFIX, sourceAddress);
        addressEventProps.put("source." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX, AddressType);
        addressEventProps.put("source." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX, "test-source");
        when(sourceAddress.getEventProperties("source.")).thenReturn(addressEventProps);
        when(sourceAddress.getName()).thenReturn("test-source");
        
        Address destAddress = mock(Address.class);
        addressEventProps = new HashMap<String, Object>();
        addressEventProps.put("dest." + Address.EVENT_PROP_ADDRESS_SUFFIX, destAddress);
        addressEventProps.put("dest." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX, AddressType);
        addressEventProps.put("dest." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX, "test-dest");
        when(destAddress.getEventProperties("dest.")).thenReturn(addressEventProps);
        when(destAddress.getName()).thenReturn("test-dest");

        m_SUT.internalSetName("transport");
        m_SUT.beginReceiving();
        verify(m_WakeLock).activate();
        TransportPacket pkt = mock(TransportPacket.class);
        m_SUT.endReceiving(pkt, sourceAddress, destAddress);
        verify(m_WakeLock).cancel();
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        Event event = EventAdminVerifier.assertEventByTopicOnly(eventCaptor, TransportLayer.TOPIC_PACKET_RECEIVED);
        
        // verify all properties are set per standard
        assertThat((Address)event.getProperty("source." + Address.EVENT_PROP_ADDRESS_SUFFIX), is(sourceAddress));
        assertThat((String)event.getProperty("source." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX), is(AddressType));
        assertThat((String)event.getProperty("source." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX), is("test-source"));
        
        assertThat((Address)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_SUFFIX), is(destAddress));
        assertThat((String)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX), is(AddressType));
        assertThat((String)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX), is("test-dest"));
        
        assertThat((TransportLayerImpl)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ), is(m_SUT));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_TYPE), 
                is(m_SUT.getFactory().getProductType()));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_NAME), is("transport"));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_PID), is(m_SUT.getPid()));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_BASE_TYPE), 
                is(m_BaseType));
        assertThat((TransportPacket)event.getProperty(TransportLayer.EVENT_PROP_PACKET), is(pkt));
    }
/**
     * Verify that the end receive method will post an event with all the properties set.
     */
Verify that the end receive method will post an event with all the properties set.
Verify that the end receive method will post an event with all the properties set .
@Test
    public void testPostDataRecieved() 
        throws IllegalArgumentException, IllegalStateException, FactoryException, 
        IOException, ConfigurationException, AssetException
    {
        initTransportLayer(false);
        final String AddressType = Address.class.toString();       
        Address sourceAddress = mock(Address.class);
        Map<String, Object> addressEventProps = new HashMap<String, Object>();
        addressEventProps.put("source." + Address.EVENT_PROP_ADDRESS_SUFFIX, sourceAddress);
        addressEventProps.put("source." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX, AddressType);
        addressEventProps.put("source." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX, "test-source");
        when(sourceAddress.getEventProperties("source.")).thenReturn(addressEventProps);
        when(sourceAddress.getName()).thenReturn("test-source");
        Address destAddress = mock(Address.class);
        addressEventProps = new HashMap<String, Object>();
        addressEventProps.put("dest." + Address.EVENT_PROP_ADDRESS_SUFFIX, destAddress);
        addressEventProps.put("dest." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX, AddressType);
        addressEventProps.put("dest." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX, "test-dest");
        when(destAddress.getEventProperties("dest.")).thenReturn(addressEventProps);
        when(destAddress.getName()).thenReturn("test-dest");
        m_SUT.internalSetName("transport");
        m_SUT.beginReceiving();
        verify(m_WakeLock).activate();
        TransportPacket pkt = mock(TransportPacket.class);
        m_SUT.endReceiving(pkt, sourceAddress, destAddress);
        verify(m_WakeLock).cancel();
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        Event event = EventAdminVerifier.assertEventByTopicOnly(eventCaptor, TransportLayer.TOPIC_PACKET_RECEIVED);
        assertThat((Address)event.getProperty("source." + Address.EVENT_PROP_ADDRESS_SUFFIX), is(sourceAddress));
        assertThat((String)event.getProperty("source." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX), is(AddressType));
        assertThat((String)event.getProperty("source." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX), is("test-source"));
        assertThat((Address)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_SUFFIX), is(destAddress));
        assertThat((String)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX), is(AddressType));
        assertThat((String)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX), is("test-dest"));
        assertThat((TransportLayerImpl)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ), is(m_SUT));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_TYPE), 
                is(m_SUT.getFactory().getProductType()));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_NAME), is("transport"));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_PID), is(m_SUT.getPid()));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_BASE_TYPE), 
                is(m_BaseType));
        assertThat((TransportPacket)event.getProperty(TransportLayer.EVENT_PROP_PACKET), is(pkt));
    }
@ Test public void testPostDataRecieved ( ) throws IllegalArgumentException , IllegalStateException , FactoryException , IOException , ConfigurationException , AssetException { initTransportLayer ( false ) ; final String AddressType = Address . class . toString ( ) ; Address sourceAddress = mock ( Address . class ) ; Map < String , Object > addressEventProps = new HashMap < String , Object > ( ) ; addressEventProps . put ( "source." + Address . EVENT_PROP_ADDRESS_SUFFIX , sourceAddress ) ; addressEventProps . put ( "source." + Address . EVENT_PROP_ADDRESS_TYPE_SUFFIX , AddressType ) ; addressEventProps . put ( "source." + Address . EVENT_PROP_ADDRESS_NAME_SUFFIX , "test-source" ) ; when ( sourceAddress . getEventProperties ( "source." ) ) . thenReturn ( addressEventProps ) ; when ( sourceAddress . getName ( ) ) . thenReturn ( "test-source" ) ; Address destAddress = mock ( Address . class ) ; addressEventProps = new HashMap < String , Object > ( ) ; addressEventProps . put ( "dest." + Address . EVENT_PROP_ADDRESS_SUFFIX , destAddress ) ; addressEventProps . put ( "dest." + Address . EVENT_PROP_ADDRESS_TYPE_SUFFIX , AddressType ) ; addressEventProps . put ( "dest." + Address . EVENT_PROP_ADDRESS_NAME_SUFFIX , "test-dest" ) ; when ( destAddress . getEventProperties ( "dest." ) ) . thenReturn ( addressEventProps ) ; when ( destAddress . getName ( ) ) . thenReturn ( "test-dest" ) ; m_SUT . internalSetName ( "transport" ) ; m_SUT . beginReceiving ( ) ; verify ( m_WakeLock ) . activate ( ) ; TransportPacket pkt = mock ( TransportPacket . class ) ; m_SUT . endReceiving ( pkt , sourceAddress , destAddress ) ; verify ( m_WakeLock ) . cancel ( ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 1 ) ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = EventAdminVerifier . assertEventByTopicOnly ( eventCaptor , TransportLayer . TOPIC_PACKET_RECEIVED ) ; assertThat ( ( Address ) event . getProperty ( "source." + Address . EVENT_PROP_ADDRESS_SUFFIX ) , is ( sourceAddress ) ) ; assertThat ( ( String ) event . getProperty ( "source." + Address . EVENT_PROP_ADDRESS_TYPE_SUFFIX ) , is ( AddressType ) ) ; assertThat ( ( String ) event . getProperty ( "source." + Address . EVENT_PROP_ADDRESS_NAME_SUFFIX ) , is ( "test-source" ) ) ; assertThat ( ( Address ) event . getProperty ( "dest." + Address . EVENT_PROP_ADDRESS_SUFFIX ) , is ( destAddress ) ) ; assertThat ( ( String ) event . getProperty ( "dest." + Address . EVENT_PROP_ADDRESS_TYPE_SUFFIX ) , is ( AddressType ) ) ; assertThat ( ( String ) event . getProperty ( "dest." + Address . EVENT_PROP_ADDRESS_NAME_SUFFIX ) , is ( "test-dest" ) ) ; assertThat ( ( TransportLayerImpl ) event . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ ) , is ( m_SUT ) ) ; assertThat ( ( String ) event . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ_TYPE ) , is ( m_SUT . getFactory ( ) . getProductType ( ) ) ) ; assertThat ( ( String ) event . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ_NAME ) , is ( "transport" ) ) ; assertThat ( ( String ) event . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ_PID ) , is ( m_SUT . getPid ( ) ) ) ; assertThat ( ( String ) event . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ_BASE_TYPE ) , is ( m_BaseType ) ) ; assertThat ( ( TransportPacket ) event . getProperty ( TransportLayer . EVENT_PROP_PACKET ) , is ( pkt ) ) ; }
Verify that the end receive method will post an event with all the properties set.
Verify that the end receive method will post an event with all the properties set .
// verify all properties are set per standard