1 package org.tigris.scarab.om; 2 3 48 49 import java.util.Date ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.Map ; 53 54 import org.apache.torque.om.NumberKey; 55 import org.tigris.scarab.services.security.ScarabSecurity; 56 import org.tigris.scarab.test.BaseScarabTestCase; 57 58 64 public class ScarabModuleTest extends BaseScarabTestCase 65 { 66 ScarabModule newModule; 67 public void setUp() throws Exception { 68 super.setUp(); 69 newModule = (ScarabModule)ModuleManager.getInstance(); 70 Date d = new Date (); 71 newModule.setRealName("Test Module " + d.getTime()); 72 newModule.setOwnerId(new Integer (1)); 73 newModule.setParentId(new Integer (1)); 74 newModule.setDescription("This is the new module description"); 75 76 77 newModule.save(); 78 79 } 80 81 82 public void testGetParents() throws Exception 83 { 84 Module module = ModuleManager 85 .getInstance(new NumberKey(7), false); 86 List parents = module.getAncestors(); 87 Iterator itr = parents.iterator(); 88 while (itr.hasNext()) 89 { 90 Module me = (Module) itr.next(); 91 System.out.println (me.getName()); 92 } 93 System.out.println ("parents=" + parents.size()); 94 } 95 96 97 public void testIssueTypes() throws Exception 98 { 99 List issueTypes = newModule.getRModuleIssueTypes(); 100 for (int i = 0;i<issueTypes.size();i++) 101 { 102 IssueType issueType = ((RModuleIssueType)issueTypes 103 .get(i)).getIssueType(); 104 System.out.println("ISSUE TYPE = " + issueType.getName()); 105 Issue issue = new Issue(); 106 issue.setModule(newModule); 107 issue.setIssueType(issueType); 108 109 testGetAllAttributeValuesMap(issue); 110 testGetAttributeGroups(issueType); 111 testGetUserAttributes(issueType); 112 } 113 } 114 115 public void testGetAttributeGroups(IssueType issueType) 116 throws Exception 117 { 118 System.out.println ("testGetAttributeGroups()"); 119 List attrGroups = issueType.getAttributeGroups(newModule, true); 120 for (int i=0;i<attrGroups.size(); i++) 121 { 122 AttributeGroup group = (AttributeGroup)attrGroups.get(i); 123 System.out.println("attribute group = " + group.getName()); 124 } 125 } 126 127 128 public void testGetUsers() throws Exception 129 { 130 ScarabUser[] users = newModule.getUsers(ScarabSecurity.ISSUE__VIEW); 131 System.out.println(users); 132 } 133 134 public void testGetAllAttributeValuesMap(Issue issue) throws Exception 135 { 136 System.out.println ("testGetAllAttributeValuesMap()"); 137 Map attrMap = issue.getAllAttributeValuesMap(); 138 System.out.println ("getAllAttributeValuesMap().size(): " 139 + attrMap.size()); 140 assertEquals (getExpectedSize(issue.getIssueType()), attrMap.size()); 141 Iterator iter = attrMap.keySet().iterator(); 142 Attribute attr = null; 143 while (iter.hasNext()) 144 { 145 attr = ((AttributeValue)attrMap.get(iter.next())) 146 .getAttribute(); 147 if (attr.isOptionAttribute()) 148 { 149 int expectedSize = 0; 150 switch (Integer.parseInt(attr.getAttributeId().toString())) 151 { 152 case 3: expectedSize = 7;break; 153 case 4: expectedSize = 8;break; 154 case 5: expectedSize = 8;break; 155 case 6: expectedSize = 52;break; 156 case 7: expectedSize = 4;break; 157 case 8: expectedSize = 4;break; 158 case 9: expectedSize = 10;break; 159 case 12: expectedSize = 3;break; 160 } 161 assertTrue(expectedSize >0); 162 } 163 } 164 } 165 166 public void testGetUserAttributes(IssueType issueType) 167 throws Exception 168 { 169 System.out.println ("testGetUserAttributes"); 170 List attrs = newModule.getUserAttributes(issueType); 171 assertEquals (2, attrs.size()); 172 } 173 174 175 private int getExpectedSize(IssueType issueType) throws Exception 176 177 { 178 int expectedSize = 0; 179 switch (Integer.parseInt(issueType.getIssueTypeId().toString())) 180 { 181 case 1: expectedSize = 12;break; 182 case 3: expectedSize = 11;break; 183 case 5: expectedSize = 9;break; 184 case 7: expectedSize = 9;break; 185 case 9: expectedSize = 9;break; 186 } 187 return expectedSize; 188 } 189 190 191 } 192 | Popular Tags |