forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestExceptionInvocable.java
More file actions
50 lines (41 loc) · 1.29 KB
/
Copy pathTestExceptionInvocable.java
File metadata and controls
50 lines (41 loc) · 1.29 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
42
43
44
45
46
47
48
49
50
package php.java.test;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import junit.framework.TestCase;
public class TestExceptionInvocable extends TestCase {
public TestExceptionInvocable(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void test() throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine e = manager.getEngineByName("php-invocable");
OutputStream out = new ByteArrayOutputStream();
Writer w = new OutputStreamWriter(out);
e.getContext().setWriter(w);
e.getContext().setErrorWriter(w);
e.eval("<?php function f() { throw new JavaException('java.io.IOException'); };?>");
Invocable i = (Invocable) e;
try {
i.invokeFunction("f", new Object[] {});
} catch (ScriptException ex) {
((Closeable)e).close();
if (out.toString().length() != 0) throw new Exception("test failed");
return;
}
((Closeable)e).close();
fail("test failed");
}
}