KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > util > word > IssueSearchTest


1 package org.tigris.scarab.util.word;
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
50 import org.tigris.scarab.test.BaseScarabTestCase;
51 import org.tigris.scarab.om.Module;
52 import org.tigris.scarab.om.IssueType;
53 import org.tigris.scarab.om.AttributeValue;
54 import org.tigris.scarab.om.AttributeManager;
55 import org.tigris.scarab.om.AttributeOptionManager;
56 import org.tigris.scarab.om.AttributeOption;
57 import org.tigris.scarab.util.IteratorWithSize;
58
59 /**
60  * A Testing Suite for the om.IssueSearch class.
61  *
62  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
63  * @version $Id: IssueSearchTest.java 9446 2005-03-12 11:59:50Z jorgeuriarte $
64  */

65 public class IssueSearchTest extends BaseScarabTestCase
66 {
67     private IssueSearch search;
68
69     private int[] attributeIds = {3, 4, 6, 7, 8}; //, 9, 12};
70
private int[] optionIds = {1, 8, 24, 54, 58}; //, 62, 88};
71

72     private IssueSearch getSearch()
73         throws Exception JavaDoc, MaxConcurrentSearchException
74     {
75         Module module = getModule();
76         IssueType it = getDefaultIssueType();
77         IssueSearch search = IssueSearchFactory.INSTANCE
78             .getInstance(module, it, getUser1());
79         search.setIssueListAttributeColumns(
80             module.getDefaultRModuleUserAttributes(it));
81         return search;
82     }
83
84     public void testSingleOptionAttribute()
85         throws Exception JavaDoc
86     {
87         IssueSearch search = getSearch();
88         AttributeValue platformAV = AttributeValue
89             .getNewInstance(getPlatformAttribute(), search);
90         AttributeOption sgi =
91             AttributeOptionManager.getInstance(new Integer JavaDoc(21));
92         platformAV.setAttributeOption(sgi);
93         search.addAttributeValue(platformAV);
94         IteratorWithSize results = search.getQueryResults();
95         assertTrue("Should be one result.", (results.size() == 1));
96         IssueSearchFactory.INSTANCE.notifyDone();
97     }
98
99     public void testWrongOptionAttribute()
100         throws Exception JavaDoc
101     {
102         IssueSearch search = getSearch();
103         AttributeValue platformAV = AttributeValue
104             .getNewInstance(getPlatformAttribute(), search);
105         AttributeOption notsgi =
106             AttributeOptionManager.getInstance(new Integer JavaDoc(20));
107         platformAV.setAttributeOption(notsgi);
108         search.addAttributeValue(platformAV);
109         IteratorWithSize results = search.getQueryResults();
110         assertTrue("Should be no result.", (results.size() == 0));
111         IssueSearchFactory.INSTANCE.notifyDone();
112     }
113
114     public void testUserWithAny()
115         throws Exception JavaDoc
116     {
117         IssueSearch search = getSearch();
118         search.addUserCriteria(getUser5().getUserId().toString(),
119                                IssueSearch.ANY_KEY);
120         IteratorWithSize results = search.getQueryResults();
121         assertTrue("Should be one result.", (results.size() == 1));
122         IssueSearchFactory.INSTANCE.notifyDone();
123     }
124
125     public void testUserWithCreatedBy()
126         throws Exception JavaDoc
127     {
128         IssueSearch search = getSearch();
129         search.addUserCriteria(getUser5().getUserId().toString(),
130                                IssueSearch.CREATED_BY_KEY);
131         IteratorWithSize results = search.getQueryResults();
132         assertTrue("Should be one result.", (results.size() == 1));
133         IssueSearchFactory.INSTANCE.notifyDone();
134     }
135
136     public void testUserWithAssignedTo()
137         throws Exception JavaDoc
138     {
139         IssueSearch search = getSearch();
140         search.addUserCriteria(getUser5().getUserId().toString(),
141             getAssignAttribute().getAttributeId().toString());
142         IteratorWithSize results = search.getQueryResults();
143         assertTrue("Should be no results.", (results.size() == 0));
144         IssueSearchFactory.INSTANCE.notifyDone();
145     }
146
147     // these seem to cause timeouts
148
public void OFFtestUserWithAssignedToAndCreatedDate()
149         throws Exception JavaDoc
150     {
151         IssueSearch search = getSearch();
152         search.addUserCriteria(getUser5().getUserId().toString(),
153             getAssignAttribute().getAttributeId().toString());
154         search.setMinDate("01/01/2000");
155         IteratorWithSize results = search.getQueryResults();
156         assertTrue("Should be no results.", (results.size() == 0));
157         IssueSearchFactory.INSTANCE.notifyDone();
158     }
159
160
161     public void testSingleOptionAndUserWithAny()
162         throws Exception JavaDoc
163     {
164         IssueSearch search = getSearch();
165         AttributeValue platformAV = AttributeValue
166             .getNewInstance(getPlatformAttribute(), search);
167         AttributeOption sgi =
168             AttributeOptionManager.getInstance(new Integer JavaDoc(21));
169         platformAV.setAttributeOption(sgi);
170         search.addAttributeValue(platformAV);
171         search.addUserCriteria(getUser5().getUserId().toString(),
172                                IssueSearch.ANY_KEY);
173         IteratorWithSize results = search.getQueryResults();
174         assertTrue("Should be one result.", (results.size() == 1));
175         IssueSearchFactory.INSTANCE.notifyDone();
176     }
177
178
179     public void OFFtestLargeQuery()
180         throws Exception JavaDoc
181     {
182         IssueSearch search = getSearch();
183         search.setMinDate("01/01/2000"); // 1
184
AttributeValue av;
185         AttributeOption o;
186         for (int i = 0; i < attributeIds.length; i++)
187         {
188             av = AttributeValue.getNewInstance(AttributeManager.getInstance(
189                  new Integer JavaDoc(attributeIds[i])), search);
190             o = AttributeOptionManager.getInstance(new Integer JavaDoc(optionIds[i]));
191             av.setAttributeOption(o);
192             search.addAttributeValue(av); // 6
193
}
194         
195         search.addUserCriteria(getUser5().getUserId().toString(),
196                                IssueSearch.ANY_KEY); // 7
197

198         search.setStateChangeFromOptionId(new Integer JavaDoc(2));
199         search.setStateChangeToOptionId(new Integer JavaDoc(1)); // 8
200
search.setStateChangeFromDate("01/01/2000");
201         search.setStateChangeToDate("01/01/2004"); // 9
202

203         IteratorWithSize results = search.getQueryResults();
204         assertTrue("Should be no results.", (results.size() == 0));
205         IssueSearchFactory.INSTANCE.notifyDone();
206
207         av = AttributeValue.getNewInstance(getPlatformAttribute(), search);
208         o = AttributeOptionManager.getInstance(new Integer JavaDoc(21));
209         av.setAttributeOption(o);
210         System.out.println("av size=" + search.getAttributeValues().size());
211         search.addAttributeValue(av); // 11
212
System.out.println("after av size=" + search.getAttributeValues().size());
213
214         try
215         {
216             search.getQueryResults();
217             fail("Should have thrown ComplexQueryException");
218         }
219         catch (ComplexQueryException e)
220         {
221             // expected
222
}
223         IssueSearchFactory.INSTANCE.notifyDone();
224     }
225 }
226
227
Popular Tags