1 package org.jbpm.bpel.def; 2 3 import javax.wsdl.Message; 4 import javax.wsdl.Part; 5 import javax.xml.namespace.QName ; 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 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 NON_MATCHING_NAME = new QName (BpelConstants.NS_EXAMPLES, "unexpected"); 34 35 public void setUp() { 36 scope = new Scope(); 37 38 QName faultName = new QName (BpelConstants.NS_EXAMPLES, "aFault"); 39 40 catchName.setFaultName(faultName); 41 scope.addFaultHandler(catchName); 42 43 QName elementName = new QName (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 53 catchNameElement.setFaultName(faultName); 54 catchNameElement.setFaultVariable(elementVariable); 55 scope.addFaultHandler(catchNameElement); 56 57 60 Part part = new PartImpl(); 61 part.setName("aPart"); 62 part.setElementName(elementName); 63 64 Message message = new MessageImpl(); 65 message.setQName(new QName (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 76 catchNameMessage.setFaultName(faultName); 77 catchNameMessage.setFaultVariable(messageVariable); 78 scope.addFaultHandler(catchNameMessage); 79 } 80 81 82 83 85 public void test_faultNoData_catchName() { 86 assertSame( catchName, scope.getFaultHandler(new Fault(catchName.getFaultName())) ); 87 } 88 89 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 96 public void test_faultNoData_noCatch() { 97 assertNull( scope.getFaultHandler(new Fault(NON_MATCHING_NAME)) ); 98 } 99 100 101 102 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 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 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 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 158 public void test_faultMessage_catchElement() { 159 Part part = new PartImpl(); 161 part.setName("aPart"); 162 part.setElementName(catchElement.getFaultVariable().getTypeInfo().getName()); 163 Message message = new MessageImpl(); 165 message.setQName(NON_MATCHING_NAME); 166 message.addPart(part); 167 Fault fault = new Fault(NON_MATCHING_NAME, null, new MessageTypeInfo(message)); 169 assertSame( catchElement, scope.getFaultHandler(fault) ); 170 } 171 172 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 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 |