1 package org.tigris.scarab.util.word; 2 3 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 65 public class IssueSearchTest extends BaseScarabTestCase 66 { 67 private IssueSearch search; 68 69 private int[] attributeIds = {3, 4, 6, 7, 8}; private int[] optionIds = {1, 8, 24, 54, 58}; 72 private IssueSearch getSearch() 73 throws Exception , 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 86 { 87 IssueSearch search = getSearch(); 88 AttributeValue platformAV = AttributeValue 89 .getNewInstance(getPlatformAttribute(), search); 90 AttributeOption sgi = 91 AttributeOptionManager.getInstance(new Integer (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 101 { 102 IssueSearch search = getSearch(); 103 AttributeValue platformAV = AttributeValue 104 .getNewInstance(getPlatformAttribute(), search); 105 AttributeOption notsgi = 106 AttributeOptionManager.getInstance(new Integer (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 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 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 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 public void OFFtestUserWithAssignedToAndCreatedDate() 149 throws Exception 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 163 { 164 IssueSearch search = getSearch(); 165 AttributeValue platformAV = AttributeValue 166 .getNewInstance(getPlatformAttribute(), search); 167 AttributeOption sgi = 168 AttributeOptionManager.getInstance(new Integer (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 181 { 182 IssueSearch search = getSearch(); 183 search.setMinDate("01/01/2000"); AttributeValue av; 185 AttributeOption o; 186 for (int i = 0; i < attributeIds.length; i++) 187 { 188 av = AttributeValue.getNewInstance(AttributeManager.getInstance( 189 new Integer (attributeIds[i])), search); 190 o = AttributeOptionManager.getInstance(new Integer (optionIds[i])); 191 av.setAttributeOption(o); 192 search.addAttributeValue(av); } 194 195 search.addUserCriteria(getUser5().getUserId().toString(), 196 IssueSearch.ANY_KEY); 198 search.setStateChangeFromOptionId(new Integer (2)); 199 search.setStateChangeToOptionId(new Integer (1)); search.setStateChangeFromDate("01/01/2000"); 201 search.setStateChangeToDate("01/01/2004"); 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 (21)); 209 av.setAttributeOption(o); 210 System.out.println("av size=" + search.getAttributeValues().size()); 211 search.addAttributeValue(av); 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 } 223 IssueSearchFactory.INSTANCE.notifyDone(); 224 } 225 } 226 227 | Popular Tags |