mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
move integration tests for audit Holds events from community to enterprise
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
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;
|
||||
@@ -41,14 +40,12 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -62,21 +59,12 @@ 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()
|
||||
*/
|
||||
@@ -173,7 +161,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()
|
||||
@@ -588,315 +576,6 @@ 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<QName, Serializable> 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<QName, Serializable> 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<QName, Serializable> 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<QName, Serializable> 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<RecordsManagementAuditEntry> 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<RecordsManagementAuditEntry> 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<RecordsManagementAuditEntry> getAuditTrail(String asUser)
|
||||
@@ -945,47 +624,6 @@ 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<RecordsManagementAuditEntry> 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<RecordsManagementAuditEntry> getAuditEntryAssertOnlyOne(RecordsManagementAuditQueryParameters params)
|
||||
{
|
||||
List<RecordsManagementAuditEntry> auditEntries;
|
||||
auditEntries = getAuditTrail(params, 1, ADMIN_USER);
|
||||
return auditEntries;
|
||||
}
|
||||
|
||||
private List<RecordsManagementAuditEntry> 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<RecordsManagementAuditEntry> auditEntries = getAllAuditEntries(params);
|
||||
|
||||
return auditEntries;
|
||||
}
|
||||
|
||||
private List<RecordsManagementAuditEntry> getAllAuditEntries(RecordsManagementAuditQueryParameters params)
|
||||
{
|
||||
List<RecordsManagementAuditEntry> auditEntries;
|
||||
auditEntries = getAuditTrail(params, -1, ADMIN_USER);
|
||||
return auditEntries;
|
||||
}
|
||||
|
||||
private RecordsManagementAuditQueryParameters createAuditQueryParameters(String auditEvent)
|
||||
{
|
||||
RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters();
|
||||
|
Reference in New Issue
Block a user