Search in sources :

Example 1 with SourceExecutableScript

use of org.camunda.bpm.engine.impl.scripting.SourceExecutableScript in project camunda-bpm-platform by camunda.

the class EnvScriptCachingTest method executeScript.

protected void executeScript(final ProcessApplicationInterface processApplication) {
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            return Context.executeWithinProcessApplication(new Callable<Void>() {

                public Void call() throws Exception {
                    ScriptingEngines scriptingEngines = processEngineConfiguration.getScriptingEngines();
                    ScriptEngine scriptEngine = scriptingEngines.getScriptEngineForLanguage(SCRIPT_LANGUAGE);
                    SourceExecutableScript script = createScript(SCRIPT_LANGUAGE, SCRIPT);
                    ScriptingEnvironment scriptingEnvironment = processEngineConfiguration.getScriptingEnvironment();
                    scriptingEnvironment.execute(script, null, null, scriptEngine);
                    return null;
                }
            }, processApplication.getReference());
        }
    });
}
Also used : SourceExecutableScript(org.camunda.bpm.engine.impl.scripting.SourceExecutableScript) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ScriptingEngines(org.camunda.bpm.engine.impl.scripting.engine.ScriptingEngines) ScriptingEnvironment(org.camunda.bpm.engine.impl.scripting.env.ScriptingEnvironment) Callable(java.util.concurrent.Callable) ScriptEngine(javax.script.ScriptEngine)

Example 2 with SourceExecutableScript

use of org.camunda.bpm.engine.impl.scripting.SourceExecutableScript in project camunda-bpm-platform by camunda.

the class ScriptCompilationTest method testDisableScriptCompilationByDisabledScriptEngineCaching.

public void testDisableScriptCompilationByDisabledScriptEngineCaching() {
    // when script engine caching is disabled and a script is created
    processEngineConfiguration.setEnableScriptEngineCaching(false);
    SourceExecutableScript script = createScript(SCRIPT_LANGUAGE, EXAMPLE_SCRIPT);
    assertNotNull(script);
    // then it should not be compiled on creation
    assertTrue(script.isShouldBeCompiled());
    assertNull(script.getCompiledScript());
    // and after first execution
    executeScript(script);
    // it was also not compiled
    assertFalse(script.isShouldBeCompiled());
    assertNull(script.getCompiledScript());
    // re-enable script engine caching
    processEngineConfiguration.setEnableScriptEngineCaching(true);
}
Also used : SourceExecutableScript(org.camunda.bpm.engine.impl.scripting.SourceExecutableScript)

Example 3 with SourceExecutableScript

use of org.camunda.bpm.engine.impl.scripting.SourceExecutableScript in project camunda-bpm-platform by camunda.

the class ScriptCompilationTest method testScriptShouldBeCompiledByDefault.

public void testScriptShouldBeCompiledByDefault() {
    // when a script is created
    SourceExecutableScript script = createScript(SCRIPT_LANGUAGE, EXAMPLE_SCRIPT);
    assertNotNull(script);
    // then it should not be compiled on creation
    assertTrue(script.isShouldBeCompiled());
    assertNull(script.getCompiledScript());
    // but after first execution
    executeScript(script);
    // it was compiled
    assertFalse(script.isShouldBeCompiled());
    assertNotNull(script.getCompiledScript());
}
Also used : SourceExecutableScript(org.camunda.bpm.engine.impl.scripting.SourceExecutableScript)

Example 4 with SourceExecutableScript

use of org.camunda.bpm.engine.impl.scripting.SourceExecutableScript in project camunda-bpm-platform by camunda.

the class ScriptCompilationTest method testOverrideScriptSource.

public void testOverrideScriptSource() {
    // when a script is created and executed
    SourceExecutableScript script = createScript(SCRIPT_LANGUAGE, EXAMPLE_SCRIPT);
    assertNotNull(script);
    executeScript(script);
    // it was compiled
    assertFalse(script.isShouldBeCompiled());
    assertNotNull(script.getCompiledScript());
    // if the script source changes
    script.setScriptSource(EXAMPLE_SCRIPT);
    // then it should not be compiled after change
    assertTrue(script.isShouldBeCompiled());
    assertNull(script.getCompiledScript());
    // but after next execution
    executeScript(script);
    // it is compiled again
    assertFalse(script.isShouldBeCompiled());
    assertNotNull(script.getCompiledScript());
}
Also used : SourceExecutableScript(org.camunda.bpm.engine.impl.scripting.SourceExecutableScript)

Example 5 with SourceExecutableScript

use of org.camunda.bpm.engine.impl.scripting.SourceExecutableScript in project camunda-bpm-platform by camunda.

the class ScriptCompilationTest method testDisableScriptCompilation.

public void testDisableScriptCompilation() {
    // when script compilation is disabled and a script is created
    processEngineConfiguration.setEnableScriptCompilation(false);
    SourceExecutableScript script = createScript(SCRIPT_LANGUAGE, EXAMPLE_SCRIPT);
    assertNotNull(script);
    // then it should not be compiled on creation
    assertTrue(script.isShouldBeCompiled());
    assertNull(script.getCompiledScript());
    // and after first execution
    executeScript(script);
    // it was also not compiled
    assertFalse(script.isShouldBeCompiled());
    assertNull(script.getCompiledScript());
    // re-enable script compilation
    processEngineConfiguration.setEnableScriptCompilation(true);
}
Also used : SourceExecutableScript(org.camunda.bpm.engine.impl.scripting.SourceExecutableScript)

Aggregations

SourceExecutableScript (org.camunda.bpm.engine.impl.scripting.SourceExecutableScript)5 Callable (java.util.concurrent.Callable)1 ScriptEngine (javax.script.ScriptEngine)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1 ScriptingEngines (org.camunda.bpm.engine.impl.scripting.engine.ScriptingEngines)1 ScriptingEnvironment (org.camunda.bpm.engine.impl.scripting.env.ScriptingEnvironment)1