mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/mp/TestMissionProgrammingMessageService.java
@Test
    public void testGetProgramInfoEmptyList() throws IOException, ObjectConverterException, IllegalArgumentException, 
        PersistenceFailedException, InterruptedException, IllegalStateException, UnsupportedOperationException, 
           MissionProgramException
    {
        //activate the mission programming message service
        m_SUT.activate();
        
        //schdeules
        MissionProgramSchedule schedule = mock(MissionProgramSchedule.class);
        MissionProgramParametersGen.MissionProgramSchedule protoSched = 
                MissionProgramParametersGen.MissionProgramSchedule.
                newBuilder().setActive(true).setAtReset(false).setImmediately(true).setIndefiniteInterval(true).build();
        
        //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(schedule);
        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);
        
        //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 the event
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((GetProgramInformationRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(data));
        
        //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(2));
        
        for (ProgramInfo programInfo : responseMessage.getMissionInfoList())
        {
            if (programInfo.getMissionName().equals("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"));
            }
            else
            {
                assertThat(programInfo.getMissionName(), is("b"));
                assertThat(programInfo.getTemplateName(), is("another template name"));
                assertThat(programInfo.getMissionSchedule(), is(protoSched));
                assertThat(programInfo.getMissionStatus(), is(MissionStatus.SHUTDOWN));
                assertThat(programInfo.getExecutionParamCount(), is(2));
                assertThat(programInfo.getExecutionParamList().get(0).getKey(), isOneOf("linklayer", "physicalLink"));
                assertThat(programInfo.getExecutionParamList().get(0).getValue().getStringValue(), 
                        isOneOf("link", "phys"));
            }
        }
    }
/**
     * Test that requesting to get program information when there are no specific program's identified.
     * Verify all programs are returned.
     */
Test that requesting to get program information when there are no specific program's identified.
Verify all programs are returned.
Test that requesting to get program information when there are no specific program ' s identified . Verify all programs are returned .
@Test
    public void testGetProgramInfoEmptyList() 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();
        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(schedule);
        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);
        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<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((GetProgramInformationRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(data));
        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(2));
        for (ProgramInfo programInfo : responseMessage.getMissionInfoList())
        {
            if (programInfo.getMissionName().equals("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"));
            }
            else
            {
                assertThat(programInfo.getMissionName(), is("b"));
                assertThat(programInfo.getTemplateName(), is("another template name"));
                assertThat(programInfo.getMissionSchedule(), is(protoSched));
                assertThat(programInfo.getMissionStatus(), is(MissionStatus.SHUTDOWN));
                assertThat(programInfo.getExecutionParamCount(), is(2));
                assertThat(programInfo.getExecutionParamList().get(0).getKey(), isOneOf("linklayer", "physicalLink"));
                assertThat(programInfo.getExecutionParamList().get(0).getValue().getStringValue(), 
                        isOneOf("link", "phys"));
            }
        }
    }
@ Test public void testGetProgramInfoEmptyList ( ) 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 ( ) ; 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 ( schedule ) ; 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 ) ; 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 < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( GetProgramInformationRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( data ) ) ; 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 ( 2 ) ) ; for ( ProgramInfo programInfo : responseMessage . getMissionInfoList ( ) ) { if ( programInfo . getMissionName ( ) . equals ( "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" ) ) ; } else { assertThat ( programInfo . getMissionName ( ) , is ( "b" ) ) ; assertThat ( programInfo . getTemplateName ( ) , is ( "another template name" ) ) ; assertThat ( programInfo . getMissionSchedule ( ) , is ( protoSched ) ) ; assertThat ( programInfo . getMissionStatus ( ) , is ( MissionStatus . SHUTDOWN ) ) ; assertThat ( programInfo . getExecutionParamCount ( ) , is ( 2 ) ) ; assertThat ( programInfo . getExecutionParamList ( ) . get ( 0 ) . getKey ( ) , isOneOf ( "linklayer" , "physicalLink" ) ) ; assertThat ( programInfo . getExecutionParamList ( ) . get ( 0 ) . getValue ( ) . getStringValue ( ) , isOneOf ( "link" , "phys" ) ) ; } } }
Test that requesting to get program information when there are no specific program's identified.
Test that requesting to get program information when there are no specific program ' s identified .
//activate the mission programming message service //schdeules //execution params //mock mission program manager behavior //behaviors //create request // mock the channel the message came from // replay // verify the event //verify response //inspect the message