mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/mp/TestMissionProgrammingMessageService.java
@Test
    public void testGetProgramInfoEmptyListException() throws IOException, ObjectConverterException, 
        IllegalArgumentException, PersistenceFailedException, InterruptedException, IllegalStateException, 
        UnsupportedOperationException, MissionProgramException
    {
        //activate the mission programming message service
        m_SUT.activate();
        
        //schedules
        MissionProgramSchedule schedule = mock(MissionProgramSchedule.class);
        MissionProgramParametersGen.MissionProgramSchedule protoSched = 
                MissionProgramParametersGen.MissionProgramSchedule.
                newBuilder().setActive(true).setAtReset(false).setImmediately(true).setIndefiniteInterval(true).build();
        MissionProgramSchedule scheduleBad = mock(MissionProgramSchedule.class);
        
        //execution params
        Map<String, Object> paramsA = new HashMap<String, Object>();
        paramsA.put("asset", "asset");
        paramsA.put("physicalLink", "phys");
        Map<String, Object> paramsB = new HashMap<String, Object>();
        paramsB.put("linklayer", "link");
        paramsB.put("physicalLink", "phys");

        //mock mission program manager behavior
        Program programA = mock(Program.class);
        when(programA.getProgramName()).thenReturn("a");
        when(programA.getTemplateName()).thenReturn("a template Name");
        when(programA.getProgramStatus()).thenReturn(ProgramStatus.EXECUTED);
        when(programA.getMissionSchedule()).thenReturn(schedule);
        when(programA.getExecutionParameters()).thenReturn(paramsA);
        Program programB = mock(Program.class);
        when(programB.getProgramName()).thenReturn("b");
        when(programB.getProgramStatus()).thenReturn(ProgramStatus.SHUTDOWN);
        when(programB.getMissionSchedule()).thenReturn(scheduleBad);
        when(programB.getTemplateName()).thenReturn("another template name");
        when(programB.getExecutionParameters()).thenReturn(paramsB);
        
        Set<Program> programs = new HashSet<Program>();
        programs.add(programA);
        programs.add(programB);
        
        //behaviors
        when(m_Manager.getPrograms()).thenReturn(programs);
        when(m_Converter.convertToProto(schedule)).thenReturn(protoSched);
        when(m_Converter.convertToProto(scheduleBad)).thenThrow(new ObjectConverterException("Can't Convert"));
        
        //create request
        GetProgramInformationRequestData data = GetProgramInformationRequestData.newBuilder().build();
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
                setType(MissionProgrammingMessageType.GetProgramInformationRequest).
                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 response
        ArgumentCaptor<GetProgramInformationResponseData> responseCaptor = 
                ArgumentCaptor.forClass(GetProgramInformationResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.GetProgramInformationResponse), responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        
        //inspect the message
        GetProgramInformationResponseData responseMessage = responseCaptor.getValue();
        assertThat(responseMessage.getMissionInfoCount(), is(1));
        
        //expected values, for only one mission because the other one failed to convert
        ProgramInfo programInfo = responseMessage.getMissionInfo(0);
        assertThat(programInfo.getMissionName(), is("a"));
        assertThat(programInfo.getTemplateName(), is("a template Name"));
        assertThat(programInfo.getMissionSchedule(), is(protoSched));
        assertThat(programInfo.getMissionStatus(), is(MissionStatus.EXECUTED));
        assertThat(programInfo.getExecutionParamCount(), is(2));
        assertThat(programInfo.getExecutionParamList().get(0).getKey(), isOneOf("asset", "physicalLink"));
        assertThat(programInfo.getExecutionParamList().get(0).getValue().getStringValue(), 
                isOneOf("asset", "phys"));
    }
/**
     * Test that requesting to get program information when there are no specific program's identified, but the
     * schedule for a program cannot be converted.
     * Verify all programs are returned.
     */
