mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramSchedulerImpl.java
@Test
    public void testExecuteImmediateWithShutdownPosting() throws InterruptedException
    {
        //activate the component
        m_SUT.activate();
        
        //schedule
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(null, 
                System.currentTimeMillis() + 100L, false, true, true, true);
        
        //more behavior for the program instance
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        when(m_Program1.getProgramStatus()).thenReturn(ProgramStatus.WAITING_INITIALIZED);
        
        //mock power management
        WakeLock wakeLock = mock(WakeLock.class);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG1_NAME)).thenReturn(wakeLock);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG1_NAME + "_Stop")).thenReturn(wakeLock);

        //load the program
        m_SUT.executeProgram(m_Program1);
        
        //wait for it, give time for execution and shutdown. 
        Thread.sleep(150);
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        //once for execution once for shut down
        verify(m_EventAdmin, times (2)).postEvent(eventCaptor.capture());
        
        assertThat(eventCaptor.getAllValues().get(0).getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program1);
        assertThat(eventCaptor.getValue().getTopic(), 
                is(Program.TOPIC_PROGRAM_SHUTDOWN));
        
        assertThat(m_Program1.getProgramStatus(), is(ProgramStatus.WAITING_INITIALIZED));

        verify(wakeLock).delete();
    }
/**
     * Test that a program can be registered and executed, and that if the schedule is not indefinite that shutdown is
     * invoked.
     */
Test that a program can be registered and executed, and that if the schedule is not indefinite that shutdown is
invoked.
Test that a program can be registered and executed and that if the schedule is not indefinite that shutdown is invoked .
@Test
    public void testExecuteImmediateWithShutdownPosting() throws InterruptedException
    {
        m_SUT.activate();
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(null, 
                System.currentTimeMillis() + 100L, false, true, true, true);
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        when(m_Program1.getProgramStatus()).thenReturn(ProgramStatus.WAITING_INITIALIZED);
        WakeLock wakeLock = mock(WakeLock.class);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG1_NAME)).thenReturn(wakeLock);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG1_NAME + "_Stop")).thenReturn(wakeLock);
        m_SUT.executeProgram(m_Program1);
        Thread.sleep(150);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times (2)).postEvent(eventCaptor.capture());
        assertThat(eventCaptor.getAllValues().get(0).getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program1);
        assertThat(eventCaptor.getValue().getTopic(), 
                is(Program.TOPIC_PROGRAM_SHUTDOWN));
        assertThat(m_Program1.getProgramStatus(), is(ProgramStatus.WAITING_INITIALIZED));
        verify(wakeLock).delete();
    }
@ Test public void testExecuteImmediateWithShutdownPosting ( ) throws InterruptedException { m_SUT . activate ( ) ; MissionProgramSchedule schedule = TestProgramImpl . createMissionSchedule ( null , System . currentTimeMillis ( ) + 100L , false , true , true , true ) ; when ( m_Program1 . getMissionSchedule ( ) ) . thenReturn ( schedule ) ; when ( m_Program1 . getProgramStatus ( ) ) . thenReturn ( ProgramStatus . WAITING_INITIALIZED ) ; WakeLock wakeLock = mock ( WakeLock . class ) ; when ( m_PowerManager . createWakeLock ( m_SUT . getClass ( ) , PROG1_NAME ) ) . thenReturn ( wakeLock ) ; when ( m_PowerManager . createWakeLock ( m_SUT . getClass ( ) , PROG1_NAME + "_Stop" ) ) . thenReturn ( wakeLock ) ; m_SUT . executeProgram ( m_Program1 ) ; Thread . sleep ( 150 ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; assertThat ( eventCaptor . getAllValues ( ) . get ( 0 ) . getTopic ( ) , is ( Program . TOPIC_PROGRAM_EXECUTED ) ) ; assertProgramEventProps ( eventCaptor . getValue ( ) , m_Program1 ) ; assertThat ( eventCaptor . getValue ( ) . getTopic ( ) , is ( Program . TOPIC_PROGRAM_SHUTDOWN ) ) ; assertThat ( m_Program1 . getProgramStatus ( ) , is ( ProgramStatus . WAITING_INITIALIZED ) ) ; verify ( wakeLock ) . delete ( ) ; }
Test that a program can be registered and executed, and that if the schedule is not indefinite that shutdown is
 invoked.
Test that a program can be registered and executed and that if the schedule is not indefinite that shutdown is invoked .
//activate the component //schedule //more behavior for the program instance //mock power management //load the program //wait for it, give time for execution and shutdown.  //once for execution once for shut down