From e767ce187a0fa8fb262da5de3bb13312a06cf03f Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Thu, 12 Apr 2012 07:20:20 +0000 Subject: [PATCH] RM Unit Tests: * Removed web script tests dependancy on DOD test data * refactor base RM test and placed common utils in common class * base rm web script class created * unit tests refactored (still some work on the older tests required) * junit conflict resolved RM Bug Fixs: * user rights view working again * fix from Erik so RM admin console works git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@35190 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- rm-server/.classpath | 5 +- rm-server/build.gradle | 6 +- .../FileableCapabilityCondition.java | 3 +- ...OD5015Test.java => DOD5015SystemTest.java} | 56 +- .../capabilities/BaseCapabilitiesTest.java | 922 ------------------ .../test/capabilities/CapabilitiesTest.java | 38 +- .../DeclarativeCapabilityTest.java | 26 +- .../jscript/JSONConversionComponentTest.java | 2 +- .../test/jscript/RMJScriptTest.java | 15 +- .../service/DispositionServiceImplTest.java | 35 +- ...RecordsManagementAdminServiceImplTest.java | 16 +- ...ecordsManagementSearchServiceImplTest.java | 12 +- .../RecordsManagementServiceImplTest.java | 2 +- .../service/VitalRecordServiceImplTest.java | 10 +- .../test/system/DODDataLoadSystemTest.java | 78 -- .../NotificationServiceHelperSystemTest.java | 6 +- ...ecordsManagementServiceImplSystemTest.java | 16 +- .../test/util/BaseRMTestCase.java | 164 +--- .../test/util/BaseRMWebScriptTestCase.java | 236 +++++ .../test/util/CommonRMTestUtils.java | 202 ++++ .../test/util/TestUtilities.java | 123 +-- .../BootstraptestDataRestApiTest.java | 3 +- .../webscript/DispositionRestApiTest.java | 251 +---- .../test/webscript/EmailMapScriptTest.java | 4 +- .../test/webscript/EventRestApiTest.java | 58 +- .../webscript/RMCaveatConfigScriptTest.java | 25 +- .../webscript/RMConstraintScriptTest.java | 43 +- .../test/webscript/RmRestApiTest.java | 527 ++-------- .../test/webscript/RoleRestApiTest.java | 74 +- 29 files changed, 784 insertions(+), 2174 deletions(-) rename rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/{DOD5015Test.java => DOD5015SystemTest.java} (97%) delete mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/BaseCapabilitiesTest.java delete mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/DODDataLoadSystemTest.java create mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMWebScriptTestCase.java create mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java diff --git a/rm-server/.classpath b/rm-server/.classpath index dce9320965..10f3e73b1d 100644 --- a/rm-server/.classpath +++ b/rm-server/.classpath @@ -9,7 +9,6 @@ - @@ -26,8 +25,8 @@ - - + + diff --git a/rm-server/build.gradle b/rm-server/build.gradle index 708db68c1d..75520e3ae5 100644 --- a/rm-server/build.gradle +++ b/rm-server/build.gradle @@ -20,7 +20,7 @@ test { beforeTest { descriptor -> logger.lifecycle("Running test: " + descriptor) } - onOutput { descriptor, event -> - logger.lifecycle(event.message) - } + //onOutput { descriptor, event -> + // logger.lifecycle(event.message) + //} } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/declarative/condition/FileableCapabilityCondition.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/declarative/condition/FileableCapabilityCondition.java index 1b52f2d838..942d73c8eb 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/declarative/condition/FileableCapabilityCondition.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/declarative/condition/FileableCapabilityCondition.java @@ -49,7 +49,8 @@ public class FileableCapabilityCondition extends AbstractCapabilityCondition @Override public boolean evaluate(NodeRef nodeRef) { - QName type = nodeService.getType(nodeRef); + QName type = nodeService.getType(nodeRef); + // TODO and not already a record? return (dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT) || dictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)); } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/DOD5015Test.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/DOD5015SystemTest.java similarity index 97% rename from rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/DOD5015Test.java rename to rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/DOD5015SystemTest.java index d32ee96e76..0c406b31e0 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/DOD5015Test.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/DOD5015SystemTest.java @@ -100,7 +100,7 @@ import org.alfresco.util.PropertyMap; * * @author Roy Wetherall, Neil McErlean */ -public class DOD5015Test extends BaseSpringTest implements RecordsManagementModel, DOD5015Model +public class DOD5015SystemTest extends BaseSpringTest implements RecordsManagementModel, DOD5015Model { private static final Period weeklyReview = new Period("week|1"); private static final Period dailyReview = new Period("day|1"); @@ -222,7 +222,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void xtestTestData() throws Exception { // make sure the folders that should have disposition schedules do so - NodeRef janAuditRecordsFolder = TestUtilities.getRecordFolder(searchService, "Reports", "AIS Audit Records", "January AIS Audit Records"); + NodeRef janAuditRecordsFolder = TestUtilities.getRecordFolder(rmService, nodeService, "Reports", "AIS Audit Records", "January AIS Audit Records"); assertNotNull(janAuditRecordsFolder); // ensure the folder has the disposition lifecycle aspect @@ -233,7 +233,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode checkSearchAspect(janAuditRecordsFolder); // check another folder that has events as part of the disposition schedule - NodeRef equalOppCoordFolder = TestUtilities.getRecordFolder(searchService, "Military Files", "Personnel Security Program Records", "Equal Opportunity Coordinator"); + NodeRef equalOppCoordFolder = TestUtilities.getRecordFolder(rmService, nodeService, "Military Files", "Personnel Security Program Records", "Equal Opportunity Coordinator"); assertNotNull(equalOppCoordFolder); assertTrue("Expected 'Equal Opportunity Coordinator' folder to have disposition lifecycle aspect applied", nodeService.hasAspect(equalOppCoordFolder, ASPECT_DISPOSITION_LIFECYCLE)); @@ -260,7 +260,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public NodeRef execute() throws Throwable { // Create a record folder under a "non-vital" category - NodeRef nonVitalRecordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "Unit Manning Documents"); + NodeRef nonVitalRecordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "Unit Manning Documents"); assertNotNull(nonVitalRecordCategory); return createRecFolderNode(nonVitalRecordCategory); @@ -314,7 +314,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode // Create another folder with different vital/disposition instructions //TODO Change disposition instructions - NodeRef vitalRecordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); + NodeRef vitalRecordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); assertNotNull(vitalRecordCategory); return createRecFolderNode(vitalRecordCategory); } @@ -494,7 +494,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testDispositionLifecycle_0318_01_basictest() throws Exception { - final NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); + final NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); setComplete(); endTransaction(); @@ -765,7 +765,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode */ public void testDispositionLifecycle_0318_reschedule_folderlevel() throws Exception { - final NodeRef recordSeries = TestUtilities.getRecordSeries(searchService, "Reports"); + final NodeRef recordSeries = TestUtilities.getRecordSeries(rmService, nodeService, "Reports"); setComplete(); endTransaction(); @@ -1076,7 +1076,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode */ public void testDispositionLifecycle_0318_reschedule_recordlevel() throws Exception { - final NodeRef recordSeries = TestUtilities.getRecordSeries(searchService, "Reports"); + final NodeRef recordSeries = TestUtilities.getRecordSeries(rmService, nodeService, "Reports"); setComplete(); endTransaction(); @@ -1512,7 +1512,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode */ public void testDispositionLifecycle_0318_reschedule_deletion_folderlevel() throws Exception { - final NodeRef recordSeries = TestUtilities.getRecordSeries(searchService, "Reports"); + final NodeRef recordSeries = TestUtilities.getRecordSeries(rmService, nodeService, "Reports"); setComplete(); endTransaction(); @@ -1836,7 +1836,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode */ public void testDispositionLifecycle_0318_reschedule_deletion_recordlevel() throws Exception { - final NodeRef recordSeries = TestUtilities.getRecordSeries(searchService, "Reports"); + final NodeRef recordSeries = TestUtilities.getRecordSeries(rmService, nodeService, "Reports"); setComplete(); endTransaction(); @@ -2014,7 +2014,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode */ public void testDispositionLifecycle_0318_existingfolders() throws Exception { - final NodeRef recordSeries = TestUtilities.getRecordSeries(searchService, "Reports"); + final NodeRef recordSeries = TestUtilities.getRecordSeries(rmService, nodeService, "Reports"); setComplete(); endTransaction(); @@ -2114,7 +2114,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode */ public void testFolderLevelDispositionScheduleUpdate() throws Exception { - final NodeRef recordSeries = TestUtilities.getRecordSeries(searchService, "Reports"); + final NodeRef recordSeries = TestUtilities.getRecordSeries(rmService, nodeService, "Reports"); setComplete(); endTransaction(); @@ -2193,7 +2193,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode */ public void testRecordLevelDispositionScheduleUpdate() throws Exception { - final NodeRef recordSeries = TestUtilities.getRecordSeries(searchService, "Reports"); + final NodeRef recordSeries = TestUtilities.getRecordSeries(rmService, nodeService, "Reports"); setComplete(); endTransaction(); @@ -2295,7 +2295,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testUnCutoff() { - final NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); + final NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); setComplete(); endTransaction(); @@ -2400,7 +2400,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testFreeze() throws Exception { - final NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Reports", "AIS Audit Records"); + final NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); assertNotNull(recordCategory); assertEquals("AIS Audit Records", this.nodeService.getProperty(recordCategory, ContentModel.PROP_NAME)); @@ -2711,7 +2711,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testAutoSuperseded() { - final NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Civilian Files", "Employee Performance File System Records"); + final NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Civilian Files", "Employee Performance File System Records"); assertNotNull(recordCategory); assertEquals("Employee Performance File System Records", this.nodeService.getProperty(recordCategory, ContentModel.PROP_NAME)); @@ -2804,7 +2804,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testVersioned() { - final NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Civilian Files", "Employee Performance File System Records"); + final NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Civilian Files", "Employee Performance File System Records"); assertNotNull(recordCategory); assertEquals("Employee Performance File System Records", this.nodeService.getProperty(recordCategory, ContentModel.PROP_NAME)); @@ -2878,7 +2878,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testDispositionLifecycle_0430_02_transfer() throws Exception { - final NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Civilian Files", "Foreign Employee Award Files"); + final NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Civilian Files", "Foreign Employee Award Files"); assertNotNull(recordCategory); assertEquals("Foreign Employee Award Files", this.nodeService.getProperty(recordCategory, ContentModel.PROP_NAME)); @@ -3129,7 +3129,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testDispositionLifecycle_0430_01_recordleveldisposition() throws Exception { - NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Civilian Files", "Employee Performance File System Records"); + NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Civilian Files", "Employee Performance File System Records"); assertNotNull(recordCategory); assertEquals("Employee Performance File System Records", this.nodeService.getProperty(recordCategory, ContentModel.PROP_NAME)); @@ -3225,7 +3225,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testDispositionLifecycle_0412_03_eventtest() throws Exception { - NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Military Files", "Personnel Security Program Records"); + NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Military Files", "Personnel Security Program Records"); assertNotNull(recordCategory); assertEquals("Personnel Security Program Records", this.nodeService.getProperty(recordCategory, ContentModel.PROP_NAME)); @@ -3421,7 +3421,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode */ public void testFileDOD5015CustomTypes() throws Exception { - NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Reports", "AIS Audit Records"); + NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); NodeRef recordFolder = createRecordFolder(recordCategory, "March AIS Audit Records"); setComplete(); @@ -3458,7 +3458,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testFileDOD5015CustomTypes2() throws Exception { - NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Reports", "AIS Audit Records"); + NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); NodeRef recordFolder = createRecordFolder(recordCategory, "March AIS Audit Records"); setComplete(); @@ -3494,7 +3494,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public void testFileFromDoclib() throws Exception { // Get the relevant RecordCategory and create a RecordFolder underneath it. - NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Reports", "AIS Audit Records"); + NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); NodeRef recordFolder = createRecordFolder(recordCategory, "March AIS Audit Records"); setComplete(); @@ -3565,7 +3565,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode public NodeRef execute() throws Throwable { // Get the relevant RecordCategory and create a RecordFolder underneath it. - NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); + NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); NodeRef result = createRecordFolder(recordCategory, "March AIS Audit Records" + System.currentTimeMillis()); return result; @@ -3717,7 +3717,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode // Create record category / record folder - final NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); + final NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); assertNotNull(recordCategory); assertEquals("AIS Audit Records", nodeService.getProperty(recordCategory, ContentModel.PROP_NAME)); @@ -4272,7 +4272,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode */ public void testETHREEOH3587() { - NodeRef recordFolder = TestUtilities.getRecordFolder(searchService, "Reports", "AIS Audit Records", "January AIS Audit Records"); + NodeRef recordFolder = TestUtilities.getRecordFolder(rmService, nodeService, "Reports", "AIS Audit Records", "January AIS Audit Records"); assertNotNull(recordFolder); // Create a record @@ -4323,7 +4323,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode // TODO Don't think I need to do this. Can I reuse the existing January one? NodeRef vitalRecCategory = - TestUtilities.getRecordCategory(this.searchService, "Reports", "AIS Audit Records"); + TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); assertNotNull(vitalRecCategory); assertEquals("AIS Audit Records", @@ -4389,7 +4389,7 @@ public class DOD5015Test extends BaseSpringTest implements RecordsManagementMode // // Create a record folder under a "non-vital" category // - NodeRef nonVitalRecordCategory = TestUtilities.getRecordCategory(this.searchService, "Reports", "Unit Manning Documents"); + NodeRef nonVitalRecordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "Unit Manning Documents"); assertNotNull(nonVitalRecordCategory); assertEquals("Unit Manning Documents", this.nodeService.getProperty(nonVitalRecordCategory, ContentModel.PROP_NAME)); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/BaseCapabilitiesTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/BaseCapabilitiesTest.java deleted file mode 100644 index 7c429e4b58..0000000000 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/BaseCapabilitiesTest.java +++ /dev/null @@ -1,922 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.module.org_alfresco_module_rm.test.capabilities; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.transaction.UserTransaction; - -import junit.framework.TestCase; - -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; -import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; -import org.alfresco.module.org_alfresco_module_rm.capability.Capability; -import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService; -import org.alfresco.module.org_alfresco_module_rm.capability.RMEntryVoter; -import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; -import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventService; -import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; -import org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService; -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.repo.security.permissions.AccessDeniedException; -import org.alfresco.repo.security.permissions.PermissionReference; -import org.alfresco.repo.security.permissions.impl.model.PermissionModel; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.ContentWriter; -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.security.AccessStatus; -import org.alfresco.service.cmr.security.AuthorityService; -import org.alfresco.service.cmr.security.AuthorityType; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.security.PersonService; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.namespace.RegexQNamePattern; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.util.ApplicationContextHelper; -import org.springframework.context.ApplicationContext; - -/** - * @author Roy Wetherall - */ -public abstract class BaseCapabilitiesTest extends TestCase - implements RMPermissionModel, RecordsManagementModel -{ - /* Application context */ - protected ApplicationContext ctx; - - /* Root node reference */ - protected StoreRef storeRef; - protected NodeRef rootNodeRef; - - /* Services */ - protected NodeService nodeService; - protected NodeService publicNodeService; - protected TransactionService transactionService; - protected PermissionService permissionService; - protected RecordsManagementService recordsManagementService; - protected RecordsManagementSecurityService recordsManagementSecurityService; - protected RecordsManagementActionService recordsManagementActionService; - protected RecordsManagementEventService recordsManagementEventService; - protected PermissionModel permissionModel; - protected ContentService contentService; - protected AuthorityService authorityService; - protected PersonService personService; - protected ContentService publicContentService; - protected RetryingTransactionHelper retryingTransactionHelper; - protected CapabilityService capabilityService; - - protected RMEntryVoter rmEntryVoter; - - protected UserTransaction testTX; - - protected NodeRef filePlan; - protected NodeRef recordSeries; - protected NodeRef recordCategory_1; - protected NodeRef recordCategory_2; - protected NodeRef recordFolder_1; - protected NodeRef recordFolder_2; - protected NodeRef record_1; - protected NodeRef record_2; - protected NodeRef recordCategory_3; - protected NodeRef recordFolder_3; - protected NodeRef record_3; - - protected String rmUsers; - protected String rmPowerUsers; - protected String rmSecurityOfficers; - protected String rmRecordsManagers; - protected String rmAdministrators; - - protected String rm_user; - protected String rm_power_user; - protected String rm_security_officer; - protected String rm_records_manager; - protected String rm_administrator; - protected String test_user; - - protected String testers; - - protected String[] stdUsers; - protected NodeRef[] stdNodeRefs;; - - /** - * Test setup - * @throws Exception - */ - protected void setUp() throws Exception - { - // Get the application context - ctx = ApplicationContextHelper.getApplicationContext(); - - // Get beans - nodeService = (NodeService) ctx.getBean("dbNodeService"); - publicNodeService = (NodeService) ctx.getBean("NodeService"); - transactionService = (TransactionService) ctx.getBean("transactionComponent"); - permissionService = (PermissionService) ctx.getBean("permissionService"); - permissionModel = (PermissionModel) ctx.getBean("permissionsModelDAO"); - contentService = (ContentService) ctx.getBean("contentService"); - publicContentService = (ContentService) ctx.getBean("ContentService"); - authorityService = (AuthorityService) ctx.getBean("authorityService"); - personService = (PersonService) ctx.getBean("personService"); - recordsManagementService = (RecordsManagementService) ctx.getBean("RecordsManagementService"); - recordsManagementSecurityService = (RecordsManagementSecurityService) ctx.getBean("RecordsManagementSecurityService"); - recordsManagementActionService = (RecordsManagementActionService) ctx.getBean("RecordsManagementActionService"); - recordsManagementEventService = (RecordsManagementEventService) ctx.getBean("RecordsManagementEventService"); - rmEntryVoter = (RMEntryVoter) ctx.getBean("rmEntryVoter"); - retryingTransactionHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper"); - capabilityService = (CapabilityService)ctx.getBean("capabilityService"); - - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - // As system user - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - - // Create store and get the root node reference - storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); - rootNodeRef = nodeService.getRootNode(storeRef); - - // As admin user - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - - // Create test events - recordsManagementEventService.getEvents(); - recordsManagementEventService.addEvent("rmEventType.simple", "event", "My Event"); - - // Create file plan node - filePlan = nodeService.createNode( - rootNodeRef, - ContentModel.ASSOC_CHILDREN, - TYPE_FILE_PLAN, - TYPE_FILE_PLAN).getChildRef(); - - return null; - } - }, false, true); - - - // Load in the plan data required for the test - loadFilePlanData(); - - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - // As system user - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - - // create people ... - rm_user = "rm_user_" + storeRef.getIdentifier(); - rm_power_user = "rm_power_user_" + storeRef.getIdentifier(); - rm_security_officer = "rm_security_officer_" + storeRef.getIdentifier(); - rm_records_manager = "rm_records_manager_" + storeRef.getIdentifier(); - rm_administrator = "rm_administrator_" + storeRef.getIdentifier(); - test_user = "test_user_" + storeRef.getIdentifier(); - - personService.createPerson(createDefaultProperties(rm_user)); - personService.createPerson(createDefaultProperties(rm_power_user)); - personService.createPerson(createDefaultProperties(rm_security_officer)); - personService.createPerson(createDefaultProperties(rm_records_manager)); - personService.createPerson(createDefaultProperties(rm_administrator)); - personService.createPerson(createDefaultProperties(test_user)); - - // create roles as groups - rmUsers = authorityService.createAuthority(AuthorityType.GROUP, "RM_USER_" + storeRef.getIdentifier()); - rmPowerUsers = authorityService.createAuthority(AuthorityType.GROUP, "RM_POWER_USER_" + storeRef.getIdentifier()); - rmSecurityOfficers = authorityService.createAuthority(AuthorityType.GROUP, "RM_SECURITY_OFFICER_" + storeRef.getIdentifier()); - rmRecordsManagers = authorityService.createAuthority(AuthorityType.GROUP, "RM_RECORDS_MANAGER_" + storeRef.getIdentifier()); - rmAdministrators = authorityService.createAuthority(AuthorityType.GROUP, "RM_ADMINISTRATOR_" + storeRef.getIdentifier()); - testers = authorityService.createAuthority(AuthorityType.GROUP, "RM_TESTOR_" + storeRef.getIdentifier()); - - authorityService.addAuthority(testers, test_user); - - setPermissions(rmUsers, rm_user, ROLE_USER); - setPermissions(rmPowerUsers, rm_power_user, ROLE_POWER_USER); - setPermissions(rmSecurityOfficers, rm_security_officer, ROLE_SECURITY_OFFICER); - setPermissions(rmRecordsManagers, rm_records_manager, ROLE_RECORDS_MANAGER); - setPermissions(rmAdministrators, rm_administrator, ROLE_ADMINISTRATOR); - - stdUsers = new String[] - { - AuthenticationUtil.getSystemUserName(), - rm_administrator, - rm_records_manager, - rm_security_officer, - rm_power_user, - rm_user - }; - - stdNodeRefs = new NodeRef[] - { - recordFolder_1, - record_1, - recordFolder_2, - record_2 - }; - - return null; - } - }, false, true); - } - - /** - * Test tear down - * @throws Exception - */ - @Override - protected void tearDown() throws Exception - { - // TODO we should clean up as much as we can .... - } - - /** - * Set the permissions for a group, user and role - * @param group - * @param user - * @param role - */ - private void setPermissions(String group, String user, String role) - { - for (PermissionReference pr : permissionModel.getImmediateGranteePermissions(permissionModel.getPermissionReference(null, role))) - { - setPermission(filePlan, group, pr.getName(), true); - } - authorityService.addAuthority(group, user); - setPermission(filePlan, user, FILING, true); - } - - /** - * Loads the file plan date required for the tests - */ - protected void loadFilePlanData() - { - recordSeries = createRecordSeries(filePlan, "RS", "RS-1", "Record Series", "My record series"); - - recordCategory_1 = createRecordCategory(recordSeries, "Docs", "101-1", "Docs", "Docs", "week|1", true, false); - recordCategory_2 = createRecordCategory(recordSeries, "More Docs", "101-2", "More Docs", "More Docs", "week|1", true, true); - recordCategory_3 = createRecordCategory(recordSeries, "No disp schedule", "101-3", "No disp schedule", "No disp schedule", "week|1", true, null); - - recordFolder_1 = createRecordFolder(recordCategory_1, "F1", "101-3", "title", "description", "week|1", true); - recordFolder_2 = createRecordFolder(recordCategory_2, "F2", "102-3", "title", "description", "week|1", true); - recordFolder_3 = createRecordFolder(recordCategory_3, "F3", "103-3", "title", "description", "week|1", true); - - record_1 = createRecord(recordFolder_1); - record_2 = createRecord(recordFolder_2); - record_3 = createRecord(recordFolder_3); - } - - /** - * Set permission for authority on node reference. - * @param nodeRef - * @param authority - * @param permission - * @param allow - */ - private void setPermission(NodeRef nodeRef, String authority, String permission, boolean allow) - { - permissionService.setPermission(nodeRef, authority, permission, allow); - if (permission.equals(FILING)) - { - if (recordsManagementService.isRecordCategory(nodeRef) == true) - { - List assocs = nodeService.getChildAssocs(nodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); - for (ChildAssociationRef assoc : assocs) - { - NodeRef child = assoc.getChildRef(); - if (recordsManagementService.isRecordFolder(child) == true || - recordsManagementService.isRecordCategory(child) == true) - { - setPermission(child, authority, permission, allow); - } - } - } - } - } - - /** - * Create the default person properties - * @param userName - * @return - */ - private Map createDefaultProperties(String userName) - { - HashMap properties = new HashMap(); - properties.put(ContentModel.PROP_USERNAME, userName); - properties.put(ContentModel.PROP_HOMEFOLDER, null); - properties.put(ContentModel.PROP_FIRSTNAME, userName); - properties.put(ContentModel.PROP_LASTNAME, userName); - properties.put(ContentModel.PROP_EMAIL, userName); - properties.put(ContentModel.PROP_ORGID, ""); - return properties; - } - - /** - * Create a new record. Executed in a new transaction. - */ - private NodeRef createRecord(final NodeRef recordFolder) - { - return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public NodeRef execute() throws Throwable - { - // As admin - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - - // Create the record - Map props = new HashMap(1); - props.put(ContentModel.PROP_NAME, "MyRecord.txt"); - NodeRef recordOne = nodeService.createNode(recordFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "MyRecord.txt"), - ContentModel.TYPE_CONTENT, props).getChildRef(); - - // Set the content - ContentWriter writer = contentService.getWriter(recordOne, ContentModel.PROP_CONTENT, true); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer.setEncoding("UTF-8"); - writer.putContent("There is some content in this record"); - return recordOne; - } - }, false, true); - } - - /** - * Create a test record series. Executed in a new transaction. - */ - private NodeRef createRecordSeries(final NodeRef filePlan, final String name, final String identifier, final String title, final String description) - { - return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public NodeRef execute() throws Throwable - { - // As admin - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - - HashMap properties = new HashMap(); - properties.put(ContentModel.PROP_NAME, name); - properties.put(PROP_IDENTIFIER, identifier); - properties.put(ContentModel.PROP_TITLE, title); - properties.put(ContentModel.PROP_DESCRIPTION, description); - - NodeRef recordSeried = nodeService.createNode(filePlan, ContentModel.ASSOC_CONTAINS, TYPE_RECORD_CATEGORY, TYPE_RECORD_CATEGORY, properties).getChildRef(); - permissionService.setInheritParentPermissions(recordSeried, false); - - return recordSeried; - } - }, false, true); - } - - /** - * Create a test record category in a new transaction. - */ - private NodeRef createRecordCategory( - final NodeRef recordSeries, - final String name, - final String identifier, - final String title, - final String description, - final String review, - final boolean vital, - final Boolean recordLevelDisposition) - { - return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public NodeRef execute() throws Throwable - { - // As admin - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - - HashMap properties = new HashMap(); - properties.put(ContentModel.PROP_NAME, name); - properties.put(PROP_IDENTIFIER, identifier); - properties.put(ContentModel.PROP_TITLE, title); - properties.put(ContentModel.PROP_DESCRIPTION, description); - properties.put(PROP_REVIEW_PERIOD, review); - properties.put(PROP_VITAL_RECORD_INDICATOR, vital); - - NodeRef answer = nodeService.createNode(recordSeries, ContentModel.ASSOC_CONTAINS, TYPE_RECORD_CATEGORY, TYPE_RECORD_CATEGORY, properties) - .getChildRef(); - - if (recordLevelDisposition != null) - { - properties = new HashMap(); - properties.put(PROP_DISPOSITION_AUTHORITY, "N1-218-00-4 item 023"); - properties.put(PROP_DISPOSITION_INSTRUCTIONS, "Cut off monthly, hold 1 month, then destroy."); - properties.put(PROP_RECORD_LEVEL_DISPOSITION, recordLevelDisposition); - NodeRef ds = nodeService.createNode(answer, ASSOC_DISPOSITION_SCHEDULE, TYPE_DISPOSITION_SCHEDULE, TYPE_DISPOSITION_SCHEDULE, - properties).getChildRef(); - - createDispoistionAction(ds, "cutoff", "monthend|1", null, "event"); - createDispoistionAction(ds, "transfer", "month|1", null, null); - createDispoistionAction(ds, "accession", "month|1", null, null); - createDispoistionAction(ds, "destroy", "month|1", "{http://www.alfresco.org/model/recordsmanagement/1.0}cutOffDate", null); - } - - permissionService.setInheritParentPermissions(answer, false); - - return answer; - } - }, false, true); - } - - /** - * Create disposition action. - * @param disposition - * @param actionName - * @param period - * @param periodProperty - * @param event - * @return - */ - private NodeRef createDispoistionAction(NodeRef disposition, String actionName, String period, String periodProperty, String event) - { - HashMap properties = new HashMap(); - properties.put(PROP_DISPOSITION_ACTION_NAME, actionName); - properties.put(PROP_DISPOSITION_PERIOD, period); - if (periodProperty != null) - { - properties.put(PROP_DISPOSITION_PERIOD_PROPERTY, periodProperty); - } - if (event != null) - { - properties.put(PROP_DISPOSITION_EVENT, event); - } - NodeRef answer = nodeService.createNode(disposition, ASSOC_DISPOSITION_ACTION_DEFINITIONS, TYPE_DISPOSITION_ACTION_DEFINITION, - TYPE_DISPOSITION_ACTION_DEFINITION, properties).getChildRef(); - return answer; - } - - /** - * Create record folder. Executed in a new transaction. - * @param recordCategory - * @param name - * @param identifier - * @param title - * @param description - * @param review - * @param vital - * @return - */ - private NodeRef createRecordFolder( - final NodeRef recordCategory, - final String name, - final String identifier, - final String title, - final String description, - final String review, - final boolean vital) - { - return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public NodeRef execute() throws Throwable - { - // As admin - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - - HashMap properties = new HashMap(); - properties.put(ContentModel.PROP_NAME, name); - properties.put(PROP_IDENTIFIER, identifier); - properties.put(ContentModel.PROP_TITLE, title); - properties.put(ContentModel.PROP_DESCRIPTION, description); - properties.put(PROP_REVIEW_PERIOD, review); - properties.put(PROP_VITAL_RECORD_INDICATOR, vital); - NodeRef answer = nodeService.createNode(recordCategory, ContentModel.ASSOC_CONTAINS, TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER, properties) - .getChildRef(); - permissionService.setInheritParentPermissions(answer, false); - return answer; - } - }, false, true); - } - - /** - * - * @param user - * @param nodeRef - * @param capabilityName - * @param accessStstus - */ - protected void checkCapability(final String user, final NodeRef nodeRef, final String capabilityName, final AccessStatus expected) - { - AuthenticationUtil.runAs(new RunAsWork() - { - @Override - public Object doWork() throws Exception - { - Capability capability = recordsManagementSecurityService.getCapability(capabilityName); - assertNotNull(capability); - - List capabilities = new ArrayList(1); - capabilities.add(capabilityName); - Map access = capabilityService.getCapabilitiesAccessState(nodeRef, capabilities); - - AccessStatus actual = access.get(capability); - - assertEquals( - "for user: " + user, - expected, - actual); - - return null; - } - }, user); - } - - /** - * - * @param access - * @param name - * @param accessStatus - */ - protected void check(Map access, String name, AccessStatus accessStatus) - { - Capability capability = recordsManagementSecurityService.getCapability(name); - assertNotNull(capability); - assertEquals(accessStatus, access.get(capability)); - } - - /** - * - * @param user - * @param nodeRef - * @param permission - * @param accessStstus - */ - protected void checkPermission(final String user, final NodeRef nodeRef, final String permission, final AccessStatus accessStstus) - { - AuthenticationUtil.runAs(new RunAsWork() - { - @Override - public Object doWork() throws Exception - { - AccessStatus actualAccessStatus = permissionService.hasPermission(nodeRef, permission); - assertTrue(actualAccessStatus == accessStstus); - return null; - } - }, user); - } - - /** - * - * @param nodeRef - * @param permission - * @param users - * @param expectedAccessStatus - */ - protected void checkPermissions( - final NodeRef nodeRef, - final String permission, - final String[] users, - final AccessStatus ... expectedAccessStatus) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - assertEquals( - "The number of users should match the number of expected access status", - users.length, - expectedAccessStatus.length); - - for (int i = 0; i < users.length; i++) - { - checkPermission(users[i], nodeRef, permission, expectedAccessStatus[i]); - } - - return null; - } - }, true, true); - } - - /** - * - * @param nodeRef - * @param capability - * @param users - * @param expectedAccessStatus - */ - protected void checkCapabilities( - final NodeRef nodeRef, - final String capability, - final String[] users, - final AccessStatus ... expectedAccessStatus) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - assertEquals( - "The number of users should match the number of expected access status", - users.length, - expectedAccessStatus.length); - - for (int i = 0; i < users.length; i++) - { - checkCapability(users[i], nodeRef, capability, expectedAccessStatus[i]); - } - - return null; - } - }, true, true); - } - - /** - * - * @param user - * @param capability - * @param nodeRefs - * @param expectedAccessStatus - */ - protected void checkCapabilities( - final String user, - final String capability, - final NodeRef[] nodeRefs, - final AccessStatus ... expectedAccessStatus) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - assertEquals( - "The number of node references should match the number of expected access status", - nodeRefs.length, - expectedAccessStatus.length); - - for (int i = 0; i < nodeRefs.length; i++) - { - checkCapability(user, nodeRefs[i], capability, expectedAccessStatus[i]); - } - - return null; - } - }, true, true); - } - - /** - * - * @param capability - * @param accessStatus - */ - protected void checkTestUserCapabilities(String capability, AccessStatus ... accessStatus) - { - checkCapabilities( - test_user, - capability, - stdNodeRefs, - accessStatus); - } - - /** - * Execute RM action - * @param action - * @param params - * @param nodeRefs - */ - protected void executeAction(final String action, final Map params, final String user, final NodeRef ... nodeRefs) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(user); - - for (NodeRef nodeRef : nodeRefs) - { - recordsManagementActionService.executeRecordsManagementAction(nodeRef, action, params); - } - - return null; - } - }, false, true); - } - - /** - * - * @param action - * @param nodeRefs - */ - protected void executeAction(final String action, final NodeRef ... nodeRefs) - { - executeAction(action, null, AuthenticationUtil.SYSTEM_USER_NAME, nodeRefs); - } - - /** - * - * @param action - * @param params - * @param nodeRefs - */ - protected void executeAction(final String action, final Map params, final NodeRef ... nodeRefs) - { - executeAction(action, params, AuthenticationUtil.SYSTEM_USER_NAME, nodeRefs); - } - - /** - * - * @param action - * @param params - * @param user - * @param nodeRefs - */ - protected void checkExecuteActionFail(final String action, final Map params, final String user, final NodeRef ... nodeRefs) - { - try - { - executeAction(action, params, user, nodeRefs); - fail("Action " + action + " has succeded and was expected to fail"); - } - catch (AccessDeniedException ade) - {} - } - - /** - * - * @param nodeRef - * @param property - * @param user - */ - protected void checkSetPropertyFail(final NodeRef nodeRef, final QName property, final String user, final Serializable value) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(user); - - try - { - publicNodeService.setProperty(nodeRef, property, value); - fail("Expected failure when setting property"); - } - catch (AccessDeniedException ade) - {} - - return null; - } - }, false, true); - } - - /** - * Add a capability - * @param capability - * @param authority - * @param nodeRefs - */ - protected void addCapability(final String capability, final String authority, final NodeRef ... nodeRefs) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.SYSTEM_USER_NAME); - for (NodeRef nodeRef : nodeRefs) - { - permissionService.setPermission(nodeRef, authority, capability, true); - } - return null; - } - }, false, true); - } - - /** - * Remove capability - * @param capability - * @param authority - * @param nodeRef - */ - protected void removeCapability(final String capability, final String authority, final NodeRef ... nodeRefs) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.SYSTEM_USER_NAME); - for (NodeRef nodeRef : nodeRefs) - { - permissionService.deletePermission(nodeRef, authority, capability); - } - return null; - } - }, false, true); - } - - /** - * - * @param nodeRefs - */ - protected void declare(final NodeRef ... nodeRefs) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.SYSTEM_USER_NAME); - - for (NodeRef nodeRef : nodeRefs) - { - nodeService.setProperty(nodeRef, RecordsManagementModel.PROP_ORIGINATOR, "origValue"); - nodeService.setProperty(nodeRef, RecordsManagementModel.PROP_ORIGINATING_ORGANIZATION, "origOrgValue"); - nodeService.setProperty(nodeRef, RecordsManagementModel.PROP_PUBLICATION_DATE, new Date()); - nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "titleValue"); - recordsManagementActionService.executeRecordsManagementAction(nodeRef, "declareRecord"); - } - - return null; - } - }, false, true); - } - - protected void cutoff(final NodeRef ... nodeRefs) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.SYSTEM_USER_NAME); - - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - - for (NodeRef nodeRef : nodeRefs) - { - NodeRef ndNodeRef = nodeService.getChildAssocs(nodeRef, RecordsManagementModel.ASSOC_NEXT_DISPOSITION_ACTION, RegexQNamePattern.MATCH_ALL).get(0).getChildRef(); - nodeService.setProperty(ndNodeRef, RecordsManagementModel.PROP_DISPOSITION_AS_OF, calendar.getTime()); - recordsManagementActionService.executeRecordsManagementAction(nodeRef, "cutoff", null); - } - - return null; - } - }, false, true); - } - - protected void makeEligible(final NodeRef ... nodeRefs) - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.SYSTEM_USER_NAME); - - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - - for (NodeRef nodeRef : nodeRefs) - { - NodeRef ndNodeRef = nodeService.getChildAssocs(nodeRef, RecordsManagementModel.ASSOC_NEXT_DISPOSITION_ACTION, RegexQNamePattern.MATCH_ALL).get(0).getChildRef(); - nodeService.setProperty(ndNodeRef, RecordsManagementModel.PROP_DISPOSITION_AS_OF, calendar.getTime()); - } - - return null; - } - }, false, true); - } -} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/CapabilitiesTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/CapabilitiesTest.java index ed97e266bd..3e7419f79e 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/CapabilitiesTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/CapabilitiesTest.java @@ -71,7 +71,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements { super.setupTestDataImpl(); - record = createRecord(rmFolder, "CapabilitiesTest.txt"); + record = utils.createRecord(rmFolder, "CapabilitiesTest.txt"); } @Override @@ -1303,7 +1303,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, CREATE_MODIFY_DESTROY_FILEPLAN_TYPES, AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_FOLDERS, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_RECORD_TYPES, AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_REFERENCE_TYPES, @@ -1426,7 +1426,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, CREATE_MODIFY_DESTROY_FILEPLAN_TYPES, AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_FOLDERS, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_RECORD_TYPES, AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_REFERENCE_TYPES, @@ -1548,7 +1548,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, CREATE_MODIFY_DESTROY_FILEPLAN_TYPES, AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_FOLDERS, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_RECORD_TYPES, AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_REFERENCE_TYPES, @@ -1672,7 +1672,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, CREATE_MODIFY_DESTROY_FILEPLAN_TYPES, AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_FOLDERS, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_RECORD_TYPES, AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_REFERENCE_TYPES, @@ -1796,7 +1796,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, CREATE_MODIFY_DESTROY_FILEPLAN_TYPES, AccessStatus.DENIED); check(access, CREATE_MODIFY_DESTROY_FOLDERS, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_RECORD_TYPES, AccessStatus.DENIED); check(access, CREATE_MODIFY_DESTROY_REFERENCE_TYPES, @@ -1917,7 +1917,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, CREATE_MODIFY_DESTROY_FILEPLAN_TYPES, AccessStatus.DENIED); check(access, CREATE_MODIFY_DESTROY_FOLDERS, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, CREATE_MODIFY_DESTROY_RECORD_TYPES, AccessStatus.DENIED); check(access, CREATE_MODIFY_DESTROY_REFERENCE_TYPES, @@ -2194,7 +2194,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.ALLOWED); + AccessStatus.DENIED); check(access, EDIT_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_SELECTION_LISTS, AccessStatus.ALLOWED); @@ -2318,7 +2318,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.ALLOWED); + AccessStatus.DENIED); check(access, EDIT_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_SELECTION_LISTS, AccessStatus.ALLOWED); @@ -2441,7 +2441,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.ALLOWED); + AccessStatus.DENIED); check(access, EDIT_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_SELECTION_LISTS, AccessStatus.ALLOWED); @@ -2562,7 +2562,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.ALLOWED); + AccessStatus.DENIED); check(access, EDIT_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_SELECTION_LISTS, AccessStatus.ALLOWED); @@ -2683,7 +2683,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.ALLOWED); + AccessStatus.DENIED); check(access, EDIT_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_SELECTION_LISTS, AccessStatus.DENIED); check(access, ENABLE_DISABLE_AUDIT_BY_TYPES, @@ -2801,7 +2801,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.ALLOWED); + AccessStatus.DENIED); check(access, EDIT_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_SELECTION_LISTS, AccessStatus.DENIED); check(access, ENABLE_DISABLE_AUDIT_BY_TYPES, @@ -3038,7 +3038,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, EDIT_RECORD_METADATA, AccessStatus.ALLOWED); check(access, EDIT_SELECTION_LISTS, @@ -3162,7 +3162,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, EDIT_RECORD_METADATA, AccessStatus.ALLOWED); check(access, EDIT_SELECTION_LISTS, @@ -3285,7 +3285,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, EDIT_RECORD_METADATA, AccessStatus.ALLOWED); check(access, EDIT_SELECTION_LISTS, @@ -3409,7 +3409,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, EDIT_RECORD_METADATA, AccessStatus.ALLOWED); check(access, EDIT_SELECTION_LISTS, @@ -3533,7 +3533,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, EDIT_RECORD_METADATA, AccessStatus.ALLOWED); check(access, EDIT_SELECTION_LISTS, AccessStatus.DENIED); @@ -3655,7 +3655,7 @@ public class CapabilitiesTest extends BaseRMTestCase implements check(access, EDIT_DECLARED_RECORD_METADATA, AccessStatus.DENIED); check(access, EDIT_NON_RECORD_METADATA, - AccessStatus.DENIED); + AccessStatus.ALLOWED); check(access, EDIT_RECORD_METADATA, AccessStatus.ALLOWED); check(access, EDIT_SELECTION_LISTS, AccessStatus.DENIED); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/DeclarativeCapabilityTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/DeclarativeCapabilityTest.java index 27c65e35b4..2c63548ed6 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/DeclarativeCapabilityTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/capabilities/DeclarativeCapabilityTest.java @@ -63,16 +63,16 @@ public class DeclarativeCapabilityTest extends BaseRMTestCase super.setupTestDataImpl(); // Pre-filed content - record = createRecord(rmFolder, "record.txt"); - declaredRecord = createRecord(rmFolder, "declaredRecord.txt"); + record = utils.createRecord(rmFolder, "record.txt"); + declaredRecord = utils.createRecord(rmFolder, "declaredRecord.txt"); // Open folder // Closed folder recordFolderContainsFrozen = rmService.createRecordFolder(rmContainer, "containsFrozen"); - frozenRecord = createRecord(rmFolder, "frozenRecord.txt"); - frozenRecord2 = createRecord(recordFolderContainsFrozen, "frozen2.txt"); + frozenRecord = utils.createRecord(rmFolder, "frozenRecord.txt"); + frozenRecord2 = utils.createRecord(recordFolderContainsFrozen, "frozen2.txt"); frozenRecordFolder = rmService.createRecordFolder(rmContainer, "frozenRecordFolder"); } @@ -89,12 +89,12 @@ public class DeclarativeCapabilityTest extends BaseRMTestCase { AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - declareRecord(declaredRecord); - declareRecord(frozenRecord); - declareRecord(frozenRecord2); - freeze(frozenRecord); - freeze(frozenRecordFolder); - freeze(frozenRecord2); + utils.declareRecord(declaredRecord); + utils.declareRecord(frozenRecord); + utils.declareRecord(frozenRecord2); + utils.freeze(frozenRecord); + utils.freeze(frozenRecordFolder); + utils.freeze(frozenRecord2); return null; } @@ -105,9 +105,9 @@ public class DeclarativeCapabilityTest extends BaseRMTestCase protected void tearDownImpl() { // Unfreeze stuff so it can be deleted - unfreeze(frozenRecord); - unfreeze(frozenRecordFolder); - unfreeze(frozenRecord2); + utils.unfreeze(frozenRecord); + utils.unfreeze(frozenRecordFolder); + utils.unfreeze(frozenRecord2); super.tearDownImpl(); } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/JSONConversionComponentTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/JSONConversionComponentTest.java index 9569e77008..ab7d25b4ca 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/JSONConversionComponentTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/JSONConversionComponentTest.java @@ -49,7 +49,7 @@ public class JSONConversionComponentTest extends BaseRMTestCase super.setupTestDataImpl(); // Create records - record = createRecord(rmFolder, "testRecord.txt"); + record = utils.createRecord(rmFolder, "testRecord.txt"); } public void testJSON() throws Exception diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/RMJScriptTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/RMJScriptTest.java index 1f9fe06d7a..a1326d4680 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/RMJScriptTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/RMJScriptTest.java @@ -40,18 +40,29 @@ public class RMJScriptTest extends BaseRMTestCase @Override protected void initServices() { + super.initServices(); this.scriptService = (ScriptService)this.applicationContext.getBean("ScriptService"); } + private NodeRef record; public void testCapabilities() throws Exception { + doTestInTransaction(new Test() + { + @Override + public Void run() + { + record = utils.createRecord(rmFolder, "testRecord.txt"); + return null; + } + }); + doTestInTransaction(new Test() { @Override public NodeRef run() { - NodeRef record = createRecord(rmFolder, "testRecord.txt"); - declareRecord(record); + utils.declareRecord(record); return record; } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/DispositionServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/DispositionServiceImplTest.java index a81f7594e1..4eb6cf314d 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/DispositionServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/DispositionServiceImplTest.java @@ -37,6 +37,7 @@ import org.alfresco.module.org_alfresco_module_rm.job.publish.PublishExecutor; import org.alfresco.module.org_alfresco_module_rm.job.publish.PublishExecutorRegistry; 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.CommonRMTestUtils; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; @@ -148,7 +149,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase { DispositionSchedule ds = dispositionService.getDispositionSchedule(container); assertNotNull(ds); - checkDispositionSchedule(ds, dispositionInstructions, DEFAULT_DISPOSITION_AUTHORITY, isRecordLevel); + checkDispositionSchedule(ds, dispositionInstructions, CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, isRecordLevel); } private void doCheckFolder(NodeRef container, String dispositionInstructions, boolean isRecordLevel) @@ -193,7 +194,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase */ private void checkDispositionSchedule(DispositionSchedule ds, boolean isRecordLevel) { - checkDispositionSchedule(ds, DEFAULT_DISPOSITION_INSTRUCTIONS, DEFAULT_DISPOSITION_AUTHORITY, isRecordLevel); + checkDispositionSchedule(ds, CommonRMTestUtils.DEFAULT_DISPOSITION_INSTRUCTIONS, CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, isRecordLevel); } /** @@ -266,7 +267,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase { DispositionSchedule ds = dispositionService.getAssociatedDispositionSchedule(container); assertNotNull(ds); - checkDispositionSchedule(ds, dispositionInstructions, DEFAULT_DISPOSITION_AUTHORITY, isRecordLevel); + checkDispositionSchedule(ds, dispositionInstructions, CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, isRecordLevel); } }); } @@ -283,7 +284,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase { // Add a new disposition schedule NodeRef container = rmService.createRecordCategory(rmContainer, "hasDisposableTest"); - DispositionSchedule ds = createBasicDispositionSchedule(container); + DispositionSchedule ds = utils.createBasicDispositionSchedule(container); assertTrue(dispositionService.hasDisposableItems(dispositionSchedule)); assertFalse(dispositionService.hasDisposableItems(ds)); @@ -387,7 +388,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase NodeRef container = rmService.createRecordCategory(filePlan, "testCreateDispositionSchedule"); // Create a new disposition schedule - createBasicDispositionSchedule(container, "testCreateDispositionSchedule", "testCreateDispositionSchedule", false, true); + utils.createBasicDispositionSchedule(container, "testCreateDispositionSchedule", "testCreateDispositionSchedule", false, true); return container; } @@ -413,7 +414,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase @Override public void run() { - createBasicDispositionSchedule(rmContainer); + utils.createBasicDispositionSchedule(rmContainer); } }); } @@ -434,8 +435,8 @@ public class DispositionServiceImplTest extends BaseRMTestCase NodeRef testB = rmService.createRecordCategory(testA, "testB"); // Create new disposition schedules - createBasicDispositionSchedule(testA, "testA", "testA", false, true); - createBasicDispositionSchedule(testB, "testB", "testB", false, true); + utils.createBasicDispositionSchedule(testA, "testA", "testA", false, true); + utils.createBasicDispositionSchedule(testB, "testB", "testB", false, true); // Add created containers to model setNodeRef("testA", testA); @@ -468,7 +469,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase @Override public void run() { - createBasicDispositionSchedule(mhContainer11); + utils.createBasicDispositionSchedule(mhContainer11); } }); @@ -481,7 +482,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase @Override public void run() { - createBasicDispositionSchedule(mhContainer21); + utils.createBasicDispositionSchedule(mhContainer21); } }); } @@ -554,8 +555,8 @@ public class DispositionServiceImplTest extends BaseRMTestCase @Override public Void run() throws Exception { - record43 = createRecord(mhRecordFolder43, "record1.txt"); - record45 = createRecord(mhRecordFolder45, "record2.txt"); + record43 = utils.createRecord(mhRecordFolder43, "record1.txt"); + record45 = utils.createRecord(mhRecordFolder45, "record2.txt"); return null; } @@ -692,8 +693,8 @@ public class DispositionServiceImplTest extends BaseRMTestCase checkDispositionAction( dispositionService.getNextDispositionAction(recordFolder), "cutoff", - new String[]{DEFAULT_EVENT_NAME}, - PERIOD_NONE); + new String[]{CommonRMTestUtils.DEFAULT_EVENT_NAME}, + CommonRMTestUtils.PERIOD_NONE); } private void checkDisposableItemChanged(NodeRef recordFolder) throws Exception @@ -701,7 +702,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase checkDispositionAction( dispositionService.getNextDispositionAction(recordFolder), "cutoff", - new String[]{DEFAULT_EVENT_NAME, "abolished"}, + new String[]{CommonRMTestUtils.DEFAULT_EVENT_NAME, "abolished"}, "week|1"); } @@ -709,7 +710,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase { Map updateProps = new HashMap(3); updateProps.put(PROP_DISPOSITION_PERIOD, "week|1"); - updateProps.put(PROP_DISPOSITION_EVENT, (Serializable)Arrays.asList(DEFAULT_EVENT_NAME, "abolished")); + updateProps.put(PROP_DISPOSITION_EVENT, (Serializable)Arrays.asList(CommonRMTestUtils.DEFAULT_EVENT_NAME, "abolished")); DispositionSchedule ds = dispositionService.getDispositionSchedule(nodeRef); DispositionActionDefinition dad = ds.getDispositionActionDefinitionByName("cutoff"); @@ -777,7 +778,7 @@ public class DispositionServiceImplTest extends BaseRMTestCase fail(buff.toString()); } - if (PERIOD_NONE.equals(strPeriod) == true) + if (CommonRMTestUtils.PERIOD_NONE.equals(strPeriod) == true) { assertNull(da.getAsOfDate()); } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementAdminServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementAdminServiceImplTest.java index 9574d9d72f..7b07fc1c2a 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementAdminServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementAdminServiceImplTest.java @@ -562,7 +562,7 @@ public class RecordsManagementAdminServiceImplTest extends BaseRMTestCase { public NodeRef execute() throws Throwable { - NodeRef result = createRecord(rmFolder, "testRecordA" + System.currentTimeMillis()); + NodeRef result = utils.createRecord(rmFolder, "testRecordA" + System.currentTimeMillis()); return result; } }); @@ -570,7 +570,7 @@ public class RecordsManagementAdminServiceImplTest extends BaseRMTestCase { public NodeRef execute() throws Throwable { - NodeRef result = createRecord(rmFolder, "testRecordB" + System.currentTimeMillis()); + NodeRef result = utils.createRecord(rmFolder, "testRecordB" + System.currentTimeMillis()); return result; } }); @@ -579,8 +579,8 @@ public class RecordsManagementAdminServiceImplTest extends BaseRMTestCase { public QName execute() throws Throwable { - declareRecord(testRecord1); - declareRecord(testRecord2); + utils.declareRecord(testRecord1); + utils.declareRecord(testRecord2); Map params = new HashMap(); params.put("referenceType", refType.toString()); @@ -758,8 +758,8 @@ public class RecordsManagementAdminServiceImplTest extends BaseRMTestCase { public Pair execute() throws Throwable { - NodeRef rec1 = createRecord(rmFolder, "testRecordA" + System.currentTimeMillis()); - NodeRef rec2 = createRecord(rmFolder, "testRecordB" + System.currentTimeMillis()); + NodeRef rec1 = utils.createRecord(rmFolder, "testRecordA" + System.currentTimeMillis()); + NodeRef rec2 = utils.createRecord(rmFolder, "testRecordB" + System.currentTimeMillis()); Pair result = new Pair(rec1, rec2); return result; } @@ -771,8 +771,8 @@ public class RecordsManagementAdminServiceImplTest extends BaseRMTestCase { public Void execute() throws Throwable { - declareRecord(testRecord1); - declareRecord(testRecord2); + utils.declareRecord(testRecord1); + utils.declareRecord(testRecord2); policyComponent.bindClassBehaviour( RecordsManagementPolicies.BEFORE_CREATE_REFERENCE, diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSearchServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSearchServiceImplTest.java index 8ad3c91911..085ef35879 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSearchServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSearchServiceImplTest.java @@ -107,12 +107,12 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase folderLevelRecordFolder = mhRecordFolder42; recordLevelRecordFolder = mhRecordFolder43; - recordOne = createRecord(folderLevelRecordFolder, "recordOne.txt", null, "record one - folder level - elephant"); - recordTwo = createRecord(folderLevelRecordFolder, "recordTwo.txt", null, "record two - folder level - snake"); - recordThree = createRecord(folderLevelRecordFolder, "recordThree.txt", null, "record three - folder level - monkey"); - recordFour = createRecord(recordLevelRecordFolder, "recordFour.txt", null, "record four - record level - elephant"); - recordFive = createRecord(recordLevelRecordFolder, "recordFive.txt", null, "record five - record level - snake"); - recordSix = createRecord(recordLevelRecordFolder, "recordSix.txt", null, "record six - record level - monkey"); + recordOne = utils.createRecord(folderLevelRecordFolder, "recordOne.txt", null, "record one - folder level - elephant"); + recordTwo = utils.createRecord(folderLevelRecordFolder, "recordTwo.txt", null, "record two - folder level - snake"); + recordThree = utils.createRecord(folderLevelRecordFolder, "recordThree.txt", null, "record three - folder level - monkey"); + recordFour = utils.createRecord(recordLevelRecordFolder, "recordFour.txt", null, "record four - record level - elephant"); + recordFive = utils.createRecord(recordLevelRecordFolder, "recordFive.txt", null, "record five - record level - snake"); + recordSix = utils.createRecord(recordLevelRecordFolder, "recordSix.txt", null, "record six - record level - monkey"); return null; } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java index 3c7f77db0d..f9d818bdaa 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java @@ -69,7 +69,7 @@ public class RecordsManagementServiceImplTest extends BaseRMTestCase @Override public NodeRef run() throws Exception { - return createRecord(rmFolder, "testRecord.txt"); + return utils.createRecord(rmFolder, "testRecord.txt"); } @Override diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/VitalRecordServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/VitalRecordServiceImplTest.java index ed7ff8cdc8..ce07978310 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/VitalRecordServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/VitalRecordServiceImplTest.java @@ -100,11 +100,11 @@ public class VitalRecordServiceImplTest extends BaseRMTestCase @Override public Object execute() throws Throwable { - mhRecord51 = createRecord(mhRecordFolder41, "record51.txt"); - mhRecord52 = createRecord(mhRecordFolder42, "record52.txt"); - mhRecord53 = createRecord(mhRecordFolder43, "record53.txt"); - mhRecord54 = createRecord(mhRecordFolder44, "record54.txt"); - mhRecord55 = createRecord(mhRecordFolder45, "record55.txt"); + mhRecord51 = utils.createRecord(mhRecordFolder41, "record51.txt"); + mhRecord52 = utils.createRecord(mhRecordFolder42, "record52.txt"); + mhRecord53 = utils.createRecord(mhRecordFolder43, "record53.txt"); + mhRecord54 = utils.createRecord(mhRecordFolder44, "record54.txt"); + mhRecord55 = utils.createRecord(mhRecordFolder45, "record55.txt"); return null; } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/DODDataLoadSystemTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/DODDataLoadSystemTest.java deleted file mode 100644 index ce1c02fc94..0000000000 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/DODDataLoadSystemTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.module.org_alfresco_module_rm.test.system; - -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; -import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; -import org.alfresco.module.org_alfresco_module_rm.test.util.TestUtilities; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.view.ImporterService; -import org.alfresco.util.BaseSpringTest; - -/** - * - * - * @author Roy Wetherall - */ -public class DODDataLoadSystemTest extends BaseSpringTest -{ - private NodeService nodeService; - private AuthenticationComponent authenticationComponent; - private ImporterService importer; - private PermissionService permissionService; - private SearchService searchService; - private RecordsManagementService rmService; - private RecordsManagementActionService rmActionService; - - @Override - protected void onSetUpInTransaction() throws Exception - { - super.onSetUpInTransaction(); - - // Get the service required in the tests - this.nodeService = (NodeService)this.applicationContext.getBean("NodeService"); - this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent"); - this.importer = (ImporterService)this.applicationContext.getBean("ImporterService"); - this.permissionService = (PermissionService)this.applicationContext.getBean("PermissionService"); - searchService = (SearchService)applicationContext.getBean("SearchService"); - rmService = (RecordsManagementService)applicationContext.getBean("RecordsManagementService"); - rmActionService = (RecordsManagementActionService)applicationContext.getBean("RecordsManagementActionService"); - - - // Set the current security context as admin - this.authenticationComponent.setCurrentUser(AuthenticationUtil.getSystemUserName()); - } - - public void testSetup() - { - // NOOP - } - - public void testLoadFilePlanData() - { - TestUtilities.loadFilePlanData(applicationContext); - - setComplete(); - endTransaction(); - } -} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/NotificationServiceHelperSystemTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/NotificationServiceHelperSystemTest.java index 6577dc21e1..dbdcc71dc3 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/NotificationServiceHelperSystemTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/NotificationServiceHelperSystemTest.java @@ -111,9 +111,9 @@ public class NotificationServiceHelperSystemTest extends BaseRMTestCase super.setupTestDataImpl(); // Create a few test records - record = createRecord(rmFolder, "recordOne"); - NodeRef record2 = createRecord(rmFolder, "recordTwo"); - NodeRef record3 = createRecord(rmFolder, "recordThree"); + record = utils.createRecord(rmFolder, "recordOne"); + NodeRef record2 = utils.createRecord(rmFolder, "recordTwo"); + NodeRef record3 = utils.createRecord(rmFolder, "recordThree"); records = new ArrayList(3); records.add(record); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/RecordsManagementServiceImplSystemTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/RecordsManagementServiceImplSystemTest.java index dd5f60c4d5..7ca0a52d65 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/RecordsManagementServiceImplSystemTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/RecordsManagementServiceImplSystemTest.java @@ -175,7 +175,7 @@ public class RecordsManagementServiceImplSystemTest extends BaseSpringTest imple */ public void testRescheduleRecord_IsNotCutOff() throws Exception { - final NodeRef recCat = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); + final NodeRef recCat = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); // This RC has disposition instructions "Cut off monthly, hold 1 month, then destroy." setComplete(); @@ -379,7 +379,7 @@ public class RecordsManagementServiceImplSystemTest extends BaseSpringTest imple { public Void execute() throws Throwable { - NodeRef folderRecord = TestUtilities.getRecordFolder(searchService, "Reports", "AIS Audit Records", "January AIS Audit Records"); + NodeRef folderRecord = TestUtilities.getRecordFolder(rmService, nodeService, "Reports", "AIS Audit Records", "January AIS Audit Records"); assertNotNull(folderRecord); assertEquals("January AIS Audit Records", nodeService.getProperty(folderRecord, ContentModel.PROP_NAME)); @@ -394,7 +394,7 @@ public class RecordsManagementServiceImplSystemTest extends BaseSpringTest imple assertFalse(di.isRecordLevelDisposition()); // Get a record category - NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); + NodeRef recordCategory = TestUtilities.getRecordCategory(rmService, nodeService, "Reports", "AIS Audit Records"); assertNotNull(recordCategory); assertEquals("AIS Audit Records", nodeService.getProperty(recordCategory, ContentModel.PROP_NAME)); @@ -434,7 +434,7 @@ public class RecordsManagementServiceImplSystemTest extends BaseSpringTest imple { public NodeRef execute() throws Throwable { - NodeRef result = TestUtilities.getRecordFolder(searchService, "Civilian Files", "Case Files and Papers", "Gilbert Competency Hearing"); + NodeRef result = TestUtilities.getRecordFolder(rmService, nodeService, "Civilian Files", "Case Files and Papers", "Gilbert Competency Hearing"); assertNotNull("cleanRecordFolder was null", result); final DispositionSchedule dispositionSchedule = dispositionService.getDispositionSchedule(result); @@ -451,7 +451,7 @@ public class RecordsManagementServiceImplSystemTest extends BaseSpringTest imple { public NodeRef execute() throws Throwable { - NodeRef result = TestUtilities.getRecordFolder(searchService, "Reports", "AIS Audit Records", "January AIS Audit Records"); + NodeRef result = TestUtilities.getRecordFolder(rmService, nodeService, "Reports", "AIS Audit Records", "January AIS Audit Records"); assertNotNull("dispositionAndVitalRecordFolder was null", result); final DispositionSchedule dispositionSchedule = dispositionService.getDispositionSchedule(result); @@ -579,7 +579,7 @@ public class RecordsManagementServiceImplSystemTest extends BaseSpringTest imple { public NodeRef execute() throws Throwable { - NodeRef result = TestUtilities.getRecordFolder(searchService, "Civilian Files", "Case Files and Papers", "Gilbert Competency Hearing"); + NodeRef result = TestUtilities.getRecordFolder(rmService, nodeService, "Civilian Files", "Case Files and Papers", "Gilbert Competency Hearing"); assertNotNull("cleanRecordFolder was null", result); final DispositionSchedule dispositionSchedule = dispositionService.getDispositionSchedule(result); @@ -596,7 +596,7 @@ public class RecordsManagementServiceImplSystemTest extends BaseSpringTest imple { public NodeRef execute() throws Throwable { - NodeRef result = TestUtilities.getRecordFolder(searchService, "Reports", "AIS Audit Records", "January AIS Audit Records"); + NodeRef result = TestUtilities.getRecordFolder(rmService, nodeService, "Reports", "AIS Audit Records", "January AIS Audit Records"); assertNotNull("dispositionAndVitalRecordFolder was null", result); final DispositionSchedule dispositionSchedule = dispositionService.getDispositionSchedule(result); @@ -757,7 +757,7 @@ public class RecordsManagementServiceImplSystemTest extends BaseSpringTest imple public Void execute() throws Throwable { // Get a record folder - NodeRef folderRecord = TestUtilities.getRecordFolder(searchService, "Reports", "AIS Audit Records", "January AIS Audit Records"); + NodeRef folderRecord = TestUtilities.getRecordFolder(rmService, nodeService, "Reports", "AIS Audit Records", "January AIS Audit Records"); assertNotNull(folderRecord); assertEquals("January AIS Audit Records", nodeService.getProperty(folderRecord, ContentModel.PROP_NAME)); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index 131302ffd8..28a10feff4 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -91,6 +91,9 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase /** Site id */ protected static final String SITE_ID = "mySite"; + /** Common test utils */ + protected CommonRMTestUtils utils; + /** Services */ protected NodeService nodeService; protected ContentService contentService; @@ -195,13 +198,6 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase protected NodeRef recordsManagerPerson; protected NodeRef rmAdminPerson; - /** test values */ - protected static final String DEFAULT_DISPOSITION_AUTHORITY = "disposition authority"; - protected static final String DEFAULT_DISPOSITION_INSTRUCTIONS = "disposition instructions"; - protected static final String DEFAULT_DISPOSITION_DESCRIPTION = "disposition action description"; - protected static final String DEFAULT_EVENT_NAME = "case_closed"; - protected static final String PERIOD_NONE = "none|0"; - /** * Indicates whether this is a multi-hierarchy test or not. If it is then the multi-hierarchy record * taxonomy test data is loaded. @@ -228,6 +224,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase { // Get the application context applicationContext = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS); + utils = new CommonRMTestUtils(applicationContext); // Initialise the service beans initServices(); @@ -365,7 +362,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase assertNotNull("Could not create rm container", rmContainer); // Create disposition schedule - dispositionSchedule = createBasicDispositionSchedule(rmContainer); + dispositionSchedule = utils.createBasicDispositionSchedule(rmContainer); // Create RM folder rmFolder = rmService.createRecordFolder(rmContainer, "rmFolder"); @@ -465,24 +462,24 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase // Level 1 mhContainer11 = rmService.createRecordCategory(mhContainer, "mhContainer11"); - mhDispositionSchedule11 = createBasicDispositionSchedule(mhContainer11, "ds11", DEFAULT_DISPOSITION_AUTHORITY, false, true); + mhDispositionSchedule11 = utils.createBasicDispositionSchedule(mhContainer11, "ds11", utils.DEFAULT_DISPOSITION_AUTHORITY, false, true); mhContainer12 = rmService.createRecordCategory(mhContainer, "mhContainer12"); - mhDispositionSchedule12 = createBasicDispositionSchedule(mhContainer12, "ds12", DEFAULT_DISPOSITION_AUTHORITY, false, true); + mhDispositionSchedule12 = utils.createBasicDispositionSchedule(mhContainer12, "ds12", utils.DEFAULT_DISPOSITION_AUTHORITY, false, true); // Level 2 mhContainer21 = rmService.createRecordCategory(mhContainer11, "mhContainer21"); mhContainer22 = rmService.createRecordCategory(mhContainer12, "mhContainer22"); mhContainer23 = rmService.createRecordCategory(mhContainer12, "mhContainer23"); - mhDispositionSchedule23 = createBasicDispositionSchedule(mhContainer23, "ds23", DEFAULT_DISPOSITION_AUTHORITY, false, true); + mhDispositionSchedule23 = utils.createBasicDispositionSchedule(mhContainer23, "ds23", utils.DEFAULT_DISPOSITION_AUTHORITY, false, true); // Level 3 mhContainer31 = rmService.createRecordCategory(mhContainer21, "mhContainer31"); mhContainer32 = rmService.createRecordCategory(mhContainer22, "mhContainer32"); mhContainer33 = rmService.createRecordCategory(mhContainer22, "mhContainer33"); - mhDispositionSchedule33 = createBasicDispositionSchedule(mhContainer33, "ds33", DEFAULT_DISPOSITION_AUTHORITY, true, true); + mhDispositionSchedule33 = utils.createBasicDispositionSchedule(mhContainer33, "ds33", utils.DEFAULT_DISPOSITION_AUTHORITY, true, true); mhContainer34 = rmService.createRecordCategory(mhContainer23, "mhContainer34"); mhContainer35 = rmService.createRecordCategory(mhContainer23, "mhContainer35"); - mhDispositionSchedule35 = createBasicDispositionSchedule(mhContainer35, "ds35", DEFAULT_DISPOSITION_AUTHORITY, true, true); + mhDispositionSchedule35 = utils.createBasicDispositionSchedule(mhContainer35, "ds35", utils.DEFAULT_DISPOSITION_AUTHORITY, true, true); // Record folders mhRecordFolder41 = rmService.createRecordFolder(mhContainer31, "mhFolder41"); @@ -491,145 +488,4 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase mhRecordFolder44 = rmService.createRecordFolder(mhContainer34, "mhFolder44"); mhRecordFolder45 = rmService.createRecordFolder(mhContainer35, "mhFolder45"); } - - /** - * - * @param container - * @return - */ - protected DispositionSchedule createBasicDispositionSchedule(NodeRef container) - { - return createBasicDispositionSchedule(container, DEFAULT_DISPOSITION_INSTRUCTIONS, DEFAULT_DISPOSITION_AUTHORITY, false, true); - } - - /** - * - * @param container - * @param isRecordLevel - * @param defaultDispositionActions - * @return - */ - protected DispositionSchedule createBasicDispositionSchedule( - NodeRef container, - String dispositionInstructions, - String dispositionAuthority, - boolean isRecordLevel, - boolean defaultDispositionActions) - { - Map dsProps = new HashMap(3); - dsProps.put(PROP_DISPOSITION_AUTHORITY, dispositionAuthority); - dsProps.put(PROP_DISPOSITION_INSTRUCTIONS, dispositionInstructions); - dsProps.put(PROP_RECORD_LEVEL_DISPOSITION, isRecordLevel); - DispositionSchedule dispositionSchedule = dispositionService.createDispositionSchedule(container, dsProps); - assertNotNull(dispositionSchedule); - - if (defaultDispositionActions == true) - { - Map adParams = new HashMap(3); - adParams.put(PROP_DISPOSITION_ACTION_NAME, "cutoff"); - adParams.put(PROP_DISPOSITION_DESCRIPTION, DEFAULT_DISPOSITION_DESCRIPTION); - - List events = new ArrayList(1); - events.add(DEFAULT_EVENT_NAME); - adParams.put(PROP_DISPOSITION_EVENT, (Serializable)events); - - dispositionService.addDispositionActionDefinition(dispositionSchedule, adParams); - - adParams = new HashMap(3); - adParams.put(PROP_DISPOSITION_ACTION_NAME, "destroy"); - adParams.put(PROP_DISPOSITION_DESCRIPTION, DEFAULT_DISPOSITION_DESCRIPTION); - adParams.put(PROP_DISPOSITION_PERIOD, "immediately|0"); - - dispositionService.addDispositionActionDefinition(dispositionSchedule, adParams); - } - - return dispositionSchedule; - } - - protected NodeRef createRecord(NodeRef recordFolder, String name) - { - return createRecord(recordFolder, name, null, "Some test content"); - } - - protected NodeRef createRecord(NodeRef recordFolder, String name, Map properties, String content) - { - // Create the document - if (properties == null) - { - properties = new HashMap(1); - } - if (properties.containsKey(ContentModel.PROP_NAME) == false) - { - properties.put(ContentModel.PROP_NAME, name); - } - NodeRef recordOne = this.nodeService.createNode(recordFolder, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), - ContentModel.TYPE_CONTENT, - properties).getChildRef(); - - // Set the content - ContentWriter writer = contentService.getWriter(recordOne, ContentModel.PROP_CONTENT, true); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer.setEncoding("UTF-8"); - writer.putContent(content); - - return recordOne; - } - - protected void declareRecord(final NodeRef record) - { - AuthenticationUtil.runAs(new RunAsWork() - { - @Override - public Void doWork() throws Exception - { - // Declare record - nodeService.setProperty(record, RecordsManagementModel.PROP_PUBLICATION_DATE, new Date()); - nodeService.setProperty(record, RecordsManagementModel.PROP_MEDIA_TYPE, "mediaTypeValue"); - nodeService.setProperty(record, RecordsManagementModel.PROP_FORMAT, "formatValue"); - nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_RECEIVED, new Date()); - nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_FILED, new Date()); - nodeService.setProperty(record, RecordsManagementModel.PROP_ORIGINATOR, "origValue"); - nodeService.setProperty(record, RecordsManagementModel.PROP_ORIGINATING_ORGANIZATION, "origOrgValue"); - nodeService.setProperty(record, ContentModel.PROP_TITLE, "titleValue"); - actionService.executeRecordsManagementAction(record, "declareRecord"); - - return null; - } - - }, AuthenticationUtil.getAdminUserName()); - - } - - protected void freeze(final NodeRef nodeRef) - { - AuthenticationUtil.runAs(new RunAsWork() - { - @Override - public Void doWork() throws Exception - { - Map params = new HashMap(1); - params.put(FreezeAction.PARAM_REASON, "Freeze reason."); - actionService.executeRecordsManagementAction(nodeRef, "freeze", params); - - return null; - } - - }, AuthenticationUtil.getSystemUserName()); - } - - protected void unfreeze(final NodeRef nodeRef) - { - AuthenticationUtil.runAs(new RunAsWork() - { - @Override - public Void doWork() throws Exception - { - actionService.executeRecordsManagementAction(nodeRef, "unfreeze"); - return null; - } - - }, AuthenticationUtil.getSystemUserName()); - } } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMWebScriptTestCase.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMWebScriptTestCase.java new file mode 100644 index 0000000000..f45947b6f1 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMWebScriptTestCase.java @@ -0,0 +1,236 @@ +/** + * + */ +package org.alfresco.module.org_alfresco_module_rm.test.util; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService; +import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; +import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; +import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditService; +import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; +import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventService; +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.model.RmSiteType; +import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService; +import org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService; +import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordService; +import org.alfresco.repo.policy.PolicyComponent; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.transaction.RetryingTransactionHelper; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.repo.web.scripts.BaseWebScriptTest; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.Period; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.cmr.security.AuthorityService; +import org.alfresco.service.cmr.security.MutableAuthenticationService; +import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.service.cmr.site.SiteInfo; +import org.alfresco.service.cmr.site.SiteService; +import org.alfresco.service.cmr.site.SiteVisibility; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.springframework.context.ApplicationContext; + +/** + * @author Roy Wetherall + */ +public class BaseRMWebScriptTestCase extends BaseWebScriptTest +{ + /** Site id */ + protected static final String SITE_ID = "mySite"; + + /** Common test utils */ + protected CommonRMTestUtils utils; + + /** Services */ + protected NodeService nodeService; + protected ContentService contentService; + protected DictionaryService dictionaryService; + protected RetryingTransactionHelper retryingTransactionHelper; + protected PolicyComponent policyComponent; + protected NamespaceService namespaceService; + protected SearchService searchService; + protected SiteService siteService; + protected MutableAuthenticationService authenticationService; + protected AuthorityService authorityService; + protected PersonService personService; + + /** RM Services */ + protected RecordsManagementService rmService; + protected DispositionService dispositionService; + protected RecordsManagementEventService eventService; + protected RecordsManagementAdminService adminService; + protected RecordsManagementActionService actionService; + protected RecordsManagementSearchService rmSearchService; + protected RecordsManagementSecurityService securityService; + protected RecordsManagementAuditService auditService; + protected CapabilityService capabilityService; + protected VitalRecordService vitalRecordService; + + /** test data */ + protected StoreRef storeRef; + protected NodeRef rootNodeRef; + protected SiteInfo siteInfo; + protected NodeRef folder; + protected NodeRef filePlan; + protected NodeRef recordSeries; // A category with no disposition schedule + protected NodeRef recordCategory; + protected DispositionSchedule dispositionSchedule; + protected NodeRef recordFolder; + protected NodeRef recordFolder2; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + + // Initialise the service beans + initServices(); + + // Setup test data + setupTestData(); + } + + /** + * Initialise the service beans. + */ + protected void initServices() + { + ApplicationContext applicationContext = getServer().getApplicationContext(); + + // Common test utils + utils = new CommonRMTestUtils(applicationContext); + + // Get services + nodeService = (NodeService)applicationContext.getBean("NodeService"); + contentService = (ContentService)applicationContext.getBean("ContentService"); + retryingTransactionHelper = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper"); + namespaceService = (NamespaceService)applicationContext.getBean("NamespaceService"); + searchService = (SearchService)applicationContext.getBean("SearchService"); + policyComponent = (PolicyComponent)applicationContext.getBean("policyComponent"); + dictionaryService = (DictionaryService)applicationContext.getBean("DictionaryService"); + siteService = (SiteService)applicationContext.getBean("SiteService"); + authorityService = (AuthorityService)applicationContext.getBean("AuthorityService"); + authenticationService = (MutableAuthenticationService)applicationContext.getBean("AuthenticationService"); + personService = (PersonService)applicationContext.getBean("PersonService"); + + // Get RM services + rmService = (RecordsManagementService)applicationContext.getBean("RecordsManagementService"); + dispositionService = (DispositionService)applicationContext.getBean("DispositionService"); + eventService = (RecordsManagementEventService)applicationContext.getBean("RecordsManagementEventService"); + adminService = (RecordsManagementAdminService)applicationContext.getBean("RecordsManagementAdminService"); + actionService = (RecordsManagementActionService)applicationContext.getBean("RecordsManagementActionService"); + rmSearchService = (RecordsManagementSearchService)applicationContext.getBean("RecordsManagementSearchService"); + securityService = (RecordsManagementSecurityService)applicationContext.getBean("RecordsManagementSecurityService"); + auditService = (RecordsManagementAuditService)applicationContext.getBean("RecordsManagementAuditService"); + capabilityService = (CapabilityService)applicationContext.getBean("CapabilityService"); + vitalRecordService = (VitalRecordService)applicationContext.getBean("VitalRecordService"); + } + + /** + * @see junit.framework.TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception + { + retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() + { + @Override + public Object execute() throws Throwable + { + // As system user + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); + + // Do the tear down + tearDownImpl(); + + return null; + } + }); + } + + /** + * Tear down implementation + */ + protected void tearDownImpl() + { + // Delete the folder + nodeService.deleteNode(folder); + + // Delete the site + siteService.deleteSite(SITE_ID); + } + + /** + * Setup test data for tests + */ + protected void setupTestData() + { + retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() + { + @Override + public Object execute() throws Throwable + { + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + setupTestDataImpl(); + return null; + } + }); + } + + /** + * Impl of test data setup + */ + protected void setupTestDataImpl() + { + storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE; + rootNodeRef = nodeService.getRootNode(storeRef); + + // Create folder + String containerName = "RM2_" + System.currentTimeMillis(); + Map containerProps = new HashMap(1); + containerProps.put(ContentModel.PROP_NAME, containerName); + folder = nodeService.createNode( + rootNodeRef, + ContentModel.ASSOC_CHILDREN, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, containerName), + ContentModel.TYPE_FOLDER, + containerProps).getChildRef(); + assertNotNull("Could not create base folder", folder); + + // Create the site + siteInfo = siteService.createSite("preset", SITE_ID, "title", "descrition", SiteVisibility.PUBLIC, RecordsManagementModel.TYPE_RM_SITE); + filePlan = siteService.getContainer(SITE_ID, RmSiteType.COMPONENT_DOCUMENT_LIBRARY); + assertNotNull("Site document library container was not created successfully.", filePlan); + + recordSeries = rmService.createRecordCategory(filePlan, "recordSeries"); + assertNotNull("Could not create record category with no disposition schedule", recordSeries); + + recordCategory = rmService.createRecordCategory(recordSeries, "rmContainer"); + assertNotNull("Could not create record category", recordCategory); + + // Make vital record + vitalRecordService.setVitalRecordDefintion(recordCategory, true, new Period("week|1")); + + // Create disposition schedule + dispositionSchedule = utils.createBasicDispositionSchedule(recordCategory); + + // Create RM folder + recordFolder = rmService.createRecordFolder(recordCategory, "rmFolder"); + assertNotNull("Could not create rm folder", recordFolder); + recordFolder2 = rmService.createRecordFolder(recordCategory, "rmFolder2"); + assertNotNull("Could not create rm folder 2", recordFolder2); + } +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java new file mode 100644 index 0000000000..e146b08575 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java @@ -0,0 +1,202 @@ +/** + * + */ +package org.alfresco.module.org_alfresco_module_rm.test.util; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; +import org.alfresco.module.org_alfresco_module_rm.action.impl.FreezeAction; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.springframework.context.ApplicationContext; + +/** + * @author Roy Wetherall + */ +public class CommonRMTestUtils implements RecordsManagementModel +{ + private DispositionService dispositionService; + private NodeService nodeService; + private ContentService contentService; + private RecordsManagementActionService actionService; + + /** test values */ + public static final String DEFAULT_DISPOSITION_AUTHORITY = "disposition authority"; + public static final String DEFAULT_DISPOSITION_INSTRUCTIONS = "disposition instructions"; + public static final String DEFAULT_DISPOSITION_DESCRIPTION = "disposition action description"; + public static final String DEFAULT_EVENT_NAME = "case_closed"; + public static final String PERIOD_NONE = "none|0"; + public static final String PERIOD_IMMEDIATELY = "immediately|0"; + + public CommonRMTestUtils(ApplicationContext applicationContext) + { + dispositionService = (DispositionService)applicationContext.getBean("DispositionService"); + nodeService = (NodeService)applicationContext.getBean("NodeService"); + contentService = (ContentService)applicationContext.getBean("ContentService"); + actionService = (RecordsManagementActionService)applicationContext.getBean("RecordsManagementActionService"); + } + + /** + * + * @param container + * @return + */ + public DispositionSchedule createBasicDispositionSchedule(NodeRef container) + { + return createBasicDispositionSchedule(container, DEFAULT_DISPOSITION_INSTRUCTIONS, DEFAULT_DISPOSITION_AUTHORITY, false, true); + } + + /** + * + * @param container + * @param isRecordLevel + * @param defaultDispositionActions + * @return + */ + public DispositionSchedule createBasicDispositionSchedule( + NodeRef container, + String dispositionInstructions, + String dispositionAuthority, + boolean isRecordLevel, + boolean defaultDispositionActions) + { + Map dsProps = new HashMap(3); + dsProps.put(PROP_DISPOSITION_AUTHORITY, dispositionAuthority); + dsProps.put(PROP_DISPOSITION_INSTRUCTIONS, dispositionInstructions); + dsProps.put(PROP_RECORD_LEVEL_DISPOSITION, isRecordLevel); + DispositionSchedule dispositionSchedule = dispositionService.createDispositionSchedule(container, dsProps); + + if (defaultDispositionActions == true) + { + Map adParams = new HashMap(3); + adParams.put(PROP_DISPOSITION_ACTION_NAME, "cutoff"); + adParams.put(PROP_DISPOSITION_DESCRIPTION, DEFAULT_DISPOSITION_DESCRIPTION); + + List events = new ArrayList(1); + events.add(DEFAULT_EVENT_NAME); + adParams.put(PROP_DISPOSITION_EVENT, (Serializable)events); + + dispositionService.addDispositionActionDefinition(dispositionSchedule, adParams); + + adParams = new HashMap(3); + adParams.put(PROP_DISPOSITION_ACTION_NAME, "destroy"); + adParams.put(PROP_DISPOSITION_DESCRIPTION, DEFAULT_DISPOSITION_DESCRIPTION); + adParams.put(PROP_DISPOSITION_PERIOD, "immediately|0"); + + dispositionService.addDispositionActionDefinition(dispositionSchedule, adParams); + } + + return dispositionSchedule; + } + + public NodeRef createRecord(NodeRef recordFolder, String name) + { + return createRecord(recordFolder, name, null, "Some test content"); + } + + public NodeRef createRecord(NodeRef recordFolder, String name, String title) + { + Map props = new HashMap(1); + props.put(ContentModel.PROP_TITLE, title); + return createRecord(recordFolder, name, props, "Some test content"); + } + + public NodeRef createRecord(NodeRef recordFolder, String name, Map properties, String content) + { + // Create the document + if (properties == null) + { + properties = new HashMap(1); + } + if (properties.containsKey(ContentModel.PROP_NAME) == false) + { + properties.put(ContentModel.PROP_NAME, name); + } + NodeRef recordOne = nodeService.createNode(recordFolder, + ContentModel.ASSOC_CONTAINS, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), + ContentModel.TYPE_CONTENT, + properties).getChildRef(); + + // Set the content + ContentWriter writer = contentService.getWriter(recordOne, ContentModel.PROP_CONTENT, true); + writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); + writer.setEncoding("UTF-8"); + writer.putContent(content); + + return recordOne; + } + + public void declareRecord(final NodeRef record) + { + AuthenticationUtil.runAs(new RunAsWork() + { + @Override + public Void doWork() throws Exception + { + // Declare record + nodeService.setProperty(record, RecordsManagementModel.PROP_PUBLICATION_DATE, new Date()); + nodeService.setProperty(record, RecordsManagementModel.PROP_MEDIA_TYPE, "mediaTypeValue"); + nodeService.setProperty(record, RecordsManagementModel.PROP_FORMAT, "formatValue"); + nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_RECEIVED, new Date()); + nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_FILED, new Date()); + nodeService.setProperty(record, RecordsManagementModel.PROP_ORIGINATOR, "origValue"); + nodeService.setProperty(record, RecordsManagementModel.PROP_ORIGINATING_ORGANIZATION, "origOrgValue"); + nodeService.setProperty(record, ContentModel.PROP_TITLE, "titleValue"); + actionService.executeRecordsManagementAction(record, "declareRecord"); + + return null; + } + + }, AuthenticationUtil.getAdminUserName()); + + } + + public void freeze(final NodeRef nodeRef) + { + AuthenticationUtil.runAs(new RunAsWork() + { + @Override + public Void doWork() throws Exception + { + Map params = new HashMap(1); + params.put(FreezeAction.PARAM_REASON, "Freeze reason."); + actionService.executeRecordsManagementAction(nodeRef, "freeze", params); + + return null; + } + + }, AuthenticationUtil.getSystemUserName()); + } + + public void unfreeze(final NodeRef nodeRef) + { + AuthenticationUtil.runAs(new RunAsWork() + { + @Override + public Void doWork() throws Exception + { + actionService.executeRecordsManagementAction(nodeRef, "unfreeze"); + return null; + } + + }, AuthenticationUtil.getSystemUserName()); + } +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestUtilities.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestUtilities.java index 5a1f68f198..214e03d4a9 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestUtilities.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestUtilities.java @@ -24,6 +24,7 @@ import java.io.Reader; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,7 +34,6 @@ import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; -import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementSearchBehaviour; import org.alfresco.module.org_alfresco_module_rm.script.BootstrapTestDataGet; @@ -42,8 +42,6 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef; 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.search.ResultSet; -import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.PermissionService; @@ -51,7 +49,6 @@ import org.alfresco.service.cmr.view.ImporterBinding; import org.alfresco.service.cmr.view.ImporterService; import org.alfresco.service.cmr.view.Location; import org.alfresco.service.namespace.QName; -import org.alfresco.util.ISO9075; import org.springframework.context.ApplicationContext; /** @@ -67,6 +64,22 @@ public class TestUtilities implements RecordsManagementModel return TestUtilities.loadFilePlanData(applicationContext, true, false); } + public static final String TEST_FILE_PLAN_NAME = "testUtilities.filePlan"; + + private static NodeRef getFilePlan(NodeService nodeService, NodeRef rootNode) + { + NodeRef filePlan = null; + + // Try and find a file plan hanging from the root node + List assocs = nodeService.getChildAssocs(rootNode, ContentModel.ASSOC_CHILDREN, TYPE_FILE_PLAN); + if (assocs.size() != 0) + { + filePlan = assocs.get(0).getChildRef(); + } + + return filePlan; + } + public static NodeRef loadFilePlanData(ApplicationContext applicationContext, boolean patchData, boolean alwaysLoad) { NodeService nodeService = (NodeService)applicationContext.getBean("NodeService"); @@ -83,21 +96,18 @@ public class TestUtilities implements RecordsManagementModel NodeRef filePlan = null; NodeRef rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - if (alwaysLoad == false) + if (alwaysLoad == false && getFilePlan(nodeService, rootNode) != null) { - // Try and find a file plan hanging from the root node - List assocs = nodeService.getChildAssocs(rootNode, ContentModel.ASSOC_CHILDREN, TYPE_FILE_PLAN); - if (assocs.size() != 0) - { - filePlan = assocs.get(0).getChildRef(); - return filePlan; - } + return filePlan; } // For now creating the filePlan beneath the + Map props = new HashMap(1); + props.put(ContentModel.PROP_NAME, TEST_FILE_PLAN_NAME); filePlan = nodeService.createNode(rootNode, ContentModel.ASSOC_CHILDREN, TYPE_FILE_PLAN, - TYPE_FILE_PLAN).getChildRef(); + TYPE_FILE_PLAN, + props).getChildRef(); // Do the data load into the the provided filePlan node reference // TODO ... @@ -122,71 +132,42 @@ public class TestUtilities implements RecordsManagementModel return filePlan; } - public static NodeRef getRecordSeries(SearchService searchService, String seriesName) + public static NodeRef getRecordSeries(RecordsManagementService rmService, NodeService nodeService, String seriesName) { - SearchParameters searchParameters = new SearchParameters(); - searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - - String query = "PATH:\"dod:filePlan/cm:" + ISO9075.encode(seriesName) + "\""; - - searchParameters.setQuery(query); - searchParameters.setLanguage(SearchService.LANGUAGE_LUCENE); - ResultSet rs = searchService.query(searchParameters); - try - { - //setComplete(); - //endTransaction(); - return rs.getNodeRefs().isEmpty() ? null : rs.getNodeRef(0); - } - finally - { - rs.close(); - } + NodeRef result = null; + NodeRef rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); + NodeRef filePlan = getFilePlan(nodeService, rootNode); + + if (filePlan != null) + { + result = nodeService.getChildByName(filePlan, ContentModel.ASSOC_CONTAINS, seriesName); + } + return result; } - public static NodeRef getRecordCategory(SearchService searchService, String seriesName, String categoryName) + public static NodeRef getRecordCategory(RecordsManagementService rmService, NodeService nodeService, String seriesName, String categoryName) { - SearchParameters searchParameters = new SearchParameters(); - searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - - String query = "PATH:\"dod:filePlan/cm:" + ISO9075.encode(seriesName) + "/cm:" + ISO9075.encode(categoryName) + "\""; - - searchParameters.setQuery(query); - searchParameters.setLanguage(SearchService.LANGUAGE_LUCENE); - ResultSet rs = searchService.query(searchParameters); - try - { - //setComplete(); - //endTransaction(); - return rs.getNodeRefs().isEmpty() ? null : rs.getNodeRef(0); - } - finally - { - rs.close(); - } + NodeRef seriesNodeRef = getRecordSeries(rmService, nodeService, seriesName); + + NodeRef result = null; + if (seriesNodeRef != null) + { + result = nodeService.getChildByName(seriesNodeRef, ContentModel.ASSOC_CONTAINS, categoryName); + } + return result; } - public static NodeRef getRecordFolder(SearchService searchService, String seriesName, String categoryName, String folderName) + public static NodeRef getRecordFolder(RecordsManagementService rmService, NodeService nodeService, String seriesName, String categoryName, String folderName) { - SearchParameters searchParameters = new SearchParameters(); - searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - String query = "PATH:\"dod:filePlan/cm:" + ISO9075.encode(seriesName) - + "/cm:" + ISO9075.encode(categoryName) - + "/cm:" + ISO9075.encode(folderName) + "\""; - System.out.println("Query: " + query); - searchParameters.setQuery(query); - searchParameters.setLanguage(SearchService.LANGUAGE_LUCENE); - ResultSet rs = searchService.query(searchParameters); - try - { - // setComplete(); - // endTransaction(); - return rs.getNodeRefs().isEmpty() ? null : rs.getNodeRef(0); - } - finally - { - rs.close(); - } + NodeRef categoryNodeRef = getRecordCategory(rmService, nodeService, seriesName, categoryName); + + NodeRef result = null; + if (categoryNodeRef != null) + { + result = nodeService.getChildByName(categoryNodeRef, ContentModel.ASSOC_CONTAINS, folderName); + } + return result; + } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/BootstraptestDataRestApiTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/BootstraptestDataRestApiTest.java index 58c486efdd..e137b85263 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/BootstraptestDataRestApiTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/BootstraptestDataRestApiTest.java @@ -19,6 +19,7 @@ package org.alfresco.module.org_alfresco_module_rm.test.webscript; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.TestUtilities; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper; @@ -33,7 +34,7 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; * * @author Roy Wetherall */ -public class BootstraptestDataRestApiTest extends BaseWebScriptTest implements RecordsManagementModel +public class BootstraptestDataRestApiTest extends BaseRMWebScriptTestCase implements RecordsManagementModel { protected static StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); protected static final String URL = "/api/rma/bootstraptestdata"; diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/DispositionRestApiTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/DispositionRestApiTest.java index 6795639b56..7a6521d4ed 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/DispositionRestApiTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/DispositionRestApiTest.java @@ -18,36 +18,15 @@ */ package org.alfresco.module.org_alfresco_module_rm.test.webscript; -import java.io.Serializable; import java.text.MessageFormat; -import java.util.Date; -import java.util.Map; -import javax.transaction.UserTransaction; - -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; -import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; -import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; -import org.alfresco.module.org_alfresco_module_rm.test.util.TestUtilities; -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; +import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.Period; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.view.ImporterService; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.GUID; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONTokener; @@ -62,7 +41,7 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; * * @author Gavin Cornwell */ -public class DispositionRestApiTest extends BaseWebScriptTest implements RecordsManagementModel +public class DispositionRestApiTest extends BaseRMWebScriptTestCase implements RecordsManagementModel { protected static StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); protected static final String GET_SCHEDULE_URL_FORMAT = "/api/node/{0}/dispositionschedule"; @@ -74,50 +53,6 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records protected static final String SERVICE_URL_PREFIX = "/alfresco/service"; protected static final String APPLICATION_JSON = "application/json"; - protected NodeService nodeService; - protected ContentService contentService; - protected SearchService searchService; - protected ImporterService importService; - protected PermissionService permissionService; - protected TransactionService transactionService; - protected RecordsManagementService rmService; - protected RecordsManagementActionService rmActionService; - protected RecordsManagementEventService rmEventService; - protected RetryingTransactionHelper retryingTransactionHelper; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService"); - this.contentService = (ContentService)getServer().getApplicationContext().getBean("ContentService"); - this.searchService = (SearchService)getServer().getApplicationContext().getBean("SearchService"); - this.importService = (ImporterService)getServer().getApplicationContext().getBean("ImporterService"); - this.permissionService = (PermissionService)getServer().getApplicationContext().getBean("PermissionService"); - this.transactionService = (TransactionService)getServer().getApplicationContext().getBean("TransactionService"); - this.rmService = (RecordsManagementService)getServer().getApplicationContext().getBean("RecordsManagementService"); - this.rmActionService = (RecordsManagementActionService)getServer().getApplicationContext().getBean("RecordsManagementActionService"); - this.rmEventService = (RecordsManagementEventService)getServer().getApplicationContext().getBean("RecordsManagementEventService"); - this.retryingTransactionHelper = (RetryingTransactionHelper)getServer().getApplicationContext().getBean("retryingTransactionHelper"); - - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Void execute() throws Throwable - { - TestUtilities.loadFilePlanData(getServer().getApplicationContext()); - return null; - } - }); - - // Bring the filePlan into the test database. - // - // This is quite a slow call, so if this class grew to have many test methods, - // there would be a real benefit in using something like @BeforeClass for the line below. - //TestUtilities.loadFilePlanData(getServer().getApplicationContext()); - } public void testGetDispositionSchedule() throws Exception { @@ -128,20 +63,16 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records Response rsp = sendRequest(new GetRequest(nonExistentUrl), expectedStatus); // Test 404 status for node that doesn't have dispostion schedule i.e. a record series - NodeRef series = TestUtilities.getRecordSeries(searchService, "Reports"); - assertNotNull(series); - String seriesNodeUrl = series.toString().replace("://", "/"); + String seriesNodeUrl = recordSeries.toString().replace("://", "/"); String wrongNodeUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, seriesNodeUrl); rsp = sendRequest(new GetRequest(wrongNodeUrl), expectedStatus); // Test data structure returned from "AIS Audit Records" expectedStatus = 200; - NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Reports", "AIS Audit Records"); - assertNotNull(recordCategory); + String categoryNodeUrl = recordCategory.toString().replace("://", "/"); String requestUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, categoryNodeUrl); rsp = sendRequest(new GetRequest(requestUrl), expectedStatus); - System.out.println(" 888 GET response: " + rsp.getContentAsString()); assertEquals("application/json;charset=UTF-8", rsp.getContentType()); // get response as JSON @@ -160,10 +91,11 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records assertEquals(serviceUrl, url); String authority = rootDataObject.getString("authority"); - assertEquals("N1-218-00-4 item 023", authority); + + assertEquals(CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, authority); String instructions = rootDataObject.getString("instructions"); - assertEquals("Cut off monthly, hold 1 month, then destroy.", instructions); + assertEquals(CommonRMTestUtils.DEFAULT_DISPOSITION_INSTRUCTIONS, instructions); String actionsUrl = rootDataObject.getString("actionsUrl"); assertEquals(serviceUrl + "/dispositionactiondefinitions", actionsUrl); @@ -177,84 +109,26 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records assertNotNull(actions); assertEquals(2, actions.length()); JSONObject action1 = (JSONObject)actions.get(0); - assertEquals(7, action1.length()); + assertEquals(9, action1.length()); assertNotNull(action1.get("id")); assertNotNull(action1.get("url")); assertEquals(0, action1.getInt("index")); assertEquals("cutoff", action1.getString("name")); assertEquals("Cutoff", action1.getString("label")); - assertEquals("monthend|1", action1.getString("period")); assertTrue(action1.getBoolean("eligibleOnFirstCompleteEvent")); JSONObject action2 = (JSONObject)actions.get(1); assertEquals(8, action2.length()); - assertEquals("rma:cutOffDate", action2.get("periodProperty")); // make sure the disposition schedule node ref is present and valid String scheduleNodeRefJSON = rootDataObject.getString("nodeRef"); NodeRef scheduleNodeRef = new NodeRef(scheduleNodeRefJSON); assertTrue(this.nodeService.exists(scheduleNodeRef)); - // Test data structure returned from "Personnel Security Program Records" - recordCategory = TestUtilities.getRecordCategory(this.searchService, "Civilian Files", "Employee Performance File System Records"); - assertNotNull(recordCategory); - categoryNodeUrl = recordCategory.toString().replace("://", "/"); - requestUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, categoryNodeUrl); - rsp = sendRequest(new GetRequest(requestUrl), expectedStatus); - //System.out.println("GET response: " + rsp.getContentAsString()); - assertEquals("application/json;charset=UTF-8", rsp.getContentType()); - - // get response as JSON - jsonParsedObject = new JSONObject(new JSONTokener(rsp.getContentAsString())); - assertNotNull(jsonParsedObject); - - // check JSON data - dataObj = jsonParsedObject.getJSONObject("data"); - assertNotNull(dataObj); - rootDataObject = (JSONObject)dataObj; - assertEquals(10, rootDataObject.length()); - - // check individual data items - serviceUrl = SERVICE_URL_PREFIX + requestUrl; - url = rootDataObject.getString("url"); - assertEquals(serviceUrl, url); - - authority = rootDataObject.getString("authority"); - assertEquals("GRS 1 item 23b(1)", authority); - - instructions = rootDataObject.getString("instructions"); - assertEquals("Cutoff when superseded. Destroy immediately after cutoff", instructions); - - recordLevel = rootDataObject.getBoolean("recordLevelDisposition"); - assertTrue(recordLevel); - - assertTrue(rootDataObject.getBoolean("canStepsBeRemoved")); - - actions = rootDataObject.getJSONArray("actions"); - assertNotNull(actions); - assertEquals(2, actions.length()); - action1 = (JSONObject)actions.get(0); - assertEquals(8, action1.length()); - assertNotNull(action1.get("id")); - assertNotNull(action1.get("url")); - assertEquals(0, action1.getInt("index")); - assertEquals("cutoff", action1.getString("name")); - assertEquals("Cutoff", action1.getString("label")); - assertTrue(action1.getBoolean("eligibleOnFirstCompleteEvent")); - JSONArray events = action1.getJSONArray("events"); - assertNotNull(events); - assertEquals(1, events.length()); - assertEquals("superseded", events.get(0)); - - // Test the retrieval of an empty disposition schedule - NodeRef recordSeries = TestUtilities.getRecordSeries(this.searchService, "Civilian Files"); - assertNotNull(recordSeries); - // create a new recordCategory node in the recordSeries and then get // the disposition schedule - NodeRef newRecordCategory = this.nodeService.createNode(recordSeries, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("recordCategory")), - TYPE_RECORD_CATEGORY).getChildRef(); + NodeRef newRecordCategory = rmService.createRecordCategory(recordSeries, GUID.generate()); + dispositionService.createDispositionSchedule(newRecordCategory, null); categoryNodeUrl = newRecordCategory.toString().replace("://", "/"); requestUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, categoryNodeUrl); @@ -278,15 +152,10 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records public void testPostDispositionAction() throws Exception { - // create a recordCategory to get a disposition schedule - NodeRef recordSeries = TestUtilities.getRecordSeries(this.searchService, "Civilian Files"); - assertNotNull(recordSeries); - // create a new recordCategory node in the recordSeries and then get // the disposition schedule - NodeRef newRecordCategory = this.nodeService.createNode(recordSeries, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("recordCategory")), - TYPE_RECORD_CATEGORY).getChildRef(); + NodeRef newRecordCategory = rmService.createRecordCategory(recordSeries, GUID.generate()); + dispositionService.createDispositionSchedule(newRecordCategory, null); String categoryNodeUrl = newRecordCategory.toString().replace("://", "/"); String requestUrl = MessageFormat.format(POST_ACTIONDEF_URL_FORMAT, categoryNodeUrl); @@ -363,13 +232,8 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records public void testPutDispositionAction() throws Exception { - // create a new recordCategory node in the recordSeries and then get - // the disposition schedule - NodeRef recordSeries = TestUtilities.getRecordSeries(this.searchService, "Civilian Files"); - assertNotNull(recordSeries); - NodeRef newRecordCategory = this.nodeService.createNode(recordSeries, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("recordCategory")), - TYPE_RECORD_CATEGORY).getChildRef(); + NodeRef newRecordCategory = rmService.createRecordCategory(recordSeries, GUID.generate()); + dispositionService.createDispositionSchedule(newRecordCategory, null); // create an action definition to then update String categoryNodeUrl = newRecordCategory.toString().replace("://", "/"); @@ -437,13 +301,8 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records public void testDeleteDispositionAction() throws Exception { - // create a new recordCategory node in the recordSeries and then get - // the disposition schedule - NodeRef recordSeries = TestUtilities.getRecordSeries(this.searchService, "Civilian Files"); - assertNotNull(recordSeries); - NodeRef newRecordCategory = this.nodeService.createNode(recordSeries, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("recordCategory")), - TYPE_RECORD_CATEGORY).getChildRef(); + NodeRef newRecordCategory = rmService.createRecordCategory(recordSeries, GUID.generate()); + dispositionService.createDispositionSchedule(newRecordCategory, null); // create an action definition to then delete String categoryNodeUrl = newRecordCategory.toString().replace("://", "/"); @@ -477,51 +336,18 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records public void testGetDispositionLifecycle() throws Exception { - // create a new recordFolder in a recordCategory - NodeRef recordCategory = TestUtilities.getRecordCategory(this.searchService, "Military Files", - "Military Assignment Documents"); - assertNotNull(recordCategory); - // Test 404 for disposition lifecycle request on incorrect node String categoryUrl = recordCategory.toString().replace("://", "/"); String requestUrl = MessageFormat.format(GET_LIFECYCLE_URL_FORMAT, categoryUrl); Response rsp = sendRequest(new GetRequest(requestUrl), 404); - UserTransaction txn = transactionService.getUserTransaction(false); - txn.begin(); - - NodeRef newRecordFolder = this.nodeService.createNode(recordCategory, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("recordFolder")), - TYPE_RECORD_FOLDER).getChildRef(); - - txn.commit(); - txn = transactionService.getUserTransaction(false); - txn.begin(); - - // Create the document - NodeRef recordOne = this.nodeService.createNode(newRecordFolder, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "record"), - ContentModel.TYPE_CONTENT).getChildRef(); - - // Set the content - ContentWriter writer = this.contentService.getWriter(recordOne, ContentModel.PROP_CONTENT, true); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer.setEncoding("UTF-8"); - writer.putContent("There is some content in this record"); - - txn.commit(); // - triggers FileAction - - txn = transactionService.getUserTransaction(false); - txn.begin(); - declareRecord(recordOne); - txn.commit(); + NodeRef newRecordFolder = rmService.createRecordFolder(recordCategory, "recordFolder"); + // there should now be a disposition lifecycle for the record - String recordUrl = recordOne.toString().replace("://", "/"); - requestUrl = MessageFormat.format(GET_LIFECYCLE_URL_FORMAT, recordUrl); + requestUrl = MessageFormat.format(GET_LIFECYCLE_URL_FORMAT, newRecordFolder.toString().replace("://", "/")); rsp = sendRequest(new GetRequest(requestUrl), 200); - //System.out.println("GET : " + rsp.getContentAsString()); + System.out.println("GET : " + rsp.getContentAsString()); assertEquals("application/json;charset=UTF-8", rsp.getContentType()); // get response as JSON @@ -538,10 +364,10 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records JSONArray events = dataObj.getJSONArray("events"); assertEquals(1, events.length()); JSONObject event1 = events.getJSONObject(0); - assertEquals("superseded", event1.get("name")); - assertEquals("Superseded", event1.get("label")); + assertEquals("case_closed", event1.get("name")); + assertEquals("Case Closed", event1.get("label")); assertFalse(event1.getBoolean("complete")); - assertTrue(event1.getBoolean("automatic")); + assertFalse(event1.getBoolean("automatic")); // check stuff expected to be missing is missing assertFalse(dataObj.has("asOf")); @@ -556,10 +382,8 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records public void testGetListOfValues() throws Exception { // call the list service - Response rsp = sendRequest(new GetRequest(GET_LIST_URL), 200); - //System.out.println("GET : " + rsp.getContentAsString()); + Response rsp = sendRequest(new GetRequest(GET_LIST_URL), 200); assertEquals("application/json;charset=UTF-8", rsp.getContentType()); - //System.out.println(rsp.getContentAsString()); // get response as JSON JSONObject jsonParsedObject = new JSONObject(new JSONTokener(rsp.getContentAsString())); @@ -570,7 +394,7 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records JSONObject actions = data.getJSONObject("dispositionActions"); assertEquals(SERVICE_URL_PREFIX + GET_LIST_URL + "/dispositionactions", actions.getString("url")); JSONArray items = actions.getJSONArray("items"); - assertEquals(this.rmActionService.getDispositionActions().size(), items.length()); + assertEquals(actionService.getDispositionActions().size(), items.length()); assertTrue(items.length() > 0); JSONObject item = items.getJSONObject(0); assertTrue(item.length() == 2); @@ -581,7 +405,7 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records JSONObject events = data.getJSONObject("events"); assertEquals(SERVICE_URL_PREFIX + GET_LIST_URL + "/events", events.getString("url")); items = events.getJSONArray("items"); - assertEquals(this.rmEventService.getEvents().size(), items.length()); + assertEquals(eventService.getEvents().size(), items.length()); assertTrue(items.length() > 0); item = items.getJSONObject(0); assertTrue(item.length() == 3); @@ -611,23 +435,4 @@ public class DispositionRestApiTest extends BaseWebScriptTest implements Records assertTrue(item.has("label")); assertTrue(item.has("value")); } - - private void declareRecord(NodeRef recordOne) - { - // Declare record - Map propValues = this.nodeService.getProperties(recordOne); - propValues.put(RecordsManagementModel.PROP_PUBLICATION_DATE, new Date()); - // List smList = new ArrayList(2); - // smList.add("FOUO"); - // smList.add("NOFORN"); - // propValues.put(RecordsManagementModel.PROP_SUPPLEMENTAL_MARKING_LIST, (Serializable)smList); - propValues.put(RecordsManagementModel.PROP_MEDIA_TYPE, "mediaTypeValue"); - propValues.put(RecordsManagementModel.PROP_FORMAT, "formatValue"); - propValues.put(RecordsManagementModel.PROP_DATE_RECEIVED, new Date()); - propValues.put(RecordsManagementModel.PROP_ORIGINATOR, "origValue"); - propValues.put(RecordsManagementModel.PROP_ORIGINATING_ORGANIZATION, "origOrgValue"); - propValues.put(ContentModel.PROP_TITLE, "titleValue"); - this.nodeService.setProperties(recordOne, propValues); - this.rmActionService.executeRecordsManagementAction(recordOne, "declareRecord"); - } } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/EmailMapScriptTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/EmailMapScriptTest.java index 90c0a574f8..1187aebf9b 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/EmailMapScriptTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/EmailMapScriptTest.java @@ -18,8 +18,8 @@ */ package org.alfresco.module.org_alfresco_module_rm.test.webscript; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; import org.alfresco.service.cmr.security.AuthenticationService; import org.json.JSONArray; import org.json.JSONObject; @@ -28,7 +28,7 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.Response; -public class EmailMapScriptTest extends BaseWebScriptTest +public class EmailMapScriptTest extends BaseRMWebScriptTestCase { public final static String URL_RM_EMAILMAP = "/api/rma/admin/emailmap"; diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/EventRestApiTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/EventRestApiTest.java index c1b1aa5a66..8b8229278c 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/EventRestApiTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/EventRestApiTest.java @@ -18,54 +18,34 @@ */ package org.alfresco.module.org_alfresco_module_rm.test.webscript; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; -import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; import org.alfresco.util.GUID; +import org.json.JSONObject; import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.Response; -import org.json.JSONObject; /** * RM event REST API test * * @author Roy Wetherall */ -public class EventRestApiTest extends BaseWebScriptTest implements RecordsManagementModel +public class EventRestApiTest extends BaseRMWebScriptTestCase implements RecordsManagementModel { - protected static StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); protected static final String GET_EVENTS_URL = "/api/rma/admin/rmevents"; protected static final String GET_EVENTTYPES_URL = "/api/rma/admin/rmeventtypes"; protected static final String SERVICE_URL_PREFIX = "/alfresco/service"; protected static final String APPLICATION_JSON = "application/json"; + protected static final String DISPLAY_LABEL = "display label"; protected static final String EVENT_TYPE = "rmEventType.simple"; protected static final String KEY_EVENT_NAME = "eventName"; protected static final String KEY_EVENT_TYPE = "eventType"; protected static final String KEY_EVENT_DISPLAY_LABEL = "eventDisplayLabel"; - - protected NodeService nodeService; - protected RecordsManagementService rmService; - protected RecordsManagementEventService rmEventService; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService"); - this.rmService = (RecordsManagementService)getServer().getApplicationContext().getBean("RecordsManagementService"); - this.rmEventService = (RecordsManagementEventService)getServer().getApplicationContext().getBean("RecordsManagementEventService"); - - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - } - + public void testGetEventTypes() throws Exception { Response rsp = sendRequest(new GetRequest(GET_EVENTTYPES_URL),200); @@ -89,8 +69,8 @@ public class EventRestApiTest extends BaseWebScriptTest implements RecordsManage String event2 = GUID.generate(); // Create a couple or events by hand - rmEventService.addEvent(EVENT_TYPE, event1, DISPLAY_LABEL); - rmEventService.addEvent(EVENT_TYPE, event2, DISPLAY_LABEL); + eventService.addEvent(EVENT_TYPE, event1, DISPLAY_LABEL); + eventService.addEvent(EVENT_TYPE, event2, DISPLAY_LABEL); try { @@ -117,8 +97,8 @@ public class EventRestApiTest extends BaseWebScriptTest implements RecordsManage finally { // Clean up - rmEventService.removeEvent(event1); - rmEventService.removeEvent(event2); + eventService.removeEvent(event1); + eventService.removeEvent(event2); } } @@ -148,7 +128,7 @@ public class EventRestApiTest extends BaseWebScriptTest implements RecordsManage } finally { - rmEventService.removeEvent(eventName); + eventService.removeEvent(eventName); } // Test with no event name set @@ -172,14 +152,14 @@ public class EventRestApiTest extends BaseWebScriptTest implements RecordsManage } finally { - rmEventService.removeEvent(eventName); + eventService.removeEvent(eventName); } } public void testPutRole() throws Exception { String eventName = GUID.generate(); - rmEventService.addEvent(EVENT_TYPE, eventName, DISPLAY_LABEL); + eventService.addEvent(EVENT_TYPE, eventName, DISPLAY_LABEL); try { @@ -206,7 +186,7 @@ public class EventRestApiTest extends BaseWebScriptTest implements RecordsManage finally { // Clean up - rmEventService.removeEvent(eventName); + eventService.removeEvent(eventName); } } @@ -214,7 +194,7 @@ public class EventRestApiTest extends BaseWebScriptTest implements RecordsManage public void testGetRole() throws Exception { String eventName = GUID.generate(); - rmEventService.addEvent(EVENT_TYPE, eventName, DISPLAY_LABEL); + eventService.addEvent(EVENT_TYPE, eventName, DISPLAY_LABEL); try { @@ -236,7 +216,7 @@ public class EventRestApiTest extends BaseWebScriptTest implements RecordsManage finally { // Clean up - rmEventService.removeEvent(eventName); + eventService.removeEvent(eventName); } } @@ -244,11 +224,11 @@ public class EventRestApiTest extends BaseWebScriptTest implements RecordsManage public void testDeleteRole() throws Exception { String eventName = GUID.generate(); - assertFalse(rmEventService.existsEvent(eventName)); - rmEventService.addEvent(EVENT_TYPE, eventName, DISPLAY_LABEL); - assertTrue(rmEventService.existsEvent(eventName)); + assertFalse(eventService.existsEvent(eventName)); + eventService.addEvent(EVENT_TYPE, eventName, DISPLAY_LABEL); + assertTrue(eventService.existsEvent(eventName)); sendRequest(new DeleteRequest(GET_EVENTS_URL + "/" + eventName),200); - assertFalse(rmEventService.existsEvent(eventName)); + assertFalse(eventService.existsEvent(eventName)); // Bad request sendRequest(new DeleteRequest(GET_EVENTS_URL + "/cheese"), 404); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RMCaveatConfigScriptTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RMCaveatConfigScriptTest.java index 4caab0b1ca..c7e17a2ba6 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RMCaveatConfigScriptTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RMCaveatConfigScriptTest.java @@ -23,8 +23,8 @@ import java.util.List; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.util.PropertyMap; @@ -42,14 +42,12 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; * * @author Mark Rogers */ -public class RMCaveatConfigScriptTest extends BaseWebScriptTest +public class RMCaveatConfigScriptTest extends BaseRMWebScriptTestCase { private MutableAuthenticationService authenticationService; private RMCaveatConfigService caveatConfigService; private PersonService personService; - private static final String USER_ONE = "RMCaveatConfigTestOne"; - private static final String USER_TWO = "RMCaveatConfigTestTwo"; protected final static String RM_LIST = "rmc:smListTest"; protected final static String RM_LIST_URI_ELEM = "rmc_smListTest"; @@ -57,16 +55,13 @@ public class RMCaveatConfigScriptTest extends BaseWebScriptTest private static final String URL_RM_CONSTRAINTS = "/api/rma/admin/rmconstraints"; @Override - protected void setUp() throws Exception + protected void initServices() { - super.setUp(); - - this.caveatConfigService = (RMCaveatConfigService)getServer().getApplicationContext().getBean("CaveatConfigService"); + super.initServices(); + + this.caveatConfigService = (RMCaveatConfigService)getServer().getApplicationContext().getBean("CaveatConfigService"); this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); - - // Set the current security context as admin - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); } private void createUser(String userName) @@ -87,14 +82,6 @@ public class RMCaveatConfigScriptTest extends BaseWebScriptTest } } - @Override - protected void tearDown() throws Exception - { - super.tearDown(); - //this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); - - } - public void testGetRMConstraints() throws Exception { diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RMConstraintScriptTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RMConstraintScriptTest.java index b3cdd47bbc..6116258954 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RMConstraintScriptTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RMConstraintScriptTest.java @@ -23,12 +23,11 @@ import java.util.List; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.util.PropertyMap; -import org.json.JSONArray; import org.json.JSONObject; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; @@ -39,7 +38,7 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; * * @author Mark Rogers */ -public class RMConstraintScriptTest extends BaseWebScriptTest +public class RMConstraintScriptTest extends BaseRMWebScriptTestCase { private MutableAuthenticationService authenticationService; private RMCaveatConfigService caveatConfigService; @@ -51,18 +50,13 @@ public class RMConstraintScriptTest extends BaseWebScriptTest private static final String URL_RM_CONSTRAINTS = "/api/rma/rmconstraints"; @Override - protected void setUp() throws Exception + protected void initServices() { + super.initServices(); + this.caveatConfigService = (RMCaveatConfigService)getServer().getApplicationContext().getBean("CaveatConfigService"); this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); - super.setUp(); - } - - @Override - protected void tearDown() throws Exception - { - super.tearDown(); } /** @@ -108,32 +102,11 @@ public class RMConstraintScriptTest extends BaseWebScriptTest JSONObject data = top.getJSONObject("data"); System.out.println(response.getContentAsString()); - JSONArray allowedValues = data.getJSONArray("allowedValuesForCurrentUser"); - -// assertTrue("values not correct", compare(array, allowedValues)); - -// JSONArray constraintDetails = data.getJSONArray("constraintDetails"); -// -// assertTrue("details array does not contain 3 elements", constraintDetails.length() == 3); -// for(int i =0; i < constraintDetails.length(); i++) -// { -// JSONObject detail = constraintDetails.getJSONObject(i); -// } + data.getJSONArray("allowedValuesForCurrentUser"); + } - /** - * - * @throws Exception - */ - -// /** -// * Negative test - Attempt to get a constraint that does exist -// */ -// { -// String url = URL_RM_CONSTRAINTS + "/" + "rmc_wibble"; -// sendRequest(new GetRequest(url), Status.STATUS_NOT_FOUND); -// } -// + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); personService.deletePerson("fbloggs"); personService.deletePerson("jrogers"); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RmRestApiTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RmRestApiTest.java index ed44c7db6e..24e0cce361 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RmRestApiTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RmRestApiTest.java @@ -22,49 +22,19 @@ import java.io.IOException; import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.text.MessageFormat; -import java.util.Calendar; import java.util.Date; -import java.util.HashMap; -import java.util.List; import java.util.Map; -import javax.transaction.UserTransaction; - -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminServiceImpl; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; -import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; -import org.alfresco.module.org_alfresco_module_rm.action.impl.CompleteEventAction; -import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditService; -import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction; -import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomModel; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.script.CustomReferenceType; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.TestActionParams; -import org.alfresco.module.org_alfresco_module_rm.test.util.TestUtilities; -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; -import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AssociationDefinition; -import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.ContentWriter; 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.search.ResultSet; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.cmr.view.ImporterService; -import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; -import org.alfresco.service.namespace.RegexQNamePattern; -import org.alfresco.service.transaction.TransactionService; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -82,7 +52,7 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; * * @author Neil McErlean */ -public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagementModel +public class RmRestApiTest extends BaseRMWebScriptTestCase implements RecordsManagementModel { protected static final String GET_NODE_AUDITLOG_URL_FORMAT = "/api/node/{0}/rmauditlog"; protected static final String GET_TRANSFER_URL_FORMAT = "/api/node/{0}/transfers/{1}"; @@ -95,60 +65,60 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen protected static final String APPLICATION_JSON = "application/json"; protected static final String RMA_CUSTOM_PROPS_DEFINITIONS_URL = "/api/rma/admin/custompropertydefinitions"; protected static final String RMA_CUSTOM_REFS_DEFINITIONS_URL = "/api/rma/admin/customreferencedefinitions"; - protected NamespaceService namespaceService; - protected NodeService nodeService; - protected ContentService contentService; - protected DictionaryService dictionaryService; - protected SearchService searchService; - protected ImporterService importService; - protected TransactionService transactionService; - protected ServiceRegistry services; - protected RecordsManagementService rmService; - protected RecordsManagementActionService rmActionService; - protected RecordsManagementAuditService rmAuditService; - protected RecordsManagementAdminService rmAdminService; - protected RetryingTransactionHelper transactionHelper; - protected DispositionService dispositionService; +// protected NamespaceService namespaceService; +// protected NodeService nodeService; +// protected ContentService contentService; +// protected DictionaryService dictionaryService; +// protected SearchService searchService; +// protected ImporterService importService; +// protected TransactionService transactionService; +// protected ServiceRegistry services; +// protected RecordsManagementService rmService; +// protected RecordsManagementActionService rmActionService; +// protected RecordsManagementAuditService rmAuditService; +// protected RecordsManagementAdminService rmAdminService; +// protected RetryingTransactionHelper transactionHelper; +// protected DispositionService dispositionService; private static final String BI_DI = "BiDi"; private static final String CHILD_SRC = "childSrc"; private static final String CHILD_TGT = "childTgt"; - @Override - protected void setUp() throws Exception - { - setCustomContext("classpath:test-context.xml"); - - super.setUp(); - this.namespaceService = (NamespaceService) getServer().getApplicationContext().getBean("NamespaceService"); - this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService"); - this.contentService = (ContentService)getServer().getApplicationContext().getBean("ContentService"); - this.dictionaryService = (DictionaryService)getServer().getApplicationContext().getBean("DictionaryService"); - this.searchService = (SearchService)getServer().getApplicationContext().getBean("SearchService"); - this.importService = (ImporterService)getServer().getApplicationContext().getBean("ImporterService"); - this.transactionService = (TransactionService)getServer().getApplicationContext().getBean("TransactionService"); - this.services = (ServiceRegistry)getServer().getApplicationContext().getBean("ServiceRegistry"); - this.rmService = (RecordsManagementService)getServer().getApplicationContext().getBean("RecordsManagementService"); - this.rmActionService = (RecordsManagementActionService)getServer().getApplicationContext().getBean("RecordsManagementActionService"); - this.rmAuditService = (RecordsManagementAuditService)getServer().getApplicationContext().getBean("RecordsManagementAuditService"); - this.rmAdminService = (RecordsManagementAdminService)getServer().getApplicationContext().getBean("RecordsManagementAdminService"); - transactionHelper = (RetryingTransactionHelper)getServer().getApplicationContext().getBean("retryingTransactionHelper"); - dispositionService = (DispositionService)getServer().getApplicationContext().getBean("DispositionService"); - - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - - // Bring the filePlan into the test database. - // - // This is quite a slow call, so if this class grew to have many test methods, - // there would be a real benefit in using something like @BeforeClass for the line below. - transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() - { - public NodeRef execute() throws Throwable - { - return TestUtilities.loadFilePlanData(getServer().getApplicationContext()); - } - }); - } +// @Override +// protected void setUp() throws Exception +// { +// setCustomContext("classpath:test-context.xml"); +// +// super.setUp(); +// this.namespaceService = (NamespaceService) getServer().getApplicationContext().getBean("NamespaceService"); +// this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService"); +// this.contentService = (ContentService)getServer().getApplicationContext().getBean("ContentService"); +// this.dictionaryService = (DictionaryService)getServer().getApplicationContext().getBean("DictionaryService"); +// this.searchService = (SearchService)getServer().getApplicationContext().getBean("SearchService"); +// this.importService = (ImporterService)getServer().getApplicationContext().getBean("ImporterService"); +// this.transactionService = (TransactionService)getServer().getApplicationContext().getBean("TransactionService"); +// this.services = (ServiceRegistry)getServer().getApplicationContext().getBean("ServiceRegistry"); +// this.rmService = (RecordsManagementService)getServer().getApplicationContext().getBean("RecordsManagementService"); +// this.rmActionService = (RecordsManagementActionService)getServer().getApplicationContext().getBean("RecordsManagementActionService"); +// this.rmAuditService = (RecordsManagementAuditService)getServer().getApplicationContext().getBean("RecordsManagementAuditService"); +// this.rmAdminService = (RecordsManagementAdminService)getServer().getApplicationContext().getBean("RecordsManagementAdminService"); +// transactionHelper = (RetryingTransactionHelper)getServer().getApplicationContext().getBean("retryingTransactionHelper"); +// dispositionService = (DispositionService)getServer().getApplicationContext().getBean("DispositionService"); +// +// AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); +// +// // Bring the filePlan into the test database. +// // +// // This is quite a slow call, so if this class grew to have many test methods, +// // there would be a real benefit in using something like @BeforeClass for the line below. +// transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() +// { +// public NodeRef execute() throws Throwable +// { +// return TestUtilities.loadFilePlanData(getServer().getApplicationContext()); +// } +// }); +// } /** * This test method ensures that a POST of an RM action to a non-existent node @@ -156,12 +126,8 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen * * @throws Exception */ - // TODO taken out for now - public void xtestPostActionToNonExistentNode() throws Exception + public void testPostActionToNonExistentNode() throws Exception { - NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); - assertNotNull(recordCategory); - NodeRef nonExistentNode = new NodeRef("workspace://SpacesStore/09ca1e02-1c87-4a53-97e7-xxxxxxxxxxxx"); // Construct the JSON request. @@ -181,24 +147,7 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen public void testPostReviewedAction() throws IOException, JSONException { - // Get the recordCategory under which we will create the testNode. - NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); - assertNotNull(recordCategory); - - NodeRef recordFolder = TestUtilities.getRecordFolder(searchService, "Reports", "AIS Audit Records", "January AIS Audit Records"); - assertNotNull(recordFolder); - - // Create a testNode/file which is to be declared as a record. - NodeRef testRecord = this.nodeService.createNode(recordFolder, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "MyRecord.txt"), - ContentModel.TYPE_CONTENT).getChildRef(); - - // Set some dummy content. - ContentWriter writer = this.contentService.getWriter(testRecord, ContentModel.PROP_CONTENT, true); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer.setEncoding("UTF-8"); - writer.putContent("There is some content in this record"); + NodeRef testRecord = utils.createRecord(recordFolder, "test.txt"); // In this test, this property has a date-value equal to the model import time. Serializable pristineReviewAsOf = this.nodeService.getProperty(testRecord, PROP_REVIEW_AS_OF); @@ -230,46 +179,9 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen public void testPostMultiReviewedAction() throws IOException, JSONException { - // Get the recordCategory under which we will create the testNode. - NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Reports", "AIS Audit Records"); - assertNotNull(recordCategory); - - NodeRef recordFolder = TestUtilities.getRecordFolder(searchService, "Reports", "AIS Audit Records", "January AIS Audit Records"); - assertNotNull(recordFolder); - - // Create a testNode/file which is to be declared as a record. - NodeRef testRecord = this.nodeService.createNode(recordFolder, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "MyRecord.txt"), - ContentModel.TYPE_CONTENT).getChildRef(); - - // Set some dummy content. - ContentWriter writer = this.contentService.getWriter(testRecord, ContentModel.PROP_CONTENT, true); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer.setEncoding("UTF-8"); - writer.putContent("There is some content in this record"); - - NodeRef testRecord2 = this.nodeService.createNode(recordFolder, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "MyRecord2.txt"), - ContentModel.TYPE_CONTENT).getChildRef(); - - // Set some dummy content. - writer = this.contentService.getWriter(testRecord2, ContentModel.PROP_CONTENT, true); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer.setEncoding("UTF-8"); - writer.putContent("There is some content in this record"); - - NodeRef testRecord3 = this.nodeService.createNode(recordFolder, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "MyRecord3.txt"), - ContentModel.TYPE_CONTENT).getChildRef(); - - // Set some dummy content. - writer = this.contentService.getWriter(testRecord3, ContentModel.PROP_CONTENT, true); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer.setEncoding("UTF-8"); - writer.putContent("There is some content in this record"); + NodeRef testRecord = utils.createRecord(recordFolder, "test1.txt"); + NodeRef testRecord2 = utils.createRecord(recordFolder, "test2.txt"); + NodeRef testRecord3 = utils.createRecord(recordFolder, "test3.txt"); // In this test, this property has a date-value equal to the model import time. Serializable pristineReviewAsOf = this.nodeService.getProperty(testRecord, PROP_REVIEW_AS_OF); @@ -332,8 +244,8 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen // Submit the JSON request. final int expectedStatus = 200; //TODO Currently failing unit test. -// Response rsp = sendRequest(new PostRequest(RMA_ACTIONS_URL, -// jsonString, APPLICATION_JSON), expectedStatus); + sendRequest(new PostRequest(RMA_ACTIONS_URL, + jsonString, APPLICATION_JSON), expectedStatus); } public void testPostCustomReferenceDefinitions() throws IOException, JSONException @@ -402,11 +314,11 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen dictionaryService.getAspect(QName.createQName(RecordsManagementAdminServiceImpl.RMC_CUSTOM_ASSOCS, namespaceService)); assertNotNull("Missing customAssocs aspect", customAssocsAspect); - QName newRefQname = rmAdminService.getQNameForClientId(generatedChildRefId); + QName newRefQname = adminService.getQNameForClientId(generatedChildRefId); Map associations = customAssocsAspect.getAssociations(); assertTrue("Custom child assoc not returned by dataDictionary.", associations.containsKey(newRefQname)); - newRefQname = rmAdminService.getQNameForClientId(generatedBidiRefId); + newRefQname = adminService.getQNameForClientId(generatedBidiRefId); assertTrue("Custom std assoc not returned by dataDictionary.", customAssocsAspect.getAssociations().containsKey(newRefQname)); return result; @@ -609,10 +521,8 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen public void testGetPostAndRemoveCustomReferenceInstances() throws Exception { - // Create test records. - NodeRef recordFolder = retrievePreexistingRecordFolder(); - NodeRef testRecord1 = createRecord(recordFolder, "testRecord1" + System.currentTimeMillis(), "The from recørd"); - NodeRef testRecord2 = createRecord(recordFolder, "testRecord2" + System.currentTimeMillis(), "The to récord"); + NodeRef testRecord1 = utils.createRecord(recordFolder, "testRecord1" + System.currentTimeMillis(), "The from recørd"); + NodeRef testRecord2 = utils.createRecord(recordFolder, "testRecord2" + System.currentTimeMillis(), "The to récord"); String node1Url = testRecord1.toString().replace("://", "/"); String refInstancesRecord1Url = MessageFormat.format(REF_INSTANCES_URL_FORMAT, node1Url); @@ -722,9 +632,8 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen public void testMob1630ShouldNotBeAbleToCreateTwoSupersedesReferencesOnOneRecordPair() throws Exception { // Create 2 test records. - NodeRef recordFolder = retrievePreexistingRecordFolder(); - NodeRef testRecord1 = createRecord(recordFolder, "testRecord1" + System.currentTimeMillis(), "The from recørd"); - NodeRef testRecord2 = createRecord(recordFolder, "testRecord2" + System.currentTimeMillis(), "The to récord"); + NodeRef testRecord1 = utils.createRecord(recordFolder, "testRecord1" + System.currentTimeMillis(), "The from recørd"); + NodeRef testRecord2 = utils.createRecord(recordFolder, "testRecord2" + System.currentTimeMillis(), "The to récord"); String node1Url = testRecord1.toString().replace("://", "/"); String node2Url = testRecord2.toString().replace("://", "/"); @@ -1042,27 +951,19 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen JSONArray aspects = dataObj.getJSONArray("recordMetaDataAspects"); assertNotNull(aspects); - assertEquals(5, aspects.length()); + assertEquals(4, aspects.length()); // TODO test the items themselves } public void testExport() throws Exception { - NodeRef recordFolder1 = TestUtilities.getRecordFolder(searchService, "Reports", - "AIS Audit Records", "January AIS Audit Records"); - assertNotNull(recordFolder1); - - NodeRef recordFolder2 = TestUtilities.getRecordFolder(searchService, "Reports", - "Unit Manning Documents", "1st Quarter Unit Manning Documents"); - assertNotNull(recordFolder2); - String exportUrl = "/api/rma/admin/export"; // define JSON POST body JSONObject jsonPostData = new JSONObject(); JSONArray nodeRefs = new JSONArray(); - nodeRefs.put(recordFolder1.toString()); + nodeRefs.put(recordFolder.toString()); nodeRefs.put(recordFolder2.toString()); jsonPostData.put("nodeRefs", nodeRefs); String jsonPostString = jsonPostData.toString(); @@ -1074,20 +975,12 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen public void testExportInTransferFormat() throws Exception { - NodeRef recordFolder1 = TestUtilities.getRecordFolder(searchService, "Reports", - "AIS Audit Records", "January AIS Audit Records"); - assertNotNull(recordFolder1); - - NodeRef recordFolder2 = TestUtilities.getRecordFolder(searchService, "Reports", - "Unit Manning Documents", "1st Quarter Unit Manning Documents"); - assertNotNull(recordFolder2); - String exportUrl = "/api/rma/admin/export"; // define JSON POST body JSONObject jsonPostData = new JSONObject(); JSONArray nodeRefs = new JSONArray(); - nodeRefs.put(recordFolder1.toString()); + nodeRefs.put(recordFolder.toString()); nodeRefs.put(recordFolder2.toString()); jsonPostData.put("nodeRefs", nodeRefs); jsonPostData.put("transferFormat", true); @@ -1098,216 +991,6 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen assertEquals("application/zip", rsp.getContentType()); } - public void testTransfer() throws Exception - { - // Test 404 status for non existent node - String transferId = "yyy"; - String nonExistentNode = "workspace/SpacesStore/09ca1e02-1c87-4a53-97e7-xxxxxxxxxxxx"; - String nonExistentUrl = MessageFormat.format(GET_TRANSFER_URL_FORMAT, nonExistentNode, transferId); - Response rsp = sendRequest(new GetRequest(nonExistentUrl), 404); - - // Test 400 status for node that isn't a file plan - NodeRef series = TestUtilities.getRecordSeries(searchService, "Reports"); - assertNotNull(series); - String seriesNodeUrl = series.toString().replace("://", "/"); - String wrongNodeUrl = MessageFormat.format(GET_TRANSFER_URL_FORMAT, seriesNodeUrl, transferId); - rsp = sendRequest(new GetRequest(wrongNodeUrl), 400); - - // Test 404 status for file plan with no transfers - NodeRef rootNode = this.rmService.getFilePlan(series); - String rootNodeUrl = rootNode.toString().replace("://", "/"); - String transferUrl = MessageFormat.format(GET_TRANSFER_URL_FORMAT, rootNodeUrl, transferId); - rsp = sendRequest(new GetRequest(transferUrl), 404); - - // Get test in state where a transfer will be present - NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Civilian Files", "Foreign Employee Award Files"); - assertNotNull(recordCategory); - - UserTransaction txn = transactionService.getUserTransaction(false); - txn.begin(); - - NodeRef newRecordFolder = this.nodeService.createNode(recordCategory, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("recordFolder")), - TYPE_RECORD_FOLDER).getChildRef(); - Map folderProps = new HashMap(1); - folderProps.put(PROP_IDENTIFIER, "2009-000000" + nodeService.getProperty(newRecordFolder, ContentModel.PROP_NODE_DBID)); - nodeService.addProperties(newRecordFolder, folderProps); - - txn.commit(); - txn = transactionService.getUserTransaction(false); - txn.begin(); - - // Create 2 documents - Map props1 = new HashMap(1); - props1.put(ContentModel.PROP_NAME, "record1"); - NodeRef recordOne = this.nodeService.createNode(newRecordFolder, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "record1"), - ContentModel.TYPE_CONTENT, props1).getChildRef(); - - // Set the content - ContentWriter writer1 = this.contentService.getWriter(recordOne, ContentModel.PROP_CONTENT, true); - writer1.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer1.setEncoding("UTF-8"); - writer1.putContent("There is some content for record 1"); - - Map props2 = new HashMap(1); - props2.put(ContentModel.PROP_NAME, "record2"); - NodeRef recordTwo = this.nodeService.createNode(newRecordFolder, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "record2"), - ContentModel.TYPE_CONTENT, props2).getChildRef(); - - // Set the content - ContentWriter writer2 = this.contentService.getWriter(recordTwo, ContentModel.PROP_CONTENT, true); - writer2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer2.setEncoding("UTF-8"); - writer2.putContent("There is some content for record 2"); - txn.commit(); - - // declare the new record - txn = transactionService.getUserTransaction(false); - txn.begin(); - declareRecord(recordOne); - declareRecord(recordTwo); - - // prepare for the transfer - Map params = new HashMap(3); - params.put(CompleteEventAction.PARAM_EVENT_NAME, "case_complete"); - params.put(CompleteEventAction.PARAM_EVENT_COMPLETED_AT, new Date()); - params.put(CompleteEventAction.PARAM_EVENT_COMPLETED_BY, "gavinc"); - this.rmActionService.executeRecordsManagementAction(newRecordFolder, "completeEvent", params); - this.rmActionService.executeRecordsManagementAction(newRecordFolder, "cutoff"); - - DispositionAction da = dispositionService.getNextDispositionAction(newRecordFolder); - assertNotNull(da); - assertEquals("transfer", da.getName()); - txn.commit(); - - // Clock the asOf date back to ensure eligibility - txn = transactionService.getUserTransaction(false); - txn.begin(); - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - this.nodeService.setProperty(da.getNodeRef(), PROP_DISPOSITION_AS_OF, calendar.getTime()); - - // Do the transfer - this.rmActionService.executeRecordsManagementAction(newRecordFolder, "transfer", null); - txn.commit(); - - // check that there is a transfer object present - List assocs = this.nodeService.getChildAssocs(rootNode, ASSOC_TRANSFERS, RegexQNamePattern.MATCH_ALL); - assertNotNull(assocs); - assertTrue(assocs.size() > 0); - - // Test 404 status for file plan with transfers but not the requested one - rootNode = this.rmService.getFilePlan(newRecordFolder); - rootNodeUrl = rootNode.toString().replace("://", "/"); - transferUrl = MessageFormat.format(GET_TRANSFER_URL_FORMAT, rootNodeUrl, transferId); - rsp = sendRequest(new GetRequest(transferUrl), 404); - - // retrieve the id of the last transfer - NodeRef transferNodeRef = assocs.get(assocs.size()-1).getChildRef(); - Date transferDate = (Date)nodeService.getProperty(transferNodeRef, ContentModel.PROP_CREATED); - - // Test successful retrieval of transfer archive - transferId = transferNodeRef.getId(); - transferUrl = MessageFormat.format(GET_TRANSFER_URL_FORMAT, rootNodeUrl, transferId); - rsp = sendRequest(new GetRequest(transferUrl), 200); - assertEquals("application/zip", rsp.getContentType()); - - // Test retrieval of transfer report, will be in JSON format - String transferReportUrl = MessageFormat.format(TRANSFER_REPORT_URL_FORMAT, rootNodeUrl, transferId); - rsp = sendRequest(new GetRequest(transferReportUrl), 200); - //System.out.println(rsp.getContentAsString()); - assertEquals("application/json", rsp.getContentType()); - JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString())); - assertTrue(jsonRsp.has("data")); - JSONObject data = jsonRsp.getJSONObject("data"); - assertTrue(data.has("transferDate")); - Date transferDateRsp = ISO8601DateFormat.parse(data.getString("transferDate")); - assertEquals(transferDate, transferDateRsp); - assertTrue(data.has("transferPerformedBy")); - assertEquals("System", data.getString("transferPerformedBy")); - assertTrue(data.has("dispositionAuthority")); - assertEquals("N1-218-00-3 item 18", data.getString("dispositionAuthority")); - assertTrue(data.has("items")); - JSONArray items = data.getJSONArray("items"); - assertEquals("Expecting 1 transferred folder", 1, items.length()); - JSONObject folder = items.getJSONObject(0); - assertTrue(folder.has("type")); - assertEquals("folder", folder.getString("type")); - assertTrue(folder.has("name")); - assertTrue(folder.getString("name").length() > 0); - assertTrue(folder.has("nodeRef")); - assertTrue(folder.getString("nodeRef").startsWith("workspace://SpacesStore/")); - assertTrue(folder.has("id")); - - // "id" should start with year-number pattern e.g. 2009-0000 - // This regular expression represents a string that starts with 4 digits followed by a hyphen, - // then 4 more digits and then any other characters - final String idRegExp = "^\\d{4}-\\d{4}.*"; - assertTrue(folder.getString("id").matches(idRegExp)); - - assertTrue(folder.has("children")); - JSONArray records = folder.getJSONArray("children"); - assertEquals("Expecting 2 transferred records", 2, records.length()); - JSONObject record1 = records.getJSONObject(0); - assertTrue(record1.has("type")); - assertEquals("record", record1.getString("type")); - assertTrue(record1.has("name")); - assertEquals("record1", record1.getString("name")); - assertTrue(record1.has("nodeRef")); - assertTrue(record1.getString("nodeRef").startsWith("workspace://SpacesStore/")); - assertTrue(record1.has("id")); - assertTrue(record1.getString("id").matches(idRegExp)); - assertTrue(record1.has("declaredBy")); - assertEquals("System", record1.getString("declaredBy")); - assertTrue(record1.has("declaredAt")); - - // Test filing a transfer report as a record - - // Attempt to store transfer report at non existent destination, make sure we get 404 - JSONObject jsonPostData = new JSONObject(); - jsonPostData.put("destination", "workspace://SpacesStore/09ca1e02-1c87-4a53-97e7-xxxxxxxxxxxx"); - String jsonPostString = jsonPostData.toString(); - rsp = sendRequest(new PostRequest(transferReportUrl, jsonPostString, APPLICATION_JSON), 404); - - // Attempt to store audit log at wrong type of destination, make sure we get 400 - NodeRef wrongCategory = TestUtilities.getRecordCategory(searchService, "Civilian Files", - "Foreign Employee Award Files"); - assertNotNull(wrongCategory); - jsonPostData = new JSONObject(); - jsonPostData.put("destination", wrongCategory.toString()); - jsonPostString = jsonPostData.toString(); - rsp = sendRequest(new PostRequest(transferReportUrl, jsonPostString, APPLICATION_JSON), 400); - - // get record folder to file into - NodeRef destination = TestUtilities.getRecordFolder(searchService, "Civilian Files", - "Foreign Employee Award Files", "Christian Bohr"); - assertNotNull(destination); - - // Store the full audit log as a record - jsonPostData = new JSONObject(); - jsonPostData.put("destination", destination); - jsonPostString = jsonPostData.toString(); - rsp = sendRequest(new PostRequest(transferReportUrl, jsonPostString, APPLICATION_JSON), 200); - - // check the response - System.out.println(rsp.getContentAsString()); - jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString())); - assertTrue(jsonRsp.has("success")); - assertTrue(jsonRsp.getBoolean("success")); - assertTrue(jsonRsp.has("record")); - assertNotNull(jsonRsp.get("record")); - assertTrue(nodeService.exists(new NodeRef(jsonRsp.getString("record")))); - assertTrue(jsonRsp.has("recordName")); - assertNotNull(jsonRsp.get("recordName")); - assertTrue(jsonRsp.getString("recordName").startsWith("report_")); - } - public void testAudit() throws Exception { // call the list service to get audit events @@ -1321,7 +1004,7 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen JSONObject data = jsonParsedObject.getJSONObject("data"); JSONObject events = data.getJSONObject("auditEvents"); JSONArray items = events.getJSONArray("items"); - assertEquals(this.rmAuditService.getAuditEvents().size(), items.length()); + assertEquals(auditService.getAuditEvents().size(), items.length()); assertTrue(items.length() > 0); JSONObject item = items.getJSONObject(0); assertTrue(item.length() == 2); @@ -1342,10 +1025,6 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen assertEquals("application/json", rsp.getContentType()); jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString())); - // get category - NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Civilian Files", "Foreign Employee Award Files"); - assertNotNull(recordCategory); - // construct the URL String nodeUrl = recordCategory.toString().replace("://", "/"); String auditUrl = MessageFormat.format(GET_NODE_AUDITLOG_URL_FORMAT, nodeUrl); @@ -1369,7 +1048,7 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen assertEquals("application/json", rsp.getContentType()); jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString())); - checkAuditStatus(true); + checkAuditStatus(false); // start the RM audit log JSONObject jsonPostData = new JSONObject(); @@ -1431,22 +1110,15 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen Response rsp = sendRequest(new PostRequest(RMA_AUDITLOG_URL, jsonPostString, APPLICATION_JSON), 404); // Attempt to store audit log at wrong type of destination, make sure we get 400 - NodeRef recordCategory = TestUtilities.getRecordCategory(searchService, "Civilian Files", - "Foreign Employee Award Files"); - assertNotNull(recordCategory); jsonPostData = new JSONObject(); jsonPostData.put("destination", recordCategory.toString()); jsonPostString = jsonPostData.toString(); rsp = sendRequest(new PostRequest(RMA_AUDITLOG_URL, jsonPostString, APPLICATION_JSON), 400); - // get record folder to file into - NodeRef destination = TestUtilities.getRecordFolder(searchService, "Civilian Files", - "Foreign Employee Award Files", "Christian Bohr"); - assertNotNull(destination); // Store the full audit log as a record jsonPostData = new JSONObject(); - jsonPostData.put("destination", destination); + jsonPostData.put("destination", recordFolder2); jsonPostString = jsonPostData.toString(); rsp = sendRequest(new PostRequest(RMA_AUDITLOG_URL, jsonPostString, APPLICATION_JSON), 200); @@ -1464,7 +1136,7 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen // Store a filtered audit log as a record jsonPostData = new JSONObject(); - jsonPostData.put("destination", destination); + jsonPostData.put("destination", recordFolder2); jsonPostData.put("size", "50"); jsonPostData.put("user", "gavinc"); jsonPostData.put("event", "Update Metadata"); @@ -1484,63 +1156,6 @@ public class RmRestApiTest extends BaseWebScriptTest implements RecordsManagemen assertNotNull(jsonRsp.get("recordName")); assertTrue(jsonRsp.getString("recordName").startsWith("audit_")); } - - private void declareRecord(NodeRef recordOne) - { - // Declare record - Map propValues = this.nodeService.getProperties(recordOne); - propValues.put(RecordsManagementModel.PROP_PUBLICATION_DATE, new Date()); - /*List smList = new ArrayList(2); - smList.add("FOUO"); - smList.add("NOFORN"); - propValues.put(RecordsManagementModel.PROP_SUPPLEMENTAL_MARKING_LIST, (Serializable)smList);*/ - propValues.put(RecordsManagementModel.PROP_MEDIA_TYPE, "mediaTypeValue"); - propValues.put(RecordsManagementModel.PROP_FORMAT, "formatValue"); - propValues.put(RecordsManagementModel.PROP_DATE_RECEIVED, new Date()); - propValues.put(RecordsManagementModel.PROP_ORIGINATOR, "origValue"); - propValues.put(RecordsManagementModel.PROP_ORIGINATING_ORGANIZATION, "origOrgValue"); - propValues.put(ContentModel.PROP_TITLE, "titleValue"); - this.nodeService.setProperties(recordOne, propValues); - this.rmActionService.executeRecordsManagementAction(recordOne, "declareRecord"); - } - - private NodeRef retrievePreexistingRecordFolder() - { - final List resultNodeRefs = retrieveJanuaryAISVitalFolders(); - - return resultNodeRefs.get(0); - } - - private List retrieveJanuaryAISVitalFolders() - { - String typeQuery = "TYPE:\"" + TYPE_RECORD_FOLDER + "\" AND @cm\\:name:\"January AIS Audit Records\""; - ResultSet types = this.searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_LUCENE, typeQuery); - - final List resultNodeRefs = types.getNodeRefs(); - types.close(); - return resultNodeRefs; - } - - private NodeRef createRecord(NodeRef recordFolder, String name, String title) - { - // Create the document - Map props = new HashMap(1); - props.put(ContentModel.PROP_NAME, name); - props.put(ContentModel.PROP_TITLE, title); - NodeRef recordOne = this.nodeService.createNode(recordFolder, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), - ContentModel.TYPE_CONTENT, - props).getChildRef(); - - // Set the content - ContentWriter writer = this.contentService.getWriter(recordOne, ContentModel.PROP_CONTENT, true); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer.setEncoding("UTF-8"); - writer.putContent("There is some content in this record"); - - return recordOne; - } public void testPropertyLabelWithAccentedChars() throws Exception { diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RoleRestApiTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RoleRestApiTest.java index a7d870fbce..6130973037 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RoleRestApiTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RoleRestApiTest.java @@ -19,19 +19,11 @@ package org.alfresco.module.org_alfresco_module_rm.test.webscript; import java.util.HashSet; -import java.util.List; import java.util.Set; -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; import org.alfresco.module.org_alfresco_module_rm.capability.Capability; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; -import org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; import org.alfresco.util.GUID; import org.json.JSONArray; import org.json.JSONObject; @@ -46,41 +38,11 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; * * @author Roy Wetherall */ -public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagementModel +public class RoleRestApiTest extends BaseRMWebScriptTestCase implements RecordsManagementModel { - protected static StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); protected static final String GET_ROLES_URL = "/api/rma/admin/rmroles"; protected static final String SERVICE_URL_PREFIX = "/alfresco/service"; - protected static final String APPLICATION_JSON = "application/json"; - - protected NodeService nodeService; - protected RecordsManagementService rmService; - protected RecordsManagementSecurityService rmSecurityService; - - private NodeRef rmRootNode; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService"); - this.rmService = (RecordsManagementService)getServer().getApplicationContext().getBean("RecordsManagementService"); - this.rmSecurityService = (RecordsManagementSecurityService)getServer().getApplicationContext().getBean("RecordsManagementSecurityService"); - - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - - List roots = rmService.getFilePlans(); - if (roots.size() != 0) - { - rmRootNode = roots.get(0); - } - else - { - NodeRef root = this.nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore")); - rmRootNode = this.nodeService.createNode(root, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, TYPE_FILE_PLAN).getChildRef(); - } - - } + protected static final String APPLICATION_JSON = "application/json"; public void testGetRoles() throws Exception { @@ -88,11 +50,11 @@ public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagem String role2 = GUID.generate(); // Create a couple or roles by hand - rmSecurityService.createRole(rmRootNode, role1, "My Test Role", getListOfCapabilities(5)); - rmSecurityService.createRole(rmRootNode, role2, "My Test Role Too", getListOfCapabilities(5)); + securityService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5)); + securityService.createRole(filePlan, role2, "My Test Role Too", getListOfCapabilities(5)); // Add the admin user to one of the roles - rmSecurityService.assignRoleToAuthority(rmRootNode, role1, "admin"); + securityService.assignRoleToAuthority(filePlan, role1, "admin"); try { @@ -141,8 +103,8 @@ public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagem finally { // Clean up - rmSecurityService.deleteRole(rmRootNode, role1); - rmSecurityService.deleteRole(rmRootNode, role2); + securityService.deleteRole(filePlan, role1); + securityService.deleteRole(filePlan, role2); } } @@ -181,7 +143,7 @@ public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagem } finally { - rmSecurityService.deleteRole(rmRootNode, roleName); + securityService.deleteRole(filePlan, roleName); } } @@ -189,7 +151,7 @@ public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagem public void testPutRole() throws Exception { String role1 = GUID.generate(); - rmSecurityService.createRole(rmRootNode, role1, "My Test Role", getListOfCapabilities(5)); + securityService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5)); try { @@ -227,7 +189,7 @@ public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagem finally { // Clean up - rmSecurityService.deleteRole(rmRootNode, role1); + securityService.deleteRole(filePlan, role1); } } @@ -235,7 +197,7 @@ public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagem public void testGetRole() throws Exception { String role1 = GUID.generate(); - rmSecurityService.createRole(rmRootNode, role1, "My Test Role", getListOfCapabilities(5)); + securityService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5)); try { @@ -260,7 +222,7 @@ public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagem finally { // Clean up - rmSecurityService.deleteRole(rmRootNode, role1); + securityService.deleteRole(filePlan, role1); } } @@ -268,11 +230,11 @@ public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagem public void testDeleteRole() throws Exception { String role1 = GUID.generate(); - assertFalse(rmSecurityService.existsRole(rmRootNode, role1)); - rmSecurityService.createRole(rmRootNode, role1, "My Test Role", getListOfCapabilities(5)); - assertTrue(rmSecurityService.existsRole(rmRootNode, role1)); + assertFalse(securityService.existsRole(filePlan, role1)); + securityService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5)); + assertTrue(securityService.existsRole(filePlan, role1)); sendRequest(new DeleteRequest(GET_ROLES_URL + "/" + role1),200); - assertFalse(rmSecurityService.existsRole(rmRootNode, role1)); + assertFalse(securityService.existsRole(filePlan, role1)); // Bad request sendRequest(new DeleteRequest(GET_ROLES_URL + "/cheese"), 404); @@ -286,7 +248,7 @@ public class RoleRestApiTest extends BaseWebScriptTest implements RecordsManagem private Set getListOfCapabilities(int size, int offset) { Set result = new HashSet(size); - Set caps = rmSecurityService.getCapabilities(); + Set caps = securityService.getCapabilities(); int count = 0; for (Capability cap : caps) {