mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramSchedulerImpl.java
@Test
    public void testSchdeuledExecutionStillExecAtShutdown() throws InterruptedException, PrivilegedActionException
    {
        //activate the component
        m_SUT.activate();
        
        //quick schedule, shouldn't be able to remove, will already be gone
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 100L, 
            System.currentTimeMillis() + 150L, 
            false, true, true, true);
        
        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);

        m_SUT.executeProgram(m_Program1);

        //verify interactions
        verify(m_Script, timeout(500)).execute();

        //mock that the program is STILL executing
        doThrow(new IllegalStateException()).when(m_Program1).changeStatus(Mockito.any(ProgramStatus.class));
        
        //wait for shutdown to try
        Thread.sleep(100);
        
        //verify it was unsuccessful because the status change was denied
        verify(m_Script, never()).shutdown();

        verify(wakeLock).delete();
    }
/**
     * Test submitting a program for scheduled execution with an ending time.
     * Verify shutdown not successful if status isn't executed
     */
Test submitting a program for scheduled execution with an ending time.
Verify shutdown not successful if status isn't executed
Test submitting a program for scheduled execution with an ending time . Verify shutdown not successful if status isn ' t executed
@Test
    public void testSchdeuledExecutionStillExecAtShutdown() throws InterruptedException, PrivilegedActionException
    {
        m_SUT.activate();
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 100L, 
            System.currentTimeMillis() + 150L, 
            false, true, true, true);
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        WakeLock wakeLock = mock(WakeLock.class);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG1_NAME)).thenReturn(wakeLock);
        m_SUT.executeProgram(m_Program1);
        verify(m_Script, timeout(500)).execute();
        doThrow(new IllegalStateException()).when(m_Program1).changeStatus(Mockito.any(ProgramStatus.class));
        Thread.sleep(100);
        verify(m_Script, never()).shutdown();
        verify(wakeLock).delete();
    }
@ Test public void testSchdeuledExecutionStillExecAtShutdown ( ) throws InterruptedException , PrivilegedActionException { m_SUT . activate ( ) ; MissionProgramSchedule schedule = TestProgramImpl . createMissionSchedule ( System . currentTimeMillis ( ) + 100L , System . currentTimeMillis ( ) + 150L , false , true , true , true ) ; when ( m_Program1 . getMissionSchedule ( ) ) . thenReturn ( schedule ) ; WakeLock wakeLock = mock ( WakeLock . class ) ; when ( m_PowerManager . createWakeLock ( m_SUT . getClass ( ) , PROG1_NAME ) ) . thenReturn ( wakeLock ) ; m_SUT . executeProgram ( m_Program1 ) ; verify ( m_Script , timeout ( 500 ) ) . execute ( ) ; doThrow ( new IllegalStateException ( ) ) . when ( m_Program1 ) . changeStatus ( Mockito . any ( ProgramStatus . class ) ) ; Thread . sleep ( 100 ) ; verify ( m_Script , never ( ) ) . shutdown ( ) ; verify ( wakeLock ) . delete ( ) ; }
Test submitting a program for scheduled execution with an ending time.
Test submitting a program for scheduled execution with an ending time .
//activate the component //quick schedule, shouldn't be able to remove, will already be gone //mock power management //verify interactions //mock that the program is STILL executing //wait for shutdown to try //verify it was unsuccessful because the status change was denied