1 package org.tigris.scarab.om; 2 3 48 49 import org.apache.torque.om.NumberKey; 50 import org.tigris.scarab.services.cache.ScarabCache; 51 import org.tigris.scarab.test.BaseScarabTestCase; 52 import org.tigris.scarab.util.ScarabException; 53 54 60 public class AttributeGroupTest extends BaseScarabTestCase { 61 private AttributeGroup group = null; 62 63 private Attribute severity = null; 64 65 private Attribute desc = null; 66 67 private ScarabUser user2; 68 69 public void setUp() throws Exception { 70 super.setUp(); 71 severity = AttributeManager.getInstance(new NumberKey("9")); 72 desc = AttributeManager.getInstance(new NumberKey("1")); 73 group = AttributeGroupManager.getInstance(new NumberKey("131")); 74 75 } 76 77 82 public void OFFtestDeleteAddAttribute() throws Exception { 83 84 Attribute test = severity.copyAttribute(getUser1()); 85 test.save(); 86 assertFalse(test.getAttributeId().equals(severity.getAttributeId())); 87 int numberOfAttributes = group.getAttributes().size(); 88 group.addAttribute(test); 89 assertEquals(numberOfAttributes + 1, group.getAttributes().size()); 90 try { 91 group.deleteAttribute(test, getUser1(), getModule()); 92 fail("User 1 doesn't have permissions to delete attributes."); 93 } catch (Exception e) { 94 assertTrue(e instanceof ScarabException); 95 } 96 group.deleteAttribute(test, getUser2(), getModule()); 97 assertEquals(numberOfAttributes, group.getAttributes().size()); 98 } 99 100 protected ScarabUser getUser2() throws Exception { 101 if (user2 == null) { 102 user2 = ScarabUserManager.getInstance(new NumberKey(2), false); 103 } 104 return user2; 105 } 106 107 public void testGetAttributes() throws Exception { 108 System.out.println("\ntestGetAttributes()"); 109 assertTrue(group.getAttributes().size() > 0); 110 } 111 112 public void testGetRAttributeAttributeGroup() throws Exception { 113 114 assertEquals(new Integer (9), group.getRAttributeAttributeGroup(severity).getAttributeId()); 115 } 116 117 125 public void testDelete() throws Exception { 126 System.out.println("\ntestDelete()"); 127 AttributeGroup newGroup = group.copyGroup(); 128 newGroup.setIssueType(group.getIssueType()); 129 newGroup.save(); 130 assertFalse(newGroup.getAttributeGroupId().equals(group.getAttributeGroupId())); 131 132 newGroup.delete(); 133 ScarabCache.clear(); 134 assertFalse(AttributeGroupManager.exists(newGroup)); 135 136 group = AttributeGroupManager.getInstance(new NumberKey("131")); 137 assertNotNull(group); 138 assertTrue(AttributeGroupManager.exists(group)); 139 140 } 141 } | Popular Tags |