KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.xml;
2
3 import java.util.Collections JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.jbpm.bpel.data.def.VariableDefinition;
7 import org.jbpm.bpel.def.Invoke;
8 import org.jbpm.bpel.def.Scope;
9 import org.jbpm.bpel.service.def.CorrelationSetDefinition;
10 import org.jbpm.bpel.service.def.Correlations;
11
12 public class InvokeReaderTest extends AbstractReaderTestCase {
13   
14   VariableDefinition outputVariable;
15   
16   public void setUp() throws Exception JavaDoc {
17     super.setUp();
18     initMessageProperties();
19     // output variable
20
outputVariable = new VariableDefinition();
21     outputVariable.setName("ov");
22     outputVariable.setTypeInfo(messageVariable.getTypeInfo());
23     scope.addVariable(outputVariable);
24   }
25   
26   public void testScopedInvoke() throws Exception JavaDoc {
27     String JavaDoc xml =
28       "<invoke partnerLink='aPartner' operation='o' inputVariable='iv'>" +
29       "<compensationHandler><empty/></compensationHandler>" +
30       "<faultHandlers><catchAll><empty/></catchAll></faultHandlers>" +
31       "</invoke>";
32     Scope scope = (Scope) readActivity(xml);
33     
34     assertTrue( scope.isImplicit() );
35     assertEquals( Invoke.class, scope.getRoot().getClass() );
36     assertNotNull( scope.getHandler(Scope.COMPENSATION) );
37     assertNotNull( scope.getHandler(Scope.CATCH_ALL) );
38     
39     assertEquals(pLink, ((Invoke)scope.getRoot()).getInvoker().getPartnerLink() );
40   }
41   
42   // --- INVOKE ATTRIBUTES AND ELEMENTS ---
43
public void testPartnerLink() throws Exception JavaDoc {
44     String JavaDoc xml = "<invoke partnerLink='aPartner' operation='o' inputVariable='iv'/>";
45     Invoke invoke = (Invoke) readActivity(xml);
46     assertEquals(pLink, invoke.getInvoker().getPartnerLink() );
47   }
48
49   public void testPortType() {
50     String JavaDoc xml = "<invoke partnerLink='aPartner' portType='def:ppt' operation='o' inputVariable='iv'" +
51         " xmlns:def='http://manufacturing.org/wsdl/purchase'/>";
52     try {
53       readActivity(xml);
54     }
55     catch (Exception JavaDoc e) {
56       fail(e.toString());
57     }
58   }
59
60   public void testPortTypeDefault() {
61     String JavaDoc xml = "<invoke partnerLink='aPartner' operation='o' inputVariable='iv'/>";
62     try {
63       readActivity(xml);
64     }
65     catch (Exception JavaDoc e) {
66       fail(e.toString());
67     }
68   }
69   
70   public void testPortTypeNotFound() throws Exception JavaDoc {
71     String JavaDoc xml = "<invoke partnerLink='aPartner' portType='invalidPT' operation='o' inputVariable='iv'/>";
72     ProblemCollector collector = new ProblemCollector();
73     reader.setProblemHandler(collector);
74     readActivity(xml);
75     if(!collector.hasErrors()) {
76       fail("invoke parse must fail when portType doesn't match partnerRole's portType");
77     }
78   }
79   
80   public void testOperation() throws Exception JavaDoc {
81     String JavaDoc xml = "<invoke partnerLink='aPartner' operation='o' inputVariable='iv'/>";
82     Invoke invoke = (Invoke) readActivity(xml);
83     assertEquals( "o", invoke.getInvoker().getOperation().getName() );
84   }
85
86   public void testInputVariableDefinition() throws Exception JavaDoc {
87     String JavaDoc xml =
88       "<invoke partnerLink='aPartner' operation='o' inputVariable='iv'/>";
89     Invoke invoke = (Invoke) readActivity(xml);
90     assertSame(messageVariable, invoke.getInvoker().getInputVariable() );
91   }
92   
93   public void testOutputVariableDefinition() throws Exception JavaDoc {
94     String JavaDoc xml =
95       "<invoke partnerLink='aPartner' operation='o2' inputVariable='iv' outputVariable='ov'/>";
96     Invoke invoke = (Invoke) readActivity(xml);
97     assertSame(outputVariable, invoke.getInvoker().getOutputVariable() );
98   }
99
100   public void testOutputVariableDefinitionDefault() throws Exception JavaDoc {
101     String JavaDoc xml = "<invoke partnerLink='aPartner' operation='o' inputVariable='iv'/>";
102     Invoke invoke = (Invoke) readActivity(xml);
103     assertNull( invoke.getInvoker().getOutputVariable() );
104   }
105   
106   public void testCorrelations() throws Exception JavaDoc {
107     String JavaDoc xml =
108       "<invoke partnerLink='aPartner' operation='o2' inputVariable='iv' outputVariable='ov'>" +
109       " <correlations>" +
110       " <correlation set='in' initiate='yes' pattern='in'/> " +
111       " <correlation set='out' initiate='no' pattern='out'/> " +
112       " <correlation set='outin' pattern='out-in'/> " +
113       " </correlations>" +
114       "</invoke>";
115     
116     CorrelationSetDefinition set = new CorrelationSetDefinition();
117     set.setName("in");
118     set.setProperties(Collections.EMPTY_SET);
119     scope.addCorrelationSet(set);
120     
121     set = new CorrelationSetDefinition();
122     set.setName("out");
123     set.setProperties(Collections.EMPTY_SET);
124     scope.addCorrelationSet(set);
125     
126     set = new CorrelationSetDefinition();
127     set.setName("outin");
128     set.setProperties(Collections.EMPTY_SET);
129     scope.addCorrelationSet(set);
130     
131     Invoke invoke = (Invoke) readActivity(xml);
132     
133     Correlations correlations = invoke.getInvoker().getInCorrelations();
134     Map JavaDoc correlationMap = correlations.getCorrelations();
135     
136     assertNotNull( correlationMap.get("in") );
137     assertNotNull( correlationMap.get("outin") );
138     
139     correlations = invoke.getInvoker().getOutCorrelations();
140     correlationMap = correlations.getCorrelations();
141
142     assertNotNull( correlationMap.get("out") );
143     assertNotNull( correlationMap.get("outin") );
144   }
145 }
146
Popular Tags