mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramManagerImpl.java
@Test
    public void testProgramActivationInWhichProgramDependsOnAnotherProgram() throws InterruptedException
    {
        final MockWaitRunnable runner = new MockWaitRunnable();
        final Thread runningThread = new Thread(runner);
       
        //mock the behavior in the scheduler service
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                ProgramImpl prog = (ProgramImpl)invocation.getArguments()[0];
           
                //if statement here to make sure that the program1 simulates
                //a program that takes long to initialize. All other programs 
                //are to change their status immediately.
                if (prog.getProgramName().equals("program1"))
                {
                    runner.setProgram(prog);
                    runningThread.start();
                }
                else
                {
                    prog.changeStatus(ProgramStatus.EXECUTING);
                    prog.changeStatus(ProgramStatus.EXECUTED);
                    
                    //post event
                    Map<String, Object> props = new HashMap<String, Object>();
                    props.put(Program.EVENT_PROP_PROGRAM_NAME, prog.getProgramName());
                    m_EventHandlerAnswer.getHandler().handleEvent(new Event(Program.TOPIC_PROGRAM_EXECUTED, props));
                }
                
                return null;
            }
        }).when(m_Scheduler).executeProgram(Mockito.any(ProgramImpl.class));
   
        mockDependentMissionTemplates();
        mockProgram2DependsProgram1();
   
        setScriptEngineAndActivate();
   
        //wait for long simulation of program changing states to end.
        runningThread.join();
   
        Program program1 = m_SUT.getProgram("program1");
        Program program2 = m_SUT.getProgram("program2");
       
        assertThat(program1.getProgramStatus(), is(ProgramStatus.EXECUTED));
        assertThat(program2.getProgramStatus(), is(ProgramStatus.EXECUTED));
    }
/**
    * Test used to verify that bug with program dependencies is fixed. Verification method for TH-2542
    */
Test used to verify that bug with program dependencies is fixed. Verification method for TH-2542
Test used to verify that bug with program dependencies is fixed . Verification method for TH - 2542
@Test
    public void testProgramActivationInWhichProgramDependsOnAnotherProgram() throws InterruptedException
    {
        final MockWaitRunnable runner = new MockWaitRunnable();
        final Thread runningThread = new Thread(runner);
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                ProgramImpl prog = (ProgramImpl)invocation.getArguments()[0];
                if (prog.getProgramName().equals("program1"))
                {
                    runner.setProgram(prog);
                    runningThread.start();
                }
                else
                {
                    prog.changeStatus(ProgramStatus.EXECUTING);
                    prog.changeStatus(ProgramStatus.EXECUTED);
                    Map<String, Object> props = new HashMap<String, Object>();
                    props.put(Program.EVENT_PROP_PROGRAM_NAME, prog.getProgramName());
                    m_EventHandlerAnswer.getHandler().handleEvent(new Event(Program.TOPIC_PROGRAM_EXECUTED, props));
                }
                return null;
            }
        }).when(m_Scheduler).executeProgram(Mockito.any(ProgramImpl.class));
        mockDependentMissionTemplates();
        mockProgram2DependsProgram1();
        setScriptEngineAndActivate();
        runningThread.join();
        Program program1 = m_SUT.getProgram("program1");
        Program program2 = m_SUT.getProgram("program2");
        assertThat(program1.getProgramStatus(), is(ProgramStatus.EXECUTED));
        assertThat(program2.getProgramStatus(), is(ProgramStatus.EXECUTED));
    }
@ Test public void testProgramActivationInWhichProgramDependsOnAnotherProgram ( ) throws InterruptedException { final MockWaitRunnable runner = new MockWaitRunnable ( ) ; final Thread runningThread = new Thread ( runner ) ; doAnswer ( new Answer < Object > ( ) { @ Override public Object answer ( InvocationOnMock invocation ) throws Throwable { ProgramImpl prog = ( ProgramImpl ) invocation . getArguments ( ) [ 0 ] ; if ( prog . getProgramName ( ) . equals ( "program1" ) ) { runner . setProgram ( prog ) ; runningThread . start ( ) ; } else { prog . changeStatus ( ProgramStatus . EXECUTING ) ; prog . changeStatus ( ProgramStatus . EXECUTED ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( Program . EVENT_PROP_PROGRAM_NAME , prog . getProgramName ( ) ) ; m_EventHandlerAnswer . getHandler ( ) . handleEvent ( new Event ( Program . TOPIC_PROGRAM_EXECUTED , props ) ) ; } return null ; } } ) . when ( m_Scheduler ) . executeProgram ( Mockito . any ( ProgramImpl . class ) ) ; mockDependentMissionTemplates ( ) ; mockProgram2DependsProgram1 ( ) ; setScriptEngineAndActivate ( ) ; runningThread . join ( ) ; Program program1 = m_SUT . getProgram ( "program1" ) ; Program program2 = m_SUT . getProgram ( "program2" ) ; assertThat ( program1 . getProgramStatus ( ) , is ( ProgramStatus . EXECUTED ) ) ; assertThat ( program2 . getProgramStatus ( ) , is ( ProgramStatus . EXECUTED ) ) ; }
Test used to verify that bug with program dependencies is fixed.
Test used to verify that bug with program dependencies is fixed .
//mock the behavior in the scheduler service //if statement here to make sure that the program1 simulates //a program that takes long to initialize. All other programs  //are to change their status immediately. //post event //wait for long simulation of program changing states to end.