diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementActionServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementActionServiceImplTest.java index b87e6474ad..600fb85e64 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementActionServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementActionServiceImplTest.java @@ -24,80 +24,53 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - import org.alfresco.model.ContentModel; 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.OnRMActionExecution; 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.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; 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.repo.policy.JavaBehaviour; -import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; +import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper; 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.NodeService; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.namespace.NamespaceService; 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 * * @author Roy Wetherall */ -public class RecordsManagementActionServiceImplTest extends TestCase - implements RecordsManagementModel, - BeforeRMActionExecution, +public class RecordsManagementActionServiceImplTest extends BaseRMTestCase + implements BeforeRMActionExecution, 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 NodeService nodeService; - private RecordsManagementActionService rmActionService; - private PolicyComponent policyComponent; - private NodeRef nodeRef; - private List nodeRefs; + private NodeRef nodeRef; + private List nodeRefs; private boolean beforeMarker; private boolean onMarker; private boolean inTest; - @Override - protected void setUp() throws Exception - { - ctx = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS); + @Override + protected void setUp() throws Exception + { + super.setUp(); - this.serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); - this.transactionService = serviceRegistry.getTransactionService(); this.txnHelper = transactionService.getRetryingTransactionHelper(); - this.nodeService = serviceRegistry.getNodeService(); - this.rmActionService = (RecordsManagementActionService)ctx.getBean("RecordsManagementActionService"); - this.policyComponent = (PolicyComponent)ctx.getBean("policyComponent"); + // Set the current security context as system + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - // Set the current security context as admin - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - - RetryingTransactionCallback setUpCallback = new RetryingTransactionCallback() + RetryingTransactionCallback setUpCallback = new RetryingTransactionCallback() { public Void execute() throws Throwable { @@ -128,17 +101,17 @@ public class RecordsManagementActionServiceImplTest extends TestCase beforeMarker = false; onMarker = false; inTest = false; - } + } - @Override - protected void tearDown() - { + @Override + protected void tearDown() + { AuthenticationUtil.clearCurrentSecurityContext(); - } + } - public void testGetActions() - { - RetryingTransactionCallback testCallback = new RetryingTransactionCallback() + public void testGetActions() + { + RetryingTransactionCallback testCallback = new RetryingTransactionCallback() { public Void execute() throws Throwable { @@ -147,36 +120,36 @@ public class RecordsManagementActionServiceImplTest extends TestCase } }; txnHelper.doInTransaction(testCallback); - } + } - private void getActionsImpl() - { - List result = this.rmActionService.getRecordsManagementActions(); - assertNotNull(result); - Map resultMap = new HashMap(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(8); + private void getActionsImpl() + { + List result = this.rmActionService.getRecordsManagementActions(); + assertNotNull(result); + Map resultMap = new HashMap(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()); + assertTrue(resultMap.containsKey(TestAction.NAME)); + assertTrue(resultMap.containsKey(TestAction2.NAME)); - RecordsManagementAction freeze = this.rmActionService.getRecordsManagementAction("freeze"); + result = this.rmActionService.getDispositionActions(); + resultMap = new HashMap(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); assertEquals("Freeze", freeze.getLabel()); assertEquals("Freeze", freeze.getLabel()); @@ -184,7 +157,7 @@ public class RecordsManagementActionServiceImplTest extends TestCase // test non-existent actions assertNull(this.rmActionService.getDispositionAction("notThere")); assertNull(this.rmActionService.getRecordsManagementAction("notThere")); - } + } public void testExecution() { @@ -225,37 +198,37 @@ public class RecordsManagementActionServiceImplTest extends TestCase } } - private void executionImpl() - { - inTest = true; - try - { - policyComponent.bindClassBehaviour( - RecordsManagementPolicies.BEFORE_RM_ACTION_EXECUTION, - this, - new JavaBehaviour(this, "beforeRMActionExecution", NotificationFrequency.EVERY_EVENT)); - policyComponent.bindClassBehaviour( + private void executionImpl() + { + inTest = true; + try + { + policyComponent.bindClassBehaviour( + RecordsManagementPolicies.BEFORE_RM_ACTION_EXECUTION, + this, + new JavaBehaviour(this, "beforeRMActionExecution", NotificationFrequency.EVERY_EVENT)); + policyComponent.bindClassBehaviour( RecordsManagementPolicies.ON_RM_ACTION_EXECUTION, this, new JavaBehaviour(this, "onRMActionExecution", NotificationFrequency.EVERY_EVENT)); - assertFalse(beforeMarker); - assertFalse(onMarker); - assertFalse(this.nodeService.hasAspect(this.nodeRef, ASPECT_RECORD)); + assertFalse(beforeMarker); + assertFalse(onMarker); + assertFalse(this.nodeService.hasAspect(this.nodeRef, ASPECT_RECORD)); - Map params = new HashMap(1); - params.put(TestAction.PARAM, TestAction.PARAM_VALUE); - this.rmActionService.executeRecordsManagementAction(this.nodeRef, TestAction.NAME, params); + Map params = new HashMap(1); + params.put(TestAction.PARAM, TestAction.PARAM_VALUE); + this.rmActionService.executeRecordsManagementAction(this.nodeRef, TestAction.NAME, params); - assertTrue(beforeMarker); + assertTrue(beforeMarker); assertTrue(onMarker); assertTrue(this.nodeService.hasAspect(this.nodeRef, ASPECT_RECORD)); - } - finally - { - inTest = false; - } - } + } + finally + { + inTest = false; + } + } public void testBulkExecution() { @@ -270,20 +243,20 @@ public class RecordsManagementActionServiceImplTest extends TestCase txnHelper.doInTransaction(testCallback); } - private void bulkExecutionImpl() - { - for (NodeRef nodeRef : this.nodeRefs) + private void bulkExecutionImpl() + { + for (NodeRef nodeRef : this.nodeRefs) { - assertFalse(this.nodeService.hasAspect(nodeRef, ASPECT_RECORD)); + assertFalse(this.nodeService.hasAspect(nodeRef, ASPECT_RECORD)); } - Map params = new HashMap(1); + Map params = new HashMap(1); params.put(TestAction.PARAM, TestAction.PARAM_VALUE); 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)); } - } + } } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementSearchServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementSearchServiceImplTest.java index 0a7fb2272a..4cd6e709cf 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementSearchServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementSearchServiceImplTest.java @@ -47,7 +47,7 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase private static final String SEARCH3 = "search3"; private static final String SEARCH4 = "search4"; - private static final String USER1 = generate(); + private String user; private NodeRef folderLevelRecordFolder; private NodeRef recordLevelRecordFolder; @@ -72,7 +72,8 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase assertNotNull(searches); numberOfReports = searches.size(); - createPerson(USER1); + user = generate(); + createPerson(user); return null; } @@ -163,7 +164,7 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase return null; } - }, USER1); + }, user); // Get searches (as admin user) doTestInTransaction(new Test() @@ -222,7 +223,7 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase return null; } - }, USER1); + }, user); // Update search (as admin user) doTestInTransaction(new Test()