Search in sources :

Example 1 with DefaultScriptEngineResolver

use of org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver in project camunda-engine-dmn by camunda.

the class DefaultDmnEngineConfigurationApiTest method shouldSetScriptEngineResolver.

@Test
public void shouldSetScriptEngineResolver() {
    configuration.setScriptEngineResolver(null);
    assertThat(configuration.getScriptEngineResolver()).isNull();
    DefaultScriptEngineResolver scriptEngineResolver = new DefaultScriptEngineResolver();
    configuration.setScriptEngineResolver(scriptEngineResolver);
    assertThat(configuration.getScriptEngineResolver()).isEqualTo(scriptEngineResolver);
}
Also used : DefaultScriptEngineResolver(org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver) Test(org.junit.Test)

Example 2 with DefaultScriptEngineResolver

use of org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver in project camunda-engine-dmn by camunda.

the class DefaultDmnEngineConfigurationApiTest method shouldBeFluentConfigurable.

@Test
public void shouldBeFluentConfigurable() {
    DefaultEngineMetricCollector metricCollector = new DefaultEngineMetricCollector();
    ArrayList<DmnDecisionTableEvaluationListener> preListeners = new ArrayList<DmnDecisionTableEvaluationListener>();
    preListeners.add(new DefaultEngineMetricCollector());
    ArrayList<DmnDecisionTableEvaluationListener> postListeners = new ArrayList<DmnDecisionTableEvaluationListener>();
    preListeners.add(new DefaultEngineMetricCollector());
    ArrayList<DmnDecisionEvaluationListener> preDecisionListeners = new ArrayList<DmnDecisionEvaluationListener>();
    preDecisionListeners.add(new TestDecisionEvaluationListener());
    ArrayList<DmnDecisionEvaluationListener> postDecisionListeners = new ArrayList<DmnDecisionEvaluationListener>();
    postDecisionListeners.add(new TestDecisionEvaluationListener());
    DefaultScriptEngineResolver scriptEngineResolver = new DefaultScriptEngineResolver();
    ElProvider elProvider = new JuelElProvider();
    FeelEngineFactory feelEngineFactory = new FeelEngineFactoryImpl();
    DmnTransformer transformer = new DefaultDmnTransformer();
    DmnEngine engine = configuration.engineMetricCollector(metricCollector).customPreDecisionTableEvaluationListeners(preListeners).customPostDecisionTableEvaluationListeners(postListeners).customPreDecisionEvaluationListeners(preDecisionListeners).customPostDecisionEvaluationListeners(postDecisionListeners).scriptEngineResolver(scriptEngineResolver).elProvider(elProvider).feelEngineFactory(feelEngineFactory).defaultInputExpressionExpressionLanguage("camunda").defaultInputEntryExpressionLanguage("camunda").defaultOutputEntryExpressionLanguage("camunda").transformer(transformer).buildEngine();
    configuration = (DefaultDmnEngineConfiguration) engine.getConfiguration();
    assertThat(configuration.getEngineMetricCollector()).isEqualTo(metricCollector);
    assertThat(configuration.getCustomPreDecisionTableEvaluationListeners()).containsExactlyElementsOf(preListeners);
    assertThat(configuration.getCustomPostDecisionTableEvaluationListeners()).containsExactlyElementsOf(postListeners);
    assertThat(configuration.getCustomPreDecisionEvaluationListeners()).containsExactlyElementsOf(preDecisionListeners);
    assertThat(configuration.getCustomPostDecisionEvaluationListeners()).containsExactlyElementsOf(postDecisionListeners);
    assertThat(configuration.getScriptEngineResolver()).isEqualTo(scriptEngineResolver);
    assertThat(configuration.getElProvider()).isEqualTo(elProvider);
    assertThat(configuration.getFeelEngineFactory()).isEqualTo(feelEngineFactory);
    assertThat(configuration.getDefaultInputExpressionExpressionLanguage()).isEqualTo("camunda");
    assertThat(configuration.getDefaultInputEntryExpressionLanguage()).isEqualTo("camunda");
    assertThat(configuration.getDefaultOutputEntryExpressionLanguage()).isEqualTo("camunda");
    assertThat(configuration.getTransformer()).isEqualTo(transformer);
}
Also used : DmnDecisionEvaluationListener(org.camunda.bpm.dmn.engine.delegate.DmnDecisionEvaluationListener) ArrayList(java.util.ArrayList) DefaultDmnTransformer(org.camunda.bpm.dmn.engine.impl.transform.DefaultDmnTransformer) DefaultEngineMetricCollector(org.camunda.bpm.dmn.engine.impl.metrics.DefaultEngineMetricCollector) FeelEngineFactory(org.camunda.bpm.dmn.feel.impl.FeelEngineFactory) FeelEngineFactoryImpl(org.camunda.bpm.dmn.feel.impl.juel.FeelEngineFactoryImpl) ElProvider(org.camunda.bpm.dmn.engine.impl.spi.el.ElProvider) JuelElProvider(org.camunda.bpm.dmn.engine.impl.el.JuelElProvider) DefaultDmnEngine(org.camunda.bpm.dmn.engine.impl.DefaultDmnEngine) DmnEngine(org.camunda.bpm.dmn.engine.DmnEngine) JuelElProvider(org.camunda.bpm.dmn.engine.impl.el.JuelElProvider) DefaultDmnTransformer(org.camunda.bpm.dmn.engine.impl.transform.DefaultDmnTransformer) DmnTransformer(org.camunda.bpm.dmn.engine.impl.spi.transform.DmnTransformer) DefaultScriptEngineResolver(org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver) DmnDecisionTableEvaluationListener(org.camunda.bpm.dmn.engine.delegate.DmnDecisionTableEvaluationListener) Test(org.junit.Test)

