mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestMessageRouterImpl.java
@Test
    public void testHandleMessage_InvalidProtoBufferException() throws Exception
    {
        // construct a single base namespace message just to satisfy input
        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ControllerInfo)
                .build();
        TerraHarvestMessage baseMessage = 
                TerraHarvestMessageHelper.createTerraHarvestMessage(0, m_SystemId, Namespace.Base, 100, 
                        baseNamespaceMessage);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        when(channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(true);
        
        // register a service that will throw exception when handling message
        MessageService baseMessageService = mock(MessageService.class);
        when(baseMessageService.getNamespace()).thenReturn(Namespace.Base);
        
        //---Verify protocol buffer exception (will throw an IO exception since it extends it)---
        InvalidProtocolBufferException exception = new InvalidProtocolBufferException("exception-message");
        doThrow(exception).when(baseMessageService).handleMessage(Mockito.any(TerraHarvestMessage.class), 
            Mockito.any(TerraHarvestPayload.class), eq(channel));
        
        m_SUT.bindMessageService(baseMessageService);
        
        //decryption call
        when(m_EcryptService.decryptRemoteMessage(Mockito.any(TerraHarvestMessage.class))).
            thenReturn(TerraHarvestPayload.parseFrom(baseMessage.getTerraHarvestPayload()));
        
        // replay, should not bomb
        m_SUT.handleMessage(baseMessage, channel);
        
        // verify error response is queued from the channel
        verifyBaseErrorResponse(channel, ErrorCode.INVALID_REQUEST, 
                "Failed IO operation when handling [Base] namespace message: exception-message");
    }
/**
     * Verify message handler handles an invalid protocol exception. Verify the channel the message
     * was sent on queues an error response message for the exception.
     */
Verify message handler handles an invalid protocol exception. Verify the channel the message
was sent on queues an error response message for the exception.
Verify message handler handles an invalid protocol exception . Verify the channel the message was sent on queues an error response message for the exception .
@Test
    public void testHandleMessage_InvalidProtoBufferException() throws Exception
    {
        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ControllerInfo)
                .build();
        TerraHarvestMessage baseMessage = 
                TerraHarvestMessageHelper.createTerraHarvestMessage(0, m_SystemId, Namespace.Base, 100, 
                        baseNamespaceMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        when(channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(true);
        MessageService baseMessageService = mock(MessageService.class);
        when(baseMessageService.getNamespace()).thenReturn(Namespace.Base);
        InvalidProtocolBufferException exception = new InvalidProtocolBufferException("exception-message");
        doThrow(exception).when(baseMessageService).handleMessage(Mockito.any(TerraHarvestMessage.class), 
            Mockito.any(TerraHarvestPayload.class), eq(channel));
        m_SUT.bindMessageService(baseMessageService);
        when(m_EcryptService.decryptRemoteMessage(Mockito.any(TerraHarvestMessage.class))).
            thenReturn(TerraHarvestPayload.parseFrom(baseMessage.getTerraHarvestPayload()));
        m_SUT.handleMessage(baseMessage, channel);
        verifyBaseErrorResponse(channel, ErrorCode.INVALID_REQUEST, 
                "Failed IO operation when handling [Base] namespace message: exception-message");
    }
@ Test public void testHandleMessage_InvalidProtoBufferException ( ) throws Exception { BaseNamespace baseNamespaceMessage = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . ControllerInfo ) . build ( ) ; TerraHarvestMessage baseMessage = TerraHarvestMessageHelper . createTerraHarvestMessage ( 0 , m_SystemId , Namespace . Base , 100 , baseNamespaceMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; when ( channel . queueMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( true ) ; MessageService baseMessageService = mock ( MessageService . class ) ; when ( baseMessageService . getNamespace ( ) ) . thenReturn ( Namespace . Base ) ; InvalidProtocolBufferException exception = new InvalidProtocolBufferException ( "exception-message" ) ; doThrow ( exception ) . when ( baseMessageService ) . handleMessage ( Mockito . any ( TerraHarvestMessage . class ) , Mockito . any ( TerraHarvestPayload . class ) , eq ( channel ) ) ; m_SUT . bindMessageService ( baseMessageService ) ; when ( m_EcryptService . decryptRemoteMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( TerraHarvestPayload . parseFrom ( baseMessage . getTerraHarvestPayload ( ) ) ) ; m_SUT . handleMessage ( baseMessage , channel ) ; verifyBaseErrorResponse ( channel , ErrorCode . INVALID_REQUEST , "Failed IO operation when handling [Base] namespace message: exception-message" ) ; }
Verify message handler handles an invalid protocol exception.
Verify message handler handles an invalid protocol exception .
// construct a single base namespace message just to satisfy input // mock the channel the message came from // register a service that will throw exception when handling message //---Verify protocol buffer exception (will throw an IO exception since it extends it)--- //decryption call // replay, should not bomb // verify error response is queued from the channel