From 51ab8d82e60bcab40f679ce7fff3430cedd29014 Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Wed, 11 Sep 2024 15:08:14 +0200 Subject: [PATCH] Graalvm JS unit tests - Changed method to private as it only used by ScriptEvaluator class. - Updated graalvm to v22.3.5 --- pom.xml | 2 +- .../org/lsc/utils/ScriptingEvaluator.java | 2 +- .../org/lsc/utils/ScriptingEvaluatorTest.java | 45 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/lsc/utils/ScriptingEvaluatorTest.java diff --git a/pom.xml b/pom.xml index 0df0468d..86697e74 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 2.12.7.1 ${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 895c8fd1..b3683e78 100644 --- a/src/main/java/org/lsc/utils/ScriptingEvaluator.java +++ b/src/main/java/org/lsc/utils/ScriptingEvaluator.java @@ -94,7 +94,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