mil.dod.th.ose.core.integration/src/mil/dod/th/ose/core/integration/TestMissionProgramming.java
@Test
    public void testTimedObservationRemovalLoop() throws IllegalArgumentException, PersistenceFailedException, 
        InterruptedException, AssetException, FactoryException, IOException
    {
        // Create asset
        AssetDirectoryService assetDirectoryService = 
            ServiceUtils.getService(m_Context, AssetDirectoryService.class);
        Asset testAsset = assetDirectoryService.createAsset(ExampleAsset.class.getName(), "testDataCapturer");
        
        // Capture observations
        testAsset.captureData();
        testAsset.captureData();
        
        // Check that the observations do exist
        ObservationStore observationStore = ServiceUtils.getService(m_Context, ObservationStore.class);
        Collection<Observation> observations = observationStore.newQuery()
                .withAsset(testAsset)
                .withSubType(ObservationSubTypeEnum.DETECTION)
                .execute();
        assertThat(observations.size(), is(2));
        
        // Schedule and parameters to use for execution of the removal template
        MissionProgramSchedule removeLoopSchedule = new MissionProgramSchedule()
            .withIndefiniteInterval(true)
            .withImmediately(true)
            .withActive(true);
        final MapEntry param1 = new MapEntry("initTimeDelay", 0);
        final MapEntry param2 = new MapEntry("timeDelayInterval", 1);
        final MapEntry param3 = new MapEntry("removeTime", 0);
        final MapEntry param4 = new MapEntry("timeUnitStr", "Second");
        
        // Sync the event handler to the Executed state of the mission
        EventHandlerSyncer executeMissionSyncer = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_EXECUTED, 
                      String.format("(%s=%s)", Program.EVENT_PROP_PROGRAM_NAME, "timed-observation-removal-loop-test"));
        
        // Mission parameters are filled with values set above
        MissionProgramParameters parameters = new MissionProgramParameters()
            .withTemplateName("timed-observation-removal-loop")
            .withSchedule(removeLoopSchedule)
            .withParameters(param1, param2, param3, param4)
            .withProgramName("timed-observation-removal-loop-test");   
    
        // Load the mission
        Program program = m_MissionProgramManager.loadParameters(parameters);
        
        // Wait up to 5 seconds for the Executed state of the mission to occur
        executeMissionSyncer.waitForEvent(5);
                
        // After waiting, make sure the mission status is Executed
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTED));  
        
        // Since the initial time delay is set to 0, the mission will immediately remove the observations.
        // This sleep ensures that there is time to actually delete the observations before it checks that they 
        // have been deleted.
        Thread.sleep(500);
        
        // Check that observations have been deleted
        observations = observationStore.queryByAsset(testAsset);
        assertThat(observations.size(), is(0));
        
        // Create more observations
        testAsset.captureData();
        testAsset.captureData();
        
        // Sleep long enough for the next removal to occur
        Thread.sleep(2000);
       
        // Check that observations have been deleted again
        observations = observationStore.queryByAsset(testAsset);
        assertThat(observations.size(), is(0));
        
        // Sync the event handler to the Shutdown state of the mission
        executeMissionSyncer = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_SHUTDOWN, 
                "(name=timed-observation-removal-loop-test)");
        
        // Stop the mission 
        program.executeShutdown();
        
        // Wait up to 5 seconds for the Shutdown state of the mission to occur
        executeMissionSyncer.waitForEvent(5);
        
        // After waiting, make sure that the mission status is Shutdown
        assertThat(program.getProgramStatus(), is(ProgramStatus.SHUTDOWN));
        
        // Remove the mission
        program.remove();
    }
/**
     * Test running of the timed-observation-removal-loop template.  Test will periodically remove all observations.
     */
Test running of the timed-observation-removal-loop template.  Test will periodically remove all observations.
Test running of the timed - observation - removal - loop template . Test will periodically remove all observations .
@Test
    public void testTimedObservationRemovalLoop() throws IllegalArgumentException, PersistenceFailedException, 
        InterruptedException, AssetException, FactoryException, IOException
    {
        AssetDirectoryService assetDirectoryService = 
            ServiceUtils.getService(m_Context, AssetDirectoryService.class);
        Asset testAsset = assetDirectoryService.createAsset(ExampleAsset.class.getName(), "testDataCapturer");
        testAsset.captureData();
        testAsset.captureData();
        ObservationStore observationStore = ServiceUtils.getService(m_Context, ObservationStore.class);
        Collection<Observation> observations = observationStore.newQuery()
                .withAsset(testAsset)
                .withSubType(ObservationSubTypeEnum.DETECTION)
                .execute();
        assertThat(observations.size(), is(2));
        MissionProgramSchedule removeLoopSchedule = new MissionProgramSchedule()
            .withIndefiniteInterval(true)
            .withImmediately(true)
            .withActive(true);
        final MapEntry param1 = new MapEntry("initTimeDelay", 0);
        final MapEntry param2 = new MapEntry("timeDelayInterval", 1);
        final MapEntry param3 = new MapEntry("removeTime", 0);
        final MapEntry param4 = new MapEntry("timeUnitStr", "Second");
        EventHandlerSyncer executeMissionSyncer = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_EXECUTED, 
                      String.format("(%s=%s)", Program.EVENT_PROP_PROGRAM_NAME, "timed-observation-removal-loop-test"));
        MissionProgramParameters parameters = new MissionProgramParameters()
            .withTemplateName("timed-observation-removal-loop")
            .withSchedule(removeLoopSchedule)
            .withParameters(param1, param2, param3, param4)
            .withProgramName("timed-observation-removal-loop-test");   
        Program program = m_MissionProgramManager.loadParameters(parameters);
        executeMissionSyncer.waitForEvent(5);
        assertThat(program.getProgramStatus(), is(ProgramStatus.EXECUTED));  
        Thread.sleep(500);
        observations = observationStore.queryByAsset(testAsset);
        assertThat(observations.size(), is(0));
        testAsset.captureData();
        testAsset.captureData();
        Thread.sleep(2000);
         again
        observations = observationStore.queryByAsset(testAsset);
        assertThat(observations.size(), is(0));
        executeMissionSyncer = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_SHUTDOWN, 
                "(name=timed-observation-removal-loop-test)");
        program.executeShutdown();
        executeMissionSyncer.waitForEvent(5);
        assertThat(program.getProgramStatus(), is(ProgramStatus.SHUTDOWN));
        program.remove();
    }
