mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public void testCommandExecutionObjectConverterException() 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);
        
        when(m_CommandConverterService.getResponseTypeFromCommandType(CommandTypeEnum.SET_POSITION_COMMAND))
            .thenReturn(CommandResponseEnum.SET_POSITION_RESPONSE);
        
        Exception exception = new ObjectConverterException("");
        when(m_CommandConverterService.getJavaCommandType(Mockito.any(byte[].class), 
                    eq(CommandTypeEnum.SET_POSITION_COMMAND))).thenThrow(exception);
        
        //mock
        Asset asset = mock(Asset.class);
        when(asset.getUuid()).thenReturn(m_AssetUuid);
        when(asset.getName()).thenReturn("Name");
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        
        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_MessageFactory).createBaseErrorResponse(message, exception, String.format(
                "Unable to retrieve java command from execute request for asset %s. Cannot execute command %s.", 
                asset.getName(), CommandTypeEnum.SET_POSITION_COMMAND));
        verify(m_ResponseWrapper).queue(channel);
    }
/*
     * Verify that if an object converter exception occurs when trying to retrieve the java command 
     * then the exception is properly handled.
     */
Verify that if an object converter exception occurs when trying to retrieve the java command
then the exception is properly handled.
Verify that if an object converter exception occurs when trying to retrieve the java command then the exception is properly handled .
@Test
    public void testCommandExecutionObjectConverterException() 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);
        when(m_CommandConverterService.getResponseTypeFromCommandType(CommandTypeEnum.SET_POSITION_COMMAND))
            .thenReturn(CommandResponseEnum.SET_POSITION_RESPONSE);
        Exception exception = new ObjectConverterException("");
        when(m_CommandConverterService.getJavaCommandType(Mockito.any(byte[].class), 
                    eq(CommandTypeEnum.SET_POSITION_COMMAND))).thenThrow(exception);
        Asset asset = mock(Asset.class);
        when(asset.getUuid()).thenReturn(m_AssetUuid);
        when(asset.getName()).thenReturn("Name");
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorResponse(message, exception, String.format(
                "Unable to retrieve java command from execute request for asset %s. Cannot execute command %s.", 
                asset.getName(), CommandTypeEnum.SET_POSITION_COMMAND));
        verify(m_ResponseWrapper).queue(channel);
    }
@ Test public void testCommandExecutionObjectConverterException ( ) 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 ) ; when ( m_CommandConverterService . getResponseTypeFromCommandType ( CommandTypeEnum . SET_POSITION_COMMAND ) ) . thenReturn ( CommandResponseEnum . SET_POSITION_RESPONSE ) ; Exception exception = new ObjectConverterException ( "" ) ; when ( m_CommandConverterService . getJavaCommandType ( Mockito . any ( byte [ ] . class ) , eq ( CommandTypeEnum . SET_POSITION_COMMAND ) ) ) . thenThrow ( exception ) ; Asset asset = mock ( Asset . class ) ; when ( asset . getUuid ( ) ) . thenReturn ( m_AssetUuid ) ; when ( asset . getName ( ) ) . thenReturn ( "Name" ) ; when ( m_AssetDirectoryService . getAssetByUuid ( m_AssetUuid ) ) . thenReturn ( asset ) ; when ( m_AssetDirectoryService . getAssetByUuid ( m_AssetUuid ) ) . thenReturn ( asset ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorResponse ( message , exception , String . format ( "Unable to retrieve java command from execute request for asset %s. Cannot execute command %s." , asset . getName ( ) , CommandTypeEnum . SET_POSITION_COMMAND ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; }
Verify that if an object converter exception occurs when trying to retrieve the java command
 then the exception is properly handled.
Verify that if an object converter exception occurs when trying to retrieve the java command then the exception is properly handled .
//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