mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestMessageRouterImpl.java
@SuppressWarnings("unchecked")
    @Test
    public void testHandlePayloadInvalidProtocolException() throws InvalidProtocolBufferException, 
        InvalidKeySignatureException
    {
        TerraHarvestMessage baseMessage = TerraHarvestMessageHelper.createBaseMessage();
                
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        when(channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(true);
        
        //encryption service behavior force throw invalid protocol exception.
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.NONE);
        when(m_EcryptService.decryptRemoteMessage(Mockito.any(TerraHarvestMessage.class))).thenThrow(
                InvalidProtocolBufferException.class);
        
        m_SUT.handleMessage(baseMessage, channel);
        
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(channel).queueMessage(messageCaptor.capture());
        
        //Verify invalid protocol message.
        TerraHarvestMessage errorMessage = messageCaptor.getAllValues().get(0);
        TerraHarvestPayload errorPayload = TerraHarvestPayload.parseFrom(errorMessage.getTerraHarvestPayload());
        BaseNamespace baseNamespaceMessage = BaseNamespace.parseFrom(errorPayload.getNamespaceMessage());
        GenericErrorResponseData errorResponse = GenericErrorResponseData.parseFrom(baseNamespaceMessage.getData());
        
        assertThat(errorResponse.getError(), is(ErrorCode.INVALID_REQUEST));
        assertThat(errorResponse.getErrorDescription(), is("Invalid payload exception when handling a message"));
    }
/**
     * Verify that the invalid protocol exception is handled correctly when calling the handle message function.
     */
Verify that the invalid protocol exception is handled correctly when calling the handle message function.
Verify that the invalid protocol exception is handled correctly when calling the handle message function .
@SuppressWarnings("unchecked")
    @Test
    public void testHandlePayloadInvalidProtocolException() throws InvalidProtocolBufferException, 
        InvalidKeySignatureException
    {
        TerraHarvestMessage baseMessage = TerraHarvestMessageHelper.createBaseMessage();
        RemoteChannel channel = mock(RemoteChannel.class);
        when(channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(true);
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.NONE);
        when(m_EcryptService.decryptRemoteMessage(Mockito.any(TerraHarvestMessage.class))).thenThrow(
                InvalidProtocolBufferException.class);
        m_SUT.handleMessage(baseMessage, channel);
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(channel).queueMessage(messageCaptor.capture());
        TerraHarvestMessage errorMessage = messageCaptor.getAllValues().get(0);
        TerraHarvestPayload errorPayload = TerraHarvestPayload.parseFrom(errorMessage.getTerraHarvestPayload());
        BaseNamespace baseNamespaceMessage = BaseNamespace.parseFrom(errorPayload.getNamespaceMessage());
        GenericErrorResponseData errorResponse = GenericErrorResponseData.parseFrom(baseNamespaceMessage.getData());
        assertThat(errorResponse.getError(), is(ErrorCode.INVALID_REQUEST));
        assertThat(errorResponse.getErrorDescription(), is("Invalid payload exception when handling a message"));
    }
@ SuppressWarnings ( "unchecked" ) @ Test public void testHandlePayloadInvalidProtocolException ( ) throws InvalidProtocolBufferException , InvalidKeySignatureException { TerraHarvestMessage baseMessage = TerraHarvestMessageHelper . createBaseMessage ( ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; when ( channel . queueMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( true ) ; when ( m_RemoteSettings . getEncryptionMode ( ) ) . thenReturn ( EncryptionMode . NONE ) ; when ( m_EcryptService . decryptRemoteMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenThrow ( InvalidProtocolBufferException . class ) ; m_SUT . handleMessage ( baseMessage , channel ) ; ArgumentCaptor < TerraHarvestMessage > messageCaptor = ArgumentCaptor . forClass ( TerraHarvestMessage . class ) ; verify ( channel ) . queueMessage ( messageCaptor . capture ( ) ) ; TerraHarvestMessage errorMessage = messageCaptor . getAllValues ( ) . get ( 0 ) ; TerraHarvestPayload errorPayload = TerraHarvestPayload . parseFrom ( errorMessage . getTerraHarvestPayload ( ) ) ; BaseNamespace baseNamespaceMessage = BaseNamespace . parseFrom ( errorPayload . getNamespaceMessage ( ) ) ; GenericErrorResponseData errorResponse = GenericErrorResponseData . parseFrom ( baseNamespaceMessage . getData ( ) ) ; assertThat ( errorResponse . getError ( ) , is ( ErrorCode . INVALID_REQUEST ) ) ; assertThat ( errorResponse . getErrorDescription ( ) , is ( "Invalid payload exception when handling a message" ) ) ; }
Verify that the invalid protocol exception is handled correctly when calling the handle message function.
Verify that the invalid protocol exception is handled correctly when calling the handle message function .
// mock the channel the message came from //encryption service behavior force throw invalid protocol exception. //Verify invalid protocol message.