KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > AbstractBindingTest


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;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24
25 // Zeus imports
26
import org.enhydra.zeus.InvalidCollectionTypeException;
27
28 /**
29  * <p>
30  * <code>AbstractBindingTest</code> is an abstract test case for
31  * <code>Binding</code> objects. This class provides tests for
32  * methods on the <code>org.enhydra.zeus.Binding</code> interface that
33  * all <code>Binding</code> subclasses will inherit.
34  * </p><p>
35  * Concrete <code>Binding</code> test cases should extend this class,
36  * override the <code>{@link createBinding}</code> method, and add any
37  * tests specific to the class being tested.
38  * </p>
39  *
40  * @author Robert Sese
41  */

42 public abstract class AbstractBindingTest extends TestCase {
43
44     /**
45      * <p>
46      * This creates a new <code>Binding</code> object that will be used to
47      * test <code>Binding</code> methods.
48      * </p>
49      *
50      * @return <code>Binding</code> - the created <code>Binding</code>
51      */

52     public abstract Binding createBinding();
53
54     /**
55      * <p>
56      * Constructor
57      * </p>
58      *
59      * @param name the name of the test for use in reports
60      */

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

74     public static Test suite() {
75         return new TestSuite(AbstractBindingTest.class);
76     }
77     
78     /**
79      * <p>
80      * This tests the <code>getXMLName()</code> method.
81      * </p>
82      */

83     public void testGetXMLName() {
84         Binding binding = createBinding();
85         String JavaDoc expected = "my_xml_name";
86
87         binding.setXMLName(expected);
88         assertEquals(expected, binding.getXMLName());
89     }
90
91     /**
92      * <p>
93      * This tests the <code>setXMLName()</code> method.
94      * </p>
95      */

96     public void testSetXMLName() {
97         Binding binding = createBinding();
98         String JavaDoc expected1 = "my_xml_name_1";
99         String JavaDoc expected2 = "my_xml_name_2";
100
101         binding.setXMLName(expected1);
102         assertEquals(expected1, binding.getXMLName());
103         binding.setXMLName(expected2);
104         assertEquals(expected2, binding.getXMLName());
105     }
106     
107     /**
108      * <p>
109      * This tests the <code>getXMLNamespaceURI()</code> method.
110      * </p>
111      */

112     public void testGetXMLNamespaceURI() {
113         Binding binding = createBinding();
114         String JavaDoc expected = "http://www.namespace.com";
115
116         binding.setXMLNamespaceURI(expected);
117         assertEquals(expected, binding.getXMLNamespaceURI());
118     }
119
120     /**
121      * <p>
122      * This tests the <code>setXMLNamespaceURI()</code> method.
123      * </p>
124      */

125     public void testSetXMLNamespaceURI() {
126         Binding binding = createBinding();
127         String JavaDoc expected1 = "http://www.namespace1.com";
128         String JavaDoc expected2 = "http://www.namespace2.com";
129
130         binding.setXMLNamespaceURI(expected1);
131         assertEquals(expected1, binding.getXMLNamespaceURI());
132         binding.setXMLNamespaceURI(expected2);
133         assertEquals(expected2, binding.getXMLNamespaceURI());
134     }
135     
136     /**
137      * <p>
138      * This tests the <code>getXMLType()</code> method.
139      * </p>
140      */

141     public void testGetXMLType() {
142         Binding binding = createBinding();
143         String JavaDoc expected = "my_xml_type";
144
145         binding.setXMLType(expected);
146         assertEquals(expected, binding.getXMLType());
147     }
148
149     /**
150      * <p>
151      * This tests the <code>setXMLType()</code> method.
152      * </p>
153      */

154     public void testSetXMLType() {
155         Binding binding = createBinding();
156         String JavaDoc expected1 = "my_xml_type_1";
157         String JavaDoc expected2 = "my_xml_type_2";
158
159         binding.setXMLType(expected1);
160         assertEquals(expected1, binding.getXMLType());
161         binding.setXMLType(expected2);
162         assertEquals(expected2, binding.getXMLType());
163     }
164     
165     /**
166      * <p>
167      * This tests the <code>getXMLTypeNamespaceURI()</code> method.
168      * </p>
169      */

170     public void testGetXMLTypeNamespaceURI() {
171         Binding binding = createBinding();
172         String JavaDoc expected = "http://www.typeNamespace.com";
173
174         binding.setXMLTypeNamespaceURI(expected);
175         assertEquals(expected, binding.getXMLTypeNamespaceURI());
176     }
177
178     /**
179      * <p>
180      * This tests the <code>setXMLTypeNamespaceURI()</code> method.
181      * </p>
182      */

183     public void testSetXMLTypeNamespaceURI() {
184         Binding binding = createBinding();
185         String JavaDoc expected1 = "http://www.typeNamespace1.com";
186         String JavaDoc expected2 = "http://www.typeNamespace2.com";
187
188         binding.setXMLTypeNamespaceURI(expected1);
189         assertEquals(expected1, binding.getXMLTypeNamespaceURI());
190         binding.setXMLTypeNamespaceURI(expected2);
191         assertEquals(expected2, binding.getXMLTypeNamespaceURI());
192     }
193
194     /**
195      * <p>
196      * This tests the <code>getJavaName()</code> method.
197      * </p>
198      */

199     public void testGetJavaName() {
200         Binding binding = createBinding();
201         String JavaDoc expected = "myJavaName";
202
203         binding.setJavaName(expected);
204         assertEquals(expected, binding.getJavaName());
205     }
206
207     /**
208      * <p>
209      * This tests the <code>setJavaName()</code> method.
210      * </p>
211      */

212     public void testSetJavaName() {
213         Binding binding = createBinding();
214         String JavaDoc expected1 = "myJavaName1";
215         String JavaDoc expected2 = "myJavaName2";
216
217         binding.setJavaName(expected1);
218         assertEquals(expected1, binding.getJavaName());
219         binding.setJavaName(expected2);
220         assertEquals(expected2, binding.getJavaName());
221     }
222     
223     /**
224      * <p>
225      * This tests the <code>getJavaVariableName()</code> method.
226      * </p>
227      */

228     public void testGetJavaVariableName() {
229         Binding binding = createBinding();
230         String JavaDoc expected = "myJavaVariableName";
231
232         binding.setJavaVariableName(expected);
233         assertEquals(expected, binding.getJavaVariableName());
234     }
235
236     /**
237      * <p>
238      * This tests the <code>setJavaVariableName()</code> method.
239      * </p>
240      */

241     public void testSetJavaVariableName() {
242         Binding binding = createBinding();
243         String JavaDoc expected1 = "myJavaVariableName1";
244         String JavaDoc expected2 = "myJavaVariableName2";
245
246         binding.setJavaVariableName(expected1);
247         assertEquals(expected1, binding.getJavaVariableName());
248         binding.setJavaVariableName(expected2);
249         assertEquals(expected2, binding.getJavaVariableName());
250     }
251
252     /**
253      * <p>
254      * This tests the <code>getJavaType()</code> method.
255      * </p>
256      */

257     public void testGetJavaType() {
258         Binding binding = createBinding();
259         String JavaDoc expected = "MyType";
260
261         binding.setJavaType(expected);
262         assertEquals(expected, binding.getJavaType());
263     }
264
265     /**
266      * <p>
267      * This tests the <code>setJavaType()</code> method.
268      * </p>
269      */

270     public void testSetJavaType() {
271         Binding binding = createBinding();
272         String JavaDoc expected1 = "MyType1";
273         String JavaDoc expected2 = "MyType2";
274
275         binding.setJavaType(expected1);
276         assertEquals(expected1, binding.getJavaType());
277         binding.setJavaType(expected2);
278         assertEquals(expected2, binding.getJavaType());
279     }
280
281     /**
282      * <p>
283      * This tests the <code>getJavaInterfacePackage()</code> method.
284      * </p>
285      */

286     public void testGetJavaInterfacePackage() {
287         Binding binding = createBinding();
288         String JavaDoc expected = "org.my.interface.package";
289
290         binding.setJavaInterfacePackage(expected);
291         assertEquals(expected, binding.getJavaInterfacePackage());
292     }
293
294     /**
295      * <p>
296      * This tests the <code>setJavaInterfacePackage()</code> method.
297      * </p>
298      */

299     public void testSetJavaInterfacePackage() {
300         Binding binding = createBinding();
301         String JavaDoc expected1 = "org.my.interface.package1";
302         String JavaDoc expected2 = "org.my.interface.package2";
303
304         binding.setJavaInterfacePackage(expected1);
305         assertEquals(expected1, binding.getJavaInterfacePackage());
306         binding.setJavaInterfacePackage(expected2);
307         assertEquals(expected2, binding.getJavaInterfacePackage());
308     }
309     
310     /**
311      * <p>
312      * This tests the <code>getJavaImplementationPackage()</code> method.
313      * </p>
314      */

315     public void testGetJavaImplementationPackage() {
316         Binding binding = createBinding();
317         String JavaDoc expected = "org.my.implementation.package";
318
319         binding.setJavaImplementationPackage(expected);
320         assertEquals(expected, binding.getJavaImplementationPackage());
321     }
322
323     /**
324      * <p>
325      * This tests the <code>setJavaImplementationPackage()</code> method.
326      * </p>
327      */

328     public void testSetJavaImplementationPackage() {
329         Binding binding = createBinding();
330         String JavaDoc expected1 = "org.my.implementation.package1";
331         String JavaDoc expected2 = "org.my.implementation.package2";
332
333         binding.setJavaImplementationPackage(expected1);
334         assertEquals(expected1, binding.getJavaImplementationPackage());
335         binding.setJavaImplementationPackage(expected2);
336         assertEquals(expected2, binding.getJavaImplementationPackage());
337     }
338     
339     /**
340      * <p>
341      * This tests the <code>getJavaCollectionClass()</code> method.
342      * </p>
343      */

344     public void testGetJavaCollectionClass() {
345         Binding binding = createBinding();
346         String JavaDoc expected = "java.util.List";
347
348         try {
349             binding.setJavaCollectionClass(expected);
350             assertEquals(expected, binding.getJavaCollectionClass());
351         } catch (InvalidCollectionTypeException e) {
352             // If this failed, the test failed
353
assertTrue(false);
354         }
355     }
356
357     /**
358      * <p>
359      * This tests the <code>setJavaCollectionClass()</code> method.
360      * </p>
361      */

362     public void testSetJavaCollectionClass() {
363         Binding binding = createBinding();
364         String JavaDoc collection1 = "java.util.List";
365         String JavaDoc collection2 = "java.util.ArrayList";
366         boolean success = true;
367         
368         try {
369             binding.setJavaCollectionClass(collection1);
370             binding.setJavaCollectionClass(collection2);
371         } catch (InvalidCollectionTypeException e) {
372             // If this failed, the test failed
373
success = false;
374         }
375         
376         assertTrue(success);
377     }
378     
379     /**
380      * <p>
381      * This tests the <code>getJavaCollectionClass()</code> method, and ensures
382      * that an <code>{@link InvalidCollectionTypeException}</code> is thrown
383      * when an invlalid collection type is supplied.
384      * </p>
385      */

386     public void testSetJavaCollectionClassNegative() {
387         Binding binding = createBinding();
388         String JavaDoc expected = "java.lang.String";
389         boolean caught = false;
390
391         try {
392             binding.setJavaCollectionClass(expected);
393             assertEquals(expected, binding.getJavaCollectionClass());
394         } catch (InvalidCollectionTypeException e) {
395             // This indicates correct behavior
396
caught = true;
397         } finally {
398             assertTrue(caught);
399         }
400     }
401     
402     /**
403      * <p>
404      * This tests the <code>isJavaSerializable()</code> method.
405      * </p>
406      */

407     public void testIsJavaSerializable() {
408         Binding binding = createBinding();
409         boolean expected = true;
410
411         binding.setIsJavaSerializable(expected);
412         assertEquals(expected, binding.isJavaSerializable());
413     }
414
415     /**
416      * <p>
417      * This tests the <code>setIsJavaSerializable()</code> method.
418      * </p>
419      */

420     public void testSetIsJavaSerializable() {
421         Binding binding = createBinding();
422         boolean expected1 = true;
423         boolean expected2 = false;
424
425         binding.setIsJavaSerializable(expected1);
426         assertEquals(expected1, binding.isJavaSerializable());
427         binding.setIsJavaSerializable(expected2);
428         assertEquals(expected2, binding.isJavaSerializable());
429     }
430 }
431
432
Popular Tags