Skip to content

Commit

Permalink
Graalvm JS unit tests
Browse files Browse the repository at this point in the history
 - Changed method to private as it only used by ScriptEvaluator class.
 - Updated graalvm to v22.3.5
  • Loading branch information
abpai94 committed Sep 12, 2024
1 parent 1e42009 commit 51ab8d8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<staging.dir>${project.build.directory}/staging</staging.dir>
<jmockit-version>1.5</jmockit-version>
<graalvm.version>22.3.1</graalvm.version>
<graalvm.version>22.3.5</graalvm.version>
<jackson.version>2.12.7.1</jackson.version>
<compiler.dir>${project.build.directory}/compiler</compiler.dir>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/lsc/utils/ScriptingEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
45 changes: 45 additions & 0 deletions src/test/java/org/lsc/utils/ScriptingEvaluatorTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 51ab8d8

Please sign in to comment.