001: package org.tigris.scarab.da;
002:
003: /* ================================================================
004: * Copyright (c) 2000 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 CollabNet (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" name
028: * nor may "Tigris" appear in their names without prior written
029: * permission of CollabNet.
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 CollabNet.
047: */
048:
049: import java.util.Collection;
050: import java.util.List;
051: import java.util.Set;
052:
053: import org.apache.turbine.Turbine;
054: import org.tigris.scarab.test.BaseScarabTestCase;
055: import org.tigris.scarab.util.ScarabException;
056:
057: /**
058: * Tests the AttributeAccess implementation.
059: *
060: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
061: */
062: public class AttributeAccessTest extends BaseScarabTestCase {
063: public void setUp() throws Exception {
064: super .setUp();
065: Turbine.getConfiguration().setProperty(
066: "dataaccess.AttributeAccess.classname",
067: "org.tigris.scarab.da.AttributeAccess");
068: assertNotNull(Turbine.getConfiguration().getString(
069: "dataaccess.AttributeAccess.classname"));
070: }
071:
072: public void testRetrieveQueryColumnIDs() throws ScarabException {
073: AttributeAccess aa = DAFactory.getAttributeAccess();
074: String userID = "1";
075: String listID = "1";
076: String moduleID = "5";
077: String artifactTypeID = "1";
078: List ids = aa.retrieveQueryColumnIDs(userID, listID, moduleID,
079: artifactTypeID);
080: System.out.println("ids are " + ids);
081: // TODO: finish
082: }
083:
084: /*
085: * Make sure delete doesn't break another testcase that needs the data!
086: * Better would be to create a new set of data!
087: */
088: public void OFFtestDeleteQueryColumnIDs() throws ScarabException {
089: AttributeAccess aa = DAFactory.getAttributeAccess();
090: String userID = "1";
091: String listID = "1";
092: String moduleID = "5";
093: String artifactTypeID = "1";
094: aa.deleteQueryColumnIDs(userID, listID, moduleID,
095: artifactTypeID);
096: // TODO: finish
097: }
098:
099: public void testRetrieveRequiredAttributeIDs()
100: throws ScarabException {
101: AttributeAccess aa = DAFactory.getAttributeAccess();
102: String moduleID = "5";
103: String[] artifactTypeID = { "1", "3", "5", "7", "9" };
104: Set ids;
105: for (int i = 0; i < artifactTypeID.length; i++) {
106: ids = aa.retrieveRequiredAttributeIDs(moduleID,
107: artifactTypeID[i]);
108: assertEquals(getExpectedRequiredSize(artifactTypeID[i]),
109: ids.size());
110: }
111: }
112:
113: private int getExpectedRequiredSize(String artifactTypeID)
114:
115: {
116: int expectedSize = 0;
117: switch (Integer.parseInt(artifactTypeID)) {
118: case 1:
119: expectedSize = 4;
120: break;
121: case 3:
122: expectedSize = 4;
123: break;
124: case 5:
125: expectedSize = 2;
126: break;
127: case 7:
128: expectedSize = 2;
129: break;
130: case 9:
131: expectedSize = 2;
132: break;
133: }
134: return expectedSize;
135: }
136:
137: public void testRetrieveQuickSearchAttributeIDs()
138: throws ScarabException {
139: AttributeAccess aa = DAFactory.getAttributeAccess();
140: String moduleID = "5";
141: String artifactTypeID = "1";
142: Set ids = aa.retrieveQuickSearchAttributeIDs(moduleID,
143: artifactTypeID);
144: // assertEquals (1, ids.size());
145: }
146:
147: public void testRetrieveActiveAttributeOMs() throws ScarabException {
148: AttributeAccess aa = DAFactory.getAttributeAccess();
149: String moduleID = "5";
150: boolean isOrdered = false;
151: String[] artifactTypeID = { "1", "3", "5", "7", "9" };
152: Collection oms;
153: for (int i = 0; i < artifactTypeID.length; i++) {
154: oms = aa.retrieveActiveAttributeOMs(moduleID,
155: artifactTypeID[i], isOrdered);
156: assertEquals(getExpectedActiveSize(artifactTypeID[i]), oms
157: .size());
158: }
159: }
160:
161: private int getExpectedActiveSize(String artifactTypeID)
162:
163: {
164: int expectedSize = 0;
165: switch (Integer.parseInt(artifactTypeID)) {
166: // these values include 2 user attributes
167: case 1:
168: expectedSize = 12;
169: break;
170: case 3:
171: expectedSize = 11;
172: break;
173: case 5:
174: expectedSize = 9;
175: break;
176: case 7:
177: expectedSize = 9;
178: break;
179: case 9:
180: expectedSize = 9;
181: break;
182: }
183: return expectedSize;
184: }
185:
186: public void testRetrieveDefaultTextAttributeID()
187: throws ScarabException {
188: AttributeAccess aa = DAFactory.getAttributeAccess();
189: String moduleID = "5";
190: String artifactTypeID = "1";
191: String id = aa.retrieveDefaultTextAttributeID(moduleID,
192: artifactTypeID);
193: // assertEquals("11", id);
194: }
195:
196: public void testRetrieveFirstActiveTextAttributeID()
197: throws ScarabException {
198: AttributeAccess aa = DAFactory.getAttributeAccess();
199: String moduleID = "5";
200: String artifactTypeID = "1";
201: String id = aa.retrieveFirstActiveTextAttributeID(moduleID,
202: artifactTypeID);
203: // assertEquals("11", id);
204: }
205: }
|