mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/mp/TestMissionProgrammingMessageService.java
@Test
    public void testCancelPrograms() throws IOException, ObjectConverterException, IllegalArgumentException, 
        PersistenceFailedException, InterruptedException, IllegalStateException, UnsupportedOperationException, 
           MissionProgramException
    {
        //activate the mission programming message service
        m_SUT.activate();
        
        //mock mission program manager behavior
        Program program = mock(Program.class);
        when(program.getProgramName()).thenReturn("a");
        when(program.getProgramStatus()).thenReturn(ProgramStatus.CANCELED);
        when(m_Manager.getProgram("a")).thenReturn(program);
        
        //create request
        CancelProgramRequestData data = CancelProgramRequestData.newBuilder().
                setMissionName("a").build();
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
                setType(MissionProgrammingMessageType.CancelProgramRequest).
                setData(data.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.CancelProgramRequest.toString()));
        
        //verify response
        ArgumentCaptor<CancelProgramResponseData> messageCaptor = 
                ArgumentCaptor.forClass(CancelProgramResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.CancelProgramResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        
        CancelProgramResponseData responseData = messageCaptor.getValue();
        assertThat(responseData.getMissionName(), is("a"));
        assertThat(responseData.getMissionStatus(), is(MissionStatus.CANCELED));
        
    }
/**
     * Test requesting to cancel a program.
     * Verify correct program is canceled.
     */
Test requesting to cancel a program.
Verify correct program is canceled.
Test requesting to cancel a program . Verify correct program is canceled .
@Test
    public void testCancelPrograms() throws IOException, ObjectConverterException, IllegalArgumentException, 
        PersistenceFailedException, InterruptedException, IllegalStateException, UnsupportedOperationException, 
           MissionProgramException
    {
        m_SUT.activate();
        Program program = mock(Program.class);
        when(program.getProgramName()).thenReturn("a");
        when(program.getProgramStatus()).thenReturn(ProgramStatus.CANCELED);
        when(m_Manager.getProgram("a")).thenReturn(program);
        CancelProgramRequestData data = CancelProgramRequestData.newBuilder().
                setMissionName("a").build();
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
                setType(MissionProgrammingMessageType.CancelProgramRequest).
                setData(data.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.CancelProgramRequest.toString()));
        ArgumentCaptor<CancelProgramResponseData> messageCaptor = 
                ArgumentCaptor.forClass(CancelProgramResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.CancelProgramResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        CancelProgramResponseData responseData = messageCaptor.getValue();
        assertThat(responseData.getMissionName(), is("a"));
        assertThat(responseData.getMissionStatus(), is(MissionStatus.CANCELED));
    }
@ Test public void testCancelPrograms ( ) throws IOException , ObjectConverterException , IllegalArgumentException , PersistenceFailedException , InterruptedException , IllegalStateException , UnsupportedOperationException , MissionProgramException { m_SUT . activate ( ) ; Program program = mock ( Program . class ) ; when ( program . getProgramName ( ) ) . thenReturn ( "a" ) ; when ( program . getProgramStatus ( ) ) . thenReturn ( ProgramStatus . CANCELED ) ; when ( m_Manager . getProgram ( "a" ) ) . thenReturn ( program ) ; CancelProgramRequestData data = CancelProgramRequestData . newBuilder ( ) . setMissionName ( "a" ) . build ( ) ; MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace . newBuilder ( ) . setType ( MissionProgrammingMessageType . CancelProgramRequest ) . setData ( data . 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 . CancelProgramRequest . toString ( ) ) ) ; ArgumentCaptor < CancelProgramResponseData > messageCaptor = ArgumentCaptor . forClass ( CancelProgramResponseData . class ) ; verify ( m_MessageFactory ) . createMissionProgrammingResponseMessage ( eq ( message ) , eq ( MissionProgrammingMessageType . CancelProgramResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; CancelProgramResponseData responseData = messageCaptor . getValue ( ) ; assertThat ( responseData . getMissionName ( ) , is ( "a" ) ) ; assertThat ( responseData . getMissionStatus ( ) , is ( MissionStatus . CANCELED ) ) ; }
Test requesting to cancel a program.
Test requesting to cancel a program .
//activate the mission programming message service //mock mission program manager behavior //create request // mock the channel the message came from // replay // verify the event //verify response