KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > servant > AbstractProxySupplierTest


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

21
22 package org.jacorb.test.notification.servant;
23
24 import java.util.List JavaDoc;
25
26 import junit.framework.Test;
27
28 import org.easymock.MockControl;
29 import org.jacorb.notification.OfferManager;
30 import org.jacorb.notification.SubscriptionManager;
31 import org.jacorb.notification.interfaces.Message;
32 import org.jacorb.notification.interfaces.MessageConsumer;
33 import org.jacorb.notification.servant.AbstractProxySupplier;
34 import org.jacorb.notification.servant.IAdmin;
35 import org.jacorb.test.notification.NotificationTestCase;
36 import org.jacorb.test.notification.NotificationTestCaseSetup;
37 import org.omg.CORBA.Object JavaDoc;
38 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin;
39 import org.omg.CosNotifyChannelAdmin.ProxyType;
40 import org.omg.PortableServer.POA JavaDoc;
41 import org.omg.PortableServer.Servant JavaDoc;
42
43 /**
44  * @author Alphonse Bendt
45  * @version $Id: AbstractProxySupplierTest.java,v 1.2 2005/04/27 10:51:33 alphonse.bendt Exp $
46  */

47 public class AbstractProxySupplierTest extends NotificationTestCase
48 {
49     private AbstractProxySupplier objectUnderTest_;
50
51     private MockControl controlMessage_;
52
53     private Message mockMessage_;
54
55     private MockControl controlClient_;
56
57     private org.omg.CORBA.Object JavaDoc mockClient_;
58
59     /*
60      * @see TestCase#setUp()
61      */

62     protected void setUpTest() throws Exception JavaDoc
63     {
64         MockControl controlIAdmin = MockControl.createControl(IAdmin.class);
65         IAdmin mockIAdmin = (IAdmin) controlIAdmin.getMock();
66
67         mockIAdmin.getProxyID();
68         controlIAdmin.setReturnValue(0);
69
70         mockIAdmin.isIDPublic();
71         controlIAdmin.setReturnValue(false);
72
73         mockIAdmin.getContainer();
74         controlIAdmin.setReturnValue(null);
75
76         controlIAdmin.replay();
77
78         MockControl controlConsumerAdmin = MockControl.createControl(ConsumerAdmin.class);
79         ConsumerAdmin mockConsumerAdmin = (ConsumerAdmin) controlConsumerAdmin.getMock();
80
81         MockControl controlPOA = MockControl.createNiceControl(POA JavaDoc.class);
82         POA JavaDoc mockPOA = (POA JavaDoc) controlPOA.getMock();
83
84         objectUnderTest_ = new AbstractProxySupplier(mockIAdmin, getORB(), mockPOA,
85                 getConfiguration(), getTaskProcessor(), new OfferManager(),
86                 new SubscriptionManager(), mockConsumerAdmin)
87         {
88             protected long getCost()
89             {
90                 return 0;
91             }
92
93             public ProxyType MyType()
94             {
95                 return ProxyType.PULL_ANY;
96             }
97
98             protected void disconnectClient()
99             {
100                 // ignored
101
}
102
103             protected Servant JavaDoc getServant()
104             {
105                 return null;
106             }
107
108             public void deliverPendingData()
109             {
110                 // ignored
111
}
112
113             public MessageConsumer getMessageConsumer()
114             {
115                 return null;
116             }
117
118             public List JavaDoc getSubsequentFilterStages()
119             {
120                 return null;
121             }
122
123             public Object JavaDoc activate()
124             {
125                 return null;
126             }
127         };
128
129         controlMessage_ = MockControl.createControl(Message.class);
130         mockMessage_ = (Message) controlMessage_.getMock();
131
132         controlClient_ = MockControl.createControl(org.omg.CORBA.Object JavaDoc.class);
133         mockClient_ = (org.omg.CORBA.Object JavaDoc) controlClient_.getMock();
134     }
135
136     public AbstractProxySupplierTest(String JavaDoc name, NotificationTestCaseSetup setup)
137     {
138         super(name, setup);
139     }
140
141     public void testNotConnectedSupplierDoesNotAccessMessage()
142     {
143         controlMessage_.replay();
144
145         objectUnderTest_.deliverMessage(mockMessage_);
146
147         controlMessage_.verify();
148     }
149
150     public void testConnectedSupplierDoesCloneMessage()
151     {
152         mockMessage_.clone();
153         controlMessage_.setReturnValue(mockMessage_);
154
155         controlMessage_.replay();
156
157         controlClient_.replay();
158
159         objectUnderTest_.connectClient(mockClient_);
160
161         objectUnderTest_.deliverMessage(mockMessage_);
162
163         controlMessage_.verify();
164     }
165
166     public void testDisposeDisposesPendingMessages() throws Exception JavaDoc
167     {
168         mockMessage_.clone();
169         controlMessage_.setReturnValue(mockMessage_);
170
171         mockMessage_.dispose();
172         controlMessage_.replay();
173
174         objectUnderTest_.connectClient(mockClient_);
175         objectUnderTest_.deliverMessage(mockMessage_);
176         objectUnderTest_.dispose();
177
178         controlMessage_.verify();
179     }
180
181     public static Test suite() throws Exception JavaDoc
182     {
183         return NotificationTestCase.suite(AbstractProxySupplierTest.class);
184     }
185 }
186
Popular Tags