KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > binding > AbstractPropertyTest


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19 package org.enhydra.zeus.binding;
20
21 import java.util.BitSet JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import junit.framework.Test;
25 import junit.framework.TestCase;
26 import junit.framework.TestSuite;
27
28 import org.enhydra.zeus.AbstractBindingTest;
29 import org.enhydra.zeus.Binding;
30
31 /**
32  * <p>
33  * <code>AbstractPropertyTest</code> is a base test for
34  * <code>{@link Property}</code> objects.
35  * </p><p>
36  * Concrete <code>Property</code> test cases should extend this class,
37  * override the <code>{@link #createProperty}</code> method, and add any
38  * tests specific to the class being tested.
39  * </p>
40  *
41  * @author Robert Sese
42  * @author Brett McLaughlin
43  */

44 public abstract class AbstractPropertyTest extends AbstractBindingTest {
45
46     /**
47      * <p>
48      * This creates a new <code>{@link Property}</code> object that will be
49      * used to test <code>Property</code>-level methods.
50      * </p>
51      *
52      * @return <code>Property</code> - Property object to test with.
53      */

54     protected abstract Property createProperty();
55
56     /**
57      * <p>
58      * This constructs a new <code>AbstractPropertyTest</code>.
59      * </p>
60      *
61      * @param name the name of the test case.
62      */

63     public AbstractPropertyTest(String JavaDoc name) {
64         super(name);
65     }
66     
67     /**
68      * <p>
69      * This method maeks it easier to call these
70      * tests dynamically.
71      * </p>
72      *
73      * @return <code>TestSuite</code> - corresponds to this
74      * <code>TestCase</code>.
75      */

76     public static Test suite() {
77         return new TestSuite(AbstractPropertyTest.class);
78     }
79     
80     /**
81      * <p>
82      * This creates a new <code>Binding</code> object that will be used to
83      * test <code>Binding</code> methods.
84      * </p>
85      *
86      * @return <code>Binding</code> - the created <code>Binding</code>
87      */

88     public Binding createBinding() {
89
90         // Delegate to the Property being tested.
91
return createProperty();
92     }
93
94     /**
95      * <p>
96      * This tests the <code>{@link Property#setModifier}</code> method.
97      * </p>
98      */

99     public void testSetModifier() {
100         Property property = createProperty();
101         BitSet JavaDoc modifiers = new BitSet JavaDoc();
102         modifiers.set(Property.ACCESS_PRIVATE);
103         modifiers.set(Property.SOURCE_ATTLIST);
104
105         property.setModifier(modifiers);
106         assertEquals(modifiers, property.getModifier());
107
108         modifiers = new BitSet JavaDoc();
109         modifiers.set(Property.ACCESS_PUBLIC);
110         modifiers.set(Property.SOURCE_ELEMENT);
111
112         property.setModifier(modifiers);
113         assertEquals(modifiers, property.getModifier());
114     }
115
116     /**
117      * <p>
118      * This tests the <code>{@link Property#getModifier}</code> method.
119      * </p>
120      */

121     public void testGetModifier() {
122         Property property = createProperty();
123         BitSet JavaDoc modifiers = new BitSet JavaDoc();
124         modifiers.set(Property.ACCESS_PRIVATE);
125         modifiers.set(Property.SOURCE_ATTLIST);
126
127         property.setModifier(modifiers);
128         assertEquals(modifiers, property.getModifier());
129     }
130
131     /**
132      * <p>
133      * This tests the <code>{@link Property#getModifierString}</code> method.
134      * </p>
135      */

136     public void testGetModifierString() {
137         Property property = createProperty();
138         BitSet JavaDoc modifiers = new BitSet JavaDoc();
139         modifiers.set(Property.ACCESS_PRIVATE);
140         modifiers.set(Property.SOURCE_ATTLIST);
141         String JavaDoc expected = "private";
142
143         property.setModifier(modifiers);
144         assertEquals(expected, property.getModifierString());
145         
146         modifiers = new BitSet JavaDoc();
147         modifiers.set(Property.ACCESS_PUBLIC);
148         modifiers.set(Property.STORAGE_STATIC);
149         modifiers.set(Property.MUTABILITY_FINAL);
150         expected = "public static final";
151
152         property.setModifier(modifiers);
153         assertEquals(expected, property.getModifierString());
154     }
155
156     /**
157      * <p>
158      * This tests the <code>{@link Property#setIsCollection}</code> method.
159      * </p>
160      */

161     public void testSetIsCollection() {
162         Property property = createProperty();
163         boolean expected = true;
164         property.setIsCollection(expected);
165         assertEquals(expected, property.isCollection());
166
167         expected = false;
168         property.setIsCollection(expected);
169         assertEquals(expected, property.isCollection());
170     }
171
172     /**
173      * <p>
174      * This tests the <code>{@link Property#isCollection}</code> method.
175      * </p>
176      */

177     public void testIsCollection() {
178         Property property = createProperty();
179         boolean expected = true;
180         property.setIsCollection(expected);
181         assertEquals(expected, property.isCollection());
182     }
183
184     /**
185      * <p>
186      * This tests the <code>{@link Property#hasDefaultValue}</code> method.
187      * </p>
188      */

189     public void testHasDefaultValue() {
190         Property property = createProperty();
191         boolean expected = true;
192         property.setDefaultValue("defaultValue");
193         assertEquals(expected, property.hasDefaultValue());
194     }
195
196     /**
197      * <p>
198      * This tests the <code>{@link Property#setDefaultValue}</code> method.
199      * </p>
200      */

201     public void testSetDefaultValue() {
202         Property property = createProperty();
203         String JavaDoc expected1 = "defaultValue";
204         property.setDefaultValue(expected1);
205         assertEquals(expected1, (String JavaDoc)property.getDefaultValue());
206
207         Integer JavaDoc expected2 = new Integer JavaDoc(10);
208         property.setDefaultValue(expected2);
209         assertEquals(expected2, (Integer JavaDoc)property.getDefaultValue());
210     }
211
212     /**
213      * <p>
214      * This tests the <code>{@link Property#getDefaultValue}</code> method.
215      * </p>
216      */

217     public void testGetDefaultValue() {
218         Property property = createProperty();
219         String JavaDoc expected1 = "defaultValue";
220         property.setDefaultValue(expected1);
221         assertEquals(expected1, (String JavaDoc)property.getDefaultValue());
222     }
223
224     /**
225      * <p>
226      * This tests the <code>{@link Property#hasEnumeration}</code> method.
227      * </p>
228      */

229     public void testHasEnumeration() {
230         Property property = createProperty();
231         boolean expected = true;
232         property.setEnumeration(new Vector JavaDoc());
233         assertEquals(expected, property.hasEnumeration());
234     }
235
236     /**
237      * <p>
238      * This tests the <code>{@link Property#setEnumeration}</code> method.
239      * </p>
240      */

241     public void testSetEnumeration() {
242         Property property = createProperty();
243         Vector JavaDoc expected1 = new Vector JavaDoc();
244         expected1.add("value1");
245         expected1.add("value2");
246         property.setEnumeration(expected1);
247         assertEquals(expected1, property.getEnumeration());
248
249         Vector JavaDoc expected2 = new Vector JavaDoc();
250         expected2.add(new Integer JavaDoc(1));
251         expected2.add(new Integer JavaDoc(2));
252         property.setEnumeration(expected2);
253         assertEquals(expected2, property.getEnumeration());
254     }
255
256     /**
257      * <p>
258      * This tests the <code>{@link Property#getEnumeration}</code> method.
259      * </p>
260      */

261     public void testGetEnumeration() {
262         Property property = createProperty();
263         Vector JavaDoc expected1 = new Vector JavaDoc();
264         expected1.add("value1");
265         expected1.add("value2");
266         property.setEnumeration(expected1);
267         assertEquals(expected1, property.getEnumeration());
268     }
269 }
270
Popular Tags