mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/mp/TestMissionLoadSelected.java
@Test
    public void testLocalLoadMission() throws ObjectConverterException
    {
        //schedule
        MissionProgramSchedule schedule = getSchedule();
        //mock mission model
        MissionModel model = getModelA();
        
        //mock mission manager behavior
        when(m_MissionManager.getMission()).thenReturn(model);
        when(m_MissionManager.getSchedule()).thenReturn(schedule);
        when(m_MissionManager.getProgramName()).thenReturn("name");
        
        //mock controller
        ControllerModel controller = mock(ControllerModel.class);
        when(controller.getId()).thenReturn(123);
        //mock active controller
        when(m_ActiveController.isActiveControllerSet()).thenReturn(true);
        when(m_ActiveController.getActiveController()).thenReturn(controller);
        
        //template representing the model
        MissionProgramTemplate template = getTemplate();
        //mock template program manager behavior
        when(m_TemplateManager.getTemplate(model.getName())).thenReturn(template);
        
        //template proto message
        Message templateGen = MissionProgramTemplateGen.
            MissionProgramTemplate.newBuilder().
            setName("IamATest").
            setSource("TheSource!@@#(*&$^%_@##$").build();
        
        //parameters proto message
        MissionProgramParametersGen.MissionProgramSchedule genSched = 
            MissionProgramParametersGen.MissionProgramSchedule.
            newBuilder().
            setActive(false).
            setAtReset(true).
            setImmediately(true).
            setIndefiniteInterval(true).build();
        Multitype value = Multitype.newBuilder().setStringValue("Money").setType(Type.STRING).build();
        MapEntry entry = MapEntry.newBuilder().setKey("Currency").setValue(value).build();
        MissionProgramParametersGen.MissionProgramParameters parametersGen = 
            MissionProgramParametersGen.MissionProgramParameters.newBuilder().
                addParameters(entry). 
                setSchedule(genSched).
                setProgramName("name").
                setTemplateName("Bueller").build();        
        //mock converters behavior
        when(m_Converter.convertToProto(Mockito.any())).thenReturn(templateGen, parametersGen);
        
        //try to load mock mission, capture string returned
        String outcome = m_SUT.loadMission();
        //verify growl 'success' message
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(), 
            Mockito.anyString());
        
        //verify template
        ArgumentCaptor<Message> templateCaptor = ArgumentCaptor.
                forClass(Message.class);

        verify(m_MissionProgMgr).queueMessage(eq(123), templateCaptor.capture(), 
                eq(MissionProgrammingMessageType.LoadTemplateRequest));

        LoadTemplateRequestData data = (LoadTemplateRequestData)templateCaptor.getValue();

        assertThat(data.getMission(), is(templateGen));

        //verify parameters
        ArgumentCaptor<Message> paramCaptor = ArgumentCaptor.
                forClass(Message.class);
        verify(m_MissionProgMgr).queueMessage(
                eq(123), paramCaptor.capture(), eq(MissionProgrammingMessageType.LoadParametersRequest));
        
        assertThat(((LoadParametersRequestData)paramCaptor.getValue()).getParameters(), is(parametersGen));
        
        //verify outcome
        assertThat(outcome, is(""));
    }
/**
     * Test loading a local mission.
     * 
     * Verify message sender sends template.
     * 
     * Verify message sender sends parameters.
     */
Test loading a local mission.

Verify message sender sends template.

Verify message sender sends parameters.
Test loading a local mission . Verify message sender sends template . Verify message sender sends parameters .
@Test
    public void testLocalLoadMission() throws ObjectConverterException
    {
        MissionProgramSchedule schedule = getSchedule();
        MissionModel model = getModelA();
        when(m_MissionManager.getMission()).thenReturn(model);
        when(m_MissionManager.getSchedule()).thenReturn(schedule);
        when(m_MissionManager.getProgramName()).thenReturn("name");
        ControllerModel controller = mock(ControllerModel.class);
        when(controller.getId()).thenReturn(123);
        when(m_ActiveController.isActiveControllerSet()).thenReturn(true);
        when(m_ActiveController.getActiveController()).thenReturn(controller);
        MissionProgramTemplate template = getTemplate();
        when(m_TemplateManager.getTemplate(model.getName())).thenReturn(template);
        Message templateGen = MissionProgramTemplateGen.
            MissionProgramTemplate.newBuilder().
            setName("IamATest").
            setSource("TheSource!@@#(*&$^%_@##$").build();
        MissionProgramParametersGen.MissionProgramSchedule genSched = 
            MissionProgramParametersGen.MissionProgramSchedule.
            newBuilder().
            setActive(false).
            setAtReset(true).
            setImmediately(true).
            setIndefiniteInterval(true).build();
        Multitype value = Multitype.newBuilder().setStringValue("Money").setType(Type.STRING).build();
        MapEntry entry = MapEntry.newBuilder().setKey("Currency").setValue(value).build();
        MissionProgramParametersGen.MissionProgramParameters parametersGen = 
            MissionProgramParametersGen.MissionProgramParameters.newBuilder().
                addParameters(entry). 
                setSchedule(genSched).
                setProgramName("name").
                setTemplateName("Bueller").build();        
        when(m_Converter.convertToProto(Mockito.any())).thenReturn(templateGen, parametersGen);
        String outcome = m_SUT.loadMission();
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(), 
            Mockito.anyString());
        ArgumentCaptor<Message> templateCaptor = ArgumentCaptor.
                forClass(Message.class);
        verify(m_MissionProgMgr).queueMessage(eq(123), templateCaptor.capture(), 
                eq(MissionProgrammingMessageType.LoadTemplateRequest));
        LoadTemplateRequestData data = (LoadTemplateRequestData)templateCaptor.getValue();
        assertThat(data.getMission(), is(templateGen));
        ArgumentCaptor<Message> paramCaptor = ArgumentCaptor.
                forClass(Message.class);
        verify(m_MissionProgMgr).queueMessage(
                eq(123), paramCaptor.capture(), eq(MissionProgrammingMessageType.LoadParametersRequest));
        assertThat(((LoadParametersRequestData)paramCaptor.getValue()).getParameters(), is(parametersGen));
        assertThat(outcome, is(""));
    }
