This project has retired. For details please refer to its Attic page.
API_050_BindingTemplateTest 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.api.impl;
16  
17  import java.rmi.RemoteException;
18  
19  import org.apache.commons.configuration.ConfigurationException;
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.juddi.Registry;
23  import org.apache.juddi.v3.client.UDDIConstants;
24  import org.apache.juddi.v3.client.config.UDDIClient;
25  import org.apache.juddi.v3.client.config.UDDIClientContainer;
26  import org.apache.juddi.v3.client.ext.wsdm.WSDMQosConstants;
27  import org.apache.juddi.v3.client.mapping.ServiceLocator;
28  import org.apache.juddi.v3.client.transport.Transport;
29  import org.apache.juddi.v3.error.ValueNotAllowedException;
30  import org.apache.juddi.v3.tck.TckBindingTemplate;
31  import static org.apache.juddi.v3.tck.TckBindingTemplate.JOE_BINDING_KEY;
32  import static org.apache.juddi.v3.tck.TckBindingTemplate.JOE_BINDING_XML;
33  import org.apache.juddi.v3.tck.TckBusiness;
34  import org.apache.juddi.v3.tck.TckBusinessService;
35  import org.apache.juddi.v3.tck.TckCommon;
36  import org.apache.juddi.v3.tck.TckFindEntity;
37  import org.apache.juddi.v3.tck.TckPublisher;
38  import org.apache.juddi.v3.tck.TckSecurity;
39  import org.apache.juddi.v3.tck.TckTModel;
40  import org.junit.AfterClass;
41  import org.junit.Assert;
42  import org.junit.BeforeClass;
43  import org.junit.Ignore;
44  import org.junit.Test;
45  import org.uddi.api_v3.BindingDetail;
46  import org.uddi.api_v3.FindBinding;
47  import org.uddi.api_v3.FindTModel;
48  import org.uddi.api_v3.IdentifierBag;
49  import org.uddi.api_v3.KeyedReference;
50  import org.uddi.api_v3.TModelBag;
51  import org.uddi.v3_service.UDDIPublicationPortType;
52  import org.uddi.v3_service.UDDISecurityPortType;
53  
54  /**
55   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
56   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
57   */
58  public class API_050_BindingTemplateTest {
59  
60          private static Log logger = LogFactory.getLog(API_050_BindingTemplateTest.class);
61  
62          private static API_010_PublisherTest api010 = new API_010_PublisherTest();
63          private static TckTModel tckTModel = new TckTModel(new UDDIPublicationImpl(), new UDDIInquiryImpl());
64          private static TckBusiness tckBusiness = new TckBusiness(new UDDIPublicationImpl(), new UDDIInquiryImpl());
65          private static TckBusinessService tckBusinessService = new TckBusinessService(new UDDIPublicationImpl(), new UDDIInquiryImpl());
66          private static TckBindingTemplate tckBindingTemplate = new TckBindingTemplate(new UDDIPublicationImpl(), new UDDIInquiryImpl());
67          private static TckFindEntity tckFindEntity = new TckFindEntity(new UDDIInquiryImpl());
68  
69          private static String authInfoJoe = null;
70  
71          @BeforeClass
72          public static void setup() throws ConfigurationException {
73                  Registry.start();
74                  logger.debug("Getting auth token..");
75                  try {
76                          api010.saveJoePublisher();
77                          authInfoJoe = TckSecurity.getAuthToken(new UDDISecurityImpl(), TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
78                          UDDISecurityPortType security = new UDDISecurityImpl();
79                          String authInfoUDDI = TckSecurity.getAuthToken(security, TckPublisher.getUDDIPublisherId(), TckPublisher.getUDDIPassword());
80                          tckTModel.saveUDDIPublisherTmodel(authInfoUDDI);
81                          tckTModel.saveTModels(authInfoUDDI, TckTModel.TMODELS_XML);
82                  } catch (RemoteException e) {
83                          logger.error(e.getMessage(), e);
84                          Assert.fail("Could not obtain authInfo token.");
85                  }
86          }
87  
88          @AfterClass
89          public static void stopRegistry() throws ConfigurationException {
90                  Registry.stop();
91          }
92  
93          @Test
94          public void joepublisher() throws Exception {
95                  try {
96                          tckTModel.saveJoePublisherTmodel(authInfoJoe);
97                          tckBusiness.saveJoePublisherBusiness(authInfoJoe);
98                          tckBusinessService.saveJoePublisherService(authInfoJoe);
99                          tckBindingTemplate.saveJoePublisherBinding(authInfoJoe);
100                         tckBindingTemplate.deleteJoePublisherBinding(authInfoJoe);
101                 } finally {
102                         tckBusinessService.deleteJoePublisherService(authInfoJoe);
103                         tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
104                         tckTModel.deleteJoePublisherTmodel(authInfoJoe);
105                 }
106         }
107 
108         @Test
109         public void testSearchBinding() throws Exception {
110                 try {
111                         tckTModel.saveJoePublisherTmodel(authInfoJoe);
112                         tckBusiness.saveJoePublisherBusiness(authInfoJoe);
113                         tckBusinessService.saveJoePublisherService(authInfoJoe);
114 
115                         tckFindEntity.findServiceDetail("uddi:uddi.joepublisher.com:serviceone");
116                         tckBindingTemplate.deleteBinding(authInfoJoe, "uddi:uddi.joepublisher.com:bindingone");
117                         String serviceKey = tckFindEntity.findService(null);
118                         tckFindEntity.findServiceDetail(serviceKey);
119 
120                         tckBindingTemplate.saveJoePublisherBinding(authInfoJoe);
121 
122                         serviceKey = tckFindEntity.findService(null);
123                         tckFindEntity.findServiceDetail(serviceKey);
124 
125                         tckBindingTemplate.deleteJoePublisherBinding(authInfoJoe);
126 
127                         tckFindEntity.findService(null);
128                         tckFindEntity.findServiceDetail(serviceKey);
129                 } finally {
130                         tckBusinessService.deleteJoePublisherService(authInfoJoe);
131                         tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
132                         tckTModel.deleteJoePublisherTmodel(authInfoJoe);
133                 }
134         }
135 
136         /**
137          * https://issues.apache.org/jira/browse/JUDDI-728 Inquiry NPE on
138          * find_binding
139          *
140          * @throws Exception
141          */
142         @Test
143         public void testJUDDI_728() throws Exception {
144                 UDDIInquiryImpl inquiry = new UDDIInquiryImpl();
145                 FindBinding fb = new FindBinding();
146                 fb.setAuthInfo(authInfoJoe);
147                 org.uddi.api_v3.FindQualifiers fq = new org.uddi.api_v3.FindQualifiers();
148                 fq.getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
149                 fb.setFindQualifiers(fq);
150                 fb.setFindTModel(new FindTModel());
151                 fb.getFindTModel().setIdentifierBag(new IdentifierBag());
152                 fb.getFindTModel().getIdentifierBag().getKeyedReference().add(new KeyedReference(WSDMQosConstants.METRIC_FAULT_COUNT_KEY, "%", "%"));
153                 inquiry.findBinding(fb);
154         }
155 
156         /**
157          * https://issues.apache.org/jira/browse/JUDDI-899 findBinding by
158          * category bag doesn't work
159          *
160          * @throws Exception
161          */
162         @Test 
163         public void testJUDDI_899() throws Exception {
164                 try {
165                         tckTModel.saveJoePublisherTmodel(authInfoJoe);
166                         tckBusiness.saveJoePublisherBusiness(authInfoJoe);
167                         tckBusinessService.saveJoePublisherService(authInfoJoe);
168                         tckBindingTemplate.saveJoePublisherBinding(authInfoJoe);
169                         
170                         UDDIInquiryImpl inquiry = new UDDIInquiryImpl();
171 
172                         FindBinding fb = new FindBinding();
173                         fb.setAuthInfo(authInfoJoe);
174 
175                         fb.setTModelBag(new TModelBag());
176                         //this is stored in joe's binding template 
177                         fb.getTModelBag().getTModelKey().add("uddi:uddi.org:protocol:serverauthenticatedssl3");
178                         logger.info("testJUDDI_899 searching...");
179                         BindingDetail findBinding = inquiry.findBinding(fb);
180                         logger.info("testJUDDI_899 searching complete.");
181                         Assert.assertNotNull(findBinding);
182                         Assert.assertNotNull(findBinding.getBindingTemplate());
183                         Assert.assertFalse(findBinding.getBindingTemplate().isEmpty());
184 
185                         for (int i = 0; i < findBinding.getBindingTemplate().size(); i++) {
186                                 if (findBinding.getBindingTemplate().get(i).getBindingKey().equals(TckBindingTemplate.JOE_BINDING_KEY)) {
187                                         return;
188                                 }
189                         }
190 
191                         Assert.fail("Binding wasn't returned");
192                 } finally {
193                         tckBusinessService.deleteJoePublisherService(authInfoJoe);
194                         tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
195                         tckTModel.deleteJoePublisherTmodel(authInfoJoe);
196                 }
197                 /*  if (findBinding.isTruncated()==null) {
198                  findBinding.setTruncated(false);
199                  }
200                  //support for paging
201                  while (!findBinding.isTruncated() && !findBinding.getBindingTemplate().isEmpty()) {
202                        
203                  findBinding = inquiry.findBinding(fb);
204                  Assert.assertNotNull(findBinding);
205                         
206                  if (findBinding.isTruncated()) {
207                  findBinding.setTruncated(false);
208                  }
209                  }
210 
211                  Assert.fail("The expected service wasn't returned");*/
212         }
213         
214         /**
215          * https://issues.apache.org/jira/browse/JUDDI-999
216          * max length test for tmodel instance info
217          */
218          @Test 
219         public void testJUDDI_999() throws Exception {
220             try {
221                         tckTModel.saveJoePublisherTmodel(authInfoJoe);
222                         tckBusiness.saveJoePublisherBusiness(authInfoJoe);
223                         tckBusinessService.saveJoePublisherService(authInfoJoe);
224                        tckBindingTemplate. saveBinding(authInfoJoe, "uddi_data/joepublisher/bindingTemplateMaxLength.xml", JOE_BINDING_KEY);
225                                 
226                 } finally {
227                         tckBusinessService.deleteJoePublisherService(authInfoJoe);
228                         tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
229                         tckTModel.deleteJoePublisherTmodel(authInfoJoe);
230                 }
231         }
232         
233         
234         /**
235          * https://issues.apache.org/jira/browse/JUDDI-999
236          * too long length test for tmodel instance info
237          */
238         
239         @Test(expected=org.apache.juddi.v3.error.ValueNotAllowedException.class)
240         public void testJUDDI_999_2() throws Exception {
241             try {
242                         tckTModel.saveJoePublisherTmodel(authInfoJoe);
243                         tckBusiness.saveJoePublisherBusiness(authInfoJoe);
244                         tckBusinessService.saveJoePublisherService(authInfoJoe);
245                         tckBindingTemplate.saveBinding(authInfoJoe, "uddi_data/joepublisher/bindingTemplateInvalid.xml", JOE_BINDING_KEY,false);
246                                 
247                 } finally {
248                         tckBusinessService.deleteJoePublisherService(authInfoJoe);
249                         tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
250                         tckTModel.deleteJoePublisherTmodel(authInfoJoe);
251                 }
252         }
253         
254         @Test
255         public void testJuddi937ServiceLocatorWithCache() throws Exception {
256                 try {
257                         tckTModel.saveJoePublisherTmodel(authInfoJoe);
258                         tckBusiness.saveJoePublisherBusiness(authInfoJoe);
259                         tckBusinessService.saveJoePublisherService(authInfoJoe);
260                         tckBindingTemplate.saveBinding(authInfoJoe, "uddi_data/joepublisher/bindingTemplate.xml", JOE_BINDING_KEY, false);
261 
262                         //create a client using invm transport
263                         UDDIClientContainer.removeAll();
264                         UDDIClient.clearServiceLocatorCaches();
265                         UDDIClient c = new UDDIClient("META-INF/uddi.xml");
266                         ServiceLocator serviceLocator = c.getServiceLocator("joe");
267                         serviceLocator.withSimpleCache();
268                         serviceLocator.clearCaches();
269                         String lookupEndpoint = serviceLocator.lookupEndpoint(TckBusinessService.JOE_SERVICE_KEY);
270                         String lookupEndpoint2 = serviceLocator.lookupEndpoint(TckBusinessService.JOE_SERVICE_KEY);
271                         System.out.println(TckCommon.DumpAllServices(authInfoJoe, c.getTransport("default").getUDDIInquiryService()));
272                         Assert.assertNotEquals(lookupEndpoint, lookupEndpoint2);
273                 } finally {
274                         tckBusinessService.deleteJoePublisherService(authInfoJoe);
275                         tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
276                         tckTModel.deleteJoePublisherTmodel(authInfoJoe);
277                 }
278          }
279         
280         
281         
282         @Test
283         public void testJuddi937ServiceLocatorWithoutCache() throws Exception {
284                 try {
285                     
286                         tckTModel.saveJoePublisherTmodel(authInfoJoe);
287                         tckBusiness.saveJoePublisherBusiness(authInfoJoe);
288                         tckBusinessService.saveJoePublisherService(authInfoJoe);
289                         tckBindingTemplate.saveBinding(authInfoJoe, "uddi_data/joepublisher/bindingTemplate.xml", JOE_BINDING_KEY, false);
290 
291                         //create a client using invm transport
292                         UDDIClientContainer.removeAll();
293                         UDDIClient.clearServiceLocatorCaches();
294                         UDDIClient c = new UDDIClient("META-INF/uddi.xml");
295                         ServiceLocator serviceLocator = c.getServiceLocator("joe");
296                         serviceLocator.clearCaches();
297                         //serviceLocator.withSimpleCache();
298                         String lookupEndpoint = serviceLocator.lookupEndpoint(TckBusinessService.JOE_SERVICE_KEY);
299                         String lookupEndpoint2 = serviceLocator.lookupEndpoint(TckBusinessService.JOE_SERVICE_KEY);
300                         
301                         System.out.println(TckCommon.DumpAllServices(authInfoJoe, c.getTransport("default").getUDDIInquiryService()));
302                         Assert.assertEquals(lookupEndpoint, lookupEndpoint2);
303                 } finally {
304                         tckBusinessService.deleteJoePublisherService(authInfoJoe);
305                         tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
306                         tckTModel.deleteJoePublisherTmodel(authInfoJoe);
307                 }
308          }
309 }