-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
script runner tests and ability to capture implicit value of last sta…
…tement
- Loading branch information
1 parent
6eef654
commit d40d862
Showing
2 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import com.nuix.innovation.enginewrapper.RubyScriptRunner; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class RubyScriptRunnerTests { | ||
@Test | ||
public void RunScript() throws Exception { | ||
// Validate that script runs and output is captured | ||
String script = "puts 'hello'"; | ||
List<String> output = new ArrayList<>(); | ||
RubyScriptRunner rubyScriptRunner = new RubyScriptRunner(); | ||
rubyScriptRunner.setStandardOutputConsumer(output::add); | ||
rubyScriptRunner.setErrorOutputConsumer(output::add); | ||
rubyScriptRunner.runScriptAsync(script, "0.0.0.0", Map.of()); | ||
rubyScriptRunner.join(); | ||
assertTrue(output.size() > 0); | ||
} | ||
|
||
@Test | ||
public void ReturnedValue() throws Exception { | ||
// Test that returned value from last statement is captured | ||
String script = "response['sum'] = 10 + 15 + 15 + 2"; | ||
List<String> output = new ArrayList<>(); | ||
RubyScriptRunner rubyScriptRunner = new RubyScriptRunner(); | ||
|
||
rubyScriptRunner.whenScriptCompletes((ret) -> { | ||
assertEquals(42L, ret); | ||
}); | ||
|
||
Map<String, Object> varContainer = new HashMap<>(); | ||
Map<String, Object> response = new HashMap<>(); | ||
varContainer.put("response", response); | ||
|
||
rubyScriptRunner.setStandardOutputConsumer(output::add); | ||
rubyScriptRunner.setErrorOutputConsumer(output::add); | ||
rubyScriptRunner.runScriptAsync(script, "0.0.0.0", varContainer); | ||
rubyScriptRunner.join(); | ||
|
||
assertEquals(42L, response.get("sum")); | ||
} | ||
} |