mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/ccomm/link/TestLinkLayerImpl.java
@Test
    public void testSend() throws CCommException, IOException, IllegalArgumentException, IllegalStateException,
        FactoryException, ConfigurationException, AssetException
    {
        //mocks
        Address destAddress = mock(Address.class);
        LinkFrame frame = mock(LinkFrame.class);
        
        final String addressType = Address.class.toString();
        
        Map<String, Object> 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");
        
        //need to activate so that isActivated returns true
        m_SUT.activateLayer();
        m_SUT.send(frame, destAddress);
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        //one for activate, last is send
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        
        Event event = EventAdminVerifier.assertEventByTopicOnly(eventCaptor, LinkLayer.TOPIC_DATA_SENT);
        assertThat((LinkLayer)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ), is((LinkLayer)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(m_Name));
        assertThat((LinkStatus)event.getProperty(LinkLayer.EVENT_PROP_LINK_STATUS), is(LinkStatus.LOST));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_PID), is(m_Pid));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_BASE_TYPE), 
                is(m_BaseType));
        assertThat((LinkFrame)event.getProperty(LinkLayer.EVENT_PROP_LINK_FRAME), is(frame));

        assertThat((Address)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_SUFFIX), is(destAddress));
        assertThat((String)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX), 
                is(destAddress.getName()));
        assertThat((String)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX), is(addressType));
        
        verify(m_WakeLock, times(2)).activate();
        verify(m_LinkLayerProxy, times(1)).send(frame, destAddress);
        verify(m_WakeLock, times(2)).cancel();
    }
/**
     * Verify send called on layer proxy.
     * Verify event has correct props.
     */
Verify send called on layer proxy.
Verify event has correct props.
Verify send called on layer proxy . Verify event has correct props .
@Test
    public void testSend() throws CCommException, IOException, IllegalArgumentException, IllegalStateException,
        FactoryException, ConfigurationException, AssetException
    {
        Address destAddress = mock(Address.class);
        LinkFrame frame = mock(LinkFrame.class);
        final String addressType = Address.class.toString();
        Map<String, Object> 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.activateLayer();
        m_SUT.send(frame, destAddress);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        Event event = EventAdminVerifier.assertEventByTopicOnly(eventCaptor, LinkLayer.TOPIC_DATA_SENT);
        assertThat((LinkLayer)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ), is((LinkLayer)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(m_Name));
        assertThat((LinkStatus)event.getProperty(LinkLayer.EVENT_PROP_LINK_STATUS), is(LinkStatus.LOST));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_PID), is(m_Pid));
        assertThat((String)event.getProperty(FactoryDescriptor.EVENT_PROP_OBJ_BASE_TYPE), 
                is(m_BaseType));
        assertThat((LinkFrame)event.getProperty(LinkLayer.EVENT_PROP_LINK_FRAME), is(frame));
        assertThat((Address)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_SUFFIX), is(destAddress));
        assertThat((String)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_NAME_SUFFIX), 
                is(destAddress.getName()));
        assertThat((String)event.getProperty("dest." + Address.EVENT_PROP_ADDRESS_TYPE_SUFFIX), is(addressType));
        verify(m_WakeLock, times(2)).activate();
        verify(m_LinkLayerProxy, times(1)).send(frame, destAddress);
        verify(m_WakeLock, times(2)).cancel();
    }
@ Test public void testSend ( ) throws CCommException , IOException , IllegalArgumentException , IllegalStateException , FactoryException , ConfigurationException , AssetException { Address destAddress = mock ( Address . class ) ; LinkFrame frame = mock ( LinkFrame . class ) ; final String addressType = Address . class . toString ( ) ; Map < String , Object > 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 . activateLayer ( ) ; m_SUT . send ( frame , destAddress ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = EventAdminVerifier . assertEventByTopicOnly ( eventCaptor , LinkLayer . TOPIC_DATA_SENT ) ; assertThat ( ( LinkLayer ) event . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ ) , is ( ( LinkLayer ) 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 ( m_Name ) ) ; assertThat ( ( LinkStatus ) event . getProperty ( LinkLayer . EVENT_PROP_LINK_STATUS ) , is ( LinkStatus . LOST ) ) ; assertThat ( ( String ) event . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ_PID ) , is ( m_Pid ) ) ; assertThat ( ( String ) event . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ_BASE_TYPE ) , is ( m_BaseType ) ) ; assertThat ( ( LinkFrame ) event . getProperty ( LinkLayer . EVENT_PROP_LINK_FRAME ) , is ( frame ) ) ; assertThat ( ( Address ) event . getProperty ( "dest." + Address . EVENT_PROP_ADDRESS_SUFFIX ) , is ( destAddress ) ) ; assertThat ( ( String ) event . getProperty ( "dest." + Address . EVENT_PROP_ADDRESS_NAME_SUFFIX ) , is ( destAddress . getName ( ) ) ) ; assertThat ( ( String ) event . getProperty ( "dest." + Address . EVENT_PROP_ADDRESS_TYPE_SUFFIX ) , is ( addressType ) ) ; verify ( m_WakeLock , times ( 2 ) ) . activate ( ) ; verify ( m_LinkLayerProxy , times ( 1 ) ) . send ( frame , destAddress ) ; verify ( m_WakeLock , times ( 2 ) ) . cancel ( ) ; }
Verify send called on layer proxy.
Verify send called on layer proxy .
//mocks //need to activate so that isActivated returns true //one for activate, last is send