mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestMessageRouterImpl.java
@Test
    public void testHandlePayloadInvalidKeySignatureException() 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(
                new InvalidKeySignatureException("test failure!"));
        
        m_SUT.handleMessage(baseMessage, channel);
        
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(channel).queueMessage(messageCaptor.capture());
        
        //Verify invalid key signature method.
        TerraHarvestMessage errorMessage = messageCaptor.getAllValues().get(0);
        TerraHarvestPayload errorPayload = TerraHarvestPayload.parseFrom(errorMessage.getTerraHarvestPayload());
        EncryptionInfoNamespace namespaceMessage = 
                EncryptionInfoNamespace.parseFrom(errorPayload.getNamespaceMessage());
        EncryptionInfoErrorResponseData errorResponse = 
                EncryptionInfoErrorResponseData.parseFrom(namespaceMessage.getData());
        
        assertThat(errorResponse.getError(), is(EncryptionErrorCode.INVALID_SIGNATURE_KEY));
        assertThat(errorResponse.getErrorDescription(), 
                is("test failure!"));
    }
/**
     * Verify that the invalid key signature exception is handled correctly when calling the handle message function.
     */
Verify that the invalid key signature exception is handled correctly when calling the handle message function.
Verify that the invalid key signature exception is handled correctly when calling the handle message function .
@Test
    public void testHandlePayloadInvalidKeySignatureException() 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(
                new InvalidKeySignatureException("test failure!"));
        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());
        EncryptionInfoNamespace namespaceMessage = 
                EncryptionInfoNamespace.parseFrom(errorPayload.getNamespaceMessage());
        EncryptionInfoErrorResponseData errorResponse = 
                EncryptionInfoErrorResponseData.parseFrom(namespaceMessage.getData());
        assertThat(errorResponse.getError(), is(EncryptionErrorCode.INVALID_SIGNATURE_KEY));
        assertThat(errorResponse.getErrorDescription(), 
                is("test failure!"));
    }
@ Test public void testHandlePayloadInvalidKeySignatureException ( ) 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 ( new InvalidKeySignatureException ( "test failure!" ) ) ; 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 ( ) ) ; EncryptionInfoNamespace namespaceMessage = EncryptionInfoNamespace . parseFrom ( errorPayload . getNamespaceMessage ( ) ) ; EncryptionInfoErrorResponseData errorResponse = EncryptionInfoErrorResponseData . parseFrom ( namespaceMessage . getData ( ) ) ; assertThat ( errorResponse . getError ( ) , is ( EncryptionErrorCode . INVALID_SIGNATURE_KEY ) ) ; assertThat ( errorResponse . getErrorDescription ( ) , is ( "test failure!" ) ) ; }
Verify that the invalid key signature exception is handled correctly when calling the handle message function.
Verify that the invalid key signature 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 key signature method.