mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/mp/TestMissionProgrammingMessageService.java
@Test
    public void testGetProgramNames() throws IOException, ObjectConverterException, IllegalArgumentException, 
        PersistenceFailedException, InterruptedException, IllegalStateException, UnsupportedOperationException, 
           MissionProgramException
    {
        //activate the mission programming message service
        m_SUT.activate();
        
        //mock mission program manager behavior
        final Set<Program> programs = new HashSet<Program>();
        Program programA = mock(Program.class);
        when(programA.getProgramName()).thenReturn("a");
        programs.add(programA);
        Program programB = mock(Program.class);
        when(programB.getProgramName()).thenReturn("b");
        programs.add(programB);
        when(m_Manager.getPrograms()).thenReturn(programs);
        //create request
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
                setType(MissionProgrammingMessageType.GetProgramNamesRequest).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 contains the data message
        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.GetProgramNamesRequest.toString()));
        
        //verify the contents of the response
        ArgumentCaptor<GetProgramNamesResponseData> responseCaptor = 
                ArgumentCaptor.forClass(GetProgramNamesResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.GetProgramNamesResponse), responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        
        assertThat(responseCaptor.getValue().getMissionNameCount(), is(2));
        assertThat(responseCaptor.getValue().getMissionNameList(), hasItems("a", "b"));
    }
/**
     * Test that requesting to get program names that all expected names are returned.
     */
Test that requesting to get program names that all expected names are returned.
Test that requesting to get program names that all expected names are returned .
@Test
    public void testGetProgramNames() throws IOException, ObjectConverterException, IllegalArgumentException, 
        PersistenceFailedException, InterruptedException, IllegalStateException, UnsupportedOperationException, 
           MissionProgramException
    {
        m_SUT.activate();
        final Set<Program> programs = new HashSet<Program>();
        Program programA = mock(Program.class);
        when(programA.getProgramName()).thenReturn("a");
        programs.add(programA);
        Program programB = mock(Program.class);
        when(programB.getProgramName()).thenReturn("b");
        programs.add(programB);
        when(m_Manager.getPrograms()).thenReturn(programs);
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
                setType(MissionProgrammingMessageType.GetProgramNamesRequest).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.GetProgramNamesRequest.toString()));
        ArgumentCaptor<GetProgramNamesResponseData> responseCaptor = 
                ArgumentCaptor.forClass(GetProgramNamesResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.GetProgramNamesResponse), responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        assertThat(responseCaptor.getValue().getMissionNameCount(), is(2));
        assertThat(responseCaptor.getValue().getMissionNameList(), hasItems("a", "b"));
    }
@ Test public void testGetProgramNames ( ) throws IOException , ObjectConverterException , IllegalArgumentException , PersistenceFailedException , InterruptedException , IllegalStateException , UnsupportedOperationException , MissionProgramException { m_SUT . activate ( ) ; final Set < Program > programs = new HashSet < Program > ( ) ; Program programA = mock ( Program . class ) ; when ( programA . getProgramName ( ) ) . thenReturn ( "a" ) ; programs . add ( programA ) ; Program programB = mock ( Program . class ) ; when ( programB . getProgramName ( ) ) . thenReturn ( "b" ) ; programs . add ( programB ) ; when ( m_Manager . getPrograms ( ) ) . thenReturn ( programs ) ; MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace . newBuilder ( ) . setType ( MissionProgrammingMessageType . GetProgramNamesRequest ) . 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 . GetProgramNamesRequest . toString ( ) ) ) ; ArgumentCaptor < GetProgramNamesResponseData > responseCaptor = ArgumentCaptor . forClass ( GetProgramNamesResponseData . class ) ; verify ( m_MessageFactory ) . createMissionProgrammingResponseMessage ( eq ( message ) , eq ( MissionProgrammingMessageType . GetProgramNamesResponse ) , responseCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; assertThat ( responseCaptor . getValue ( ) . getMissionNameCount ( ) , is ( 2 ) ) ; assertThat ( responseCaptor . getValue ( ) . getMissionNameList ( ) , hasItems ( "a" , "b" ) ) ; }
Test that requesting to get program names that all expected names are returned.
Test that requesting to get program names that all expected names are returned .
//activate the mission programming message service //mock mission program manager behavior //create request // mock the channel the message came from // replay // verify the event contains the data message //verify the contents of the response