mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/asset/TestCommandHandlerMgrImpl.java
@SuppressWarnings("unchecked")
    @Test
    public void testSendCommandWithCommandInstance() throws ObjectConverterException
    {
        UUID assetUuid = UUID.randomUUID();
        
        Message testMessage = mock(Message.class);
        ByteString testByteString = ByteString.copyFrom(new byte[1024]);
        SetCameraSettingsCommand cameraSettingsCmnd = new SetCameraSettingsCommand(null, null, null, 0.5f, 0.5f,
                null, null, null, null, null);
        
        AzimuthDegrees pan = new AzimuthDegrees().withValue(0.2);
        ElevationDegrees tilt = new ElevationDegrees().withValue(0.2);
        OrientationOffset panTilt = new OrientationOffset(pan, tilt, null);
        SetPanTiltCommand panTiltCmd = new SetPanTiltCommand(null, null, panTilt);
        DetectTargetCommand detectTargetCmnd = new DetectTargetCommand(null, null, null, null, null, null, null,
                5, 5, 6, null);
        CaptureImageCommand captureImageCmd = new CaptureImageCommand(null, null, null, null, null, null, null, null,
                null);
        
        //Mock converter behavior.
        when(m_Converter.convertToProto(Mockito.any(Command.class))).thenReturn(testMessage);
        when(testMessage.toByteString()).thenReturn(testByteString);
        
        //Test sending the four known command types.
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, cameraSettingsCmnd, CommandTypeEnum.SET_CAMERA_SETTINGS_COMMAND);
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, panTiltCmd, CommandTypeEnum.SET_PAN_TILT_COMMAND);
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, detectTargetCmnd, CommandTypeEnum.DETECT_TARGET_COMMAND);
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, captureImageCmd, CommandTypeEnum.CAPTURE_IMAGE_COMMAND);
        
        //Capture messages being sent out by remote message sender.
        ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
        
        //Verify four messages were sent by the remote message sender, one for each command type.
        verify(m_MessageFactory, times(4)).createAssetMessage(eq(AssetMessageType.ExecuteCommandRequest), 
                messageCaptor.capture());
        verify(m_MessageWrapper, times(4)).queue(eq(CONTROLLER_ID), Mockito.any(ResponseHandler.class));
        
        ExecuteCommandRequestData msg = (ExecuteCommandRequestData)messageCaptor.getAllValues().get(0);
        assertThat(msg.getCommandType(), is(CommandTypesGen.CommandType.Enum.SET_CAMERA_SETTINGS_COMMAND));
        msg = (ExecuteCommandRequestData)messageCaptor.getAllValues().get(1);
        assertThat(msg.getCommandType(), is(CommandTypesGen.CommandType.Enum.SET_PAN_TILT_COMMAND));
        msg = (ExecuteCommandRequestData)messageCaptor.getAllValues().get(2);
        assertThat(msg.getCommandType(), is(CommandTypesGen.CommandType.Enum.DETECT_TARGET_COMMAND));
        msg = (ExecuteCommandRequestData)messageCaptor.getAllValues().get(3);
        assertThat(msg.getCommandType(), is(CommandTypesGen.CommandType.Enum.CAPTURE_IMAGE_COMMAND));
        
        //Test exception being thrown when converting command to a protocol message.
        when(m_Converter.convertToProto(Mockito.any(Command.class))).thenThrow(ObjectConverterException.class);
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, panTiltCmd, CommandTypeEnum.SET_PAN_TILT_COMMAND);
        
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_ERROR), eq("Asset Command Error:"), 
                eq("Unable to send " + panTiltCmd.getClass().getSimpleName().toString() + " command. See server "
                        + "log for futher details."), Mockito.any(ObjectConverterException.class));
    }
/**
     * Test the send command method.
     * Verify that the appropriate remote message is sent for a command.
     */