@ Test public void testLocalLoadMission ( ) throws ObjectConverterException { MissionProgramSchedule schedule = getSchedule ( ) ; MissionModel model = getModelA ( ) ; when ( m_MissionManager . getMission ( ) ) . thenReturn ( model ) ; when ( m_MissionManager . getSchedule ( ) ) . thenReturn ( schedule ) ; when ( m_MissionManager . getProgramName ( ) ) . thenReturn ( "name" ) ; ControllerModel controller = mock ( ControllerModel . class ) ; when ( controller . getId ( ) ) . thenReturn ( 123 ) ; when ( m_ActiveController . isActiveControllerSet ( ) ) . thenReturn ( true ) ; when ( m_ActiveController . getActiveController ( ) ) . thenReturn ( controller ) ; MissionProgramTemplate template = getTemplate ( ) ; when ( m_TemplateManager . getTemplate ( model . getName ( ) ) ) . thenReturn ( template ) ; Message templateGen = MissionProgramTemplateGen . MissionProgramTemplate . newBuilder ( ) . setName ( "IamATest" ) . setSource ( "TheSource!@@#(*&$^%_@##$" ) . build ( ) ; MissionProgramParametersGen . MissionProgramSchedule genSched = MissionProgramParametersGen . MissionProgramSchedule . newBuilder ( ) . setActive ( false ) . setAtReset ( true ) . setImmediately ( true ) . setIndefiniteInterval ( true ) . build ( ) ; Multitype value = Multitype . newBuilder ( ) . setStringValue ( "Money" ) . setType ( Type . STRING ) . build ( ) ; MapEntry entry = MapEntry . newBuilder ( ) . setKey ( "Currency" ) . setValue ( value ) . build ( ) ; MissionProgramParametersGen . MissionProgramParameters parametersGen = MissionProgramParametersGen . MissionProgramParameters . newBuilder ( ) . addParameters ( entry ) . setSchedule ( genSched ) . setProgramName ( "name" ) . setTemplateName ( "Bueller" ) . build ( ) ; when ( m_Converter . convertToProto ( Mockito . any ( ) ) ) . thenReturn ( templateGen , parametersGen ) ; String outcome = m_SUT . loadMission ( ) ; verify ( m_GrowlUtil ) . createLocalFacesMessage ( eq ( FacesMessage . SEVERITY_INFO ) , Mockito . anyString ( ) , Mockito . anyString ( ) ) ; ArgumentCaptor < Message > templateCaptor = ArgumentCaptor . forClass ( Message . class ) ; verify ( m_MissionProgMgr ) . queueMessage ( eq ( 123 ) , templateCaptor . capture ( ) , eq ( MissionProgrammingMessageType . LoadTemplateRequest ) ) ; LoadTemplateRequestData data = ( LoadTemplateRequestData ) templateCaptor . getValue ( ) ; assertThat ( data . getMission ( ) , is ( templateGen ) ) ; ArgumentCaptor < Message > paramCaptor = ArgumentCaptor . forClass ( Message . class ) ; verify ( m_MissionProgMgr ) . queueMessage ( eq ( 123 ) , paramCaptor . capture ( ) , eq ( MissionProgrammingMessageType . LoadParametersRequest ) ) ; assertThat ( ( ( LoadParametersRequestData ) paramCaptor . getValue ( ) ) . getParameters ( ) , is ( parametersGen ) ) ; assertThat ( outcome , is ( "" ) ) ; }
Test loading a local mission.
Test loading a local mission .
//schedule //mock mission model //mock mission manager behavior //mock controller //mock active controller //template representing the model //mock template program manager behavior //template proto message //parameters proto message //mock converters behavior //try to load mock mission, capture string returned //verify growl 'success' message //verify template //verify parameters //verify outcome