This project has retired. For details please refer to its Attic page.
BPEL2UDDITest xref
View Javadoc
1   /*
2    * Copyright 2001-2009 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *      http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.apache.juddi.v3.client.mapping.wsdl;
16  
17  import java.net.MalformedURLException;
18  import java.net.URL;
19  import java.util.Map;
20  import java.util.Properties;
21  import java.util.Set;
22  
23  import javax.wsdl.Binding;
24  import javax.wsdl.Definition;
25  import javax.wsdl.PortType;
26  import javax.wsdl.WSDLException;
27  import javax.xml.bind.JAXBException;
28  import javax.xml.namespace.QName;
29  
30  import org.apache.commons.configuration.ConfigurationException;
31  import org.apache.juddi.jaxb.PrintUDDI;
32  import org.apache.juddi.v3.client.mapping.URLLocalizer;
33  import org.apache.juddi.v3.client.mapping.URLLocalizerDefaultImpl;
34  import org.apache.juddi.v3.client.mapping.wsdl.BPEL2UDDI;
35  import org.apache.juddi.v3.client.mapping.wsdl.ReadWSDL;
36  import org.junit.Assert;
37  import org.junit.BeforeClass;
38  import org.junit.Test;
39  import org.uddi.api_v3.BindingTemplate;
40  import org.uddi.api_v3.FindTModel;
41  import org.uddi.api_v3.TModel;
42  
43  /**
44   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
45   */
46  public class BPEL2UDDITest {
47  
48  	
49  	static BPEL2UDDI bpel2UDDI;
50  	PrintUDDI<TModel> pTModel = new PrintUDDI<TModel>();
51  	PrintUDDI<FindTModel> pFindTModel = new PrintUDDI<FindTModel>();
52  	PrintUDDI<BindingTemplate> pBinding = new PrintUDDI<BindingTemplate>();
53  	ReadWSDL rw = new ReadWSDL();
54  
55          static boolean serialize=false;
56  	public BPEL2UDDITest(){
57              if (System.getProperty("debug")!=null && System.getProperty("debug").equalsIgnoreCase("true"))
58                  serialize = true;
59          }
60          
61  	@BeforeClass
62  	public static void before() throws JAXBException, ConfigurationException {
63  		Properties properties = new Properties();
64  		properties.put("keyDomain", "juddi.apache.org");
65  		properties.put("nodeName", "localhost");
66  		URLLocalizer urlLocalizer = new URLLocalizerDefaultImpl();
67  		
68  		bpel2UDDI = new BPEL2UDDI(null, urlLocalizer, properties);
69  	}
70  	
71  	@Test
72  	public void testTN_WSDLPortTypeModels() throws WSDLException, JAXBException, Exception {
73  
74  		// Reading the WSDL
75  		Definition wsdlDefinition = rw.readWSDL("bpel/bpel-technote.wsdl");
76  	    @SuppressWarnings("unchecked")
77  		Map<QName,PortType> portTypes= (Map<QName,PortType>) wsdlDefinition.getAllPortTypes();
78  	    Set<TModel> portTypeTModels = bpel2UDDI.createWSDLPortTypeTModels(wsdlDefinition.getDocumentBaseURI(), portTypes); 
79  	    for (TModel tModel : portTypeTModels) {
80  			System.out.println("***** UDDI PortType TModel: " + tModel.getName().getValue());
81                          if (serialize)
82  			System.out.println(pTModel.print(tModel));
83  		}
84  		Assert.assertEquals(2,portTypeTModels.size());
85  	}
86  	
87  	@Test
88  	public void testTN_BPEL4WSProcessTModel() throws WSDLException, JAXBException, Exception {
89  
90  		// Obtained from the .bpel file:
91  		String targetNamespace = "http://example.com/travelagent";
92  		QName serviceName = new QName (targetNamespace, "ReservationAndBookingTickets");
93  		String bpelOverViewUrl = "http://localhost/registry/" + serviceName.getLocalPart() + ".bpel";
94  		
95  		// Reading the WSDL
96  		Definition wsdlDefinition = rw.readWSDL("bpel/bpel-technote.wsdl");
97  		
98  	    @SuppressWarnings("unchecked")
99  		Map<QName,PortType> portTypes= (Map<QName,PortType>) wsdlDefinition.getAllPortTypes();
100 	    TModel bpel4WSTModel = bpel2UDDI.createBPEL4WSProcessTModel(serviceName, targetNamespace, portTypes, bpelOverViewUrl);
101 	    
102 		System.out.println("***** BPEL4WS Process TModel: " + bpel4WSTModel.getName().getValue());
103                 if (serialize)
104 		System.out.println(pTModel.print(bpel4WSTModel));
105 		
106 		Assert.assertNotNull(bpel4WSTModel);
107 	}
108 	
109 	@Test
110 	public void testTN_FindTModelForProcessName() throws JAXBException {
111 		
112 		QName processName = new QName("http://example.com/travelagent","ReservationAndBookingTickets");
113 	
114 		FindTModel findTModel = bpel2UDDI.createFindTModelForProcessName(processName);
115 		
116 		System.out.println("***** Find TModel For ProcessName: " + processName);
117                 if (serialize)
118 		System.out.println(pFindTModel.print(findTModel));
119 		
120 		Assert.assertNotNull(findTModel.getCategoryBag());
121 	}
122 	
123 	@Test
124 	public void testHelloWorld_WSDLPortTypeModels() throws WSDLException, JAXBException , Exception{
125 
126 		// Reading the WSDL
127 		Definition wsdlDefinition = rw.readWSDL("bpel/HelloWorld.wsdl");
128 	    @SuppressWarnings("unchecked")
129 		Map<QName,PortType> portTypes= (Map<QName,PortType>) wsdlDefinition.getAllPortTypes();
130 	    Set<TModel> portTypeTModels = bpel2UDDI.createWSDLPortTypeTModels(wsdlDefinition.getDocumentBaseURI(), portTypes);
131 	    
132 		for (TModel tModel : portTypeTModels) {
133 			System.out.println("***** UDDI PortType TModel: " + tModel.getName().getValue());
134                         if (serialize)
135 			System.out.println(pTModel.print(tModel));
136 		}
137 		Assert.assertEquals(1,portTypeTModels.size());
138 	}
139 	
140 	@Test
141 	public void testHelloWorld_UDDIBindingModel() throws WSDLException, JAXBException, Exception {
142 
143 		// Reading the WSDL
144 		Definition wsdlDefinition = rw.readWSDL("bpel/HelloWorld.wsdl");
145 	    @SuppressWarnings("unchecked")
146 		Map<QName,Binding> bindings = (Map<QName,Binding>) wsdlDefinition.getAllBindings();
147 	    Set<TModel> bindingTModels = bpel2UDDI.createWSDLBindingTModels(wsdlDefinition.getDocumentBaseURI(), bindings);
148 	    
149 		for (TModel tModel : bindingTModels) {
150 			System.out.println("***** UDDI Binding TModel: " + tModel.getName().getValue());
151                         if (serialize)
152 			System.out.println(pTModel.print(tModel));
153 		}
154 		Assert.assertEquals(1,bindingTModels.size());
155 	}
156 	
157 	@Test
158 	public void testHelloWorld_BPEL4WSProcessTModel() throws WSDLException, JAXBException , Exception{
159 
160 		//Obtained from the .bpel file:
161 		String targetNamespace = "http://www.jboss.org/bpel/examples";
162 		QName serviceName = new QName (targetNamespace, "HelloWorld");
163 		String bpelOverViewUrl = "http://localhost/registry/" + serviceName.getLocalPart() + ".bpel";
164 		
165 		// Reading the WSDL
166 		Definition wsdlDefinition = rw.readWSDL("bpel/HelloWorld.wsdl");
167 		
168 	    @SuppressWarnings("unchecked")
169 		Map<QName,PortType> portTypes= (Map<QName,PortType>) wsdlDefinition.getAllPortTypes();
170 	    TModel bpel4WSTModel = bpel2UDDI.createBPEL4WSProcessTModel(serviceName, targetNamespace, portTypes, bpelOverViewUrl);
171 	    
172 		System.out.println("***** BPEL4WS Process TModel: " + bpel4WSTModel.getName().getValue());
173                 if (serialize)
174 		System.out.println(pTModel.print(bpel4WSTModel));
175 		
176 		Assert.assertNotNull(bpel4WSTModel);
177 	}
178 	
179 	@Test
180 	public void testHelloWorld_BPELBinding() throws WSDLException, JAXBException, MalformedURLException, Exception {
181 
182 		//Obtained from the .bpel file:
183 		String portName = "HelloPort";
184 		QName serviceName = new QName ("http://www.jboss.org/bpel/examples/wsdl", "HelloService");
185 		URL serviceUrl =  new URL("http://localhost/sample");
186 		
187 		// Reading the WSDL
188 		Definition wsdlDefinition = rw.readWSDL("bpel/HelloWorld.wsdl");
189 	    BindingTemplate binding = bpel2UDDI.createBPELBinding(serviceName, portName, serviceUrl, wsdlDefinition);
190 	    
191 		System.out.println("***** WSDL Port BindingTemplate: " + binding.getBindingKey());
192                 if (serialize)
193 		System.out.println(pBinding.print(binding));
194 		
195 		Assert.assertNotNull(binding.getTModelInstanceDetails());
196 	}
197 	
198 	@Test
199 	public void testHelloWorld_FindTModelForProcessName() throws JAXBException {
200 		
201 		QName processName = new QName("http://www.jboss.org/bpel/examples/wsdl","HelloWorld");
202 		 
203 		FindTModel findTModel = bpel2UDDI.createFindTModelForProcessName(processName);
204 		
205 		System.out.println("***** Find TModel For ProcessName: " + processName);
206                 if (serialize)
207 		System.out.println(pFindTModel.print(findTModel));
208 		
209 		Assert.assertNotNull(findTModel.getCategoryBag());
210 	}
211 }