mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramManagerImpl.java
@Test
    public void testActivateAutoExecuteProg1ProgramMissing() throws ScriptException,
        IllegalArgumentException, MissionProgramException
    {
        // mock
        mockMissionProgramPersistentData();
        mockTemplates();
        
        //mock asset and transport layer
        Asset mockAsset = mock(Asset.class);
        TransportLayer mockTrans = mock(TransportLayer.class);
        // make assetX,Z and transport tl7 available
        when(m_AssetDirectoryService.isAssetAvailable("assetX")).thenReturn(true);
        when(m_AssetDirectoryService.isAssetAvailable("assetZ")).thenReturn(true);
        when(m_CustomCommsService.isTransportLayerCreated("tl7")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("assetX")).thenReturn(mockAsset);
        when(m_CustomCommsService.getTransportLayer("tl7")).thenReturn(mockTrans);
        when(m_AssetDirectoryService.getAssetByName("assetZ")).thenReturn(mockAsset);
        
        MissionScript missionMock = mock(MissionScript.class);
        when(m_ScriptEngine.eval(eq("test"), Mockito.any(Bindings.class))).thenReturn(new Object());
        when(((Invocable) m_ScriptEngine).getInterface(any(), eq(MissionScript.class))).thenReturn(missionMock);

        setScriptEngineAndActivate();
        
        // verify still not executed
        ArgumentCaptor<ScriptContext> context = ArgumentCaptor.forClass(ScriptContext.class);
        verify(m_ScriptEngine, never()).eval(eq("test"), context.capture());
        
        // make asset3 available
        when(m_AssetDirectoryService.isAssetAvailable("asset3")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("asset3")).thenReturn(mockAsset);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_NAME, "asset3");
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_BASE_TYPE, "Asset");
        m_EventHandlerAnswer.getHandler().handleEvent(new Event(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED, props));
        
        // verify script 3 ran as well as script 1 since it depends on it
        verify(m_ScriptEngine, times(1)).eval(eq("something"), context.capture());
        verify(m_ScriptEngine, times(1)).eval(eq("test"), context.capture());
        assertThat((Integer)context.getValue().getBindings(ScriptContext.ENGINE_SCOPE).get("argA"), is(88));
        assertThat((String)context.getValue().getBindings(ScriptContext.ENGINE_SCOPE).get("argB"), is("arg-b-value"));
    }
/**
     * Test that the script engine will not initialize a script or execute the script until the deps are satisfied.
     * 
     * Verify that that script successfully initializes and executes once the deps (program dependency) are satisfied.
     */
Test that the script engine will not initialize a script or execute the script until the deps are satisfied.

Verify that that script successfully initializes and executes once the deps (program dependency) are satisfied.
Test that the script engine will not initialize a script or execute the script until the deps are satisfied . Verify that that script successfully initializes and executes once the deps ( program dependency ) are satisfied .
@Test
    public void testActivateAutoExecuteProg1ProgramMissing() throws ScriptException,
        IllegalArgumentException, MissionProgramException
    {
        mockMissionProgramPersistentData();
        mockTemplates();
        Asset mockAsset = mock(Asset.class);
        TransportLayer mockTrans = mock(TransportLayer.class);
        when(m_AssetDirectoryService.isAssetAvailable("assetX")).thenReturn(true);
        when(m_AssetDirectoryService.isAssetAvailable("assetZ")).thenReturn(true);
        when(m_CustomCommsService.isTransportLayerCreated("tl7")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("assetX")).thenReturn(mockAsset);
        when(m_CustomCommsService.getTransportLayer("tl7")).thenReturn(mockTrans);
        when(m_AssetDirectoryService.getAssetByName("assetZ")).thenReturn(mockAsset);
        MissionScript missionMock = mock(MissionScript.class);
        when(m_ScriptEngine.eval(eq("test"), Mockito.any(Bindings.class))).thenReturn(new Object());
        when(((Invocable) m_ScriptEngine).getInterface(any(), eq(MissionScript.class))).thenReturn(missionMock);
        setScriptEngineAndActivate();
        ArgumentCaptor<ScriptContext> context = ArgumentCaptor.forClass(ScriptContext.class);
        verify(m_ScriptEngine, never()).eval(eq("test"), context.capture());
        when(m_AssetDirectoryService.isAssetAvailable("asset3")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("asset3")).thenReturn(mockAsset);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_NAME, "asset3");
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_BASE_TYPE, "Asset");
        m_EventHandlerAnswer.getHandler().handleEvent(new Event(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED, props));
        verify(m_ScriptEngine, times(1)).eval(eq("something"), context.capture());
        verify(m_ScriptEngine, times(1)).eval(eq("test"), context.capture());
        assertThat((Integer)context.getValue().getBindings(ScriptContext.ENGINE_SCOPE).get("argA"), is(88));
        assertThat((String)context.getValue().getBindings(ScriptContext.ENGINE_SCOPE).get("argB"), is("arg-b-value"));
    }
