From d2870081bbd90cc7f2c4e66cbd99a7ab70b0b963 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Tue, 15 Mar 2016 14:53:01 +0000 Subject: [PATCH] RM-3132 (Update license headers) --- .../test/integration/issue/RM1887Test.java | 146 +- .../test/integration/issue/RM2072Test.java | 346 ++--- .../test/integration/issue/RM452Test.java | 178 +-- .../test/integration/issue/RM804Test.java | 362 ++--- .../test/integration/issue/RM994Test.java | 234 ++-- .../integration/version/AutoVersionTest.java | 446 +++--- .../version/DeleteRecordVersionTest.java | 992 +++++++------- .../RecordsManagementServiceImplTest.java | 1212 ++++++++--------- .../legacy/webscript/AuditRestApiTest.java | 166 +-- .../NotificationServiceHelperSystemTest.java | 278 ++-- .../test/util/GenerateCapabilityReport.java | 132 +- .../test/util/TestWebScriptRepoServer.java | 424 +++--- .../hold/HoldServiceImplUnitTest.java | 902 ++++++------ ...tionaryBootstrapPostProcessorUnitTest.java | 174 +-- 14 files changed, 2996 insertions(+), 2996 deletions(-) diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM1887Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM1887Test.java index 2e0e7e34ad..dbb99454b1 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM1887Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM1887Test.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,70 +21,70 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; - -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.service.cmr.repository.NodeRef; - -/** - * Integration test for RM-1887 - * - * @author Roy Wetherall - * @since 2.3 - */ -public class RM1887Test extends BaseRMTestCase -{ - @Override - protected boolean isRecordTest() - { - return true; - } - - /** - * Given that a record is unfiled - * And an unfiled folder has been created - * When I move the unfiled record into the unfiled folder - * Then the filed date of the unfiled record remains unset - */ - public void testMoveUnfiledRecord() throws Exception - { - doBehaviourDrivenTest(new BehaviourDrivenTest() - { - private NodeRef unfiledRecordFolder; - private NodeRef unfiledRecord; - - public void given() throws Exception - { - // create unfiled folder - unfiledRecordFolder = fileFolderService.create(filePlanService.getUnfiledContainer(filePlan), "my test folder", TYPE_UNFILED_RECORD_FOLDER).getNodeRef(); - - // crate unfiled record - unfiledRecord = recordService.createRecordFromContent(filePlan, "test.txt", TYPE_CONTENT, null, null); - - // check the record - assertTrue(recordService.isRecord(unfiledRecord)); - assertFalse(recordService.isFiled(unfiledRecord)); - } - - public void when() throws Exception - { - // move the record into the unfiled folder - fileFolderService.move(unfiledRecord, unfiledRecordFolder, null); - } - - public void then() - { - // check the record - assertTrue(recordService.isRecord(unfiledRecord)); - assertFalse(recordService.isFiled(unfiledRecord)); - } - }); - - } - - -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Integration test for RM-1887 + * + * @author Roy Wetherall + * @since 2.3 + */ +public class RM1887Test extends BaseRMTestCase +{ + @Override + protected boolean isRecordTest() + { + return true; + } + + /** + * Given that a record is unfiled + * And an unfiled folder has been created + * When I move the unfiled record into the unfiled folder + * Then the filed date of the unfiled record remains unset + */ + public void testMoveUnfiledRecord() throws Exception + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef unfiledRecordFolder; + private NodeRef unfiledRecord; + + public void given() throws Exception + { + // create unfiled folder + unfiledRecordFolder = fileFolderService.create(filePlanService.getUnfiledContainer(filePlan), "my test folder", TYPE_UNFILED_RECORD_FOLDER).getNodeRef(); + + // crate unfiled record + unfiledRecord = recordService.createRecordFromContent(filePlan, "test.txt", TYPE_CONTENT, null, null); + + // check the record + assertTrue(recordService.isRecord(unfiledRecord)); + assertFalse(recordService.isFiled(unfiledRecord)); + } + + public void when() throws Exception + { + // move the record into the unfiled folder + fileFolderService.move(unfiledRecord, unfiledRecordFolder, null); + } + + public void then() + { + // check the record + assertTrue(recordService.isRecord(unfiledRecord)); + assertFalse(recordService.isFiled(unfiledRecord)); + } + }); + + } + + +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM2072Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM2072Test.java index 488efa9f4b..3ce8b32dd9 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM2072Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM2072Test.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,170 +21,170 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction; -import org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.rule.Rule; -import org.alfresco.service.cmr.rule.RuleService; -import org.alfresco.service.cmr.rule.RuleType; - -/** - * System test for RM-2072: Concurrency exceptions and deadlocks on Records Management "File to" rule - * - * @author Roy Wetherall - * @since 2.2.1.1 - */ -public class RM2072Test extends BaseRMTestCase -{ - private static final int NUMBER_OF_BATCHES = 1; - private static final int NUMBER_IN_BATCH = 500; - - private RuleService ruleService; - private NodeRef ruleFolder; - - @Override - protected void initServices() - { - super.initServices(); - - ruleService = (RuleService)applicationContext.getBean("RuleService"); - } - - @Override - protected boolean isCollaborationSiteTest() - { - return true; - } - - @Override - protected boolean isRecordTest() - { - return true; - } - - /** - * Given that I have auto declare configured - * And that I have auto file configured to a path where only the record folder needs to be created - * When I add lots of documents in the same transaction - * Then the rules should fire - * And the documents should be filed in the new record folder - */ - public void testAutoDeclareAutoFileCreateRecordFolderOnly() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - // create the folder - ruleFolder = fileFolderService.create(documentLibrary, "mytestfolder", ContentModel.TYPE_FOLDER).getNodeRef(); - - // create record category - NodeRef nodeRefA = filePlanService.createRecordCategory(filePlan, "A"); - NodeRef nodeRefB = filePlanService.createRecordCategory(nodeRefA, "B"); - filePlanService.createRecordCategory(nodeRefB, "C"); - - Action action = actionService.createAction(CreateRecordAction.NAME); - action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan); - - Rule rule = new Rule(); - rule.setRuleType(RuleType.INBOUND); - rule.setTitle("my rule"); - rule.setAction(action); - rule.setExecuteAsynchronously(true); - ruleService.saveRule(ruleFolder, rule); - - Action fileAction = actionService.createAction(FileToAction.NAME); - fileAction.setParameterValue(FileToAction.PARAM_PATH, "/A/B/C/{date.year.long}/{date.month.long}/{date.day.month}"); - fileAction.setParameterValue(FileToAction.PARAM_CREATE_RECORD_PATH, true); - - Rule fileRule = new Rule(); - fileRule.setRuleType(RuleType.INBOUND); - fileRule.setTitle("my rule"); - fileRule.setAction(fileAction); - fileRule.setExecuteAsynchronously(true); - ruleService.saveRule(filePlanService.getUnfiledContainer(filePlan), fileRule); - - return null; - } - - @Override - public void test(Void result) throws Exception - { - assertFalse(ruleService.getRules(ruleFolder).isEmpty()); - } - }); - - List records = new ArrayList(NUMBER_OF_BATCHES*NUMBER_IN_BATCH); - - for (int i = 0; i < NUMBER_OF_BATCHES; i++) - { - final int finali = i; - records.addAll(doTestInTransaction(new Test>() - { - @Override - public List run() throws Exception - { - List records = new ArrayList(NUMBER_IN_BATCH); - for (int j = 0; j < NUMBER_IN_BATCH; j++) - { - int count = (finali+1)*(j+1); - String name = "content" + count + ".txt"; - System.out.println(name + " - creating"); - - NodeRef record = fileFolderService.create(ruleFolder, name, ContentModel.TYPE_CONTENT).getNodeRef(); - records.add(record); - } - return records; - } - })); - } - - try - { - while(!records.isEmpty()) - { - Thread.sleep(1000); - - final Iterator temp = records.iterator(); - doTestInTransaction(new Test() - { - @Override - public Void run() throws Exception - { - while (temp.hasNext()) - { - NodeRef record = temp.next(); - if (nodeService.hasAspect(record, ASPECT_RECORD) && recordService.isFiled(record)) - { - String name = (String) nodeService.getProperty(record, ContentModel.PROP_NAME); - System.out.println(name + " - complete"); - temp.remove(); - } - } - - return null; - } - }); - } - } - catch (Exception exception) - { - exception.printStackTrace(); - throw exception; - } - } -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction; +import org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.rule.Rule; +import org.alfresco.service.cmr.rule.RuleService; +import org.alfresco.service.cmr.rule.RuleType; + +/** + * System test for RM-2072: Concurrency exceptions and deadlocks on Records Management "File to" rule + * + * @author Roy Wetherall + * @since 2.2.1.1 + */ +public class RM2072Test extends BaseRMTestCase +{ + private static final int NUMBER_OF_BATCHES = 1; + private static final int NUMBER_IN_BATCH = 500; + + private RuleService ruleService; + private NodeRef ruleFolder; + + @Override + protected void initServices() + { + super.initServices(); + + ruleService = (RuleService)applicationContext.getBean("RuleService"); + } + + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + @Override + protected boolean isRecordTest() + { + return true; + } + + /** + * Given that I have auto declare configured + * And that I have auto file configured to a path where only the record folder needs to be created + * When I add lots of documents in the same transaction + * Then the rules should fire + * And the documents should be filed in the new record folder + */ + public void testAutoDeclareAutoFileCreateRecordFolderOnly() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public Void run() + { + // create the folder + ruleFolder = fileFolderService.create(documentLibrary, "mytestfolder", ContentModel.TYPE_FOLDER).getNodeRef(); + + // create record category + NodeRef nodeRefA = filePlanService.createRecordCategory(filePlan, "A"); + NodeRef nodeRefB = filePlanService.createRecordCategory(nodeRefA, "B"); + filePlanService.createRecordCategory(nodeRefB, "C"); + + Action action = actionService.createAction(CreateRecordAction.NAME); + action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan); + + Rule rule = new Rule(); + rule.setRuleType(RuleType.INBOUND); + rule.setTitle("my rule"); + rule.setAction(action); + rule.setExecuteAsynchronously(true); + ruleService.saveRule(ruleFolder, rule); + + Action fileAction = actionService.createAction(FileToAction.NAME); + fileAction.setParameterValue(FileToAction.PARAM_PATH, "/A/B/C/{date.year.long}/{date.month.long}/{date.day.month}"); + fileAction.setParameterValue(FileToAction.PARAM_CREATE_RECORD_PATH, true); + + Rule fileRule = new Rule(); + fileRule.setRuleType(RuleType.INBOUND); + fileRule.setTitle("my rule"); + fileRule.setAction(fileAction); + fileRule.setExecuteAsynchronously(true); + ruleService.saveRule(filePlanService.getUnfiledContainer(filePlan), fileRule); + + return null; + } + + @Override + public void test(Void result) throws Exception + { + assertFalse(ruleService.getRules(ruleFolder).isEmpty()); + } + }); + + List records = new ArrayList(NUMBER_OF_BATCHES*NUMBER_IN_BATCH); + + for (int i = 0; i < NUMBER_OF_BATCHES; i++) + { + final int finali = i; + records.addAll(doTestInTransaction(new Test>() + { + @Override + public List run() throws Exception + { + List records = new ArrayList(NUMBER_IN_BATCH); + for (int j = 0; j < NUMBER_IN_BATCH; j++) + { + int count = (finali+1)*(j+1); + String name = "content" + count + ".txt"; + System.out.println(name + " - creating"); + + NodeRef record = fileFolderService.create(ruleFolder, name, ContentModel.TYPE_CONTENT).getNodeRef(); + records.add(record); + } + return records; + } + })); + } + + try + { + while(!records.isEmpty()) + { + Thread.sleep(1000); + + final Iterator temp = records.iterator(); + doTestInTransaction(new Test() + { + @Override + public Void run() throws Exception + { + while (temp.hasNext()) + { + NodeRef record = temp.next(); + if (nodeService.hasAspect(record, ASPECT_RECORD) && recordService.isFiled(record)) + { + String name = (String) nodeService.getProperty(record, ContentModel.PROP_NAME); + System.out.println(name + " - complete"); + temp.remove(); + } + } + + return null; + } + }); + } + } + catch (Exception exception) + { + exception.printStackTrace(); + throw exception; + } + } +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM452Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM452Test.java index b1e86eaaf1..108409b5ae 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM452Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM452Test.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,86 +21,86 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.module.org_alfresco_module_rm.test.util.TestService; - -/** - * System test for RM-452 - * - * See alfresco.extension.rm-method-security.properties - * - * @author Roy Wetherall - * @since 2.1 - */ -public class RM452Test extends BaseRMTestCase -{ - private TestService testService; - - @Override - protected void initServices() - { - super.initServices(); - - testService = (TestService)applicationContext.getBean("TestService"); - } - - @Override - protected boolean isCollaborationSiteTest() - { - return true; - } - - @Override - protected boolean isRecordTest() - { - return true; - } - - public void testRM452() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - assertNotNull(folder); - assertNotNull(recordOne); - assertFalse(filePlanService.isFilePlanComponent(folder)); - assertTrue(filePlanService.isFilePlanComponent(recordOne)); - - // call methodOne with non-RM artifact .. expect success - testService.testMethodOne(folder); - - // call methodTwo with non-RM artifact .. expect success - testService.testMethodTwo(folder); - - // call methodOne with an RM artifact .. expect success - testService.testMethodOne(recordOne); - - return null; - } - }); - - doTestInTransaction(new FailureTest - ( - "Shouldn't be able to call testMethodTwo on TestService, because override RM security for method is not configred.", - AlfrescoRuntimeException.class - ) - { - - @Override - public void run() throws Exception - { - // call methodTwo with an RM artifact .. expect failure - testService.testMethodTwo(recordOne); - } - }); - } -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.module.org_alfresco_module_rm.test.util.TestService; + +/** + * System test for RM-452 + * + * See alfresco.extension.rm-method-security.properties + * + * @author Roy Wetherall + * @since 2.1 + */ +public class RM452Test extends BaseRMTestCase +{ + private TestService testService; + + @Override + protected void initServices() + { + super.initServices(); + + testService = (TestService)applicationContext.getBean("TestService"); + } + + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + @Override + protected boolean isRecordTest() + { + return true; + } + + public void testRM452() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public Void run() + { + assertNotNull(folder); + assertNotNull(recordOne); + assertFalse(filePlanService.isFilePlanComponent(folder)); + assertTrue(filePlanService.isFilePlanComponent(recordOne)); + + // call methodOne with non-RM artifact .. expect success + testService.testMethodOne(folder); + + // call methodTwo with non-RM artifact .. expect success + testService.testMethodTwo(folder); + + // call methodOne with an RM artifact .. expect success + testService.testMethodOne(recordOne); + + return null; + } + }); + + doTestInTransaction(new FailureTest + ( + "Shouldn't be able to call testMethodTwo on TestService, because override RM security for method is not configred.", + AlfrescoRuntimeException.class + ) + { + + @Override + public void run() throws Exception + { + // call methodTwo with an RM artifact .. expect failure + testService.testMethodTwo(recordOne); + } + }); + } +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM804Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM804Test.java index 7c46ae41dd..b570d1f464 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM804Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM804Test.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,178 +21,178 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.site.SiteRole; - -/** - * Unit test for RM-804 .. site managers are able to delete file plans - * - * @author Roy Wetherall - * @since 2.1 - */ -public class RM804Test extends BaseRMTestCase -{ - @Override - protected void initServices() - { - super.initServices(); - } - - @Override - protected boolean isCollaborationSiteTest() - { - return true; - } - - @Override - protected boolean isUserTest() - { - return true; - } - - public void testUsersHaveDeletePermissionsOnFilePlan() throws Exception - { - // as rmuser - doTestInTransaction(new Test() - { - @Override - public Void run() - { - assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); - - return null; - } - }, ADMIN_USER); - - doTestInTransaction(new Test() - { - @Override - public Void run() - { - assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); - - return null; - } - }, ADMIN_USER); - - doTestInTransaction(new Test() - { - @Override - public Void run() - { - assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); - - return null; - } - }, ADMIN_USER); - - doTestInTransaction(new Test() - { - @Override - public Void run() - { - assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); - - return null; - } - }, rmUserName); - - doTestInTransaction(new Test() - { - @Override - public Void run() - { - assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); - - return null; - } - }, userName); - } - - public void testTryAndDeleteSiteAsSiteManagerOnly() - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - siteService.setMembership(siteId, userName, SiteRole.SiteManager.toString()); - - return null; - } - }, "admin"); - - doTestInTransaction(new FailureTest - ( - "Should not be able to delete site as a site manager only.", - AlfrescoRuntimeException.class - ) - { - @Override - public void run() throws Exception - { - siteService.deleteSite(siteId); - - } - }, userName); - - // give the user a RM role (but not sufficient to delete the file plan node ref) - doTestInTransaction(new Test() - { - @Override - public Void run() - { - filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_USER, userName); - - return null; - } - }, "admin"); - - doTestInTransaction(new FailureTest - ( - "Should not be able to delete site as a site manager with an RM role that doesn't have the capability.", - AlfrescoRuntimeException.class - ) - { - @Override - public void run() throws Exception - { - siteService.deleteSite(siteId); - - } - }, userName); - - doTestInTransaction(new Test() - { - @Override - public Void run() - { - filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_ADMIN, userName); - - return null; - } - }, "admin"); - - doTestInTransaction(new Test() - { - @Override - public Void run() - { - siteService.deleteSite(siteId); - - return null; - } - }, userName); - - } - -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.site.SiteRole; + +/** + * Unit test for RM-804 .. site managers are able to delete file plans + * + * @author Roy Wetherall + * @since 2.1 + */ +public class RM804Test extends BaseRMTestCase +{ + @Override + protected void initServices() + { + super.initServices(); + } + + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + @Override + protected boolean isUserTest() + { + return true; + } + + public void testUsersHaveDeletePermissionsOnFilePlan() throws Exception + { + // as rmuser + doTestInTransaction(new Test() + { + @Override + public Void run() + { + assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); + + return null; + } + }, ADMIN_USER); + + doTestInTransaction(new Test() + { + @Override + public Void run() + { + assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); + + return null; + } + }, ADMIN_USER); + + doTestInTransaction(new Test() + { + @Override + public Void run() + { + assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); + + return null; + } + }, ADMIN_USER); + + doTestInTransaction(new Test() + { + @Override + public Void run() + { + assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); + + return null; + } + }, rmUserName); + + doTestInTransaction(new Test() + { + @Override + public Void run() + { + assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); + + return null; + } + }, userName); + } + + public void testTryAndDeleteSiteAsSiteManagerOnly() + { + doTestInTransaction(new Test() + { + @Override + public Void run() + { + siteService.setMembership(siteId, userName, SiteRole.SiteManager.toString()); + + return null; + } + }, "admin"); + + doTestInTransaction(new FailureTest + ( + "Should not be able to delete site as a site manager only.", + AlfrescoRuntimeException.class + ) + { + @Override + public void run() throws Exception + { + siteService.deleteSite(siteId); + + } + }, userName); + + // give the user a RM role (but not sufficient to delete the file plan node ref) + doTestInTransaction(new Test() + { + @Override + public Void run() + { + filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_USER, userName); + + return null; + } + }, "admin"); + + doTestInTransaction(new FailureTest + ( + "Should not be able to delete site as a site manager with an RM role that doesn't have the capability.", + AlfrescoRuntimeException.class + ) + { + @Override + public void run() throws Exception + { + siteService.deleteSite(siteId); + + } + }, userName); + + doTestInTransaction(new Test() + { + @Override + public Void run() + { + filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_ADMIN, userName); + + return null; + } + }, "admin"); + + doTestInTransaction(new Test() + { + @Override + public Void run() + { + siteService.deleteSite(siteId); + + return null; + } + }, userName); + + } + +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM994Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM994Test.java index c9b879a566..1ef5f9fbab 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM994Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM994Test.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,114 +21,114 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; - -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordDefinition; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.Period; - -/** - * System test for RM-994 - * - * @author Roy Wetherall - * @since 2.1 - */ -public class RM994Test extends BaseRMTestCase -{ - @Override - protected void initServices() - { - super.initServices(); - } - - @Override - protected boolean isCollaborationSiteTest() - { - return true; - } - - @Override - protected boolean isRecordTest() - { - return true; - } - - public void testRM944() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - checkVitalRecordNotSet(rmContainer); - checkVitalRecordNotSet(rmFolder); - checkVitalRecordNotSet(recordOne); - assertNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF)); - - vitalRecordService.setVitalRecordDefintion(rmContainer, true, new Period("month|1")); - - return null; - } - }); - - doTestInTransaction(new Test() - { - @Override - public Void run() throws Exception - { - checkVitalRecordSet(rmContainer); - checkVitalRecordSet(rmFolder); - checkVitalRecordSet(recordOne); - assertNotNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF)); - - recordService.createRecord(filePlan, dmDocument, true); - - assertTrue(recordService.isRecord(dmDocument)); - checkVitalRecordNotSet(dmDocument); - - fileFolderService.move(dmDocument, rmFolder, null); - - checkVitalRecordSet(dmDocument); - - return null; - } - }, "admin"); - - doTestInTransaction(new Test() - { - @Override - public Void run() throws Exception - { - checkVitalRecordSet(dmDocument); - - return null; - } - }); - - } - - private void checkVitalRecordSet(NodeRef nodeRef) - { - VitalRecordDefinition def = vitalRecordService.getVitalRecordDefinition(nodeRef); - assertNotNull(def); - assertTrue(def.isEnabled()); - assertEquals("month", def.getReviewPeriod().getPeriodType()); - assertEquals("1", def.getReviewPeriod().getExpression()); - } - - private void checkVitalRecordNotSet(NodeRef nodeRef) - { - VitalRecordDefinition recordDef = vitalRecordService.getVitalRecordDefinition(nodeRef); - if (recordDef != null) - { - assertFalse(recordDef.isEnabled()); - assertEquals("none", recordDef.getReviewPeriod().getPeriodType()); - assertNull(recordDef.getNextReviewDate()); - } - } -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordDefinition; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.Period; + +/** + * System test for RM-994 + * + * @author Roy Wetherall + * @since 2.1 + */ +public class RM994Test extends BaseRMTestCase +{ + @Override + protected void initServices() + { + super.initServices(); + } + + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + @Override + protected boolean isRecordTest() + { + return true; + } + + public void testRM944() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public Void run() + { + checkVitalRecordNotSet(rmContainer); + checkVitalRecordNotSet(rmFolder); + checkVitalRecordNotSet(recordOne); + assertNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF)); + + vitalRecordService.setVitalRecordDefintion(rmContainer, true, new Period("month|1")); + + return null; + } + }); + + doTestInTransaction(new Test() + { + @Override + public Void run() throws Exception + { + checkVitalRecordSet(rmContainer); + checkVitalRecordSet(rmFolder); + checkVitalRecordSet(recordOne); + assertNotNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF)); + + recordService.createRecord(filePlan, dmDocument, true); + + assertTrue(recordService.isRecord(dmDocument)); + checkVitalRecordNotSet(dmDocument); + + fileFolderService.move(dmDocument, rmFolder, null); + + checkVitalRecordSet(dmDocument); + + return null; + } + }, "admin"); + + doTestInTransaction(new Test() + { + @Override + public Void run() throws Exception + { + checkVitalRecordSet(dmDocument); + + return null; + } + }); + + } + + private void checkVitalRecordSet(NodeRef nodeRef) + { + VitalRecordDefinition def = vitalRecordService.getVitalRecordDefinition(nodeRef); + assertNotNull(def); + assertTrue(def.isEnabled()); + assertEquals("month", def.getReviewPeriod().getPeriodType()); + assertEquals("1", def.getReviewPeriod().getExpression()); + } + + private void checkVitalRecordNotSet(NodeRef nodeRef) + { + VitalRecordDefinition recordDef = vitalRecordService.getVitalRecordDefinition(nodeRef); + if (recordDef != null) + { + assertFalse(recordDef.isEnabled()); + assertEquals("none", recordDef.getReviewPeriod().getPeriodType()); + assertNull(recordDef.getNextReviewDate()); + } + } +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/AutoVersionTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/AutoVersionTest.java index 8bb0cf21d1..d03a4312b5 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/AutoVersionTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/AutoVersionTest.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,220 +21,220 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.integration.version; - -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.version.ExtendedVersionableAspect; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.version.VersionHistory; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.GUID; - -/** - * Test recorded version histories when interacting with cm:versionable aspect - * and the auto-version behvaiour. - * - * @author Roy Wetherall - * @since 2.3.1 - */ -public class AutoVersionTest extends RecordableVersionsBaseTest -{ - /** - * Given a versionable document - * When I specialise the type of the document - * Then the version history has only one initial version - * And it does not represent the current type of the document - */ - public void testSpecialisedNodeInitialVersionCreated() - { - doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) - { - private NodeRef myDocument; - - public void given() throws Exception - { - // create a document - myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); - - // make versionable - nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null); - } - - public void when() - { - // specialise document - nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); - } - - public void then() - { - VersionHistory versionHistory = versionService.getVersionHistory(myDocument); - - assertNotNull(versionHistory); - assertEquals(1, versionHistory.getAllVersions().size()); - - NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef(); - assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState)); - assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); - } - }); - } - - /** - * Given a versionable document with initial version turned off - * When I specialise the type of the document - * Then the version history remains empty - */ - public void testSpecialisedNodeInitialVersionNotCreated() - { - doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) - { - private NodeRef myDocument; - - public void given() throws Exception - { - // create a document - myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); - - // make versionable - Map props = new HashMap(1); - props.put(ContentModel.PROP_INITIAL_VERSION, false); - nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props); - } - - public void when() - { - // specialise document - nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); - } - - public void then() - { - VersionHistory versionHistory = versionService.getVersionHistory(myDocument); - assertNull(versionHistory); - } - }); - } - - /** - * Given a versionable document with initial version turned off - * And auto version on type change is set on - * When I specialise the type of the document - * Then the version history contains the initial version - */ - public void testSpecialisedNodeInitialVersionNotCreatedOnTypeChangeOn() - { - doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) - { - private ExtendedVersionableAspect extendedVersionableAspect; - private NodeRef myDocument; - - public void given() throws Exception - { - // turn auto version on type change on - extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect"); - assertNotNull(extendedVersionableAspect); - extendedVersionableAspect.setAutoVersionOnTypeChange(true); - - // create a document - myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); - - // make versionable - Map props = new HashMap(1); - props.put(ContentModel.PROP_INITIAL_VERSION, false); - nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props); - } - - public void when() - { - // specialise document - nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); - } - - public void then() - { - VersionHistory versionHistory = versionService.getVersionHistory(myDocument); - assertNotNull(versionHistory); - assertEquals(1, versionHistory.getAllVersions().size()); - - NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef(); - assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState)); - assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); - } - - public void after() throws Exception - { - // reset auto version on type to default off - extendedVersionableAspect.setAutoVersionOnTypeChange(false); - } - }); - } - - /** - * Given a versionable document with initial version turned on - * And auto version on type change is set on - * When I specialise the type of the document - * Then the version history contains the initial version - */ - public void testSpecialisedNodeInitialVersionCreatedOnTypeChangeOn() - { - doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) - { - private ExtendedVersionableAspect extendedVersionableAspect; - private NodeRef myDocument; - - public void given() throws Exception - { - // turn auto version on type change on - extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect"); - assertNotNull(extendedVersionableAspect); - extendedVersionableAspect.setAutoVersionOnTypeChange(true); - - // create a document - myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); - - // make versionable - Map props = new HashMap(1); - props.put(ContentModel.PROP_INITIAL_VERSION, true); - nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props); - } - - public void when() - { - // specialise document - nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); - } - - public void then() - { - VersionHistory versionHistory = versionService.getVersionHistory(myDocument); - assertNotNull(versionHistory); - assertEquals(2, versionHistory.getAllVersions().size()); - - NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef(); - assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState)); - assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); - - frozenState = versionHistory.getVersion("1.0").getFrozenStateNodeRef(); - assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState)); - assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); - } - - public void after() throws Exception - { - // reset auto version on type to default off - extendedVersionableAspect.setAutoVersionOnTypeChange(false); - } - }); - } - - -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.integration.version; + +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.version.ExtendedVersionableAspect; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.version.VersionHistory; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.GUID; + +/** + * Test recorded version histories when interacting with cm:versionable aspect + * and the auto-version behvaiour. + * + * @author Roy Wetherall + * @since 2.3.1 + */ +public class AutoVersionTest extends RecordableVersionsBaseTest +{ + /** + * Given a versionable document + * When I specialise the type of the document + * Then the version history has only one initial version + * And it does not represent the current type of the document + */ + public void testSpecialisedNodeInitialVersionCreated() + { + doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) + { + private NodeRef myDocument; + + public void given() throws Exception + { + // create a document + myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); + + // make versionable + nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null); + } + + public void when() + { + // specialise document + nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); + } + + public void then() + { + VersionHistory versionHistory = versionService.getVersionHistory(myDocument); + + assertNotNull(versionHistory); + assertEquals(1, versionHistory.getAllVersions().size()); + + NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef(); + assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState)); + assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); + } + }); + } + + /** + * Given a versionable document with initial version turned off + * When I specialise the type of the document + * Then the version history remains empty + */ + public void testSpecialisedNodeInitialVersionNotCreated() + { + doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) + { + private NodeRef myDocument; + + public void given() throws Exception + { + // create a document + myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); + + // make versionable + Map props = new HashMap(1); + props.put(ContentModel.PROP_INITIAL_VERSION, false); + nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props); + } + + public void when() + { + // specialise document + nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); + } + + public void then() + { + VersionHistory versionHistory = versionService.getVersionHistory(myDocument); + assertNull(versionHistory); + } + }); + } + + /** + * Given a versionable document with initial version turned off + * And auto version on type change is set on + * When I specialise the type of the document + * Then the version history contains the initial version + */ + public void testSpecialisedNodeInitialVersionNotCreatedOnTypeChangeOn() + { + doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) + { + private ExtendedVersionableAspect extendedVersionableAspect; + private NodeRef myDocument; + + public void given() throws Exception + { + // turn auto version on type change on + extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect"); + assertNotNull(extendedVersionableAspect); + extendedVersionableAspect.setAutoVersionOnTypeChange(true); + + // create a document + myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); + + // make versionable + Map props = new HashMap(1); + props.put(ContentModel.PROP_INITIAL_VERSION, false); + nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props); + } + + public void when() + { + // specialise document + nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); + } + + public void then() + { + VersionHistory versionHistory = versionService.getVersionHistory(myDocument); + assertNotNull(versionHistory); + assertEquals(1, versionHistory.getAllVersions().size()); + + NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef(); + assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState)); + assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); + } + + public void after() throws Exception + { + // reset auto version on type to default off + extendedVersionableAspect.setAutoVersionOnTypeChange(false); + } + }); + } + + /** + * Given a versionable document with initial version turned on + * And auto version on type change is set on + * When I specialise the type of the document + * Then the version history contains the initial version + */ + public void testSpecialisedNodeInitialVersionCreatedOnTypeChangeOn() + { + doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) + { + private ExtendedVersionableAspect extendedVersionableAspect; + private NodeRef myDocument; + + public void given() throws Exception + { + // turn auto version on type change on + extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect"); + assertNotNull(extendedVersionableAspect); + extendedVersionableAspect.setAutoVersionOnTypeChange(true); + + // create a document + myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); + + // make versionable + Map props = new HashMap(1); + props.put(ContentModel.PROP_INITIAL_VERSION, true); + nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props); + } + + public void when() + { + // specialise document + nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); + } + + public void then() + { + VersionHistory versionHistory = versionService.getVersionHistory(myDocument); + assertNotNull(versionHistory); + assertEquals(2, versionHistory.getAllVersions().size()); + + NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef(); + assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState)); + assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); + + frozenState = versionHistory.getVersion("1.0").getFrozenStateNodeRef(); + assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState)); + assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); + } + + public void after() throws Exception + { + // reset auto version on type to default off + extendedVersionableAspect.setAutoVersionOnTypeChange(false); + } + }); + } + + +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/DeleteRecordVersionTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/DeleteRecordVersionTest.java index fcf22bfdee..870ef2e599 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/DeleteRecordVersionTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/DeleteRecordVersionTest.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,493 +21,493 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.integration.version; - -import java.io.Serializable; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.action.impl.CompleteEventAction; -import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction; -import org.alfresco.module.org_alfresco_module_rm.action.impl.DestroyAction; -import org.alfresco.module.org_alfresco_module_rm.relationship.Relationship; -import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService; -import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils; -import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel; -import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy; -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.version.Version; -import org.alfresco.service.cmr.version.VersionHistory; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.GUID; - -/** - * Recordable version history integration tests. - * - * @author Roy Wetherall - * @since 2.3.1 - */ -public class DeleteRecordVersionTest extends RecordableVersionsBaseTest -{ - /** - * Given that a document is created - * And the initial version is record - * When I delete the version record - * Then the version is deleted - * And the version history is not deleted - * - * @see https://issues.alfresco.com/jira/browse/RM-2562 - */ - public void testDeleteFirstRecordedVersion() - { - doBehaviourDrivenTest(new BehaviourDrivenTest() - { - private NodeRef myDocument; - - public void given() throws Exception - { - // create a document - myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); - - // make versionable - Map props = new HashMap(2); - props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL); - props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan); - nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props); - nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null); - } - - public void when() - { - // check the initial version label - assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL)); - - // check that the version history contains a single version that is recorded - VersionHistory versionHistory = versionService.getVersionHistory(myDocument); - assertNotNull(versionHistory); - assertEquals(1, versionHistory.getAllVersions().size()); - - // check the recorded version is not marked as destroyed - Version head = versionHistory.getHeadVersion(); - assertNotNull(head); - assertFalse(recordableVersionService.isRecordedVersionDestroyed(head)); - - // check the version record - NodeRef record = recordableVersionService.getVersionRecord(head); - assertTrue(recordService.isRecord(record)); - - // record should not have a version history because it is immutable - assertFalse(nodeService.hasAspect(record, ContentModel.ASPECT_VERSIONABLE)); - VersionHistory recordVersionHistory = versionService.getVersionHistory(record); - assertNull(recordVersionHistory); - - // destroy record - nodeService.deleteNode(record); - } - - public void then() - { - // document is still versionable - assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE)); - - // check the initial version label - assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL)); - - // still has a version history, but the version is marked as destroyed - VersionHistory versionHistory = versionService.getVersionHistory(myDocument); - assertNotNull(versionHistory); - assertEquals(1, versionHistory.getAllVersions().size()); - - // check the recorded version is marked as destroyed and the record version is not longer available - Version version = versionHistory.getHeadVersion(); - assertNotNull(version); - assertTrue(recordableVersionService.isRecordedVersionDestroyed(version)); - assertNull(recordableVersionService.getVersionRecord(version)); - } - }); - } - - /** - * Given that a document is created - * And the initial version is record - * And the associated version record is deleted - * When a new version is created - * Then a new associated version record is created - * And the version is 1.1 (not 1.0 since this was deleted, but the version history maintained) - * - * @see https://issues.alfresco.com/jira/browse/RM-2562 - */ - public void testDeleteFirstRecordedVersionAndCreateNewVersion() - { - doBehaviourDrivenTest(new BehaviourDrivenTest() - { - private NodeRef myDocument; - - public void given() throws Exception - { - // create a document - myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); - ContentWriter writer = fileFolderService.getWriter(myDocument); - writer.setEncoding("UTF-8"); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - writer.putContent(GUID.generate()); - - // make versionable - Map props = new HashMap(2); - props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL); - props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan); - nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props); - nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null); - } - - public void when() - { - // get the created version record - VersionHistory versionHistory = versionService.getVersionHistory(myDocument); - Version head = versionHistory.getHeadVersion(); - NodeRef record = recordableVersionService.getVersionRecord(head); - - // destroy record - nodeService.deleteNode(record); - - // update the content to create a new version (and version record) - ContentWriter writer = fileFolderService.getWriter(myDocument); - writer.putContent(GUID.generate()); - } - - public void then() - { - // document is still versionable - assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE)); - - // check the version number has been incremented - assertEquals("1.1", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL)); - - // still has a version history, with 2 enties - VersionHistory versionHistory = versionService.getVersionHistory(myDocument); - assertNotNull(versionHistory); - assertEquals(2, versionHistory.getAllVersions().size()); - - // latest version is current - Version head = versionHistory.getHeadVersion(); - assertFalse(recordableVersionService.isRecordedVersionDestroyed(head)); - assertNotNull(recordableVersionService.getVersionRecord(head)); - - // first version is destroyed - Version destroyed = versionHistory.getPredecessor(head); - assertTrue(recordableVersionService.isRecordedVersionDestroyed(destroyed)); - assertNull(recordableVersionService.getVersionRecord(destroyed)); - - // get the version record for the current version - NodeRef versionRecord = recordableVersionService.getVersionRecord(head); - assertNotNull(versionRecord); - assertTrue(nodeService.exists(versionRecord)); - - Set from = relationshipService.getRelationshipsFrom(versionRecord); - assertTrue(from.isEmpty()); - - Set to = relationshipService.getRelationshipsTo(versionRecord); - assertTrue(to.isEmpty()); - } - }); - } - - /** - * Given a chain of version records (1.0, 1.1, 1.2) which are all related - * When I delete version record 1.0 - * Then 1.1 is the oldest version - */ - public void testDeleteOldestVersion() - { - final NodeRef myDocument = createDocumentWithRecordVersions(); - - doBehaviourDrivenTest(new BehaviourDrivenTest() - { - private VersionHistory versionHistory; - - public void given() throws Exception - { - // get version history - versionHistory = versionService.getVersionHistory(myDocument); - } - - public void when() - { - Version version10 = versionHistory.getVersion("1.0"); - NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); - - // delete record version 1.0 - nodeService.deleteNode(recordVersion10); - } - - public void then() - { - // check the deleted version - Version version10 = versionHistory.getVersion("1.0"); - assertNotNull(version10); - assertTrue(recordableVersionService.isRecordedVersionDestroyed(version10)); - NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); - assertNull(recordVersion10); - - // verify 1.2 setup as expected - Version version12 = versionHistory.getHeadVersion(); - assertEquals("1.2", version12.getVersionLabel()); - NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); - assertNotNull(recordVersion12); - - assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); - - Set from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS); - assertEquals(1, from12.size()); - - // verify 1.1 setup as expected - Version version11 = versionHistory.getPredecessor(version12); - assertEquals("1.1", version11.getVersionLabel()); - NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); - assertNotNull(recordVersion11); - - Set to11 = relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS); - assertEquals(1, to11.size()); - assertEquals(recordVersion12, to11.iterator().next().getSource()); - - assertTrue(relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); - } - }); - } - - /** - * Given a chain of version records (1.0, 1.1, 1.2) which are all related - * When I delete version record 1.1 - * Then 1.2 now 'versions' 1.0 - */ - public void testDeleteMiddleVersion() - { - final NodeRef myDocument = createDocumentWithRecordVersions(); - - doBehaviourDrivenTest(new BehaviourDrivenTest() - { - private VersionHistory versionHistory; - - public void given() throws Exception - { - // get version history - versionHistory = versionService.getVersionHistory(myDocument); - } - - public void when() - { - Version version11 = versionHistory.getVersion("1.1"); - NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); - - // delete record version 1.1 - nodeService.deleteNode(recordVersion11); - } - - public void then() - { - // check the deleted version - Version version11 = versionHistory.getVersion("1.1"); - assertNotNull(version11); - assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11)); - NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); - assertNull(recordVersion11); - - // verify 1.2 setup as expected - Version version12 = versionHistory.getHeadVersion(); - assertEquals("1.2", version12.getVersionLabel()); - NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); - assertNotNull(recordVersion12); - - assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); - - Set from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS); - assertEquals(1, from12.size()); - - // verify 1.0 setup as expected - Version version10 = versionHistory.getVersion("1.0"); - assertEquals("1.0", version10.getVersionLabel()); - NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); - assertNotNull(recordVersion10); - - Set to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS); - assertEquals(1, to10.size()); - assertEquals(recordVersion12, to10.iterator().next().getSource()); - - assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); - - } - }); - } - - /** - * Given a chain of version records (1.0, 1.1, 1.2) which are all related - * When I delete version record 1.2 - * Then 1.1 is the most recent version - */ - public void testDeleteCurrentVersion() - { - final NodeRef myDocument = createDocumentWithRecordVersions(); - - doBehaviourDrivenTest(new BehaviourDrivenTest() - { - private VersionHistory versionHistory; - - public void given() throws Exception - { - // get version history - versionHistory = versionService.getVersionHistory(myDocument); - } - - public void when() - { - Version version12 = versionHistory.getVersion("1.2"); - NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); - - // delete record version 1.2 - nodeService.deleteNode(recordVersion12); - } - - public void then() - { - // check 1.2 - Version version12 = versionHistory.getVersion("1.2"); - assertNotNull(version12); - assertTrue(recordableVersionService.isRecordedVersionDestroyed(version12)); - assertNull(recordableVersionService.getVersionRecord(version12)); - - // verify 1.1 - Version version11 = versionHistory.getVersion("1.1"); - assertNotNull(version11); - NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); - assertNotNull(recordVersion11); - - assertTrue(relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); - - Set from11 = relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS); - assertEquals(1, from11.size()); - - // verify 1.0 - Version version10 = versionHistory.getVersion("1.0"); - assertNotNull(version10); - NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); - assertNotNull(recordVersion10); - - Set to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS); - assertEquals(1, to10.size()); - assertEquals(recordVersion11, to10.iterator().next().getSource()); - - assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); - } - }); - } - - /** - * Given that a version record - * When the version record is destroyed whilst retaining the meta data - * Then the version is marked as destroyed in the collab version history - */ - public void testDestroyVersionRecordWithMetadata() - { - final NodeRef myDocument = createDocumentWithRecordVersions(); - - doBehaviourDrivenTest(new BehaviourDrivenTest() - { - private VersionHistory versionHistory; - private NodeRef recordVersion11; - - public void given() throws Exception - { - // create file plan structure - NodeRef myCategory = filePlanService.createRecordCategory(filePlan, GUID.generate()); - utils.createBasicDispositionSchedule(myCategory, GUID.generate(), GUID.generate(), true, true); - - NodeRef myRecordFolder = recordFolderService.createRecordFolder(myCategory, GUID.generate()); - - // get version history - versionHistory = versionService.getVersionHistory(myDocument); - - // file and complete all the version records into my record folder - for (Version version : versionHistory.getAllVersions()) - { - NodeRef record = recordableVersionService.getVersionRecord(version); - fileFolderService.move(record, myRecordFolder, null); - utils.completeRecord(record); - } - } - - public void when() - { - Version version11 = versionHistory.getVersion("1.1"); - recordVersion11 = recordableVersionService.getVersionRecord(version11); - - Map params = new HashMap(1); - params.put(CompleteEventAction.PARAM_EVENT_NAME, CommonRMTestUtils.DEFAULT_EVENT_NAME); - rmActionService.executeRecordsManagementAction(recordVersion11, CompleteEventAction.NAME, params); - - rmActionService.executeRecordsManagementAction(recordVersion11, CutOffAction.NAME); - - rmActionService.executeRecordsManagementAction(recordVersion11, DestroyAction.NAME); - } - - public void then() - { - // verify that the version history looks as expected - VersionHistory versionHistory = versionService.getVersionHistory(myDocument); - assertNotNull(versionHistory); - Collection versions = versionHistory.getAllVersions(); - assertEquals(3, versions.size()); - - // verify 1.2 setup as expected - Version version12 = versionHistory.getHeadVersion(); - assertEquals("1.2", version12.getVersionLabel()); - assertFalse(recordableVersionService.isRecordedVersionDestroyed(version12)); - NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); - assertNotNull(recordVersion12); - assertFalse(recordService.isMetadataStub(recordVersion12)); - - assertTrue(relationshipService.getRelationshipsTo(recordVersion12, "versions").isEmpty()); - - Set from12 = relationshipService.getRelationshipsFrom(recordVersion12, "versions"); - assertEquals(1, from12.size()); - - // verify 1.1 setup as expected - Version version11 = versionHistory.getPredecessor(version12); - assertEquals("1.1", version11.getVersionLabel()); - assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11)); - assertNotNull(recordVersion11); - assertTrue(recordService.isMetadataStub(recordVersion11)); - - Set to11 = relationshipService.getRelationshipsTo(recordVersion11, "versions"); - assertEquals(1, to11.size()); - assertEquals(recordVersion12, to11.iterator().next().getSource()); - - Set from11 = relationshipService.getRelationshipsFrom(recordVersion11, "versions"); - assertEquals(1, from11.size()); - - // verify 1.0 setup as expected - Version version10 = versionHistory.getPredecessor(version11); - assertEquals("1.0", version10.getVersionLabel()); - assertFalse(recordableVersionService.isRecordedVersionDestroyed(version10)); - NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); - assertNotNull(recordVersion10); - assertFalse(recordService.isMetadataStub(recordVersion10)); - - Set to10 = relationshipService.getRelationshipsTo(recordVersion10, "versions"); - assertEquals(1, to10.size()); - assertEquals(recordVersion11, to10.iterator().next().getSource()); - - assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, "versions").isEmpty()); - - } - }); - } -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.integration.version; + +import java.io.Serializable; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.action.impl.CompleteEventAction; +import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction; +import org.alfresco.module.org_alfresco_module_rm.action.impl.DestroyAction; +import org.alfresco.module.org_alfresco_module_rm.relationship.Relationship; +import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService; +import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils; +import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel; +import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy; +import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.version.Version; +import org.alfresco.service.cmr.version.VersionHistory; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.GUID; + +/** + * Recordable version history integration tests. + * + * @author Roy Wetherall + * @since 2.3.1 + */ +public class DeleteRecordVersionTest extends RecordableVersionsBaseTest +{ + /** + * Given that a document is created + * And the initial version is record + * When I delete the version record + * Then the version is deleted + * And the version history is not deleted + * + * @see https://issues.alfresco.com/jira/browse/RM-2562 + */ + public void testDeleteFirstRecordedVersion() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef myDocument; + + public void given() throws Exception + { + // create a document + myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); + + // make versionable + Map props = new HashMap(2); + props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL); + props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan); + nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props); + nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null); + } + + public void when() + { + // check the initial version label + assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL)); + + // check that the version history contains a single version that is recorded + VersionHistory versionHistory = versionService.getVersionHistory(myDocument); + assertNotNull(versionHistory); + assertEquals(1, versionHistory.getAllVersions().size()); + + // check the recorded version is not marked as destroyed + Version head = versionHistory.getHeadVersion(); + assertNotNull(head); + assertFalse(recordableVersionService.isRecordedVersionDestroyed(head)); + + // check the version record + NodeRef record = recordableVersionService.getVersionRecord(head); + assertTrue(recordService.isRecord(record)); + + // record should not have a version history because it is immutable + assertFalse(nodeService.hasAspect(record, ContentModel.ASPECT_VERSIONABLE)); + VersionHistory recordVersionHistory = versionService.getVersionHistory(record); + assertNull(recordVersionHistory); + + // destroy record + nodeService.deleteNode(record); + } + + public void then() + { + // document is still versionable + assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE)); + + // check the initial version label + assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL)); + + // still has a version history, but the version is marked as destroyed + VersionHistory versionHistory = versionService.getVersionHistory(myDocument); + assertNotNull(versionHistory); + assertEquals(1, versionHistory.getAllVersions().size()); + + // check the recorded version is marked as destroyed and the record version is not longer available + Version version = versionHistory.getHeadVersion(); + assertNotNull(version); + assertTrue(recordableVersionService.isRecordedVersionDestroyed(version)); + assertNull(recordableVersionService.getVersionRecord(version)); + } + }); + } + + /** + * Given that a document is created + * And the initial version is record + * And the associated version record is deleted + * When a new version is created + * Then a new associated version record is created + * And the version is 1.1 (not 1.0 since this was deleted, but the version history maintained) + * + * @see https://issues.alfresco.com/jira/browse/RM-2562 + */ + public void testDeleteFirstRecordedVersionAndCreateNewVersion() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef myDocument; + + public void given() throws Exception + { + // create a document + myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); + ContentWriter writer = fileFolderService.getWriter(myDocument); + writer.setEncoding("UTF-8"); + writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); + writer.putContent(GUID.generate()); + + // make versionable + Map props = new HashMap(2); + props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL); + props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan); + nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props); + nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null); + } + + public void when() + { + // get the created version record + VersionHistory versionHistory = versionService.getVersionHistory(myDocument); + Version head = versionHistory.getHeadVersion(); + NodeRef record = recordableVersionService.getVersionRecord(head); + + // destroy record + nodeService.deleteNode(record); + + // update the content to create a new version (and version record) + ContentWriter writer = fileFolderService.getWriter(myDocument); + writer.putContent(GUID.generate()); + } + + public void then() + { + // document is still versionable + assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE)); + + // check the version number has been incremented + assertEquals("1.1", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL)); + + // still has a version history, with 2 enties + VersionHistory versionHistory = versionService.getVersionHistory(myDocument); + assertNotNull(versionHistory); + assertEquals(2, versionHistory.getAllVersions().size()); + + // latest version is current + Version head = versionHistory.getHeadVersion(); + assertFalse(recordableVersionService.isRecordedVersionDestroyed(head)); + assertNotNull(recordableVersionService.getVersionRecord(head)); + + // first version is destroyed + Version destroyed = versionHistory.getPredecessor(head); + assertTrue(recordableVersionService.isRecordedVersionDestroyed(destroyed)); + assertNull(recordableVersionService.getVersionRecord(destroyed)); + + // get the version record for the current version + NodeRef versionRecord = recordableVersionService.getVersionRecord(head); + assertNotNull(versionRecord); + assertTrue(nodeService.exists(versionRecord)); + + Set from = relationshipService.getRelationshipsFrom(versionRecord); + assertTrue(from.isEmpty()); + + Set to = relationshipService.getRelationshipsTo(versionRecord); + assertTrue(to.isEmpty()); + } + }); + } + + /** + * Given a chain of version records (1.0, 1.1, 1.2) which are all related + * When I delete version record 1.0 + * Then 1.1 is the oldest version + */ + public void testDeleteOldestVersion() + { + final NodeRef myDocument = createDocumentWithRecordVersions(); + + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private VersionHistory versionHistory; + + public void given() throws Exception + { + // get version history + versionHistory = versionService.getVersionHistory(myDocument); + } + + public void when() + { + Version version10 = versionHistory.getVersion("1.0"); + NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); + + // delete record version 1.0 + nodeService.deleteNode(recordVersion10); + } + + public void then() + { + // check the deleted version + Version version10 = versionHistory.getVersion("1.0"); + assertNotNull(version10); + assertTrue(recordableVersionService.isRecordedVersionDestroyed(version10)); + NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); + assertNull(recordVersion10); + + // verify 1.2 setup as expected + Version version12 = versionHistory.getHeadVersion(); + assertEquals("1.2", version12.getVersionLabel()); + NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); + assertNotNull(recordVersion12); + + assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); + + Set from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS); + assertEquals(1, from12.size()); + + // verify 1.1 setup as expected + Version version11 = versionHistory.getPredecessor(version12); + assertEquals("1.1", version11.getVersionLabel()); + NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); + assertNotNull(recordVersion11); + + Set to11 = relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS); + assertEquals(1, to11.size()); + assertEquals(recordVersion12, to11.iterator().next().getSource()); + + assertTrue(relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); + } + }); + } + + /** + * Given a chain of version records (1.0, 1.1, 1.2) which are all related + * When I delete version record 1.1 + * Then 1.2 now 'versions' 1.0 + */ + public void testDeleteMiddleVersion() + { + final NodeRef myDocument = createDocumentWithRecordVersions(); + + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private VersionHistory versionHistory; + + public void given() throws Exception + { + // get version history + versionHistory = versionService.getVersionHistory(myDocument); + } + + public void when() + { + Version version11 = versionHistory.getVersion("1.1"); + NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); + + // delete record version 1.1 + nodeService.deleteNode(recordVersion11); + } + + public void then() + { + // check the deleted version + Version version11 = versionHistory.getVersion("1.1"); + assertNotNull(version11); + assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11)); + NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); + assertNull(recordVersion11); + + // verify 1.2 setup as expected + Version version12 = versionHistory.getHeadVersion(); + assertEquals("1.2", version12.getVersionLabel()); + NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); + assertNotNull(recordVersion12); + + assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); + + Set from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS); + assertEquals(1, from12.size()); + + // verify 1.0 setup as expected + Version version10 = versionHistory.getVersion("1.0"); + assertEquals("1.0", version10.getVersionLabel()); + NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); + assertNotNull(recordVersion10); + + Set to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS); + assertEquals(1, to10.size()); + assertEquals(recordVersion12, to10.iterator().next().getSource()); + + assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); + + } + }); + } + + /** + * Given a chain of version records (1.0, 1.1, 1.2) which are all related + * When I delete version record 1.2 + * Then 1.1 is the most recent version + */ + public void testDeleteCurrentVersion() + { + final NodeRef myDocument = createDocumentWithRecordVersions(); + + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private VersionHistory versionHistory; + + public void given() throws Exception + { + // get version history + versionHistory = versionService.getVersionHistory(myDocument); + } + + public void when() + { + Version version12 = versionHistory.getVersion("1.2"); + NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); + + // delete record version 1.2 + nodeService.deleteNode(recordVersion12); + } + + public void then() + { + // check 1.2 + Version version12 = versionHistory.getVersion("1.2"); + assertNotNull(version12); + assertTrue(recordableVersionService.isRecordedVersionDestroyed(version12)); + assertNull(recordableVersionService.getVersionRecord(version12)); + + // verify 1.1 + Version version11 = versionHistory.getVersion("1.1"); + assertNotNull(version11); + NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); + assertNotNull(recordVersion11); + + assertTrue(relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); + + Set from11 = relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS); + assertEquals(1, from11.size()); + + // verify 1.0 + Version version10 = versionHistory.getVersion("1.0"); + assertNotNull(version10); + NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); + assertNotNull(recordVersion10); + + Set to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS); + assertEquals(1, to10.size()); + assertEquals(recordVersion11, to10.iterator().next().getSource()); + + assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); + } + }); + } + + /** + * Given that a version record + * When the version record is destroyed whilst retaining the meta data + * Then the version is marked as destroyed in the collab version history + */ + public void testDestroyVersionRecordWithMetadata() + { + final NodeRef myDocument = createDocumentWithRecordVersions(); + + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private VersionHistory versionHistory; + private NodeRef recordVersion11; + + public void given() throws Exception + { + // create file plan structure + NodeRef myCategory = filePlanService.createRecordCategory(filePlan, GUID.generate()); + utils.createBasicDispositionSchedule(myCategory, GUID.generate(), GUID.generate(), true, true); + + NodeRef myRecordFolder = recordFolderService.createRecordFolder(myCategory, GUID.generate()); + + // get version history + versionHistory = versionService.getVersionHistory(myDocument); + + // file and complete all the version records into my record folder + for (Version version : versionHistory.getAllVersions()) + { + NodeRef record = recordableVersionService.getVersionRecord(version); + fileFolderService.move(record, myRecordFolder, null); + utils.completeRecord(record); + } + } + + public void when() + { + Version version11 = versionHistory.getVersion("1.1"); + recordVersion11 = recordableVersionService.getVersionRecord(version11); + + Map params = new HashMap(1); + params.put(CompleteEventAction.PARAM_EVENT_NAME, CommonRMTestUtils.DEFAULT_EVENT_NAME); + rmActionService.executeRecordsManagementAction(recordVersion11, CompleteEventAction.NAME, params); + + rmActionService.executeRecordsManagementAction(recordVersion11, CutOffAction.NAME); + + rmActionService.executeRecordsManagementAction(recordVersion11, DestroyAction.NAME); + } + + public void then() + { + // verify that the version history looks as expected + VersionHistory versionHistory = versionService.getVersionHistory(myDocument); + assertNotNull(versionHistory); + Collection versions = versionHistory.getAllVersions(); + assertEquals(3, versions.size()); + + // verify 1.2 setup as expected + Version version12 = versionHistory.getHeadVersion(); + assertEquals("1.2", version12.getVersionLabel()); + assertFalse(recordableVersionService.isRecordedVersionDestroyed(version12)); + NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); + assertNotNull(recordVersion12); + assertFalse(recordService.isMetadataStub(recordVersion12)); + + assertTrue(relationshipService.getRelationshipsTo(recordVersion12, "versions").isEmpty()); + + Set from12 = relationshipService.getRelationshipsFrom(recordVersion12, "versions"); + assertEquals(1, from12.size()); + + // verify 1.1 setup as expected + Version version11 = versionHistory.getPredecessor(version12); + assertEquals("1.1", version11.getVersionLabel()); + assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11)); + assertNotNull(recordVersion11); + assertTrue(recordService.isMetadataStub(recordVersion11)); + + Set to11 = relationshipService.getRelationshipsTo(recordVersion11, "versions"); + assertEquals(1, to11.size()); + assertEquals(recordVersion12, to11.iterator().next().getSource()); + + Set from11 = relationshipService.getRelationshipsFrom(recordVersion11, "versions"); + assertEquals(1, from11.size()); + + // verify 1.0 setup as expected + Version version10 = versionHistory.getPredecessor(version11); + assertEquals("1.0", version10.getVersionLabel()); + assertFalse(recordableVersionService.isRecordedVersionDestroyed(version10)); + NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); + assertNotNull(recordVersion10); + assertFalse(recordService.isMetadataStub(recordVersion10)); + + Set to10 = relationshipService.getRelationshipsTo(recordVersion10, "versions"); + assertEquals(1, to10.size()); + assertEquals(recordVersion11, to10.iterator().next().getSource()); + + assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, "versions").isEmpty()); + + } + }); + } +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementServiceImplTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementServiceImplTest.java index 2258b305cc..61bbdc9c1b 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementServiceImplTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementServiceImplTest.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,603 +21,603 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.legacy.service; - -import java.util.ArrayList; -import java.util.List; - -import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind; -import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; -import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.GUID; - -/** - * Records management service test. - * - * @author Roy Wetherall - */ -public class RecordsManagementServiceImplTest extends BaseRMTestCase -{ - /********** RM Component methods **********/ - - /** - * @see FilePlanService#isFilePlanComponent(NodeRef) - */ - public void testIsFilePlanComponent() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - assertTrue("The rm root container should be a rm component", filePlanService.isFilePlanComponent(filePlan)); - assertTrue("The rm container should be a rm component", filePlanService.isFilePlanComponent(rmContainer)); - assertTrue("The rm folder should be a rm component", filePlanService.isFilePlanComponent(rmFolder)); - - return null; - } - }); - } - - /** - * @see FilePlanService#getFilePlanComponentKind(NodeRef) - */ - public void testGetFilePlanComponentKind() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public NodeRef run() throws Exception - { - return utils.createRecord(rmFolder, "testRecord.txt"); - } - - @Override - public void test(NodeRef result) throws Exception - { - assertEquals(FilePlanComponentKind.FILE_PLAN, filePlanService.getFilePlanComponentKind(filePlan)); - assertEquals(FilePlanComponentKind.RECORD_CATEGORY, filePlanService.getFilePlanComponentKind(rmContainer)); - assertEquals(FilePlanComponentKind.RECORD_FOLDER, filePlanService.getFilePlanComponentKind(rmFolder)); - assertEquals(FilePlanComponentKind.RECORD, filePlanService.getFilePlanComponentKind(result)); - // TODO HOLD and TRANSFER - assertNull(filePlanService.getFilePlanComponentKind(folder)); - } - }); - } - - /** - * @see FilePlanService#isFilePlan(NodeRef) - */ - public void testIsFilePlan() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - assertTrue("This is a records management root", filePlanService.isFilePlan(filePlan)); - assertFalse("This should not be a records management root", filePlanService.isFilePlan(rmContainer)); - assertFalse("This should not be a records management root", filePlanService.isFilePlan(rmFolder)); - - return null; - } - }); - } - - /** - * @see FilePlanService#isRecordCategory(NodeRef) - */ - public void testIsRecordCategory() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - assertFalse("This should not be a record category.", filePlanService.isRecordCategory(filePlan)); - assertTrue("This is a record category.", filePlanService.isRecordCategory(rmContainer)); - assertFalse("This should not be a record category.", filePlanService.isRecordCategory(rmFolder)); - - return null; - } - }); - } - - /** - * @see RecordFolderService#isRecordFolder(NodeRef) - */ - public void testIsRecordFolder() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - assertFalse("This should not be a record folder", recordFolderService.isRecordFolder(filePlan)); - assertFalse("This should not be a record folder", recordFolderService.isRecordFolder(rmContainer)); - assertTrue("This should be a record folder", recordFolderService.isRecordFolder(rmFolder)); - - return null; - } - }); - } - - public void testGetRecordsManagementRoot() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - assertEquals(filePlan, filePlanService.getFilePlan(filePlan)); - assertEquals(filePlan, filePlanService.getFilePlan(rmContainer)); - assertEquals(filePlan, filePlanService.getFilePlan(rmFolder)); - - return null; - } - }); - } - - /********** Record Management Root methods **********/ - - /** - * @see FilePlanService#getFilePlans() - */ - public void testGetRecordsManagementRoots() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - List roots = new ArrayList(filePlanService.getFilePlans()); - assertNotNull(roots); - assertTrue(roots.size() != 0); - assertTrue(roots.contains(filePlan)); - - return null; - } - }); - } - - /** - * @see FilePlanService#createFilePlan(NodeRef, String) - * @see FilePlanService#createFilePlan(NodeRef, String, QName) - */ - public void testCreateFilePlan() throws Exception - { - // Create default type of root - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - String id = setString("id", GUID.generate()); - return filePlanService.createFilePlan(folder, id); - } - - @Override - public void test(NodeRef result) - { - assertNotNull("Unable to create records management root", result); - basicRMContainerCheck(result, getString("id"), TYPE_FILE_PLAN); - } - }); - - // Create specific type of root - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - String id = setString("id", GUID.generate()); - return filePlanService.createFilePlan(folder, id, TYPE_FILE_PLAN); - } - - @Override - public void test(NodeRef result) - { - assertNotNull("Unable to create records management root", result); - basicRMContainerCheck(result, getString("id"), TYPE_FILE_PLAN); - } - }); - - // Failure: creating root in existing hierarchy - doTestInTransaction(new FailureTest() - { - @Override - public void run() - { - filePlanService.createFilePlan(rmContainer, GUID.generate()); - } - }); - - // Failure: type no extended from root container - doTestInTransaction(new FailureTest() - { - @Override - public void run() - { - filePlanService.createFilePlan(folder, GUID.generate(), TYPE_FOLDER); - } - }); - } - - /********** Records Management Container methods **********/ - - /** - * @see FilePlanService#createRecordCategory(NodeRef, String) - * @see FilePlanService#createFilePlan(NodeRef, String, QName) - */ - public void testCreateRecordCategory() throws Exception - { - // Create container (in root) - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - String id = setString("id", GUID.generate()); - return filePlanService.createRecordCategory(filePlan, id); - } - - @Override - public void test(NodeRef result) - { - assertNotNull("Unable to create records management container", result); - basicRMContainerCheck(result, getString("id"), TYPE_RECORD_CATEGORY); - } - }); - - // Create container (in container) - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - String id = setString("id", GUID.generate()); - return filePlanService.createRecordCategory(rmContainer, id); - } - - @Override - public void test(NodeRef result) - { - assertNotNull("Unable to create records management container", result); - basicRMContainerCheck(result, getString("id"), TYPE_RECORD_CATEGORY); - } - }); - - // TODO need a custom type of container! - // Create container of a given type -// doTestInTransaction(new Test() -// { -// @Override -// public NodeRef run() -// { -// String id = setString("id", GUID.generate()); -// return filePlanService.createRecordCategory(filePlan, id, TYPE_RECORD_SERIES); -// } -// -// @Override -// public void test(NodeRef result) -// { -// assertNotNull("Unable to create records management container", result); -// basicRMContainerCheck(result, getString("id"), TYPE_RECORD_SERIES); -// } -// }); - - // Fail Test: parent is not a container - doTestInTransaction(new FailureTest() - { - @Override - public void run() - { - filePlanService.createRecordCategory(folder, GUID.generate()); - } - }); - - // Fail Test: type is not a sub-type of rm:recordsManagementContainer - doTestInTransaction(new FailureTest() - { - @Override - public void run() - { - filePlanService.createRecordCategory(filePlan, GUID.generate(), TYPE_FOLDER); - } - }); - } - - /** - * @see FilePlanService#getAllContained(NodeRef) - * @see FilePlanService#getAllContained(NodeRef, boolean) - */ - public void testGetAllContained() throws Exception - { - // Get all contained test - doTestInTransaction(new Test() - { - @Override - public Void run() - { - // Add to the test data - NodeRef series = filePlanService.createRecordCategory(rmContainer, "rmSeries"); - NodeRef seriesChildFolder = recordFolderService.createRecordFolder(series, "seriesRecordFolder"); - NodeRef seriesChildContainer = filePlanService.createRecordCategory(series, "childContainer"); - - // Put in model - setNodeRef("series", series); - setNodeRef("seriesChildFolder", seriesChildFolder); - setNodeRef("seriesChildContainer", seriesChildContainer); - - return null; - } - - @Override - public void test(Void result) throws Exception - { - List nodes = filePlanService.getAllContained(rmContainer); - assertNotNull(nodes); - assertEquals(2, nodes.size()); - assertTrue(nodes.contains(getNodeRef("series"))); - assertTrue(nodes.contains(rmFolder)); - - nodes = filePlanService.getAllContained(rmContainer, false); - assertNotNull(nodes); - assertEquals(2, nodes.size()); - assertTrue(nodes.contains(getNodeRef("series"))); - assertTrue(nodes.contains(rmFolder)); - - nodes = filePlanService.getAllContained(rmContainer, true); - assertNotNull(nodes); - assertEquals(4, nodes.size()); - assertTrue(nodes.contains(getNodeRef("series"))); - assertTrue(nodes.contains(rmFolder)); - assertTrue(nodes.contains(getNodeRef("seriesChildFolder"))); - assertTrue(nodes.contains(getNodeRef("seriesChildContainer"))); - - } - }); - - // Failure: call on record folder - doTestInTransaction(new FailureTest() - { - @Override - public void run() - { - filePlanService.getAllContained(rmFolder); - } - }); - } - - /** - * @see FilePlanService#getContainedRecordCategories(NodeRef) - * @see FilePlanService#getContainedRecordCategories(NodeRef, boolean) - */ - public void testGetContainedRecordCategories() throws Exception - { - // Test getting all contained containers - doTestInTransaction(new Test() - { - @Override - public Void run() - { - // Add to the test data - NodeRef series = filePlanService.createRecordCategory(rmContainer, "rmSeries"); - NodeRef seriesChildFolder = recordFolderService.createRecordFolder(series, "seriesRecordFolder"); - NodeRef seriesChildContainer = filePlanService.createRecordCategory(series, "childContainer"); - - // Put in model - setNodeRef("series", series); - setNodeRef("seriesChildFolder", seriesChildFolder); - setNodeRef("seriesChildContainer", seriesChildContainer); - - return null; - } - - @Override - public void test(Void result) throws Exception - { - List nodes = filePlanService.getContainedRecordCategories(rmContainer); - assertNotNull(nodes); - assertEquals(1, nodes.size()); - assertTrue(nodes.contains(getNodeRef("series"))); - - nodes = filePlanService.getContainedRecordCategories(rmContainer, false); - assertNotNull(nodes); - assertEquals(1, nodes.size()); - assertTrue(nodes.contains(getNodeRef("series"))); - - nodes = filePlanService.getContainedRecordCategories(rmContainer, true); - assertNotNull(nodes); - assertEquals(2, nodes.size()); - assertTrue(nodes.contains(getNodeRef("series"))); - assertTrue(nodes.contains(getNodeRef("seriesChildContainer"))); - } - }); - - // Failure: call on record folder - doTestInTransaction(new FailureTest() - { - @Override - public void run() - { - filePlanService.getContainedRecordCategories(rmFolder); - } - }); - } - - /** - * @see FilePlanService#getContainedRecordFolders(NodeRef) - * @see FilePlanService#getContainedRecordFolders(NodeRef, boolean) - */ - public void testGetContainedRecordFolders() throws Exception - { - // Test getting all contained record folders - doTestInTransaction(new Test() - { - @Override - public Void run() - { - // Add to the test data - NodeRef series = filePlanService.createRecordCategory(rmContainer, "rmSeries"); - NodeRef seriesChildFolder = recordFolderService.createRecordFolder(series, "seriesRecordFolder"); - NodeRef seriesChildContainer = filePlanService.createRecordCategory(series, "childContainer"); - - // Put in model - setNodeRef("series", series); - setNodeRef("seriesChildFolder", seriesChildFolder); - setNodeRef("seriesChildContainer", seriesChildContainer); - - return null; - } - - @Override - public void test(Void result) throws Exception - { - List nodes = filePlanService.getContainedRecordFolders(rmContainer); - assertNotNull(nodes); - assertEquals(1, nodes.size()); - assertTrue(nodes.contains(rmFolder)); - - nodes = filePlanService.getContainedRecordFolders(rmContainer, false); - assertNotNull(nodes); - assertEquals(1, nodes.size()); - assertTrue(nodes.contains(rmFolder)); - - nodes = filePlanService.getContainedRecordFolders(rmContainer, true); - assertNotNull(nodes); - assertEquals(2, nodes.size()); - assertTrue(nodes.contains(rmFolder)); - assertTrue(nodes.contains(getNodeRef("seriesChildFolder"))); - } - }); - - // Failure: call on record folder - doTestInTransaction(new FailureTest() - { - @Override - public void run() - { - filePlanService.getContainedRecordFolders(rmFolder); - } - }); - } - - /********** Record Folder methods **********/ - - // TODO void testIsRecordFolderDeclared() - - // TODO void testIsRecordFolderClosed() - - // TODO void testGetRecords() - - /** - * @see RecordFolderService#createRecordFolder(NodeRef, String) - * @see RecordFolderService#createRecordFolder(NodeRef, String, QName) - */ - public void testCreateRecordFolder() throws Exception - { - // Create record - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - String id = setString("id", GUID.generate()); - return recordFolderService.createRecordFolder(rmContainer, id); - } - - @Override - public void test(NodeRef result) - { - assertNotNull("Unable to create record folder", result); - basicRMContainerCheck(result, getString("id"), TYPE_RECORD_FOLDER); - } - }); - - // TODO Create record of type - - // Failure: Create record with invalid type - doTestInTransaction(new FailureTest() - { - @Override - public void run() - { - recordFolderService.createRecordFolder(rmContainer, GUID.generate(), TYPE_FOLDER); - } - }); - - // Failure: Create record folder in root - doTestInTransaction(new FailureTest() - { - @Override - public void run() - { - recordFolderService.createRecordFolder(filePlan, GUID.generate()); - } - }); - } - - - /********** RM2 - Multi-hierarchy record taxonomy's **********/ - - /** - * Test to create a simple multi-hierarchy record taxonomy - */ - public void testCreateSimpleHierarchy() - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - // Create 3 level hierarchy - NodeRef levelOne = setNodeRef("container1", filePlanService.createRecordCategory(filePlan, "container1")); - assertNotNull("Unable to create container", levelOne); - NodeRef levelTwo = setNodeRef("container2", filePlanService.createRecordCategory(levelOne, "container2")); - assertNotNull("Unable to create container", levelTwo); - NodeRef levelThree = setNodeRef("container3", filePlanService.createRecordCategory(levelTwo, "container3")); - assertNotNull("Unable to create container", levelThree); - NodeRef levelThreeRecordFolder = setNodeRef("recordFolder3", recordFolderService.createRecordFolder(levelThree, "recordFolder3")); - assertNotNull("Unable to create record folder", levelThreeRecordFolder); - - return null; - } - - @Override - public void test(Void result) - { - // Test that the hierarchy has been created correctly - basicRMContainerCheck(getNodeRef("container1"), "container1", TYPE_RECORD_CATEGORY); - basicRMContainerCheck(getNodeRef("container2"), "container2", TYPE_RECORD_CATEGORY); - basicRMContainerCheck(getNodeRef("container3"), "container3", TYPE_RECORD_CATEGORY); - basicRMContainerCheck(getNodeRef("recordFolder3"), "recordFolder3", TYPE_RECORD_FOLDER); - - // TODO need to check that the parents and children can be retrieved correctly - } - }); - } - - /** - * A basic test of a records management container - * - * @param nodeRef node reference - * @param name name of the container - * @param type the type of container - */ - private void basicRMContainerCheck(NodeRef nodeRef, String name, QName type) - { - // Check the basic details - assertEquals(name, nodeService.getProperty(nodeRef, PROP_NAME)); - assertNotNull("RM id has not been set", nodeService.getProperty(nodeRef, PROP_IDENTIFIER)); - assertEquals(type, nodeService.getType(nodeRef)); - } - -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.legacy.service; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind; +import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; +import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.GUID; + +/** + * Records management service test. + * + * @author Roy Wetherall + */ +public class RecordsManagementServiceImplTest extends BaseRMTestCase +{ + /********** RM Component methods **********/ + + /** + * @see FilePlanService#isFilePlanComponent(NodeRef) + */ + public void testIsFilePlanComponent() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + assertTrue("The rm root container should be a rm component", filePlanService.isFilePlanComponent(filePlan)); + assertTrue("The rm container should be a rm component", filePlanService.isFilePlanComponent(rmContainer)); + assertTrue("The rm folder should be a rm component", filePlanService.isFilePlanComponent(rmFolder)); + + return null; + } + }); + } + + /** + * @see FilePlanService#getFilePlanComponentKind(NodeRef) + */ + public void testGetFilePlanComponentKind() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() throws Exception + { + return utils.createRecord(rmFolder, "testRecord.txt"); + } + + @Override + public void test(NodeRef result) throws Exception + { + assertEquals(FilePlanComponentKind.FILE_PLAN, filePlanService.getFilePlanComponentKind(filePlan)); + assertEquals(FilePlanComponentKind.RECORD_CATEGORY, filePlanService.getFilePlanComponentKind(rmContainer)); + assertEquals(FilePlanComponentKind.RECORD_FOLDER, filePlanService.getFilePlanComponentKind(rmFolder)); + assertEquals(FilePlanComponentKind.RECORD, filePlanService.getFilePlanComponentKind(result)); + // TODO HOLD and TRANSFER + assertNull(filePlanService.getFilePlanComponentKind(folder)); + } + }); + } + + /** + * @see FilePlanService#isFilePlan(NodeRef) + */ + public void testIsFilePlan() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + assertTrue("This is a records management root", filePlanService.isFilePlan(filePlan)); + assertFalse("This should not be a records management root", filePlanService.isFilePlan(rmContainer)); + assertFalse("This should not be a records management root", filePlanService.isFilePlan(rmFolder)); + + return null; + } + }); + } + + /** + * @see FilePlanService#isRecordCategory(NodeRef) + */ + public void testIsRecordCategory() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + assertFalse("This should not be a record category.", filePlanService.isRecordCategory(filePlan)); + assertTrue("This is a record category.", filePlanService.isRecordCategory(rmContainer)); + assertFalse("This should not be a record category.", filePlanService.isRecordCategory(rmFolder)); + + return null; + } + }); + } + + /** + * @see RecordFolderService#isRecordFolder(NodeRef) + */ + public void testIsRecordFolder() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + assertFalse("This should not be a record folder", recordFolderService.isRecordFolder(filePlan)); + assertFalse("This should not be a record folder", recordFolderService.isRecordFolder(rmContainer)); + assertTrue("This should be a record folder", recordFolderService.isRecordFolder(rmFolder)); + + return null; + } + }); + } + + public void testGetRecordsManagementRoot() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + assertEquals(filePlan, filePlanService.getFilePlan(filePlan)); + assertEquals(filePlan, filePlanService.getFilePlan(rmContainer)); + assertEquals(filePlan, filePlanService.getFilePlan(rmFolder)); + + return null; + } + }); + } + + /********** Record Management Root methods **********/ + + /** + * @see FilePlanService#getFilePlans() + */ + public void testGetRecordsManagementRoots() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + List roots = new ArrayList(filePlanService.getFilePlans()); + assertNotNull(roots); + assertTrue(roots.size() != 0); + assertTrue(roots.contains(filePlan)); + + return null; + } + }); + } + + /** + * @see FilePlanService#createFilePlan(NodeRef, String) + * @see FilePlanService#createFilePlan(NodeRef, String, QName) + */ + public void testCreateFilePlan() throws Exception + { + // Create default type of root + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + String id = setString("id", GUID.generate()); + return filePlanService.createFilePlan(folder, id); + } + + @Override + public void test(NodeRef result) + { + assertNotNull("Unable to create records management root", result); + basicRMContainerCheck(result, getString("id"), TYPE_FILE_PLAN); + } + }); + + // Create specific type of root + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + String id = setString("id", GUID.generate()); + return filePlanService.createFilePlan(folder, id, TYPE_FILE_PLAN); + } + + @Override + public void test(NodeRef result) + { + assertNotNull("Unable to create records management root", result); + basicRMContainerCheck(result, getString("id"), TYPE_FILE_PLAN); + } + }); + + // Failure: creating root in existing hierarchy + doTestInTransaction(new FailureTest() + { + @Override + public void run() + { + filePlanService.createFilePlan(rmContainer, GUID.generate()); + } + }); + + // Failure: type no extended from root container + doTestInTransaction(new FailureTest() + { + @Override + public void run() + { + filePlanService.createFilePlan(folder, GUID.generate(), TYPE_FOLDER); + } + }); + } + + /********** Records Management Container methods **********/ + + /** + * @see FilePlanService#createRecordCategory(NodeRef, String) + * @see FilePlanService#createFilePlan(NodeRef, String, QName) + */ + public void testCreateRecordCategory() throws Exception + { + // Create container (in root) + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + String id = setString("id", GUID.generate()); + return filePlanService.createRecordCategory(filePlan, id); + } + + @Override + public void test(NodeRef result) + { + assertNotNull("Unable to create records management container", result); + basicRMContainerCheck(result, getString("id"), TYPE_RECORD_CATEGORY); + } + }); + + // Create container (in container) + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + String id = setString("id", GUID.generate()); + return filePlanService.createRecordCategory(rmContainer, id); + } + + @Override + public void test(NodeRef result) + { + assertNotNull("Unable to create records management container", result); + basicRMContainerCheck(result, getString("id"), TYPE_RECORD_CATEGORY); + } + }); + + // TODO need a custom type of container! + // Create container of a given type +// doTestInTransaction(new Test() +// { +// @Override +// public NodeRef run() +// { +// String id = setString("id", GUID.generate()); +// return filePlanService.createRecordCategory(filePlan, id, TYPE_RECORD_SERIES); +// } +// +// @Override +// public void test(NodeRef result) +// { +// assertNotNull("Unable to create records management container", result); +// basicRMContainerCheck(result, getString("id"), TYPE_RECORD_SERIES); +// } +// }); + + // Fail Test: parent is not a container + doTestInTransaction(new FailureTest() + { + @Override + public void run() + { + filePlanService.createRecordCategory(folder, GUID.generate()); + } + }); + + // Fail Test: type is not a sub-type of rm:recordsManagementContainer + doTestInTransaction(new FailureTest() + { + @Override + public void run() + { + filePlanService.createRecordCategory(filePlan, GUID.generate(), TYPE_FOLDER); + } + }); + } + + /** + * @see FilePlanService#getAllContained(NodeRef) + * @see FilePlanService#getAllContained(NodeRef, boolean) + */ + public void testGetAllContained() throws Exception + { + // Get all contained test + doTestInTransaction(new Test() + { + @Override + public Void run() + { + // Add to the test data + NodeRef series = filePlanService.createRecordCategory(rmContainer, "rmSeries"); + NodeRef seriesChildFolder = recordFolderService.createRecordFolder(series, "seriesRecordFolder"); + NodeRef seriesChildContainer = filePlanService.createRecordCategory(series, "childContainer"); + + // Put in model + setNodeRef("series", series); + setNodeRef("seriesChildFolder", seriesChildFolder); + setNodeRef("seriesChildContainer", seriesChildContainer); + + return null; + } + + @Override + public void test(Void result) throws Exception + { + List nodes = filePlanService.getAllContained(rmContainer); + assertNotNull(nodes); + assertEquals(2, nodes.size()); + assertTrue(nodes.contains(getNodeRef("series"))); + assertTrue(nodes.contains(rmFolder)); + + nodes = filePlanService.getAllContained(rmContainer, false); + assertNotNull(nodes); + assertEquals(2, nodes.size()); + assertTrue(nodes.contains(getNodeRef("series"))); + assertTrue(nodes.contains(rmFolder)); + + nodes = filePlanService.getAllContained(rmContainer, true); + assertNotNull(nodes); + assertEquals(4, nodes.size()); + assertTrue(nodes.contains(getNodeRef("series"))); + assertTrue(nodes.contains(rmFolder)); + assertTrue(nodes.contains(getNodeRef("seriesChildFolder"))); + assertTrue(nodes.contains(getNodeRef("seriesChildContainer"))); + + } + }); + + // Failure: call on record folder + doTestInTransaction(new FailureTest() + { + @Override + public void run() + { + filePlanService.getAllContained(rmFolder); + } + }); + } + + /** + * @see FilePlanService#getContainedRecordCategories(NodeRef) + * @see FilePlanService#getContainedRecordCategories(NodeRef, boolean) + */ + public void testGetContainedRecordCategories() throws Exception + { + // Test getting all contained containers + doTestInTransaction(new Test() + { + @Override + public Void run() + { + // Add to the test data + NodeRef series = filePlanService.createRecordCategory(rmContainer, "rmSeries"); + NodeRef seriesChildFolder = recordFolderService.createRecordFolder(series, "seriesRecordFolder"); + NodeRef seriesChildContainer = filePlanService.createRecordCategory(series, "childContainer"); + + // Put in model + setNodeRef("series", series); + setNodeRef("seriesChildFolder", seriesChildFolder); + setNodeRef("seriesChildContainer", seriesChildContainer); + + return null; + } + + @Override + public void test(Void result) throws Exception + { + List nodes = filePlanService.getContainedRecordCategories(rmContainer); + assertNotNull(nodes); + assertEquals(1, nodes.size()); + assertTrue(nodes.contains(getNodeRef("series"))); + + nodes = filePlanService.getContainedRecordCategories(rmContainer, false); + assertNotNull(nodes); + assertEquals(1, nodes.size()); + assertTrue(nodes.contains(getNodeRef("series"))); + + nodes = filePlanService.getContainedRecordCategories(rmContainer, true); + assertNotNull(nodes); + assertEquals(2, nodes.size()); + assertTrue(nodes.contains(getNodeRef("series"))); + assertTrue(nodes.contains(getNodeRef("seriesChildContainer"))); + } + }); + + // Failure: call on record folder + doTestInTransaction(new FailureTest() + { + @Override + public void run() + { + filePlanService.getContainedRecordCategories(rmFolder); + } + }); + } + + /** + * @see FilePlanService#getContainedRecordFolders(NodeRef) + * @see FilePlanService#getContainedRecordFolders(NodeRef, boolean) + */ + public void testGetContainedRecordFolders() throws Exception + { + // Test getting all contained record folders + doTestInTransaction(new Test() + { + @Override + public Void run() + { + // Add to the test data + NodeRef series = filePlanService.createRecordCategory(rmContainer, "rmSeries"); + NodeRef seriesChildFolder = recordFolderService.createRecordFolder(series, "seriesRecordFolder"); + NodeRef seriesChildContainer = filePlanService.createRecordCategory(series, "childContainer"); + + // Put in model + setNodeRef("series", series); + setNodeRef("seriesChildFolder", seriesChildFolder); + setNodeRef("seriesChildContainer", seriesChildContainer); + + return null; + } + + @Override + public void test(Void result) throws Exception + { + List nodes = filePlanService.getContainedRecordFolders(rmContainer); + assertNotNull(nodes); + assertEquals(1, nodes.size()); + assertTrue(nodes.contains(rmFolder)); + + nodes = filePlanService.getContainedRecordFolders(rmContainer, false); + assertNotNull(nodes); + assertEquals(1, nodes.size()); + assertTrue(nodes.contains(rmFolder)); + + nodes = filePlanService.getContainedRecordFolders(rmContainer, true); + assertNotNull(nodes); + assertEquals(2, nodes.size()); + assertTrue(nodes.contains(rmFolder)); + assertTrue(nodes.contains(getNodeRef("seriesChildFolder"))); + } + }); + + // Failure: call on record folder + doTestInTransaction(new FailureTest() + { + @Override + public void run() + { + filePlanService.getContainedRecordFolders(rmFolder); + } + }); + } + + /********** Record Folder methods **********/ + + // TODO void testIsRecordFolderDeclared() + + // TODO void testIsRecordFolderClosed() + + // TODO void testGetRecords() + + /** + * @see RecordFolderService#createRecordFolder(NodeRef, String) + * @see RecordFolderService#createRecordFolder(NodeRef, String, QName) + */ + public void testCreateRecordFolder() throws Exception + { + // Create record + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + String id = setString("id", GUID.generate()); + return recordFolderService.createRecordFolder(rmContainer, id); + } + + @Override + public void test(NodeRef result) + { + assertNotNull("Unable to create record folder", result); + basicRMContainerCheck(result, getString("id"), TYPE_RECORD_FOLDER); + } + }); + + // TODO Create record of type + + // Failure: Create record with invalid type + doTestInTransaction(new FailureTest() + { + @Override + public void run() + { + recordFolderService.createRecordFolder(rmContainer, GUID.generate(), TYPE_FOLDER); + } + }); + + // Failure: Create record folder in root + doTestInTransaction(new FailureTest() + { + @Override + public void run() + { + recordFolderService.createRecordFolder(filePlan, GUID.generate()); + } + }); + } + + + /********** RM2 - Multi-hierarchy record taxonomy's **********/ + + /** + * Test to create a simple multi-hierarchy record taxonomy + */ + public void testCreateSimpleHierarchy() + { + doTestInTransaction(new Test() + { + @Override + public Void run() + { + // Create 3 level hierarchy + NodeRef levelOne = setNodeRef("container1", filePlanService.createRecordCategory(filePlan, "container1")); + assertNotNull("Unable to create container", levelOne); + NodeRef levelTwo = setNodeRef("container2", filePlanService.createRecordCategory(levelOne, "container2")); + assertNotNull("Unable to create container", levelTwo); + NodeRef levelThree = setNodeRef("container3", filePlanService.createRecordCategory(levelTwo, "container3")); + assertNotNull("Unable to create container", levelThree); + NodeRef levelThreeRecordFolder = setNodeRef("recordFolder3", recordFolderService.createRecordFolder(levelThree, "recordFolder3")); + assertNotNull("Unable to create record folder", levelThreeRecordFolder); + + return null; + } + + @Override + public void test(Void result) + { + // Test that the hierarchy has been created correctly + basicRMContainerCheck(getNodeRef("container1"), "container1", TYPE_RECORD_CATEGORY); + basicRMContainerCheck(getNodeRef("container2"), "container2", TYPE_RECORD_CATEGORY); + basicRMContainerCheck(getNodeRef("container3"), "container3", TYPE_RECORD_CATEGORY); + basicRMContainerCheck(getNodeRef("recordFolder3"), "recordFolder3", TYPE_RECORD_FOLDER); + + // TODO need to check that the parents and children can be retrieved correctly + } + }); + } + + /** + * A basic test of a records management container + * + * @param nodeRef node reference + * @param name name of the container + * @param type the type of container + */ + private void basicRMContainerCheck(NodeRef nodeRef, String name, QName type) + { + // Check the basic details + assertEquals(name, nodeService.getProperty(nodeRef, PROP_NAME)); + assertNotNull("RM id has not been set", nodeService.getProperty(nodeRef, PROP_IDENTIFIER)); + assertEquals(type, nodeService.getType(nodeRef)); + } + +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/webscript/AuditRestApiTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/webscript/AuditRestApiTest.java index 21cdfaa556..0781a3d0b0 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/webscript/AuditRestApiTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/webscript/AuditRestApiTest.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,80 +21,80 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.legacy.webscript; - -import static org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService.DEFAULT_RM_SITE_ID; - -import java.io.IOException; -import java.text.MessageFormat; - -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.util.GUID; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; - -public class AuditRestApiTest extends BaseRMWebScriptTestCase -{ - /** URL for the REST APIs */ - protected static final String GET_NODE_AUDITLOG_URL_FORMAT = "/api/node/{0}/rmauditlog"; - - private static final String USER_WITHOUT_AUDIT_CAPABILITY = GUID.generate(); - - private NodeRef record; - - public void testAuditAccessCapability() throws IOException - { - - String recordAuditUrl = MessageFormat.format(GET_NODE_AUDITLOG_URL_FORMAT,record.toString().replace("://", "/")); - - sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_OK, AuthenticationUtil.getAdminUserName() ); - - sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_FORBIDDEN, USER_WITHOUT_AUDIT_CAPABILITY ); - } - - @Override - protected void setupTestData() - { - super.setupTestData(); - - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil - .getSystemUserName()); - - createUser(USER_WITHOUT_AUDIT_CAPABILITY); - - record = utils.createRecord(recordFolder, GUID.generate()); - - - return null; - } - }); - } - - @Override - protected void tearDownImpl() - { - super.tearDownImpl(); - - deleteUser(USER_WITHOUT_AUDIT_CAPABILITY); - } - - protected String getRMSiteId() - { - return DEFAULT_RM_SITE_ID; - } - - -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.legacy.webscript; + +import static org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService.DEFAULT_RM_SITE_ID; + +import java.io.IOException; +import java.text.MessageFormat; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.util.GUID; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; + +public class AuditRestApiTest extends BaseRMWebScriptTestCase +{ + /** URL for the REST APIs */ + protected static final String GET_NODE_AUDITLOG_URL_FORMAT = "/api/node/{0}/rmauditlog"; + + private static final String USER_WITHOUT_AUDIT_CAPABILITY = GUID.generate(); + + private NodeRef record; + + public void testAuditAccessCapability() throws IOException + { + + String recordAuditUrl = MessageFormat.format(GET_NODE_AUDITLOG_URL_FORMAT,record.toString().replace("://", "/")); + + sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_OK, AuthenticationUtil.getAdminUserName() ); + + sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_FORBIDDEN, USER_WITHOUT_AUDIT_CAPABILITY ); + } + + @Override + protected void setupTestData() + { + super.setupTestData(); + + retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() + { + @Override + public Object execute() throws Throwable + { + + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil + .getSystemUserName()); + + createUser(USER_WITHOUT_AUDIT_CAPABILITY); + + record = utils.createRecord(recordFolder, GUID.generate()); + + + return null; + } + }); + } + + @Override + protected void tearDownImpl() + { + super.tearDownImpl(); + + deleteUser(USER_WITHOUT_AUDIT_CAPABILITY); + } + + protected String getRMSiteId() + { + return DEFAULT_RM_SITE_ID; + } + + +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/NotificationServiceHelperSystemTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/NotificationServiceHelperSystemTest.java index 8a39e41004..dee9edef6a 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/NotificationServiceHelperSystemTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/NotificationServiceHelperSystemTest.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,136 +21,136 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.system; - -import java.util.ArrayList; -import java.util.List; - -import org.alfresco.module.org_alfresco_module_rm.notification.RecordsManagementNotificationHelper; -import org.alfresco.module.org_alfresco_module_rm.role.Role; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.util.GUID; -import org.alfresco.util.PropertyMap; - -/** - * Notification helper (system) test - * - * @author Roy Wetherall - */ -public class NotificationServiceHelperSystemTest extends BaseRMTestCase -{ - private static final String NOTIFICATION_ROLE = "RecordsManager"; - private static final String EMAIL_ADDRESS = "roy.wetherall@alfreso.com"; - - /** Services */ - private RecordsManagementNotificationHelper notificationHelper; - - /** Test data */ - private NodeRef record; - private List records; - private String userName; - private NodeRef person; - - @Override - protected void initServices() - { - super.initServices(); - - // Get the notification helper - notificationHelper = (RecordsManagementNotificationHelper)applicationContext.getBean("recordsManagementNotificationHelper"); - } - - @Override - protected void setupTestData() - { - super.setupTestData(); - - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - @Override - public Object execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - - // Create a user - userName = GUID.generate(); - authenticationService.createAuthentication(userName, "".toCharArray()); - PropertyMap props = new PropertyMap(); - props.put(PROP_USERNAME, userName); - props.put(PROP_FIRSTNAME, "Test"); - props.put(PROP_LASTNAME, "User"); - props.put(PROP_EMAIL, EMAIL_ADDRESS); - person = personService.createPerson(props); - - // Find the authority for the given role - Role role = filePlanRoleService.getRole(filePlan, NOTIFICATION_ROLE); - assertNotNull("Notification role could not be retrieved", role); - String roleGroup = role.getRoleGroupName(); - assertNotNull("Notification role group can not be null.", roleGroup); - - // Add user to notification role group - authorityService.addAuthority(roleGroup, userName); - - return null; - } - }); - } - - @Override - protected void setupTestDataImpl() - { - super.setupTestDataImpl(); - - // Create a few test records - record = utils.createRecord(rmFolder, "recordOne"); - NodeRef record2 = utils.createRecord(rmFolder, "recordTwo"); - NodeRef record3 = utils.createRecord(rmFolder, "recordThree"); - - records = new ArrayList(3); - records.add(record); - records.add(record2); - records.add(record3); - } - - @Override - protected void tearDownImpl() - { - super.tearDownImpl(); - - // Delete the person and user - personService.deletePerson(person); - } - - public void testSendDueForReviewNotification() - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - notificationHelper.recordsDueForReviewEmailNotification(records); - return null; - } - }); - } - - public void testSendSupersededNotification() - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - notificationHelper.recordSupersededEmailNotification(record); - return null; - } - }); - } -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.system; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.module.org_alfresco_module_rm.notification.RecordsManagementNotificationHelper; +import org.alfresco.module.org_alfresco_module_rm.role.Role; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.util.GUID; +import org.alfresco.util.PropertyMap; + +/** + * Notification helper (system) test + * + * @author Roy Wetherall + */ +public class NotificationServiceHelperSystemTest extends BaseRMTestCase +{ + private static final String NOTIFICATION_ROLE = "RecordsManager"; + private static final String EMAIL_ADDRESS = "roy.wetherall@alfreso.com"; + + /** Services */ + private RecordsManagementNotificationHelper notificationHelper; + + /** Test data */ + private NodeRef record; + private List records; + private String userName; + private NodeRef person; + + @Override + protected void initServices() + { + super.initServices(); + + // Get the notification helper + notificationHelper = (RecordsManagementNotificationHelper)applicationContext.getBean("recordsManagementNotificationHelper"); + } + + @Override + protected void setupTestData() + { + super.setupTestData(); + + retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() + { + @Override + public Object execute() throws Throwable + { + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + + // Create a user + userName = GUID.generate(); + authenticationService.createAuthentication(userName, "".toCharArray()); + PropertyMap props = new PropertyMap(); + props.put(PROP_USERNAME, userName); + props.put(PROP_FIRSTNAME, "Test"); + props.put(PROP_LASTNAME, "User"); + props.put(PROP_EMAIL, EMAIL_ADDRESS); + person = personService.createPerson(props); + + // Find the authority for the given role + Role role = filePlanRoleService.getRole(filePlan, NOTIFICATION_ROLE); + assertNotNull("Notification role could not be retrieved", role); + String roleGroup = role.getRoleGroupName(); + assertNotNull("Notification role group can not be null.", roleGroup); + + // Add user to notification role group + authorityService.addAuthority(roleGroup, userName); + + return null; + } + }); + } + + @Override + protected void setupTestDataImpl() + { + super.setupTestDataImpl(); + + // Create a few test records + record = utils.createRecord(rmFolder, "recordOne"); + NodeRef record2 = utils.createRecord(rmFolder, "recordTwo"); + NodeRef record3 = utils.createRecord(rmFolder, "recordThree"); + + records = new ArrayList(3); + records.add(record); + records.add(record2); + records.add(record3); + } + + @Override + protected void tearDownImpl() + { + super.tearDownImpl(); + + // Delete the person and user + personService.deletePerson(person); + } + + public void testSendDueForReviewNotification() + { + doTestInTransaction(new Test() + { + @Override + public Void run() + { + notificationHelper.recordsDueForReviewEmailNotification(records); + return null; + } + }); + } + + public void testSendSupersededNotification() + { + doTestInTransaction(new Test() + { + @Override + public Void run() + { + notificationHelper.recordSupersededEmailNotification(record); + return null; + } + }); + } +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/GenerateCapabilityReport.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/GenerateCapabilityReport.java index d90347154c..38ffacaaef 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/GenerateCapabilityReport.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/GenerateCapabilityReport.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,63 +21,63 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.util; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.util.Set; - -import org.alfresco.module.org_alfresco_module_rm.capability.Capability; -import org.alfresco.module.org_alfresco_module_rm.capability.Group; - -/** - * Utility test case to generate a report of the capabilities in the system. - * - * @author Roy Wetherall - * @since 2.1 - */ -public class GenerateCapabilityReport extends BaseRMTestCase -{ - public void testGetCapability() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public Void run() throws Exception - { - FileWriter writer = new FileWriter("c:\\mywork\\capabilityReport.csv"); - BufferedWriter out = new BufferedWriter(writer); - try - { - Set capabilities = capabilityService.getCapabilities(true); - for (Capability capability : capabilities) - { - Group group = capability.getGroup(); - String groupId = "none"; - if (group != null) - { - groupId = group.getId(); - } - - out.write(groupId); - out.write(","); - out.write(capability.getName()); - out.write(","); - out.write(Boolean.toString(capability.isPrivate())); - out.write("\n"); - } - } - finally - { - out.close(); - } - - return null; - } - }); - } -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.util; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.util.Set; + +import org.alfresco.module.org_alfresco_module_rm.capability.Capability; +import org.alfresco.module.org_alfresco_module_rm.capability.Group; + +/** + * Utility test case to generate a report of the capabilities in the system. + * + * @author Roy Wetherall + * @since 2.1 + */ +public class GenerateCapabilityReport extends BaseRMTestCase +{ + public void testGetCapability() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public Void run() throws Exception + { + FileWriter writer = new FileWriter("c:\\mywork\\capabilityReport.csv"); + BufferedWriter out = new BufferedWriter(writer); + try + { + Set capabilities = capabilityService.getCapabilities(true); + for (Capability capability : capabilities) + { + Group group = capability.getGroup(); + String groupId = "none"; + if (group != null) + { + groupId = group.getId(); + } + + out.write(groupId); + out.write(","); + out.write(capability.getName()); + out.write(","); + out.write(Boolean.toString(capability.isPrivate())); + out.write("\n"); + } + } + finally + { + out.close(); + } + + return null; + } + }); + } +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestWebScriptRepoServer.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestWebScriptRepoServer.java index 494194febc..2723047345 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestWebScriptRepoServer.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestWebScriptRepoServer.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,209 +21,209 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.test.util; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.alfresco.repo.security.authentication.AuthenticationException; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.cmr.security.AuthenticationService; -import org.alfresco.util.EqualsHelper; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.extensions.webscripts.TestWebScriptServer; - -/** - * Stand-alone Web Script Test Server - * - * @author davidc - */ -public class TestWebScriptRepoServer extends TestWebScriptServer -{ - /** - * Main entry point. - */ - public static void main(String[] args) - { - try - { - TestWebScriptServer testServer = getTestServer(); - AuthenticationUtil.setRunAsUserSystem(); - testServer.rep(); - } - catch(Throwable e) - { - StringWriter strWriter = new StringWriter(); - PrintWriter printWriter = new PrintWriter(strWriter); - e.printStackTrace(printWriter); - System.out.println(strWriter.toString()); - } - finally - { - System.exit(0); - } - } - - private final static String[] CONFIG_LOCATIONS = new String[] - { - "classpath:alfresco/application-context.xml", - "classpath:alfresco/web-scripts-application-context.xml", - "classpath:alfresco/web-scripts-application-context-test.xml" - }; - - /** A static reference to the application context being used */ - private static ClassPathXmlApplicationContext ctx; - private static String appendedTestConfiguration; - - private RetryingTransactionHelper retryingTransactionHelper; - private AuthenticationService authenticationService; - - - /** - * Sets helper that provides transaction callbacks - */ - public void setTransactionHelper(RetryingTransactionHelper retryingTransactionHelper) - { - this.retryingTransactionHelper = retryingTransactionHelper; - } - - /** - * @param authenticationService - */ - public void setAuthenticationService(AuthenticationService authenticationService) - { - this.authenticationService = authenticationService; - } - - /** - * Get default user name - */ - protected String getDefaultUserName() - { - return AuthenticationUtil.getAdminUserName(); - } - - /** - * {@inheritDoc #getTestServer(String)} - */ - public static TestWebScriptServer getTestServer() - { - return getTestServer(null); - } - - /** - * Start up a context and get the server bean. - *

- * This method will close and restart the application context only if the configuration has - * changed. - * - * @param appendTestConfigLocation additional context file to include in the application context - * @return Test Server - */ - public static synchronized TestWebScriptServer getTestServer(String appendTestConfigLocation) - { - if (TestWebScriptRepoServer.ctx != null) - { - boolean configChanged = !EqualsHelper.nullSafeEquals( - appendTestConfigLocation, - TestWebScriptRepoServer.appendedTestConfiguration); - if (configChanged) - { - // The config changed, so close the context (it'll be restarted later) - try - { - ctx.close(); - ctx = null; - } - catch (Throwable e) - { - throw new RuntimeException("Failed to shut down existing application context", e); - } - } - else - { - // There is already a context with the required configuration - } - } - - // Check if we need to start/restart the context - if (TestWebScriptRepoServer.ctx == null) - { - // Restart it - final String[] configLocations; - if (appendTestConfigLocation == null) - { - configLocations = CONFIG_LOCATIONS; - } - else - { - configLocations = new String[CONFIG_LOCATIONS.length+1]; - System.arraycopy(CONFIG_LOCATIONS, 0, configLocations, 0, CONFIG_LOCATIONS.length); - configLocations[CONFIG_LOCATIONS.length] = appendTestConfigLocation; - } - TestWebScriptRepoServer.ctx = new ClassPathXmlApplicationContext(configLocations); - TestWebScriptRepoServer.appendedTestConfiguration = appendTestConfigLocation; - } - - // Get the bean - TestWebScriptServer testServer = (org.alfresco.repo.web.scripts.TestWebScriptRepoServer)TestWebScriptRepoServer.ctx.getBean("webscripts.test"); - return testServer; - } - - /** - * Interpret a single command using the BufferedReader passed in for any data needed. - * - * @param line The unparsed command - * @return The textual output of the command. - */ - @Override - protected String interpretCommand(final String line) - throws IOException - { - try - { - if (username.startsWith("TICKET_")) - { - try - { - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - public Object execute() throws Exception - { - authenticationService.validate(username); - return null; - } - }); - return executeCommand(line); - } - finally - { - authenticationService.clearCurrentSecurityContext(); - } - } - } - catch(AuthenticationException e) - { - executeCommand("user " + getDefaultUserName()); - } - - // execute command in context of currently selected user - return AuthenticationUtil.runAs(new RunAsWork() - { - @SuppressWarnings("synthetic-access") - public String doWork() throws Exception - { - return executeCommand(line); - } - }, username); - } - -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.util; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.alfresco.repo.security.authentication.AuthenticationException; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.repo.transaction.RetryingTransactionHelper; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.cmr.security.AuthenticationService; +import org.alfresco.util.EqualsHelper; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.extensions.webscripts.TestWebScriptServer; + +/** + * Stand-alone Web Script Test Server + * + * @author davidc + */ +public class TestWebScriptRepoServer extends TestWebScriptServer +{ + /** + * Main entry point. + */ + public static void main(String[] args) + { + try + { + TestWebScriptServer testServer = getTestServer(); + AuthenticationUtil.setRunAsUserSystem(); + testServer.rep(); + } + catch(Throwable e) + { + StringWriter strWriter = new StringWriter(); + PrintWriter printWriter = new PrintWriter(strWriter); + e.printStackTrace(printWriter); + System.out.println(strWriter.toString()); + } + finally + { + System.exit(0); + } + } + + private final static String[] CONFIG_LOCATIONS = new String[] + { + "classpath:alfresco/application-context.xml", + "classpath:alfresco/web-scripts-application-context.xml", + "classpath:alfresco/web-scripts-application-context-test.xml" + }; + + /** A static reference to the application context being used */ + private static ClassPathXmlApplicationContext ctx; + private static String appendedTestConfiguration; + + private RetryingTransactionHelper retryingTransactionHelper; + private AuthenticationService authenticationService; + + + /** + * Sets helper that provides transaction callbacks + */ + public void setTransactionHelper(RetryingTransactionHelper retryingTransactionHelper) + { + this.retryingTransactionHelper = retryingTransactionHelper; + } + + /** + * @param authenticationService + */ + public void setAuthenticationService(AuthenticationService authenticationService) + { + this.authenticationService = authenticationService; + } + + /** + * Get default user name + */ + protected String getDefaultUserName() + { + return AuthenticationUtil.getAdminUserName(); + } + + /** + * {@inheritDoc #getTestServer(String)} + */ + public static TestWebScriptServer getTestServer() + { + return getTestServer(null); + } + + /** + * Start up a context and get the server bean. + *

+ * This method will close and restart the application context only if the configuration has + * changed. + * + * @param appendTestConfigLocation additional context file to include in the application context + * @return Test Server + */ + public static synchronized TestWebScriptServer getTestServer(String appendTestConfigLocation) + { + if (TestWebScriptRepoServer.ctx != null) + { + boolean configChanged = !EqualsHelper.nullSafeEquals( + appendTestConfigLocation, + TestWebScriptRepoServer.appendedTestConfiguration); + if (configChanged) + { + // The config changed, so close the context (it'll be restarted later) + try + { + ctx.close(); + ctx = null; + } + catch (Throwable e) + { + throw new RuntimeException("Failed to shut down existing application context", e); + } + } + else + { + // There is already a context with the required configuration + } + } + + // Check if we need to start/restart the context + if (TestWebScriptRepoServer.ctx == null) + { + // Restart it + final String[] configLocations; + if (appendTestConfigLocation == null) + { + configLocations = CONFIG_LOCATIONS; + } + else + { + configLocations = new String[CONFIG_LOCATIONS.length+1]; + System.arraycopy(CONFIG_LOCATIONS, 0, configLocations, 0, CONFIG_LOCATIONS.length); + configLocations[CONFIG_LOCATIONS.length] = appendTestConfigLocation; + } + TestWebScriptRepoServer.ctx = new ClassPathXmlApplicationContext(configLocations); + TestWebScriptRepoServer.appendedTestConfiguration = appendTestConfigLocation; + } + + // Get the bean + TestWebScriptServer testServer = (org.alfresco.repo.web.scripts.TestWebScriptRepoServer)TestWebScriptRepoServer.ctx.getBean("webscripts.test"); + return testServer; + } + + /** + * Interpret a single command using the BufferedReader passed in for any data needed. + * + * @param line The unparsed command + * @return The textual output of the command. + */ + @Override + protected String interpretCommand(final String line) + throws IOException + { + try + { + if (username.startsWith("TICKET_")) + { + try + { + retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() + { + public Object execute() throws Exception + { + authenticationService.validate(username); + return null; + } + }); + return executeCommand(line); + } + finally + { + authenticationService.clearCurrentSecurityContext(); + } + } + } + catch(AuthenticationException e) + { + executeCommand("user " + getDefaultUserName()); + } + + // execute command in context of currently selected user + return AuthenticationUtil.runAs(new RunAsWork() + { + @SuppressWarnings("synthetic-access") + public String doWork() throws Exception + { + return executeCommand(line); + } + }, username); + } + +} diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldServiceImplUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldServiceImplUnitTest.java index 2477400fed..ff1956a82b 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldServiceImplUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldServiceImplUnitTest.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,448 +21,448 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.hold; - -import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateQName; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.namespace.RegexQNamePattern; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Spy; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -/** - * Hold service implementation unit test - * - * @author Roy Wetherall - * @since 2.2 - */ -public class HoldServiceImplUnitTest extends BaseUnitTest -{ - /** test values */ - private static final String HOLD_NAME = "holdname"; - private static final String HOLD_REASON = "holdreason"; - private static final String HOLD_DESCRIPTION = "holddescription"; - - protected NodeRef holdContainer; - protected NodeRef hold; - protected NodeRef hold2; - - @Spy @InjectMocks HoldServiceImpl holdService; - - @Before - @Override - public void before() throws Exception - { - super.before(); - - // setup objects used in mock interactions - holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER); - hold = generateNodeRef(TYPE_HOLD); - hold2 = generateNodeRef(TYPE_HOLD); - - // setup interactions - doReturn(holdContainer).when(mockedFilePlanService).getHoldContainer(filePlan); - } - - @Test - public void isHold() - { - assertTrue(holdService.isHold(hold)); - assertFalse(holdService.isHold(recordFolder)); - } - - @Test - public void heldByMultipleResults() - { - // setup record folder in multiple holds - List holds = new ArrayList(2); - holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold, ASSOC_FROZEN_RECORDS, recordFolder, true, 1)); - holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold2, ASSOC_FROZEN_RECORDS, recordFolder, true, 2)); - doReturn(holds).when(mockedNodeService).getParentAssocs(recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); - - // check that both holds are found for record folder - List heldByHolds = holdService.heldBy(recordFolder, true); - assertNotNull(heldByHolds); - assertEquals(2, heldByHolds.size()); - assertTrue(holdService.heldBy(recordFolder, false).isEmpty()); - - // check that both holds are found for record (even thou they are one level deep) - heldByHolds = holdService.heldBy(record, true); - assertNotNull(heldByHolds); - assertEquals(2, heldByHolds.size()); - assertTrue(holdService.heldBy(record, false).isEmpty()); - } - - @Test (expected=AlfrescoRuntimeException.class) - public void getHold() - { - // setup node service interactions - when(mockedNodeService.getChildByName(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), anyString())).thenReturn(null) - .thenReturn(hold) - .thenReturn(recordFolder); - - // no hold - NodeRef noHold = holdService.getHold(filePlan, "notAHold"); - assertNull(noHold); - - // found hold - NodeRef someHold = holdService.getHold(filePlan, "someHold"); - assertNotNull(someHold); - assertEquals(TYPE_HOLD, mockedNodeService.getType(someHold)); - - // ensure runtime exception is thrown - holdService.getHold(filePlan, "notHold"); - } - - @Test (expected=RuntimeException.class) - public void getHeldNotAHold() - { - holdService.getHeld(recordFolder); - } - - @Test - public void getHeldNoResults() - { - assertTrue(holdService.getHeld(hold).isEmpty()); - } - - @Test - public void getHeldWithResults() - { - // setup record folder in hold - List holds = new ArrayList(1); - holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold, ASSOC_FROZEN_RECORDS, recordFolder, true, 1)); - doReturn(holds).when(mockedNodeService).getChildAssocs(hold, ASSOC_FROZEN_RECORDS, RegexQNamePattern.MATCH_ALL); - - List list = holdService.getHeld(hold); - assertEquals(1, list.size()); - assertEquals(recordFolder, list.get(0)); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Test - public void createHold() - { - // setup node service interactions - when(mockedNodeService.createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), any(QName.class) , eq(TYPE_HOLD), any(Map.class))) - .thenReturn(new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, holdContainer, generateQName(), hold)); - - // create hold - NodeRef newHold = holdService.createHold(filePlan, HOLD_NAME, HOLD_REASON, HOLD_DESCRIPTION); - assertNotNull(newHold); - assertEquals(TYPE_HOLD, mockedNodeService.getType(newHold)); - assertEquals(hold, newHold); - - // check the node service interactions - ArgumentCaptor propertyMapCaptor = ArgumentCaptor.forClass(Map.class); - ArgumentCaptor assocNameCaptor = ArgumentCaptor.forClass(QName.class); - verify(mockedNodeService).createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), assocNameCaptor.capture() , eq(TYPE_HOLD), propertyMapCaptor.capture()); - - // check property map - Map propertyMap = (Map)propertyMapCaptor.getValue(); - assertNotNull(propertyMap); - assertEquals(3, propertyMap.size()); - assertTrue(propertyMap.containsKey(ContentModel.PROP_NAME)); - assertEquals(HOLD_NAME, propertyMap.get(ContentModel.PROP_NAME)); - assertTrue(propertyMap.containsKey(ContentModel.PROP_DESCRIPTION)); - assertEquals(HOLD_DESCRIPTION, propertyMap.get(ContentModel.PROP_DESCRIPTION)); - assertTrue(propertyMap.containsKey(PROP_HOLD_REASON)); - assertEquals(HOLD_REASON, propertyMap.get(PROP_HOLD_REASON)); - - // check assoc name - assertNotNull(assocNameCaptor.getValue()); - assertEquals(NamespaceService.CONTENT_MODEL_1_0_URI, assocNameCaptor.getValue().getNamespaceURI()); - assertEquals(HOLD_NAME, assocNameCaptor.getValue().getLocalName()); - } - - @Test - public void getHoldReason() - { - // setup node service interactions - when(mockedNodeService.exists(hold)) - .thenReturn(false) - .thenReturn(true) - .thenReturn(true) - .thenReturn(true); - when(mockedNodeService.getProperty(eq(hold), eq(PROP_HOLD_REASON))) - .thenReturn(null) - .thenReturn(HOLD_REASON); - - // node does not exist - assertNull(holdService.getHoldReason(hold)); - - // node isn't a hold - assertNull(holdService.getHoldReason(recordFolder)); - - // hold reason isn't set - assertNull(holdService.getHoldReason(hold)); - - // hold reason set - assertEquals(HOLD_REASON, holdService.getHoldReason(hold)); - } - - @Test - public void setHoldReason() - { - // setup node service interactions - when(mockedNodeService.exists(hold)) - .thenReturn(false) - .thenReturn(true) - .thenReturn(true); - - // node does not exist - holdService.setHoldReason(hold, HOLD_REASON); - verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON); - - // node isn't a hold - holdService.setHoldReason(recordFolder, HOLD_REASON); - verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON); - - // set hold reason - holdService.setHoldReason(hold, HOLD_REASON); - verify(mockedNodeService).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON); - } - - @Test (expected=AlfrescoRuntimeException.class) - public void deleteHoldNotAHold() - { - holdService.deleteHold(recordFolder); - verify(mockedNodeService, never()).deleteNode(hold); - } - - @Test - public void deleteHold() - { - // delete hold - holdService.deleteHold(hold); - verify(mockedNodeService).deleteNode(hold); - - // TODO check interactions with policy component!!! - } - - @Test (expected=AlfrescoRuntimeException.class) - public void addToHoldNotAHold() - { - holdService.addToHold(recordFolder, recordFolder); - } - - @Test (expected=AlfrescoRuntimeException.class) - public void addToHoldNotARecordFolderOrRecord() - { - NodeRef anotherThing = generateNodeRef(TYPE_RECORD_CATEGORY); - holdService.addToHold(hold, anotherThing); - } - - @SuppressWarnings("unchecked") - @Test - public void addToHoldNotInHold() - { - holdService.addToHold(hold, recordFolder); - - verify(mockedNodeService).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); - verify(mockedNodeService).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedNodeService).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString()); - - holdService.addToHold(hold, record); - verify(mockedNodeService).addChild(hold, record, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); - verify(mockedNodeService).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedNodeService, times(2)).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(record), anyString()); - } - - @SuppressWarnings("unchecked") - @Test - public void addToHoldAlreadyInHold() - { - doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); - - holdService.addToHold(hold, recordFolder); - - verify(mockedNodeService, never()).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); - verify(mockedNodeService, never()).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedNodeService, never()).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString()); - } - - @SuppressWarnings("unchecked") - @Test - public void addToHoldAldeadyFrozen() - { - doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); - doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); - - holdService.addToHold(hold, recordFolder); - - verify(mockedNodeService, times(1)).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); - verify(mockedNodeService, never()).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedNodeService, never()).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString()); - } - - @SuppressWarnings("unchecked") - @Test - public void addToHolds() - { - // ensure the interaction indicates that a node has the frozen aspect applied if it has - doAnswer(new Answer() - { - public Void answer(InvocationOnMock invocation) - { - NodeRef nodeRef = (NodeRef)invocation.getArguments()[0]; - doReturn(true).when(mockedNodeService).hasAspect(nodeRef, ASPECT_FROZEN); - return null; - } - - }).when(mockedNodeService).addAspect(any(NodeRef.class), eq(ASPECT_FROZEN), any(Map.class)); - - // build a list of holds - List holds = new ArrayList(2); - holds.add(hold); - holds.add(hold2); - - // add the record folder to both holds - holdService.addToHolds(holds, recordFolder); - - // verify the interactions - verify(mockedNodeService, times(1)).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); - verify(mockedNodeService, times(1)).addChild(hold2, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); - verify(mockedNodeService, times(1)).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedNodeService, times(1)).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); - verify(mockedRecordsManagementAuditService, times(2)).auditEvent(eq(recordFolder), anyString()); - } - - @Test (expected=AlfrescoRuntimeException.class) - public void removeFromHoldNotAHold() - { - holdService.removeFromHold(recordFolder, recordFolder); - } - - @Test - public void removeFromHoldNotInHold() - { - holdService.removeFromHold(hold, recordFolder); - - verify(mockedNodeService, never()).removeChild(hold, recordFolder); - verify(mockedNodeService, never()).removeAspect(recordFolder, ASPECT_FROZEN); - verify(mockedNodeService, never()).removeAspect(record, ASPECT_FROZEN); - verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString()); - } - - @Test - public void removeFromHold() - { - doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); - doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); - doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); - - holdService.removeFromHold(hold, recordFolder); - - verify(mockedNodeService, times(1)).removeChild(hold, recordFolder); - verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN); - verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN); - verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString()); - } - - @Test - public void removeFromHolds() - { - doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); - doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2); - doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); - doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); - - // build a list of holds - List holds = new ArrayList(2); - holds.add(hold); - holds.add(hold2); - - holdService.removeFromHolds(holds, recordFolder); - - verify(mockedNodeService, times(1)).removeChild(hold, recordFolder); - verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder); - verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN); - verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN); - verify(mockedRecordsManagementAuditService, times(2)).auditEvent(any(NodeRef.class), anyString()); - } - - @Test - public void removeFromAllHolds() - { - // build a list of holds - List holds = new ArrayList(2); - holds.add(hold); - holds.add(hold2); - - doAnswer(new Answer() - { - public Void answer(InvocationOnMock invocation) - { - doReturn(Collections.singletonList(hold2)).when(holdService).heldBy(recordFolder, true); - return null; - } - - }).when(mockedNodeService).removeChild(hold, recordFolder); - - doAnswer(new Answer() - { - public Void answer(InvocationOnMock invocation) - { - doReturn(new ArrayList()).when(holdService).heldBy(recordFolder, true); - return null; - } - - }).when(mockedNodeService).removeChild(hold2, recordFolder); - - // define interactions - doReturn(holds).when(holdService).heldBy(recordFolder, true); - doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); - doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2); - doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); - doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); - - // remove record folder from all holds - holdService.removeFromAllHolds(recordFolder); - - // verify interactions - verify(mockedNodeService, times(1)).removeChild(hold, recordFolder); - verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder); - verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN); - verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN); - } -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.hold; + +import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateQName; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.namespace.RegexQNamePattern; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +/** + * Hold service implementation unit test + * + * @author Roy Wetherall + * @since 2.2 + */ +public class HoldServiceImplUnitTest extends BaseUnitTest +{ + /** test values */ + private static final String HOLD_NAME = "holdname"; + private static final String HOLD_REASON = "holdreason"; + private static final String HOLD_DESCRIPTION = "holddescription"; + + protected NodeRef holdContainer; + protected NodeRef hold; + protected NodeRef hold2; + + @Spy @InjectMocks HoldServiceImpl holdService; + + @Before + @Override + public void before() throws Exception + { + super.before(); + + // setup objects used in mock interactions + holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER); + hold = generateNodeRef(TYPE_HOLD); + hold2 = generateNodeRef(TYPE_HOLD); + + // setup interactions + doReturn(holdContainer).when(mockedFilePlanService).getHoldContainer(filePlan); + } + + @Test + public void isHold() + { + assertTrue(holdService.isHold(hold)); + assertFalse(holdService.isHold(recordFolder)); + } + + @Test + public void heldByMultipleResults() + { + // setup record folder in multiple holds + List holds = new ArrayList(2); + holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold, ASSOC_FROZEN_RECORDS, recordFolder, true, 1)); + holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold2, ASSOC_FROZEN_RECORDS, recordFolder, true, 2)); + doReturn(holds).when(mockedNodeService).getParentAssocs(recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); + + // check that both holds are found for record folder + List heldByHolds = holdService.heldBy(recordFolder, true); + assertNotNull(heldByHolds); + assertEquals(2, heldByHolds.size()); + assertTrue(holdService.heldBy(recordFolder, false).isEmpty()); + + // check that both holds are found for record (even thou they are one level deep) + heldByHolds = holdService.heldBy(record, true); + assertNotNull(heldByHolds); + assertEquals(2, heldByHolds.size()); + assertTrue(holdService.heldBy(record, false).isEmpty()); + } + + @Test (expected=AlfrescoRuntimeException.class) + public void getHold() + { + // setup node service interactions + when(mockedNodeService.getChildByName(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), anyString())).thenReturn(null) + .thenReturn(hold) + .thenReturn(recordFolder); + + // no hold + NodeRef noHold = holdService.getHold(filePlan, "notAHold"); + assertNull(noHold); + + // found hold + NodeRef someHold = holdService.getHold(filePlan, "someHold"); + assertNotNull(someHold); + assertEquals(TYPE_HOLD, mockedNodeService.getType(someHold)); + + // ensure runtime exception is thrown + holdService.getHold(filePlan, "notHold"); + } + + @Test (expected=RuntimeException.class) + public void getHeldNotAHold() + { + holdService.getHeld(recordFolder); + } + + @Test + public void getHeldNoResults() + { + assertTrue(holdService.getHeld(hold).isEmpty()); + } + + @Test + public void getHeldWithResults() + { + // setup record folder in hold + List holds = new ArrayList(1); + holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold, ASSOC_FROZEN_RECORDS, recordFolder, true, 1)); + doReturn(holds).when(mockedNodeService).getChildAssocs(hold, ASSOC_FROZEN_RECORDS, RegexQNamePattern.MATCH_ALL); + + List list = holdService.getHeld(hold); + assertEquals(1, list.size()); + assertEquals(recordFolder, list.get(0)); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + public void createHold() + { + // setup node service interactions + when(mockedNodeService.createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), any(QName.class) , eq(TYPE_HOLD), any(Map.class))) + .thenReturn(new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, holdContainer, generateQName(), hold)); + + // create hold + NodeRef newHold = holdService.createHold(filePlan, HOLD_NAME, HOLD_REASON, HOLD_DESCRIPTION); + assertNotNull(newHold); + assertEquals(TYPE_HOLD, mockedNodeService.getType(newHold)); + assertEquals(hold, newHold); + + // check the node service interactions + ArgumentCaptor propertyMapCaptor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor assocNameCaptor = ArgumentCaptor.forClass(QName.class); + verify(mockedNodeService).createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), assocNameCaptor.capture() , eq(TYPE_HOLD), propertyMapCaptor.capture()); + + // check property map + Map propertyMap = (Map)propertyMapCaptor.getValue(); + assertNotNull(propertyMap); + assertEquals(3, propertyMap.size()); + assertTrue(propertyMap.containsKey(ContentModel.PROP_NAME)); + assertEquals(HOLD_NAME, propertyMap.get(ContentModel.PROP_NAME)); + assertTrue(propertyMap.containsKey(ContentModel.PROP_DESCRIPTION)); + assertEquals(HOLD_DESCRIPTION, propertyMap.get(ContentModel.PROP_DESCRIPTION)); + assertTrue(propertyMap.containsKey(PROP_HOLD_REASON)); + assertEquals(HOLD_REASON, propertyMap.get(PROP_HOLD_REASON)); + + // check assoc name + assertNotNull(assocNameCaptor.getValue()); + assertEquals(NamespaceService.CONTENT_MODEL_1_0_URI, assocNameCaptor.getValue().getNamespaceURI()); + assertEquals(HOLD_NAME, assocNameCaptor.getValue().getLocalName()); + } + + @Test + public void getHoldReason() + { + // setup node service interactions + when(mockedNodeService.exists(hold)) + .thenReturn(false) + .thenReturn(true) + .thenReturn(true) + .thenReturn(true); + when(mockedNodeService.getProperty(eq(hold), eq(PROP_HOLD_REASON))) + .thenReturn(null) + .thenReturn(HOLD_REASON); + + // node does not exist + assertNull(holdService.getHoldReason(hold)); + + // node isn't a hold + assertNull(holdService.getHoldReason(recordFolder)); + + // hold reason isn't set + assertNull(holdService.getHoldReason(hold)); + + // hold reason set + assertEquals(HOLD_REASON, holdService.getHoldReason(hold)); + } + + @Test + public void setHoldReason() + { + // setup node service interactions + when(mockedNodeService.exists(hold)) + .thenReturn(false) + .thenReturn(true) + .thenReturn(true); + + // node does not exist + holdService.setHoldReason(hold, HOLD_REASON); + verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON); + + // node isn't a hold + holdService.setHoldReason(recordFolder, HOLD_REASON); + verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON); + + // set hold reason + holdService.setHoldReason(hold, HOLD_REASON); + verify(mockedNodeService).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON); + } + + @Test (expected=AlfrescoRuntimeException.class) + public void deleteHoldNotAHold() + { + holdService.deleteHold(recordFolder); + verify(mockedNodeService, never()).deleteNode(hold); + } + + @Test + public void deleteHold() + { + // delete hold + holdService.deleteHold(hold); + verify(mockedNodeService).deleteNode(hold); + + // TODO check interactions with policy component!!! + } + + @Test (expected=AlfrescoRuntimeException.class) + public void addToHoldNotAHold() + { + holdService.addToHold(recordFolder, recordFolder); + } + + @Test (expected=AlfrescoRuntimeException.class) + public void addToHoldNotARecordFolderOrRecord() + { + NodeRef anotherThing = generateNodeRef(TYPE_RECORD_CATEGORY); + holdService.addToHold(hold, anotherThing); + } + + @SuppressWarnings("unchecked") + @Test + public void addToHoldNotInHold() + { + holdService.addToHold(hold, recordFolder); + + verify(mockedNodeService).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); + verify(mockedNodeService).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedNodeService).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString()); + + holdService.addToHold(hold, record); + verify(mockedNodeService).addChild(hold, record, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); + verify(mockedNodeService).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedNodeService, times(2)).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(record), anyString()); + } + + @SuppressWarnings("unchecked") + @Test + public void addToHoldAlreadyInHold() + { + doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); + + holdService.addToHold(hold, recordFolder); + + verify(mockedNodeService, never()).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); + verify(mockedNodeService, never()).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedNodeService, never()).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString()); + } + + @SuppressWarnings("unchecked") + @Test + public void addToHoldAldeadyFrozen() + { + doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); + doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); + + holdService.addToHold(hold, recordFolder); + + verify(mockedNodeService, times(1)).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); + verify(mockedNodeService, never()).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedNodeService, never()).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString()); + } + + @SuppressWarnings("unchecked") + @Test + public void addToHolds() + { + // ensure the interaction indicates that a node has the frozen aspect applied if it has + doAnswer(new Answer() + { + public Void answer(InvocationOnMock invocation) + { + NodeRef nodeRef = (NodeRef)invocation.getArguments()[0]; + doReturn(true).when(mockedNodeService).hasAspect(nodeRef, ASPECT_FROZEN); + return null; + } + + }).when(mockedNodeService).addAspect(any(NodeRef.class), eq(ASPECT_FROZEN), any(Map.class)); + + // build a list of holds + List holds = new ArrayList(2); + holds.add(hold); + holds.add(hold2); + + // add the record folder to both holds + holdService.addToHolds(holds, recordFolder); + + // verify the interactions + verify(mockedNodeService, times(1)).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); + verify(mockedNodeService, times(1)).addChild(hold2, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); + verify(mockedNodeService, times(1)).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedNodeService, times(1)).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); + verify(mockedRecordsManagementAuditService, times(2)).auditEvent(eq(recordFolder), anyString()); + } + + @Test (expected=AlfrescoRuntimeException.class) + public void removeFromHoldNotAHold() + { + holdService.removeFromHold(recordFolder, recordFolder); + } + + @Test + public void removeFromHoldNotInHold() + { + holdService.removeFromHold(hold, recordFolder); + + verify(mockedNodeService, never()).removeChild(hold, recordFolder); + verify(mockedNodeService, never()).removeAspect(recordFolder, ASPECT_FROZEN); + verify(mockedNodeService, never()).removeAspect(record, ASPECT_FROZEN); + verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString()); + } + + @Test + public void removeFromHold() + { + doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); + doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); + doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); + + holdService.removeFromHold(hold, recordFolder); + + verify(mockedNodeService, times(1)).removeChild(hold, recordFolder); + verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN); + verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN); + verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString()); + } + + @Test + public void removeFromHolds() + { + doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); + doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2); + doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); + doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); + + // build a list of holds + List holds = new ArrayList(2); + holds.add(hold); + holds.add(hold2); + + holdService.removeFromHolds(holds, recordFolder); + + verify(mockedNodeService, times(1)).removeChild(hold, recordFolder); + verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder); + verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN); + verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN); + verify(mockedRecordsManagementAuditService, times(2)).auditEvent(any(NodeRef.class), anyString()); + } + + @Test + public void removeFromAllHolds() + { + // build a list of holds + List holds = new ArrayList(2); + holds.add(hold); + holds.add(hold2); + + doAnswer(new Answer() + { + public Void answer(InvocationOnMock invocation) + { + doReturn(Collections.singletonList(hold2)).when(holdService).heldBy(recordFolder, true); + return null; + } + + }).when(mockedNodeService).removeChild(hold, recordFolder); + + doAnswer(new Answer() + { + public Void answer(InvocationOnMock invocation) + { + doReturn(new ArrayList()).when(holdService).heldBy(recordFolder, true); + return null; + } + + }).when(mockedNodeService).removeChild(hold2, recordFolder); + + // define interactions + doReturn(holds).when(holdService).heldBy(recordFolder, true); + doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); + doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2); + doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); + doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); + + // remove record folder from all holds + holdService.removeFromAllHolds(recordFolder); + + // verify interactions + verify(mockedNodeService, times(1)).removeChild(hold, recordFolder); + verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder); + verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN); + verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN); + } +} diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/compatibility/DictionaryBootstrapPostProcessorUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/compatibility/DictionaryBootstrapPostProcessorUnitTest.java index e727bc0c3e..a072004f1d 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/compatibility/DictionaryBootstrapPostProcessorUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/compatibility/DictionaryBootstrapPostProcessorUnitTest.java @@ -1,9 +1,9 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% * This file is part of the Alfresco software. * * If the software was purchased under a paid Alfresco license, the terms of @@ -21,84 +21,84 @@ * 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 . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.model.compatibility; - -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; - -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; - -/** - * Dictionary bootstrap post processor unit test. - * - * @author Roy Wetherall - * @since 2.2 - */ -public class DictionaryBootstrapPostProcessorUnitTest extends BaseUnitTest -{ - /** bean id's */ - private static final String BEAN_SITESERVICE_BOOTSTRAP = "siteService_dictionaryBootstrap"; - private static final String BEAN_RM_DICTIONARY_BOOTSTRAP = "org_alfresco_module_rm_dictionaryBootstrap"; - - @Mock private ConfigurableListableBeanFactory mockedBeanFactory; - @Mock private BeanDefinition mockedBeanDefinition; - - @InjectMocks private DictionaryBootstrapPostProcessor postProcessor; - - /** - * given the bean factory does not contain the site service bootstrap bean then ensure that it is - * not added as a dependency - */ - @Test - public void noSiteServiceBootstrapBeanAvailable() - { - // === given ==== - doReturn(false).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP); - - // === when === - postProcessor.postProcessBeanFactory(mockedBeanFactory); - - // === then === - verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP); - verifyNoMoreInteractions(mockedBeanFactory); - verifyZeroInteractions(mockedBeanDefinition); - } - - /** - * given that the site service bootstrap bean is contained within the bean factory, ensure that - * it is added as a dependency - */ - @Test - public void siteServiceBootstrapBeanAvailable() - { - // === given ==== - doReturn(true).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP); - doReturn(true).when(mockedBeanFactory).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP); - doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP); - - // === when === - postProcessor.postProcessBeanFactory(mockedBeanFactory); - - // === then === - verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP); - verify(mockedBeanFactory, times(1)).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP); - - verify(mockedBeanFactory, times(1)).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP); - verify(mockedBeanDefinition, times(1)).setDependsOn(new String[]{BEAN_SITESERVICE_BOOTSTRAP}); - - verifyNoMoreInteractions(mockedBeanFactory, mockedBeanDefinition); - - } -} + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.model.compatibility; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.verifyZeroInteractions; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; + +/** + * Dictionary bootstrap post processor unit test. + * + * @author Roy Wetherall + * @since 2.2 + */ +public class DictionaryBootstrapPostProcessorUnitTest extends BaseUnitTest +{ + /** bean id's */ + private static final String BEAN_SITESERVICE_BOOTSTRAP = "siteService_dictionaryBootstrap"; + private static final String BEAN_RM_DICTIONARY_BOOTSTRAP = "org_alfresco_module_rm_dictionaryBootstrap"; + + @Mock private ConfigurableListableBeanFactory mockedBeanFactory; + @Mock private BeanDefinition mockedBeanDefinition; + + @InjectMocks private DictionaryBootstrapPostProcessor postProcessor; + + /** + * given the bean factory does not contain the site service bootstrap bean then ensure that it is + * not added as a dependency + */ + @Test + public void noSiteServiceBootstrapBeanAvailable() + { + // === given ==== + doReturn(false).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP); + + // === when === + postProcessor.postProcessBeanFactory(mockedBeanFactory); + + // === then === + verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP); + verifyNoMoreInteractions(mockedBeanFactory); + verifyZeroInteractions(mockedBeanDefinition); + } + + /** + * given that the site service bootstrap bean is contained within the bean factory, ensure that + * it is added as a dependency + */ + @Test + public void siteServiceBootstrapBeanAvailable() + { + // === given ==== + doReturn(true).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP); + doReturn(true).when(mockedBeanFactory).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP); + doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP); + + // === when === + postProcessor.postProcessBeanFactory(mockedBeanFactory); + + // === then === + verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP); + verify(mockedBeanFactory, times(1)).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP); + + verify(mockedBeanFactory, times(1)).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP); + verify(mockedBeanDefinition, times(1)).setDependsOn(new String[]{BEAN_SITESERVICE_BOOTSTRAP}); + + verifyNoMoreInteractions(mockedBeanFactory, mockedBeanDefinition); + + } +}