This project has retired. For details please refer to its Attic page.
TckSubscription 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 java.util.ArrayList;
18  import java.util.List;
19  
20  import javax.xml.ws.Holder;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.juddi.jaxb.EntityCreator;
25  import org.junit.Assert;
26  import org.uddi.api_v3.BusinessDetail;
27  import org.uddi.api_v3.BusinessEntity;
28  import org.uddi.api_v3.BusinessService;
29  import org.uddi.api_v3.ServiceInfo;
30  import org.uddi.api_v3.ServiceInfos;
31  import org.uddi.api_v3.TModelDetail;
32  import org.uddi.api_v3.TModelList;
33  import org.uddi.sub_v3.DeleteSubscription;
34  import org.uddi.sub_v3.GetSubscriptionResults;
35  import org.uddi.sub_v3.KeyBag;
36  import org.uddi.sub_v3.Subscription;
37  import org.uddi.sub_v3.SubscriptionResultsList;
38  import org.uddi.v3_service.UDDISubscriptionPortType;
39  import static junit.framework.Assert.assertEquals;
40  import org.uddi.api_v3.CategoryBag;
41  import org.uddi.api_v3.FindTModel;
42  import org.uddi.api_v3.KeyedReference;
43  import org.uddi.v3_service.UDDIInquiryPortType;
44  import org.uddi.v3_service.UDDISecurityPortType;
45  
46  /**
47   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
48   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
49   * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
50   */
51  public class TckSubscription 
52  {	
53  	final static String JOE_SUBSCRIPTION_XML = "uddi_data/subscription/subscription1.xml";
54      final static String JOE_SUBSCRIPTION_KEY = "uddi:uddi.joepublisher.com:subscriptionone";
55  	final static String JOE_SUBSCRIPTIONRESULTS_XML = "uddi_data/subscription/subscriptionresults1.xml";
56  
57  	final static String SAM_SUBSCRIPTION_XML = "uddi_data/subscription/subscription2.xml";
58      final static String SAM_SUBSCRIPTION_KEY = "uddi:www.samco.com:subscriptionone";
59  	final static String SAM_SUBSCRIPTIONRESULTS_XML = "uddi_data/subscription/subscriptionresults2.xml";
60  	final static String SAM_DUMMYBUSINESSKEY = "uddi:www.this.key.doesnot.exist";
61  
62  	final static String SAM_SUBSCRIPTION2_XML = "uddi_data/subscription/subscription3.xml";
63      final static String SAM_SUBSCRIPTION2_KEY = "uddi:www.samco.com:subscriptiontwo";
64  	final static String SAM_SUBSCRIPTIONRESULTS2_XML = "uddi_data/subscription/subscriptionresults3.xml";
65  	 static int FINDQUALIFIER_TMODEL_TOTAL = 22;
66  
67  	final static String SAM_SUBSCRIPTION3_XML = "uddi_data/subscription/subscription4.xml";
68      final static String SAM_SUBSCRIPTION3_KEY = "uddi:www.samco.com:subscriptionthree";
69  	final static String SAM_SUBSCRIPTIONRESULTS3_XML = "uddi_data/subscription/subscriptionresults4.xml";
70  	
71  	private Log logger = LogFactory.getLog(this.getClass());
72      UDDISubscriptionPortType subscription = null;
73  	UDDISecurityPortType security = null;
74          UDDIInquiryPortType inquiry=null;
75  	
76  	public TckSubscription(UDDISubscriptionPortType subscription,UDDISecurityPortType security,UDDIInquiryPortType inquiry) {
77  		super();
78  		this.subscription = subscription;
79  		this.security = security;
80                  this.inquiry=inquiry;
81  	}
82  
83  	public void saveJoePublisherSubscription(String authInfoJoe, String subscriptionXML,String subscriptionKey) {
84  		saveSubscription(authInfoJoe, subscriptionXML, subscriptionKey, null);
85  	}
86  		
87  	public void saveJoePublisherSubscription(String authInfoJoe) {
88  		saveSubscription(authInfoJoe, JOE_SUBSCRIPTION_XML, JOE_SUBSCRIPTION_KEY, null);
89  	}
90           
91          public void saveJoePublisherSubscription(String authInfoJoe, String bindingkey) {
92  		saveSubscription(authInfoJoe, JOE_SUBSCRIPTION_XML, JOE_SUBSCRIPTION_KEY, bindingkey);
93  	}
94  
95  	public void deleteJoePublisherSubscription(String authInfoJoe) {
96  		deleteSubscription(authInfoJoe, JOE_SUBSCRIPTION_KEY);
97  	}
98  	
99  	public void getJoePublisherSubscriptionResults(String authInfoJoe) {		
100 		try {
101 			GetSubscriptionResults getSubResultsIn = (GetSubscriptionResults)EntityCreator.buildFromDoc(JOE_SUBSCRIPTIONRESULTS_XML, "org.uddi.sub_v3");
102 			getSubResultsIn.setAuthInfo(authInfoJoe);
103 			
104 			SubscriptionResultsList result = subscription.getSubscriptionResults(getSubResultsIn);
105 			if (result == null)
106 				Assert.fail("Null result from getSubscriptionResults operation");
107                         ServiceInfos sInfos=null;
108                         if (result.getServiceList()!=null)
109                                 sInfos = result.getServiceList().getServiceInfos();
110 			if (sInfos == null)
111 				Assert.fail("No result from getSubscriptionResults operation");
112 			List<ServiceInfo> siList = sInfos.getServiceInfo();
113 			if (siList == null || siList.size() == 0)
114 				Assert.fail("No result from getSubscriptionResults operation");
115 			ServiceInfo siOut = siList.get(0);
116 			
117 			BusinessService bsIn = (BusinessService)EntityCreator.buildFromDoc(TckBusinessService.JOE_SERVICE_XML, "org.uddi.api_v3");
118 
119 			assertEquals(bsIn.getServiceKey(), siOut.getServiceKey());
120 			
121 			TckValidator.checkNames(bsIn.getName(), siOut.getName());
122 		}
123 		catch(Exception e) {
124 			logger.error(e.getMessage(), e);
125 			Assert.fail("No exception should be thrown");		
126 		}
127 		
128 	}
129 	
130 	public void saveSamSyndicatorSubscription(String authInfoSam) {
131 		saveSubscription(authInfoSam, SAM_SUBSCRIPTION_XML, SAM_SUBSCRIPTION_KEY, null);
132 	}
133 
134 	public void saveSamSyndicatorSubscriptionWithChunkingOnFind(String authInfoSam) {
135 		saveSubscription(authInfoSam, SAM_SUBSCRIPTION2_XML, SAM_SUBSCRIPTION2_KEY, null);
136 	}
137 
138 	public void saveSamSyndicatorSubscriptionWithChunkingOnGet(String authInfoSam) {
139 		saveSubscription(authInfoSam, SAM_SUBSCRIPTION3_XML, SAM_SUBSCRIPTION3_KEY, null);
140 	}
141 	
142 	public void deleteSamSyndicatorSubscription(String authInfoSam) {
143 		deleteSubscription(authInfoSam, SAM_SUBSCRIPTION_KEY);
144 	}
145 
146 	public void deleteSamSyndicatorSubscriptionWithChunkingOnFind(String authInfoSam) {
147 		deleteSubscription(authInfoSam, SAM_SUBSCRIPTION2_KEY);
148 	}
149 
150 	public void deleteSamSyndicatorSubscriptionWithChunkingOnGet(String authInfoSam) {
151 		deleteSubscription(authInfoSam, SAM_SUBSCRIPTION3_KEY);
152 	}
153 	
154 	public void getSamSyndicatorSubscriptionResults(String authInfoSam) {		
155 		try {
156 			GetSubscriptionResults getSubResultsIn = (GetSubscriptionResults)EntityCreator.buildFromDoc(SAM_SUBSCRIPTIONRESULTS_XML, "org.uddi.sub_v3");
157 			getSubResultsIn.setAuthInfo(authInfoSam);
158 			
159 			SubscriptionResultsList result = subscription.getSubscriptionResults(getSubResultsIn);
160 			if (result == null)
161 				Assert.fail("Null result from getSubscriptionResults operation");
162 
163 			BusinessDetail busDetail = result.getBusinessDetail();
164 			if (busDetail == null)
165 				Assert.fail("No result from getSubscriptionResults operation");
166 			List<BusinessEntity> beList = busDetail.getBusinessEntity();
167 			if (beList == null || beList.size() == 0)
168 				Assert.fail("No result from getSubscriptionResults operation");
169 			BusinessEntity beOut = beList.get(0);
170 			
171 			BusinessEntity beIn = (BusinessEntity)EntityCreator.buildFromDoc(TckBusiness.SAM_BUSINESS_XML, "org.uddi.api_v3");
172 
173 			assertEquals(beIn.getBusinessKey(), beOut.getBusinessKey());
174 			
175 			TckValidator.checkNames(beIn.getName(), beOut.getName());
176 			TckValidator.checkDescriptions(beIn.getDescription(), beOut.getDescription());
177 			TckValidator.checkDiscoveryUrls(beIn.getDiscoveryURLs(), beOut.getDiscoveryURLs());
178 			TckValidator.checkContacts(beIn.getContacts(), beOut.getContacts());
179 			TckValidator.checkCategories(beIn.getCategoryBag(), beOut.getCategoryBag());
180 			
181 			List<KeyBag> keyBagList = result.getKeyBag();
182 			if (keyBagList == null || keyBagList.size() == 0)
183 				Assert.fail("No keyBag from SamSyndicator getSubscriptionResults operation");
184 			KeyBag keyBag = keyBagList.get(0);
185 			assertEquals(SAM_DUMMYBUSINESSKEY, keyBag.getBusinessKey().get(0));
186 			
187 		}
188 		catch(Exception e) {
189 			logger.error(e.getMessage(), e);
190 			Assert.fail("No exception should be thrown");		
191 		}
192 		
193 	}
194 	
195 	public void getSamSyndicatorSubscriptionResultsWithChunkingOnFind(String authInfoSam) {		
196 		try {
197                         
198 			GetSubscriptionResults getSubResultsIn = (GetSubscriptionResults)EntityCreator.buildFromDoc(SAM_SUBSCRIPTIONRESULTS2_XML, "org.uddi.sub_v3");
199 			getSubResultsIn.setAuthInfo(authInfoSam);
200                         FindTModel ftm = new FindTModel();
201                         ftm.setAuthInfo(authInfoSam);
202                         ftm.setCategoryBag(new CategoryBag());
203                         ftm.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:types", "uddi-org:types:findQualifier", "findQualifier"));
204                         TModelList findTModel = inquiry.findTModel(ftm);
205 			
206                         FINDQUALIFIER_TMODEL_TOTAL = findTModel.getListDescription().getActualCount();
207                         
208 			Subscription subIn = (Subscription)EntityCreator.buildFromDoc(SAM_SUBSCRIPTION2_XML, "org.uddi.sub_v3");
209 			
210 			int expectedIterations = FINDQUALIFIER_TMODEL_TOTAL / subIn.getMaxEntities();
211 			if (FINDQUALIFIER_TMODEL_TOTAL % subIn.getMaxEntities() >0)
212 				expectedIterations++;
213 			
214                         
215                         logger.info("getSamSyndicatorSubscriptionResultsWithChunkingOnFind loading from " + SAM_SUBSCRIPTION2_XML + " expecting " + FINDQUALIFIER_TMODEL_TOTAL + " find qualifier tmodels. Fetching "
216                         + subIn.getMaxEntities() + " at a time, expected iterations " + expectedIterations);
217 			
218 			String chunkToken = "";
219 			int iterations = 0;
220                         //JUDDI-655
221 			while (chunkToken != null && !chunkToken.equalsIgnoreCase("0")) {
222 				iterations++;
223                                 
224 				getSubResultsIn.setChunkToken(chunkToken);
225 				SubscriptionResultsList result = subscription.getSubscriptionResults(getSubResultsIn);
226 				if (result == null)
227 					Assert.fail("Null result from getSubscriptionResults operation");
228 				Assert.assertNotNull("Chunk token should either be not null or '0'",result.getChunkToken());
229 				TModelList tmodelList = result.getTModelList();
230 				if (tmodelList == null || tmodelList.getTModelInfos()==null)
231 					Assert.fail("No result from getSubscriptionResults operation on chunk attempt " + iterations);
232 
233 				int resultSize = tmodelList.getTModelInfos().getTModelInfo().size();
234 				
235 				if (iterations < expectedIterations)
236 					assertEquals(resultSize, subIn.getMaxEntities().intValue());
237 				else {
238 					if (FINDQUALIFIER_TMODEL_TOTAL % subIn.getMaxEntities() > 0)
239 						assertEquals(resultSize, FINDQUALIFIER_TMODEL_TOTAL % subIn.getMaxEntities());
240 					else
241 						assertEquals(resultSize, subIn.getMaxEntities().intValue());
242 				}
243 				
244 				chunkToken = result.getChunkToken();
245 				
246 			}
247 		
248 			assertEquals(iterations, expectedIterations);
249 		}
250 		catch(Exception e) {
251 			logger.error(e.getMessage(), e);
252 			Assert.fail("No exception should be thrown");		
253 		}
254 		
255 	}
256 	
257 	public void getSamSyndicatorSubscriptionResultsWithChunkingOnGet(String authInfoSam) {
258 		try {
259 			GetSubscriptionResults getSubResultsIn = (GetSubscriptionResults)EntityCreator.buildFromDoc(SAM_SUBSCRIPTIONRESULTS3_XML, "org.uddi.sub_v3");
260 			getSubResultsIn.setAuthInfo(authInfoSam);
261 					
262 			Subscription subIn = (Subscription)EntityCreator.buildFromDoc(SAM_SUBSCRIPTION3_XML, "org.uddi.sub_v3");
263 			
264                         FINDQUALIFIER_TMODEL_TOTAL = 22;
265                         
266 			int expectedIterations = FINDQUALIFIER_TMODEL_TOTAL / subIn.getMaxEntities();
267 			if (FINDQUALIFIER_TMODEL_TOTAL % subIn.getMaxEntities() >0)
268 				expectedIterations++;
269 			
270 			String chunkToken = "";
271 			int iterations = 0;
272 			while (chunkToken != null && !chunkToken.equalsIgnoreCase("0")) {
273 				iterations++;
274 				
275 				getSubResultsIn.setChunkToken(chunkToken);
276 				SubscriptionResultsList result = subscription.getSubscriptionResults(getSubResultsIn);
277 				if (result == null)
278 					Assert.fail("Null result from getSubscriptionResults operation");
279 				Assert.assertNotNull("Chunk token should either be not null or '0'",result.getChunkToken());
280 				TModelDetail tmodelDetail = result.getTModelDetail();
281 				if (tmodelDetail == null)
282 					Assert.fail("No result from getSubscriptionResults operation on chunk attempt " + iterations);
283 
284 				int resultSize = tmodelDetail.getTModel().size();
285 				
286 				if (iterations < expectedIterations)
287 					assertEquals(resultSize, subIn.getMaxEntities().intValue());
288 				else {
289 					if (FINDQUALIFIER_TMODEL_TOTAL % subIn.getMaxEntities() > 0)
290 						assertEquals(resultSize, FINDQUALIFIER_TMODEL_TOTAL % subIn.getMaxEntities());
291 					else
292 						assertEquals(resultSize, subIn.getMaxEntities().intValue());
293 				}
294 				
295 				chunkToken = result.getChunkToken();
296 				
297 			}
298 		
299 			assertEquals(iterations, expectedIterations);
300 		}
301 		catch(Exception e) {
302 			logger.error(e.getMessage(), e);
303 			Assert.fail("No exception should be thrown");		
304 		}
305 		
306 	}
307 	
308 	public void saveSubscription(String authInfo, String subscriptionXML, String subscriptionKey, String bindingkey) {
309 		try {
310 			Subscription subIn = (Subscription)EntityCreator.buildFromDoc(subscriptionXML, "org.uddi.sub_v3");
311 			List<Subscription> subscriptionList = new ArrayList<Subscription>();
312                         subIn.setSubscriptionKey(subscriptionKey);
313                        // if (subIn.getBindingKey()!=null && subIn.getBindingKey().length()==0){
314                          //       subIn.setBindingKey(null);
315                         //}
316                         subIn.setBindingKey(bindingkey);
317 			subscriptionList.add(subIn);
318 			Holder<List<Subscription>> subscriptionHolder = new Holder<List<Subscription>>();
319 			subscriptionHolder.value = subscriptionList;
320 			
321 			subscription.saveSubscription(authInfo, subscriptionHolder);
322 			
323 			Subscription subDirectOut = subscriptionHolder.value.get(0);
324 			assertEquals(subIn.getSubscriptionKey(), subDirectOut.getSubscriptionKey());
325 			
326 			List<Subscription> outSubscriptionList = subscription.getSubscriptions(authInfo);
327 			Assert.assertNotNull(outSubscriptionList);
328 			Subscription subOut = outSubscriptionList.get(0);
329 			
330 			assertEquals(subIn.getSubscriptionKey(), subOut.getSubscriptionKey());
331 			assertEquals(subDirectOut.getExpiresAfter().getMonth(), subOut.getExpiresAfter().getMonth());
332 			assertEquals(subDirectOut.getExpiresAfter().getDay(), subOut.getExpiresAfter().getDay());
333 			assertEquals(subDirectOut.getExpiresAfter().getYear(), subOut.getExpiresAfter().getYear());
334 			
335 			//assertEquals(subIn.getSubscriptionFilter().getFindService().getName().get(0).getValue(), 
336 			//			 subOut.getSubscriptionFilter().getFindService().getName().get(0).getValue());
337 			
338 		} catch (Exception e) {
339 			logger.error(e.getMessage(), e);
340 			Assert.fail("No exception should be thrown");		
341 		}
342 		
343 	}
344 	
345 	public void deleteSubscription(String authInfo, String subscriptionKey) {
346 		try {
347 			// Delete the entity and make sure it is removed
348 			DeleteSubscription ds = new DeleteSubscription();
349 			ds.setAuthInfo(authInfo);
350 			
351 			ds.getSubscriptionKey().add(subscriptionKey);
352 			subscription.deleteSubscription(ds);
353 		}
354 		catch(Exception e) {
355 			logger.error(e.getMessage(), e);
356 			Assert.fail("No exception should be thrown.");
357 		}
358 	}
359 		
360 }