KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.Test;
25
26 import org.easymock.MockControl;
27 import org.jacorb.notification.OfferManager;
28 import org.jacorb.notification.SubscriptionManager;
29 import org.jacorb.notification.engine.DefaultPushTaskExecutorFactory;
30 import org.jacorb.notification.engine.TaskExecutor;
31 import org.jacorb.notification.engine.TaskProcessor;
32 import org.jacorb.notification.interfaces.Message;
33 import org.jacorb.notification.servant.IAdmin;
34 import org.jacorb.notification.servant.StructuredProxyPushSupplierImpl;
35 import org.jacorb.test.notification.NotificationTestCase;
36 import org.jacorb.test.notification.NotificationTestCaseSetup;
37 import org.omg.CORBA.TRANSIENT JavaDoc;
38 import org.omg.CosNotification.StructuredEvent;
39 import org.omg.CosNotifyComm.StructuredPushConsumer;
40
41 /**
42  * @author Alphonse Bendt
43  * @version $Id: StructuredProxyPushSupplierImplTest.java,v 1.4 2005/05/01 21:15:51 alphonse.bendt Exp $
44  */

45 public class StructuredProxyPushSupplierImplTest extends NotificationTestCase
46 {
47     private StructuredProxyPushSupplierImpl objectUnderTest_;
48
49     private MockControl controlTaskExecutor_;
50
51     private MockControl controlTaskProcessor_;
52
53     private TaskProcessor mockTaskProcessor_;
54
55     /*
56      * @see TestCase#setUp()
57      */

58     protected void setUpTest() throws Exception JavaDoc
59     {
60         MockControl controlAdmin = MockControl.createControl(IAdmin.class);
61         IAdmin mockAdmin = (IAdmin) controlAdmin.getMock();
62
63         mockAdmin.isIDPublic();
64         controlAdmin.setReturnValue(true);
65
66         mockAdmin.getProxyID();
67         controlAdmin.setReturnValue(10);
68
69         mockAdmin.getContainer();
70         controlAdmin.setReturnValue(null);
71
72         controlAdmin.replay();
73
74         controlTaskProcessor_ = MockControl.createControl(TaskProcessor.class);
75         mockTaskProcessor_ = (TaskProcessor) controlTaskProcessor_.getMock();
76         controlTaskExecutor_ = MockControl.createControl(TaskExecutor.class);
77         objectUnderTest_ = new StructuredProxyPushSupplierImpl(mockAdmin, getORB(), getPOA(),
78                 getConfiguration(), mockTaskProcessor_, new DefaultPushTaskExecutorFactory(1), new OfferManager(),
79                 new SubscriptionManager(), null);
80
81         assertEquals(new Integer JavaDoc(10), objectUnderTest_.getID());
82     }
83
84     /**
85      * Constructor for StructuredProxyPushSupplierImplTest.
86      *
87      * @param name
88      */

89     public StructuredProxyPushSupplierImplTest(String JavaDoc name, NotificationTestCaseSetup setup)
90     {
91         super(name, setup);
92     }
93
94     public void testDeliveryToNotConnectedDoesNotAccessMessage()
95     {
96         MockControl controlMessage = MockControl.createStrictControl(Message.class);
97         Message mockMessage = (Message) controlMessage.getMock();
98
99         controlMessage.replay();
100
101         controlTaskExecutor_.replay();
102
103         controlTaskProcessor_.replay();
104
105         objectUnderTest_.deliverMessage(mockMessage);
106
107         controlMessage.verify();
108
109         controlTaskExecutor_.verify();
110
111         controlTaskProcessor_.verify();
112     }
113
114     public void testDeliveryToDisabledConsumerEnqueues() throws Exception JavaDoc
115     {
116         MockControl controlMessage = MockControl.createStrictControl(Message.class);
117         Message mockMessage = (Message) controlMessage.getMock();
118
119         mockMessage.clone();
120         controlMessage.setReturnValue(mockMessage);
121
122         controlMessage.replay();
123
124         controlTaskExecutor_.replay();
125
126         controlTaskProcessor_.replay();
127
128         MockControl controlStructuredPushConsumer = MockControl
129                 .createControl(StructuredPushConsumer.class);
130         StructuredPushConsumer mockStructuredPushConsumer = (StructuredPushConsumer) controlStructuredPushConsumer
131                 .getMock();
132
133         objectUnderTest_.connect_structured_push_consumer(mockStructuredPushConsumer);
134
135         objectUnderTest_.disableDelivery();
136
137         objectUnderTest_.deliverMessage(mockMessage);
138
139         controlMessage.verify();
140
141         controlTaskExecutor_.verify();
142
143         controlTaskProcessor_.verify();
144     }
145
146     public void testDeliveryToConsumerDoesEnqueueAndDisposeMessage() throws Exception JavaDoc
147     {
148         StructuredEvent event = new StructuredEvent();
149
150         MockControl controlMessage = MockControl.createStrictControl(Message.class);
151         Message mockMessage = (Message) controlMessage.getMock();
152
153         mockMessage.clone();
154         controlMessage.setReturnValue(mockMessage);
155
156         mockMessage.toStructuredEvent();
157         controlMessage.setReturnValue(event);
158
159         mockMessage.dispose();
160
161         controlMessage.replay();
162
163         controlTaskExecutor_.replay();
164
165         MockControl controlStructuredPushConsumer = MockControl
166                 .createControl(StructuredPushConsumer.class);
167         StructuredPushConsumer mockStructuredPushConsumer = (StructuredPushConsumer) controlStructuredPushConsumer
168                 .getMock();
169
170         mockStructuredPushConsumer.push_structured_event(event);
171
172         controlStructuredPushConsumer.replay();
173
174         objectUnderTest_.connect_structured_push_consumer(mockStructuredPushConsumer);
175
176         objectUnderTest_.deliverMessage(mockMessage);
177
178         objectUnderTest_.pushPendingData();
179
180         controlMessage.verify();
181
182         controlTaskExecutor_.verify();
183     }
184
185     public void testFailedDeliveryToConsumerDoesNotDisposeMessage() throws Exception JavaDoc
186     {
187         StructuredEvent event = new StructuredEvent();
188
189         MockControl controlMessage = MockControl.createControl(Message.class);
190         Message mockMessage = (Message) controlMessage.getMock();
191
192         mockMessage.clone();
193         controlMessage.setReturnValue(mockMessage, 2);
194
195         mockMessage.toStructuredEvent();
196         controlMessage.setReturnValue(event);
197
198         mockMessage.dispose();
199
200         controlMessage.replay();
201
202         controlTaskExecutor_.replay();
203
204         mockTaskProcessor_.executeTaskAfterDelay(0, null);
205         controlTaskProcessor_.setMatcher(MockControl.ALWAYS_MATCHER);
206         controlTaskProcessor_.setReturnValue(null);
207
208         controlTaskProcessor_.replay();
209
210         MockControl controlStructuredPushConsumer = MockControl
211                 .createControl(StructuredPushConsumer.class);
212         StructuredPushConsumer mockStructuredPushConsumer = (StructuredPushConsumer) controlStructuredPushConsumer
213                 .getMock();
214
215         mockStructuredPushConsumer.push_structured_event(event);
216         controlStructuredPushConsumer.setThrowable(new TRANSIENT JavaDoc());
217
218         controlStructuredPushConsumer.replay();
219
220         objectUnderTest_.connect_structured_push_consumer(mockStructuredPushConsumer);
221
222         objectUnderTest_.deliverMessage(mockMessage);
223
224         objectUnderTest_.pushPendingData();
225
226         controlMessage.verify();
227
228         controlTaskExecutor_.verify();
229
230         controlTaskProcessor_.verify();
231     }
232
233     public static Test suite() throws Exception JavaDoc
234     {
235         return NotificationTestCase.suite(StructuredProxyPushSupplierImplTest.class);
236     }
237 }
Popular Tags