@ Test public void testActivateAutoExecuteProg1ProgramMissing ( ) throws ScriptException , IllegalArgumentException , MissionProgramException { mockMissionProgramPersistentData ( ) ; mockTemplates ( ) ; Asset mockAsset = mock ( Asset . class ) ; TransportLayer mockTrans = mock ( TransportLayer . class ) ; when ( m_AssetDirectoryService . isAssetAvailable ( "assetX" ) ) . thenReturn ( true ) ; when ( m_AssetDirectoryService . isAssetAvailable ( "assetZ" ) ) . thenReturn ( true ) ; when ( m_CustomCommsService . isTransportLayerCreated ( "tl7" ) ) . thenReturn ( true ) ; when ( m_AssetDirectoryService . getAssetByName ( "assetX" ) ) . thenReturn ( mockAsset ) ; when ( m_CustomCommsService . getTransportLayer ( "tl7" ) ) . thenReturn ( mockTrans ) ; when ( m_AssetDirectoryService . getAssetByName ( "assetZ" ) ) . thenReturn ( mockAsset ) ; MissionScript missionMock = mock ( MissionScript . class ) ; when ( m_ScriptEngine . eval ( eq ( "test" ) , Mockito . any ( Bindings . class ) ) ) . thenReturn ( new Object ( ) ) ; when ( ( ( Invocable ) m_ScriptEngine ) . getInterface ( any ( ) , eq ( MissionScript . class ) ) ) . thenReturn ( missionMock ) ; setScriptEngineAndActivate ( ) ; ArgumentCaptor < ScriptContext > context = ArgumentCaptor . forClass ( ScriptContext . class ) ; verify ( m_ScriptEngine , never ( ) ) . eval ( eq ( "test" ) , context . capture ( ) ) ; when ( m_AssetDirectoryService . isAssetAvailable ( "asset3" ) ) . thenReturn ( true ) ; when ( m_AssetDirectoryService . getAssetByName ( "asset3" ) ) . thenReturn ( mockAsset ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( FactoryDescriptor . EVENT_PROP_OBJ_NAME , "asset3" ) ; props . put ( FactoryDescriptor . EVENT_PROP_OBJ_BASE_TYPE , "Asset" ) ; m_EventHandlerAnswer . getHandler ( ) . handleEvent ( new Event ( FactoryDescriptor . TOPIC_FACTORY_OBJ_CREATED , props ) ) ; verify ( m_ScriptEngine , times ( 1 ) ) . eval ( eq ( "something" ) , context . capture ( ) ) ; verify ( m_ScriptEngine , times ( 1 ) ) . eval ( eq ( "test" ) , context . capture ( ) ) ; assertThat ( ( Integer ) context . getValue ( ) . getBindings ( ScriptContext . ENGINE_SCOPE ) . get ( "argA" ) , is ( 88 ) ) ; assertThat ( ( String ) context . getValue ( ) . getBindings ( ScriptContext . ENGINE_SCOPE ) . get ( "argB" ) , is ( "arg-b-value" ) ) ; }
Test that the script engine will not initialize a script or execute the script until the deps are satisfied.
Test that the script engine will not initialize a script or execute the script until the deps are satisfied .
// mock //mock asset and transport layer // make assetX,Z and transport tl7 available // verify still not executed // make asset3 available // verify script 3 ran as well as script 1 since it depends on it