1 package org.jbpm.bpel.xml; 2 3 import java.util.Collections ; 4 import java.util.List ; 5 6 import javax.wsdl.Output; 7 8 import com.ibm.wsdl.OutputImpl; 9 10 import org.jbpm.bpel.data.def.MessageTypeInfo; 11 import org.jbpm.bpel.def.Activity; 12 import org.jbpm.bpel.def.Empty; 13 import org.jbpm.bpel.def.Pick; 14 import org.jbpm.bpel.service.def.CorrelationSetDefinition; 15 import org.jbpm.bpel.service.def.Receiver; 16 import org.jbpm.bpel.timer.def.Alarm; 17 18 22 public class PickReaderTest extends AbstractReaderTestCase { 23 24 public void testCreateInstanceYes() throws Exception { 25 initMessageProperties(); 26 String xml = 27 "<pick createInstance='yes'>" + 28 "<onMessage partnerLink='aPartner' operation='o' variable='iv'>" + 29 " <empty name='oM1'/>" + 30 "</onMessage>" + 31 "</pick>"; 32 33 scope.initial = true; 34 Pick pick = (Pick) readActivity(xml); 35 assertEquals(true, pick.isCreateInstance()); 36 } 37 38 public void testCreateInstanceNo() throws Exception { 39 String xml = 40 "<pick createInstance='no'>" + 41 "<onAlarm><for>$f</for><empty/></onAlarm>" + 42 "</pick>"; 43 44 Pick pick = (Pick) readActivity(xml); 45 assertEquals(false, pick.isCreateInstance()); 46 } 47 48 public void testCreateInstanceDefault() throws Exception { 49 String xml = 50 "<pick>" + 51 "<onAlarm><for>$f</for><empty/></onAlarm>" + 52 "</pick>"; 53 54 Pick pick = (Pick) readActivity(xml); 55 assertEquals(false, pick.isCreateInstance()); 56 } 57 58 public void testOnAlarmFor() throws Exception { 59 String xml = 60 "<pick>" + 61 "<onAlarm>" + 62 "<for>$f</for>" + 63 "<empty name='oA1'/>" + 64 "</onAlarm>" + 65 "</pick>"; 66 Pick pick = (Pick) readActivity(xml); 67 Alarm alarm = ((Alarm) pick.getOnAlarms().iterator().next()); 68 assertEquals( "$f", alarm.getFor().getText() ); 69 assertEquals( Alarm.AlarmKind.DURATION, alarm.getAlarmKind() ); 70 } 71 72 public void testOnAlarmUntil() throws Exception { 73 String xml = 74 "<pick>" + 75 "<onAlarm>" + 76 "<until>$u</until>" + 77 "<empty name='oA1'/></onAlarm>" + 78 "</pick>"; 79 80 Pick pick = (Pick) readActivity(xml); 81 Alarm alarm = ((Alarm) pick.getOnAlarms().iterator().next()); 82 assertEquals( "$u", alarm.getUntil().getText() ); 83 assertEquals( Alarm.AlarmKind.DEADLINE, alarm.getAlarmKind() ); 84 } 85 86 public void testOnAlarmRepeat() throws Exception { 87 String xml = 88 "<pick>" + 89 "<onAlarm>" + 90 "<repeatEvery>$r</repeatEvery>" + 91 "<until>$u</until>" + 92 "<for>$f</for>" + 93 "<empty name='oA1'/></onAlarm>" + 94 "</pick>"; 95 96 Pick pick = (Pick) readActivity(xml); 97 Alarm alarm = ((Alarm) pick.getOnAlarms().iterator().next()); 98 assertEquals( "$r", alarm.getRepeatEvery().getText() ); 99 assertEquals( "$u", alarm.getUntil().getText() ); 100 assertEquals( "$f", alarm.getFor().getText() ); 101 assertEquals( Alarm.AlarmKind.CYCLIC, alarm.getAlarmKind() ); 102 } 103 104 public void testOnAlarmActivity() throws Exception { 105 String xml = 106 "<pick>" + 107 "<onAlarm><for>$f</for><empty name='oA1'/></onAlarm>" + 108 "</pick>"; 109 110 Pick pick = (Pick) readActivity(xml); 111 List alarms = pick.getOnAlarms(); 112 assertEquals(1, alarms.size()); 113 Activity activity = pick.getOnAlarm((Alarm) alarms.get(0)); 114 assertEquals( Empty.class, activity.getClass()); 115 assertEquals( "oA1", ((Empty)activity).getName()); 116 } 117 118 public void testOnMessageActivity() throws Exception { 119 initMessageProperties(); 120 String xml = 121 "<pick>" + 122 "<onMessage partnerLink='aPartner' operation='o' variable='iv'>" + 123 " <empty name='oM1'/>" + 124 "</onMessage>" + 125 "</pick>"; 126 127 Pick pick = (Pick) readActivity(xml); 128 List receivers = pick.getOnMessages(); 129 assertEquals(1, receivers.size()); 130 Activity activity = pick.getOnMessage((Receiver) receivers.get(0)); 131 assertEquals( Empty.class, activity.getClass()); 132 assertEquals( "oM1", ((Empty)activity).getName()); 133 } 134 135 public void testOnMessagePartnerLink() throws Exception { 136 initMessageProperties(); 137 String xml = 138 "<pick>" + 139 "<onMessage partnerLink='aPartner' operation='o' variable='iv'>" + 140 " <empty name='oM1'/>" + 141 "</onMessage>" + 142 "</pick>"; 143 144 Pick pick = (Pick) readActivity(xml); 145 Receiver receiver = (Receiver) pick.getOnMessages().iterator().next(); 146 assertEquals( pLink, receiver.getPartnerLink() ); 147 } 148 149 public void testOnMessagePortType() throws Exception { 150 initMessageProperties(); 151 String xml = 152 "<pick xmlns:def='http://manufacturing.org/wsdl/purchase'>" + 153 "<onMessage partnerLink='aPartner' portType='def:mpt' operation='o' variable='iv'>" + 154 " <empty name='oM1'/>" + 155 "</onMessage>" + 156 "</pick>"; 157 158 try { 159 Pick pick = (Pick) readActivity(xml); 160 assertEquals(1, pick.getOnMessages().size()); 161 } 162 catch (Exception e) { 163 fail(e.toString()); 164 } 165 } 166 167 public void testOnMessagePortTypeDefault() throws Exception { 168 initMessageProperties(); 169 String xml = 170 "<pick>" + 171 "<onMessage partnerLink='aPartner' operation='o' variable='iv'>" + 172 " <empty name='oM1'/>" + 173 "</onMessage>" + 174 "</pick>"; 175 176 try { 177 Pick pick = (Pick) readActivity(xml); 178 assertEquals(1, pick.getOnMessages().size()); 179 } 180 catch (Exception e) { 181 fail(e.toString()); 182 } 183 } 184 185 public void testOnMessageOperation() throws Exception { 186 initMessageProperties(); 187 String xml = 188 "<pick>" + 189 "<onMessage partnerLink='aPartner' operation='o' variable='iv'>" + 190 " <empty name='oM1'/>" + 191 "</onMessage>" + 192 "</pick>"; 193 Pick pick = (Pick) readActivity(xml); 194 Receiver receiver = (Receiver) pick.getOnMessages().iterator().next(); 195 assertEquals( "o", receiver.getOperation().getName() ); 196 } 197 198 public void testOnMessageVariable() throws Exception { 199 initMessageProperties(); 200 MessageTypeInfo typeInfo = (MessageTypeInfo) messageVariable.getTypeInfo(); 201 Output output = new OutputImpl(); 202 output.setMessage(typeInfo.getMessage()); 203 operation.setOutput(output); 204 205 String xml = 206 "<pick>" + 207 "<onMessage partnerLink='aPartner' operation='o' variable='iv'>" + 208 " <empty name='oM1'/>" + 209 "</onMessage>" + 210 "</pick>"; 211 212 Pick pick = (Pick) readActivity(xml); 213 Receiver receiver = (Receiver) pick.getOnMessages().iterator().next(); 214 assertEquals(messageVariable, receiver.getVariable() ); 215 } 216 217 public void testOnMessageCorrelations() throws Exception { 218 initMessageProperties(); 219 CorrelationSetDefinition set = new CorrelationSetDefinition(); 220 set.setName("corr"); 221 set.setProperties(Collections.EMPTY_SET); 222 scope.addCorrelationSet(set); 223 String xml = 224 "<pick>" + 225 "<onMessage partnerLink='aPartner' operation='o' variable='iv'>" + 226 " <empty name='oM1'/>" + 227 " <correlations>" + 228 " <correlation set='corr'/> " + 229 " </correlations>" + 230 "</onMessage>" + 231 "</pick>"; 232 Pick pick = (Pick) readActivity(xml); 233 Receiver receiver = (Receiver) pick.getOnMessages().iterator().next(); 234 assertNotNull( receiver.getCorrelations() ); 235 } 236 } 237 | Popular Tags |