KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > FilterManagerTest


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;
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.FilterManager;
30 import org.omg.CosNotifyFilter.Filter;
31 import org.omg.CosNotifyFilter.FilterNotFound;
32
33 /**
34  * @author Alphonse Bendt
35  * @version $Id: FilterManagerTest.java,v 1.2 2005/05/01 21:14:29 alphonse.bendt Exp $
36  */

37 public class FilterManagerTest extends TestCase
38 {
39     private FilterManager objectUnderTest_;
40
41     private Filter mockFilter_;
42
43     private MockControl controlFilter_;
44
45     protected void setUp() throws Exception JavaDoc
46     {
47         super.setUp();
48
49         objectUnderTest_ = new FilterManager();
50
51         controlFilter_ = MockControl.createControl(Filter.class);
52         mockFilter_ = (Filter) controlFilter_.getMock();
53
54         controlFilter_.replay();
55     }
56
57     protected void tearDown() throws Exception JavaDoc
58     {
59         controlFilter_.verify();
60         super.tearDown();
61     }
62
63     public FilterManagerTest(String JavaDoc name)
64     {
65         super(name);
66     }
67
68     public void testAdd_filter() throws Exception JavaDoc
69     {
70         assertEquals(0, objectUnderTest_.get_all_filters().length);
71
72         objectUnderTest_.add_filter(mockFilter_);
73
74         assertEquals(1, objectUnderTest_.get_all_filters().length);
75     }
76
77     public void testRemove_filter() throws Exception JavaDoc
78     {
79         int id = objectUnderTest_.add_filter(mockFilter_);
80
81         assertEquals(1, objectUnderTest_.get_all_filters().length);
82
83         objectUnderTest_.remove_filter(id);
84
85         assertEquals(0, objectUnderTest_.get_all_filters().length);
86
87         try
88         {
89             objectUnderTest_.remove_filter(id);
90             fail();
91         } catch (FilterNotFound e)
92         {
93             // expected
94
}
95
96         assertEquals(0, objectUnderTest_.get_all_filters().length);
97     }
98
99     public void testGet_filter() throws Exception JavaDoc
100     {
101         int id = objectUnderTest_.add_filter(mockFilter_);
102
103         assertEquals(mockFilter_, objectUnderTest_.get_filter(id));
104
105         objectUnderTest_.remove_all_filters();
106
107         try
108         {
109             objectUnderTest_.get_filter(id);
110             fail();
111         } catch (FilterNotFound e)
112         {
113             // expected
114
}
115     }
116
117     public void testGet_all_filters()
118     {
119         assertEquals(0, objectUnderTest_.get_all_filters().length);
120
121         int id = objectUnderTest_.add_filter(mockFilter_);
122
123         int[] all = objectUnderTest_.get_all_filters();
124
125         assertEquals(1, all.length);
126
127         assertEquals(id, all[0]);
128     }
129
130     public void testRemove_all_filters()
131     {
132         objectUnderTest_.add_filter(mockFilter_);
133
134         assertEquals(1, objectUnderTest_.get_all_filters().length);
135
136         objectUnderTest_.remove_all_filters();
137
138         assertEquals(0, objectUnderTest_.get_all_filters().length);
139     }
140
141     public void testGetFilters()
142     {
143         assertTrue(objectUnderTest_.getFilters().isEmpty());
144         
145         objectUnderTest_.add_filter(mockFilter_);
146         assertEquals(1, objectUnderTest_.getFilters().size());
147         assertEquals(mockFilter_, objectUnderTest_.getFilters().get(0));
148         
149         try {
150             objectUnderTest_.getFilters().clear();
151             fail();
152         } catch (Exception JavaDoc e)
153         {
154             // expected
155
}
156         
157         objectUnderTest_.remove_all_filters();
158         
159         assertTrue(objectUnderTest_.getFilters().isEmpty());
160     }
161
162     
163     public static Test suite()
164     {
165         return new TestSuite(FilterManagerTest.class);
166     }
167 }
Popular Tags