@ Test public void testTimedObservationRemovalLoop ( ) throws IllegalArgumentException , PersistenceFailedException , InterruptedException , AssetException , FactoryException , IOException { AssetDirectoryService assetDirectoryService = ServiceUtils . getService ( m_Context , AssetDirectoryService . class ) ; Asset testAsset = assetDirectoryService . createAsset ( ExampleAsset . class . getName ( ) , "testDataCapturer" ) ; testAsset . captureData ( ) ; testAsset . captureData ( ) ; ObservationStore observationStore = ServiceUtils . getService ( m_Context , ObservationStore . class ) ; Collection < Observation > observations = observationStore . newQuery ( ) . withAsset ( testAsset ) . withSubType ( ObservationSubTypeEnum . DETECTION ) . execute ( ) ; assertThat ( observations . size ( ) , is ( 2 ) ) ; MissionProgramSchedule removeLoopSchedule = new MissionProgramSchedule ( ) . withIndefiniteInterval ( true ) . withImmediately ( true ) . withActive ( true ) ; final MapEntry param1 = new MapEntry ( "initTimeDelay" , 0 ) ; final MapEntry param2 = new MapEntry ( "timeDelayInterval" , 1 ) ; final MapEntry param3 = new MapEntry ( "removeTime" , 0 ) ; final MapEntry param4 = new MapEntry ( "timeUnitStr" , "Second" ) ; EventHandlerSyncer executeMissionSyncer = new EventHandlerSyncer ( m_Context , Program . TOPIC_PROGRAM_EXECUTED , String . format ( "(%s=%s)" , Program . EVENT_PROP_PROGRAM_NAME , "timed-observation-removal-loop-test" ) ) ; MissionProgramParameters parameters = new MissionProgramParameters ( ) . withTemplateName ( "timed-observation-removal-loop" ) . withSchedule ( removeLoopSchedule ) . withParameters ( param1 , param2 , param3 , param4 ) . withProgramName ( "timed-observation-removal-loop-test" ) ; Program program = m_MissionProgramManager . loadParameters ( parameters ) ; executeMissionSyncer . waitForEvent ( 5 ) ; assertThat ( program . getProgramStatus ( ) , is ( ProgramStatus . EXECUTED ) ) ; Thread . sleep ( 500 ) ; observations = observationStore . queryByAsset ( testAsset ) ; assertThat ( observations . size ( ) , is ( 0 ) ) ; testAsset . captureData ( ) ; testAsset . captureData ( ) ; Thread . sleep ( 2000 ) ; observations = observationStore . queryByAsset ( testAsset ) ; assertThat ( observations . size ( ) , is ( 0 ) ) ; executeMissionSyncer = new EventHandlerSyncer ( m_Context , Program . TOPIC_PROGRAM_SHUTDOWN , "(name=timed-observation-removal-loop-test)" ) ; program . executeShutdown ( ) ; executeMissionSyncer . waitForEvent ( 5 ) ; assertThat ( program . getProgramStatus ( ) , is ( ProgramStatus . SHUTDOWN ) ) ; program . remove ( ) ; }
Test running of the timed-observation-removal-loop template.
Test running of the timed - observation - removal - loop template .
// Create asset // Capture observations // Check that the observations do exist // Schedule and parameters to use for execution of the removal template // Sync the event handler to the Executed state of the mission // Mission parameters are filled with values set above // Load the mission // Wait up to 5 seconds for the Executed state of the mission to occur // After waiting, make sure the mission status is Executed // Since the initial time delay is set to 0, the mission will immediately remove the observations. // This sleep ensures that there is time to actually delete the observations before it checks that they  // have been deleted. // Check that observations have been deleted // Create more observations // Sleep long enough for the next removal to occur // Check that observations have been deleted again // Sync the event handler to the Shutdown state of the mission // Stop the mission  // Wait up to 5 seconds for the Shutdown state of the mission to occur // After waiting, make sure that the mission status is Shutdown // Remove the mission