mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramSchedulerImpl.java
@Test
    public void testExecutePastScheduled() throws InterruptedException
    {
        //activate the component
        m_SUT.activate();
        
        //schedule
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() - 1000L, 
                System.currentTimeMillis() - 100L, false, false, true, true);
        
        //more behavior for the program instance
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        
        //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);
        
        //give time for execution and shutdown which should happen immediately afterward
        Thread.sleep(500);
        verify(m_Program1).changeStatus(ProgramStatus.SHUTDOWN);
        
        Thread.sleep(100);
        
        //once for shutdown and execute only
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times (2)).postEvent(eventCaptor.capture());
        
        //verify no more status changes
        verify(m_Program1, times(1)).changeStatus(ProgramStatus.SHUTDOWN);
        verify(m_Program1, times(1)).changeStatus(ProgramStatus.EXECUTED);

        verify(wakeLock, times(2)).delete();
    }
/**
     * Test that a program can be registered and executed, but the scheduled time is in the past.
     */
Test that a program can be registered and executed, but the scheduled time is in the past.
Test that a program can be registered and executed but the scheduled time is in the past .
@Test
    public void testExecutePastScheduled() throws InterruptedException
    {
        m_SUT.activate();
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() - 1000L, 
                System.currentTimeMillis() - 100L, false, false, true, true);
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        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(500);
        verify(m_Program1).changeStatus(ProgramStatus.SHUTDOWN);
        Thread.sleep(100);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times (2)).postEvent(eventCaptor.capture());
        verify(m_Program1, times(1)).changeStatus(ProgramStatus.SHUTDOWN);
        verify(m_Program1, times(1)).changeStatus(ProgramStatus.EXECUTED);
        verify(wakeLock, times(2)).delete();
    }
@ Test public void testExecutePastScheduled ( ) throws InterruptedException { m_SUT . activate ( ) ; MissionProgramSchedule schedule = TestProgramImpl . createMissionSchedule ( System . currentTimeMillis ( ) - 1000L , System . currentTimeMillis ( ) - 100L , false , false , true , true ) ; when ( m_Program1 . getMissionSchedule ( ) ) . thenReturn ( schedule ) ; 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 ( 500 ) ; verify ( m_Program1 ) . changeStatus ( ProgramStatus . SHUTDOWN ) ; Thread . sleep ( 100 ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; verify ( m_Program1 , times ( 1 ) ) . changeStatus ( ProgramStatus . SHUTDOWN ) ; verify ( m_Program1 , times ( 1 ) ) . changeStatus ( ProgramStatus . EXECUTED ) ; verify ( wakeLock , times ( 2 ) ) . delete ( ) ; }
Test that a program can be registered and executed, but the scheduled time is in the past.
Test that a program can be registered and executed but the scheduled time is in the past .
//activate the component //schedule //more behavior for the program instance //mock power management //load the program //give time for execution and shutdown which should happen immediately afterward //once for shutdown and execute only //verify no more status changes