mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public void testCommandExecutionThreadGenericExcpetion() 
        throws CommandExecutionException, ObjectConverterException, IOException, InterruptedException
    {
        //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);
        
        SetPositionCommand command = new SetPositionCommand();
        when(m_CommandConverterService.getJavaCommandType(Mockito.any(byte[].class), 
                    eq(CommandTypeEnum.SET_POSITION_COMMAND))).thenReturn(command);
        //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);
        
        RuntimeException exception = new RuntimeException();
        when(asset.executeCommand(command)).thenThrow(exception);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        verify(m_ResponseWrapper, timeout(5000)).queue(channel);
        verify(m_MessageFactory).createBaseErrorResponse(message, exception, 
                String.format("An exception occurred for asset %s while processing command %s.", 
                        asset.getName(), CommandTypeEnum.SET_POSITION_COMMAND));
    }
/**
     * Verify any other exception besides a CommandExecutionException and an ObjectConverterException
     * will be caught by the thread that executes the command.
     */
Verify any other exception besides a CommandExecutionException and an ObjectConverterException
will be caught by the thread that executes the command.
Verify any other exception besides a CommandExecutionException and an ObjectConverterException will be caught by the thread that executes the command .
@Test
    public void testCommandExecutionThreadGenericExcpetion() 
        throws CommandExecutionException, ObjectConverterException, IOException, InterruptedException
    {
        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);
        SetPositionCommand command = new SetPositionCommand();
        when(m_CommandConverterService.getJavaCommandType(Mockito.any(byte[].class), 
                    eq(CommandTypeEnum.SET_POSITION_COMMAND))).thenReturn(command);
        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);
        RuntimeException exception = new RuntimeException();
        when(asset.executeCommand(command)).thenThrow(exception);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_ResponseWrapper, timeout(5000)).queue(channel);
        verify(m_MessageFactory).createBaseErrorResponse(message, exception, 
                String.format("An exception occurred for asset %s while processing command %s.", 
                        asset.getName(), CommandTypeEnum.SET_POSITION_COMMAND));
    }
@ Test public void testCommandExecutionThreadGenericExcpetion ( ) throws CommandExecutionException , ObjectConverterException , IOException , InterruptedException { 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 ) ; SetPositionCommand command = new SetPositionCommand ( ) ; when ( m_CommandConverterService . getJavaCommandType ( Mockito . any ( byte [ ] . class ) , eq ( CommandTypeEnum . SET_POSITION_COMMAND ) ) ) . thenReturn ( command ) ; 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 ) ; RuntimeException exception = new RuntimeException ( ) ; when ( asset . executeCommand ( command ) ) . thenThrow ( exception ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_ResponseWrapper , timeout ( 5000 ) ) . queue ( channel ) ; verify ( m_MessageFactory ) . createBaseErrorResponse ( message , exception , String . format ( "An exception occurred for asset %s while processing command %s." , asset . getName ( ) , CommandTypeEnum . SET_POSITION_COMMAND ) ) ; }
Verify any other exception besides a CommandExecutionException and an ObjectConverterException
 will be caught by the thread that executes the command.
Verify any other exception besides a CommandExecutionException and an ObjectConverterException will be caught by the thread that executes the command .
//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