blob: 03a9151a4788579d3fbcf432fb6946a529fed7e0 (
plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
|
package org.apache.tuscany.container.python;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.isA;
import static org.easymock.EasyMock.replay;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.ScopeContainer;
import org.apache.tuscany.spi.model.Scope;
import org.easymock.IAnswer;
public class PythonInvokerTestCase extends TestCase {
private PythonComponent context;
private Method method;
private ScopeContainer scopeContainer;
public void testInvokeTarget() throws InvocationTargetException {
PythonInvoker invoker = new PythonInvoker(method, context);
Object o = invoker.invokeTarget(new Object[] { "petra" });
assertEquals("hello petra", o);
}
public void testInvokeTargetException() throws InvocationTargetException, SecurityException, NoSuchMethodException {
PythonInvoker invoker = new PythonInvoker(method, context);
try {
invoker.invokeTarget(null);
fail();
} catch (InvocationTargetException e) {
// expected
}
}
@SuppressWarnings("unchecked")
protected void setUp() throws Exception {
super.setUp();
scopeContainer = createMock(ScopeContainer.class);
expect(scopeContainer.getInstance(isA(AtomicComponent.class))).andStubAnswer(new IAnswer() {
public Object answer() throws Throwable {
return "hello ";
}
});
expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
public Object answer() throws Throwable {
return Scope.MODULE;
}
});
replay(scopeContainer);
context = new PythonComponent(null, null, null, null, scopeContainer, null, null);
method = String.class.getDeclaredMethod("concat", new Class[] { String.class });
}
}
|