mil.dod.th.ose.core.integration/src/mil/dod/th/ose/core/integration/TestMissionProgramming.java
@Test
    public void testAssetEvent() throws Exception
    {
        //syncer used to listen for executed event, mission's execute on a separate thread
        EventHandlerSyncer syncer = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_EXECUTED,
                String.format("(%s=%s)", Program.EVENT_PROP_PROGRAM_NAME, "ads-event-test"));
        
        AssetDirectoryService assetDirectoryService = ServiceUtils.getService(m_Context, AssetDirectoryService.class);
        Asset asset = assetDirectoryService.createAsset(ExampleAsset.class.getName());       
        
        MissionProgramSchedule schedule = new MissionProgramSchedule().withIndefiniteInterval(false).
            withImmediately(false).withActive(true).withAtReset(true);
        MissionProgramParameters params = new MissionProgramParameters().withTemplateName("asset-event-template").
            withParameters(new MapEntry("assetUuid", asset.getUuid())).
                withProgramName("ads-event-test").withSchedule(schedule);
        
        Program program = m_MissionProgramManager.loadParameters(params);
        program.execute();
        //wait for execute event
        syncer.waitForEvent(5);
        
        EventHandlerSyncer persistedDataSyncer = 
                new EventHandlerSyncer(m_Context, PersistentDataStore.TOPIC_DATA_PERSISTED);
        Observation o = asset.captureData();
        persistedDataSyncer.waitForEvent(5);
        
        PersistentDataStore persistentDataStore = ServiceUtils.getService(m_Context, PersistentDataStore.class);
        PersistentData data = persistentDataStore.find(o.getUuid());
        assertThat((String)data.getEntity(), is("mil/dod/th/core/asset/Asset/DATA_CAPTURED"));
        
        EventHandlerHelper eventHandlerHelper = ServiceUtils.getService(m_Context, EventHandlerHelper.class);
        assertThat(eventHandlerHelper, is(notNullValue()));
        
        eventHandlerHelper.unregisterAllHandlers();
        
        syncer = new EventHandlerSyncer(m_Context, PersistentDataStore.TOPIC_DATA_PERSISTED);
        o = asset.captureData();
        syncer.waitForEvent(2, 0, 0); // wait for 2 seconds to verify event not posted
        
        assertThat(persistentDataStore.contains(o.getUuid()), is(false));
    }
/**
     * Tests the ability for scripts to receive events from event admin service. 
     */
Tests the ability for scripts to receive events from event admin service.
Tests the ability for scripts to receive events from event admin service .
@Test
    public void testAssetEvent() throws Exception
    {
        EventHandlerSyncer syncer = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_EXECUTED,
                String.format("(%s=%s)", Program.EVENT_PROP_PROGRAM_NAME, "ads-event-test"));
        AssetDirectoryService assetDirectoryService = ServiceUtils.getService(m_Context, AssetDirectoryService.class);
        Asset asset = assetDirectoryService.createAsset(ExampleAsset.class.getName());       
        MissionProgramSchedule schedule = new MissionProgramSchedule().withIndefiniteInterval(false).
            withImmediately(false).withActive(true).withAtReset(true);
        MissionProgramParameters params = new MissionProgramParameters().withTemplateName("asset-event-template").
            withParameters(new MapEntry("assetUuid", asset.getUuid())).
                withProgramName("ads-event-test").withSchedule(schedule);
        Program program = m_MissionProgramManager.loadParameters(params);
        program.execute();
        syncer.waitForEvent(5);
        EventHandlerSyncer persistedDataSyncer = 
                new EventHandlerSyncer(m_Context, PersistentDataStore.TOPIC_DATA_PERSISTED);
        Observation o = asset.captureData();
        persistedDataSyncer.waitForEvent(5);
        PersistentDataStore persistentDataStore = ServiceUtils.getService(m_Context, PersistentDataStore.class);
        PersistentData data = persistentDataStore.find(o.getUuid());
        assertThat((String)data.getEntity(), is("mil/dod/th/core/asset/Asset/DATA_CAPTURED"));
        EventHandlerHelper eventHandlerHelper = ServiceUtils.getService(m_Context, EventHandlerHelper.class);
        assertThat(eventHandlerHelper, is(notNullValue()));
        eventHandlerHelper.unregisterAllHandlers();
        syncer = new EventHandlerSyncer(m_Context, PersistentDataStore.TOPIC_DATA_PERSISTED);
        o = asset.captureData();
        syncer.waitForEvent(2, 0, 0); 
        assertThat(persistentDataStore.contains(o.getUuid()), is(false));
    }
@ Test public void testAssetEvent ( ) throws Exception { EventHandlerSyncer syncer = new EventHandlerSyncer ( m_Context , Program . TOPIC_PROGRAM_EXECUTED , String . format ( "(%s=%s)" , Program . EVENT_PROP_PROGRAM_NAME , "ads-event-test" ) ) ; AssetDirectoryService assetDirectoryService = ServiceUtils . getService ( m_Context , AssetDirectoryService . class ) ; Asset asset = assetDirectoryService . createAsset ( ExampleAsset . class . getName ( ) ) ; MissionProgramSchedule schedule = new MissionProgramSchedule ( ) . withIndefiniteInterval ( false ) . withImmediately ( false ) . withActive ( true ) . withAtReset ( true ) ; MissionProgramParameters params = new MissionProgramParameters ( ) . withTemplateName ( "asset-event-template" ) . withParameters ( new MapEntry ( "assetUuid" , asset . getUuid ( ) ) ) . withProgramName ( "ads-event-test" ) . withSchedule ( schedule ) ; Program program = m_MissionProgramManager . loadParameters ( params ) ; program . execute ( ) ; syncer . waitForEvent ( 5 ) ; EventHandlerSyncer persistedDataSyncer = new EventHandlerSyncer ( m_Context , PersistentDataStore . TOPIC_DATA_PERSISTED ) ; Observation o = asset . captureData ( ) ; persistedDataSyncer . waitForEvent ( 5 ) ; PersistentDataStore persistentDataStore = ServiceUtils . getService ( m_Context , PersistentDataStore . class ) ; PersistentData data = persistentDataStore . find ( o . getUuid ( ) ) ; assertThat ( ( String ) data . getEntity ( ) , is ( "mil/dod/th/core/asset/Asset/DATA_CAPTURED" ) ) ; EventHandlerHelper eventHandlerHelper = ServiceUtils . getService ( m_Context , EventHandlerHelper . class ) ; assertThat ( eventHandlerHelper , is ( notNullValue ( ) ) ) ; eventHandlerHelper . unregisterAllHandlers ( ) ; syncer = new EventHandlerSyncer ( m_Context , PersistentDataStore . TOPIC_DATA_PERSISTED ) ; o = asset . captureData ( ) ; syncer . waitForEvent ( 2 , 0 , 0 ) ; assertThat ( persistentDataStore . contains ( o . getUuid ( ) ) , is ( false ) ) ; }
Tests the ability for scripts to receive events from event admin service.
Tests the ability for scripts to receive events from event admin service .
//syncer used to listen for executed event, mission's execute on a separate thread //wait for execute event // wait for 2 seconds to verify event not posted