01: package test;
02:
03: import dalma.test.WorkflowTestProgram;
04: import dalma.ErrorHandler;
05: import junit.textui.TestRunner;
06:
07: import java.io.Serializable;
08:
09: /**
10: * Makes sure that an error in a conversation kills a conversation cleanly.
11: * @author Kohsuke Kawaguchi
12: */
13: public class ConversationDeathTest extends WorkflowTestProgram {
14: public ConversationDeathTest(String name) {
15: super (name);
16: }
17:
18: public static void main(String[] args) {
19: TestRunner.run(ConversationDeathTest.class);
20: }
21:
22: protected void setupEndPoints() throws Exception {
23: // no endpoint to set up
24: }
25:
26: Throwable reportedError;
27:
28: public void test() throws Exception {
29: engine.setErrorHandler(new ErrorHandler() {
30: public void onError(Throwable t) {
31: // make sure that the error is reported before the completion
32: try {
33: Thread.sleep(1000);
34: } catch (InterruptedException e) {
35: e.printStackTrace();
36: }
37: System.out.println("error reported");
38: reportedError = t;
39: }
40: });
41:
42: createConversation(ErrorConversation.class);
43: engine.waitForCompletion();
44: assert reportedError instanceof UnsupportedOperationException;
45: }
46:
47: private static final class ErrorConversation implements Runnable,
48: Serializable {
49: public ErrorConversation() {
50: }
51:
52: public void run() {
53: System.out.println("Going to die");
54: throw new UnsupportedOperationException();
55: }
56: }
57: }
|