KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > exe > ActionExceptionsTest


1 package org.jbpm.graph.exe;
2
3 import junit.framework.TestCase;
4
5 import org.jbpm.graph.def.ActionHandler;
6 import org.jbpm.graph.def.ProcessDefinition;
7
8 public class ActionExceptionsTest extends TestCase {
9
10   public static class FailingAction implements ActionHandler {
11     private static final long serialVersionUID = 1L;
12     public void execute(ExecutionContext context) {
13       throw new IllegalArgumentException JavaDoc();
14     }
15   }
16
17   public void testFailingReferenced() throws Exception JavaDoc {
18     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
19       "<process-definition>" +
20       " <start-state name='start'>" +
21       " <transition to='state'/>" +
22       " </start-state>" +
23       " <state name='state'>" +
24       " <transition to='end'>" +
25       " <action ref-name='failing'/>" +
26       " </transition>"+
27       " </state>" +
28       " <end-state name='end'/>" +
29       " <action name='failing' class='org.jbpm.graph.exe.ActionExceptionsTest$FailingAction'/>"+
30       "</process-definition>");
31     ProcessInstance pi = new ProcessInstance(processDefinition);
32
33     pi.signal();
34     try {
35       pi.signal();
36     } catch (RuntimeException JavaDoc e) {
37       e.printStackTrace();
38       // ObjectAssert.assertInstanceOf(IllegalArgumentException.class,
39
// e.getCause());
40
assertTrue(e.getCause() instanceof IllegalArgumentException JavaDoc);
41       return;
42     }
43     fail("should have throws IllegalArgumentException");
44   }
45
46   public void testFailingNotReferenced() throws Exception JavaDoc {
47     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
48       "<process-definition>" +
49       " <start-state name='start'>" +
50       " <transition to='state'/>" +
51       " </start-state>" +
52       " <state name='state'>" +
53       " <transition to='end'>" +
54       " <action class='org.jbpm.graph.exe.ActionExceptionsTest$FailingAction'/>" +
55       " </transition>" +
56       " </state>" +
57       " <end-state name='end'/>" +
58       "</process-definition>");
59     ProcessInstance pi = new ProcessInstance(processDefinition);
60
61     pi.signal();
62     try {
63       pi.signal();
64     } catch (RuntimeException JavaDoc e) {
65       e.printStackTrace();
66       // ObjectAssert.assertInstanceOf(IllegalArgumentException.class,
67
// e.getCause());
68
assertTrue(e.getCause() instanceof IllegalArgumentException JavaDoc);
69       return;
70     }
71     fail("should have throws IllegalArgumentException");
72   }
73
74 }
75
Popular Tags