RM-2130 (Check classification after method execution, filtering results where appropriate)

- Fixed failing integration tests

+review RM-94

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/ENFORCE@107274 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2015-06-28 17:29:54 +00:00
parent c64b092294
commit 158eaecf16
2 changed files with 80 additions and 106 deletions

View File

@@ -24,80 +24,53 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeRMActionExecution; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeRMActionExecution;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnRMActionExecution; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnRMActionExecution;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction; import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.TestAction; import org.alfresco.module.org_alfresco_module_rm.test.util.TestAction;
import org.alfresco.module.org_alfresco_module_rm.test.util.TestAction2; import org.alfresco.module.org_alfresco_module_rm.test.util.TestAction2;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
/** /**
* Records management action service implementation test * Records management action service implementation test
* *
* @author Roy Wetherall * @author Roy Wetherall
*/ */
public class RecordsManagementActionServiceImplTest extends TestCase public class RecordsManagementActionServiceImplTest extends BaseRMTestCase
implements RecordsManagementModel, implements BeforeRMActionExecution,
BeforeRMActionExecution,
OnRMActionExecution OnRMActionExecution
{ {
private static final String[] CONFIG_LOCATIONS = new String[] {
"classpath:alfresco/application-context.xml",
"classpath:test-context.xml"};
private ApplicationContext ctx;
private ServiceRegistry serviceRegistry;
private TransactionService transactionService;
private RetryingTransactionHelper txnHelper; private RetryingTransactionHelper txnHelper;
private NodeService nodeService;
private RecordsManagementActionService rmActionService;
private PolicyComponent policyComponent;
private NodeRef nodeRef; private NodeRef nodeRef;
private List<NodeRef> nodeRefs; private List<NodeRef> nodeRefs;
private boolean beforeMarker; private boolean beforeMarker;
private boolean onMarker; private boolean onMarker;
private boolean inTest; private boolean inTest;
@Override @Override
protected void setUp() throws Exception protected void setUp() throws Exception
{ {
ctx = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS); super.setUp();
this.serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
this.transactionService = serviceRegistry.getTransactionService();
this.txnHelper = transactionService.getRetryingTransactionHelper(); this.txnHelper = transactionService.getRetryingTransactionHelper();
this.nodeService = serviceRegistry.getNodeService();
this.rmActionService = (RecordsManagementActionService)ctx.getBean("RecordsManagementActionService"); // Set the current security context as system
this.policyComponent = (PolicyComponent)ctx.getBean("policyComponent"); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Set the current security context as admin RetryingTransactionCallback<Void> setUpCallback = new RetryingTransactionCallback<Void>()
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
RetryingTransactionCallback<Void> setUpCallback = new RetryingTransactionCallback<Void>()
{ {
public Void execute() throws Throwable public Void execute() throws Throwable
{ {
@@ -128,17 +101,17 @@ public class RecordsManagementActionServiceImplTest extends TestCase
beforeMarker = false; beforeMarker = false;
onMarker = false; onMarker = false;
inTest = false; inTest = false;
} }
@Override @Override
protected void tearDown() protected void tearDown()
{ {
AuthenticationUtil.clearCurrentSecurityContext(); AuthenticationUtil.clearCurrentSecurityContext();
} }
public void testGetActions() public void testGetActions()
{ {
RetryingTransactionCallback<Void> testCallback = new RetryingTransactionCallback<Void>() RetryingTransactionCallback<Void> testCallback = new RetryingTransactionCallback<Void>()
{ {
public Void execute() throws Throwable public Void execute() throws Throwable
{ {
@@ -147,36 +120,36 @@ public class RecordsManagementActionServiceImplTest extends TestCase
} }
}; };
txnHelper.doInTransaction(testCallback); txnHelper.doInTransaction(testCallback);
} }
private void getActionsImpl() private void getActionsImpl()
{ {
List<RecordsManagementAction> result = this.rmActionService.getRecordsManagementActions(); List<RecordsManagementAction> result = this.rmActionService.getRecordsManagementActions();
assertNotNull(result); assertNotNull(result);
Map<String, RecordsManagementAction> resultMap = new HashMap<String, RecordsManagementAction>(8); Map<String, RecordsManagementAction> resultMap = new HashMap<String, RecordsManagementAction>(8);
for (RecordsManagementAction action : result)
{
resultMap.put(action.getName(), action);
}
assertTrue(resultMap.containsKey(TestAction.NAME));
assertTrue(resultMap.containsKey(TestAction2.NAME));
result = this.rmActionService.getDispositionActions();
resultMap = new HashMap<String, RecordsManagementAction>(8);
for (RecordsManagementAction action : result) for (RecordsManagementAction action : result)
{ {
resultMap.put(action.getName(), action); resultMap.put(action.getName(), action);
} }
assertTrue(resultMap.containsKey(TestAction.NAME));
assertFalse(resultMap.containsKey(TestAction2.NAME));
// get some specific actions and check the label assertTrue(resultMap.containsKey(TestAction.NAME));
RecordsManagementAction cutoff = this.rmActionService.getDispositionAction("cutoff"); assertTrue(resultMap.containsKey(TestAction2.NAME));
assertNotNull(cutoff);
assertEquals("Cut off", cutoff.getLabel());
RecordsManagementAction freeze = this.rmActionService.getRecordsManagementAction("freeze"); result = this.rmActionService.getDispositionActions();
resultMap = new HashMap<String, RecordsManagementAction>(8);
for (RecordsManagementAction action : result)
{
resultMap.put(action.getName(), action);
}
assertTrue(resultMap.containsKey(TestAction.NAME));
assertFalse(resultMap.containsKey(TestAction2.NAME));
// get some specific actions and check the label
RecordsManagementAction cutoff = this.rmActionService.getDispositionAction("cutoff");
assertNotNull(cutoff);
assertEquals("Cut off", cutoff.getLabel());
RecordsManagementAction freeze = this.rmActionService.getRecordsManagementAction("freeze");
assertNotNull(freeze); assertNotNull(freeze);
assertEquals("Freeze", freeze.getLabel()); assertEquals("Freeze", freeze.getLabel());
assertEquals("Freeze", freeze.getLabel()); assertEquals("Freeze", freeze.getLabel());
@@ -184,7 +157,7 @@ public class RecordsManagementActionServiceImplTest extends TestCase
// test non-existent actions // test non-existent actions
assertNull(this.rmActionService.getDispositionAction("notThere")); assertNull(this.rmActionService.getDispositionAction("notThere"));
assertNull(this.rmActionService.getRecordsManagementAction("notThere")); assertNull(this.rmActionService.getRecordsManagementAction("notThere"));
} }
public void testExecution() public void testExecution()
{ {
@@ -225,37 +198,37 @@ public class RecordsManagementActionServiceImplTest extends TestCase
} }
} }
private void executionImpl() private void executionImpl()
{ {
inTest = true; inTest = true;
try try
{ {
policyComponent.bindClassBehaviour( policyComponent.bindClassBehaviour(
RecordsManagementPolicies.BEFORE_RM_ACTION_EXECUTION, RecordsManagementPolicies.BEFORE_RM_ACTION_EXECUTION,
this, this,
new JavaBehaviour(this, "beforeRMActionExecution", NotificationFrequency.EVERY_EVENT)); new JavaBehaviour(this, "beforeRMActionExecution", NotificationFrequency.EVERY_EVENT));
policyComponent.bindClassBehaviour( policyComponent.bindClassBehaviour(
RecordsManagementPolicies.ON_RM_ACTION_EXECUTION, RecordsManagementPolicies.ON_RM_ACTION_EXECUTION,
this, this,
new JavaBehaviour(this, "onRMActionExecution", NotificationFrequency.EVERY_EVENT)); new JavaBehaviour(this, "onRMActionExecution", NotificationFrequency.EVERY_EVENT));
assertFalse(beforeMarker); assertFalse(beforeMarker);
assertFalse(onMarker); assertFalse(onMarker);
assertFalse(this.nodeService.hasAspect(this.nodeRef, ASPECT_RECORD)); assertFalse(this.nodeService.hasAspect(this.nodeRef, ASPECT_RECORD));
Map<String, Serializable> params = new HashMap<String, Serializable>(1); Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(TestAction.PARAM, TestAction.PARAM_VALUE); params.put(TestAction.PARAM, TestAction.PARAM_VALUE);
this.rmActionService.executeRecordsManagementAction(this.nodeRef, TestAction.NAME, params); this.rmActionService.executeRecordsManagementAction(this.nodeRef, TestAction.NAME, params);
assertTrue(beforeMarker); assertTrue(beforeMarker);
assertTrue(onMarker); assertTrue(onMarker);
assertTrue(this.nodeService.hasAspect(this.nodeRef, ASPECT_RECORD)); assertTrue(this.nodeService.hasAspect(this.nodeRef, ASPECT_RECORD));
} }
finally finally
{ {
inTest = false; inTest = false;
} }
} }
public void testBulkExecution() public void testBulkExecution()
{ {
@@ -270,20 +243,20 @@ public class RecordsManagementActionServiceImplTest extends TestCase
txnHelper.doInTransaction(testCallback); txnHelper.doInTransaction(testCallback);
} }
private void bulkExecutionImpl() private void bulkExecutionImpl()
{ {
for (NodeRef nodeRef : this.nodeRefs) for (NodeRef nodeRef : this.nodeRefs)
{ {
assertFalse(this.nodeService.hasAspect(nodeRef, ASPECT_RECORD)); assertFalse(this.nodeService.hasAspect(nodeRef, ASPECT_RECORD));
} }
Map<String, Serializable> params = new HashMap<String, Serializable>(1); Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(TestAction.PARAM, TestAction.PARAM_VALUE); params.put(TestAction.PARAM, TestAction.PARAM_VALUE);
this.rmActionService.executeRecordsManagementAction(this.nodeRefs, TestAction.NAME, params); this.rmActionService.executeRecordsManagementAction(this.nodeRefs, TestAction.NAME, params);
for (NodeRef nodeRef : this.nodeRefs) for (NodeRef nodeRef : this.nodeRefs)
{ {
assertTrue(this.nodeService.hasAspect(nodeRef, ASPECT_RECORD)); assertTrue(this.nodeService.hasAspect(nodeRef, ASPECT_RECORD));
} }
} }
} }

View File

@@ -47,7 +47,7 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase
private static final String SEARCH3 = "search3"; private static final String SEARCH3 = "search3";
private static final String SEARCH4 = "search4"; private static final String SEARCH4 = "search4";
private static final String USER1 = generate(); private String user;
private NodeRef folderLevelRecordFolder; private NodeRef folderLevelRecordFolder;
private NodeRef recordLevelRecordFolder; private NodeRef recordLevelRecordFolder;
@@ -72,7 +72,8 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase
assertNotNull(searches); assertNotNull(searches);
numberOfReports = searches.size(); numberOfReports = searches.size();
createPerson(USER1); user = generate();
createPerson(user);
return null; return null;
} }
@@ -163,7 +164,7 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase
return null; return null;
} }
}, USER1); }, user);
// Get searches (as admin user) // Get searches (as admin user)
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
@@ -222,7 +223,7 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase
return null; return null;
} }
}, USER1); }, user);
// Update search (as admin user) // Update search (as admin user)
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()