KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.def;
2
3 import javax.wsdl.Message;
4 import javax.wsdl.Part;
5 import javax.xml.namespace.QName JavaDoc;
6
7 import junit.framework.TestCase;
8
9 import org.jbpm.bpel.data.def.ElementTypeInfo;
10 import org.jbpm.bpel.data.def.MessageTypeInfo;
11 import org.jbpm.bpel.data.def.VariableDefinition;
12 import org.jbpm.bpel.exe.Fault;
13 import org.jbpm.bpel.xml.BpelConstants;
14
15 import com.ibm.wsdl.MessageImpl;
16 import com.ibm.wsdl.PartImpl;
17
18 /**
19  * @author Juan Cantu
20  * @version $Revision: 1.3 $ $Date: 2005/06/17 01:29:11 $
21  */

22 public class ScopeDefTest extends TestCase {
23
24   Scope scope;
25   Fault fault;
26   FaultHandler catchName = new FaultHandler();
27   FaultHandler catchMessage = new FaultHandler();
28   FaultHandler catchNameMessage = new FaultHandler();
29   FaultHandler catchElement = new FaultHandler();
30   FaultHandler catchNameElement = new FaultHandler();
31   FaultHandler catchAll = new FaultHandler();
32
33   static final QName JavaDoc NON_MATCHING_NAME = new QName JavaDoc(BpelConstants.NS_EXAMPLES, "unexpected");
34   
35   public void setUp() {
36     scope = new Scope();
37     
38     QName JavaDoc faultName = new QName JavaDoc(BpelConstants.NS_EXAMPLES, "aFault");
39     
40     catchName.setFaultName(faultName);
41     scope.addFaultHandler(catchName);
42      
43     QName JavaDoc elementName = new QName JavaDoc(BpelConstants.NS_EXAMPLES, "anElement");
44
45     VariableDefinition elementVariable = new VariableDefinition("anElementVariable");
46     elementVariable.setTypeInfo(new ElementTypeInfo(elementName));
47     
48     catchElement.setFaultVariable(elementVariable);
49     scope.addFaultHandler(catchElement);
50     
51     /* handlers with faultName have priority over handlers without faultName in the case of a fault
52      * with a matching faultName; add handler with faultName later to verify this */

53     catchNameElement.setFaultName(faultName);
54     catchNameElement.setFaultVariable(elementVariable);
55     scope.addFaultHandler(catchNameElement);
56     
57     /* handlers with a faultVariable of message type have priority over handlers with a faultVariable
58      * of type element in the case of a fault with a matching message that contains a single part
59      * defined by a matching element; add handlers with a message type later to verify this */

60     Part part = new PartImpl();
61     part.setName("aPart");
62     part.setElementName(elementName);
63
64     Message message = new MessageImpl();
65     message.setQName(new QName JavaDoc(BpelConstants.NS_EXAMPLES, "aMessage"));
66     message.addPart(part);
67     
68     VariableDefinition messageVariable = new VariableDefinition("aMessageVariable");
69     messageVariable.setTypeInfo(new MessageTypeInfo(message));
70
71     catchMessage.setFaultVariable(messageVariable);
72     scope.addFaultHandler(catchMessage);
73     
74     /* handlers with faultName have priority over handlers without faultName in the case of a fault
75      * with a matching faultName; add handler with faultName later to verify this */

76     catchNameMessage.setFaultName(faultName);
77     catchNameMessage.setFaultVariable(messageVariable);
78     scope.addFaultHandler(catchNameMessage);
79   }
80   
81   /* In the case of faults thrown with no associated data: */
82   
83   /* If there is a catch activity with a matching faultName value that does not specify a faultVariable
84    * attribute then the fault is passed to the identified catch activity*/

85   public void test_faultNoData_catchName() {
86     assertSame( catchName, scope.getFaultHandler(new Fault(catchName.getFaultName())) );
87   }
88   
89   /* Otherwise if there is a catchAll handler then the fault is passed to the catchAll handler*/
90   public void test_faultNoData_catchAll() {
91     scope.setHandler(Scope.CATCH_ALL, catchAll);
92     assertSame( catchAll, scope.getFaultHandler(new Fault(NON_MATCHING_NAME)) );
93   }
94   
95   /* Otherwise the fault is thrown to the immediately enclosing scope*/
96   public void test_faultNoData_noCatch() {
97     assertNull( scope.getFaultHandler(new Fault(NON_MATCHING_NAME)) );
98   }
99   
100   /* In the case of faults thrown with associated data: */
101
102   /* If there is a catch activity with a matching faultName value that has a faultVariable or
103    * faultMessageType whose type matches the type of the fault data then the fault is passed to the
104    * identified catch activity */

105   public void test_faultMessage_catchNameMessage() {
106     Fault fault = new Fault(catchNameMessage.getFaultName(),
107         null, catchNameMessage.getFaultVariable().getTypeInfo());
108     assertSame( catchNameMessage, scope.getFaultHandler(fault) );
109   }
110   
111   public void test_faultElement_catchNameElement() {
112     Fault fault = new Fault(catchNameElement.getFaultName(),
113         null, catchNameElement.getFaultVariable().getTypeInfo());
114     assertSame(catchNameElement, scope.getFaultHandler(fault));
115   }
116   
117   /* Otherwise if the fault data is a WSDL message type where the message contains a single part defined
118    * by an element and there exists a catch activity with a matching faultName value that has a
119    * faultVariable whose type matches the type of the element used to define the part then the fault
120    * is passed to the identified catch activity */

121   public void test_faultMessage_catchNameElement() {
122     Part part = new PartImpl();
123     part.setName("aPart");
124     part.setElementName(catchNameElement.getFaultVariable().getTypeInfo().getName());
125
126     Message message = new MessageImpl();
127     message.setQName(NON_MATCHING_NAME);
128     message.addPart(part);
129
130     Fault fault = new Fault(catchNameMessage.getFaultName(), null, new MessageTypeInfo(message));
131     assertSame( catchNameElement, scope.getFaultHandler(fault) );
132   }
133   
134   /* If there is a catch activity with a matching faultName value that does not specify a faultVariable
135    * or faultMessageType value then the fault is passed to the identified catch activity */

136   public void test_faultMessage_catchName() {
137     Fault fault = new Fault(catchName.getFaultName(), null, new ElementTypeInfo(NON_MATCHING_NAME));
138     assertSame(catchName, scope.getFaultHandler(fault));
139   }
140   
141   /* Otherwise if there is a catch activity without a faultName attribute that has a faultVariable or
142    * faultMessageType whose type matches the type of the fault data then the fault is passed to the
143    * identified catch activity */

144   public void test_faultMessage_catchMessage() {
145     Fault fault = new Fault(NON_MATCHING_NAME, null, catchMessage.getFaultVariable().getTypeInfo());
146     assertSame( catchMessage, scope.getFaultHandler(fault) );
147   }
148   
149   public void test_faultElement_catchElement() {
150     Fault fault = new Fault(NON_MATCHING_NAME, null, catchElement.getFaultVariable().getTypeInfo());
151     assertSame(catchElement, scope.getFaultHandler(fault));
152   }
153   
154   /* Otherwise if the fault data is a WSDL message type where the message contains a single part defined
155    * by an element and there exists a catch activity without a faultName attribute that has a
156    * faultVariable whose type matches the type of the element used to define the part then the fault is
157    * passed to the identified catch activity */

158   public void test_faultMessage_catchElement() {
159     // element part
160
Part part = new PartImpl();
161     part.setName("aPart");
162     part.setElementName(catchElement.getFaultVariable().getTypeInfo().getName());
163     // message
164
Message message = new MessageImpl();
165     message.setQName(NON_MATCHING_NAME);
166     message.addPart(part);
167     // fault
168
Fault fault = new Fault(NON_MATCHING_NAME, null, new MessageTypeInfo(message));
169     assertSame( catchElement, scope.getFaultHandler(fault) );
170   }
171   
172   /* Otherwise if there is a catchAll handler then the fault is passed to the catchAll handler */
173   public void test_faultMessage_catchAll() {
174     Message message = new MessageImpl();
175     message.setQName(NON_MATCHING_NAME);
176     
177     Fault fault = new Fault(NON_MATCHING_NAME, null, new MessageTypeInfo(message) );
178     scope.setHandler(Scope.CATCH_ALL, catchAll);
179     assertSame( catchAll, scope.getFaultHandler(fault) );
180   }
181   
182   public void test_faultElement_catchAll() {
183     Fault fault = new Fault(NON_MATCHING_NAME, null, new ElementTypeInfo(NON_MATCHING_NAME));
184     scope.setHandler(Scope.CATCH_ALL, catchAll);
185     assertSame(catchAll, scope.getFaultHandler(fault));
186   }
187   
188   /* Otherwise, the fault will be handled by the default fault handler */
189   public void test_faultMessage_noCatch() {
190     Message message = new MessageImpl();
191     message.setQName(NON_MATCHING_NAME);
192
193     Fault fault = new Fault(NON_MATCHING_NAME, null, new MessageTypeInfo(message) );
194     assertNull( scope.getFaultHandler(fault) );
195   }
196   
197   public void test_faultElement_noCatch() {
198     Fault fault = new Fault(NON_MATCHING_NAME, null, new ElementTypeInfo(NON_MATCHING_NAME));
199     assertNull(scope.getFaultHandler(fault));
200   }
201 }
Popular Tags