001: package org.tigris.scarab.om;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048:
049: import java.util.Iterator;
050: import java.util.List;
051:
052: import org.apache.torque.om.NumberKey;
053: import org.tigris.scarab.test.BaseScarabTestCase;
054:
055: /**
056: * A Testing Suite for the om.Attribute class.
057: *
058: * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
059: * @version $Id: AttributeOptionTest.java 9271 2004-11-23 08:35:00Z dep4b $
060: */
061: public class AttributeOptionTest extends BaseScarabTestCase {
062: private AttributeOption ao;
063:
064: public void setUp() throws Exception {
065: super .setUp();
066: ao = AttributeOptionManager.getInstance(new NumberKey(83));
067:
068: }
069:
070: public void testGetChildren() throws Exception {
071: System.out
072: .println("Testing: testGetChildren() with AttributeOption: "
073: + ao.getName());
074: List options = ao.getChildren();
075: Iterator itr = options.iterator();
076: while (itr.hasNext()) {
077: AttributeOption val = ((AttributeOption) itr.next());
078: System.out.println(val);
079: }
080: int size = options.size();
081: assertEquals(size, 8);
082: assertEquals("BSDI",
083: ((AttributeOption) ao.getChildren().get(0)).getName());
084: assertEquals("AIX", ((AttributeOption) ao.getChildren().get(1))
085: .getName());
086: assertEquals("BeOS",
087: ((AttributeOption) ao.getChildren().get(2)).getName());
088: assertEquals("HPUX",
089: ((AttributeOption) ao.getChildren().get(3)).getName());
090: assertEquals("IRIX",
091: ((AttributeOption) ao.getChildren().get(4)).getName());
092: assertEquals("OSF1",
093: ((AttributeOption) ao.getChildren().get(5)).getName());
094: assertEquals("Solaris", ((AttributeOption) ao.getChildren()
095: .get(6)).getName());
096: assertEquals("SunOS", ((AttributeOption) ao.getChildren()
097: .get(7)).getName());
098: }
099:
100: public void testGetParents() throws Exception {
101: System.out
102: .println("Testing: testGetParents() with AttributeOption: "
103: + ao.getName());
104: List options = ao.getParents();
105: Iterator itr = options.iterator();
106: while (itr.hasNext()) {
107: AttributeOption val = ((AttributeOption) itr.next());
108: System.out.println(val);
109: }
110: int size = options.size();
111: assertEquals(size, 1);
112: assertEquals(((AttributeOption) ao.getParents().get(0))
113: .getName(), "Unix");
114: }
115:
116: public void testIsChildOf() throws Exception {
117: System.out
118: .println("Testing: testIsChildOf() with AttributeOption: "
119: + ao.getName());
120: AttributeOption parent = AttributeOptionManager
121: .getInstance(new NumberKey(87));
122: assertEquals(true, ao.isChildOf(parent));
123: System.out.println(ao.isChildOf(parent));
124: }
125:
126: public void testIsParentOf() throws Exception {
127: System.out
128: .println("Testing: testIsParentOf() with AttributeOption: "
129: + ao.getName());
130: AttributeOption child = AttributeOptionManager
131: .getInstance(new NumberKey(39));
132: assertEquals(true, ao.isParentOf(child));
133: System.out.println(ao.isParentOf(child));
134: }
135:
136: public void testHasChildren() throws Exception {
137: System.out
138: .println("Testing: testHasChildren() with AttributeOption: "
139: + ao.getName());
140: assertEquals(true, ao.hasChildren());
141: System.out.println(ao.hasChildren());
142: }
143:
144: public void testHasParents() throws Exception {
145: System.out
146: .println("Testing: testHasParents() with AttributeOption: "
147: + ao.getName());
148: assertEquals(true, ao.hasParents());
149: System.out.println(ao.hasParents());
150: }
151:
152: /*
153: private void testAddDeleteChild()
154: throws Exception
155: {
156: System.out.println (
157: "Testing: testAddDeleteChild()");
158:
159: // get an Operating System Attribute
160: Attribute attribute = Attribute.getInstance((ObjectKey)new NumberKey(6));
161:
162: AttributeOption ao1 = AttributeOption.getInstance();
163: ao1.setName("TestParent");
164: ao1.setAttribute(attribute);
165: AttributeOption ao2 = AttributeOption.getInstance();
166: ao2.setName("TestChild");
167: ao2.setAttribute(attribute);
168:
169: ao1.addChild(ao2);
170:
171: assertEquals(1, ao1.getChildren().size());
172: assertEquals(0, ao2.getParents().size());
173:
174: List options = ao1.getChildren();
175: Iterator itr = options.iterator();
176: while (itr.hasNext())
177: {
178: AttributeOption val = ((AttributeOption)itr.next());
179: System.out.println (val.getWeight() + " : " + val.getName());
180: }
181: assertEquals(true, ao1.isParentOf(ao2));
182: assertEquals(true, ao2.isChildOf(ao1));
183:
184: ao1.deleteChild(ao2);
185:
186: assertEquals(false, ao1.isParentOf(ao2));
187: assertEquals(false, ao2.isChildOf(ao1));
188:
189: AttributeOptionPeer.doDelete(ao1);
190: AttributeOptionPeer.doDelete(ao2);
191: }
192:
193: private void testAddDeleteParent()
194: throws Exception
195: {
196: System.out.println (
197: "Testing: testAddDeleteParent()");
198:
199: // get an Operating System Attribute
200: Attribute attribute = Attribute.getInstance((ObjectKey)new NumberKey(6));
201:
202: AttributeOption ao1 = AttributeOption.getInstance();
203: ao1.setName("TestChild");
204: ao1.setAttribute(attribute);
205: AttributeOption ao2 = AttributeOption.getInstance();
206: ao2.setName("TestParent");
207: ao2.setAttribute(attribute);
208: ao2.setPreferredOrder(1);
209:
210: ao1.addParent(ao2);
211:
212: assertEquals(1, ao1.getParents().size());
213: assertEquals(0, ao2.getChildren().size());
214:
215: List options = ao1.getParents();
216: Iterator itr = options.iterator();
217: while (itr.hasNext())
218: {
219: AttributeOption val = ((AttributeOption)itr.next());
220: System.out.println (val.getWeight() + " : " + val.getName());
221: }
222: assertEquals(true, ao1.isChildOf(ao2));
223: assertEquals(true, ao2.isParentOf(ao1));
224:
225: ao1.deleteParent(ao2);
226:
227: assertEquals(false, ao1.isChildOf(ao2));
228: assertEquals(false, ao2.isParentOf(ao1));
229:
230: AttributeOptionPeer.doDelete(ao1);
231: AttributeOptionPeer.doDelete(ao2);
232: }
233: */
234: public void testGetAncestors() throws Exception {
235: System.out.println("Testing: testGetAncestors()");
236:
237: List ancestors = ao.getAncestors();
238: Iterator itr = ancestors.iterator();
239: while (itr.hasNext()) {
240: AttributeOption val = ((AttributeOption) itr.next());
241: System.out.println(val.getPrimaryKey() + " : "
242: + val.getName());
243: }
244: assertEquals("Unix", ((AttributeOption) (ancestors.get(0)))
245: .getName());
246: assertEquals("All", ((AttributeOption) (ancestors.get(1)))
247: .getName());
248: }
249:
250: public void testGetDescendants() throws Exception {
251: System.out.println("Testing: testGetDescendants()");
252:
253: List descendants = ao.getDescendants();
254: Iterator itr = descendants.iterator();
255: while (itr.hasNext()) {
256: AttributeOption val = ((AttributeOption) itr.next());
257: System.out.println(val.getPrimaryKey() + " : "
258: + val.getName());
259: }
260: assertEquals("SunOS", ((AttributeOption) (descendants.get(0)))
261: .getName());
262: assertEquals("Solaris",
263: ((AttributeOption) (descendants.get(1))).getName());
264: assertEquals("OSF1", ((AttributeOption) (descendants.get(2)))
265: .getName());
266: assertEquals("IRIX", ((AttributeOption) (descendants.get(3)))
267: .getName());
268: assertEquals("HPUX", ((AttributeOption) (descendants.get(4)))
269: .getName());
270: assertEquals("BeOS", ((AttributeOption) (descendants.get(5)))
271: .getName());
272: assertEquals("AIX", ((AttributeOption) (descendants.get(6)))
273: .getName());
274: assertEquals("BSDI", ((AttributeOption) (descendants.get(7)))
275: .getName());
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: }
|