Test that requesting to get program information when there are no specific program's identified, but the
schedule for a program cannot be converted.
Verify all programs are returned.
Test that requesting to get program information when there are no specific program ' s identified but the schedule for a program cannot be converted . Verify all programs are returned .
@Test
    public void testGetProgramInfoEmptyListException() throws IOException, ObjectConverterException, 
        IllegalArgumentException, PersistenceFailedException, InterruptedException, IllegalStateException, 
        UnsupportedOperationException, MissionProgramException
    {
        m_SUT.activate();
        MissionProgramSchedule schedule = mock(MissionProgramSchedule.class);
        MissionProgramParametersGen.MissionProgramSchedule protoSched = 
                MissionProgramParametersGen.MissionProgramSchedule.
                newBuilder().setActive(true).setAtReset(false).setImmediately(true).setIndefiniteInterval(true).build();
        MissionProgramSchedule scheduleBad = mock(MissionProgramSchedule.class);
        Map<String, Object> paramsA = new HashMap<String, Object>();
        paramsA.put("asset", "asset");
        paramsA.put("physicalLink", "phys");
        Map<String, Object> paramsB = new HashMap<String, Object>();
        paramsB.put("linklayer", "link");
        paramsB.put("physicalLink", "phys");
        Program programA = mock(Program.class);
        when(programA.getProgramName()).thenReturn("a");
        when(programA.getTemplateName()).thenReturn("a template Name");
        when(programA.getProgramStatus()).thenReturn(ProgramStatus.EXECUTED);
        when(programA.getMissionSchedule()).thenReturn(schedule);
        when(programA.getExecutionParameters()).thenReturn(paramsA);
        Program programB = mock(Program.class);
        when(programB.getProgramName()).thenReturn("b");
        when(programB.getProgramStatus()).thenReturn(ProgramStatus.SHUTDOWN);
        when(programB.getMissionSchedule()).thenReturn(scheduleBad);
        when(programB.getTemplateName()).thenReturn("another template name");
        when(programB.getExecutionParameters()).thenReturn(paramsB);
        Set<Program> programs = new HashSet<Program>();
        programs.add(programA);
        programs.add(programB);
        when(m_Manager.getPrograms()).thenReturn(programs);
        when(m_Converter.convertToProto(schedule)).thenReturn(protoSched);
        when(m_Converter.convertToProto(scheduleBad)).thenThrow(new ObjectConverterException("Can't Convert"));
        GetProgramInformationRequestData data = GetProgramInformationRequestData.newBuilder().build();
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
                setType(MissionProgrammingMessageType.GetProgramInformationRequest).
                setData(data.toByteString()).build();
        TerraHarvestMessage message = createMissionProgrammingMessage(missionMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, createPayload(missionMessage), channel);
        ArgumentCaptor<GetProgramInformationResponseData> responseCaptor = 
                ArgumentCaptor.forClass(GetProgramInformationResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.GetProgramInformationResponse), responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetProgramInformationResponseData responseMessage = responseCaptor.getValue();
        assertThat(responseMessage.getMissionInfoCount(), is(1));
        ProgramInfo programInfo = responseMessage.getMissionInfo(0);
        assertThat(programInfo.getMissionName(), is("a"));
        assertThat(programInfo.getTemplateName(), is("a template Name"));
        assertThat(programInfo.getMissionSchedule(), is(protoSched));
        assertThat(programInfo.getMissionStatus(), is(MissionStatus.EXECUTED));
        assertThat(programInfo.getExecutionParamCount(), is(2));
        assertThat(programInfo.getExecutionParamList().get(0).getKey(), isOneOf("asset", "physicalLink"));
        assertThat(programInfo.getExecutionParamList().get(0).getValue().getStringValue(), 
                isOneOf("asset", "phys"));
    }
