KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > AdminLimitTest


1 package org.jacorb.test.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2003 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import junit.framework.Test;
28
29 import org.jacorb.notification.OfferManager;
30 import org.jacorb.notification.SubscriptionManager;
31 import org.jacorb.notification.interfaces.ApplicationEvent;
32 import org.jacorb.notification.interfaces.ProxyEvent;
33 import org.jacorb.notification.interfaces.ProxyEventListener;
34 import org.jacorb.notification.servant.ConsumerAdminImpl;
35 import org.jacorb.notification.servant.IEventChannel;
36 import org.jacorb.notification.util.QoSPropertySet;
37 import org.omg.CORBA.IntHolder JavaDoc;
38 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded;
39 import org.omg.CosNotifyChannelAdmin.ClientType;
40 import org.omg.CosNotifyChannelAdmin.ConsumerAdminOperations;
41 import org.omg.CosNotifyChannelAdmin.EventChannel;
42 import org.omg.CosNotifyChannelAdmin.ProxySupplier;
43 import org.picocontainer.MutablePicoContainer;
44
45 import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
46
47 /**
48  * @author Alphonse Bendt
49  * @version $Id: AdminLimitTest.java,v 1.19 2005/05/04 14:00:32 alphonse.bendt Exp $
50  */

51
52 public class AdminLimitTest extends NotificationTestCase
53 {
54     private ConsumerAdminImpl objectUnderTest_;
55
56     private ConsumerAdminOperations consumerAdmin_;
57
58     public void setUpTest() throws Exception JavaDoc
59     {
60         QoSPropertySet _qosSettings = new QoSPropertySet(getConfiguration(),
61                 QoSPropertySet.ADMIN_QOS);
62
63         getPicoContainer().registerComponentImplementation(OfferManager.class);
64         getPicoContainer().registerComponentImplementation(SubscriptionManager.class);
65
66         IEventChannel channel = new IEventChannel()
67         {
68             public MutablePicoContainer getContainer()
69             {
70                 return getPicoContainer();
71             }
72
73             public EventChannel getEventChannel()
74             {
75                 try
76                 {
77                     return getDefaultChannel();
78                 } catch (Exception JavaDoc e)
79                 {
80                     throw new RuntimeException JavaDoc();
81                 }
82             }
83
84             public int getAdminID()
85             {
86                 return 20;
87             }
88
89             public int getChannelID()
90             {
91                 return 10;
92             }
93             
94             public void destroy()
95             {
96                 // nothing to do
97
}
98         };
99
100         objectUnderTest_ = new ConsumerAdminImpl(channel, getORB(), getPOA(),
101                 getConfiguration(), getMessageFactory(), (OfferManager) getPicoContainer()
102                         .getComponentInstance(OfferManager.class), (SubscriptionManager) getPicoContainer()
103                         .getComponentInstance(SubscriptionManager.class));
104
105         objectUnderTest_.set_qos(_qosSettings.get_qos());
106
107         consumerAdmin_ = objectUnderTest_;
108     }
109
110     public void testBasics() throws Exception JavaDoc
111     {
112         assertEquals(20, consumerAdmin_.MyID());
113         
114         assertEquals(getDefaultChannel(), consumerAdmin_.MyChannel());
115     }
116
117     public void testObtainNotificationPullSupplierFiresEvent() throws Exception JavaDoc
118     {
119         IntHolder JavaDoc _proxyId = new IntHolder JavaDoc();
120
121         final List JavaDoc _events = new ArrayList JavaDoc();
122
123         ProxyEventListener _listener = new ProxyEventListener()
124         {
125             public void actionProxyCreationRequest(ProxyEvent event) throws AdminLimitExceeded
126             {
127                 _events.add(event);
128             }
129
130             public void actionProxyCreated(ProxyEvent event)
131             {
132                 // nothing to do
133
}
134
135             public void actionProxyDisposed(ProxyEvent event)
136             {
137                 // ignore
138
}
139         };
140
141         objectUnderTest_.addProxyEventListener(_listener);
142
143         ProxySupplier _proxySupplier = objectUnderTest_.obtain_notification_pull_supplier(
144                 ClientType.STRUCTURED_EVENT, _proxyId);
145
146         assertNotNull(_proxySupplier);
147
148         assertEquals(1, _events.size());
149
150         assertEquals(objectUnderTest_, ((ApplicationEvent) _events.get(0)).getSource());
151     }
152
153     public void testDenyCreateNotificationPullSupplier() throws Exception JavaDoc
154     {
155         IntHolder JavaDoc _proxyId = new IntHolder JavaDoc();
156
157         ProxyEventListener _listener = new ProxyEventListener()
158         {
159             public void actionProxyCreationRequest(ProxyEvent e) throws AdminLimitExceeded
160             {
161                 throw new AdminLimitExceeded();
162             }
163
164             public void actionProxyDisposed(ProxyEvent event)
165             {
166                 // ignored
167
}
168
169             public void actionProxyCreated(ProxyEvent event)
170             {
171                 // ignored
172
}
173         };
174
175         objectUnderTest_.addProxyEventListener(_listener);
176
177         try
178         {
179             objectUnderTest_.obtain_notification_pull_supplier(ClientType.STRUCTURED_EVENT,
180                     _proxyId);
181
182             fail();
183         } catch (AdminLimitExceeded e)
184         {
185             // expected
186
}
187     }
188
189     public void testEvents() throws Exception JavaDoc
190     {
191         IntHolder JavaDoc _proxyId = new IntHolder JavaDoc();
192         final SynchronizedInt _counter = new SynchronizedInt(0);
193
194         ProxyEventListener _listener = new ProxyEventListener()
195         {
196             public void actionProxyCreated(ProxyEvent event)
197             {
198                 // ignored
199
}
200
201             public void actionProxyDisposed(ProxyEvent event)
202             {
203                 // ignored
204
}
205
206             public void actionProxyCreationRequest(ProxyEvent event) throws AdminLimitExceeded
207             {
208                 _counter.increment();
209             }
210         };
211
212         objectUnderTest_.addProxyEventListener(_listener);
213
214         ProxySupplier[] _seqProxySupplier = new ProxySupplier[3];
215
216         _seqProxySupplier[0] = objectUnderTest_.obtain_notification_pull_supplier(
217                 ClientType.STRUCTURED_EVENT, _proxyId);
218         assertEquals(_seqProxySupplier[0], objectUnderTest_.get_proxy_supplier(_proxyId.value));
219
220         _seqProxySupplier[1] = objectUnderTest_.obtain_notification_pull_supplier(
221                 ClientType.ANY_EVENT, _proxyId);
222         assertEquals(_seqProxySupplier[1], objectUnderTest_.get_proxy_supplier(_proxyId.value));
223
224         _seqProxySupplier[2] = objectUnderTest_.obtain_notification_pull_supplier(
225                 ClientType.SEQUENCE_EVENT, _proxyId);
226         assertEquals(_seqProxySupplier[2], objectUnderTest_.get_proxy_supplier(_proxyId.value));
227
228         objectUnderTest_.obtain_pull_supplier();
229
230         assertEquals(3, _counter.get());
231     }
232
233     public AdminLimitTest(String JavaDoc name, NotificationTestCaseSetup setup)
234     {
235         super(name, setup);
236     }
237
238     public static Test suite() throws Exception JavaDoc
239     {
240         return NotificationTestCase.suite(AdminLimitTest.class);
241     }
242 }
Popular Tags