1 package org.jbpm.bpel.xml; 2 3 import java.util.Collection ; 4 import java.util.Iterator ; 5 import java.util.Set ; 6 7 import javax.xml.namespace.QName ; 8 9 import org.w3c.dom.Element ; 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 22 public class ScopeReaderTest extends AbstractReaderTestCase { 23 24 public void setUp() throws Exception { 25 super.setUp(); 26 initMessageProperties(); 27 } 28 29 public void testActivity() throws Exception { 30 String 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 { 38 String 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 { 45 String xml = "<scope isolated='yes'><empty/></scope>"; 46 Scope localScope = (Scope) readActivity( xml ); 47 assertTrue( localScope.isIsolated() ); 48 } 49 50 public void testImplicit() throws Exception { 51 String 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 { 58 String 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 { 71 initMessageProperties(); 72 String 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 { 87 String 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 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 { 110 QName wsdlFaultType = new QName (NS_TNS, "aQName"); 111 String 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 QName firstFaultName = new QName ("firstFault"); 126 Iterator handlerIt = scope.getFaultHandlers().iterator(); 127 FaultHandler firstFaultHandler = (FaultHandler) handlerIt.next(); 128 129 assertEquals( firstFaultName, firstFaultHandler.getFaultName() ); 130 assertNull( firstFaultHandler.getFaultVariable() ); 131 132 QName secondFaultName = new QName ("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 { 140 String 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 { 152 String 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 { 164 String 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 { 176 String 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 onAlarms = scope.getAlarmHandlers(); 186 assertEquals(1, onAlarms.size()); 187 AlarmHandler handler = (AlarmHandler) onAlarms.iterator().next(); 188 Object 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 { 195 String 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 receivers = scope.getMessageHandlers(); 209 assertEquals(1, receivers.size()); 210 MessageHandler handler = (MessageHandler) receivers.iterator().next(); 211 Object activity = handler.getActivity(); 212 assertEquals( Empty.class, activity.getClass()); 214 assertEquals( "oM1", ((Empty)activity).getName()); 215 assertNotNull(handler.getReceiver()); 217 assertNotNull(handler.getCorrelationSet("cs1")); 219 assertEquals("v", handler.getVariableDefinition().getName()); 221 } 222 223 private void loadScope(String xml) throws Exception { 224 Element element = parseAsBpelElement(xml); 225 reader.readScope(element, scope); 226 } 227 } | Popular Tags |