This project has retired. For details please refer to its Attic page.
JUDDI_091_RMISubscriptionListenerIntegrationTest 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.net.InetAddress;
18  import java.net.URI;
19  import java.rmi.registry.LocateRegistry;
20  import java.rmi.registry.Registry;
21  import java.util.Iterator;
22  import java.util.Random;
23  import javax.xml.ws.BindingProvider;
24  
25  import org.apache.commons.configuration.ConfigurationException;
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  import org.apache.juddi.v3.client.config.UDDIClient;
29  import org.apache.juddi.v3.client.transport.Transport;
30  import org.junit.AfterClass;
31  import org.junit.Assert;
32  import org.junit.Assume;
33  import org.junit.BeforeClass;
34  import org.junit.Test;
35  import org.uddi.v3_service.UDDIInquiryPortType;
36  import org.uddi.v3_service.UDDIPublicationPortType;
37  import org.uddi.v3_service.UDDISecurityPortType;
38  import org.uddi.v3_service.UDDISubscriptionPortType;
39  
40  /**
41   * jUDDI specific test
42   *
43   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
44   * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
45   */
46  public class JUDDI_091_RMISubscriptionListenerIntegrationTest {
47  
48          private static Log logger = LogFactory.getLog(JUDDI_091_RMISubscriptionListenerIntegrationTest.class);
49          private static TckTModel tckTModel = null;
50          private static TckBusiness tckBusiness = null;
51          private static TckBusinessService tckBusinessService = null;
52          private static TckSubscriptionListenerRMI rmiSubscriptionListener = null;
53          private static String authInfoJoe = null;
54          private static String hostname = null;
55          private static UDDIClient manager;
56          private static UDDISubscriptionListenerImpl rmiSubscriptionListenerService = null;
57          private static Registry registry;
58          private static Integer randomPort = null;
59  
60          @AfterClass
61          public static void stopManager() throws ConfigurationException {
62                  if (!TckPublisher.isEnabled()) return;
63                  if (manager!=null)
64                          manager.stop();
65                  //shutting down the TCK SubscriptionListener
66                  //re
67          }
68  
69          @BeforeClass
70          public static void startManager() throws ConfigurationException {
71  
72               if (!TckPublisher.isEnabled()) return;
73                  try {
74                          //bring up the RMISubscriptionListener
75                          //random port
76                          randomPort = 19800 + new Random().nextInt(99);
77                          logger.info("RMI Random port=" + randomPort);
78                          //bring up the RMISubscriptionListener
79                          //saw this once before
80                          // internal error: ObjID already in use
81                          URI rmiEndPoint = new URI("rmi://localhost:" + randomPort + "/tck/rmisubscriptionlistener");
82                          registry = LocateRegistry.createRegistry(rmiEndPoint.getPort());
83                          String path = rmiEndPoint.getPath();
84                          hostname = InetAddress.getLocalHost().getHostName();
85                          //starting the service
86                          rmiSubscriptionListenerService = new UDDISubscriptionListenerImpl(0);
87                          //binding to the RMI Registry
88                          registry.bind(path, rmiSubscriptionListenerService);
89  
90                          //double check that the service is bound in the local Registry
91                          Registry registry2 = LocateRegistry.getRegistry(rmiEndPoint.getHost(), rmiEndPoint.getPort());
92                          registry2.lookup(rmiEndPoint.getPath());
93  
94  
95                  } catch (Exception e2) {
96                          e2.printStackTrace();
97                          Assert.fail(e2.getMessage());
98                  }
99  
100                 manager = new UDDIClient();
101                 manager.start();
102 
103                 logger.debug("Getting auth tokens..");
104                 try {
105 
106                         Transport transport = manager.getTransport("uddiv3");
107                         UDDISecurityPortType security = transport.getUDDISecurityService();
108                         authInfoJoe = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
109 
110 
111                         UDDISubscriptionPortType subscription = transport.getUDDISubscriptionService();
112                         UDDIPublicationPortType publication = transport.getUDDIPublishService();
113                         UDDIInquiryPortType inquiry = transport.getUDDIInquiryService();
114 
115                         tckTModel = new TckTModel(publication, inquiry);
116                         tckBusiness = new TckBusiness(publication, inquiry);
117                         tckBusinessService = new TckBusinessService(publication, inquiry);
118                         rmiSubscriptionListener = new TckSubscriptionListenerRMI(subscription, publication);
119 
120                         if (!TckPublisher.isUDDIAuthMode()) {
121                                 TckSecurity.setCredentials((BindingProvider) publication, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
122                                 TckSecurity.setCredentials((BindingProvider) subscription, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
123                                 TckSecurity.setCredentials((BindingProvider) inquiry, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
124                         }
125 
126                 } catch (Exception e) {
127                         logger.error(e.getMessage(), e);
128                         Assert.fail("Could not obtain authInfo token." + e.getMessage());
129                 }
130                 JUDDI_300_MultiNodeIntegrationTest.testSetupReplicationConfig();
131         }
132 
133         @Test
134         public void joePublisher() {
135              Assume.assumeTrue(TckPublisher.isEnabled());
136                 Assume.assumeTrue(TckPublisher.isRMI());
137                 Assume.assumeTrue(TckPublisher.isSubscriptionEnabled());
138                 try {
139                         UDDISubscriptionListenerImpl.notifcationMap.clear();
140                         UDDISubscriptionListenerImpl.notificationCount=0;
141                         tckTModel.saveJoePublisherTmodel(authInfoJoe);
142                         tckBusiness.saveJoePublisherBusiness(authInfoJoe);
143                         tckBusinessService.saveJoePublisherService(authInfoJoe);
144                         rmiSubscriptionListener.saveService(authInfoJoe, TckSubscriptionListener.LISTENER_RMI_SERVICE_XML, randomPort, hostname);
145 
146                         rmiSubscriptionListener.saveNotifierSubscription(authInfoJoe, TckSubscriptionListenerRMI.SUBSCRIPTION_XML_RMI);
147 
148                         tckBusinessService.updateJoePublisherService(authInfoJoe, "foo");
149 
150                         //waiting up to 100 seconds for the listener to notice the change.
151                         
152                         for (int i = 0; i < 60; i++) {
153                                 Thread.sleep(1000);
154                                 
155                                 if (UDDISubscriptionListenerImpl.notificationCount > 0) {
156                                         break;
157                                 } 
158                         }
159                         if (UDDISubscriptionListenerImpl.notificationCount == 0) {
160                                 Assert.fail("No Notification was sent");
161                         }
162                         Iterator<String> it = UDDISubscriptionListenerImpl.notifcationMap.values().iterator();
163                         boolean found=false;
164                         while (it.hasNext()){
165                                 String test = it.next();
166                                 if (test.toLowerCase().contains("service one"))
167                                         found = true;
168                         }
169                         if (!found){
170                         //if (!UDDISubscriptionListenerImpl.notifcationMap.get(0).contains("<name xml:lang=\"en\">Service One</name>")) {
171                                 Assert.fail("Notification does not contain the correct service");
172                         }
173 
174                 } catch (Exception e) {
175                         e.printStackTrace();
176 
177                         Assert.fail(e.getMessage());
178                 } finally {
179 
180                         rmiSubscriptionListener.deleteNotifierSubscription(authInfoJoe, TckSubscriptionListenerRMI.SUBSCRIPTION_KEY_RMI);
181                         tckBusinessService.deleteJoePublisherService(authInfoJoe);
182                         tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
183                         tckTModel.deleteJoePublisherTmodel(authInfoJoe);
184                 }
185         }
186 }