KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.xml;
2
3 import java.util.Collection JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Set JavaDoc;
6
7 import javax.xml.namespace.QName JavaDoc;
8
9 import org.w3c.dom.Element JavaDoc;
10
11 import org.jbpm.bpel.data.def.VariableDefinition;
12 import org.jbpm.bpel.def.*;
13 import org.jbpm.bpel.def.Activity;
14 import org.jbpm.bpel.def.Scope;
15 import org.jbpm.bpel.service.def.CorrelationSetDefinition;
16 import org.jbpm.bpel.service.def.PartnerLinkDefinition;
17
18 /**
19  * @author Juan Cantú
20  * @version $Revision: 1.6 $ $Date: 2005/06/16 19:15:35 $
21  */

22 public class ScopeReaderTest extends AbstractReaderTestCase {
23
24   public void setUp() throws Exception JavaDoc {
25     super.setUp();
26     initMessageProperties();
27   }
28   
29   public void testActivity() throws Exception JavaDoc {
30     String JavaDoc xml = "<scope><empty/></scope>";
31     Scope localScope = (Scope) readActivity( xml );
32     Activity root = localScope.getRoot();
33     assertNotNull(root);
34     assertEquals(localScope, root.getCompositeActivity());
35   }
36   
37   public void testScope() throws Exception JavaDoc {
38     String JavaDoc xml = "<scope><empty/></scope>";
39     Scope localScope = (Scope) readActivity( xml );
40     Activity root = localScope.getRoot();
41     assertEquals( localScope, root.getScope() );
42   }
43   
44   public void testIsolated() throws Exception JavaDoc {
45     String JavaDoc xml = "<scope isolated='yes'><empty/></scope>";
46     Scope localScope = (Scope) readActivity( xml );
47     assertTrue( localScope.isIsolated() );
48   }
49   
50   public void testImplicit() throws Exception JavaDoc {
51     String JavaDoc xml = "<scope isolated='yes'><empty/></scope>";
52     Scope localScope = (Scope) readActivity( xml );
53     assertFalse( localScope.isImplicit() );
54     assertTrue( localScope.getScope().isImplicit() );
55   }
56   
57   public void testVariables() throws Exception JavaDoc {
58     String JavaDoc xml =
59      "<scope>" +
60      " <variables>" +
61      " <variable name='v' type='simple'/>" +
62      " </variables>" +
63      " <empty/>" +
64      "</scope>";
65     loadScope( xml );
66     VariableDefinition variable = scope.getVariable("v");
67     assertNotNull(variable);
68   }
69   
70   public void testPartnerLinks() throws Exception JavaDoc {
71     initMessageProperties();
72     String JavaDoc xml =
73       "<scope xmlns:tns='http://manufacturing.org/wsdl/purchase'>" +
74       " <partnerLinks xmlns:vendor='http://jbpm.org'>" +
75       " <partnerLink name='aPartner' partnerLinkType='tns:aPartnerLinkType'" +
76       " partnerRole='role1' myRole='role2'/>" +
77       " </partnerLinks>" +
78       " <receive partnerLink='aPartner' operation='o' variable='iv'/>" +
79       "</scope>";
80     
81     loadScope( xml );
82     PartnerLinkDefinition pl = scope.getPartnerLink("aPartner");
83     assertNotNull( pl );
84   }
85   
86   public void testCorrelationSets() throws Exception JavaDoc {
87     String JavaDoc xml =
88       "<pd xmlns:def='http://manufacturing.org/wsdl/purchase'>" +
89       " <correlationSets>" +
90       " <correlationSet name='cs1' properties='def:p1 def:p2'/>" +
91       " <correlationSet name='cs2' properties='def:p3'/>" +
92       " </correlationSets>" +
93       " <receive partnerLink='aPartner' operation='o' variable='iv'/>" +
94       "</pd>";
95     loadScope( xml );
96     
97     CorrelationSetDefinition cs = scope.getCorrelationSet("cs1");
98     Set JavaDoc properties = cs.getProperties();
99     assertEquals(2, properties.size());
100     assertTrue(properties.contains(p1));
101     assertTrue(properties.contains(p2));
102     
103     CorrelationSetDefinition cs2 = scope.getCorrelationSet("cs2");
104     properties = cs2.getProperties();
105     assertEquals(1, properties.size());
106     assertTrue(properties.contains(p3));
107   }
108   
109   public void testCatches() throws Exception JavaDoc {
110     QName JavaDoc wsdlFaultType = new QName JavaDoc(NS_TNS, "aQName");
111     String JavaDoc xml =
112     "<pd>" +
113     " <receive partnerLink='aPartner' operation='o' variable='iv'/>" +
114     " <faultHandlers xmlns:def='http://manufacturing.org/wsdl/purchase'>" +
115     " <catch faultName='firstFault'><empty name='firstFaultActivity'/></catch>" +
116     " <catch faultName='secondFault' faultVariable='fv' faultMessageType='def:aQName'><empty/></catch>" +
117     " <catch faultName='thirdFault' faultMessageType='def:aQName'><empty/></catch>" +
118     " <catch faultVariable='fourthFault' faultElement='xmlType'><empty/></catch>" +
119     " </faultHandlers>" +
120     "</pd>";
121     
122     loadScope( xml );
123     
124     //test first fault
125
QName JavaDoc firstFaultName = new QName JavaDoc("firstFault");
126     Iterator JavaDoc handlerIt = scope.getFaultHandlers().iterator();
127     FaultHandler firstFaultHandler = (FaultHandler) handlerIt.next();
128
129     assertEquals( firstFaultName, firstFaultHandler.getFaultName() );
130     assertNull( firstFaultHandler.getFaultVariable() );
131     
132     //test second fault
133
QName JavaDoc secondFaultName = new QName JavaDoc("secondFault");
134     FaultHandler secondFaultHandler = (FaultHandler) handlerIt.next();
135     assertEquals( secondFaultName, secondFaultHandler.getFaultName() );
136     assertEquals( wsdlFaultType, secondFaultHandler.getFaultVariable().getTypeInfo().getName() );
137   }
138   
139   public void testCatchAll() throws Exception JavaDoc {
140     String JavaDoc xml =
141       "<pd>" +
142       " <receive partnerLink='aPartner' operation='o' variable='iv'/>" +
143       " <faultHandlers><catchAll><empty name='catchAllActivity'/></catchAll></faultHandlers>" +
144       "</pd>";
145     loadScope( xml );
146     ScopeHandler catchAll = scope.getHandler(Scope.CATCH_ALL);
147     assertNotNull(catchAll);
148     assertEquals("catchAllActivity", catchAll.getActivity().getName());
149   }
150   
151   public void testCompensationHandler() throws Exception JavaDoc {
152     String JavaDoc xml =
153       "<pd>" +
154       " <receive partnerLink='aPartner' operation='o' variable='iv'/>" +
155       " <compensationHandler><empty name='compActivity'/></compensationHandler>" +
156       "</pd>";
157     loadScope( xml );
158     ScopeHandler compensation = scope.getHandler(Scope.COMPENSATION);
159     assertNotNull(compensation);
160     assertEquals("compActivity", compensation.getActivity().getName());
161   }
162   
163   public void testTerminationHandler() throws Exception JavaDoc {
164     String JavaDoc xml =
165       "<pd>" +
166       " <receive partnerLink='aPartner' operation='o' variable='iv'/>" +
167       " <terminationHandler><empty name='activity'/></terminationHandler>" +
168       "</pd>";
169     loadScope( xml );
170     ScopeHandler termination = scope.getHandler(Scope.TERMINATION);
171     assertNotNull(termination);
172     assertEquals("activity", termination.getActivity().getName());
173   }
174   
175   public void testOnAlarm() throws Exception JavaDoc {
176     String JavaDoc xml =
177       "<pd>" +
178       " <receive partnerLink='aPartner' operation='o' variable='iv'/>" +
179       " <eventHandlers>" +
180       " <onAlarm><for>$f</for><empty name='oA1'/></onAlarm>" +
181       " </eventHandlers>" +
182       "</pd>";
183     
184     loadScope( xml );
185     Collection JavaDoc onAlarms = scope.getAlarmHandlers();
186     assertEquals(1, onAlarms.size());
187     AlarmHandler handler = (AlarmHandler) onAlarms.iterator().next();
188     Object JavaDoc activity = handler.getActivity();
189     assertEquals( Empty.class, activity.getClass());
190     assertEquals( "oA1", ((Empty)activity).getName());
191     assertNotNull(handler.getAlarm());
192   }
193   
194   public void testOnEvent() throws Exception JavaDoc {
195     String JavaDoc xml =
196       "<pd>" +
197       " <receive partnerLink='aPartner' operation='o' variable='iv'/>" +
198       " <eventHandlers xmlns:tns='http://manufacturing.org/wsdl/purchase'>" +
199       " <onEvent partnerLink='aPartner' operation='o' variable='v' messageType='tns:aQName'>" +
200       " <correlationSets>" +
201       " <correlationSet name='cs1' properties='tns:p1 tns:p2'/>" +
202       " </correlationSets>" +
203       " <empty name='oM1'/>" +
204       " </onEvent>" +
205       " </eventHandlers>" +
206       "</pd>";
207     loadScope( xml );
208     Collection JavaDoc receivers = scope.getMessageHandlers();
209     assertEquals(1, receivers.size());
210     MessageHandler handler = (MessageHandler) receivers.iterator().next();
211     Object JavaDoc activity = handler.getActivity();
212     //activity
213
assertEquals( Empty.class, activity.getClass());
214     assertEquals( "oM1", ((Empty)activity).getName());
215     //receiver
216
assertNotNull(handler.getReceiver());
217     //correlation set
218
assertNotNull(handler.getCorrelationSet("cs1"));
219     //variable
220
assertEquals("v", handler.getVariableDefinition().getName());
221   }
222   
223   private void loadScope(String JavaDoc xml) throws Exception JavaDoc {
224     Element JavaDoc element = parseAsBpelElement(xml);
225     reader.readScope(element, scope);
226   }
227 }
Popular Tags