KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > typed > TypedProxyPullSupplierImplTest


1 package org.jacorb.test.notification.typed;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-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 import junit.framework.Test;
24
25 import org.easymock.MockControl;
26 import org.jacorb.notification.OfferManager;
27 import org.jacorb.notification.SubscriptionManager;
28 import org.jacorb.notification.TypedEventMessage;
29 import org.jacorb.notification.servant.ITypedAdmin;
30 import org.jacorb.notification.servant.TypedProxyPullSupplierImpl;
31 import org.jacorb.test.notification.NotificationTestCase;
32 import org.jacorb.test.notification.NotificationTestCaseSetup;
33 import org.omg.CORBA.IntHolder JavaDoc;
34 import org.omg.CORBA.StringHolder JavaDoc;
35 import org.omg.CosNotification.EventType;
36 import org.omg.CosNotification.Property;
37 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin;
38 import org.omg.CosNotifyChannelAdmin.ConsumerAdminPOATie;
39 import org.omg.CosNotifyComm.InvalidEventType;
40 import org.omg.CosNotifyComm.PullConsumerPOA;
41 import org.omg.CosTypedNotifyChannelAdmin.TypedProxyPullSupplier;
42 import org.omg.CosTypedNotifyChannelAdmin.TypedProxyPullSupplierHelper;
43
44 import EDU.oswego.cs.dl.util.concurrent.Latch;
45
46 /**
47  * @author Alphonse Bendt
48  * @version $Id: TypedProxyPullSupplierImplTest.java,v 1.5 2005/05/01 21:15:16 alphonse.bendt Exp $
49  */

