KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > AttributeOptionTest


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import java.util.Iterator JavaDoc;
50 import java.util.List JavaDoc;
51
52 import org.apache.torque.om.NumberKey;
53 import org.tigris.scarab.test.BaseScarabTestCase;
54
55 /**
56  * A Testing Suite for the om.Attribute class.
57  *
58  * @author <a HREF="mailto:jon@latchkey.com">Jon S. Stevens</a>
59  * @version $Id: AttributeOptionTest.java 9271 2004-11-23 08:35:00Z dep4b $
60  */

61 public class AttributeOptionTest extends BaseScarabTestCase
62 {
63     private AttributeOption ao;
64     
65     public void setUp()
66         throws Exception JavaDoc
67     {
68         super.setUp();
69         ao =
70             AttributeOptionManager.getInstance(new NumberKey(83));
71
72
73     }
74
75     public void testGetChildren()
76         throws Exception JavaDoc
77     {
78         System.out.println (
79             "Testing: testGetChildren() with AttributeOption: " + ao.getName());
80         List JavaDoc options = ao.getChildren();
81         Iterator JavaDoc itr = options.iterator();
82         while (itr.hasNext())
83         {
84             AttributeOption val = ((AttributeOption)itr.next());
85             System.out.println (val);
86         }
87         int size = options.size();
88         assertEquals(size, 8);
89         assertEquals("BSDI", ((AttributeOption)ao.getChildren().get(0)).getName());
90         assertEquals("AIX", ((AttributeOption)ao.getChildren().get(1)).getName());
91         assertEquals("BeOS", ((AttributeOption)ao.getChildren().get(2)).getName());
92         assertEquals("HPUX", ((AttributeOption)ao.getChildren().get(3)).getName());
93         assertEquals("IRIX", ((AttributeOption)ao.getChildren().get(4)).getName());
94         assertEquals("OSF1", ((AttributeOption)ao.getChildren().get(5)).getName());
95         assertEquals("Solaris", ((AttributeOption)ao.getChildren().get(6)).getName());
96         assertEquals("SunOS", ((AttributeOption)ao.getChildren().get(7)).getName());
97     }
98
99     public void testGetParents()
100         throws Exception JavaDoc
101     {
102         System.out.println (
103             "Testing: testGetParents() with AttributeOption: " + ao.getName());
104         List JavaDoc options = ao.getParents();
105         Iterator JavaDoc itr = options.iterator();
106         while (itr.hasNext())
107         {
108             AttributeOption val = ((AttributeOption)itr.next());
109             System.out.println (val);
110         }
111         int size = options.size();
112         assertEquals(size, 1);
113         assertEquals(((AttributeOption)ao.getParents().get(0)).getName(), "Unix");
114     }
115
116     public void testIsChildOf()
117         throws Exception JavaDoc
118     {
119         System.out.println (
120             "Testing: testIsChildOf() with AttributeOption: " + ao.getName());
121         AttributeOption parent =
122             AttributeOptionManager.getInstance(new NumberKey(87));
123         assertEquals(true, ao.isChildOf(parent));
124         System.out.println (ao.isChildOf(parent));
125     }
126
127     public void testIsParentOf()
128         throws Exception JavaDoc
129     {
130         System.out.println (
131             "Testing: testIsParentOf() with AttributeOption: " + ao.getName());
132         AttributeOption child =
133             AttributeOptionManager.getInstance(new NumberKey(39));
134         assertEquals(true, ao.isParentOf(child));
135         System.out.println (ao.isParentOf(child));
136     }
137
138     public void testHasChildren()
139         throws Exception JavaDoc
140     {
141         System.out.println (
142             "Testing: testHasChildren() with AttributeOption: " + ao.getName());
143         assertEquals(true, ao.hasChildren());
144         System.out.println (ao.hasChildren());
145     }
146
147     public void testHasParents()
148         throws Exception JavaDoc
149     {
150         System.out.println (
151             "Testing: testHasParents() with AttributeOption: " + ao.getName());
152         assertEquals(true, ao.hasParents());
153         System.out.println (ao.hasParents());
154     }
155 /*
156     private void testAddDeleteChild()
157         throws Exception
158     {
159         System.out.println (
160             "Testing: testAddDeleteChild()");
161
162         // get an Operating System Attribute
163         Attribute attribute = Attribute.getInstance((ObjectKey)new NumberKey(6));
164
165         AttributeOption ao1 = AttributeOption.getInstance();
166         ao1.setName("TestParent");
167         ao1.setAttribute(attribute);
168         AttributeOption ao2 = AttributeOption.getInstance();
169         ao2.setName("TestChild");
170         ao2.setAttribute(attribute);
171
172         ao1.addChild(ao2);
173
174         assertEquals(1, ao1.getChildren().size());
175         assertEquals(0, ao2.getParents().size());
176
177         List options = ao1.getChildren();
178         Iterator itr = options.iterator();
179         while (itr.hasNext())
180         {
181             AttributeOption val = ((AttributeOption)itr.next());
182             System.out.println (val.getWeight() + " : " + val.getName());
183         }
184         assertEquals(true, ao1.isParentOf(ao2));
185         assertEquals(true, ao2.isChildOf(ao1));
186
187         ao1.deleteChild(ao2);
188         
189         assertEquals(false, ao1.isParentOf(ao2));
190         assertEquals(false, ao2.isChildOf(ao1));
191         
192         AttributeOptionPeer.doDelete(ao1);
193         AttributeOptionPeer.doDelete(ao2);
194     }
195
196     private void testAddDeleteParent()
197         throws Exception
198     {
199         System.out.println (
200             "Testing: testAddDeleteParent()");
201
202         // get an Operating System Attribute
203         Attribute attribute = Attribute.getInstance((ObjectKey)new NumberKey(6));
204
205         AttributeOption ao1 = AttributeOption.getInstance();
206         ao1.setName("TestChild");
207         ao1.setAttribute(attribute);
208         AttributeOption ao2 = AttributeOption.getInstance();
209         ao2.setName("TestParent");
210         ao2.setAttribute(attribute);
211         ao2.setPreferredOrder(1);
212
213         ao1.addParent(ao2);
214
215         assertEquals(1, ao1.getParents().size());
216         assertEquals(0, ao2.getChildren().size());
217
218         List options = ao1.getParents();
219         Iterator itr = options.iterator();
220         while (itr.hasNext())
221         {
222             AttributeOption val = ((AttributeOption)itr.next());
223             System.out.println (val.getWeight() + " : " + val.getName());
224         }
225         assertEquals(true, ao1.isChildOf(ao2));
226         assertEquals(true, ao2.isParentOf(ao1));
227
228         ao1.deleteParent(ao2);
229         
230         assertEquals(false, ao1.isChildOf(ao2));
231         assertEquals(false, ao2.isParentOf(ao1));
232         
233         AttributeOptionPeer.doDelete(ao1);
234         AttributeOptionPeer.doDelete(ao2);
235     }
236 */

237     public void testGetAncestors()
238         throws Exception JavaDoc
239     {
240         System.out.println (
241             "Testing: testGetAncestors()");
242             
243         List JavaDoc ancestors = ao.getAncestors();
244         Iterator JavaDoc itr = ancestors.iterator();
245         while (itr.hasNext())
246         {
247             AttributeOption val = ((AttributeOption)itr.next());
248             System.out.println (val.getPrimaryKey() + " : " + val.getName());
249         }
250         assertEquals("Unix", ((AttributeOption)(ancestors.get(0))).getName());
251         assertEquals("All", ((AttributeOption)(ancestors.get(1))).getName());
252     }
253
254     public void testGetDescendants()
255         throws Exception JavaDoc
256     {
257         System.out.println (
258             "Testing: testGetDescendants()");
259             
260         List JavaDoc descendants = ao.getDescendants();
261         Iterator JavaDoc itr = descendants.iterator();
262         while (itr.hasNext())
263         {
264             AttributeOption val = ((AttributeOption)itr.next());
265             System.out.println (val.getPrimaryKey() + " : " + val.getName());
266         }
267         assertEquals("SunOS", ((AttributeOption)(descendants.get(0))).getName());
268         assertEquals("Solaris", ((AttributeOption)(descendants.get(1))).getName());
269         assertEquals("OSF1", ((AttributeOption)(descendants.get(2))).getName());
270         assertEquals("IRIX", ((AttributeOption)(descendants.get(3))).getName());
271         assertEquals("HPUX", ((AttributeOption)(descendants.get(4))).getName());
272         assertEquals("BeOS", ((AttributeOption)(descendants.get(5))).getName());
273         assertEquals("AIX", ((AttributeOption)(descendants.get(6))).getName());
274         assertEquals("BSDI", ((AttributeOption)(descendants.get(7))).getName());
275     }
276
277
278 /* private void testWalkTree()
279         throws Exception
280     {
281         // 87
282         AttributeOption ao =
283             AttributeOption.getInstance((ObjectKey)new NumberKey(24));
284
285 // ROptionOption roo =
286 // ROptionOption.getInstance((ObjectKey)new NumberKey(87));
287         Attribute attr = Attribute.getInstance((ObjectKey)new NumberKey(6));
288
289         attr.getOrderedParentChildList();
290         
291 // ROptionOption roo = new ROptionOption();
292 // roo.getAttributeOptionList(ao.getAttribute());
293     }
294 */

295 }
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
Popular Tags