1
2
3
4
5
6
7
8
9 package bexee.core;
10
11 import java.io.FileNotFoundException;
12 import java.io.InputStream;
13 import java.util.Collection;
14 import java.util.Hashtable;
15 import java.util.Iterator;
16
17 import javax.wsdl.Binding;
18 import javax.wsdl.Definition;
19 import javax.wsdl.Port;
20 import javax.wsdl.Service;
21 import javax.wsdl.extensions.ExtensibilityElement;
22 import javax.wsdl.extensions.ExtensionRegistry;
23 import javax.wsdl.extensions.soap.SOAPAddress;
24 import javax.wsdl.factory.WSDLFactory;
25 import javax.wsdl.xml.WSDLReader;
26 import javax.xml.namespace.QName;
27
28 import org.xml.sax.InputSource;
29
30 import bexee.BexeeTestCase;
31 import bexee.model.BPELDocumentException;
32 import bexee.model.BPELProcessFactory;
33 import bexee.model.elements.PartnerLink;
34 import bexee.model.elements.impl.PartnerLinkImpl;
35 import bexee.model.process.BPELProcess;
36 import bexee.wsdl.extensions.partnerlinktype.PartnerLinkTypeExtensionRegistry;
37
38 /***
39 * @author Pawel Kowalski
40 * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:12 $
41 */
42 public class ProcessControllerTest extends BexeeTestCase {
43
44 private ProcessController controller;
45
46 private BPELProcessFactory factory;
47
48 private WSDLFactory wsdlFactory;
49
50 private WSDLReader wsdlReader;
51
52 private String inputPropertyName = "input";
53
54 private String outputPropertyName = "output";
55
56 private String inputValue = "someinput";
57
58 //***************************************************/
59
60 //***************************************************/
61
62 protected void setUp() throws Exception {
63 super.setUp();
64 controller = new ProcessControllerImpl();
65 factory = BPELProcessFactory.getInstance();
66 wsdlFactory = WSDLFactory.newInstance();
67 wsdlReader = wsdlFactory.newWSDLReader();
68
69 ExtensionRegistry reg = new PartnerLinkTypeExtensionRegistry();
70 wsdlReader.setExtensionRegistry(reg);
71 wsdlReader.setFeature("javax.wsdl.importDocuments", false);
72 }
73
74 protected void tearDown() throws Exception {
75 super.tearDown();
76 }
77
78 //***************************************************/
79
80 //***************************************************/
81
82 public void testInvokationInformation() throws Exception {
83
84
85 BPELProcess bpelProcess = createReceiveReplyProcess();
86
87 InputStream inputStream = getLoader().getResourceAsStream(
88 "TravelService.wsdl");
89 bpelProcess.addPartnerWSDL(wsdlReader.readWSDL(null, new InputSource(
90 inputStream)));
91 PartnerLink pLink = new PartnerLinkImpl();
92 pLink.getPartnerLinkType();
93 QName partnerLinkType = new QName("OfferTravelPLT",
94 "http://bexee.sourceforge.net/Travel");
95 QName portTypeName = new QName("http://bexee.sourceforge.net/Travel",
96 "TravelService");
97
98 Binding binding = null;
99 SOAPAddress soapAddress = null;
100 Port port = null;
101
102 Collection wsdlCollection = bpelProcess.getPartnerWSDL();
103 mainloop: for (Iterator iter = wsdlCollection.iterator(); iter
104 .hasNext();) {
105 Definition defn = (Definition) iter.next();
106 Collection bindings = defn.getBindings().values();
107 for (Iterator iterator = bindings.iterator(); iterator.hasNext();) {
108 binding = (Binding) iterator.next();
109 if (binding.getPortType().getQName().equals(portTypeName)) {
110 break mainloop;
111 }
112 }
113 }
114
115 mainloop: for (Iterator iter = wsdlCollection.iterator(); iter
116 .hasNext();) {
117 Definition defn = (Definition) iter.next();
118 Collection services = defn.getServices().values();
119 for (Iterator iterator = services.iterator(); iterator.hasNext();) {
120 Service service = (Service) iterator.next();
121 Collection portTypes = service.getPorts().values();
122 for (Iterator iter2 = portTypes.iterator(); iter2.hasNext();) {
123 port = (Port) iter2.next();
124 if (port.getBinding().equals(binding)) {
125 break mainloop;
126 }
127 }
128 }
129 }
130
131 if (port != null) {
132 Collection extElems = port.getExtensibilityElements();
133 for (Iterator iter = extElems.iterator(); iter.hasNext();) {
134 ExtensibilityElement element = (ExtensibilityElement) iter
135 .next();
136 if (element instanceof SOAPAddress) {
137 soapAddress = (SOAPAddress) element;
138 break;
139 }
140 }
141 }
142
143 }
144
145 public void testLocalController() throws Exception {
146
147
148 BPELProcess bpelProcess = createReceiveReplyProcess();
149
150 InputStream inputStream = getLoader().getResourceAsStream(
151 "TravelService.wsdl");
152
153 bpelProcess.addPartnerWSDL(wsdlReader.readWSDL(null, new InputSource(
154 inputStream)));
155
156 ProcessContext ctx = new ProcessContext();
157 ProcessInstance processInstance = new ProcessInstance(bpelProcess, ctx);
158
159
160 BexeeMessage msg = createBexeeMessageOne();
161
162
163 controller.processMessage(processInstance, msg);
164
165
166 Object result = processInstance.getContext().getResult();
167
168 System.out.println();
169
170
171
172 }
173
174 //***************************************************/
175
176 //***************************************************/
177
178 private BPELProcess createReceiveReplyProcess()
179 throws FileNotFoundException, BPELDocumentException {
180 InputStream inputStream = getLoader().getResourceAsStream("BookTravel.xml");
181 BPELProcess bpelProcess = factory.createBPELProcess(inputStream);
182 return bpelProcess;
183 }
184
185 private BexeeMessage createBexeeMessageOne() throws Exception {
186
187
188 BexeeMessage message = new BexeeMessage();
189 message.setOperation("process");
190
191 Hashtable parts = new Hashtable();
192 parts.put("value", "inval");
193 message.setParts(parts);
194
195 return message;
196 }
197 }