mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/mp/TestMissionProgrammingMessageService.java
@Test
    public void testMessageHandling() throws IllegalArgumentException, IOException, ObjectConverterException, 
        PersistenceFailedException
    {
        //activate the mission programming message service
        m_SUT.activate();
        //create a simple mission template to send
        MissionProgramTemplateGen.MissionProgramTemplate template = MissionProgramTemplateGen.MissionProgramTemplate.
            newBuilder().setName("IamATest").setSource("TheSource!@@#(*&$^%_@##$").build();
        //construct a message        
        LoadTemplateRequestData programMessage = MissionProgramMessages.LoadTemplateRequestData.newBuilder().
            setMission(template).build();
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
            setType(MissionProgrammingMessageType.LoadTemplateRequest).setData(programMessage.toByteString()).build();
        TerraHarvestPayload payload = createPayload(missionMessage);
        TerraHarvestMessage message = createMissionProgrammingMessage(missionMessage);
    
        //mocked converter behavior
        when(m_Converter.convertToJaxb(Mockito.any(Message.class))).
            thenReturn(mock(MissionProgramTemplate.class));
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // replay
        m_SUT.handleMessage(message, payload, channel);

        //verify mission program manager is interacted with
        verify(m_TemplateManager, times(1)).loadMissionTemplate(Mockito.any(MissionProgramTemplate.class));
        
        // verify event is posted
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(missionMessage.getType().toString()));
        assertThat((MissionProgrammingNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(missionMessage));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
    }
/**
     * Tests the message handling and event service response upon receiving a message.
     *   
     */
Tests the message handling and event service response upon receiving a message.
Tests the message handling and event service response upon receiving a message .
@Test
    public void testMessageHandling() throws IllegalArgumentException, IOException, ObjectConverterException, 
        PersistenceFailedException
    {
        m_SUT.activate();
        MissionProgramTemplateGen.MissionProgramTemplate template = MissionProgramTemplateGen.MissionProgramTemplate.
            newBuilder().setName("IamATest").setSource("TheSource!@@#(*&$^%_@##$").build();
        LoadTemplateRequestData programMessage = MissionProgramMessages.LoadTemplateRequestData.newBuilder().
            setMission(template).build();
        MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace.newBuilder().
            setType(MissionProgrammingMessageType.LoadTemplateRequest).setData(programMessage.toByteString()).build();
        TerraHarvestPayload payload = createPayload(missionMessage);
        TerraHarvestMessage message = createMissionProgrammingMessage(missionMessage);
        when(m_Converter.convertToJaxb(Mockito.any(Message.class))).
            thenReturn(mock(MissionProgramTemplate.class));
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_TemplateManager, times(1)).loadMissionTemplate(Mockito.any(MissionProgramTemplate.class));
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(missionMessage.getType().toString()));
        assertThat((MissionProgrammingNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(missionMessage));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
    }
@ Test public void testMessageHandling ( ) throws IllegalArgumentException , IOException , ObjectConverterException , PersistenceFailedException { m_SUT . activate ( ) ; MissionProgramTemplateGen . MissionProgramTemplate template = MissionProgramTemplateGen . MissionProgramTemplate . newBuilder ( ) . setName ( "IamATest" ) . setSource ( "TheSource!@@#(*&$^%_@##$" ) . build ( ) ; LoadTemplateRequestData programMessage = MissionProgramMessages . LoadTemplateRequestData . newBuilder ( ) . setMission ( template ) . build ( ) ; MissionProgrammingNamespace missionMessage = MissionProgrammingNamespace . newBuilder ( ) . setType ( MissionProgrammingMessageType . LoadTemplateRequest ) . setData ( programMessage . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( missionMessage ) ; TerraHarvestMessage message = createMissionProgrammingMessage ( missionMessage ) ; when ( m_Converter . convertToJaxb ( Mockito . any ( Message . class ) ) ) . thenReturn ( mock ( MissionProgramTemplate . class ) ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_TemplateManager , times ( 1 ) ) . loadMissionTemplate ( Mockito . any ( MissionProgramTemplate . class ) ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event postedEvent = eventCaptor . getValue ( ) ; assertThat ( postedEvent . getTopic ( ) , is ( RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ) ; assertThat ( ( TerraHarvestMessage ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE ) , is ( message ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( missionMessage . getType ( ) . toString ( ) ) ) ; assertThat ( ( MissionProgrammingNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( missionMessage ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; }
Tests the message handling and event service response upon receiving a message.
Tests the message handling and event service response upon receiving a message .
//activate the mission programming message service //create a simple mission template to send //construct a message         //mocked converter behavior // mock the channel the message came from // replay //verify mission program manager is interacted with // verify event is posted