mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestMessageRouterImpl.java
@Test
    public void testHandleMessage_IllegalStateException() 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 illegal state exception---
        IllegalStateException illegalStateException = new IllegalStateException("exception-message");
        doThrow(illegalStateException).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
        m_SUT.handleMessage(baseMessage, channel);
        
        // verify error response is queued from the channel
        verifyBaseErrorResponse(channel, ErrorCode.ILLEGAL_STATE, 
                "Illegal state when handling [Base] namespace message: exception-message");
        
        // test with empty exception message
        illegalStateException = new IllegalStateException();
        doThrow(illegalStateException).when(baseMessageService).handleMessage(Mockito.any(TerraHarvestMessage.class), 
            Mockito.any(TerraHarvestPayload.class),eq(channel));
        
        // replay
        m_SUT.handleMessage(baseMessage, channel);
        
        verifyBaseErrorResponse(channel, ErrorCode.ILLEGAL_STATE, 
                "Illegal state when handling [Base] namespace message: null");  
    }
/**
     * Verify message handler handles an illegal state exception. Verify the channel the message
     * was sent on queues an error response message for the exception.
     */
Verify message handler handles an illegal state exception. Verify the channel the message
was sent on queues an error response message for the exception.
Verify message handler handles an illegal state exception . Verify the channel the message was sent on queues an error response message for the exception .
@Test
    public void testHandleMessage_IllegalStateException() 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);
        IllegalStateException illegalStateException = new IllegalStateException("exception-message");
        doThrow(illegalStateException).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.ILLEGAL_STATE, 
                "Illegal state when handling [Base] namespace message: exception-message");
        illegalStateException = new IllegalStateException();
        doThrow(illegalStateException).when(baseMessageService).handleMessage(Mockito.any(TerraHarvestMessage.class), 
            Mockito.any(TerraHarvestPayload.class),eq(channel));
        m_SUT.handleMessage(baseMessage, channel);
        verifyBaseErrorResponse(channel, ErrorCode.ILLEGAL_STATE, 
                "Illegal state when handling [Base] namespace message: null");  
    }
@ Test public void testHandleMessage_IllegalStateException ( ) 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 ) ; IllegalStateException illegalStateException = new IllegalStateException ( "exception-message" ) ; doThrow ( illegalStateException ) . 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 . ILLEGAL_STATE , "Illegal state when handling [Base] namespace message: exception-message" ) ; illegalStateException = new IllegalStateException ( ) ; doThrow ( illegalStateException ) . when ( baseMessageService ) . handleMessage ( Mockito . any ( TerraHarvestMessage . class ) , Mockito . any ( TerraHarvestPayload . class ) , eq ( channel ) ) ; m_SUT . handleMessage ( baseMessage , channel ) ; verifyBaseErrorResponse ( channel , ErrorCode . ILLEGAL_STATE , "Illegal state when handling [Base] namespace message: null" ) ; }
Verify message handler handles an illegal state exception.
Verify message handler handles an illegal state 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 illegal state exception--- //decryption call // replay // verify error response is queued from the channel // test with empty exception message // replay