ACLEntryImpl entry5 = new ACLEntryImpl(new CompositeACLPermission(BasicACLPermission.CREATE,
BasicACLPermission.DELETE), IdentityFactory.createIdentity("Identity-5"));
ACLEntryImpl entry6 = new ACLEntryImpl(new CompositeACLPermission(BasicACLPermission.values()), IdentityFactory
.createIdentity("Identity-6"));
ACLImpl acl1 = null;
ACLImpl acl2 = null;
EntityTransaction transaction = this.entityManager.getTransaction();
transaction.begin();
try
{
acl1 = this.entityManager.merge(this.persistedACLs.get(0));
acl1.addEntry(entry4);
acl1.addEntry(entry5);
acl2 = this.entityManager.merge(this.persistedACLs.get(1));
acl2.addEntry(entry6);
acl2.removeEntry(this.persistedEntries.get(0));
transaction.commit();
}
catch (RuntimeException re)
{
re.printStackTrace();
transaction.rollback();
}
// add the new entries to the persisted entries collection.
this.persistedEntries.add(entry4);
this.persistedEntries.add(entry5);
this.persistedEntries.add(entry6);
// clear the entity manager's cache.
this.entityManager.clear();
// load the ACLs again and validate the changes.
ACLImpl loadedACL1 = this.entityManager.find(ACLImpl.class, acl1.getACLId());
assertNotNull("ACL1 could not be retrieved", loadedACL1);
assertEquals("Loaded ACL contains unexpected number of entries", 2, loadedACL1.getEntries().size());
assertTrue(loadedACL1.getEntries().contains(entry4));
assertTrue(loadedACL1.getEntries().contains(entry5));
ACLImpl loadedACL2 = this.entityManager.find(ACLImpl.class, acl2.getACLId());
assertNotNull("ACL2 could not be retrieved", loadedACL2);
assertEquals("Loaded AC2 contains unexpected number of entries", 3, loadedACL2.getEntries().size());
assertFalse(loadedACL2.getEntries().contains(this.persistedEntries.get(0)));
assertTrue(loadedACL2.getEntries().contains(this.persistedEntries.get(1)));
assertTrue(loadedACL2.getEntries().contains(this.persistedEntries.get(2)));
assertTrue(loadedACL2.getEntries().contains(entry6));
}