mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestProgramImpl.java
@Test
    public void testProgramStatus() throws MissionProgramException, InterruptedException, ExecutionException
    {
        ProgramImpl program = createProgram("NAME");
        
        //at construction is not checked that deps are unsatisfied
        assertThat(program.getProgramStatus(), is(ProgramStatus.UNSATISFIED));

        //check if deps need to be reconciled if not the program is satisfied
        program.reconcileDependencies();
        assertThat(program.getProgramStatus(), is(ProgramStatus.WAITING_UNINITIALIZED));

        //this would take place in the mission program manager's script initialization
        program.changeStatus(ProgramStatus.WAITING_INITIALIZED);
        
        program.execute();

        //verify the call to the MissionProgramManager
        verify(m_Manager).executeProgram(program);
        //within the manager the following calls are made
        program.changeStatus(ProgramStatus.EXECUTING);
        //check that the flag has changed
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTING));
        //after successful completion
        program.changeStatus(ProgramStatus.EXECUTED);
        //check that the flag has changed
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTED));
        
        // the executed status is an end-point, after reaching this end-point the status cannot be changed 
        //back to waiting
        try
        {
            program.changeStatus(ProgramStatus.WAITING_UNINITIALIZED);
            fail("expected exception");
        }
        catch (IllegalStateException exception)
        {
            //expected exception
        }
        //verify still executed status
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTED));
        //programs can be re-executed after execution, but parameter values are not re-check, so status changes to
        // executing from executed. 
        program.changeStatus(ProgramStatus.EXECUTING);
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTING));
        
        try
        {
            //programs with bad variable metatdata or parameter values will throw an exception during construction
            new ProgramImpl(m_Manager, m_EventAdmin, new MissionProgramTemplate().
                withSource("something").withName("test").withVariableMetaData(new MissionVariableMetaData().
                    withName("badness")), new MissionProgramParameters().withSchedule(new MissionProgramSchedule().
                    withIndefiniteInterval(false).withActive(true)), UUID.randomUUID());
            fail("expected exception because the variable data is not complete.");
        }
        catch(IllegalArgumentException e)
        {
            //expected exception
        }
    }
/**
     * This tests the change status method in the program implementation. Certain status changes are not allowed
     * and will throw errors. 
     */
This tests the change status method in the program implementation. Certain status changes are not allowed
and will throw errors.
This tests the change status method in the program implementation . Certain status changes are not allowed and will throw errors .
@Test
    public void testProgramStatus() throws MissionProgramException, InterruptedException, ExecutionException
    {
        ProgramImpl program = createProgram("NAME");
        assertThat(program.getProgramStatus(), is(ProgramStatus.UNSATISFIED));
        program.reconcileDependencies();
        assertThat(program.getProgramStatus(), is(ProgramStatus.WAITING_UNINITIALIZED));
        program.changeStatus(ProgramStatus.WAITING_INITIALIZED);
        program.execute();
        verify(m_Manager).executeProgram(program);
        program.changeStatus(ProgramStatus.EXECUTING);
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTING));
        program.changeStatus(ProgramStatus.EXECUTED);
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTED));
        try
        {
            program.changeStatus(ProgramStatus.WAITING_UNINITIALIZED);
            fail("expected exception");
        }
        catch (IllegalStateException exception)
        {
        }
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTED));
        program.changeStatus(ProgramStatus.EXECUTING);
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTING));
        try
        {
            new ProgramImpl(m_Manager, m_EventAdmin, new MissionProgramTemplate().
                withSource("something").withName("test").withVariableMetaData(new MissionVariableMetaData().
                    withName("badness")), new MissionProgramParameters().withSchedule(new MissionProgramSchedule().
                    withIndefiniteInterval(false).withActive(true)), UUID.randomUUID());
            fail("expected exception because the variable data is not complete.");
        }
        catch(IllegalArgumentException e)
        {
        }
    }
@ Test public void testProgramStatus ( ) throws MissionProgramException , InterruptedException , ExecutionException { ProgramImpl program = createProgram ( "NAME" ) ; assertThat ( program . getProgramStatus ( ) , is ( ProgramStatus . UNSATISFIED ) ) ; program . reconcileDependencies ( ) ; assertThat ( program . getProgramStatus ( ) , is ( ProgramStatus . WAITING_UNINITIALIZED ) ) ; program . changeStatus ( ProgramStatus . WAITING_INITIALIZED ) ; program . execute ( ) ; verify ( m_Manager ) . executeProgram ( program ) ; program . changeStatus ( ProgramStatus . EXECUTING ) ; assertThat ( program . getProgramStatus ( ) , is ( ProgramStatus . EXECUTING ) ) ; program . changeStatus ( ProgramStatus . EXECUTED ) ; assertThat ( program . getProgramStatus ( ) , is ( ProgramStatus . EXECUTED ) ) ; try { program . changeStatus ( ProgramStatus . WAITING_UNINITIALIZED ) ; fail ( "expected exception" ) ; } catch ( IllegalStateException exception ) { } assertThat ( program . getProgramStatus ( ) , is ( ProgramStatus . EXECUTED ) ) ; program . changeStatus ( ProgramStatus . EXECUTING ) ; assertThat ( program . getProgramStatus ( ) , is ( ProgramStatus . EXECUTING ) ) ; try { new ProgramImpl ( m_Manager , m_EventAdmin , new MissionProgramTemplate ( ) . withSource ( "something" ) . withName ( "test" ) . withVariableMetaData ( new MissionVariableMetaData ( ) . withName ( "badness" ) ) , new MissionProgramParameters ( ) . withSchedule ( new MissionProgramSchedule ( ) . withIndefiniteInterval ( false ) . withActive ( true ) ) , UUID . randomUUID ( ) ) ; fail ( "expected exception because the variable data is not complete." ) ; } catch ( IllegalArgumentException e ) { } }
This tests the change status method in the program implementation.
This tests the change status method in the program implementation .
//at construction is not checked that deps are unsatisfied //check if deps need to be reconciled if not the program is satisfied //this would take place in the mission program manager's script initialization //verify the call to the MissionProgramManager //within the manager the following calls are made //check that the flag has changed //after successful completion //check that the flag has changed // the executed status is an end-point, after reaching this end-point the status cannot be changed  //back to waiting //expected exception //verify still executed status //programs can be re-executed after execution, but parameter values are not re-check, so status changes to // executing from executed.  //programs with bad variable metatdata or parameter values will throw an exception during construction //expected exception