forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestInvocable.java
More file actions
38 lines (27 loc) · 942 Bytes
/
Copy pathTestInvocable.java
File metadata and controls
38 lines (27 loc) · 942 Bytes
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
package php.java.test;
import java.io.Reader;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import junit.framework.TestCase;
public class TestInvocable extends TestCase {
public TestInvocable(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");
e.eval("<?php class f {function a($p) {return java_values($p)+1;}}\n" +
"java_context()->setAttribute('f', java_closure(new f()), 100); ?>");
Invocable i = (Invocable)e;
Object f = e.getContext().getAttribute("f", 100);
assertTrue(2==(Integer)i.invokeMethod(f, "a", new Object[] {new Integer(1)}));
e.eval((Reader)null);
}
}