mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/mp/TestMissionProgrammingMessageService.java
@Test
    public void testSuccessGetTemplates() throws IllegalArgumentException, IOException, ObjectConverterException
    {
        //activate the mission programming message service
        m_SUT.activate();
        
        //construct the request for templates
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
            setType(MissionProgrammingMessageType.GetTemplatesRequest).build();
        TerraHarvestPayload payload = createPayload(missionMessage);
        TerraHarvestMessage message = createMissionProgrammingMessage(missionMessage);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        Set<MissionProgramTemplate> templates = getTemplatesSet();
        when(m_TemplateManager.getTemplates()).thenReturn(templates);
        
        //mock converter behavior
        MissionProgramTemplateGen.MissionProgramTemplate protoTemplate = MissionProgramTemplateGen.
            MissionProgramTemplate.newBuilder().setName("Name").setSource("Source").build();
        when(m_Converter.convertToProto(Mockito.any(MissionProgramTemplate.class))).
            thenReturn(protoTemplate);

        // replay
        m_SUT.handleMessage(message, payload, 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();
        //verify data message is null as there is not a data message for this request
        assertThat(event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE), is(nullValue()));

        //verify the interaction with the template manager
        verify(m_TemplateManager).getTemplates();
        //verfiy that the two templates in the mocked set are passed to the converter
        ArgumentCaptor<MissionProgramTemplate> templateCaptor = ArgumentCaptor.forClass(MissionProgramTemplate.class);
        verify(m_Converter, times(2)).convertToProto(templateCaptor.capture());
           
        // verify get templates response is sent
        ArgumentCaptor<GetTemplatesResponseData> messageCaptor = 
            ArgumentCaptor.forClass(GetTemplatesResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.GetTemplatesResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetTemplatesResponseData response = messageCaptor.getValue();
        //verify that two templates were made. Behavior is mocked..
        assertThat(response.getTemplateCount(), is(2));
        assertThat(response.getTemplateList(), hasItem(protoTemplate));
        assertThat(response.getTemplate(0).getName(), is("Name"));
        assertThat(response.getTemplate(0).getSource(), is("Source"));
    }
/**
     * Test request to get templates.
     * 
     * Verify that two templates are asked to be converted.
     * 
     * Verify that the response message is sent.
     */
Test request to get templates.

Verify that two templates are asked to be converted.

Verify that the response message is sent.
Test request to get templates . Verify that two templates are asked to be converted . Verify that the response message is sent .
@Test
    public void testSuccessGetTemplates() throws IllegalArgumentException, IOException, ObjectConverterException
    {
        m_SUT.activate();
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
            setType(MissionProgrammingMessageType.GetTemplatesRequest).build();
        TerraHarvestPayload payload = createPayload(missionMessage);
        TerraHarvestMessage message = createMissionProgrammingMessage(missionMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        Set<MissionProgramTemplate> templates = getTemplatesSet();
        when(m_TemplateManager.getTemplates()).thenReturn(templates);
        MissionProgramTemplateGen.MissionProgramTemplate protoTemplate = MissionProgramTemplateGen.
            MissionProgramTemplate.newBuilder().setName("Name").setSource("Source").build();
        when(m_Converter.convertToProto(Mockito.any(MissionProgramTemplate.class))).
            thenReturn(protoTemplate);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat(event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE), is(nullValue()));
        verify(m_TemplateManager).getTemplates();
        ArgumentCaptor<MissionProgramTemplate> templateCaptor = ArgumentCaptor.forClass(MissionProgramTemplate.class);
        verify(m_Converter, times(2)).convertToProto(templateCaptor.capture());
        ArgumentCaptor<GetTemplatesResponseData> messageCaptor = 
            ArgumentCaptor.forClass(GetTemplatesResponseData.class);
        verify(m_MessageFactory).createMissionProgrammingResponseMessage(eq(message), 
                eq(MissionProgrammingMessageType.GetTemplatesResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetTemplatesResponseData response = messageCaptor.getValue();
        assertThat(response.getTemplateCount(), is(2));
        assertThat(response.getTemplateList(), hasItem(protoTemplate));
        assertThat(response.getTemplate(0).getName(), is("Name"));
        assertThat(response.getTemplate(0).getSource(), is("Source"));
    }
@ Test public void testSuccessGetTemplates ( ) throws IllegalArgumentException , IOException , ObjectConverterException { m_SUT . activate ( ) ; MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace . newBuilder ( ) . setType ( MissionProgrammingMessageType . GetTemplatesRequest ) . build ( ) ; TerraHarvestPayload payload = createPayload ( missionMessage ) ; TerraHarvestMessage message = createMissionProgrammingMessage ( missionMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; Set < MissionProgramTemplate > templates = getTemplatesSet ( ) ; when ( m_TemplateManager . getTemplates ( ) ) . thenReturn ( templates ) ; MissionProgramTemplateGen . MissionProgramTemplate protoTemplate = MissionProgramTemplateGen . MissionProgramTemplate . newBuilder ( ) . setName ( "Name" ) . setSource ( "Source" ) . build ( ) ; when ( m_Converter . convertToProto ( Mockito . any ( MissionProgramTemplate . class ) ) ) . thenReturn ( protoTemplate ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( nullValue ( ) ) ) ; verify ( m_TemplateManager ) . getTemplates ( ) ; ArgumentCaptor < MissionProgramTemplate > templateCaptor = ArgumentCaptor . forClass ( MissionProgramTemplate . class ) ; verify ( m_Converter , times ( 2 ) ) . convertToProto ( templateCaptor . capture ( ) ) ; ArgumentCaptor < GetTemplatesResponseData > messageCaptor = ArgumentCaptor . forClass ( GetTemplatesResponseData . class ) ; verify ( m_MessageFactory ) . createMissionProgrammingResponseMessage ( eq ( message ) , eq ( MissionProgrammingMessageType . GetTemplatesResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetTemplatesResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . getTemplateCount ( ) , is ( 2 ) ) ; assertThat ( response . getTemplateList ( ) , hasItem ( protoTemplate ) ) ; assertThat ( response . getTemplate ( 0 ) . getName ( ) , is ( "Name" ) ) ; assertThat ( response . getTemplate ( 0 ) . getSource ( ) , is ( "Source" ) ) ; }
Test request to get templates.
Test request to get templates .
//activate the mission programming message service //construct the request for templates // mock the channel the message came from //mock converter behavior // replay // verify the event contains the data message //verify data message is null as there is not a data message for this request //verify the interaction with the template manager //verfiy that the two templates in the mocked set are passed to the converter // verify get templates response is sent //verify that two templates were made. Behavior is mocked..