mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/mp/TestMissionProgrammingMessageService.java
@Test
    public void testGetProgramStatus() throws IllegalArgumentException, IOException
    {
        //mock the program
        Program program = mock(Program.class);
        when(program.getProgramStatus()).thenReturn(ProgramStatus.SCRIPT_ERROR);
        when(program.getLastExecutionExceptionCause()).thenReturn("Random Exception");
        when(m_Manager.getProgram("man")).thenReturn(program);
        
        //request
        GetProgramStatusRequestData request = GetProgramStatusRequestData.newBuilder().setMissionName("man").build();
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
                setType(MissionProgrammingMessageType.GetProgramStatusRequest).
                setData(request.toByteString()).build();
        TerraHarvestMessage message = createMissionProgrammingMessage(missionMessage);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // replay
        m_SUT.handleMessage(message, createPayload(missionMessage), channel);
        
        // verify the event
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((String)event.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE),
                is(MissionProgrammingMessageType.GetProgramStatusRequest.toString()));
        assertThat((GetProgramStatusRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        
        ArgumentCaptor<GetProgramStatusResponseData> responseCaptor = 
                ArgumentCaptor.forClass(GetProgramStatusResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.GetProgramStatusResponse), responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        
        GetProgramStatusResponseData response = responseCaptor.getValue();
        assertThat(response.getMissionName(), is("man"));
        assertThat(response.getMissionStatus(), is(MissionStatus.SCRIPT_ERROR));
        assertThat(response.getException(), is("Random Exception"));
    }
/**
     * Test the handling of a request to get a programs status.
     * Verify event is posted when the message is received
     */
Test the handling of a request to get a programs status.
Verify event is posted when the message is received
Test the handling of a request to get a programs status . Verify event is posted when the message is received
@Test
    public void testGetProgramStatus() throws IllegalArgumentException, IOException
    {
        Program program = mock(Program.class);
        when(program.getProgramStatus()).thenReturn(ProgramStatus.SCRIPT_ERROR);
        when(program.getLastExecutionExceptionCause()).thenReturn("Random Exception");
        when(m_Manager.getProgram("man")).thenReturn(program);
        GetProgramStatusRequestData request = GetProgramStatusRequestData.newBuilder().setMissionName("man").build();
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
                setType(MissionProgrammingMessageType.GetProgramStatusRequest).
                setData(request.toByteString()).build();
        TerraHarvestMessage message = createMissionProgrammingMessage(missionMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, createPayload(missionMessage), channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((String)event.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE),
                is(MissionProgrammingMessageType.GetProgramStatusRequest.toString()));
        assertThat((GetProgramStatusRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<GetProgramStatusResponseData> responseCaptor = 
                ArgumentCaptor.forClass(GetProgramStatusResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.GetProgramStatusResponse), responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetProgramStatusResponseData response = responseCaptor.getValue();
        assertThat(response.getMissionName(), is("man"));
        assertThat(response.getMissionStatus(), is(MissionStatus.SCRIPT_ERROR));
        assertThat(response.getException(), is("Random Exception"));
    }
@ Test public void testGetProgramStatus ( ) throws IllegalArgumentException , IOException { Program program = mock ( Program . class ) ; when ( program . getProgramStatus ( ) ) . thenReturn ( ProgramStatus . SCRIPT_ERROR ) ; when ( program . getLastExecutionExceptionCause ( ) ) . thenReturn ( "Random Exception" ) ; when ( m_Manager . getProgram ( "man" ) ) . thenReturn ( program ) ; GetProgramStatusRequestData request = GetProgramStatusRequestData . newBuilder ( ) . setMissionName ( "man" ) . build ( ) ; MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace . newBuilder ( ) . setType ( MissionProgrammingMessageType . GetProgramStatusRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message = createMissionProgrammingMessage ( missionMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , createPayload ( missionMessage ) , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( String ) event . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( MissionProgrammingMessageType . GetProgramStatusRequest . toString ( ) ) ) ; assertThat ( ( GetProgramStatusRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < GetProgramStatusResponseData > responseCaptor = ArgumentCaptor . forClass ( GetProgramStatusResponseData . class ) ; verify ( m_MessageFactory ) . createMissionProgrammingResponseMessage ( eq ( message ) , eq ( MissionProgrammingMessageType . GetProgramStatusResponse ) , responseCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetProgramStatusResponseData response = responseCaptor . getValue ( ) ; assertThat ( response . getMissionName ( ) , is ( "man" ) ) ; assertThat ( response . getMissionStatus ( ) , is ( MissionStatus . SCRIPT_ERROR ) ) ; assertThat ( response . getException ( ) , is ( "Random Exception" ) ) ; }
Test the handling of a request to get a programs status.
Test the handling of a request to get a programs status .
//mock the program //request // mock the channel the message came from // replay // verify the event