This project has retired. For details please refer to its Attic page.
JUDDI_010_PublisherIntegrationTest 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.rmi.RemoteException;
18  import java.util.List;
19  
20  import javax.xml.ws.soap.SOAPFaultException;
21  
22  import org.apache.commons.configuration.ConfigurationException;
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.juddi.api_v3.DeletePublisher;
26  import org.apache.juddi.api_v3.GetAllPublisherDetail;
27  import org.apache.juddi.api_v3.GetPublisherDetail;
28  import org.apache.juddi.api_v3.Publisher;
29  import org.apache.juddi.api_v3.PublisherDetail;
30  import org.apache.juddi.api_v3.SavePublisher;
31  import org.apache.juddi.jaxb.EntityCreator;
32  import org.apache.juddi.v3.client.config.UDDIClient;
33  import org.apache.juddi.v3.client.transport.Transport;
34  import org.apache.juddi.v3_service.JUDDIApiPortType;
35  import org.junit.AfterClass;
36  import org.junit.Assert;
37  import org.junit.Assume;
38  import org.junit.BeforeClass;
39  import org.junit.Test;
40  import org.uddi.api_v3.AuthToken;
41  import org.uddi.api_v3.GetAuthToken;
42  import org.uddi.v3_service.DispositionReportFaultMessage;
43  import org.uddi.v3_service.UDDISecurityPortType;
44  
45  /**
46   * jUDDI specific tests
47   *
48   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
49   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
50   */
51  public class JUDDI_010_PublisherIntegrationTest {
52  
53          private static Log logger = LogFactory.getLog(JUDDI_010_PublisherIntegrationTest.class);
54          private static UDDIClient manager;
55          private static UDDISecurityPortType security = null;
56          private static JUDDIApiPortType publisher = null;
57          private static String authInfo = null;
58  
59          @BeforeClass
60          public static void startManager() throws ConfigurationException {
61                  Assume.assumeTrue(TckPublisher.isJUDDI());
62                  if (!TckPublisher.isEnabled()) return;
63                  manager = new UDDIClient();
64                  manager.start();
65  
66  
67                  logger.debug("Getting auth tokens..");
68                  try {
69                          Transport transport = manager.getTransport("uddiv3");
70  
71                          security = transport.getUDDISecurityService();
72                          GetAuthToken getAuthToken = new GetAuthToken();
73                          getAuthToken.setUserID(TckPublisher.getRootPublisherId());
74                          getAuthToken.setCred(TckPublisher.getRootPassword());
75                          authInfo = security.getAuthToken(getAuthToken).getAuthInfo();
76  
77                          publisher = transport.getJUDDIApiService();
78                  } catch (Exception e) {
79                          logger.error(e.getMessage(), e);
80                          Assert.fail("Could not obtain authInfo token.");
81                  }
82                  JUDDI_300_MultiNodeIntegrationTest.testSetupReplicationConfig();
83          }
84  
85          @AfterClass
86          public static void stopManager() throws ConfigurationException {
87                  if (!TckPublisher.isEnabled()) return;
88                  manager.stop();
89          }
90  
91          @Test
92          public void testAuthToken() {
93                  Assume.assumeTrue(TckPublisher.isUDDIAuthMode());
94                  Assume.assumeTrue(TckPublisher.isEnabled());
95                  try {
96                          Transport transport = manager.getTransport("uddiv3");
97  
98                          UDDISecurityPortType securityService = transport.getUDDISecurityService();
99                          GetAuthToken getAuthToken = new GetAuthToken();
100                         getAuthToken.setUserID("root");
101                         getAuthToken.setCred("");
102                         AuthToken authToken = securityService.getAuthToken(getAuthToken);
103                         logger.info("don't log auth tokens!!!");
104                         Assert.assertNotNull(authToken);
105                 } catch (Exception e) {
106                         logger.error(e);
107                         Assert.fail();
108                 }
109         }
110 
111         @Test
112         public void testJoePublisher() {
113                 Assume.assumeTrue(TckPublisher.isJUDDI());
114                 Assume.assumeTrue(TckPublisher.isEnabled());
115                 //We can only test this if the publisher is not there already.
116                 //If it already there is probably has foreign key relationships.
117                 //This test should really only run on an empty database. Seed
118                 //data will be added if the root publisher is missing.
119                 if (!isExistPublisher(TckPublisher.getJoePublisherId())) {
120                         saveJoePublisher();
121                         deleteJoePublisher();
122                 }
123         }
124 
125         @Test
126         public void testSamSyndicator() {
127                 Assume.assumeTrue(TckPublisher.isJUDDI());
128                 Assume.assumeTrue(TckPublisher.isEnabled());
129                 //We can only test this if the publisher is not there already.
130                 if (!isExistPublisher(TckPublisher.getSamPublisherId())) {
131                         saveSamSyndicator();
132                         deleteSamSyndicator();
133                 }
134         }
135 
136         @Test
137         public void testGetAllPublishers() {
138                 Assume.assumeTrue(TckPublisher.isJUDDI());
139                 Assume.assumeTrue(TckPublisher.isEnabled());
140                 GetAllPublisherDetail gp = new GetAllPublisherDetail();
141                 gp.setAuthInfo(authInfo);
142                 try {
143                         PublisherDetail publisherDetail = publisher.getAllPublisherDetail(gp);
144                         Assert.assertTrue(publisherDetail.getPublisher().size() > 1);
145                 } catch (Exception e) {
146                         logger.error(e);
147                         Assert.fail();
148                 }
149         }
150 
151         /**
152          * Persists Joe Publisher to the database.
153          *
154          * @return - true if the published did not exist already, - false in all
155          * other cases.
156          */
157         public boolean saveJoePublisher() {
158                 Assume.assumeTrue(TckPublisher.isJUDDI());
159                 Assume.assumeTrue(TckPublisher.isEnabled());
160                 if (!isExistPublisher(TckPublisher.getJoePublisherId())) {
161                         savePublisher(TckPublisher.getJoePublisherId(), TckPublisher.JOE_PUBLISHER_XML);
162                         return true;
163                 } else {
164                         return false;
165                 }
166         }
167 
168         /**
169          * Removes Joe Publisher from the database, this will fail if there are
170          * child objects attached; think Services etc.
171          */
172         public void deleteJoePublisher() {
173                 Assume.assumeTrue(TckPublisher.isJUDDI());
174                 Assume.assumeTrue(TckPublisher.isEnabled());
175                 deletePublisher(TckPublisher.getJoePublisherId());
176         }
177 
178         /**
179          * Persists Sam Syndicator to the database.
180          *
181          * @return publisherId
182          */
183         public String saveSamSyndicator() {
184                 Assume.assumeTrue(TckPublisher.isJUDDI());
185                 Assume.assumeTrue(TckPublisher.isEnabled());
186                 if (!isExistPublisher(TckPublisher.getSamPublisherId())) {
187                         savePublisher(TckPublisher.getSamPublisherId(), TckPublisher.SAM_SYNDICATOR_XML);
188                 }
189                 return TckPublisher.getSamPublisherId();
190         }
191 
192         /**
193          * Removes Sam Syndicator from the database, this will fail if there are
194          * child objects attached; think Services etc.
195          */
196         public void deleteSamSyndicator() {
197                 Assume.assumeTrue(TckPublisher.isJUDDI());
198                 Assume.assumeTrue(TckPublisher.isEnabled());
199                 deletePublisher(TckPublisher.getSamPublisherId());
200         }
201 
202         private void savePublisher(String publisherId, String publisherXML) {
203                 try {
204                         authInfo = TckSecurity.getAuthToken(security, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
205                         logger.info("Saving new publisher: " + publisherXML);
206                         SavePublisher sp = new SavePublisher();
207                         sp.setAuthInfo(authInfo);
208                         Publisher pubIn = (Publisher) EntityCreator.buildFromDoc(publisherXML, "org.apache.juddi.api_v3");
209                         sp.getPublisher().add(pubIn);
210                         publisher.savePublisher(sp);
211 
212                         // Now get the entity and check the values
213                         GetPublisherDetail gp = new GetPublisherDetail();
214                         gp.getPublisherId().add(publisherId);
215                         gp.setAuthInfo(authInfo);
216                         PublisherDetail pd = publisher.getPublisherDetail(gp);
217                         List<Publisher> pubOutList = pd.getPublisher();
218                         Publisher pubOut = pubOutList.get(0);
219 
220                         Assert.assertEquals(pubIn.getAuthorizedName(), pubOut.getAuthorizedName());
221                         Assert.assertEquals(pubIn.getPublisherName(), pubOut.getPublisherName());
222                         Assert.assertEquals(pubIn.getEmailAddress(), pubOut.getEmailAddress());
223                         Assert.assertEquals(pubIn.isIsAdmin(), pubOut.isIsAdmin());
224                         Assert.assertEquals(pubIn.isIsEnabled(), pubOut.isIsEnabled());
225                         Assert.assertEquals(pubIn.getMaxBindingsPerService(), pubOut.getMaxBindingsPerService());
226                         Assert.assertEquals(pubIn.getMaxBusinesses(), pubOut.getMaxBusinesses());
227                         Assert.assertEquals(pubIn.getMaxServicePerBusiness(), pubOut.getMaxServicePerBusiness());
228                         Assert.assertEquals(pubIn.getMaxTModels(), pubOut.getMaxTModels());
229 
230                         logger.debug("Querying for publisher: " + publisherXML);
231                         //Querying for this publisher to make sure it's really gone
232                         //We're expecting a invalid Key exception at this point.
233                         PublisherDetail pdBeforeDelete = null;
234                         try {
235                                 pdBeforeDelete = publisher.getPublisherDetail(gp);
236                                 Assert.assertNotNull(pdBeforeDelete);
237                         } catch (Exception e) {
238                                 logger.error(e);
239                                 Assert.fail("We expected to find publisher " + publisherXML);
240                         }
241 
242                 } catch (Exception e) {
243                         logger.error(e.getMessage(), e);
244                         Assert.fail("No exception should be thrown");
245                 }
246         }
247 
248         private void deletePublisher(String publisherId) {
249                 try {
250                         authInfo = TckSecurity.getAuthToken(security, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
251                         logger.debug("Delete publisher: " + publisherId);
252                         //Now deleting this publisher
253                         DeletePublisher dp = new DeletePublisher();
254                         dp.setAuthInfo(authInfo);
255                         dp.getPublisherId().add(publisherId);
256                         publisher.deletePublisher(dp);
257 
258                         logger.info("Querying for publisher: " + publisherId + " after deletion.");
259                         //Querying for this publisher to make sure it's really gone
260                         //We're expecting a invalid Key exception at this point.
261                         GetPublisherDetail gp = new GetPublisherDetail();
262                         gp.getPublisherId().add(publisherId);
263                         gp.setAuthInfo(authInfo);
264                         PublisherDetail pdAfterDelete = null;
265                         try {
266                                 pdAfterDelete = publisher.getPublisherDetail(gp);
267                                 Assert.fail("We did not expect to find this publisher anymore.");
268                                 //don't think we really want a SOAPFaulException be thrown here.
269                         } catch (SOAPFaultException e) {
270                                 Assert.assertNull(pdAfterDelete);
271                         }
272 
273                 } catch (Exception e) {
274                         logger.error(e.getMessage(), e);
275                         Assert.fail("No exception should be thrown");
276                 }
277         }
278 
279         private boolean isExistPublisher(String publisherId) {
280                 GetPublisherDetail gp = new GetPublisherDetail();
281                 gp.setAuthInfo(authInfo);
282                 gp.getPublisherId().add(publisherId);
283                 try {
284                         publisher.getPublisherDetail(gp);
285                         return true;
286                 } catch (Exception e) {
287                         return false;
288                 }
289         }
290 
291         protected String authInfoJoe() throws RemoteException, DispositionReportFaultMessage {
292                 return TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
293         }
294 
295         protected String authInfoSam() throws RemoteException, DispositionReportFaultMessage {
296                 return TckSecurity.getAuthToken(security, TckPublisher.getSamPublisherId(), TckPublisher.getSamPassword());
297         }
298 
299 }