1 17 package org.alfresco.repo.security.permissions.impl.hibernate; 18 19 import java.io.Serializable ; 20 21 import org.alfresco.repo.domain.NodeKey; 22 import org.alfresco.util.BaseSpringTest; 23 24 30 public class HibernatePermissionTest extends BaseSpringTest 31 { 32 33 public HibernatePermissionTest() 34 { 35 } 36 37 protected void onSetUpInTransaction() throws Exception 38 { 39 40 } 41 42 protected void onTearDownInTransaction() 43 { 44 getSession().flush(); 46 getSession().clear(); 47 } 48 49 50 public void testSimpleNodePermission() throws Exception 51 { 52 NodePermissionEntry nodePermission = new NodePermissionEntryImpl(); 54 NodeKey key = new NodeKey("Random Protocol", "Random Identifier", "AAA"); 55 nodePermission.setNodeKey(key); 56 nodePermission.setInherits(true); 57 58 Serializable id = getSession().save(nodePermission); 59 60 nodePermission = (NodePermissionEntry) getSession().load(NodePermissionEntryImpl.class, id); 62 assertNotNull("Node not found", nodePermission); 63 assertTrue(nodePermission.getInherits()); 64 65 67 nodePermission.setInherits(false); 68 id = getSession().save(nodePermission); 69 70 nodePermission = (NodePermissionEntry) getSession().load(NodePermissionEntryImpl.class, id); 72 assertNotNull("Node not found", nodePermission); 73 assertFalse(nodePermission.getInherits()); 74 } 75 76 public void testSimplePermissionReference() 77 { 78 PermissionReference permissionReference = new PermissionReferenceImpl(); 79 permissionReference.setName("Test"); 80 permissionReference.setTypeUri("TestUri"); 81 permissionReference.setTypeName("TestName"); 82 83 Serializable id = getSession().save(permissionReference); 84 85 permissionReference = (PermissionReference) getSession().load(PermissionReferenceImpl.class, id); 87 assertNotNull("Node not found", permissionReference); 88 assertEquals("Test", permissionReference.getName()); 89 assertEquals("TestUri", permissionReference.getTypeUri()); 90 assertEquals("TestName", permissionReference.getTypeName()); 91 92 94 PermissionReference key = new PermissionReferenceImpl(); 95 key.setName("Test"); 96 key.setTypeUri("TestUri"); 97 key.setTypeName("TestName"); 98 99 permissionReference = (PermissionReference) getSession().load(PermissionReferenceImpl.class, key); 100 assertNotNull("Node not found", permissionReference); 101 assertEquals("Test", permissionReference.getName()); 102 assertEquals("TestUri", permissionReference.getTypeUri()); 103 assertEquals("TestName", permissionReference.getTypeName()); 104 } 105 106 public void testSimpleRecipient() 107 { 108 Recipient recipient = new RecipientImpl(); 109 recipient.setRecipient("Test"); 110 recipient.getExternalKeys().add("One"); 111 112 Serializable id = getSession().save(recipient); 113 114 recipient = (Recipient) getSession().load(RecipientImpl.class, id); 116 assertNotNull("Node not found", recipient); 117 assertEquals("Test", recipient.getRecipient()); 118 assertEquals(1, recipient.getExternalKeys().size()); 119 120 122 123 Recipient key = new RecipientImpl(); 124 key.setRecipient("Test"); 125 126 recipient = (Recipient) getSession().load(RecipientImpl.class, key); 127 assertNotNull("Node not found", recipient); 128 assertEquals("Test", recipient.getRecipient()); 129 assertEquals(1, recipient.getExternalKeys().size()); 130 131 132 134 recipient.getExternalKeys().add("Two"); 135 id = getSession().save(recipient); 136 137 recipient = (Recipient) getSession().load(RecipientImpl.class, id); 139 assertNotNull("Node not found", recipient); 140 assertEquals("Test", recipient.getRecipient()); 141 assertEquals(2, recipient.getExternalKeys().size()); 142 143 144 146 recipient.getExternalKeys().add("Three"); 147 recipient.getExternalKeys().remove("One"); 148 recipient.getExternalKeys().remove("Two"); 149 id = getSession().save(recipient); 150 151 recipient = (Recipient) getSession().load(RecipientImpl.class, id); 153 assertNotNull("Node not found", recipient); 154 assertEquals("Test", recipient.getRecipient()); 155 assertEquals(1, recipient.getExternalKeys().size()); 156 157 158 } 159 160 public void testNodePermissionEntry() 161 { 162 NodePermissionEntry nodePermission = new NodePermissionEntryImpl(); 164 NodeKey key = new NodeKey("Random Protocol", "Random Identifier", "AAA"); 165 nodePermission.setNodeKey(key); 166 nodePermission.setInherits(true); 167 168 Recipient recipient = new RecipientImpl(); 169 recipient.setRecipient("Test"); 170 recipient.getExternalKeys().add("One"); 171 172 PermissionReference permissionReference = new PermissionReferenceImpl(); 173 permissionReference.setName("Test"); 174 permissionReference.setTypeUri("TestUri"); 175 permissionReference.setTypeName("TestName"); 176 177 PermissionEntry permissionEntry = PermissionEntryImpl.create(nodePermission, permissionReference, recipient, true); 178 179 Serializable idNodePermision = getSession().save(nodePermission); 180 getSession().save(recipient); 181 getSession().save(permissionReference); 182 Serializable idPermEnt = getSession().save(permissionEntry); 183 184 permissionEntry = (PermissionEntry) getSession().load(PermissionEntryImpl.class, idPermEnt); 185 assertNotNull("Permission entry not found", permissionEntry); 186 assertTrue(permissionEntry.isAllowed()); 187 assertNotNull(permissionEntry.getNodePermissionEntry()); 188 assertTrue(permissionEntry.getNodePermissionEntry().getInherits()); 189 assertNotNull(permissionEntry.getPermissionReference()); 190 assertEquals("Test", permissionEntry.getPermissionReference().getName()); 191 assertNotNull(permissionEntry.getRecipient()); 192 assertEquals("Test", permissionEntry.getRecipient().getRecipient()); 193 assertEquals(1, permissionEntry.getRecipient().getExternalKeys().size()); 194 195 197 nodePermission = (NodePermissionEntry) getSession().load(NodePermissionEntryImpl.class, idNodePermision); 198 assertEquals(1, nodePermission.getPermissionEntries().size()); 199 200 permissionEntry.delete(); 201 getSession().delete(permissionEntry); 202 203 nodePermission = (NodePermissionEntry) getSession().load(NodePermissionEntryImpl.class, idNodePermision); 204 assertEquals(0, nodePermission.getPermissionEntries().size()); 205 206 207 } 208 209 } | Popular Tags |