diff --git a/pom.xml b/pom.xml index cff4f867..43959bdb 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ UTF-8 ${project.build.directory}/staging 1.5 - 22.3.1 + 22.3.5 ${project.build.directory}/compiler diff --git a/src/main/java/org/lsc/utils/ScriptingEvaluator.java b/src/main/java/org/lsc/utils/ScriptingEvaluator.java index b69c3b88..ebf3d3e4 100644 --- a/src/main/java/org/lsc/utils/ScriptingEvaluator.java +++ b/src/main/java/org/lsc/utils/ScriptingEvaluator.java @@ -96,7 +96,7 @@ else if ("graal.js".equals(name)) { } } - public static ScriptingEvaluator getInstance() { + private static ScriptingEvaluator getInstance() { String threadName = Thread.currentThread().getName(); ScriptingEvaluator scriptingEvaluator = null; diff --git a/src/test/java/org/lsc/utils/ScriptingEvaluatorTest.java b/src/test/java/org/lsc/utils/ScriptingEvaluatorTest.java new file mode 100644 index 00000000..9345397b --- /dev/null +++ b/src/test/java/org/lsc/utils/ScriptingEvaluatorTest.java @@ -0,0 +1,45 @@ +package org.lsc.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import mockit.Mocked; +import mockit.NonStrictExpectations; +import org.junit.Before; +import org.junit.Test; +import org.lsc.Task; +import org.lsc.configuration.*; +import org.lsc.exception.LscServiceConfigurationException; +import org.lsc.exception.LscServiceException; +import org.lsc.jndi.SimpleJndiSrcService; + +import java.util.*; + +public class ScriptingEvaluatorTest { + + @Mocked Task task; + + @Before + public void setUp() throws LscServiceConfigurationException { + new NonStrictExpectations() { + { + TaskType taskConf = LscConfiguration.getTask("ldap2ldapTestTask"); + task.getSourceService(); result = new SimpleJndiSrcService(taskConf); + } + }; + } + + @Test + public void testString() throws LscServiceException { + String expression = "gjs:dn='ou=test-user' + ',ou=people,dc=example,dc=com'"; + String stringOutput = ScriptingEvaluator.evalToString(task, expression, new HashMap<>()); + assertEquals("ou=test-user,ou=people,dc=example,dc=com", stringOutput); + } + + @Test + public void testBoolean() throws LscServiceException { + String expression = "gjs:booleanVariable=true"; + boolean booleanOutput = ScriptingEvaluator.evalToBoolean(task, expression, new HashMap<>()); + assertTrue(booleanOutput); + } +} \ No newline at end of file