From 7caa5a74adbf5f3628aeb03e4a6562cc98e3670d Mon Sep 17 00:00:00 2001 From: cagache Date: Tue, 6 Apr 2021 12:33:59 +0300 Subject: [PATCH] Revert "move integration tests for audit Holds events from community to enterprise" This reverts commit 3e4f265e --- ...RecordsManagementAuditServiceImplTest.java | 364 +++++++++++++++++- 1 file changed, 363 insertions(+), 1 deletion(-) diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAuditServiceImplTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAuditServiceImplTest.java index 6c21cf9d4b..d7787236cb 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAuditServiceImplTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAuditServiceImplTest.java @@ -28,6 +28,7 @@ package org.alfresco.module.org_alfresco_module_rm.test.legacy.service; import java.io.Serializable; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -40,12 +41,14 @@ import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditQu import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditService; import org.alfresco.module.org_alfresco_module_rm.audit.event.AuditEvent; import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.repo.security.authentication.AuthenticationException; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; import org.alfresco.util.EqualsHelper; +import org.alfresco.util.GUID; import org.alfresco.util.Pair; /** @@ -59,12 +62,21 @@ import org.alfresco.util.Pair; public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase implements RMPermissionModel { + /** A QName to display for the hold name. */ + private static final QName HOLD_NAME = QName.createQName(RecordsManagementModel.RM_URI, "Hold Name"); + /** Test record */ private NodeRef record; /** Test start time */ private Date testStartTime; + /** + * Remove from hold audit event name. + */ + private static final String REMOVE_FROM_HOLD_AUDIT_EVENT = "Remove From Hold"; + + /** * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#setUp() */ @@ -161,7 +173,7 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase /** * Test getAuditTrail method to check that deleted items always show in the audit. - * + * * @see RM-2391 (last addressed isue) */ public void testGetAuditTrailForDeletedItem() @@ -576,6 +588,315 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase }); } + /** + * Given I have created a hold + * When I will get the RM audit filter by create hold event + * Then there will be an entry for the created hold, including the hold name and reason + */ + public void testAuditForCreateHold() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + final static String CREATE_HOLD_AUDIT_EVENT = "Create Hold"; + + String holdName = "Hold " + GUID.generate(); + String holdReason = "Reason " + GUID.generate(); + + Map auditEventProperties; + + @Override + public void given() + { + rmAuditService.clearAuditLog(filePlan); + utils.createHold(filePlan, holdName, holdReason); + } + + @Override + public void when() + { + auditEventProperties = getAuditEntry(CREATE_HOLD_AUDIT_EVENT).getAfterProperties(); + } + + @Override + public void then() + { + // check create hold audit event includes the hold name + assertEquals("Create Hold event does not include hold name.", holdName, + auditEventProperties.get(HOLD_NAME)); + + // check create hold audit event includes the hold reason + assertEquals("Create Hold event does not include hold reason.", holdReason, + auditEventProperties.get(PROP_HOLD_REASON)); + } + + @Override + public void after() + { + // Stop and delete all entries + rmAuditService.stopAuditLog(filePlan); + rmAuditService.clearAuditLog(filePlan); + } + }); + } + + /** + * Given I have created a hold + * When I delete the hold and get the RM audit filter by delete hold event + * Then there will be an entry for the deleted hold, including the hold name + */ + public void testAuditForDeleteHold() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + final static String DELETE_HOLD_AUDIT_EVENT = "Delete Hold"; + + String holdName = "Hold " + GUID.generate(); + + NodeRef hold; + Map auditEventProperties; + + @Override + public void given() + { + rmAuditService.clearAuditLog(filePlan); + hold = utils.createHold(filePlan, holdName, "Reason " + GUID.generate()); + } + + @Override + public void when() + { + utils.deleteHold(hold); + auditEventProperties = getAuditEntry(DELETE_HOLD_AUDIT_EVENT).getBeforeProperties(); + } + + @Override + public void then() + { + // check delete hold audit event includes the hold name + assertEquals("Delete Hold event does not include hold name.", holdName, + auditEventProperties.get(HOLD_NAME)); + } + + @Override + public void after() + { + // Stop and delete all entries + rmAuditService.stopAuditLog(filePlan); + rmAuditService.clearAuditLog(filePlan); + } + }); + } + + /** + * Given I have added an item of content to a hold + * When I get the RM audit filter by add to hold event + * Then there will be an entry for the item added to the hold, including both the item name and hold name + */ + public void testAuditForAddContentToHold() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + final static String ADD_TO_HOLD_AUDIT_EVENT = "Add To Hold"; + + String holdName = "Hold " + GUID.generate(); + NodeRef hold; + + Map auditEventProperties; + + @Override + public void given() + { + rmAuditService.clearAuditLog(filePlan); + hold = utils.createHold(filePlan, holdName, "Reason " + GUID.generate()); + utils.addItemToHold(hold, dmDocument); + } + + @Override + public void when() + { + auditEventProperties = getAuditEntry(ADD_TO_HOLD_AUDIT_EVENT).getAfterProperties(); + } + + @Override + public void then() + { + // check add to hold audit event includes the hold name + assertEquals("Add To Hold event does not include hold name.", holdName, + auditEventProperties.get(HOLD_NAME)); + + // check add to hold audit event includes the content name + String contentName = (String) nodeService.getProperty(dmDocument, PROP_NAME); + assertEquals("Add To Hold event does not include content name.", contentName, + auditEventProperties.get(PROP_NAME)); + } + + @Override + public void after() + { + // Stop and delete all entries + rmAuditService.stopAuditLog(filePlan); + rmAuditService.clearAuditLog(filePlan); + } + }); + } + + + /** + * Given I have an item in a hold + * When I remove the item from the hold + * Then there will be an audit entry for the item removed from the hold, including both the item name and hold name + */ + @org.junit.Test + public void testAuditForRemoveContentFromHold() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + String holdName = "Hold " + GUID.generate(); + NodeRef hold; + + @Override + public void given() + { + rmAuditService.clearAuditLog(filePlan); + hold = utils.createHold(filePlan, holdName, "Reason " + GUID.generate()); + utils.addItemToHold(hold, dmDocument); + } + + @Override + public void when() + { + utils.removeItemFromHold(hold, dmDocument); + } + + @Override + public void then() + { + Map auditEventProperties = getAuditEntry(REMOVE_FROM_HOLD_AUDIT_EVENT).getBeforeProperties(); + + // check remove from hold audit event includes the hold name + assertEquals("Remove From Hold event does not include hold name.", holdName, + auditEventProperties.get(HOLD_NAME)); + + // check remove from hold audit event includes the content name + String contentName = (String) nodeService.getProperty(dmDocument, PROP_NAME); + assertEquals("Remove From Hold event does not include content name.", contentName, + auditEventProperties.get(PROP_NAME)); + } + + @Override + public void after() + { + // Stop and delete all entries + rmAuditService.stopAuditLog(filePlan); + rmAuditService.clearAuditLog(filePlan); + } + }); + + } + + + /** + * Given I have removed an item from multiple holds + * When I will get the RM audit filter by remove from hold events + * Then there will be entries for the item removed from each hold, including both the item name and hold name + */ + @org.junit.Test + public void testAuditForRemoveContentFromMultipleHolds() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + String holdName1 = "Hold " + GUID.generate(); + String holdName2 = "Hold " + GUID.generate(); + NodeRef hold1, hold2; + + @Override + public void given() + { + rmAuditService.clearAuditLog(filePlan); + + hold1 = utils.createHold(filePlan, holdName1, "Reason " + GUID.generate()); + hold2 = utils.createHold(filePlan, holdName2, "Reason " + GUID.generate()); + utils.addItemToHold(hold1, dmDocument); + utils.addItemToHold(hold2, dmDocument); + } + + @Override + public void when() + { + utils.removeItemsFromHolds(Arrays.asList(hold1, hold2), Arrays.asList(dmDocument)); + } + + @Override + public void then() + { + List auditEntries = getAuditEntries(REMOVE_FROM_HOLD_AUDIT_EVENT); + + // check remove from hold audit event exists for both holds + assertEquals(2, auditEntries.size()); + } + + @Override + public void after() + { + // Stop and delete all entries + rmAuditService.stopAuditLog(filePlan); + rmAuditService.clearAuditLog(filePlan); + } + }); + + } + + + /** + * Given I have removed items from a hold + * When I will get the RM audit filter by remove from hold events + * Then there will be entries for the items removed from the hold, including both the item name and hold name + */ + @org.junit.Test + public void testAuditForRemoveMultipleContentFromHold() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + String holdName = "Hold " + GUID.generate(); + NodeRef hold; + + @Override + public void given() + { + rmAuditService.clearAuditLog(filePlan); + + hold = utils.createHold(filePlan, holdName, "Reason " + GUID.generate()); + utils.addItemToHold(hold, dmDocument); + utils.addItemToHold(hold, dmDocument1); + } + + @Override + public void when() + { + utils.removeItemsFromHolds(Arrays.asList(hold), Arrays.asList(dmDocument, dmDocument1)); + } + + @Override + public void then() + { + List auditEntries = getAuditEntries(REMOVE_FROM_HOLD_AUDIT_EVENT); + + // check remove from hold audit event exists for both documents + assertEquals(2, auditEntries.size()); + } + + @Override + public void after() + { + // Stop and delete all entries + rmAuditService.stopAuditLog(filePlan); + rmAuditService.clearAuditLog(filePlan); + } + }); + + } + + /** === Helper methods === */ private List getAuditTrail(String asUser) @@ -624,6 +945,47 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase }, asUser); } + private RecordsManagementAuditEntry getAuditEntry(String auditEvent) + { + // create the audit query parameters for the given event + RecordsManagementAuditQueryParameters params = createAuditQueryParameters(auditEvent); + + // get the audit entries for the given event + List auditEntries = getAuditEntryAssertOnlyOne(params); + + // verify we have the expected audit event + RecordsManagementAuditEntry auditEntry = auditEntries.get(0); + assertEquals(auditEvent + " event is not audited.", auditEvent, auditEntry.getEvent()); + + // return the properties of the audit event + return auditEntry; + } + + private List getAuditEntryAssertOnlyOne(RecordsManagementAuditQueryParameters params) + { + List auditEntries; + auditEntries = getAuditTrail(params, 1, ADMIN_USER); + return auditEntries; + } + + private List getAuditEntries(String auditEvent) + { + // create the audit query parameters for the given event + RecordsManagementAuditQueryParameters params = createAuditQueryParameters(auditEvent); + + // get the audit entries for the given event + List auditEntries = getAllAuditEntries(params); + + return auditEntries; + } + + private List getAllAuditEntries(RecordsManagementAuditQueryParameters params) + { + List auditEntries; + auditEntries = getAuditTrail(params, -1, ADMIN_USER); + return auditEntries; + } + private RecordsManagementAuditQueryParameters createAuditQueryParameters(String auditEvent) { RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters();