mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestMessageRouterImpl.java
@Test
    public void testUnbindMessageService() throws Exception
    {
        // construct a single base namespace message to verify sent to base message service
        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ControllerInfo)
                .build();
        TerraHarvestPayload payload = TerraHarvestPayload.newBuilder().
                setNamespace(Namespace.Base).
                setNamespaceMessage(baseNamespaceMessage.toByteString()).
                build();
        
        TerraHarvestMessage baseMessage = 
                TerraHarvestMessageHelper.createTerraHarvestMessage(0, m_SystemId, Namespace.Base, 100, 
                        baseNamespaceMessage);
         
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        //decryption call
        when(m_EcryptService.decryptRemoteMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(payload);
        
        // now register a service that will handle the message
        MessageService baseMessageService = mock(MessageService.class);
        when(baseMessageService.getNamespace()).thenReturn(Namespace.Base);
        m_SUT.bindMessageService(baseMessageService);
        
        // now unbind
        m_SUT.unbindMessageService(baseMessageService);
        
        // replay
        m_SUT.handleMessage(baseMessage, channel);
        
        // verify proper message service is sent the same message
        verify(baseMessageService, never()).handleMessage(baseMessage, payload, channel);
    }
/**
     * Verify if a message service is unbound it will no longer be used to handle messages.
     */
Verify if a message service is unbound it will no longer be used to handle messages.
Verify if a message service is unbound it will no longer be used to handle messages .
@Test
    public void testUnbindMessageService() throws Exception
    {
        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ControllerInfo)
                .build();
        TerraHarvestPayload payload = TerraHarvestPayload.newBuilder().
                setNamespace(Namespace.Base).
                setNamespaceMessage(baseNamespaceMessage.toByteString()).
                build();
        TerraHarvestMessage baseMessage = 
                TerraHarvestMessageHelper.createTerraHarvestMessage(0, m_SystemId, Namespace.Base, 100, 
                        baseNamespaceMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        when(m_EcryptService.decryptRemoteMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(payload);
        MessageService baseMessageService = mock(MessageService.class);
        when(baseMessageService.getNamespace()).thenReturn(Namespace.Base);
        m_SUT.bindMessageService(baseMessageService);
        m_SUT.unbindMessageService(baseMessageService);
        m_SUT.handleMessage(baseMessage, channel);
        verify(baseMessageService, never()).handleMessage(baseMessage, payload, channel);
    }
@ Test public void testUnbindMessageService ( ) throws Exception { BaseNamespace baseNamespaceMessage = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . ControllerInfo ) . build ( ) ; TerraHarvestPayload payload = TerraHarvestPayload . newBuilder ( ) . setNamespace ( Namespace . Base ) . setNamespaceMessage ( baseNamespaceMessage . toByteString ( ) ) . build ( ) ; TerraHarvestMessage baseMessage = TerraHarvestMessageHelper . createTerraHarvestMessage ( 0 , m_SystemId , Namespace . Base , 100 , baseNamespaceMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; when ( m_EcryptService . decryptRemoteMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( payload ) ; MessageService baseMessageService = mock ( MessageService . class ) ; when ( baseMessageService . getNamespace ( ) ) . thenReturn ( Namespace . Base ) ; m_SUT . bindMessageService ( baseMessageService ) ; m_SUT . unbindMessageService ( baseMessageService ) ; m_SUT . handleMessage ( baseMessage , channel ) ; verify ( baseMessageService , never ( ) ) . handleMessage ( baseMessage , payload , channel ) ; }
Verify if a message service is unbound it will no longer be used to handle messages.
Verify if a message service is unbound it will no longer be used to handle messages .
// construct a single base namespace message to verify sent to base message service // mock the channel the message came from //decryption call // now register a service that will handle the message // now unbind // replay // verify proper message service is sent the same message