mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramManagerImpl.java
@Test
    public void testActivateAutoExecuteProg1AssetMissing() throws ScriptException,
        IllegalArgumentException, MissionProgramException
    {
        // mock
        mockMissionProgramPersistentData();
        mockTemplates();
        
        Asset mockAsset = mock(Asset.class);
        TransportLayer mockTrans = mock(TransportLayer.class);
        // make assetX and tl7 available
        when(m_AssetDirectoryService.isAssetAvailable("assetX")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("assetX")).thenReturn(mockAsset);
        when(m_CustomCommsService.isTransportLayerCreated("tl7")).thenReturn(true);
        when(m_CustomCommsService.getTransportLayer("tl7")).thenReturn(mockTrans);
        when(m_AssetDirectoryService.isAssetAvailable("asset3")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("asset3")).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 assetZ available
        when(m_AssetDirectoryService.isAssetAvailable("assetZ")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("assetZ")).thenReturn(mockAsset);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_NAME, "assetZ");
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_BASE_TYPE, "Asset");
        m_EventHandlerAnswer.getHandler().handleEvent(new Event(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED, props));
        
        // verify now called
        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 (asset 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 (asset 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 ( asset dependency ) are satisfied .
@Test
    public void testActivateAutoExecuteProg1AssetMissing() 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.getAssetByName("assetX")).thenReturn(mockAsset);
        when(m_CustomCommsService.isTransportLayerCreated("tl7")).thenReturn(true);
        when(m_CustomCommsService.getTransportLayer("tl7")).thenReturn(mockTrans);
        when(m_AssetDirectoryService.isAssetAvailable("asset3")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("asset3")).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("assetZ")).thenReturn(true);
        when(m_AssetDirectoryService.getAssetByName("assetZ")).thenReturn(mockAsset);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(FactoryDescriptor.EVENT_PROP_OBJ_NAME, "assetZ");
        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("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 testActivateAutoExecuteProg1AssetMissing ( ) 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 . getAssetByName ( "assetX" ) ) . thenReturn ( mockAsset ) ; when ( m_CustomCommsService . isTransportLayerCreated ( "tl7" ) ) . thenReturn ( true ) ; when ( m_CustomCommsService . getTransportLayer ( "tl7" ) ) . thenReturn ( mockTrans ) ; when ( m_AssetDirectoryService . isAssetAvailable ( "asset3" ) ) . thenReturn ( true ) ; when ( m_AssetDirectoryService . getAssetByName ( "asset3" ) ) . 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 ( "assetZ" ) ) . thenReturn ( true ) ; when ( m_AssetDirectoryService . getAssetByName ( "assetZ" ) ) . thenReturn ( mockAsset ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( FactoryDescriptor . EVENT_PROP_OBJ_NAME , "assetZ" ) ; 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 ( "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 // make assetX and tl7 available // verify still not executed // make assetZ available // verify now called