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