mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramSchedulerImpl.java
@Test
    public void testRemoval() throws InterruptedException
    {
        //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,
                null, true, false, true, true);
        //should be able to remove
        MissionProgramSchedule schedule2 = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 400L,
                null, true, false, true, true);
        
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        when(m_Program2.getMissionSchedule()).thenReturn(schedule2);
        
        //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(), PROG2_NAME)).thenReturn(wakeLock);

        m_SUT.executeProgram(m_Program1);
        m_SUT.executeProgram(m_Program2);

        verify(wakeLock, times(2)).scheduleWakeTime(anyObject());
        
        //wait for execution
        Thread.sleep(250);
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        
        assertThat(eventCaptor.getValue().getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program1);

        //remove the remaining one
        assertThat(m_SUT.cancelScheduledProgram(PROG2_NAME), is(true));
        
        //sleep again to make sure the removed program does NOT execute.
        Thread.sleep(450);
        
        //try again for exception
        try
        {
            m_SUT.cancelScheduledProgram(PROG2_NAME);
            fail("expecting exception the program was already removed");
        }
        catch (IllegalArgumentException e)
        {
            //expecting exception
        }
        
       //verify there was only one invocation for the execution of the first program
        verify(m_EventAdmin, times(1)).postEvent(Mockito.any(Event.class));

        verify(wakeLock, times(2)).delete();
    }
/**
     * Test removing a mission from the executor queue.
     * Verify the mission DOES NOT execute.
     */
Test removing a mission from the executor queue.
Verify the mission DOES NOT execute.
Test removing a mission from the executor queue . Verify the mission DOES NOT execute .
@Test
    public void testRemoval() throws InterruptedException
    {
        m_SUT.activate();
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 100L,
                null, true, false, true, true);
        MissionProgramSchedule schedule2 = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 400L,
                null, true, false, true, true);
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        when(m_Program2.getMissionSchedule()).thenReturn(schedule2);
        WakeLock wakeLock = mock(WakeLock.class);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG1_NAME)).thenReturn(wakeLock);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG2_NAME)).thenReturn(wakeLock);
        m_SUT.executeProgram(m_Program1);
        m_SUT.executeProgram(m_Program2);
        verify(wakeLock, times(2)).scheduleWakeTime(anyObject());
        Thread.sleep(250);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        assertThat(eventCaptor.getValue().getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program1);
        assertThat(m_SUT.cancelScheduledProgram(PROG2_NAME), is(true));
        Thread.sleep(450);
        try
        {
            m_SUT.cancelScheduledProgram(PROG2_NAME);
            fail("expecting exception the program was already removed");
        }
        catch (IllegalArgumentException e)
        {
        }
        verify(m_EventAdmin, times(1)).postEvent(Mockito.any(Event.class));
        verify(wakeLock, times(2)).delete();
    }
@ Test public void testRemoval ( ) throws InterruptedException { m_SUT . activate ( ) ; MissionProgramSchedule schedule = TestProgramImpl . createMissionSchedule ( System . currentTimeMillis ( ) + 100L , null , true , false , true , true ) ; MissionProgramSchedule schedule2 = TestProgramImpl . createMissionSchedule ( System . currentTimeMillis ( ) + 400L , null , true , false , true , true ) ; when ( m_Program1 . getMissionSchedule ( ) ) . thenReturn ( schedule ) ; when ( m_Program2 . getMissionSchedule ( ) ) . thenReturn ( schedule2 ) ; WakeLock wakeLock = mock ( WakeLock . class ) ; when ( m_PowerManager . createWakeLock ( m_SUT . getClass ( ) , PROG1_NAME ) ) . thenReturn ( wakeLock ) ; when ( m_PowerManager . createWakeLock ( m_SUT . getClass ( ) , PROG2_NAME ) ) . thenReturn ( wakeLock ) ; m_SUT . executeProgram ( m_Program1 ) ; m_SUT . executeProgram ( m_Program2 ) ; verify ( wakeLock , times ( 2 ) ) . scheduleWakeTime ( anyObject ( ) ) ; Thread . sleep ( 250 ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 1 ) ) . postEvent ( eventCaptor . capture ( ) ) ; assertThat ( eventCaptor . getValue ( ) . getTopic ( ) , is ( Program . TOPIC_PROGRAM_EXECUTED ) ) ; assertProgramEventProps ( eventCaptor . getValue ( ) , m_Program1 ) ; assertThat ( m_SUT . cancelScheduledProgram ( PROG2_NAME ) , is ( true ) ) ; Thread . sleep ( 450 ) ; try { m_SUT . cancelScheduledProgram ( PROG2_NAME ) ; fail ( "expecting exception the program was already removed" ) ; } catch ( IllegalArgumentException e ) { } verify ( m_EventAdmin , times ( 1 ) ) . postEvent ( Mockito . any ( Event . class ) ) ; verify ( wakeLock , times ( 2 ) ) . delete ( ) ; }
Test removing a mission from the executor queue.
Test removing a mission from the executor queue .
//activate the component //quick schedule, shouldn't be able to remove, will already be gone //should be able to remove //mock power management //wait for execution //remove the remaining one //sleep again to make sure the removed program does NOT execute. //try again for exception //expecting exception //verify there was only one invocation for the execution of the first program