forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestScript.java
More file actions
41 lines (31 loc) · 1.09 KB
/
Copy pathTestScript.java
File metadata and controls
41 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package php.java.test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import junit.framework.TestCase;
public class TestScript extends TestCase {
public TestScript(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void test() throws IOException, ScriptException {
ScriptEngine eng = (new ScriptEngineManager()).getEngineByName("php");
OutputStream out = new ByteArrayOutputStream();
Writer w = new OutputStreamWriter(out);
eng.getContext().setWriter(w);
eng.getContext().setErrorWriter(w);
eng.eval("<?php if(java_is_true(java_context()->call(java_closure()))) print('test okay'); ?>");
eng.eval((String)null);
assertTrue("test okay".equals(String.valueOf(out)));
}
}