Example 3 with DefaultScriptEngineResolver

use of org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver in project camunda-engine-dmn by camunda.

the class DefaultDmnEngineConfigurationApiTest method shouldSetFluentScriptEngineResolver.

@Test
public void shouldSetFluentScriptEngineResolver() {
    configuration.scriptEngineResolver(null);
    assertThat(configuration.getScriptEngineResolver()).isNull();
    DefaultScriptEngineResolver scriptEngineResolver = new DefaultScriptEngineResolver();
    configuration.scriptEngineResolver(scriptEngineResolver);
    assertThat(configuration.getScriptEngineResolver()).isEqualTo(scriptEngineResolver);
}
Also used : DefaultScriptEngineResolver(org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver) Test(org.junit.Test)

Example 4 with DefaultScriptEngineResolver

use of org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver in project camunda-engine-dmn by camunda.

the class DefaultScriptEngineResolverTest method testCacheScriptEngine.

@Test
public void testCacheScriptEngine() {
    String scriptLang = "hipster-script";
    ScriptEngineManager mockScriptEngineManager = mock(ScriptEngineManager.class);
    ScriptEngine hipsterScriptEngine = mock(ScriptEngine.class);
    DefaultScriptEngineResolver scriptEngineResolver = new DefaultScriptEngineResolver(mockScriptEngineManager);
    // given
    when(mockScriptEngineManager.getEngineByName(scriptLang)).thenReturn(hipsterScriptEngine);
    // when engine is requested twice
    ScriptEngine engine1 = scriptEngineResolver.getScriptEngineForLanguage(scriptLang);
    ScriptEngine engine2 = scriptEngineResolver.getScriptEngineForLanguage(scriptLang);
    // then it is only created once
    verify(mockScriptEngineManager, times(1)).getEngineByName(scriptLang);
    assertThat(engine1).isSameAs(hipsterScriptEngine);
    assertThat(engine2).isSameAs(engine1);
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) DefaultScriptEngineResolver(org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver) ScriptEngine(javax.script.ScriptEngine) Test(org.junit.Test)

Example 5 with DefaultScriptEngineResolver

use of org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver in project camunda-engine-dmn by camunda.

the class ExpressionCachingTest method setup.

@Before
public void setup() {
    ScriptEngineManager scriptEngineManager = spy(new ScriptEngineManager());
    when(scriptEngineManager.getEngineByName(anyString())).then(new Answer<ScriptEngine>() {

        public ScriptEngine answer(InvocationOnMock invocation) throws Throwable {
            scriptEngineSpy = spy((ScriptEngine) invocation.callRealMethod());
            compilableSpy = (Compilable) scriptEngineSpy;
            return scriptEngineSpy;
        }
    });
    DefaultDmnEngineConfiguration configuration = new DefaultDmnEngineConfiguration();
    configuration.setScriptEngineResolver(new DefaultScriptEngineResolver(scriptEngineManager));
    configuration.init();
    elProviderSpy = spy(configuration.getElProvider());
    configuration.setElProvider(elProviderSpy);
    expressionEvaluationHandler = new ExpressionEvaluationHandler(configuration);
}
Also used : ExpressionEvaluationHandler(org.camunda.bpm.dmn.engine.impl.evaluation.ExpressionEvaluationHandler) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Compilable(javax.script.Compilable) ScriptEngineManager(javax.script.ScriptEngineManager) DefaultScriptEngineResolver(org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver) DefaultDmnEngineConfiguration(org.camunda.bpm.dmn.engine.impl.DefaultDmnEngineConfiguration) ScriptEngine(javax.script.ScriptEngine) Before(org.junit.Before)

Aggregations

DefaultScriptEngineResolver (org.camunda.bpm.dmn.engine.impl.el.DefaultScriptEngineResolver)5 Test (org.junit.Test)4 ScriptEngine (javax.script.ScriptEngine)2 ScriptEngineManager (javax.script.ScriptEngineManager)2 ArrayList (java.util.ArrayList)1 Compilable (javax.script.Compilable)1 DmnEngine (org.camunda.bpm.dmn.engine.DmnEngine)1 DmnDecisionEvaluationListener (org.camunda.bpm.dmn.engine.delegate.DmnDecisionEvaluationListener)1 DmnDecisionTableEvaluationListener (org.camunda.bpm.dmn.engine.delegate.DmnDecisionTableEvaluationListener)1 DefaultDmnEngine (org.camunda.bpm.dmn.engine.impl.DefaultDmnEngine)1 DefaultDmnEngineConfiguration (org.camunda.bpm.dmn.engine.impl.DefaultDmnEngineConfiguration)1 JuelElProvider (org.camunda.bpm.dmn.engine.impl.el.JuelElProvider)1 ExpressionEvaluationHandler (org.camunda.bpm.dmn.engine.impl.evaluation.ExpressionEvaluationHandler)1 DefaultEngineMetricCollector (org.camunda.bpm.dmn.engine.impl.metrics.DefaultEngineMetricCollector)1 ElProvider (org.camunda.bpm.dmn.engine.impl.spi.el.ElProvider)1 DmnTransformer (org.camunda.bpm.dmn.engine.impl.spi.transform.DmnTransformer)1 DefaultDmnTransformer (org.camunda.bpm.dmn.engine.impl.transform.DefaultDmnTransformer)1 FeelEngineFactory (org.camunda.bpm.dmn.feel.impl.FeelEngineFactory)1 FeelEngineFactoryImpl (org.camunda.bpm.dmn.feel.impl.juel.FeelEngineFactoryImpl)1 Before (org.junit.Before)1