mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public final void testObjectConverterExceptionExecuteCommand() throws 
        ObjectConverterException, IOException
    {
        //Get the ordinal value of the command
        final CommandType.Enum commandType = CommandTypeEnumConverter
                .convertJavaEnumToProto(CommandTypeEnum.SET_POSITION_COMMAND);
        
        //Generate the proto command   
        SetPositionCommandGen.SetPositionCommand setPositionProto = 
                SetPositionCommandGen.SetPositionCommand.newBuilder()
                .setBase(BaseTypesGen.Command.getDefaultInstance()).build();
        //Generate the proto request data
        ExecuteCommandRequestData request = ExecuteCommandRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).
                setCommandType(commandType).setCommand(setPositionProto.toByteString()).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);

        //mock
        Asset asset = mock(Asset.class);
        
        when(asset.getName()).thenReturn("Name");
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        
        when(m_CommandConverterService.getResponseTypeFromCommandType(CommandTypeEnum.SET_POSITION_COMMAND))
            .thenReturn(CommandResponseEnum.SET_POSITION_RESPONSE);
        Command command = mock(Command.class);
        when(m_CommandConverterService.getJavaCommandType(
                Mockito.any(byte[].class), eq(CommandTypeEnum.SET_POSITION_COMMAND)))
            .thenReturn(command);
       
        Exception exception = new ObjectConverterException("Cannot Execute Command");
        when(m_Converter.convertToProto(Mockito.any(Command.class))).thenThrow(exception);
        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(2000)).queue(channel);
        verify(m_MessageFactory).createBaseErrorResponse(message, exception, 
                String.format("Unable to convert command response to " 
                        + "proto message for asset %s when executing command %s", asset.getName(), 
                        CommandTypeEnum.SET_POSITION_COMMAND));       
    }
/**
     * Verify if a conversion exception occurs during a command response, an error response is sent instead.
     */
Verify if a conversion exception occurs during a command response, an error response is sent instead.
Verify if a conversion exception occurs during a command response an error response is sent instead .
@Test
    public final void testObjectConverterExceptionExecuteCommand() throws 
        ObjectConverterException, IOException
    {
        final CommandType.Enum commandType = CommandTypeEnumConverter
                .convertJavaEnumToProto(CommandTypeEnum.SET_POSITION_COMMAND);
        SetPositionCommandGen.SetPositionCommand setPositionProto = 
                SetPositionCommandGen.SetPositionCommand.newBuilder()
                .setBase(BaseTypesGen.Command.getDefaultInstance()).build();
        ExecuteCommandRequestData request = ExecuteCommandRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).
                setCommandType(commandType).setCommand(setPositionProto.toByteString()).build();
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.ExecuteCommandRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);
        Asset asset = mock(Asset.class);
        when(asset.getName()).thenReturn("Name");
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        when(m_CommandConverterService.getResponseTypeFromCommandType(CommandTypeEnum.SET_POSITION_COMMAND))
            .thenReturn(CommandResponseEnum.SET_POSITION_RESPONSE);
        Command command = mock(Command.class);
        when(m_CommandConverterService.getJavaCommandType(
                Mockito.any(byte[].class), eq(CommandTypeEnum.SET_POSITION_COMMAND)))
            .thenReturn(command);
        Exception exception = new ObjectConverterException("Cannot Execute Command");
        when(m_Converter.convertToProto(Mockito.any(Command.class))).thenThrow(exception);
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_ResponseWrapper, timeout(2000)).queue(channel);
        verify(m_MessageFactory).createBaseErrorResponse(message, exception, 
                String.format("Unable to convert command response to " 
                        + "proto message for asset %s when executing command %s", asset.getName(), 
                        CommandTypeEnum.SET_POSITION_COMMAND));       
    }
@ Test public final void testObjectConverterExceptionExecuteCommand ( ) throws ObjectConverterException , IOException { final CommandType . Enum commandType = CommandTypeEnumConverter . convertJavaEnumToProto ( CommandTypeEnum . SET_POSITION_COMMAND ) ; SetPositionCommandGen . SetPositionCommand setPositionProto = SetPositionCommandGen . SetPositionCommand . newBuilder ( ) . setBase ( BaseTypesGen . Command . getDefaultInstance ( ) ) . build ( ) ; ExecuteCommandRequestData request = ExecuteCommandRequestData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) . setCommandType ( commandType ) . setCommand ( setPositionProto . toByteString ( ) ) . build ( ) ; AssetNamespace assetMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . ExecuteCommandRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetMessage ) ; TerraHarvestMessage message = createMessage ( assetMessage ) ; Asset asset = mock ( Asset . class ) ; when ( asset . getName ( ) ) . thenReturn ( "Name" ) ; when ( m_AssetDirectoryService . getAssetByUuid ( m_AssetUuid ) ) . thenReturn ( asset ) ; when ( m_CommandConverterService . getResponseTypeFromCommandType ( CommandTypeEnum . SET_POSITION_COMMAND ) ) . thenReturn ( CommandResponseEnum . SET_POSITION_RESPONSE ) ; Command command = mock ( Command . class ) ; when ( m_CommandConverterService . getJavaCommandType ( Mockito . any ( byte [ ] . class ) , eq ( CommandTypeEnum . SET_POSITION_COMMAND ) ) ) . thenReturn ( command ) ; Exception exception = new ObjectConverterException ( "Cannot Execute Command" ) ; when ( m_Converter . convertToProto ( Mockito . any ( Command . class ) ) ) . thenThrow ( exception ) ; when ( m_AssetDirectoryService . getAssetByUuid ( m_AssetUuid ) ) . thenReturn ( asset ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_ResponseWrapper , timeout ( 2000 ) ) . queue ( channel ) ; verify ( m_MessageFactory ) . createBaseErrorResponse ( message , exception , String . format ( "Unable to convert command response to " + "proto message for asset %s when executing command %s" , asset . getName ( ) , CommandTypeEnum . SET_POSITION_COMMAND ) ) ; }
Verify if a conversion exception occurs during a command response, an error response is sent instead.
Verify if a conversion exception occurs during a command response an error response is sent instead .
//Get the ordinal value of the command //Generate the proto command    //Generate the proto request data //Generate the namespace //Generate the TerraHarvest message //mock // mock the channel the message came from // replay