KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > filter > CallbackManagerTest


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.filter;
23
24 import junit.framework.Test;
25 import junit.framework.TestCase;
26 import junit.framework.TestSuite;
27
28 import org.easymock.MockControl;
29 import org.jacorb.notification.filter.CallbackManager;
30 import org.omg.CosNotification.EventType;
31 import org.omg.CosNotifyComm.NotifySubscribe;
32
33 /**
34  * @author Alphonse Bendt
35  * @version $Id: CallbackManagerTest.java,v 1.1 2005/02/14 00:17:14 alphonse.bendt Exp $
36  */

37 public class CallbackManagerTest extends TestCase
38 {
39     private CallbackManager objectUnderTest_;
40
41     private MockControl controlSubscription_;
42
43     private NotifySubscribe mockSubscription_;
44
45     private final static EventType[] EMPTY = new EventType[0];
46
47     protected void setUp() throws Exception JavaDoc
48     {
49         super.setUp();
50
51         objectUnderTest_ = new CallbackManager();
52         controlSubscription_ = MockControl.createControl(NotifySubscribe.class);
53         mockSubscription_ = (NotifySubscribe) controlSubscription_.getMock();
54     }
55
56     public CallbackManagerTest(String JavaDoc name)
57     {
58         super(name);
59     }
60
61     public void testAttach_callback()
62     {
63         int id = objectUnderTest_.attach_callback(mockSubscription_);
64
65         int[] ids = objectUnderTest_.get_callbacks();
66         assertEquals(1, ids.length);
67         assertEquals(id, ids[0]);
68     }
69
70     public void testDetach_callback()
71     {
72         assertEquals(0, objectUnderTest_.get_callbacks().length);
73         objectUnderTest_.detach_callback(0);
74         int id = objectUnderTest_.attach_callback(mockSubscription_);
75
76         assertEquals(1, objectUnderTest_.get_callbacks().length);
77
78         objectUnderTest_.detach_callback(id);
79
80         assertEquals(0, objectUnderTest_.get_callbacks().length);
81     }
82
83     public void testGet_callbacks()
84     {
85         int[] ids = objectUnderTest_.get_callbacks();
86
87         assertNotNull(ids);
88         assertEquals(0, ids.length);
89     }
90
91     public void testNoChangeDoesNotNotify() throws Exception JavaDoc
92     {
93         objectUnderTest_.attach_callback(mockSubscription_);
94
95         controlSubscription_.replay();
96
97         objectUnderTest_.changeSet(EMPTY, EMPTY);
98
99         controlSubscription_.verify();
100     }
101
102     public void testAddNonExistingDoesNotify() throws Exception JavaDoc
103     {
104         EventType[] added = new EventType[] { new EventType("domain", "type") };
105
106         mockSubscription_.subscription_change(added, EMPTY);
107         controlSubscription_.setMatcher(MockControl.ARRAY_MATCHER);
108
109         controlSubscription_.replay();
110
111         objectUnderTest_.attach_callback(mockSubscription_);
112
113         objectUnderTest_.changeSet(added, EMPTY);
114
115         controlSubscription_.verify();
116     }
117
118     public void testDeleteNonExistingDoesNotNotify() throws Exception JavaDoc
119     {
120         EventType[] removed = new EventType[] { new EventType("domain", "type") };
121
122         controlSubscription_.replay();
123
124         objectUnderTest_.attach_callback(mockSubscription_);
125
126         objectUnderTest_.changeSet(EMPTY, removed);
127
128         controlSubscription_.verify();
129     }
130
131     public void testAddMultipleDoesNotifyOnce() throws Exception JavaDoc
132     {
133         final EventType eventType = new EventType("domain", "type");
134
135         EventType[] added = new EventType[] { eventType, eventType };
136
137         mockSubscription_.subscription_change(new EventType[] { eventType }, EMPTY);
138         controlSubscription_.setMatcher(MockControl.ARRAY_MATCHER);
139
140         controlSubscription_.replay();
141
142         objectUnderTest_.attach_callback(mockSubscription_);
143
144         objectUnderTest_.changeSet(added, EMPTY);
145
146         controlSubscription_.verify();
147     }
148
149     public void testAddExistingDoesNotNotify() throws Exception JavaDoc
150     {
151         EventType[] added = new EventType[] { new EventType("domain", "type") };
152
153         mockSubscription_.subscription_change(added, EMPTY);
154         controlSubscription_.setMatcher(MockControl.ARRAY_MATCHER);
155
156         controlSubscription_.replay();
157
158         objectUnderTest_.attach_callback(mockSubscription_);
159
160         objectUnderTest_.changeSet(added, EMPTY);
161         objectUnderTest_.changeSet(added, EMPTY);
162
163         controlSubscription_.verify();
164     }
165
166     public void testReplaceWithEqualSetDoesNotNotify() throws Exception JavaDoc
167     {
168         EventType[] content = new EventType[] { new EventType("domain", "type") };
169
170         controlSubscription_.replay();
171
172         objectUnderTest_.changeSet(content, EMPTY);
173
174         objectUnderTest_.attach_callback(mockSubscription_);
175
176         objectUnderTest_.replaceWith(content);
177
178         controlSubscription_.verify();
179     }
180
181     public void testReplaceNotifiesAboutAdded() throws Exception JavaDoc
182     {
183         EventType[] content = new EventType[] { new EventType("domain", "type") };
184
185         EventType eventType = new EventType("domain2", "type2");
186         EventType[] replace = new EventType[] { new EventType("domain", "type"), eventType };
187
188         mockSubscription_.subscription_change(new EventType[] { eventType }, EMPTY);
189         controlSubscription_.setMatcher(MockControl.ARRAY_MATCHER);
190
191         controlSubscription_.replay();
192
193         objectUnderTest_.changeSet(content, EMPTY);
194
195         objectUnderTest_.attach_callback(mockSubscription_);
196
197         objectUnderTest_.replaceWith(replace);
198
199         controlSubscription_.verify();
200     }
201
202     public void testReplaceNotifiesAboutRemoved() throws Exception JavaDoc
203     {
204         EventType[] content = new EventType[] { new EventType("domain", "type") };
205
206         mockSubscription_.subscription_change(EMPTY, content);
207         controlSubscription_.setMatcher(MockControl.ARRAY_MATCHER);
208
209         controlSubscription_.replay();
210
211         objectUnderTest_.changeSet(content, EMPTY);
212
213         objectUnderTest_.attach_callback(mockSubscription_);
214
215         objectUnderTest_.replaceWith(EMPTY);
216
217         controlSubscription_.verify();
218     }
219
220     public void testDispose()
221     {
222         objectUnderTest_.attach_callback(mockSubscription_);
223
224         assertEquals(1, objectUnderTest_.get_callbacks().length);
225
226         objectUnderTest_.dispose();
227
228         assertEquals(0, objectUnderTest_.get_callbacks().length);
229     }
230
231     public static Test suite()
232     {
233         return new TestSuite(CallbackManagerTest.class);
234     }
235 }
Popular Tags