KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > def > ScopeDbTest


1 package org.jbpm.bpel.def;
2
3 import org.jbpm.bpel.data.def.VariableDefinition;
4 import org.jbpm.bpel.db.AbstractDbTestCase;
5 import org.jbpm.bpel.service.def.CorrelationSetDefinition;
6 import org.jbpm.bpel.service.def.PartnerLinkDefinition;
7
8 public class ScopeDbTest extends AbstractDbTestCase {
9   
10   public void testActivity() {
11     BpelDefinition processDefinition = new BpelDefinition();
12     Scope scope = new Scope("scope");
13     processDefinition.getScope().addNode(scope);
14     scope.addNode(new Empty("e"));
15     
16     processDefinition = saveAndReload(processDefinition);
17
18     scope = (Scope) processDefinition.getScope().getNode("scope");
19     assertEquals(scope, scope.getRoot().getCompositeActivity() );
20   }
21   
22   public void testIsolated() {
23     BpelDefinition processDefinition = new BpelDefinition();
24     Scope scope = new Scope("scope");
25     scope.setIsolated(true);
26     processDefinition.addNode(scope);
27
28     processDefinition = saveAndReload(processDefinition);
29
30     scope = (Scope) processDefinition.getNode("scope");
31     assertTrue( scope.isIsolated() );
32   }
33   
34   public void testFaultHandlers() {
35     BpelDefinition processDefinition = new BpelDefinition();
36     Scope scope = processDefinition.getScope();
37     FaultHandler handler = new FaultHandler();
38     handler.setActivity( new Empty("activity") );
39     scope.addFaultHandler( handler );
40     
41     processDefinition = saveAndReload(processDefinition);
42
43     handler = (FaultHandler) processDefinition.getScope().getFaultHandlers().get(0);
44     assertEquals(handler.getCompositeActivity(), processDefinition.getScope());
45     assertNotNull( handler.getActivity() );
46   }
47   
48   public void testTerminationHandler() {
49     BpelDefinition processDefinition = new BpelDefinition();
50     Scope scope = processDefinition.getScope();
51     ScopeHandler handler = new ScopeHandler();
52     handler.setActivity( new Empty("activity") );
53     scope.setHandler( Scope.TERMINATION , handler );
54     
55     processDefinition = saveAndReload(processDefinition);
56
57     handler = processDefinition.getScope().getHandler(Scope.TERMINATION);
58     assertEquals(handler.getCompositeActivity(), processDefinition.getScope());
59     assertNotNull( handler.getActivity() );
60   }
61   
62   public void testCompensationHandler() {
63     BpelDefinition processDefinition = new BpelDefinition();
64     Scope scope = processDefinition.getScope();
65     ScopeHandler handler = new ScopeHandler();
66     handler.setActivity( new Empty("activity") );
67     scope.setHandler( Scope.COMPENSATION, handler );
68     
69     processDefinition = saveAndReload(processDefinition);
70
71     handler = processDefinition.getScope().getHandler(Scope.COMPENSATION);
72     assertEquals(handler.getCompositeActivity(), processDefinition.getScope());
73     assertNotNull( handler.getActivity() );
74   }
75   
76   public void testCatchAllHandler() {
77     BpelDefinition processDefinition = new BpelDefinition();
78     Scope scope = processDefinition.getScope();
79     ScopeHandler handler = new ScopeHandler();
80     handler.setActivity( new Empty("activity") );
81     scope.setHandler( Scope.CATCH_ALL, handler );
82     
83     processDefinition = saveAndReload(processDefinition);
84
85     handler = processDefinition.getScope().getHandler(Scope.CATCH_ALL);
86     assertEquals(handler.getCompositeActivity(), processDefinition.getScope());
87     assertNotNull( handler.getActivity() );
88   }
89   
90   public void testEventHandler() {
91     BpelDefinition processDefinition = new BpelDefinition();
92     Scope scope = processDefinition.getScope();
93     MessageHandler handler = new MessageHandler();
94     Empty eventActivity = new Empty("activity");
95     handler.setActivity( eventActivity );
96     scope.addMessageHandler(handler);
97     
98     processDefinition = saveAndReload(processDefinition);
99
100     handler = (MessageHandler) processDefinition.getScope().getMessageHandlers().iterator().next();
101     assertEquals(handler.getCompositeActivity(), processDefinition.getScope());
102     assertNotNull( handler.getActivity() );
103   }
104   
105   public void testAlarmHandler() {
106     BpelDefinition processDefinition = new BpelDefinition();
107     Scope scope = processDefinition.getScope();
108     AlarmHandler handler = new AlarmHandler();
109     Empty eventActivity = new Empty("activity");
110     handler.setActivity( eventActivity );
111     scope.addAlarmHandler(handler);
112     
113     processDefinition = saveAndReload(processDefinition);
114
115     handler = (AlarmHandler) processDefinition.getScope().getAlarmHandlers().iterator().next();
116     assertEquals(handler.getCompositeActivity(), processDefinition.getScope());
117     assertNotNull( handler.getActivity() );
118   }
119   
120   public void testVariableDefinitions() {
121     BpelDefinition processDefinition = new BpelDefinition();
122     Scope scope = processDefinition.getScope();
123     VariableDefinition variable = new VariableDefinition();
124     variable.setName("aVar");
125     scope.addVariable(variable);
126     
127     processDefinition = saveAndReload(processDefinition);
128
129     assertNotNull( scope.getVariable("aVar") );
130   }
131   
132   public void testPartnerLinkDefinitions() {
133     BpelDefinition processDefinition = new BpelDefinition();
134     Scope scope = processDefinition.getScope();
135     PartnerLinkDefinition plink = new PartnerLinkDefinition();
136     plink.setName("pl");
137     scope.addPartnerLink(plink);
138     
139     processDefinition = saveAndReload(processDefinition);
140
141     assertNotNull( scope.getPartnerLink("pl") );
142   }
143   
144   public void testCorrelationSetDefinitions() {
145     BpelDefinition processDefinition = new BpelDefinition();
146     Scope scope = processDefinition.getScope();
147     CorrelationSetDefinition cs = new CorrelationSetDefinition();
148     cs.setName("cs");
149     scope.addCorrelationSet(cs);
150     
151     processDefinition = saveAndReload(processDefinition);
152
153     assertNotNull( scope.getCorrelationSet("cs") );
154   }
155   
156 }
157
Popular Tags