Test the send command method.
Verify that the appropriate remote message is sent for a command.
Test the send command method . Verify that the appropriate remote message is sent for a command .
@SuppressWarnings("unchecked")
    @Test
    public void testSendCommandWithCommandInstance() throws ObjectConverterException
    {
        UUID assetUuid = UUID.randomUUID();
        Message testMessage = mock(Message.class);
        ByteString testByteString = ByteString.copyFrom(new byte[1024]);
        SetCameraSettingsCommand cameraSettingsCmnd = new SetCameraSettingsCommand(null, null, null, 0.5f, 0.5f,
                null, null, null, null, null);
        AzimuthDegrees pan = new AzimuthDegrees().withValue(0.2);
        ElevationDegrees tilt = new ElevationDegrees().withValue(0.2);
        OrientationOffset panTilt = new OrientationOffset(pan, tilt, null);
        SetPanTiltCommand panTiltCmd = new SetPanTiltCommand(null, null, panTilt);
        DetectTargetCommand detectTargetCmnd = new DetectTargetCommand(null, null, null, null, null, null, null,
                5, 5, 6, null);
        CaptureImageCommand captureImageCmd = new CaptureImageCommand(null, null, null, null, null, null, null, null,
                null);
        when(m_Converter.convertToProto(Mockito.any(Command.class))).thenReturn(testMessage);
        when(testMessage.toByteString()).thenReturn(testByteString);
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, cameraSettingsCmnd, CommandTypeEnum.SET_CAMERA_SETTINGS_COMMAND);
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, panTiltCmd, CommandTypeEnum.SET_PAN_TILT_COMMAND);
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, detectTargetCmnd, CommandTypeEnum.DETECT_TARGET_COMMAND);
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, captureImageCmd, CommandTypeEnum.CAPTURE_IMAGE_COMMAND);
        ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
        verify(m_MessageFactory, times(4)).createAssetMessage(eq(AssetMessageType.ExecuteCommandRequest), 
                messageCaptor.capture());
        verify(m_MessageWrapper, times(4)).queue(eq(CONTROLLER_ID), Mockito.any(ResponseHandler.class));
        ExecuteCommandRequestData msg = (ExecuteCommandRequestData)messageCaptor.getAllValues().get(0);
        assertThat(msg.getCommandType(), is(CommandTypesGen.CommandType.Enum.SET_CAMERA_SETTINGS_COMMAND));
        msg = (ExecuteCommandRequestData)messageCaptor.getAllValues().get(1);
        assertThat(msg.getCommandType(), is(CommandTypesGen.CommandType.Enum.SET_PAN_TILT_COMMAND));
        msg = (ExecuteCommandRequestData)messageCaptor.getAllValues().get(2);
        assertThat(msg.getCommandType(), is(CommandTypesGen.CommandType.Enum.DETECT_TARGET_COMMAND));
        msg = (ExecuteCommandRequestData)messageCaptor.getAllValues().get(3);
        assertThat(msg.getCommandType(), is(CommandTypesGen.CommandType.Enum.CAPTURE_IMAGE_COMMAND));
        when(m_Converter.convertToProto(Mockito.any(Command.class))).thenThrow(ObjectConverterException.class);
        m_SUT.sendCommand(CONTROLLER_ID, assetUuid, panTiltCmd, CommandTypeEnum.SET_PAN_TILT_COMMAND);
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_ERROR), eq("Asset Command Error:"), 
                eq("Unable to send " + panTiltCmd.getClass().getSimpleName().toString() + " command. See server "
                        + "log for futher details."), Mockito.any(ObjectConverterException.class));
    }