@ Test public void testGetProgramInfoEmptyListException ( ) throws IOException , ObjectConverterException , IllegalArgumentException , PersistenceFailedException , InterruptedException , IllegalStateException , UnsupportedOperationException , MissionProgramException { m_SUT . activate ( ) ; MissionProgramSchedule schedule = mock ( MissionProgramSchedule . class ) ; MissionProgramParametersGen . MissionProgramSchedule protoSched = MissionProgramParametersGen . MissionProgramSchedule . newBuilder ( ) . setActive ( true ) . setAtReset ( false ) . setImmediately ( true ) . setIndefiniteInterval ( true ) . build ( ) ; MissionProgramSchedule scheduleBad = mock ( MissionProgramSchedule . class ) ; Map < String , Object > paramsA = new HashMap < String , Object > ( ) ; paramsA . put ( "asset" , "asset" ) ; paramsA . put ( "physicalLink" , "phys" ) ; Map < String , Object > paramsB = new HashMap < String , Object > ( ) ; paramsB . put ( "linklayer" , "link" ) ; paramsB . put ( "physicalLink" , "phys" ) ; Program programA = mock ( Program . class ) ; when ( programA . getProgramName ( ) ) . thenReturn ( "a" ) ; when ( programA . getTemplateName ( ) ) . thenReturn ( "a template Name" ) ; when ( programA . getProgramStatus ( ) ) . thenReturn ( ProgramStatus . EXECUTED ) ; when ( programA . getMissionSchedule ( ) ) . thenReturn ( schedule ) ; when ( programA . getExecutionParameters ( ) ) . thenReturn ( paramsA ) ; Program programB = mock ( Program . class ) ; when ( programB . getProgramName ( ) ) . thenReturn ( "b" ) ; when ( programB . getProgramStatus ( ) ) . thenReturn ( ProgramStatus . SHUTDOWN ) ; when ( programB . getMissionSchedule ( ) ) . thenReturn ( scheduleBad ) ; when ( programB . getTemplateName ( ) ) . thenReturn ( "another template name" ) ; when ( programB . getExecutionParameters ( ) ) . thenReturn ( paramsB ) ; Set < Program > programs = new HashSet < Program > ( ) ; programs . add ( programA ) ; programs . add ( programB ) ; when ( m_Manager . getPrograms ( ) ) . thenReturn ( programs ) ; when ( m_Converter . convertToProto ( schedule ) ) . thenReturn ( protoSched ) ; when ( m_Converter . convertToProto ( scheduleBad ) ) . thenThrow ( new ObjectConverterException ( "Can't Convert" ) ) ; GetProgramInformationRequestData data = GetProgramInformationRequestData . newBuilder ( ) . build ( ) ; MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace . newBuilder ( ) . setType ( MissionProgrammingMessageType . GetProgramInformationRequest ) . setData ( data . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message = createMissionProgrammingMessage ( missionMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , createPayload ( missionMessage ) , channel ) ; ArgumentCaptor < GetProgramInformationResponseData > responseCaptor = ArgumentCaptor . forClass ( GetProgramInformationResponseData . class ) ; verify ( m_MessageFactory ) . createMissionProgrammingResponseMessage ( eq ( message ) , eq ( MissionProgrammingMessageType . GetProgramInformationResponse ) , responseCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetProgramInformationResponseData responseMessage = responseCaptor . getValue ( ) ; assertThat ( responseMessage . getMissionInfoCount ( ) , is ( 1 ) ) ; ProgramInfo programInfo = responseMessage . getMissionInfo ( 0 ) ; assertThat ( programInfo . getMissionName ( ) , is ( "a" ) ) ; assertThat ( programInfo . getTemplateName ( ) , is ( "a template Name" ) ) ; assertThat ( programInfo . getMissionSchedule ( ) , is ( protoSched ) ) ; assertThat ( programInfo . getMissionStatus ( ) , is ( MissionStatus . EXECUTED ) ) ; assertThat ( programInfo . getExecutionParamCount ( ) , is ( 2 ) ) ; assertThat ( programInfo . getExecutionParamList ( ) . get ( 0 ) . getKey ( ) , isOneOf ( "asset" , "physicalLink" ) ) ; assertThat ( programInfo . getExecutionParamList ( ) . get ( 0 ) . getValue ( ) . getStringValue ( ) , isOneOf ( "asset" , "phys" ) ) ; }
Test that requesting to get program information when there are no specific program's identified, but the
 schedule for a program cannot be converted.
Test that requesting to get program information when there are no specific program ' s identified but the schedule for a program cannot be converted .
//activate the mission programming message service //schedules //execution params //mock mission program manager behavior //behaviors //create request // mock the channel the message came from // replay //verify response //inspect the message //expected values, for only one mission because the other one failed to convert