KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
22 import java.util.LinkedList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28
29 import org.enhydra.zeus.AbstractBindingTest;
30 import org.enhydra.zeus.Binding;
31
32 /**
33  * <p>
34  * <code>AbstractContainerTest</code> is a base test for
35  * <code>{@link Container}</code> objects.
36  * </p><p>
37  * Concrete <code>Container</code> test cases should extend this class,
38  * override the <code>{@link #createContainer}</code> method, and add any
39  * tests specific to the class being tested.
40  * </p>
41  *
42  * @author Robert Sese
43  * @author Brett McLaughlin
44  */

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

55     protected abstract Container createContainer();
56
57     /**
58      * <p>
59      * This constructs a new <code>AbstractContainerTest</code>.
60      * </p>
61      *
62      * @param name the name of the test case.
63      */

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

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

89     public Binding createBinding() {
90
91         // Just delegate to the Container subclass.
92
return createContainer();
93     }
94
95     /**
96      * <p>
97      * This tests the <code>{@link Container#addProperty}</code> method.
98      * </p>
99      */

100     public void testAddProperty() {
101         Container container = createContainer();
102         Property property = new AtomicProperty("xmlName", "xmlType");
103         container.addProperty(property);
104
105         /**
106          * XXX: Do we need to define equals for Bindings, or is comparsion by
107          * name enough?
108          */

109         List JavaDoc properties = container.getProperties();
110         boolean hasProperty = false;
111         for (Iterator JavaDoc i = properties.iterator(); i.hasNext(); ) {
112             Property p = (Property)i.next();
113             if (p.getXMLName().equals(property.getXMLName())) {
114                 hasProperty = true;
115                 break;
116             }
117         }
118         assertTrue(hasProperty);
119     }
120
121     /**
122      * <p>
123      * This tests the <code>{@link Container#removeProperty}</code> method.
124      * </p>
125      */

126     public void testRemoveProperty() {
127         Container container = createContainer();
128         Property property = new AtomicProperty("xmlName", "xmlType");
129         property.setJavaName("javaName");
130         container.addProperty(property);
131         container.removeProperty(property.getJavaName());
132
133         /*
134          * XXX: Do we need to define equals for Bindings, or is comparsion by
135          * name enough?
136          */

137         List JavaDoc properties = container.getProperties();
138         
139         boolean removedProperty = true;
140         for (Iterator JavaDoc i = properties.iterator(); i.hasNext(); ) {
141             Property p = (Property)i.next();
142             if (p.getXMLName().equals(property.getXMLName())) {
143                 removedProperty = false;
144                 break;
145             }
146         }
147         assertTrue(removedProperty);
148     }
149
150     /**
151      * <p>
152      * This tests the <code>{@link Container#getProperties}</code> method.
153      * </p>
154      */

155     public void testGetProperties() {
156         Container container = createContainer();
157         Property property1 = new AtomicProperty("xmlName1", "xmlType1");
158         Property property2 = new AtomicProperty("xmlName2", "xmlType2");
159         container.addProperty(property1);
160         container.addProperty(property2);
161
162         List JavaDoc properties = container.getProperties();
163         boolean hasProperty1 = false;
164         boolean hasProperty2 = false;
165         for (Iterator JavaDoc i = properties.iterator(); i.hasNext(); ) {
166             Property p = (Property)i.next();
167             if (p.getXMLName().equals(property1.getXMLName())) {
168                 hasProperty1 = true;
169             } else if (p.getXMLName().equals(property2.getXMLName())) {
170                 hasProperty2 = true;
171             }
172         }
173         assertTrue(hasProperty1 && hasProperty2);
174     }
175     
176     /**
177      * This tests the <code>{@link Container#setProperties}</code> method.
178      */

179     public void testSetProperties() {
180         Container container = createContainer();
181         Property property1 = new AtomicProperty("xmlName1", "xmlType1");
182         Property property2 = new AtomicProperty("xmlName2", "xmlType2");
183         List JavaDoc properties = new LinkedList JavaDoc();
184         properties.add(property1);
185         properties.add(property2);
186         container.setProperties(properties);
187         
188         List JavaDoc containerProperties = container.getProperties();
189         boolean hasProperty1 = false;
190         boolean hasProperty2 = false;
191         boolean hasOtherProperties = false;
192         for (Iterator JavaDoc i = containerProperties.iterator(); i.hasNext(); ) {
193             Property property = (Property)i.next();
194             if (property.getXMLName().equals(property1.getXMLName())) {
195                 hasProperty1 = true;
196             } else if (property.getXMLName().equals(property2.getXMLName())) {
197                 hasProperty2 = true;
198             } else {
199                 hasOtherProperties = true;
200             }
201         }
202         assertTrue(hasProperty1 && hasProperty2 && !hasOtherProperties);
203     }
204
205     /**
206      * This tests the <code>{@link Container#clearProperties}</code> method.
207      */

208     public void testClearProperties() {
209         Container container = createContainer();
210         Property property1 = new AtomicProperty("xmlName1", "xmlType1");
211         Property property2 = new AtomicProperty("xmlName2", "xmlType2");
212         container.addProperty(property1);
213         container.addProperty(property2);
214         container.clearProperties();
215         
216         List JavaDoc properties = container.getProperties();
217         assertTrue(properties.size() == 0);
218     }
219 }
220
Popular Tags