This project has retired. For details please refer to its Attic page.
TckFindEntity 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.tck;
16  
17  import static junit.framework.Assert.assertEquals;
18  import static junit.framework.Assert.assertTrue;
19  import static junit.framework.Assert.assertNotNull;
20  
21  import java.util.HashSet;
22  import java.util.List;
23  import java.util.Set;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.apache.juddi.jaxb.EntityCreator;
28  import org.junit.Assert;
29  import org.uddi.api_v3.BindingDetail;
30  import org.uddi.api_v3.BindingTemplate;
31  import org.uddi.api_v3.BindingTemplates;
32  import org.uddi.api_v3.BusinessDetail;
33  import org.uddi.api_v3.BusinessEntity;
34  import org.uddi.api_v3.BusinessInfo;
35  import org.uddi.api_v3.BusinessInfos;
36  import org.uddi.api_v3.BusinessList;
37  import org.uddi.api_v3.BusinessService;
38  import org.uddi.api_v3.FindBinding;
39  import org.uddi.api_v3.FindBusiness;
40  import org.uddi.api_v3.FindRelatedBusinesses;
41  import org.uddi.api_v3.FindService;
42  import org.uddi.api_v3.FindTModel;
43  import org.uddi.api_v3.GetBusinessDetail;
44  import org.uddi.api_v3.GetServiceDetail;
45  import org.uddi.api_v3.RelatedBusinessInfo;
46  import org.uddi.api_v3.RelatedBusinessInfos;
47  import org.uddi.api_v3.RelatedBusinessesList;
48  import org.uddi.api_v3.ServiceDetail;
49  import org.uddi.api_v3.ServiceInfo;
50  import org.uddi.api_v3.ServiceInfos;
51  import org.uddi.api_v3.ServiceList;
52  import org.uddi.api_v3.TModel;
53  import org.uddi.api_v3.TModelInfo;
54  import org.uddi.api_v3.TModelInfos;
55  import org.uddi.api_v3.TModelList;
56  import org.uddi.api_v3.DispositionReport;
57  import org.uddi.v3_service.DispositionReportFaultMessage;
58  import org.uddi.v3_service.UDDIInquiryPortType;
59  
60  /**
61   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
62   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
63   */
64  public class TckFindEntity 
65  {
66  	final static String FIND_BUSINESS_XML             = "uddi_data/find/findBusiness1.xml";
67  	final static String FIND_ALL_BUSINESSES_XML       = "uddi_data/find/findAllBusinesses.xml";
68  	final static String FIND_ALL_SIGNED_BUSINESSES_XML= "uddi_data/find/findAllSignedBusinesses.xml";
69  	final static String FIND_RELATED_BUSINESS_SORT_BY_NAME_XML = "uddi_data/find/findRelatedBusinesses_sortByName.xml";
70  	final static String FIND_RELATED_BUSINESS_FROM_KEY= "uddi_data/find/findRelatedBusinesses_fromKey.xml";
71  	final static String FIND_RELATED_BUSINESS_TO_KEY  = "uddi_data/find/findRelatedBusinesses_toKey.xml";
72  	final static String FIND_SERVICE_XML              = "uddi_data/find/findService1.xml";
73  	final static String FIND_BINDING_XML              = "uddi_data/find/findBinding1.xml";
74  	final static String FIND_TMODEL_XML               = "uddi_data/find/findTModel1.xml";
75  	final static String COMBINE_CAT_FIND_SERVICES     = "uddi_data/joepublisher/combineCatBagsFindServices.xml";
76  	   
77     
78  	private Log logger = LogFactory.getLog(this.getClass());
79  	UDDIInquiryPortType inquiry =null;
80  	
81  	public TckFindEntity(UDDIInquiryPortType inquiry) {
82  		super();
83  		this.inquiry = inquiry;
84  	}
85  
86  	public void findBusiness() {
87  		try {
88  			FindBusiness body = (FindBusiness)EntityCreator.buildFromDoc(FIND_BUSINESS_XML, "org.uddi.api_v3");
89  			BusinessList result = inquiry.findBusiness(body);
90  			if (result == null)
91  				Assert.fail("Null result from find business operation");
92  			BusinessInfos bInfos = result.getBusinessInfos();
93  			if (bInfos == null)
94  				Assert.fail("No result from find business operation");
95  			List<BusinessInfo> biList = bInfos.getBusinessInfo();
96  			if (biList == null || biList.size() == 0)
97  				Assert.fail("No result from find business operation");
98  			BusinessInfo biOut = biList.get(0);
99  			
100 			BusinessEntity beIn = (BusinessEntity)EntityCreator.buildFromDoc(TckBusiness.JOE_BUSINESS_XML, "org.uddi.api_v3");
101 			
102 			assertEquals(beIn.getBusinessKey(), biOut.getBusinessKey());
103 			
104 			TckValidator.checkNames(beIn.getName(), biOut.getName());
105 			TckValidator.checkDescriptions(beIn.getDescription(), biOut.getDescription());
106 		}
107 		catch(Exception e) {
108 			logger.error(e.getMessage(), e);
109 			Assert.fail("No exception should be thrown.");
110 		}
111 	}
112 	
113 	public void getNonExitingBusiness() {
114 		String nonExistingKey = "nonexistingKey";
115 		try {
116 			GetBusinessDetail body = new GetBusinessDetail();
117 			body.getBusinessKey().add(nonExistingKey);
118 			BusinessDetail  result = inquiry.getBusinessDetail(body);
119 			Assert.fail("No business should be found");
120 			System.out.println(result.getBusinessEntity().size());
121 		} catch (Exception e) {
122 			try {
123 				System.out.println("(Expected) Error message = " + e.getMessage());
124 				DispositionReport report = DispositionReportFaultMessage.getDispositionReport(e);
125 				assertNotNull(report);
126 				assertTrue(report.countainsErrorCode(DispositionReport.E_INVALID_KEY_PASSED));
127 			} catch (Exception e1) {
128 				Assert.fail("We only expect DispositionReportFaultMessage, not " + e1.getClass());
129 				logger.error(e.getMessage(), e1);
130 			}
131 		}
132 	}
133 	
134 	public void findAllBusiness() {
135 		try {
136 			FindBusiness body = (FindBusiness)EntityCreator.buildFromDoc(FIND_ALL_BUSINESSES_XML, "org.uddi.api_v3");
137 			BusinessList result = inquiry.findBusiness(body);
138 			if (result == null)
139 				Assert.fail("Null result from find business operation");
140 			BusinessInfos bInfos = result.getBusinessInfos();
141 			if (bInfos == null)
142 				Assert.fail("No result from find business operation");
143 			List<BusinessInfo> biList = bInfos.getBusinessInfo();
144 			if (biList == null || biList.size() == 0)
145 				Assert.fail("No result from find business operation");
146 			//expecting more than 2 businesses
147 			Assert.assertTrue(biList.size()>1);
148 			
149 		}
150 		catch(Exception e) {
151 			logger.error(e.getMessage(), e);
152 			Assert.fail("No exception should be thrown." + e.getMessage());
153 		}
154 	}
155 	
156 	public List<BusinessInfo> findAllSignedBusiness() {
157 		List<BusinessInfo> biList = null;
158 		try {
159 			FindBusiness body = (FindBusiness)EntityCreator.buildFromDoc(FIND_ALL_SIGNED_BUSINESSES_XML, "org.uddi.api_v3");
160 			BusinessList result = inquiry.findBusiness(body);
161 			if (result == null)
162 				Assert.fail("Null result from find business operation");
163 			BusinessInfos bInfos = result.getBusinessInfos();
164 			if (bInfos == null)
165 				Assert.fail("No result from find business operation");
166 			biList = bInfos.getBusinessInfo();
167 			if (biList == null || biList.size() == 0)
168 				Assert.fail("No result from find business operation");
169 			//expecting at one business
170 			Assert.assertTrue(biList.size()==1);
171 			return biList;
172 		}
173 		catch(Exception e) {
174 			logger.error(e.getMessage(), e);
175 			Assert.fail("No exception should be thrown.");
176 		}
177 		return biList;
178 	}
179 	
180 	public void findRelatedBusiness_sortByName(boolean isOneSided) {
181 		try {
182 			FindRelatedBusinesses body = (FindRelatedBusinesses)EntityCreator.buildFromDoc(FIND_RELATED_BUSINESS_SORT_BY_NAME_XML, "org.uddi.api_v3");
183 			RelatedBusinessesList result = inquiry.findRelatedBusinesses(body);
184 			if (result == null)
185 				Assert.fail("Null result from find related business operation");
186 			RelatedBusinessInfos bInfos = result.getRelatedBusinessInfos();
187 		
188 			//both parties need to register the assertion for it to be live.
189 			if (isOneSided) {
190 				Assert.assertNull(bInfos);
191 			} else {
192 				if (bInfos == null)
193 					Assert.fail("No result from find related business operation");
194 				List<RelatedBusinessInfo> biList = bInfos.getRelatedBusinessInfo();
195 				if (biList == null || biList.size() == 0)
196 					Assert.fail("No result from find related business operation");
197 				Set<String> keys = new HashSet<String>();
198 				for (RelatedBusinessInfo relatedBusinessInfo : biList) {
199 					keys.add(relatedBusinessInfo.getBusinessKey());
200 				}
201 				Assert.assertTrue(keys.contains("uddi:www.samco.com:samco"));
202 				Assert.assertTrue(keys.contains("uddi:uddi.marypublisher.com:marybusinessone"));
203 			}
204 		}
205 		catch(Exception e) {
206 			logger.error(e.getMessage(), e);
207 			Assert.fail("No exception should be thrown.");
208 		}
209 	}
210 	
211 	public void findRelatedBusinessToKey(boolean isOneSided) {
212 		try {
213 			FindRelatedBusinesses body = (FindRelatedBusinesses)EntityCreator.buildFromDoc(FIND_RELATED_BUSINESS_TO_KEY, "org.uddi.api_v3");
214 			RelatedBusinessesList result = inquiry.findRelatedBusinesses(body);
215 			if (result == null)
216 				Assert.fail("Null result from find related business operation");
217 			RelatedBusinessInfos bInfos = result.getRelatedBusinessInfos();
218 		
219 			//both parties need to register the assertion for it to be live.
220 			if (isOneSided) {
221 				Assert.assertNull(bInfos);
222 			} else {
223 				if (bInfos == null)
224 					Assert.fail("No result from find related business operation");
225 				List<RelatedBusinessInfo> biList = bInfos.getRelatedBusinessInfo();
226 				if (biList == null || biList.size() == 0)
227 					Assert.fail("No result from find related business operation");
228 				Set<String> keys = new HashSet<String>();
229 				for (RelatedBusinessInfo relatedBusinessInfo : biList) {
230 					keys.add(relatedBusinessInfo.getBusinessKey());
231 				}
232 				Assert.assertTrue(keys.contains("uddi:uddi.joepublisher.com:businessone"));
233 			}
234 		}
235 		catch(Exception e) {
236 			logger.error(e.getMessage(), e);
237 			Assert.fail("No exception should be thrown.");
238 		}
239 	}
240 	
241 	public void findRelatedBusinessFromKey(boolean isOneSided) {
242 		try {
243 			FindRelatedBusinesses body = (FindRelatedBusinesses)EntityCreator.buildFromDoc(FIND_RELATED_BUSINESS_FROM_KEY, "org.uddi.api_v3");
244 			RelatedBusinessesList result = inquiry.findRelatedBusinesses(body);
245 			if (result == null)
246 				Assert.fail("Null result from find related business operation");
247 			RelatedBusinessInfos bInfos = result.getRelatedBusinessInfos();
248 		
249 			//both parties need to register the assertion for it to be live.
250 			if (isOneSided) {
251 				Assert.assertNull(bInfos);
252 			} else {
253 				if (bInfos == null)
254 					Assert.fail("No result from find related business operation");
255 				List<RelatedBusinessInfo> biList = bInfos.getRelatedBusinessInfo();
256 				if (biList == null || biList.size() == 0)
257 					Assert.fail("No result from find related business operation");
258 				Set<String> keys = new HashSet<String>();
259 				for (RelatedBusinessInfo relatedBusinessInfo : biList) {
260 					keys.add(relatedBusinessInfo.getBusinessKey());
261 				}
262 				Assert.assertTrue(keys.contains("uddi:www.samco.com:samco"));
263 			}
264 		}
265 		catch(Exception e) {
266 			logger.error(e.getMessage(), e);
267 			Assert.fail("No exception should be thrown.");
268 		}
269 	}
270 	
271 	public String findService(String findQualifier) {
272 		String serviceKey = null;
273 		try {
274 			FindService body = (FindService)EntityCreator.buildFromDoc(FIND_SERVICE_XML, "org.uddi.api_v3");
275 			if (findQualifier!=null) body.getFindQualifiers().getFindQualifier().add(findQualifier);
276 			ServiceList result = inquiry.findService(body);
277 			if (result == null)
278 				Assert.fail("Null result from find service operation");
279 			ServiceInfos sInfos = result.getServiceInfos();
280 			if (sInfos == null)
281 				Assert.fail("No result from find service operation");
282 			List<ServiceInfo> siList = sInfos.getServiceInfo();
283 			if (siList == null || siList.size() == 0)
284 				Assert.fail("No result from find service operation");
285 			ServiceInfo siOut = siList.get(0);
286 			
287 			BusinessService bsIn = (BusinessService)EntityCreator.buildFromDoc(TckBusinessService.JOE_SERVICE_XML, "org.uddi.api_v3");
288 			
289 			assertEquals(bsIn.getServiceKey(), siOut.getServiceKey());
290 			
291 			TckValidator.checkNames(bsIn.getName(), siOut.getName());
292 			serviceKey = siOut.getServiceKey();
293 		}
294 		catch(Exception e) {
295 			logger.error(e.getMessage(), e);
296 			Assert.fail("No exception should be thrown.");
297 		}
298 		return serviceKey;
299 	}
300 	
301 	public String findService_CombinedCatBag() {
302 		String serviceKey = null;
303 		try {
304 			FindService body = (FindService)EntityCreator.buildFromDoc(COMBINE_CAT_FIND_SERVICES, "org.uddi.api_v3");
305 			ServiceList result = inquiry.findService(body);
306 			if (result == null)
307 				Assert.fail("Null result from find service operation");
308 			ServiceInfos sInfos = result.getServiceInfos();
309 			if (sInfos == null)
310 				Assert.fail("No result from find service operation");
311 			List<ServiceInfo> siList = sInfos.getServiceInfo();
312 			if (siList == null || siList.size() == 0)
313 				Assert.fail("No result from find service operation");
314 			ServiceInfo siOut = siList.get(0);
315 			
316 			serviceKey = siOut.getServiceKey();
317 		}
318 		catch(Exception e) {
319 			logger.error(e.getMessage(), e);
320 			Assert.fail("No exception should be thrown.");
321 		}
322 		return serviceKey;
323 	}
324 
325 	public void findServiceDetail(String serviceKey) {
326 		try {
327 			GetServiceDetail getServiceDetail = new GetServiceDetail();
328 			getServiceDetail.getServiceKey().add(serviceKey);
329 			
330 			
331 			ServiceDetail result = inquiry.getServiceDetail(getServiceDetail);
332 			
333 			if (result == null)
334 				Assert.fail("Null result from find service operation");
335 			
336 			BindingTemplates templates = result.getBusinessService().get(0).getBindingTemplates();
337 			if (templates!=null && templates.getBindingTemplate()!=null) {
338 				System.out.println(templates.getBindingTemplate().size());
339 				System.out.println("key=" + templates.getBindingTemplate().get(0).getBindingKey());
340 			}
341 //			ServiceInfos sInfos = result.getServiceInfos();
342 //			if (sInfos == null)
343 //				Assert.fail("No result from find service operation");
344 //			List<ServiceInfo> siList = sInfos.getServiceInfo();
345 //			if (siList == null || siList.size() == 0)
346 //				Assert.fail("No result from find service operation");
347 //			ServiceInfo siOut = siList.get(0);
348 //			
349 //			BusinessService bsIn = (BusinessService)EntityCreator.buildFromDoc(TckBusinessService.JOE_SERVICE_XML, "org.uddi.api_v3");
350 //			
351 //			assertEquals(bsIn.getServiceKey(), siOut.getServiceKey());
352 //			
353 //			TckValidator.checkNames(bsIn.getName(), siOut.getName());
354 		}
355 		catch(Exception e) {
356 			logger.error(e.getMessage(), e);
357 			Assert.fail("No exception should be thrown.");
358 		}
359 	}
360 	public void findBinding(String findQualifier) {
361 		try {
362 			FindBinding body = (FindBinding)EntityCreator.buildFromDoc(FIND_BINDING_XML, "org.uddi.api_v3");
363 			if (findQualifier!=null) body.getFindQualifiers().getFindQualifier().add(findQualifier);
364 			BindingDetail result = inquiry.findBinding(body);
365 			if (result == null)
366 				Assert.fail("Null result from find binding operation");
367 			List<BindingTemplate> btList = result.getBindingTemplate();
368 			if (btList == null || btList.size() == 0)
369 				Assert.fail("No result from find binding operation");
370 			BindingTemplate btOut = btList.get(0);
371 			
372 			BindingTemplate btIn = (BindingTemplate)EntityCreator.buildFromDoc(TckBindingTemplate.JOE_BINDING_XML, "org.uddi.api_v3");
373 			
374 			assertEquals(btIn.getServiceKey(), btOut.getServiceKey());
375 			assertEquals(btIn.getBindingKey(), btOut.getBindingKey());
376 			
377 			TckValidator.checkDescriptions(btIn.getDescription(), btOut.getDescription());
378 			TckValidator.checkCategories(btIn.getCategoryBag(), btOut.getCategoryBag());
379 		}
380 		catch(Exception e) {
381 			logger.error(e.getMessage(), e);
382 			Assert.fail("No exception should be thrown:  " + e.getMessage());
383 		}
384 	}
385 	
386 	public void findTModel(String findQualifier) {
387 		try {
388 			FindTModel body = (FindTModel)EntityCreator.buildFromDoc(FIND_TMODEL_XML, "org.uddi.api_v3");
389 			if (findQualifier!=null) body.getFindQualifiers().getFindQualifier().add(findQualifier);
390 			TModelList result = inquiry.findTModel(body);
391 			if (result == null)
392 				Assert.fail("Null result from find tModel operation");
393 			TModelInfos tInfos = result.getTModelInfos();
394 			if (tInfos == null)
395 				Assert.fail("No result from find tModel operation");
396 			List<TModelInfo> tiList = tInfos.getTModelInfo();
397 			if (tiList == null || tiList.size() == 0)
398 				Assert.fail("No result from find tModel operation");
399 			TModelInfo tiOut = tiList.get(0);
400 			
401 			TModel tmIn = (TModel)EntityCreator.buildFromDoc(TckTModel.JOE_PUBLISHER_TMODEL_XML, "org.uddi.api_v3");
402 			
403 			assertEquals(tmIn.getTModelKey(), tiOut.getTModelKey());
404 			assertEquals(tmIn.getName().getLang(), tiOut.getName().getLang());
405 			assertEquals(tmIn.getName().getValue(), tiOut.getName().getValue());
406 
407 			TckValidator.checkDescriptions(tmIn.getDescription(), tiOut.getDescription());
408 		}
409 		catch(Exception e) {
410 			logger.error(e.getMessage(), e);
411 			Assert.fail("No exception should be thrown.");
412 		}
413 	}
414 }