KickJava   Java API By Example, From Geeks To Geeks.

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


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.TaskProcessor;
31 import org.jacorb.notification.interfaces.Message;
32 import org.jacorb.notification.servant.IAdmin;
33 import org.jacorb.notification.servant.ProxyPushSupplierImpl;
34 import org.jacorb.test.notification.NotificationTestCase;
35 import org.jacorb.test.notification.NotificationTestCaseSetup;
36 import org.omg.CORBA.Any JavaDoc;
37 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin;
38 import org.omg.CosNotifyComm.PushConsumer;
39
40 /**
41  * @author Alphonse Bendt
42  * @version $Id: ProxyPushSupplierImplTest.java,v 1.4 2005/05/01 21:15:51 alphonse.bendt Exp $
43  */

44 public class ProxyPushSupplierImplTest extends NotificationTestCase
45 {
46     private MockControl controlTaskProcessor_;
47
48     private TaskProcessor mockTaskProcessor_;
49
50     private ProxyPushSupplierImpl objectUnderTest_;
51
52     /**
53      * Constructor for ProxyPushSupplierImplTest.
54      *
55      * @param name
56      */

57     public ProxyPushSupplierImplTest(String JavaDoc name, NotificationTestCaseSetup setup)
58     {
59         super(name, setup);
60     }
61
62     public void setUpTest() throws Exception JavaDoc
63     {
64         MockControl controlAdmin = MockControl.createControl(IAdmin.class);
65         IAdmin mockAdmin = (IAdmin) controlAdmin.getMock();
66
67         mockAdmin.isIDPublic();
68         controlAdmin.setReturnValue(true);
69
70         mockAdmin.getProxyID();
71         controlAdmin.setReturnValue(10);
72
73         mockAdmin.getContainer();
74         controlAdmin.setReturnValue(null);
75
76         controlAdmin.replay();
77
78         MockControl controlConsumerAdmin = MockControl.createControl(ConsumerAdmin.class);
79         ConsumerAdmin mockConsumerAdmin = (ConsumerAdmin) controlConsumerAdmin.getMock();
80
81         controlConsumerAdmin.replay();
82
83         controlTaskProcessor_ = MockControl.createControl(TaskProcessor.class);
84         mockTaskProcessor_ = (TaskProcessor) controlTaskProcessor_.getMock();
85        
86         objectUnderTest_ = new ProxyPushSupplierImpl(mockAdmin, getORB(), getPOA(),
87                 getConfiguration(), mockTaskProcessor_, new DefaultPushTaskExecutorFactory(1), new OfferManager(),
88                 new SubscriptionManager(), mockConsumerAdmin);
89
90         assertEquals(new Integer JavaDoc(10), objectUnderTest_.getID());
91     }
92
93     public void testDeliverMessage_Error() throws Exception JavaDoc
94     {
95         Any JavaDoc any = getORB().create_any();
96
97         MockControl controlMessage = MockControl.createControl(Message.class);
98         Message mockMessage = (Message) controlMessage.getMock();
99
100         mockMessage.toAny();
101         controlMessage.setReturnValue(any);
102
103         mockMessage.clone();
104         controlMessage.setReturnValue(mockMessage, 2);
105
106         mockMessage.dispose();
107
108         controlMessage.replay();
109
110         MockControl controlPushConsumer = MockControl.createControl(PushConsumer.class);
111         PushConsumer mockPushConsumer = (PushConsumer) controlPushConsumer.getMock();
112
113         mockPushConsumer.push(any);
114         controlPushConsumer.setThrowable(new RuntimeException JavaDoc());
115
116         controlPushConsumer.replay();
117
118         mockTaskProcessor_.executeTaskAfterDelay(0, null);
119         controlTaskProcessor_.setMatcher(MockControl.ALWAYS_MATCHER);
120         controlTaskProcessor_.setReturnValue(new Object JavaDoc());
121
122         mockTaskProcessor_.schedulePushOperation(objectUnderTest_);
123
124         controlTaskProcessor_.replay();
125
126         objectUnderTest_.connect_any_push_consumer(mockPushConsumer);
127         objectUnderTest_.deliverMessage(mockMessage);
128     }
129
130     public static Test suite() throws Exception JavaDoc
131     {
132         return NotificationTestCase.suite(ProxyPushSupplierImplTest.class);
133     }
134 }
Popular Tags