mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/messaging/TestMessageSenderImpl.java
@Test
    public void testEncryptionLevelCheck() throws InvalidProtocolBufferException
    {
        // construct test data message to send
        ControllerInfoData systemInfoData = ControllerInfoData.newBuilder().setName("blah").build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.Base, systemInfoData);
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        
        //Test remote system has higher encryption level than local system.
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.AES_ECDH_ECDSA);
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.NONE);
        m_SUT.queueMessage(m_RemoteId, payload, null);
        
        //Test local system has higher encryption level than remote system.
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.NONE);
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.AES_ECDH_ECDSA);
        m_SUT.queueMessage(m_RemoteId, payload, null);
        
        //Test both local and remote having no encryption
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.NONE);
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.NONE);
        m_SUT.queueMessage(m_RemoteId, payload, null);
        
        //capture the message being sent to the encryption service
        ArgumentCaptor<TerraHarvestMessage.Builder> builderCaptor = 
                ArgumentCaptor.forClass(TerraHarvestMessage.Builder.class);
        verify(m_EncryptService, times(3)).encryptMessage(builderCaptor.capture(), eq(payload));
        assertThat(builderCaptor.getAllValues().get(0).getEncryptType(), is(EncryptType.AES_ECDH_ECDSA));
        assertThat(builderCaptor.getAllValues().get(1).getEncryptType(), is(EncryptType.AES_ECDH_ECDSA));
        assertThat(builderCaptor.getAllValues().get(2).getEncryptType(), is(EncryptType.NONE));
        
        // construct encryption info namespace message.
        GetEncryptionTypeResponseData encryptResponse = GetEncryptionTypeResponseData.newBuilder().
                setType(EncryptType.AES_ECDH_ECDSA).build();
        request = createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.EncryptionInfo, encryptResponse);
        payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        
        //Test send encryption info namespace message. Encryption level should be none.
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.AES_ECDH_ECDSA);
        m_SUT.queueMessage(m_RemoteId, payload, null);
        
        builderCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.Builder.class);
        verify(m_EncryptService, times(1)).encryptMessage(builderCaptor.capture(), eq(payload));
        assertThat(builderCaptor.getAllValues().get(0).getEncryptType(), is(EncryptType.NONE));
    }
/**
     * Verify that the message encryption level is set to that of the remote system's encryption level when the local
     * system's encryption level is lower.
     */
Verify that the message encryption level is set to that of the remote system's encryption level when the local
system's encryption level is lower.
Verify that the message encryption level is set to that of the remote system ' s encryption level when the local system ' s encryption level is lower .
@Test
    public void testEncryptionLevelCheck() throws InvalidProtocolBufferException
    {
        ControllerInfoData systemInfoData = ControllerInfoData.newBuilder().setName("blah").build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.Base, systemInfoData);
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.AES_ECDH_ECDSA);
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.NONE);
        m_SUT.queueMessage(m_RemoteId, payload, null);
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.NONE);
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.AES_ECDH_ECDSA);
        m_SUT.queueMessage(m_RemoteId, payload, null);
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.NONE);
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.NONE);
        m_SUT.queueMessage(m_RemoteId, payload, null);
        ArgumentCaptor<TerraHarvestMessage.Builder> builderCaptor = 
                ArgumentCaptor.forClass(TerraHarvestMessage.Builder.class);
        verify(m_EncryptService, times(3)).encryptMessage(builderCaptor.capture(), eq(payload));
        assertThat(builderCaptor.getAllValues().get(0).getEncryptType(), is(EncryptType.AES_ECDH_ECDSA));
        assertThat(builderCaptor.getAllValues().get(1).getEncryptType(), is(EncryptType.AES_ECDH_ECDSA));
        assertThat(builderCaptor.getAllValues().get(2).getEncryptType(), is(EncryptType.NONE));
        GetEncryptionTypeResponseData encryptResponse = GetEncryptionTypeResponseData.newBuilder().
                setType(EncryptType.AES_ECDH_ECDSA).build();
        request = createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.EncryptionInfo, encryptResponse);
        payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.AES_ECDH_ECDSA);
        m_SUT.queueMessage(m_RemoteId, payload, null);
        builderCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.Builder.class);
        verify(m_EncryptService, times(1)).encryptMessage(builderCaptor.capture(), eq(payload));
        assertThat(builderCaptor.getAllValues().get(0).getEncryptType(), is(EncryptType.NONE));
    }