@ SuppressWarnings ( "unchecked" ) @ Test public void testSendCommandWithCommandInstance ( ) throws ObjectConverterException { UUID assetUuid = UUID . randomUUID ( ) ; Message testMessage = mock ( Message . class ) ; ByteString testByteString = ByteString . copyFrom ( new byte [ 1024 ] ) ; SetCameraSettingsCommand cameraSettingsCmnd = new SetCameraSettingsCommand ( null , null , null , 0.5f , 0.5f , null , null , null , null , null ) ; AzimuthDegrees pan = new AzimuthDegrees ( ) . withValue ( 0.2 ) ; ElevationDegrees tilt = new ElevationDegrees ( ) . withValue ( 0.2 ) ; OrientationOffset panTilt = new OrientationOffset ( pan , tilt , null ) ; SetPanTiltCommand panTiltCmd = new SetPanTiltCommand ( null , null , panTilt ) ; DetectTargetCommand detectTargetCmnd = new DetectTargetCommand ( null , null , null , null , null , null , null , 5 , 5 , 6 , null ) ; CaptureImageCommand captureImageCmd = new CaptureImageCommand ( null , null , null , null , null , null , null , null , null ) ; when ( m_Converter . convertToProto ( Mockito . any ( Command . class ) ) ) . thenReturn ( testMessage ) ; when ( testMessage . toByteString ( ) ) . thenReturn ( testByteString ) ; m_SUT . sendCommand ( CONTROLLER_ID , assetUuid , cameraSettingsCmnd , CommandTypeEnum . SET_CAMERA_SETTINGS_COMMAND ) ; m_SUT . sendCommand ( CONTROLLER_ID , assetUuid , panTiltCmd , CommandTypeEnum . SET_PAN_TILT_COMMAND ) ; m_SUT . sendCommand ( CONTROLLER_ID , assetUuid , detectTargetCmnd , CommandTypeEnum . DETECT_TARGET_COMMAND ) ; m_SUT . sendCommand ( CONTROLLER_ID , assetUuid , captureImageCmd , CommandTypeEnum . CAPTURE_IMAGE_COMMAND ) ; ArgumentCaptor < Message > messageCaptor = ArgumentCaptor . forClass ( Message . class ) ; verify ( m_MessageFactory , times ( 4 ) ) . createAssetMessage ( eq ( AssetMessageType . ExecuteCommandRequest ) , messageCaptor . capture ( ) ) ; verify ( m_MessageWrapper , times ( 4 ) ) . queue ( eq ( CONTROLLER_ID ) , Mockito . any ( ResponseHandler . class ) ) ; ExecuteCommandRequestData msg = ( ExecuteCommandRequestData ) messageCaptor . getAllValues ( ) . get ( 0 ) ; assertThat ( msg . getCommandType ( ) , is ( CommandTypesGen . CommandType . Enum . SET_CAMERA_SETTINGS_COMMAND ) ) ; msg = ( ExecuteCommandRequestData ) messageCaptor . getAllValues ( ) . get ( 1 ) ; assertThat ( msg . getCommandType ( ) , is ( CommandTypesGen . CommandType . Enum . SET_PAN_TILT_COMMAND ) ) ; msg = ( ExecuteCommandRequestData ) messageCaptor . getAllValues ( ) . get ( 2 ) ; assertThat ( msg . getCommandType ( ) , is ( CommandTypesGen . CommandType . Enum . DETECT_TARGET_COMMAND ) ) ; msg = ( ExecuteCommandRequestData ) messageCaptor . getAllValues ( ) . get ( 3 ) ; assertThat ( msg . getCommandType ( ) , is ( CommandTypesGen . CommandType . Enum . CAPTURE_IMAGE_COMMAND ) ) ; when ( m_Converter . convertToProto ( Mockito . any ( Command . class ) ) ) . thenThrow ( ObjectConverterException . class ) ; m_SUT . sendCommand ( CONTROLLER_ID , assetUuid , panTiltCmd , CommandTypeEnum . SET_PAN_TILT_COMMAND ) ; verify ( m_GrowlUtil ) . createLocalFacesMessage ( eq ( FacesMessage . SEVERITY_ERROR ) , eq ( "Asset Command Error:" ) , eq ( "Unable to send " + panTiltCmd . getClass ( ) . getSimpleName ( ) . toString ( ) + " command. See server " + "log for futher details." ) , Mockito . any ( ObjectConverterException . class ) ) ; }
Test the send command method.
Test the send command method .
//Mock converter behavior. //Test sending the four known command types. //Capture messages being sent out by remote message sender. //Verify four messages were sent by the remote message sender, one for each command type. //Test exception being thrown when converting command to a protocol message.