This project has retired. For details please refer to its
Attic page.
WADL2UDDITest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.v3.client.mapping.wsdl;
17
18 import java.io.File;
19 import java.net.HttpURLConnection;
20 import java.net.MalformedURLException;
21 import java.net.URL;
22 import java.util.List;
23 import java.util.Properties;
24 import java.util.logging.Logger;
25
26 import javax.xml.namespace.QName;
27
28 import org.apache.juddi.jaxb.PrintUDDI;
29 import org.apache.juddi.v3.client.config.UDDIClerk;
30 import org.apache.juddi.v3.client.mapping.URLLocalizerDefaultImpl;
31 import org.apache.juddi.v3.client.mapping.wadl.Application;
32 import org.apache.juddi.v3.client.mapping.wadl.WADL2UDDI;
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.uddi.api_v3.BusinessService;
36 import org.uddi.api_v3.SaveTModel;
37 import org.uddi.api_v3.TModel;
38
39
40
41
42
43 public class WADL2UDDITest {
44
45 static final Logger log = Logger.getLogger(WADL2UDDITest.class.getCanonicalName());
46 static PrintUDDI<TModel> pTModel = new PrintUDDI<TModel>();
47 static Properties properties = new Properties();
48 static boolean serialize = false;
49
50 public WADL2UDDITest() {
51 if (System.getProperty("debug") != null && System.getProperty("debug").equalsIgnoreCase("true")) {
52 serialize = true;
53 }
54 }
55
56
57
58
59
60
61 @Test
62 public void Test1() throws Exception {
63 log.info("Test1 read from file");
64
65 Application app = WADL2UDDI.parseWadl(new File("src/test/resources/wadl/cxf.wadl"));
66 Assert.assertNotNull(app);
67 Assert.assertNotNull(app);
68 List<URL> urls = WADL2UDDI.getBaseAddresses(app);
69 URL url = urls.get(0);
70 String domain = url.getHost();
71 PrintUDDI<TModel> tmodelPrinter = new PrintUDDI<TModel>();
72 TModel keygen = UDDIClerk.createKeyGenator("uddi:" + domain + ":keygenerator", domain, "en");
73
74 SaveTModel stm = new SaveTModel();
75 stm.getTModel().add(keygen);
76 if (serialize) {
77 System.out.println(tmodelPrinter.print(keygen));
78 }
79
80 properties.put("keyDomain", domain);
81 properties.put("businessName", domain);
82 properties.put("serverName", url.getHost());
83 properties.put("serverPort", url.getPort());
84
85 WADL2UDDI wadl2UDDI = new WADL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
86
87 Assert.assertNotNull(wadl2UDDI);
88
89 BusinessService businessServices = wadl2UDDI.createBusinessService(new QName("CXF.Sample.WADL.namespace", "Servicename"), app);
90
91 Assert.assertNotNull(businessServices);
92 Assert.assertNotNull(businessServices.getBindingTemplates());
93 Assert.assertNotNull(businessServices.getName().get(0));
94 Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0));
95 Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0).getAccessPoint());
96 Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0).getAccessPoint().getValue());
97
98
99
100
101 PrintUDDI<BusinessService> servicePrinter = new PrintUDDI<BusinessService>();
102 if (serialize) {
103 System.out.println(servicePrinter.print(businessServices));
104 }
105
106
107
108 }
109
110 private static boolean IsReachable(String url) {
111 System.out.println("Testing connectivity to " + url);
112 try {
113
114 URL url2 = new URL(url);
115
116
117 HttpURLConnection urlConnect = (HttpURLConnection) url2.openConnection();
118
119
120
121 Object objData = urlConnect.getContent();
122 urlConnect.disconnect();
123
124 } catch (Exception e) {
125 System.out.println("Connectivity failed " + e.getMessage());
126 return false;
127 }
128 System.out.println("Connectivity passed");
129 return true;
130
131 }
132
133
134
135
136
137
138 @Test
139 public void Test2readFromURL() throws MalformedURLException, Exception {
140 log.info("Test2 read from URL");
141 boolean b = IsReachable("http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl");
142 if (!b) {
143 System.out.println("Skipping test for a remote WADL due to connectivity problems");
144 }
145
146
147 org.junit.Assume.assumeTrue(b);
148
149
150 Application app = WADL2UDDI.parseWadl(new URL("http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl"));
151 Assert.assertNotNull(app);
152 Assert.assertNotNull(app);
153 List<URL> urls = WADL2UDDI.getBaseAddresses(app);
154 URL url = urls.get(0);
155 String domain = url.getHost();
156 PrintUDDI<TModel> tmodelPrinter = new PrintUDDI<TModel>();
157 TModel keygen = UDDIClerk.createKeyGenator("uddi:" + domain + ":keygenerator", domain, "en");
158
159 SaveTModel stm = new SaveTModel();
160 stm.getTModel().add(keygen);
161 if (serialize) {
162 System.out.println(tmodelPrinter.print(keygen));
163 }
164
165 properties.put("keyDomain", domain);
166 properties.put("businessName", domain);
167 properties.put("serverName", url.getHost());
168 properties.put("serverPort", url.getPort());
169
170 WADL2UDDI wadl2UDDI = new WADL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
171
172 Assert.assertNotNull(wadl2UDDI);
173
174 BusinessService businessServices = wadl2UDDI.createBusinessService(new QName("CXF.Sample.WADL.namespace", "Servicename"), app);
175
176 Assert.assertNotNull(businessServices);
177 Assert.assertNotNull(businessServices.getBindingTemplates());
178 Assert.assertNotNull(businessServices.getName().get(0));
179 Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0));
180 Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0).getAccessPoint());
181 Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0).getAccessPoint().getValue());
182
183
184
185
186 PrintUDDI<BusinessService> servicePrinter = new PrintUDDI<BusinessService>();
187 if (serialize) {
188 System.out.println(servicePrinter.print(businessServices));
189 }
190
191
192 }
193 }