KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > da > AttributeAccessTest


1 package org.tigris.scarab.da;
2
3 /* ================================================================
4  * Copyright (c) 2000 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 CollabNet (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" name
28  * nor may "Tigris" appear in their names without prior written
29  * permission of CollabNet.
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 CollabNet.
47  */

48
49 import java.util.Collection JavaDoc;
50 import java.util.List JavaDoc;
51 import java.util.Set JavaDoc;
52
53 import org.apache.turbine.Turbine;
54 import org.tigris.scarab.test.BaseScarabTestCase;
55 import org.tigris.scarab.util.ScarabException;
56
57 /**
58  * Tests the AttributeAccess implementation.
59  *
60  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
61  */

62 public class AttributeAccessTest
63     extends BaseScarabTestCase
64 {
65     public void setUp() throws Exception JavaDoc{
66         super.setUp();
67         Turbine.getConfiguration().setProperty("dataaccess.AttributeAccess.classname","org.tigris.scarab.da.AttributeAccess");
68         assertNotNull(Turbine.getConfiguration().getString("dataaccess.AttributeAccess.classname"));
69     }
70  
71
72  
73     public void testRetrieveQueryColumnIDs() throws ScarabException
74     {
75         AttributeAccess aa = DAFactory.getAttributeAccess();
76         String JavaDoc userID = "1";
77         String JavaDoc listID = "1";
78         String JavaDoc moduleID = "5";
79         String JavaDoc artifactTypeID = "1";
80         List JavaDoc ids = aa.retrieveQueryColumnIDs(userID, listID,
81                                              moduleID, artifactTypeID);
82         System.out.println("ids are " + ids);
83         // TODO: finish
84
}
85
86     /*
87      * Make sure delete doesn't break another testcase that needs the data!
88      * Better would be to create a new set of data!
89      */

90     public void OFFtestDeleteQueryColumnIDs() throws ScarabException
91     {
92         AttributeAccess aa = DAFactory.getAttributeAccess();
93         String JavaDoc userID = "1";
94         String JavaDoc listID = "1";
95         String JavaDoc moduleID = "5";
96         String JavaDoc artifactTypeID = "1";
97         aa.deleteQueryColumnIDs(userID, listID, moduleID, artifactTypeID);
98         // TODO: finish
99
}
100
101     public void testRetrieveRequiredAttributeIDs() throws ScarabException
102     {
103         AttributeAccess aa = DAFactory.getAttributeAccess();
104         String JavaDoc moduleID = "5";
105         String JavaDoc[] artifactTypeID = {"1", "3", "5", "7", "9"};
106         Set JavaDoc ids;
107         for (int i = 0; i < artifactTypeID.length; i++)
108         {
109             ids = aa.retrieveRequiredAttributeIDs(moduleID, artifactTypeID[i]);
110             assertEquals(getExpectedRequiredSize(artifactTypeID[i]),
111                          ids.size());
112         }
113     }
114
115     private int getExpectedRequiredSize(String JavaDoc artifactTypeID)
116
117     {
118         int expectedSize = 0;
119         switch (Integer.parseInt(artifactTypeID))
120         {
121             case 1: expectedSize = 4;break;
122             case 3: expectedSize = 4;break;
123             case 5: expectedSize = 2;break;
124             case 7: expectedSize = 2;break;
125             case 9: expectedSize = 2;break;
126         }
127         return expectedSize;
128     }
129
130     public void testRetrieveQuickSearchAttributeIDs() throws ScarabException
131     {
132         AttributeAccess aa = DAFactory.getAttributeAccess();
133         String JavaDoc moduleID = "5";
134         String JavaDoc artifactTypeID = "1";
135         Set JavaDoc ids = aa.retrieveQuickSearchAttributeIDs(moduleID, artifactTypeID);
136        // assertEquals (1, ids.size());
137
}
138
139     public void testRetrieveActiveAttributeOMs() throws ScarabException
140     {
141         AttributeAccess aa = DAFactory.getAttributeAccess();
142         String JavaDoc moduleID = "5";
143         boolean isOrdered = false;
144         String JavaDoc[] artifactTypeID = {"1", "3", "5", "7", "9"};
145         Collection JavaDoc oms;
146         for (int i = 0; i < artifactTypeID.length; i++)
147         {
148             oms = aa.retrieveActiveAttributeOMs(moduleID, artifactTypeID[i],
149                                              isOrdered);
150             assertEquals(getExpectedActiveSize(artifactTypeID[i]), oms.size());
151         }
152     }
153
154     private int getExpectedActiveSize(String JavaDoc artifactTypeID)
155
156     {
157         int expectedSize = 0;
158         switch (Integer.parseInt(artifactTypeID))
159         {
160             // these values include 2 user attributes
161
case 1: expectedSize = 12;break;
162             case 3: expectedSize = 11;break;
163             case 5: expectedSize = 9;break;
164             case 7: expectedSize = 9;break;
165             case 9: expectedSize = 9;break;
166         }
167         return expectedSize;
168     }
169
170     public void testRetrieveDefaultTextAttributeID() throws ScarabException
171     {
172         AttributeAccess aa = DAFactory.getAttributeAccess();
173         String JavaDoc moduleID = "5";
174         String JavaDoc artifactTypeID = "1";
175         String JavaDoc id = aa.retrieveDefaultTextAttributeID(moduleID,
176                                                       artifactTypeID);
177       // assertEquals("11", id);
178
}
179
180     public void testRetrieveFirstActiveTextAttributeID() throws ScarabException
181     {
182         AttributeAccess aa = DAFactory.getAttributeAccess();
183         String JavaDoc moduleID = "5";
184         String JavaDoc artifactTypeID = "1";
185         String JavaDoc id = aa.retrieveFirstActiveTextAttributeID(moduleID,
186                                                           artifactTypeID);
187        // assertEquals("11", id);
188
}
189 }
190
Popular Tags