mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramManagerImpl.java
@Test
    public void testRemoveProgramExecuted() 
        throws IllegalArgumentException, PersistenceFailedException, MissionProgramException
    {
        mockMissionProgramPersistentData();
        List<PersistentData> missionPrograms = new ArrayList<PersistentData>();
        doReturn(missionPrograms).when(m_PersistentDataStore).query(MissionProgramManagerImpl.class);
        // mock
        setScriptEngineAndActivate();
        
        // verify
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(0));
        
        //program to add       
        MissionProgramTemplate program = new MissionProgramTemplate().withName("blah").withSource("test");
        MissionProgramSchedule schedule = new MissionProgramSchedule().withImmediately(false).
            withIndefiniteInterval(false).withActive(true);
        MissionProgramParameters params = new MissionProgramParameters().withParameters().withTemplateName("blah").
            withSchedule(schedule).withProgramName("namerrrr");
        
        //add template
        Set<String> templateNames = new HashSet<String>();
        templateNames.add("blah");
        when(m_TemplateManager.getMissionTemplateNames()).thenReturn(templateNames);
        doReturn(program).when(m_TemplateManager).getTemplate("blah");        
        
        //add params and schedule
        Program blahProgram = m_SUT.loadParameters(params);
        
       //need to capture uuid so that it can be used during the removeProgram verification
        ArgumentCaptor<UUID> uuid = ArgumentCaptor.forClass(UUID.class);
        verify(m_PersistentDataStore, times(1)).persist(eq(MissionProgramManagerImpl.class), uuid.capture(),
                anyString(), (Serializable)Mockito.any());
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(1));
        
        ((ProgramImpl)blahProgram).changeStatus(ProgramStatus.CANCELED);

        //try to remove 
        m_SUT.removeProgram(blahProgram, uuid.getValue());
        //verify still removed
        assertThat(m_SUT.getActiveProgramsUsingTemplate("blah").size(), is(0));
        
        //verify exception if attempted to remove again
        try
        {
            //try to remove the program again. 
            m_SUT.removeProgram(blahProgram, uuid.getValue());
            fail("Expected exception the program was already removed.");
        }
        catch (IllegalArgumentException e)
        {
            //expecting exception
        }
    }
/**
     * Test removing a mission program.
     * Verify if executed that shutdown is called because the program is executed.
     */
Test removing a mission program.
Verify if executed that shutdown is called because the program is executed.
Test removing a mission program . Verify if executed that shutdown is called because the program is executed .
@Test
    public void testRemoveProgramExecuted() 
        throws IllegalArgumentException, PersistenceFailedException, MissionProgramException
    {
        mockMissionProgramPersistentData();
        List<PersistentData> missionPrograms = new ArrayList<PersistentData>();
        doReturn(missionPrograms).when(m_PersistentDataStore).query(MissionProgramManagerImpl.class);
        setScriptEngineAndActivate();
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(0));
        MissionProgramTemplate program = new MissionProgramTemplate().withName("blah").withSource("test");
        MissionProgramSchedule schedule = new MissionProgramSchedule().withImmediately(false).
            withIndefiniteInterval(false).withActive(true);
        MissionProgramParameters params = new MissionProgramParameters().withParameters().withTemplateName("blah").
            withSchedule(schedule).withProgramName("namerrrr");
        Set<String> templateNames = new HashSet<String>();
        templateNames.add("blah");
        when(m_TemplateManager.getMissionTemplateNames()).thenReturn(templateNames);
        doReturn(program).when(m_TemplateManager).getTemplate("blah");        
        Program blahProgram = m_SUT.loadParameters(params);
        ArgumentCaptor<UUID> uuid = ArgumentCaptor.forClass(UUID.class);
        verify(m_PersistentDataStore, times(1)).persist(eq(MissionProgramManagerImpl.class), uuid.capture(),
                anyString(), (Serializable)Mockito.any());
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(1));
        ((ProgramImpl)blahProgram).changeStatus(ProgramStatus.CANCELED);
        m_SUT.removeProgram(blahProgram, uuid.getValue());
        assertThat(m_SUT.getActiveProgramsUsingTemplate("blah").size(), is(0));
        try
        {
            the program again. 
            m_SUT.removeProgram(blahProgram, uuid.getValue());
            fail("Expected exception the program was already removed.");
        }
        catch (IllegalArgumentException e)
        {
        }
    }
@ Test public void testRemoveProgramExecuted ( ) throws IllegalArgumentException , PersistenceFailedException , MissionProgramException { mockMissionProgramPersistentData ( ) ; List < PersistentData > missionPrograms = new ArrayList < PersistentData > ( ) ; doReturn ( missionPrograms ) . when ( m_PersistentDataStore ) . query ( MissionProgramManagerImpl . class ) ; setScriptEngineAndActivate ( ) ; assertThat ( m_SUT . getActiveProgramTemplateNames ( ) . size ( ) , is ( 0 ) ) ; MissionProgramTemplate program = new MissionProgramTemplate ( ) . withName ( "blah" ) . withSource ( "test" ) ; MissionProgramSchedule schedule = new MissionProgramSchedule ( ) . withImmediately ( false ) . withIndefiniteInterval ( false ) . withActive ( true ) ; MissionProgramParameters params = new MissionProgramParameters ( ) . withParameters ( ) . withTemplateName ( "blah" ) . withSchedule ( schedule ) . withProgramName ( "namerrrr" ) ; Set < String > templateNames = new HashSet < String > ( ) ; templateNames . add ( "blah" ) ; when ( m_TemplateManager . getMissionTemplateNames ( ) ) . thenReturn ( templateNames ) ; doReturn ( program ) . when ( m_TemplateManager ) . getTemplate ( "blah" ) ; Program blahProgram = m_SUT . loadParameters ( params ) ; ArgumentCaptor < UUID > uuid = ArgumentCaptor . forClass ( UUID . class ) ; verify ( m_PersistentDataStore , times ( 1 ) ) . persist ( eq ( MissionProgramManagerImpl . class ) , uuid . capture ( ) , anyString ( ) , ( Serializable ) Mockito . any ( ) ) ; assertThat ( m_SUT . getActiveProgramTemplateNames ( ) . size ( ) , is ( 1 ) ) ; ( ( ProgramImpl ) blahProgram ) . changeStatus ( ProgramStatus . CANCELED ) ; m_SUT . removeProgram ( blahProgram , uuid . getValue ( ) ) ; assertThat ( m_SUT . getActiveProgramsUsingTemplate ( "blah" ) . size ( ) , is ( 0 ) ) ; try { m_SUT . removeProgram ( blahProgram , uuid . getValue ( ) ) ; fail ( "Expected exception the program was already removed." ) ; } catch ( IllegalArgumentException e ) { } }
Test removing a mission program.
Test removing a mission program .
// mock // verify //program to add        //add template //add params and schedule //need to capture uuid so that it can be used during the removeProgram verification //try to remove  //verify still removed //verify exception if attempted to remove again //try to remove the program again.  //expecting exception