50 public class TypedProxyPullSupplierImplTest extends NotificationTestCase
51 {
52     private TypedProxyPullSupplierImpl objectUnderTest_;
53
54     private TypedProxyPullSupplier proxyPullSupplier_;
55
56     private static String JavaDoc DRINKING_COFFEE_ID = "::org::jacorb::test::notification::typed::Coffee::drinking_coffee";
57
58     private MockControl controlAdmin_;
59
60     private ITypedAdmin mockAdmin_;
61
62     private ConsumerAdmin mockConsumerAdmin_;
63
64     private MockControl controlConsumerAdmin_;
65
66     public void setUpTest() throws Exception JavaDoc
67     {
68         controlAdmin_ = MockControl.createNiceControl(ITypedAdmin.class);
69         mockAdmin_ = (ITypedAdmin) controlAdmin_.getMock();
70         mockAdmin_.getProxyID();
71         controlAdmin_.setReturnValue(10);
72
73         mockAdmin_.isIDPublic();
74         controlAdmin_.setReturnValue(true);
75
76         mockAdmin_.getContainer();
77         controlAdmin_.setReturnValue(getPicoContainer());
78
79         mockAdmin_.getSupportedInterface();
80         controlAdmin_.setReturnValue(PullCoffeeHelper.id());
81
82         controlAdmin_.replay();
83
84         controlConsumerAdmin_ = MockControl.createControl(ConsumerAdmin.class);
85         mockConsumerAdmin_ = (ConsumerAdmin) controlConsumerAdmin_.getMock();
86
87         objectUnderTest_ = new TypedProxyPullSupplierImpl(mockAdmin_, new ConsumerAdminPOATie(
88                 mockConsumerAdmin_)._this(getORB()), getORB(), getPOA(), getConfiguration(),
89                 getTaskProcessor(), new OfferManager(), new SubscriptionManager(),
90                 getDynAnyFactory(), getRepository());
91
92         proxyPullSupplier_ = TypedProxyPullSupplierHelper.narrow(objectUnderTest_.activate());
93     }
94
95     public TypedProxyPullSupplierImplTest(String JavaDoc name, NotificationTestCaseSetup setup)
96     {
97         super(name, setup);
98     }
99
100     public void testID()
101     {
102         assertEquals(new Integer JavaDoc(10), objectUnderTest_.getID());
103         assertTrue(objectUnderTest_.isIDPublic());
104     }
105
106     public void testMyAdmin()
107     {
108         mockConsumerAdmin_.remove_all_filters();
109
110         controlConsumerAdmin_.replay();
111         proxyPullSupplier_.MyAdmin().remove_all_filters();
112
113         controlConsumerAdmin_.verify();
114     }
115
116     public void testConnect() throws Exception JavaDoc
117     {
118         NullPullConsumer _pullConsumer = new NullPullConsumer();
119
120         proxyPullSupplier_.connect_typed_pull_consumer(_pullConsumer._this(getClientORB()));
121     }
122
123     public void testEmptyPull() throws Exception JavaDoc
124     {
125         NullPullConsumer _pullConsumer = new NullPullConsumer();
126
127         proxyPullSupplier_.connect_typed_pull_consumer(_pullConsumer._this(getClientORB()));
128
129         org.omg.CORBA.Object JavaDoc _object = proxyPullSupplier_.get_typed_supplier();
130
131         String JavaDoc _objectAsString = _object.toString();
132
133         PullCoffee _pullCoffee = PullCoffeeHelper.narrow(getClientORB().string_to_object(
134                 _objectAsString));
135
136         StringHolder JavaDoc _name = new StringHolder JavaDoc();
137         IntHolder JavaDoc _minutes = new IntHolder JavaDoc();
138
139         assertFalse(_pullCoffee.try_drinking_coffee(_name, _minutes));
140     }
141
142     public void testTryPullDrinkingCoffee() throws Exception JavaDoc
143     {
144         TypedEventMessage _mesg = new TypedEventMessage();
145
146         _mesg.setTypedEvent(PullCoffeeHelper.id(), DRINKING_COFFEE_ID, new Property[] {
147                 new Property("name", toAny("jacorb")), new Property("minutes", toAny(10)) });
148
149         NullPullConsumer _pullConsumer = new NullPullConsumer();
150
151         proxyPullSupplier_.connect_typed_pull_consumer(_pullConsumer._this(getClientORB()));
152
153         org.omg.CORBA.Object JavaDoc _object = proxyPullSupplier_.get_typed_supplier();
154
155         String JavaDoc _objectAsString = _object.toString();
156
157         PullCoffee _pullCoffee = PullCoffeeHelper.narrow(getClientORB().string_to_object(
158                 _objectAsString));
159
160         StringHolder JavaDoc _name = new StringHolder JavaDoc();
161         IntHolder JavaDoc _minutes = new IntHolder JavaDoc();
162
163         objectUnderTest_.getMessageConsumer().deliverMessage(_mesg.getHandle());
164
165         assertTrue(_pullCoffee.try_drinking_coffee(_name, _minutes));
166
167         assertEquals("jacorb", _name.value);
168         assertEquals(10, _minutes.value);
169     }
170
171     public void testPullDrinkingCoffee() throws Exception JavaDoc
172     {
173         TypedEventMessage _mesg = new TypedEventMessage();
174
175         _mesg.setTypedEvent(PullCoffeeHelper.id(), DRINKING_COFFEE_ID, new Property[] {
176                 new Property("name", toAny("jacorb")), new Property("minutes", toAny(10)) });
177
178         NullPullConsumer _pullConsumer = new NullPullConsumer();
179
180         proxyPullSupplier_.connect_typed_pull_consumer(_pullConsumer._this(getClientORB()));
181
182         org.omg.CORBA.Object JavaDoc _object = proxyPullSupplier_.get_typed_supplier();
183
184         String JavaDoc _objectAsString = _object.toString();
185
186         final PullCoffee _pullCoffee = PullCoffeeHelper.narrow(getClientORB().string_to_object(
187                 _objectAsString));
188
189         final StringHolder JavaDoc _name = new StringHolder JavaDoc();
190         final IntHolder JavaDoc _minutes = new IntHolder JavaDoc();
191
192         final Latch _latch = new Latch();
193
194         new Thread JavaDoc()
195         {
196             public void run()
197             {
198                 _pullCoffee.drinking_coffee(_name, _minutes);
199                 _latch.release();
200             }
201         }.start();
202
203         objectUnderTest_.getMessageConsumer().deliverMessage(_mesg.getHandle());
204
205         assertTrue(_latch.attempt(1000));
206
207         assertEquals("jacorb", _name.value);
208         assertEquals(10, _minutes.value);
209     }
210
211     public static Test suite() throws Exception JavaDoc
212     {
213         return NotificationTestCase.suite(TypedProxyPullSupplierImplTest.class);
214     }
215 }
216
217 class NullPullConsumer extends PullConsumerPOA
218 {
219     public void offer_change(EventType[] eventTypeArray, EventType[] eventTypeArray1)
220             throws InvalidEventType
221     {
222         // no op
223
}
224
225     public void disconnect_pull_consumer()
226     {
227         // no op
228
}
229 }
Popular Tags