This project has retired. For details please refer to its
Attic page.
API_091_RMISubscriptionListenerIntegrationTest xref
1 package org.apache.juddi.api.impl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.net.URI;
18 import java.rmi.AccessException;
19 import java.rmi.NotBoundException;
20 import java.rmi.RemoteException;
21 import java.rmi.registry.LocateRegistry;
22 import java.rmi.registry.Registry;
23 import java.util.Iterator;
24 import java.util.Map;
25 import java.util.Random;
26
27 import org.apache.commons.configuration.ConfigurationException;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.juddi.api.util.SubscriptionListenerQuery;
31 import org.apache.juddi.v3.tck.TckBusiness;
32 import org.apache.juddi.v3.tck.TckBusinessService;
33 import org.apache.juddi.v3.tck.TckPublisher;
34 import org.apache.juddi.v3.tck.TckSecurity;
35 import org.apache.juddi.v3.tck.TckSubscriptionListener;
36 import org.apache.juddi.v3.tck.TckSubscriptionListenerRMI;
37 import org.apache.juddi.v3.tck.TckTModel;
38 import org.apache.juddi.v3.tck.UDDISubscriptionListenerImpl;
39 import org.junit.AfterClass;
40 import org.junit.Assert;
41 import org.junit.BeforeClass;
42 import org.junit.Test;
43 import org.uddi.v3_service.UDDISecurityPortType;
44
45
46
47
48 public class API_091_RMISubscriptionListenerIntegrationTest
49 {
50
51 private static Log logger = LogFactory.getLog(API_090_SubscriptionListenerIntegrationTest.class);
52 private static API_010_PublisherTest api010 = new API_010_PublisherTest();
53 private static TckTModel tckTModel = new TckTModel(new UDDIPublicationImpl(), new UDDIInquiryImpl());
54 private static TckBusiness tckBusiness = new TckBusiness(new UDDIPublicationImpl(), new UDDIInquiryImpl());
55 private static TckBusinessService tckBusinessService = new TckBusinessService(new UDDIPublicationImpl(), new UDDIInquiryImpl());
56 private static TckSubscriptionListenerRMI tckSubscriptionListenerRMI = new TckSubscriptionListenerRMI(new UDDISubscriptionImpl(), new UDDIPublicationImpl());
57
58 private static String authInfoJoe = null;
59
60 private static UDDISubscriptionListenerImpl rmiSubscriptionListenerService = null;
61 private static Registry registry;
62 private static String path = null;
63 private static Integer randomPort = null;
64
65 @AfterClass
66 public static void stopManager() throws ConfigurationException, AccessException, RemoteException, NotBoundException {
67
68
69 registry.unbind(path);
70 org.apache.juddi.Registry.stop();
71 }
72
73 @BeforeClass
74 public static void startManager() throws ConfigurationException {
75 org.apache.juddi.Registry.start();
76 try {
77
78 randomPort = 19800 + new Random().nextInt(99);
79 System.out.println("RMI Random port=" + randomPort);
80
81 URI rmiEndPoint = new URI("rmi://localhost:" + randomPort + "/tck/rmisubscriptionlistener");
82 registry = LocateRegistry.createRegistry(rmiEndPoint.getPort());
83 path = rmiEndPoint.getPath();
84
85
86 rmiSubscriptionListenerService = new UDDISubscriptionListenerImpl(0);
87
88 registry.bind(path,rmiSubscriptionListenerService);
89
90
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();
98 }
99
100
101
102
103 logger.debug("Getting auth tokens..");
104 try {
105
106 api010.saveJoePublisher();
107 UDDISecurityPortType security = new UDDISecurityImpl();
108 authInfoJoe = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
109 Assert.assertNotNull(authInfoJoe);
110
111 } catch (Exception e) {
112 logger.error(e.getMessage(), e);
113 Assert.fail("Could not obtain authInfo token.");
114 }
115 }
116
117 @Test
118 public void joePublisher() {
119 try {
120 UDDISubscriptionListenerImpl.notifcationMap.clear();
121 UDDISubscriptionListenerImpl.notificationCount=0;
122 tckTModel.saveJoePublisherTmodel(authInfoJoe);
123 tckBusiness.saveJoePublisherBusiness(authInfoJoe);
124 tckBusinessService.saveJoePublisherService(authInfoJoe);
125
126 tckSubscriptionListenerRMI.saveService(authInfoJoe, TckSubscriptionListener.LISTENER_RMI_SERVICE_XML, randomPort, "localhost");
127
128 tckSubscriptionListenerRMI.saveNotifierSubscription(authInfoJoe, TckSubscriptionListenerRMI.SUBSCRIPTION_XML_RMI);
129
130 tckBusinessService.updateJoePublisherService(authInfoJoe, "foo");
131
132
133 boolean found=API_090_SubscriptionListenerIntegrationTest.verifyDelivery("Service One");
134 if (!found)
135 {
136 logger.warn("The test failed, dumping any received notifications");
137 Iterator<Map.Entry<Integer, String>> iterator = UDDISubscriptionListenerImpl.notifcationMap.entrySet().iterator();
138 while (iterator.hasNext()){
139 logger.info("Notification RX: " +iterator.next().getValue());
140 }
141 }
142 Assert.assertTrue("Notification failed " +UDDISubscriptionListenerImpl.notificationCount + " items returned" , found);
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 } catch (Exception e) {
161 e.printStackTrace();
162
163 Assert.fail();
164 } finally {
165
166 tckSubscriptionListenerRMI.deleteNotifierSubscription(authInfoJoe, TckSubscriptionListenerRMI.SUBSCRIPTION_KEY_RMI);
167 tckBusinessService.deleteJoePublisherService(authInfoJoe);
168 tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
169 tckTModel.deleteJoePublisherTmodel(authInfoJoe);
170 }
171 }
172
173 }