mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestEventAdminMessageService.java
@Test
    public void testSendEvent() throws Exception
    {
        //Send event message
        SendEventData requestMessage = SendEventData.newBuilder()
                .setTopic("new-topic").build();

        EventAdminNamespace eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.SendEvent)
                .setData(requestMessage.toByteString())
                .build();
        TerraHarvestMessage message = createEventAdminMessage(eventAdminMessage);
        TerraHarvestPayload payload = createPayload(eventAdminMessage);

        //mock converted props
        Map<String, Object> props = new HashMap<String, Object>();
        props.put("prop1", "test");
        props.put("prop2", true);
        when(m_ConversionService.complexTypesMapToMap(Mockito.anyList())).thenReturn(props);

        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // replay
        m_SUT.handleMessage(message, payload, channel);

        // verify
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());//once in send event and again in handle message

        /* The sendEvent message is posted locally before the handle message method posts 
         * the general event info locally. Therefore, the first values captured contain the 
         * sendEvent message contents and are used to verify correct outputs.     
         */
        assertThat(eventCaptor.getAllValues().get(0).getTopic(), 
            is(RemoteInterfaceUtilities.getRemoteEventTopic("new-topic")));
        assertThat((String)eventCaptor.getAllValues().get(0).getProperty("prop1"), is("test"));
        assertThat((Boolean)eventCaptor.getAllValues().get(0).getProperty("prop2"), is(true));
        assertThat((Integer)eventCaptor.getAllValues().get(0).getProperty("controller.id"), is(200));
        
        // now verify the second event, the handle message event contains the data message
        Event event = eventCaptor.getValue();
        assertThat((SendEventData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(requestMessage));
    }
/**
     * Test if registered remote events are properly posted locally when a sendEvent
     * message is received.
     */
Test if registered remote events are properly posted locally when a sendEvent
message is received.
Test if registered remote events are properly posted locally when a sendEvent message is received .
@Test
    public void testSendEvent() throws Exception
    {
        SendEventData requestMessage = SendEventData.newBuilder()
                .setTopic("new-topic").build();
        EventAdminNamespace eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.SendEvent)
                .setData(requestMessage.toByteString())
                .build();
        TerraHarvestMessage message = createEventAdminMessage(eventAdminMessage);
        TerraHarvestPayload payload = createPayload(eventAdminMessage);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put("prop1", "test");
        props.put("prop2", true);
        when(m_ConversionService.complexTypesMapToMap(Mockito.anyList())).thenReturn(props);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        /* The sendEvent message is posted locally before the handle message method posts 
         * the general event info locally. Therefore, the first values captured contain the 
         * sendEvent message contents and are used to verify correct outputs.     
         */
        assertThat(eventCaptor.getAllValues().get(0).getTopic(), 
            is(RemoteInterfaceUtilities.getRemoteEventTopic("new-topic")));
        assertThat((String)eventCaptor.getAllValues().get(0).getProperty("prop1"), is("test"));
        assertThat((Boolean)eventCaptor.getAllValues().get(0).getProperty("prop2"), is(true));
        assertThat((Integer)eventCaptor.getAllValues().get(0).getProperty("controller.id"), is(200));
        Event event = eventCaptor.getValue();
        assertThat((SendEventData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(requestMessage));
    }
@ Test public void testSendEvent ( ) throws Exception { SendEventData requestMessage = SendEventData . newBuilder ( ) . setTopic ( "new-topic" ) . build ( ) ; EventAdminNamespace eventAdminMessage = EventAdminNamespace . newBuilder ( ) . setType ( EventAdminMessageType . SendEvent ) . setData ( requestMessage . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message = createEventAdminMessage ( eventAdminMessage ) ; TerraHarvestPayload payload = createPayload ( eventAdminMessage ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( "prop1" , "test" ) ; props . put ( "prop2" , true ) ; when ( m_ConversionService . complexTypesMapToMap ( Mockito . anyList ( ) ) ) . thenReturn ( props ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; /* The sendEvent message is posted locally before the handle message method posts 
         * the general event info locally. Therefore, the first values captured contain the 
         * sendEvent message contents and are used to verify correct outputs.     
         */ assertThat ( eventCaptor . getAllValues ( ) . get ( 0 ) . getTopic ( ) , is ( RemoteInterfaceUtilities . getRemoteEventTopic ( "new-topic" ) ) ) ; assertThat ( ( String ) eventCaptor . getAllValues ( ) . get ( 0 ) . getProperty ( "prop1" ) , is ( "test" ) ) ; assertThat ( ( Boolean ) eventCaptor . getAllValues ( ) . get ( 0 ) . getProperty ( "prop2" ) , is ( true ) ) ; assertThat ( ( Integer ) eventCaptor . getAllValues ( ) . get ( 0 ) . getProperty ( "controller.id" ) , is ( 200 ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( SendEventData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( requestMessage ) ) ; }
Test if registered remote events are properly posted locally when a sendEvent
 message is received.
Test if registered remote events are properly posted locally when a sendEvent message is received .
//Send event message //mock converted props // mock the channel the message came from // replay // verify //once in send event and again in handle message // now verify the second event, the handle message event contains the data message