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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations