mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestEventAdminMessageService.java
@Test
    public void testUnregister() throws Exception
    {
        // mock
        ServiceRegistration reg = mock(ServiceRegistration.class);

        when(m_Context.registerService(eq(EventHandler.class), Mockito.any(EventHandler.class), 
                Mockito.any(Dictionary.class))).thenReturn(reg);

        // Register Event
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic");
        // add required fields
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        EventAdminNamespace eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage.build().toByteString())
                .build();
        TerraHarvestMessage message = createEventAdminMessage(eventAdminMessage);
        TerraHarvestPayload payload = createPayload(eventAdminMessage);

        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        // create unregister event request - unique id of registered event (above) should be 1
        UnregisterEventRequestData unregisterRequestMessage = UnregisterEventRequestData.newBuilder()
                .setId(1).build();
        eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.UnregisterEventRequest)
                .setData(unregisterRequestMessage.toByteString())
                .build();
        payload = createPayload(eventAdminMessage);
        message = createEventAdminMessage(eventAdminMessage);
        m_SUT.handleMessage(message, payload, channel);
        // verify that the registered service has been unregistered
        verify(reg).unregister();
        verify(m_DataStore).removeMatching(EventAdminMessageService.class, "1");
        
        // verify the event contains the data message
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((UnregisterEventRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(unregisterRequestMessage));
        
        verify(m_MessageFactory).createEventAdminResponseMessage(message, 
                EventAdminMessageType.UnregisterEventResponse, null);
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
/**
     * Test if remote event is being properly unregistered via sending/receiving unregister event
     * requests and responses.  
     */
Test if remote event is being properly unregistered via sending/receiving unregister event
requests and responses.
Test if remote event is being properly unregistered via sending / receiving unregister event requests and responses .
@Test
    public void testUnregister() throws Exception
    {
        ServiceRegistration reg = mock(ServiceRegistration.class);
        when(m_Context.registerService(eq(EventHandler.class), Mockito.any(EventHandler.class), 
                Mockito.any(Dictionary.class))).thenReturn(reg);
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic");
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        EventAdminNamespace eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage.build().toByteString())
                .build();
        TerraHarvestMessage message = createEventAdminMessage(eventAdminMessage);
        TerraHarvestPayload payload = createPayload(eventAdminMessage);
         the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        UnregisterEventRequestData unregisterRequestMessage = UnregisterEventRequestData.newBuilder()
                .setId(1).build();
        eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.UnregisterEventRequest)
                .setData(unregisterRequestMessage.toByteString())
                .build();
        payload = createPayload(eventAdminMessage);
        message = createEventAdminMessage(eventAdminMessage);
        m_SUT.handleMessage(message, payload, channel);
        verify(reg).unregister();
        verify(m_DataStore).removeMatching(EventAdminMessageService.class, "1");
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((UnregisterEventRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(unregisterRequestMessage));
        verify(m_MessageFactory).createEventAdminResponseMessage(message, 
                EventAdminMessageType.UnregisterEventResponse, null);
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
@ Test public void testUnregister ( ) throws Exception { ServiceRegistration reg = mock ( ServiceRegistration . class ) ; when ( m_Context . registerService ( eq ( EventHandler . class ) , Mockito . any ( EventHandler . class ) , Mockito . any ( Dictionary . class ) ) ) . thenReturn ( reg ) ; EventRegistrationRequestData . Builder requestMessage = EventRegistrationRequestData . newBuilder ( ) . addTopic ( "test-topic" ) ; requestMessage = RemoteUtils . appendRequiredFields ( requestMessage , false ) ; EventAdminNamespace eventAdminMessage = EventAdminNamespace . newBuilder ( ) . setType ( EventAdminMessageType . EventRegistrationRequest ) . setData ( requestMessage . build ( ) . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message = createEventAdminMessage ( eventAdminMessage ) ; TerraHarvestPayload payload = createPayload ( eventAdminMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; UnregisterEventRequestData unregisterRequestMessage = UnregisterEventRequestData . newBuilder ( ) . setId ( 1 ) . build ( ) ; eventAdminMessage = EventAdminNamespace . newBuilder ( ) . setType ( EventAdminMessageType . UnregisterEventRequest ) . setData ( unregisterRequestMessage . toByteString ( ) ) . build ( ) ; payload = createPayload ( eventAdminMessage ) ; message = createEventAdminMessage ( eventAdminMessage ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( reg ) . unregister ( ) ; verify ( m_DataStore ) . removeMatching ( EventAdminMessageService . class , "1" ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( UnregisterEventRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( unregisterRequestMessage ) ) ; verify ( m_MessageFactory ) . createEventAdminResponseMessage ( message , EventAdminMessageType . UnregisterEventResponse , null ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; }
Test if remote event is being properly unregistered via sending/receiving unregister event
 requests and responses.
Test if remote event is being properly unregistered via sending / receiving unregister event requests and responses .
// mock // Register Event // add required fields // mock the channel the message came from // replay // create unregister event request - unique id of registered event (above) should be 1 // verify that the registered service has been unregistered // verify the event contains the data message