This project has retired. For details please refer to its
Attic page.
WSDLinaUDDIRegistryTest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.apache.juddi.v3.client.mapping.wsdl;
16
17 import java.io.IOException;
18 import java.util.HashSet;
19 import java.util.Iterator;
20 import java.util.Map;
21 import java.util.Properties;
22 import java.util.Set;
23
24 import javax.wsdl.Binding;
25 import javax.wsdl.Definition;
26 import javax.wsdl.PortType;
27 import javax.wsdl.WSDLException;
28 import javax.xml.bind.JAXBException;
29 import javax.xml.namespace.QName;
30
31 import org.apache.commons.configuration.ConfigurationException;
32 import org.apache.juddi.jaxb.EntityCreator;
33 import org.apache.juddi.jaxb.PrintUDDI;
34 import org.apache.juddi.v3.client.UDDIConstants;
35 import org.apache.juddi.v3.client.mapping.URLLocalizerDefaultImpl;
36 import org.apache.juddi.v3.client.mapping.wsdl.ReadWSDL;
37 import org.apache.juddi.v3.client.mapping.wsdl.WSDL2UDDI;
38 import org.junit.Assert;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41 import org.uddi.api_v3.BindingTemplate;
42 import org.uddi.api_v3.BusinessService;
43 import org.uddi.api_v3.BusinessServices;
44 import org.uddi.api_v3.KeyedReference;
45 import org.uddi.api_v3.TModel;
46 import org.uddi.v3_service.UDDISecurityPortType;
47
48
49
50
51
52 public class WSDLinaUDDIRegistryTest {
53
54 PrintUDDI<TModel> pTModel = new PrintUDDI<TModel>();
55 static ReadWSDL rw = new ReadWSDL();
56 static Definition wsdlDefinition = null;
57 static Definition wsdlDefinitionLongDescriptions = null;
58 static Properties properties = new Properties();
59 static String wsdlURL = null;
60 static boolean serialize = false;
61
62 public WSDLinaUDDIRegistryTest() {
63 if (System.getProperty("debug") != null && System.getProperty("debug").equalsIgnoreCase("true")) {
64 serialize = true;
65 }
66 }
67
68 @BeforeClass
69 public static void before() throws Exception {
70 try {
71 wsdlDefinition = rw.readWSDL("wsdl/sample.wsdl");
72 wsdlDefinitionLongDescriptions = rw.readWSDL("wsdl/sample_1.wsdl");
73 properties.put("keyDomain", "uddi.joepublisher.com");
74 properties.put("businessName", "samplebusiness");
75 properties.put("serverName", "api.example.org");
76 properties.put("serverPort", "80");
77 wsdlURL = wsdlDefinition.getDocumentBaseURI();
78 } catch (WSDLException e) {
79 e.printStackTrace();
80 Assert.fail(e.getMessage());
81 }
82 }
83
84 @Test
85 public void test_3_2_1_UDDI_portType_tModel() throws WSDLException, IOException, JAXBException, ConfigurationException {
86
87 WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
88 Set<TModel> tModels = new HashSet<TModel>();
89 @SuppressWarnings("unchecked")
90 Map<QName, PortType> portTypes = (Map<QName, PortType>) wsdlDefinition.getAllPortTypes();
91 Set<TModel> portTypeTModels = wsdl2UDDI.createWSDLPortTypeTModels(wsdlURL, portTypes);
92 tModels.addAll(portTypeTModels);
93
94 Assert.assertEquals(1, tModels.size());
95
96 TModel tModel = tModels.iterator().next();
97 System.out.println("UDDI PortType TModel " + tModel.getName().getValue());
98 if (serialize) {
99 System.out.println(pTModel.print(tModel));
100 }
101
102
103 String porttypeXml = "wsdl/uddiv3-xml/3_2_1_porttype.xml";
104 TModel specTModel = (org.uddi.api_v3.TModel) EntityCreator.buildFromDoc(porttypeXml, EntityCreator.UDDIv3_Package);
105
106
107 Assert.assertEquals(specTModel.getName().getValue(), tModel.getName().getValue());
108
109 Assert.assertNotNull(tModel.getOverviewDoc());
110 Assert.assertEquals(1, tModel.getOverviewDoc().size());
111 Assert.assertNotNull(tModel.getOverviewDoc().get(0).getOverviewURL());
112
113 Assert.assertTrue(specTModel.getOverviewDoc().get(0).getOverviewURL().getValue().endsWith("/sample.wsdl"));
114 Assert.assertTrue(tModel.getOverviewDoc().get(0).getOverviewURL().getValue().endsWith("/sample.wsdl"));
115
116
117 Assert.assertNotNull(tModel.getCategoryBag());
118 Assert.assertNotNull(tModel.getCategoryBag().getKeyedReference());
119 Assert.assertEquals(2, tModel.getCategoryBag().getKeyedReference().size());
120 for (KeyedReference keyedReference : tModel.getCategoryBag().getKeyedReference()) {
121 boolean match = false;
122 Iterator<KeyedReference> iter = specTModel.getCategoryBag().getKeyedReference().iterator();
123 while (iter.hasNext() && match == false) {
124 KeyedReference specKeyedRef = iter.next();
125 if (specKeyedRef.getTModelKey().equals(keyedReference.getTModelKey())) {
126 match = true;
127 Assert.assertEquals(specKeyedRef.getKeyName(), keyedReference.getKeyName());
128 Assert.assertEquals(specKeyedRef.getKeyValue(), keyedReference.getKeyValue());
129 }
130 }
131
132 Assert.assertTrue("Expected a match for keyedReference " + keyedReference.getTModelKey(), match);
133 }
134 }
135
136 @Test
137 public void test_3_2_2_UDDI_binding_tModel() throws WSDLException, JAXBException, IOException, ConfigurationException {
138
139 WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
140 @SuppressWarnings("unchecked")
141 Map<QName, Binding> bindings = (Map<QName, Binding>) wsdlDefinition.getAllBindings();
142 Set<TModel> tModels = wsdl2UDDI.createWSDLBindingTModels(wsdlURL, bindings);
143
144
145 Assert.assertEquals(1, tModels.size());
146
147 TModel tModel = tModels.iterator().next();
148 System.out.println("UDDI Binding TModel " + tModel.getName().getValue());
149 if (serialize) {
150 System.out.println(pTModel.print(tModel));
151 }
152
153
154 String bindingtmodelXml = "wsdl/uddiv3-xml/3_2_2_bindingtmodel.xml";
155 TModel specTModel = (org.uddi.api_v3.TModel) EntityCreator.buildFromDoc(bindingtmodelXml, EntityCreator.UDDIv3_Package);
156
157
158 Assert.assertEquals(specTModel.getName().getValue(), tModel.getName().getValue());
159
160 Assert.assertNotNull(tModel.getOverviewDoc());
161 Assert.assertEquals(1, tModel.getOverviewDoc().size());
162 Assert.assertNotNull(tModel.getOverviewDoc().get(0).getOverviewURL());
163
164
165 Assert.assertNotNull(tModel.getCategoryBag());
166 Assert.assertNotNull(tModel.getCategoryBag().getKeyedReference());
167 Assert.assertEquals(6, tModel.getCategoryBag().getKeyedReference().size());
168 for (KeyedReference keyedReference : tModel.getCategoryBag().getKeyedReference()) {
169 boolean match = false;
170 Iterator<KeyedReference> iter = specTModel.getCategoryBag().getKeyedReference().iterator();
171 while (iter.hasNext() && match == false) {
172 KeyedReference specKeyedRef = iter.next();
173 if (specKeyedRef.getTModelKey().equals(keyedReference.getTModelKey())) {
174 match = true;
175 Assert.assertEquals(specKeyedRef.getKeyName(), keyedReference.getKeyName());
176 Assert.assertEquals(specKeyedRef.getKeyValue(), keyedReference.getKeyValue());
177 }
178 }
179
180 Assert.assertTrue("Expected a match for keyedReference " + keyedReference.getTModelKey(), match);
181 }
182 }
183
184 @Test
185 public void test_3_2_3_UDDI_businessService_and_bindingTemplate() throws JAXBException, IOException, ConfigurationException {
186 WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
187
188 BusinessServices businessServices = wsdl2UDDI.createBusinessServices(wsdlDefinition);
189 PrintUDDI<BusinessService> servicePrinter = new PrintUDDI<BusinessService>();
190
191 Assert.assertEquals(1, businessServices.getBusinessService().size());
192
193 BusinessService businessService = businessServices.getBusinessService().get(0);
194
195 System.out.println(businessService.getName().get(0).getValue());
196 if (serialize) {
197 System.out.println(servicePrinter.print(businessService));
198 }
199
200
201 String businessServiceXml = "wsdl/uddiv3-xml/3_2_3_business_service.xml";
202 BusinessService specBusinessService = (org.uddi.api_v3.BusinessService) EntityCreator.buildFromDoc(businessServiceXml, EntityCreator.UDDIv3_Package);
203
204
205 Assert.assertEquals(specBusinessService.getName().get(0).getValue(), businessService.getName().get(0).getValue());
206
207 Assert.assertNotNull(businessService.getBindingTemplates());
208 Assert.assertEquals(1, businessService.getBindingTemplates().getBindingTemplate().size());
209 BindingTemplate bindingTemplate = businessService.getBindingTemplates().getBindingTemplate().get(0);
210 Assert.assertNotNull(bindingTemplate);
211 BindingTemplate specBindingTemplate = specBusinessService.getBindingTemplates().getBindingTemplate().get(0);
212
213 Assert.assertEquals(specBindingTemplate.getBindingKey(), bindingTemplate.getBindingKey());
214 Assert.assertEquals(specBindingTemplate.getServiceKey(), bindingTemplate.getServiceKey());
215 Assert.assertEquals(specBindingTemplate.getAccessPoint().getValue(), bindingTemplate.getAccessPoint().getValue());
216 Assert.assertTrue(2 <= bindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().size());
217
218 Assert.assertEquals(specBindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().get(0).getTModelKey(),
219 bindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().get(0).getTModelKey());
220 Assert.assertEquals(specBindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().get(0).getInstanceDetails().getInstanceParms(),
221 bindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().get(0).getInstanceDetails().getInstanceParms());
222
223 Assert.assertEquals(specBindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().get(1).getTModelKey(),
224 bindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().get(1).getTModelKey());
225
226
227
228 Assert.assertNotNull(businessService.getCategoryBag());
229 Assert.assertNotNull(businessService.getCategoryBag().getKeyedReference());
230 Assert.assertEquals(3, businessService.getCategoryBag().getKeyedReference().size());
231 for (KeyedReference keyedReference : businessService.getCategoryBag().getKeyedReference()) {
232 boolean match = false;
233 Iterator<KeyedReference> iter = specBusinessService.getCategoryBag().getKeyedReference().iterator();
234 while (iter.hasNext() && match == false) {
235 KeyedReference specKeyedRef = iter.next();
236 if (specKeyedRef.getTModelKey().equals(keyedReference.getTModelKey())) {
237 match = true;
238 Assert.assertEquals(specKeyedRef.getKeyName(), keyedReference.getKeyName());
239 Assert.assertEquals(specKeyedRef.getKeyValue(), keyedReference.getKeyValue());
240 }
241 }
242
243 Assert.assertTrue("Expected a match for keyedReference " + keyedReference.getTModelKey(), match);
244 }
245
246 }
247
248 @Test
249 public void test_3_2_3_UDDI_businessService_and_bindingTemplateLongDescriptions() throws JAXBException, IOException, ConfigurationException {
250 WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
251
252 BusinessServices businessServices = wsdl2UDDI.createBusinessServices(wsdlDefinitionLongDescriptions);
253 PrintUDDI<BusinessService> servicePrinter = new PrintUDDI<BusinessService>();
254
255 Assert.assertEquals(1, businessServices.getBusinessService().size());
256
257 BusinessService businessService = businessServices.getBusinessService().get(0);
258
259 System.out.println(businessService.getName().get(0).getValue());
260 if (serialize) {
261 System.out.println(servicePrinter.print(businessService));
262 }
263
264 for (int i = 0; i < businessService.getDescription().size(); i++) {
265 Assert.assertTrue(businessService.getDescription().get(i).getValue().length() <= UDDIConstants.MAX_description_length);
266 Assert.assertTrue(businessService.getDescription().get(i).getLang().length() <= UDDIConstants.MAX_xml_lang_length);
267 }
268 if (businessService.getBindingTemplates() != null) {
269 for (int i = 0; i < businessService.getBindingTemplates().getBindingTemplate().size(); i++) {
270 for (int k = 0; k < businessService.getBindingTemplates().getBindingTemplate().get(i).getDescription().size(); k++) {
271 for (int i2 = 0; i2 < businessService.getBindingTemplates().getBindingTemplate().get(i).getDescription().size(); i2++) {
272 Assert.assertTrue(Integer.toString(businessService.getBindingTemplates().getBindingTemplate().get(i).getDescription().get(i2).getValue().length()), businessService.getBindingTemplates().getBindingTemplate().get(i).getDescription().get(i2).getValue().length() <= UDDIConstants.MAX_description_length);
273 Assert.assertTrue(businessService.getBindingTemplates().getBindingTemplate().get(i).getDescription().get(i2).getLang().length() <= UDDIConstants.MAX_xml_lang_length);
274 }
275 }
276
277 }
278 }
279
280 }
281
282 }