1 package org.tigris.scarab.om; 2 3 48 49 import java.util.ArrayList ; 50 import java.util.HashMap ; 51 import java.util.List ; 52 import java.util.Map ; 53 import java.util.Set ; 54 55 import org.apache.torque.om.NumberKey; 56 import org.apache.torque.util.Criteria; 57 import org.tigris.scarab.test.BaseScarabTestCase; 58 59 65 public class IssueTest extends BaseScarabTestCase 66 { 67 private List issueList = new ArrayList (); 68 private Map uniqueIDs; 69 protected static int nbrDfltModules = 7; 70 protected static int nbrDfltIssueTypes = 5; 71 72 public void setUp() throws Exception 73 { 74 super.setUp(); 75 uniqueIDs = new HashMap (); 76 createTestIssues(); 77 loopThruTestIssues(); 78 79 } 80 81 82 private void createTestIssues() throws Exception 83 { 84 for (int i = 1; i < nbrDfltModules + 1; i++) 87 { 88 for (int j = 1; j < nbrDfltIssueTypes + 1; j++) 89 { 90 Module module = 91 ScarabModulePeer.retrieveByPK( 92 new NumberKey(Integer.toString(i))); 93 IssueType issueType = 94 IssueTypePeer.retrieveByPK( 95 new NumberKey(Integer.toString(j))); 96 Issue issue = Issue.getNewInstance(module, issueType); 97 issueList.add(issue); 98 } 99 } 100 } 101 102 private void loopThruTestIssues() throws Exception 103 { 104 for (int i = 1; i < issueList.size(); i++) 105 { 106 Issue issue = (Issue) issueList.get(i); 107 System.out.println("MODULE=" + issue.getModule().getName()); 108 System.out.println( 109 "ISSUE TYPE = " + issue.getIssueType().getName()); 110 String strUniqueID = issue.getUniqueId(); 111 System.out.println("Unique id: " + strUniqueID); 112 runTestGetAllAttributeValuesMap(issue); 113 } 114 } 115 116 private void runTestGetAllAttributeValuesMap(Issue issue) throws Exception 117 { 118 System.out.println("testGetAllAttributeValuesMap()"); 119 Map map = issue.getAllAttributeValuesMap(); 120 System.out.println("getAllAttributeValuesMap().size(): " + map.size()); 121 int expectedSize = 12; 122 switch (Integer.parseInt(issue.getTypeId().toString())) 123 { 124 case 1 : 125 expectedSize = 12; 126 break; 127 case 2 : 128 expectedSize = 12; 129 break; 130 case 3 : 131 expectedSize = 11; 132 break; 133 case 4 : 134 expectedSize = 11; 135 break; 136 case 5 : 137 expectedSize = 9; 138 break; 139 case 6 : 140 expectedSize = 9; 141 break; 142 case 7 : 143 expectedSize = 9; 144 break; 145 case 8 : 146 expectedSize = 9; 147 break; 148 case 9 : 149 expectedSize = 9; 150 break; 151 case 10 : 152 expectedSize = 9; 153 } 154 assertTrue("issue.getTypeId():" + issue.getTypeId(),map.size()>4); 156 } 157 158 private void assignUser() throws Exception 159 { 160 System.out.println("assignUser()"); 161 Attribute assignAttr = getAssignAttribute(); 162 ScarabUser assigner = getUser1(); 163 ScarabUser assignee = getUser2(); 164 getIssue0().assignUser( 165 null, 166 assigner, 167 assignee, 168 assignAttr, 169 getAttachment(assigner)); 170 } 171 172 public void testGetAssociatedUsers() throws Exception 173 { 174 System.out.println("testAssociatedUsers()"); 175 assignUser(); 176 assertEquals(getIssue0().getAssociatedUsers().size(), 1); 177 List pair = (List ) getIssue0().getAssociatedUsers().iterator().next(); 178 assertEquals(pair.get(1), getUser1()); 179 } 180 181 public void OFFtestChangeUserAttributeValue() throws Exception 182 { 183 System.out.println("testChangeUserAttributeValue()"); 184 assignUser(); 185 Attribute assignAttr = getAssignAttribute(); 186 Attribute ccAttr = getCcAttribute(); 187 ScarabUser assigner = getUser1(); 188 ScarabUser assignee = getUser2(); 189 AttributeValue attVal = getIssue0().getAttributeValue(assignAttr); 190 getIssue0().changeUserAttributeValue( 191 null, 192 assigner, 193 assignee, 194 attVal, 195 ccAttr, 196 getAttachment(assigner)); 197 List pair = (List ) getIssue0().getAssociatedUsers().iterator().next(); 198 assertEquals(pair.get(0), ccAttr); 199 } 200 201 public void OFFtestDeleteUser() throws Exception 202 { 203 System.out.println("testDeleteUser()"); 204 Attribute assignAttr = getAssignAttribute(); 205 ScarabUser assigner = getUser1(); 206 AttributeValue attVal = getIssue0().getAttributeValue(assignAttr); 207 getIssue0().deleteUser( 208 null, 209 getUser1(), 210 getUser2(), 211 attVal, 212 getAttachment(assigner)); 213 assertEquals(getIssue0().getAssociatedUsers().size(), 0); 214 } 215 216 public void testGetUserAttributeValues() throws Exception 217 { 218 System.out.println("testAssociatedUsers()"); 219 assignUser(); 220 List attVals = getIssue0().getUserAttributeValues(); 221 AttributeValue attVal = (AttributeValue) attVals.get(0); 222 assertEquals(attVal.getAttributeId().toString(), "2"); 223 } 224 225 public void testGetEligibleUsers() throws Exception 226 { 227 System.out.println("testGetEligibleUsers()"); 228 assignUser(); 229 List users = getIssue0().getEligibleUsers(getAssignAttribute()); 230 assertTrue(users.size()>0); 231 } 232 233 public void testGetUsersToEmail() throws Exception 234 { 235 System.out.println("testGetUsersToEmail()"); 236 assignUser(); 237 Set users = 238 getIssue0().getUsersToEmail( 239 AttributePeer.EMAIL_TO, 240 getIssue0(), 241 null); 242 assertEquals(users.size(), 2); 243 } 244 245 private Attachment getAttachment(ScarabUser assigner) throws Exception 246 { 247 Attachment attachment = new Attachment(); 248 attachment.setData("test reason"); 249 attachment.setName("comment"); 250 attachment.setTextFields( 251 assigner, 252 getIssue0(), 253 Attachment.MODIFICATION__PK); 254 attachment.save(); 255 return attachment; 256 } 257 258 public void testCounts() throws Exception 259 { 260 System.out.println("Testing IssuePeer count methods"); 261 assignUser(); 262 int count = IssuePeer.count(new Criteria()); 263 assertTrue( 264 "IssuePeer.count(new Criteria()) returned " + count, 265 count>0); 266 count = IssuePeer.countDistinct(new Criteria()); 267 assertTrue( 268 "IssuePeer.countDistinct(new Criteria()) returned " + count, 269 count>0); 270 } 271 272 protected ScarabUser getUser2() 273 throws Exception 274 { 275 return ScarabUserManager.getInstance(new NumberKey(2), false); 276 277 } 278 279 protected Attribute getAssignAttribute() 280 throws Exception 281 { 282 return AttributeManager.getInstance(new NumberKey(2)); 283 } 284 285 protected Attribute getCcAttribute() 286 throws Exception 287 { 288 289 return AttributeManager.getInstance(new NumberKey(13)); 290 291 } 292 } 293 | Popular Tags |