mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramSchedulerImpl.java
@Test
    public void testeventPostingOneNowOneLater() throws InterruptedException
    {
        //activate the component
        m_SUT.activate();

        //now schedule
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(null, null, true, true, true, true);
        
        MissionProgramSchedule schedule2 = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 200L,
                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(), PROG2_NAME)).thenReturn(wakeLock);

        m_SUT.executeProgram(m_Program1);
        verify(m_PowerManager, never()).createWakeLock(m_SUT.getClass(), PROG1_NAME);

        m_SUT.executeProgram(m_Program2);
        verify(wakeLock).scheduleWakeTime(new Date(schedule2.getStartInterval()));
        
        Thread.sleep(100);
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        //once for the first program
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        
        assertThat(eventCaptor.getAllValues().get(0).getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getAllValues().get(0), m_Program1);
        
        //wait just a little while longer
        Thread.sleep(200);
        //one more time for the second programs execution
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        
        assertThat(eventCaptor.getValue().getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program2);

        verify(wakeLock).delete();
    }
/**
     * Test an immediate execution mission and a scheduled mission.
     * Verify correct programs are executed at the expected times.
     */
Test an immediate execution mission and a scheduled mission.
Verify correct programs are executed at the expected times.
Test an immediate execution mission and a scheduled mission . Verify correct programs are executed at the expected times .
@Test
    public void testeventPostingOneNowOneLater() throws InterruptedException
    {
        m_SUT.activate();
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(null, null, true, true, true, true);
        MissionProgramSchedule schedule2 = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 200L,
                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(), PROG2_NAME)).thenReturn(wakeLock);
        m_SUT.executeProgram(m_Program1);
        verify(m_PowerManager, never()).createWakeLock(m_SUT.getClass(), PROG1_NAME);
        m_SUT.executeProgram(m_Program2);
        verify(wakeLock).scheduleWakeTime(new Date(schedule2.getStartInterval()));
        Thread.sleep(100);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        assertThat(eventCaptor.getAllValues().get(0).getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getAllValues().get(0), m_Program1);
        Thread.sleep(200);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        assertThat(eventCaptor.getValue().getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program2);
        verify(wakeLock).delete();
    }
@ Test public void testeventPostingOneNowOneLater ( ) throws InterruptedException { m_SUT . activate ( ) ; MissionProgramSchedule schedule = TestProgramImpl . createMissionSchedule ( null , null , true , true , true , true ) ; MissionProgramSchedule schedule2 = TestProgramImpl . createMissionSchedule ( System . currentTimeMillis ( ) + 200L , 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 ( ) , PROG2_NAME ) ) . thenReturn ( wakeLock ) ; m_SUT . executeProgram ( m_Program1 ) ; verify ( m_PowerManager , never ( ) ) . createWakeLock ( m_SUT . getClass ( ) , PROG1_NAME ) ; m_SUT . executeProgram ( m_Program2 ) ; verify ( wakeLock ) . scheduleWakeTime ( new Date ( schedule2 . getStartInterval ( ) ) ) ; Thread . sleep ( 100 ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 1 ) ) . postEvent ( eventCaptor . capture ( ) ) ; assertThat ( eventCaptor . getAllValues ( ) . get ( 0 ) . getTopic ( ) , is ( Program . TOPIC_PROGRAM_EXECUTED ) ) ; assertProgramEventProps ( eventCaptor . getAllValues ( ) . get ( 0 ) , m_Program1 ) ; Thread . sleep ( 200 ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; assertThat ( eventCaptor . getValue ( ) . getTopic ( ) , is ( Program . TOPIC_PROGRAM_EXECUTED ) ) ; assertProgramEventProps ( eventCaptor . getValue ( ) , m_Program2 ) ; verify ( wakeLock ) . delete ( ) ; }
Test an immediate execution mission and a scheduled mission.
Test an immediate execution mission and a scheduled mission .
//activate the component //now schedule //mock power management //once for the first program //wait just a little while longer //one more time for the second programs execution