1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.grinder.scriptengine.jython.instrumentation.dcr;
23
24 import static org.junit.Assert.assertEquals;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import net.grinder.engine.process.dcr.DCRContextImplementation;
30 import net.grinder.scriptengine.CompositeInstrumenter;
31 import net.grinder.scriptengine.Instrumenter;
32 import net.grinder.scriptengine.java.JavaScriptEngineService;
33 import net.grinder.testutility.Jython25Runner;
34 import net.grinder.testutility.RandomStubFactory;
35
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.python.core.PyObject;
39 import org.python.core.PyProxy;
40
41
42
43
44
45
46
47 @RunWith(Jython25Runner.class)
48 public class TestJython25Instrumenter
49 extends AbstractJythonDCRInstrumenterTestCase {
50
51 private static Instrumenter createInstrumenter() throws Exception {
52 final List<Instrumenter> instrumenters = new ArrayList<Instrumenter>();
53
54 instrumenters.add(
55 new Jython25Instrumenter(DCRContextImplementation.create(null)));
56
57 instrumenters.addAll(
58 new JavaScriptEngineService(DCRContextImplementation.create(null))
59 .createInstrumenters());
60
61 return new CompositeInstrumenter(instrumenters);
62 }
63
64 public TestJython25Instrumenter() throws Exception {
65 super(createInstrumenter());
66 }
67
68 @Test public void testVersion() throws Exception {
69 assertVersion("2.5");
70 }
71
72 @Test public void testBrokenPyProxy() throws Exception {
73 final RandomStubFactory<PyProxy> pyProxyStubFactory =
74 RandomStubFactory.create(PyProxy.class);
75 final PyProxy pyProxy = pyProxyStubFactory.getStub();
76
77 assertNotWrappable(pyProxy);
78 }
79
80 @Test public void testCreateProxyWithJavaClassAnd__call__() throws Exception {
81 m_interpreter.exec("from grinder.test import MyClass");
82 final PyObject pyJavaType = m_interpreter.get("MyClass");
83 createInstrumentedProxy(m_test, m_recorder, pyJavaType);
84
85 m_interpreter.exec("result2 = MyClass.__call__(1, 2, 3)");
86 final PyObject result2 = m_interpreter.get("result2");
87 assertEquals(m_one, result2.invoke("getA"));
88 m_recorderStubFactory.assertSuccess("start");
89 m_recorderStubFactory.assertSuccess("end", true);
90 m_recorderStubFactory.assertNoMoreCalls();
91 }
92 }