mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestEventAdminMessageService.java
@Test
    public final void testDeactivation() 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("ANOTHER-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);

        // Register another event
        requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("G,g,g,g,g U-N-I-T");
        // add required fields
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
                
        eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage.build().toByteString())
                .build();
        message = createEventAdminMessage(eventAdminMessage);
        payload = createPayload(eventAdminMessage);
        m_SUT.handleMessage(message, payload, channel);
        
        m_SUT.deactivate();

        //verify that both registered services have been unregistered
        verify(reg, times(2)).unregister();
    }
/**
     * Test if registered remote events are properly unregistered when the service is deactivated.
     */
Test if registered remote events are properly unregistered when the service is deactivated.
Test if registered remote events are properly unregistered when the service is deactivated .
@Test
    public final void testDeactivation() 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("ANOTHER-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);
        requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("G,g,g,g,g U-N-I-T");
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage.build().toByteString())
                .build();
        message = createEventAdminMessage(eventAdminMessage);
        payload = createPayload(eventAdminMessage);
        m_SUT.handleMessage(message, payload, channel);
        m_SUT.deactivate();
        verify(reg, times(2)).unregister();
    }
@ Test public final void testDeactivation ( ) 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 ( "ANOTHER-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 ) ; requestMessage = EventRegistrationRequestData . newBuilder ( ) . addTopic ( "G,g,g,g,g U-N-I-T" ) ; requestMessage = RemoteUtils . appendRequiredFields ( requestMessage , false ) ; eventAdminMessage = EventAdminNamespace . newBuilder ( ) . setType ( EventAdminMessageType . EventRegistrationRequest ) . setData ( requestMessage . build ( ) . toByteString ( ) ) . build ( ) ; message = createEventAdminMessage ( eventAdminMessage ) ; payload = createPayload ( eventAdminMessage ) ; m_SUT . handleMessage ( message , payload , channel ) ; m_SUT . deactivate ( ) ; verify ( reg , times ( 2 ) ) . unregister ( ) ; }
Test if registered remote events are properly unregistered when the service is deactivated.
Test if registered remote events are properly unregistered when the service is deactivated .
// mock // Register Event // add required fields // mock the channel the message came from // replay // Register another event // add required fields //verify that both registered services have been unregistered