This project has retired. For details please refer to its Attic page.
UDDI_110_FindBusinessIntegrationTest xref
View Javadoc
1   package org.apache.juddi.v3.tck;
2   
3   /*
4    * Copyright 2001-2009 The Apache Software Foundation.
5    * 
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  import java.util.List;
18  import javax.xml.ws.BindingProvider;
19  
20  import org.apache.commons.configuration.ConfigurationException;
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.juddi.v3.client.config.UDDIClient;
24  import org.apache.juddi.v3.client.transport.Transport;
25  import org.junit.AfterClass;
26  import org.junit.Assert;
27  import org.junit.Assume;
28  import org.junit.BeforeClass;
29  import org.junit.Test;
30  import org.uddi.api_v3.BusinessInfo;
31  import org.uddi.api_v3.BusinessList;
32  import org.uddi.api_v3.DeleteBusiness;
33  import org.uddi.api_v3.FindBusiness;
34  import org.uddi.api_v3.ServiceInfo;
35  import org.uddi.api_v3.TModelBag;
36  import org.uddi.v3_service.UDDIInquiryPortType;
37  import org.uddi.v3_service.UDDIPublicationPortType;
38  import org.uddi.v3_service.UDDISecurityPortType;
39  
40  /**
41   * Test to verify JUDDI-398
42   *
43   * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
44   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
45   */
46  public class UDDI_110_FindBusinessIntegrationTest {
47  
48          final static String TOM_PUBLISHER_TMODEL_XML = "uddi_data/tompublisher/tModelKeyGen.xml";
49          final static String TOM_PUBLISHER_TMODEL01_XML = "uddi_data/tompublisher/tModel01.xml";
50          final static String TOM_PUBLISHER_TMODEL02_XML = "uddi_data/tompublisher/tModel02.xml";
51          final static String TOM_PUBLISHER_TMODEL_KEY = "uddi:uddi.tompublisher.com:keygenerator";
52          final static String TOM_PUBLISHER_TMODEL01_KEY = "uddi:uddi.tompublisher.com:tmodeltest01";
53          final static String TOM_PUBLISHER_TMODEL01_NAME = "tmodeltest01";
54          final static String TOM_PUBLISHER_TMODEL02_KEY = "uddi:uddi.tompublisher.com:tmodeltest02";
55          final static String TOM_BUSINESS_XML = "uddi_data/tompublisher/businessEntity.xml";
56          final static String TOM_BUSINESS_KEY = "uddi:uddi.tompublisher.com:businesstest01";
57          final static String TOM_PUBLISHER_SERVICEINFO_NAME = "servicetest01";
58          private static Log logger = LogFactory.getLog(UDDI_040_BusinessServiceIntegrationTest.class);
59          protected static TckTModel tckTModel = null;
60          protected static TckTModel tckTModel01 = null;
61          protected static TckTModel tckTModel02 = null;
62          protected static TckBusiness tckBusiness = null;
63          protected static String authInfoJoe = null;
64          private static UDDIInquiryPortType inquiry = null;
65          private static UDDIPublicationPortType publication=null;
66          private static UDDIClient manager;
67  
68          @AfterClass
69          public static void stopManager() throws ConfigurationException {
70               if (!TckPublisher.isEnabled()) return;
71                  tckTModel.deleteCreatedTModels(authInfoJoe);
72                  tckTModel01.deleteCreatedTModels(authInfoJoe);
73                  tckTModel02.deleteCreatedTModels(authInfoJoe);
74                  manager.stop();
75          }
76  
77          @BeforeClass
78          public static void startManager() throws ConfigurationException {
79               if (!TckPublisher.isEnabled()) return;
80                  manager = new UDDIClient();
81                  manager.start();
82  
83                  logger.debug("Getting auth tokens..");
84                  try {
85                          Transport transport = manager.getTransport("uddiv3");
86                          UDDISecurityPortType security = transport.getUDDISecurityService();
87                          authInfoJoe = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
88                          //Assert.assertNotNull(authInfoJoe);
89                          
90                          publication = transport.getUDDIPublishService();
91                          inquiry = transport.getUDDIInquiryService();
92                          if (!TckPublisher.isUDDIAuthMode()){
93                                  TckSecurity.setCredentials((BindingProvider) publication, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
94                                  TckSecurity.setCredentials((BindingProvider) inquiry, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
95                          }
96                          
97  
98                          tckTModel = new TckTModel(publication, inquiry);
99                          tckTModel01 = new TckTModel(publication, inquiry);
100                         tckTModel02 = new TckTModel(publication, inquiry);
101                         tckBusiness = new TckBusiness(publication, inquiry);
102 
103                 } catch (Exception e) {
104                         logger.error(e.getMessage(), e);
105                         Assert.fail("Could not obtain authInfo token.");
106                 }
107                 JUDDI_300_MultiNodeIntegrationTest.testSetupReplicationConfig();
108         }
109 
110         /**
111          * JUDDI-881
112          * "If a tModelBag or find_tModel was used in the search, the resulting serviceInfos structure reflects data only for the businessServices that actually contained a matching bindingTemplate.
113          */
114         @Test
115         public void findBusinessByTModelBag() {
116              Assume.assumeTrue(TckPublisher.isEnabled());
117                 try {
118                         tckTModel.saveTModel(authInfoJoe, TOM_PUBLISHER_TMODEL_XML, TOM_PUBLISHER_TMODEL_KEY);
119                         tckTModel.saveTModel(authInfoJoe, TOM_PUBLISHER_TMODEL01_XML, TOM_PUBLISHER_TMODEL01_KEY);
120                         tckTModel.saveTModel(authInfoJoe, TOM_PUBLISHER_TMODEL02_XML, TOM_PUBLISHER_TMODEL02_KEY);
121 
122                         try{
123                                   // Delete the entity and make sure it is removed
124                                 DeleteBusiness db = new DeleteBusiness();
125                                 db.setAuthInfo(authInfoJoe);
126                                 db.getBusinessKey().add(TOM_BUSINESS_KEY);
127                                 publication.deleteBusiness(db);
128                         }       catch (Exception ex){}
129                         tckBusiness.saveBusinesses(authInfoJoe, TOM_BUSINESS_XML, TOM_BUSINESS_KEY, 1);
130 
131                         String before =TckCommon.DumpAllBusinesses(authInfoJoe, inquiry);
132                         try {
133                                 int size = 0;
134                                 BusinessList bl = null;
135 
136                                 FindBusiness fbb = new FindBusiness();
137                                 TModelBag tmb = new TModelBag();
138                                 tmb.getTModelKey().add(TOM_PUBLISHER_TMODEL01_KEY);
139                                 fbb.setTModelBag(tmb);
140                                 bl = inquiry.findBusiness(fbb);
141                                 size = bl.getBusinessInfos().getBusinessInfo().size();
142                                 //JUDDI-881
143                                 
144                                 if (size != 1) {
145                                         logger.error("Test failed, dumping the business list " + before);
146                                         Assert.fail("Should have found one entry on FindBusiness with TModelBag, "
147                                                 + "found " + size);
148                                 } else {
149                                         List<BusinessInfo> biList = bl.getBusinessInfos().getBusinessInfo();
150                                         if (biList.get(0).getServiceInfos().getServiceInfo().size() != 1) {
151                                                 logger.error("Test failed, dumping the business list " + before);
152                                                 Assert.fail("Should have found one ServiceInfos");
153                                         } else {
154                                                 List<ServiceInfo> siList = biList.get(0).getServiceInfos().getServiceInfo();
155                                                 ServiceInfo si = siList.get(0);
156                                                 if (!TOM_PUBLISHER_SERVICEINFO_NAME.equals(si.getName().get(0).getValue())) {
157                                                         logger.error("Test failed, dumping the business list " + before);
158                                                         Assert.fail("Should have found " + TOM_PUBLISHER_TMODEL01_NAME + " as the "
159                                                                 + "ServiceInfo name, found " + si.getName().get(0).getValue());
160                                                 }
161                                         }
162                                 }
163                         } catch (Exception e) {
164                                 e.printStackTrace();
165                                 Assert.fail(e.getMessage());
166                         }
167                 } finally {
168                         tckBusiness.deleteBusinesses(authInfoJoe, TOM_BUSINESS_XML, TOM_BUSINESS_KEY, 1);
169 
170                         tckTModel.deleteTModel(authInfoJoe, TOM_PUBLISHER_TMODEL_XML, TOM_PUBLISHER_TMODEL_KEY);
171                         tckTModel.deleteTModel(authInfoJoe, TOM_PUBLISHER_TMODEL01_XML, TOM_PUBLISHER_TMODEL01_KEY);
172                         tckTModel.deleteTModel(authInfoJoe, TOM_PUBLISHER_TMODEL02_XML, TOM_PUBLISHER_TMODEL02_KEY);
173 
174                 }
175         }
176 }