mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public final void testExecuteCommandMessages() throws Exception
    {        
        Asset asset = mock(Asset.class);
        when(asset.getUuid()).thenReturn(m_AssetUuid);
        
        //Generate the proto request data
        ExecuteCommandRequestData request = ExecuteCommandRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).
                setCommandType(CommandType.Enum.CAPTURE_IMAGE_COMMAND).
                setCommand(ByteString.copyFromUtf8("command")).build();
        //Generate the namespace
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.ExecuteCommandRequest).
                setData(request.toByteString()).build();
        //Generate the TerraHarvest message
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);
        
        Command javaCommand = new Command() 
        {
            private static final long serialVersionUID = 1L;
        };
        
        Response javaResponse = new Response() 
        {
            private static final long serialVersionUID = 1L;
        };
        
        when(m_CommandConverterService.getJavaCommandType(Mockito.any(byte[].class), 
                eq(CommandTypeEnum.CAPTURE_IMAGE_COMMAND))).thenReturn(javaCommand);
        when(m_CommandConverterService.getResponseTypeFromCommandType(CommandTypeEnum.CAPTURE_IMAGE_COMMAND))
            .thenReturn(CommandResponseEnum.CAPTURE_IMAGE_RESPONSE);
        
        when(m_Converter.convertToProto(Mockito.any(Object.class)))
            .thenReturn(CaptureImageResponseGen.CaptureImageResponse.getDefaultInstance());
        when(asset.executeCommand(javaCommand)).thenReturn(javaResponse);
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        verify(m_ResponseWrapper, timeout(3000)).queue(channel);
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        ArgumentCaptor<ExecuteCommandResponseData> responseCaptor = 
                ArgumentCaptor.forClass(ExecuteCommandResponseData.class);
        verify(m_EventAdmin, atLeastOnce()).postEvent(eventCaptor.capture());
        //Test the remote message service
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.ExecuteCommandResponse), responseCaptor.capture());
        
        Event postedEvent = eventCaptor.getValue();
        //Verify the received message
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        //Verify the Response type
        ExecuteCommandResponseData response = responseCaptor.getValue();
        assertThat(response.getResponseType(), is(CommandResponseEnumConverter
                .convertJavaEnumToProto(CommandResponseEnum.CAPTURE_IMAGE_RESPONSE)));
        assertThat(SharedMessageUtils.convertProtoUUIDtoUUID(response.getUuid()), is(m_AssetUuid));
    }
/**
     * Test executeCommand message system.
     * Specifically, the following behaviors are tested: 
     *      Verify incoming command request message is posted to event admin.
     *      Verify command response is generated 
     *      Verify Remote Message Service is started
     *      Verify correct command response is sent to the requester
     */
Test executeCommand message system.
Specifically, the following behaviors are tested:
Verify incoming command request message is posted to event admin.
Verify command response is generated
Verify Remote Message Service is started
Verify correct command response is sent to the requester
Test executeCommand message system . Specifically the following behaviors are tested : Verify incoming command request message is posted to event admin . Verify command response is generated Verify Remote Message Service is started Verify correct command response is sent to the requester
@Test
    public final void testExecuteCommandMessages() throws Exception
    {        
        Asset asset = mock(Asset.class);
        when(asset.getUuid()).thenReturn(m_AssetUuid);
        ExecuteCommandRequestData request = ExecuteCommandRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).
                setCommandType(CommandType.Enum.CAPTURE_IMAGE_COMMAND).
                setCommand(ByteString.copyFromUtf8("command")).build();
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.ExecuteCommandRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);
        Command javaCommand = new Command() 
        {
            private static final long serialVersionUID = 1L;
        };
        Response javaResponse = new Response() 
        {
            private static final long serialVersionUID = 1L;
        };
        when(m_CommandConverterService.getJavaCommandType(Mockito.any(byte[].class), 
                eq(CommandTypeEnum.CAPTURE_IMAGE_COMMAND))).thenReturn(javaCommand);
        when(m_CommandConverterService.getResponseTypeFromCommandType(CommandTypeEnum.CAPTURE_IMAGE_COMMAND))
            .thenReturn(CommandResponseEnum.CAPTURE_IMAGE_RESPONSE);
        when(m_Converter.convertToProto(Mockito.any(Object.class)))
            .thenReturn(CaptureImageResponseGen.CaptureImageResponse.getDefaultInstance());
        when(asset.executeCommand(javaCommand)).thenReturn(javaResponse);
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_ResponseWrapper, timeout(3000)).queue(channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        ArgumentCaptor<ExecuteCommandResponseData> responseCaptor = 
                ArgumentCaptor.forClass(ExecuteCommandResponseData.class);
        verify(m_EventAdmin, atLeastOnce()).postEvent(eventCaptor.capture());
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.ExecuteCommandResponse), responseCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        ExecuteCommandResponseData response = responseCaptor.getValue();
        assertThat(response.getResponseType(), is(CommandResponseEnumConverter
                .convertJavaEnumToProto(CommandResponseEnum.CAPTURE_IMAGE_RESPONSE)));
        assertThat(SharedMessageUtils.convertProtoUUIDtoUUID(response.getUuid()), is(m_AssetUuid));
    }
