mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramSchedulerImpl.java
@Test
    public void testException() throws InterruptedException, PrivilegedActionException
    {
        //activate the component
        m_SUT.activate();
        
        doThrow(new PrivilegedActionException(new Exception("EXCEPTION PIZZA!"))).when(m_Script).execute();
        
        //now execution
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(null, null, true, true, true, true);
        
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        
        m_SUT.executeProgram(m_Program1);
        
        //wait for execution
        Thread.sleep(50);
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        //once for the execution failed event
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        
        int exceptEventIndex = 0;
        for(Event event : eventCaptor.getAllValues())
        {
            if(event.getTopic().equals(Program.TOPIC_PROGRAM_EXECUTED_FAILURE))
            {
                break;
            }
            else
            {
                exceptEventIndex++;
            }
        }
        assertThat(eventCaptor.getAllValues().get(exceptEventIndex).getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED_FAILURE));
        assertProgramEventProps(eventCaptor.getAllValues().get(exceptEventIndex), m_Program1);
        assertThat((String)eventCaptor.getAllValues().get(exceptEventIndex).
                getProperty(Program.EVENT_PROP_PROGRAM_EXCEPTION), is("EXCEPTION PIZZA!"));
    }
/**
     * Test executing a program where the script execution throws an exception.
     * Verify event contains the exception and that the correct topic is used.
     */
Test executing a program where the script execution throws an exception.
Verify event contains the exception and that the correct topic is used.
Test executing a program where the script execution throws an exception . Verify event contains the exception and that the correct topic is used .
@Test
    public void testException() throws InterruptedException, PrivilegedActionException
    {
        m_SUT.activate();
        doThrow(new PrivilegedActionException(new Exception("EXCEPTION PIZZA!"))).when(m_Script).execute();
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(null, null, true, true, true, true);
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        m_SUT.executeProgram(m_Program1);
        Thread.sleep(50);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        int exceptEventIndex = 0;
        for(Event event : eventCaptor.getAllValues())
        {
            if(event.getTopic().equals(Program.TOPIC_PROGRAM_EXECUTED_FAILURE))
            {
                break;
            }
            else
            {
                exceptEventIndex++;
            }
        }
        assertThat(eventCaptor.getAllValues().get(exceptEventIndex).getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED_FAILURE));
        assertProgramEventProps(eventCaptor.getAllValues().get(exceptEventIndex), m_Program1);
        assertThat((String)eventCaptor.getAllValues().get(exceptEventIndex).
                getProperty(Program.EVENT_PROP_PROGRAM_EXCEPTION), is("EXCEPTION PIZZA!"));
    }
@ Test public void testException ( ) throws InterruptedException , PrivilegedActionException { m_SUT . activate ( ) ; doThrow ( new PrivilegedActionException ( new Exception ( "EXCEPTION PIZZA!" ) ) ) . when ( m_Script ) . execute ( ) ; MissionProgramSchedule schedule = TestProgramImpl . createMissionSchedule ( null , null , true , true , true , true ) ; when ( m_Program1 . getMissionSchedule ( ) ) . thenReturn ( schedule ) ; m_SUT . executeProgram ( m_Program1 ) ; Thread . sleep ( 50 ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 1 ) ) . postEvent ( eventCaptor . capture ( ) ) ; int exceptEventIndex = 0 ; for ( Event event : eventCaptor . getAllValues ( ) ) { if ( event . getTopic ( ) . equals ( Program . TOPIC_PROGRAM_EXECUTED_FAILURE ) ) { break ; } else { exceptEventIndex ++ ; } } assertThat ( eventCaptor . getAllValues ( ) . get ( exceptEventIndex ) . getTopic ( ) , is ( Program . TOPIC_PROGRAM_EXECUTED_FAILURE ) ) ; assertProgramEventProps ( eventCaptor . getAllValues ( ) . get ( exceptEventIndex ) , m_Program1 ) ; assertThat ( ( String ) eventCaptor . getAllValues ( ) . get ( exceptEventIndex ) . getProperty ( Program . EVENT_PROP_PROGRAM_EXCEPTION ) , is ( "EXCEPTION PIZZA!" ) ) ; }
Test executing a program where the script execution throws an exception.
Test executing a program where the script execution throws an exception .
//activate the component //now execution //wait for execution //once for the execution failed event