KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > xml > ActivityReaderTest


1 package org.jbpm.bpel.xml;
2
3 import junit.framework.Assert;
4
5 import org.w3c.dom.Element JavaDoc;
6
7 import org.jbpm.bpel.def.Activity;
8 import org.jbpm.bpel.def.Flow;
9 import org.jbpm.bpel.def.Link;
10
11 /**
12  * Tests the parsing of standard attributes and elements into a bpel activity
13  * using <empty> elements.
14  * @author Juan Cantú
15  * @version $Revision: 1.4 $ $Date: 2005/06/16 19:15:35 $
16  */

17 public class ActivityReaderTest extends AbstractReaderTestCase {
18   
19   public void testProcessDefinition() throws Exception JavaDoc {
20     Activity activity = readActivity("<empty/>");
21     assertEquals(pd, activity.getProcessDefinition());
22   }
23   
24   public void testSuperState() throws Exception JavaDoc {
25     Activity activity = readActivity("<empty/>");
26     assertEquals(scope, activity.getParent());
27   }
28   
29   public void testName() throws Exception JavaDoc {
30     Activity activity = readActivity("<empty name='n'/>");
31     assertEquals("n", activity.getName() );
32   }
33
34   public void testNameDefault() throws Exception JavaDoc {
35     Activity activity = readActivity("<empty/>");
36     assertNull( activity.getName() );
37   }
38
39   public void testSuppressJoinFailureYes() throws Exception JavaDoc {
40     Activity activity = readActivity("<empty suppressJoinFailure='yes'/>");
41     assertEquals( Boolean.TRUE, activity.getSuppressJoinFailure() );
42   }
43
44   public void testSuppressJoinFailureNo() throws Exception JavaDoc {
45     Activity activity = readActivity("<empty suppressJoinFailure='no'/>");
46     assertEquals( Boolean.FALSE, activity.getSuppressJoinFailure() );
47   }
48
49   public void testSuppressJoinFailureDefault() throws Exception JavaDoc {
50     Activity activity = readActivity("<empty/>");
51     assertNull( activity.getSuppressJoinFailure() );
52   }
53   
54   public void testSuppressJoinFailureInheritance() throws Exception JavaDoc {
55     scope.setSuppressJoinFailure(Boolean.TRUE);
56     Activity activity = readActivity("<empty/>");
57     assertEquals( activity.suppressJoinFailure(), scope.suppressJoinFailure() );
58   }
59   
60   public void testSources() throws Exception JavaDoc {
61     String JavaDoc xml =
62       "<empty>" +
63       "<sources>" +
64       " <source linkName='l1'>" +
65       " <transitionCondition>$tc</transitionCondition>" +
66       " </source>" +
67       " <source linkName='l2'/>" +
68       "</sources>" +
69       "</empty>";
70     Flow flow = initFlow();
71     
72     Element JavaDoc element = parseAsBpelElement(xml);
73     Activity activity = readActivity(element, flow);
74
75     //test link resolution
76
Link conditionedLink = activity.getSource("l1");
77     Assert.assertNotNull(conditionedLink);
78     Assert.assertNotNull(activity.getSource("l2"));
79
80     //test transition condition
81
conditionedLink = flow.getLink(conditionedLink.getName());
82     assertEquals("$tc", conditionedLink.getTransitionCondition().getText());
83   }
84   
85   public void testSourcesDefault() throws Exception JavaDoc {
86     Activity activity = readActivity("<empty/>");
87     assertNull(activity.getSources());
88   }
89   
90   public void testTargets() throws Exception JavaDoc {
91     String JavaDoc xml =
92         "<empty>" +
93         "<targets> " +
94         " <joinCondition>'l1'</joinCondition>" +
95         " <target linkName='l1'/>" +
96         " <target linkName='l2'/>" +
97         "</targets>" +
98         "</empty>";
99     Flow flow = initFlow();
100     Element JavaDoc element =
101       parseAsBpelElement(xml);
102     Activity activity = readActivity(element, flow);
103     
104     //test link resolution
105
Assert.assertNotNull(activity.getTarget("l1"));
106     Assert.assertNotNull(activity.getTarget("l2"));
107     
108     //test join condition
109
Assert.assertEquals("'l1'", activity.getJoinCondition().getText());
110   }
111   
112   public void testTargetsDefault() throws Exception JavaDoc {
113     Activity activity = readActivity("<empty/>");
114     assertEquals(null, activity.getTargets());
115   }
116   
117   public void testJoinConditionWithoutTargets() throws Exception JavaDoc {
118     Activity activity = readActivity("<empty><joinCondition>'jc'</joinCondition></empty>");
119     assertNull( activity.getJoinCondition() );
120   }
121
122   public void testJoinConditionDefault() throws Exception JavaDoc {
123     Activity activity = readActivity("<empty/>");
124     assertNull( activity.getJoinCondition() );
125   }
126   
127   private Flow initFlow() {
128     Flow flow = new Flow();
129     flow.setName("f1");
130     Link link1 = new Link("l1");
131     Link link2 = new Link("l2");
132     flow.addLink(link1);
133     flow.addLink(link2);
134     scope.addNode(flow);
135     return flow;
136   }
137 }
Popular Tags