@ Test public final void testExecuteCommandMessages ( ) throws Exception { Asset asset = mock ( Asset . class ) ; when ( asset . getUuid ( ) ) . thenReturn ( m_AssetUuid ) ; ExecuteCommandRequestData request = ExecuteCommandRequestData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) . setCommandType ( CommandType . Enum . CAPTURE_IMAGE_COMMAND ) . setCommand ( ByteString . copyFromUtf8 ( "command" ) ) . build ( ) ; AssetNamespace assetMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . ExecuteCommandRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetMessage ) ; TerraHarvestMessage message = createMessage ( assetMessage ) ; Command javaCommand = new Command ( ) { private static final long serialVersionUID = 1L ; } ; Response javaResponse = new Response ( ) { private static final long serialVersionUID = 1L ; } ; when ( m_CommandConverterService . getJavaCommandType ( Mockito . any ( byte [ ] . class ) , eq ( CommandTypeEnum . CAPTURE_IMAGE_COMMAND ) ) ) . thenReturn ( javaCommand ) ; when ( m_CommandConverterService . getResponseTypeFromCommandType ( CommandTypeEnum . CAPTURE_IMAGE_COMMAND ) ) . thenReturn ( CommandResponseEnum . CAPTURE_IMAGE_RESPONSE ) ; when ( m_Converter . convertToProto ( Mockito . any ( Object . class ) ) ) . thenReturn ( CaptureImageResponseGen . CaptureImageResponse . getDefaultInstance ( ) ) ; when ( asset . executeCommand ( javaCommand ) ) . thenReturn ( javaResponse ) ; when ( m_AssetDirectoryService . getAssetByUuid ( m_AssetUuid ) ) . thenReturn ( asset ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_ResponseWrapper , timeout ( 3000 ) ) . queue ( channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; ArgumentCaptor < ExecuteCommandResponseData > responseCaptor = ArgumentCaptor . forClass ( ExecuteCommandResponseData . class ) ; verify ( m_EventAdmin , atLeastOnce ( ) ) . postEvent ( eventCaptor . capture ( ) ) ; verify ( m_MessageFactory ) . createAssetResponseMessage ( eq ( message ) , eq ( AssetMessageType . ExecuteCommandResponse ) , responseCaptor . capture ( ) ) ; Event postedEvent = eventCaptor . getValue ( ) ; assertThat ( ( TerraHarvestMessage ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE ) , is ( message ) ) ; ExecuteCommandResponseData response = responseCaptor . getValue ( ) ; assertThat ( response . getResponseType ( ) , is ( CommandResponseEnumConverter . convertJavaEnumToProto ( CommandResponseEnum . CAPTURE_IMAGE_RESPONSE ) ) ) ; assertThat ( SharedMessageUtils . convertProtoUUIDtoUUID ( response . getUuid ( ) ) , is ( m_AssetUuid ) ) ; }
Test executeCommand message system.
Test executeCommand message system .
//Generate the proto request data //Generate the namespace //Generate the TerraHarvest message // mock the channel the message came from // replay //Test the remote message service //Verify the received message //Verify the Response type