mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramManagerImpl.java
@Test
    public void testActivateAutoExecuteProg1TransportLayerMissing() 
        throws ScriptException, IllegalArgumentException, MissionProgramException
    {
        // mock
        mockMissionProgramPersistentData();
        mockTemplates();
        
        //mock asset
        Asset mockAsset = mock(Asset.class);
        // make assetX and assetZ available
        when(m_AssetDirectoryService.isAssetAvailable("assetX")).thenReturn(true);
        when(m_AssetDirectoryService.isAssetAvailable("assetZ")).thenReturn(true);
        when(m_AssetDirectoryService.isAssetAvailable("asset3")).thenReturn(true);
        //mock return values for dep fulfillment
        when(m_AssetDirectoryService.getAssetByName("assetX")).thenReturn(mockAsset);
        when(m_AssetDirectoryService.getAssetByName("asset3")).thenReturn(mockAsset);
        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());
        
        //mock transport layer
        TransportLayer mockTrans = mock(TransportLayer.class);
        
        // make transport layer available
        when(m_CustomCommsService.isTransportLayerCreated("tl7")).thenReturn(true);
        when(m_CustomCommsService.getTransportLayer("tl7")).thenReturn(mockTrans);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_NAME, "tl7");
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_BASE_TYPE, "TransportLayer");
        m_EventHandlerAnswer.getHandler().handleEvent(new Event(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED, props));
        
        // verify finally executed
        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"));
        
        // verify not called again
        verify(m_ScriptEngine, times(1)).eval(eq("test"), context.capture());
    }
/**
     * 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 (Transport Layer) 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 (Transport Layer) 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 ( Transport Layer ) are satisfied .
@Test
    public void testActivateAutoExecuteProg1TransportLayerMissing() 
        throws ScriptException, IllegalArgumentException, MissionProgramException
    {
        mockMissionProgramPersistentData();
        mockTemplates();
        Asset mockAsset = mock(Asset.class);
        when(m_AssetDirectoryService.isAssetAvailable("assetX")).thenReturn(true);
        when(m_AssetDirectoryService.isAssetAvailable("assetZ")).thenReturn(true);
        when(m_AssetDirectoryService.isAssetAvailable("asset3")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("assetX")).thenReturn(mockAsset);
        when(m_AssetDirectoryService.getAssetByName("asset3")).thenReturn(mockAsset);
        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());
        TransportLayer mockTrans = mock(TransportLayer.class);
        when(m_CustomCommsService.isTransportLayerCreated("tl7")).thenReturn(true);
        when(m_CustomCommsService.getTransportLayer("tl7")).thenReturn(mockTrans);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_NAME, "tl7");
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_BASE_TYPE, "TransportLayer");
        m_EventHandlerAnswer.getHandler().handleEvent(new Event(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED, props));
        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"));
        verify(m_ScriptEngine, times(1)).eval(eq("test"), context.capture());
    }
@ Test public void testActivateAutoExecuteProg1TransportLayerMissing ( ) throws ScriptException , IllegalArgumentException , MissionProgramException { mockMissionProgramPersistentData ( ) ; mockTemplates ( ) ; Asset mockAsset = mock ( Asset . class ) ; when ( m_AssetDirectoryService . isAssetAvailable ( "assetX" ) ) . thenReturn ( true ) ; when ( m_AssetDirectoryService . isAssetAvailable ( "assetZ" ) ) . thenReturn ( true ) ; when ( m_AssetDirectoryService . isAssetAvailable ( "asset3" ) ) . thenReturn ( true ) ; when ( m_AssetDirectoryService . getAssetByName ( "assetX" ) ) . thenReturn ( mockAsset ) ; when ( m_AssetDirectoryService . getAssetByName ( "asset3" ) ) . thenReturn ( mockAsset ) ; 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 ( ) ) ; TransportLayer mockTrans = mock ( TransportLayer . class ) ; when ( m_CustomCommsService . isTransportLayerCreated ( "tl7" ) ) . thenReturn ( true ) ; when ( m_CustomCommsService . getTransportLayer ( "tl7" ) ) . thenReturn ( mockTrans ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( FactoryDescriptor . EVENT_PROP_OBJ_NAME , "tl7" ) ; props . put ( FactoryDescriptor . EVENT_PROP_OBJ_BASE_TYPE , "TransportLayer" ) ; m_EventHandlerAnswer . getHandler ( ) . handleEvent ( new Event ( FactoryDescriptor . TOPIC_FACTORY_OBJ_CREATED , props ) ) ; 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" ) ) ; verify ( m_ScriptEngine , times ( 1 ) ) . eval ( eq ( "test" ) , context . capture ( ) ) ; }
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 // make assetX and assetZ available //mock return values for dep fulfillment // verify still not executed //mock transport layer // make transport layer available // verify finally executed // verify not called again