Skip to content

Commit

Permalink
Changed method to private as it only used by ScriptEvaluator class.
Browse files Browse the repository at this point in the history
JUnit tests for graalvm js script evaluator.
  • Loading branch information
abpai94 committed Sep 12, 2024
1 parent 1e42009 commit 3a61b7b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
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 3a61b7b

Please sign in to comment.