@ Test public void testEncryptionLevelCheck ( ) throws InvalidProtocolBufferException { ControllerInfoData systemInfoData = ControllerInfoData . newBuilder ( ) . setName ( "blah" ) . build ( ) ; TerraHarvestMessage request = createMessageWithDestSource ( m_LocalId , m_RemoteId , 0 , Namespace . Base , systemInfoData ) ; TerraHarvestPayload payload = TerraHarvestPayload . parseFrom ( request . getTerraHarvestPayload ( ) ) ; when ( m_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( request ) ; when ( m_RemoteSystemEncryption . getEncryptType ( m_RemoteId ) ) . thenReturn ( EncryptType . AES_ECDH_ECDSA ) ; when ( m_RemoteSettings . getEncryptionMode ( ) ) . thenReturn ( EncryptionMode . NONE ) ; m_SUT . queueMessage ( m_RemoteId , payload , null ) ; when ( m_RemoteSystemEncryption . getEncryptType ( m_RemoteId ) ) . thenReturn ( EncryptType . NONE ) ; when ( m_RemoteSettings . getEncryptionMode ( ) ) . thenReturn ( EncryptionMode . AES_ECDH_ECDSA ) ; m_SUT . queueMessage ( m_RemoteId , payload , null ) ; when ( m_RemoteSystemEncryption . getEncryptType ( m_RemoteId ) ) . thenReturn ( EncryptType . NONE ) ; when ( m_RemoteSettings . getEncryptionMode ( ) ) . thenReturn ( EncryptionMode . NONE ) ; m_SUT . queueMessage ( m_RemoteId , payload , null ) ; ArgumentCaptor < TerraHarvestMessage . Builder > builderCaptor = ArgumentCaptor . forClass ( TerraHarvestMessage . Builder . class ) ; verify ( m_EncryptService , times ( 3 ) ) . encryptMessage ( builderCaptor . capture ( ) , eq ( payload ) ) ; assertThat ( builderCaptor . getAllValues ( ) . get ( 0 ) . getEncryptType ( ) , is ( EncryptType . AES_ECDH_ECDSA ) ) ; assertThat ( builderCaptor . getAllValues ( ) . get ( 1 ) . getEncryptType ( ) , is ( EncryptType . AES_ECDH_ECDSA ) ) ; assertThat ( builderCaptor . getAllValues ( ) . get ( 2 ) . getEncryptType ( ) , is ( EncryptType . NONE ) ) ; GetEncryptionTypeResponseData encryptResponse = GetEncryptionTypeResponseData . newBuilder ( ) . setType ( EncryptType . AES_ECDH_ECDSA ) . build ( ) ; request = createMessageWithDestSource ( m_LocalId , m_RemoteId , 0 , Namespace . EncryptionInfo , encryptResponse ) ; payload = TerraHarvestPayload . parseFrom ( request . getTerraHarvestPayload ( ) ) ; when ( m_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( request ) ; when ( m_RemoteSystemEncryption . getEncryptType ( m_RemoteId ) ) . thenReturn ( EncryptType . AES_ECDH_ECDSA ) ; m_SUT . queueMessage ( m_RemoteId , payload , null ) ; builderCaptor = ArgumentCaptor . forClass ( TerraHarvestMessage . Builder . class ) ; verify ( m_EncryptService , times ( 1 ) ) . encryptMessage ( builderCaptor . capture ( ) , eq ( payload ) ) ; assertThat ( builderCaptor . getAllValues ( ) . get ( 0 ) . getEncryptType ( ) , is ( EncryptType . NONE ) ) ; }
Verify that the message encryption level is set to that of the remote system's encryption level when the local
 system's encryption level is lower.
Verify that the message encryption level is set to that of the remote system ' s encryption level when the local system ' s encryption level is lower .
// construct test data message to send //Test remote system has higher encryption level than local system. //Test local system has higher encryption level than remote system. //Test both local and remote having no encryption //capture the message being sent to the encryption service // construct encryption info namespace message. //Test send encryption info namespace message. Encryption level should be none.