From 379f65db0dd1299b544df6681c5e045c08842a17 Mon Sep 17 00:00:00 2001 From: "shishuraj.bisht" Date: Tue, 1 Nov 2022 17:40:07 +0530 Subject: [PATCH 01/21] Added copyToRuleOnFoldersTest [ags] --- .../rules/CopyToRuleOnFoldersTest.java | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/CopyToRuleOnFoldersTest.java diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/CopyToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/CopyToRuleOnFoldersTest.java new file mode 100644 index 0000000000..c3885f8f41 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/CopyToRuleOnFoldersTest.java @@ -0,0 +1,113 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2022 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.rm.community.rules; + +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.record.Record; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; +import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; +import org.alfresco.rest.rm.community.model.rules.RuleDefinition; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI; +import org.alfresco.rest.rm.community.smoke.CreateCategoriesTests; +import org.alfresco.rest.v0.RulesAPI; +import org.alfresco.test.AlfrescoTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +import java.util.Collections; + +import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX; +import static org.alfresco.rest.rm.community.base.TestData.ELECTRONIC_RECORD_NAME; +import static org.alfresco.rest.rm.community.base.TestData.NONELECTRONIC_RECORD_NAME; +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; +import static org.alfresco.rest.rm.community.utils.CoreUtil.createBodyForMoveCopy; +import static org.alfresco.rest.rm.community.utils.CoreUtil.toContentModel; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.*; +import static org.alfresco.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.*; + +public class CopyToRuleOnFoldersTest extends BaseRMRestTest { + + private RecordCategory category; + private RecordCategoryChild folder1,folder2; + private final static String title = "Run in background"; + private final String TEST_PREFIX = generateTestPrefix(CopyToRuleOnFoldersTest.class); + private final String RM_ADMIN = TEST_PREFIX + "rm_admin"; + private final String electronicRecord = TEST_PREFIX + "record_electronic_for_copyTo"; + private final String nonElectronicRecord = TEST_PREFIX + "record_non_electronic_for_copyTo"; + + @Autowired + private RulesAPI rulesAPI; + + @Test + @AlfrescoTest(jira = "RM-2994") + public void copyToRuleOnFoldersTest() + { + + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1") + .runInBackground(true).title(title) + .actions(Collections.singletonList(ActionsOnRule.COPY_TO.getActionValue())); + + + STEP("Create the RM site if doesn't exist"); + createRMSiteIfNotExists(); + + STEP("Create record categories and record folders"); + category= createRootCategory(getRandomName("recordCategory")); + String folder1 = createCategoryFolderInFilePlan().getId(); + String folder2 = createCategoryFolderInFilePlan().getId(); + + // create a rule on folder + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folder1, ruleDefinition); + + // create electronic record in record folder + String electronicRecordId = createElectronicRecord(folder1, ELECTRONIC_RECORD_NAME).getId(); + assertStatusCode(CREATED); + + // create non-electronic record in record folder + String nonElectronicRecord = createElectronicRecord(folder1, NONELECTRONIC_RECORD_NAME).getId(); + assertStatusCode(CREATED); + + // Move the electronic and non-electronic records from "Category with records"> "Folder with rule" + // to "Copy Category with records" > "Folder with rule" + getRestAPIFactory().getNodeAPI(toContentModel(folder1)).copy(createBodyForMoveCopy(category.getId())); + getRestAPIFactory().getNodeAPI(toContentModel( electronicRecord)).move(createBodyForMoveCopy(folder2)); + getRestAPIFactory().getNodeAPI(toContentModel( nonElectronicRecord)).move(createBodyForMoveCopy(folder2)); + + RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(); + recordsAPI.deleteRecord(electronicRecord); + recordsAPI.deleteRecord(nonElectronicRecord); + assertStatusCode(NO_CONTENT); + + + } + + +} From d68ceb1a4b57ab89f7f4be502ce4154fb3f285f1 Mon Sep 17 00:00:00 2001 From: ashiva Date: Wed, 2 Nov 2022 07:06:46 +0000 Subject: [PATCH 02/21] [ags]"MoveToRuleOnFoldersTest converted" --- .../rule/MoveToRuleOnFoldersTest.java | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rule/MoveToRuleOnFoldersTest.java diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rule/MoveToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rule/MoveToRuleOnFoldersTest.java new file mode 100644 index 0000000000..b8c2b3d720 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rule/MoveToRuleOnFoldersTest.java @@ -0,0 +1,167 @@ +package org.alfresco.rest.rm.community.rule; + +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.record.Record; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; +import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; +import org.alfresco.rest.rm.community.model.rules.RuleDefinition; +import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer; +import org.alfresco.rest.rm.community.model.user.UserRoles; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; +import org.alfresco.rest.v0.HoldsAPI; +import org.alfresco.rest.v0.RecordsAPI; +import org.alfresco.rest.v0.RulesAPI; +import org.alfresco.rest.v0.service.RoleService; +import org.alfresco.utility.model.UserModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collections; +import java.util.Random; + +import static java.lang.Integer.MAX_VALUE; +import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; +import static org.alfresco.rest.rm.community.utils.CoreUtil.createBodyForMoveCopy; +import static org.alfresco.rest.rm.community.utils.CoreUtil.toContentModel; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.*; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; +import static org.alfresco.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; +import static org.testng.Assert.assertNotNull; + + +public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ + + private String unfiledRecordsNodeRef; + + private String recordFolder2; + private String nonElectronicId; + + private Record electronicRecord; + private UnfiledContainer unfiledContainer; + + private UserModel rmAdmin; + private RecordCategory RecordCategoryOne; + private RecordCategoryChild recordFolder; + public static final String RECORD_FOLDER_ONE = "record-folder-one"; + private final String TEST_PREFIX = generateTestPrefix(MoveToRuleOnFoldersTest.class); + // private final String RM_ADMIN = TEST_PREFIX + "rm_admin"; + private final String RECORD_CATEGORY_ONE = TEST_PREFIX + "category"; + + private final String recordName = "Test record"; + private final String recordTitle = recordName + " title"; + private final String recordDescription = recordName + " description"; + @Autowired + private RulesAPI rulesAPI; + @Autowired + private HoldsAPI holdsAPI; + + @Autowired + private RoleService roleService; + + @Autowired + private RecordsAPI recordsAPI; + + @BeforeClass(alwaysRun = true) + public void precondition() + { + //create RM site + createRMSiteIfNotExists(); + rmAdmin = roleService.createUserWithRMRole(UserRoles.ROLE_RM_ADMIN.roleId); + /** + * Removes rules on File Plan and Unfiled Records + */ + final String holdName = TEST_PREFIX + "holdToBeDeleted"; + holdsAPI.deleteHold(rmAdmin.getUsername(), rmAdmin.getPassword(), holdName); + unfiledContainer = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS); + + unfiledRecordsNodeRef = NODE_PREFIX + unfiledContainer.getId(); + rulesAPI.deleteAllRulesOnContainer(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), unfiledRecordsNodeRef); + + //create root category, create folders , add electronic and non electronic records + RecordCategoryOne = createRootCategory(RECORD_CATEGORY_ONE); + String recordFolder1 = createRecordFolder(RecordCategoryOne.getId(), getRandomName("recFolder")).getId(); + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + + electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1, getFile(IMAGE_FILE)); + STEP("Check the electronic record has been created"); + assertStatusCode(CREATED); + + // Generate update metadata + String newName = getModifiedPropertyValue(electronicRecord.getName()); + String newTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); + String newDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); + + // Update record:EDIT electronic and non electronic metadata [PENDING] + +// recordsAPI.updateRecord(createRecordModel(newName, newDescription, newTitle), electronicRecord.getId()); +// assertStatusCode(OK); + + + + //create non electronic record + STEP("Create a non-electronic record by completing some of the fields"); + // Use these properties for non-electronic record to be created + String title = "Title " + getRandomAlphanumeric(); + String description = "Description " + getRandomAlphanumeric(); + String box = "Box "+ getRandomAlphanumeric(); + String file = "File " + getRandomAlphanumeric(); + String shelf = "Shelf " + getRandomAlphanumeric(); + String storageLocation = "Storage Location " + getRandomAlphanumeric(); + String name = "Record " + getRandomAlphanumeric(); + Random random = new Random(); + Integer numberOfCopies = random.nextInt(MAX_VALUE); + Integer physicalSize = random.nextInt(MAX_VALUE); + + // Set values of all available properties for the non electronic records + Record nonElectrinicRecordModel = createFullNonElectronicRecordModel(name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize); + // Create non-electronic record + nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1).getId(); +// STEP("Check the non-electronic record has been created"); + assertStatusCode(CREATED); + + // move the electronic and nonelectronic record from folder1 to folder2 + STEP("Create the record folder2 inside the rootCategory"); + recordFolder2 = createCategoryFolderInFilePlan().getId(); + +// //create a rule for completing record for folder 2 + + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1") + .applyToChildren(true).title(title) + .actions(Collections.singletonList(ActionsOnRule.COMPLETE_RECORD.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder2, ruleDefinition); + + } + @Test + public void MoveToRuleFoldersTest() + { STEP("Move electronic record from folder1 to folder2"); + RestNodeModel electronicDocRestNodeModel = getRestAPIFactory() + .getNodeAPI(toContentModel(electronicRecord.getId())) + .move(createBodyForMoveCopy(recordFolder2)); + assertStatusCode(OK); + + STEP("Move non-electronic record from folder1 to folder2"); + + RestNodeModel nonelectronicDocRestNodeModel = getRestAPIFactory() + .getNodeAPI(toContentModel(nonElectronicId)) + .move(createBodyForMoveCopy(recordFolder2)); + assertStatusCode(OK); + + } + + private String getModifiedPropertyValue(String originalValue) { + /* to be used to append to modifications */ + String MODIFIED_PREFIX = "modified_"; + return MODIFIED_PREFIX + originalValue; + } + } + + From af2c11063bbf82386ab8969fe4d5d4ca4265cc86 Mon Sep 17 00:00:00 2001 From: ashiva Date: Wed, 2 Nov 2022 07:26:06 +0000 Subject: [PATCH 03/21] [ags]"MoveToRuleOnFoldersTest converted" --- .../rm/community/{rule => rules}/MoveToRuleOnFoldersTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/{rule => rules}/MoveToRuleOnFoldersTest.java (99%) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rule/MoveToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java similarity index 99% rename from amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rule/MoveToRuleOnFoldersTest.java rename to amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java index b8c2b3d720..49540e65d0 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rule/MoveToRuleOnFoldersTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java @@ -1,4 +1,4 @@ -package org.alfresco.rest.rm.community.rule; +package org.alfresco.rest.rm.community.rules; import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.rm.community.base.BaseRMRestTest; From 7430c80a4188a9083cee97115ee53d57fb20c141 Mon Sep 17 00:00:00 2001 From: cchandan Date: Fri, 4 Nov 2022 13:39:11 +0530 Subject: [PATCH 04/21] Added FileAsRecordRuleTests [ags] --- .../rules/FileAsRecordRuleTests.java | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java new file mode 100644 index 0000000000..b42fcaee62 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java @@ -0,0 +1,216 @@ +package org.alfresco.rest.rm.community.rules; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; +import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; +import org.alfresco.rest.rm.community.model.rules.RuleDefinition; +import org.alfresco.rest.rm.community.model.user.UserRoles; + +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; + +import org.alfresco.rest.v0.RulesAPI; +import org.alfresco.rest.v0.service.RoleService; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; + +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collections; + +import static java.util.Arrays.asList; +import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING; +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; + +import static org.alfresco.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; + +@AlfrescoTest (jira = "APPS-36") +public class FileAsRecordRuleTests extends BaseRMRestTest +{ + private static final String CATEGORY_MANAGER = "categoryManager" + generateTestPrefix(FileAsRecordRuleTests.class); + private static final String CATEGORY_ADMIN = "categoryAdmin" + generateTestPrefix(FileAsRecordRuleTests.class); + private static final String FOLDER_MANAGER = "recordFolder" + generateTestPrefix(FileAsRecordRuleTests.class); + private static final String FOLDER_ADMIN = "recordFolder" + generateTestPrefix(FileAsRecordRuleTests.class); + + private UserModel nonRMUser,rmManager; + private SiteModel publicSite; + private FolderModel testFolder; + private FileModel inPlaceRecord; + private RecordCategory category_manager,category_admin; + private RecordCategoryChild folder_admin,folder_manager; + private static final String RULE_NAME = "File as Record Rule"; + private static final String FOLDER_MANAGER_PATH = "/" + CATEGORY_MANAGER + "/" + FOLDER_MANAGER; + @Autowired + private RoleService roleService; + @Autowired + private RulesAPI rulesAPI; + + /** + * Create preconditions: + * 1. RM site is created + * 2. Two users: user without RM role and a user with RM manager role + * 3. Two Record categories with one folder each + * 4. User with RM MANAGER role has Filling permission over one category + * 5. A collaboration folder with rule set to declare and file as record to a record folder + **/ + @BeforeClass(alwaysRun = true) + public void preconditionForDeclareFileAsRecordRuleTests() + { + STEP("Create the RM site if doesn't exist"); + createRMSiteIfNotExists(); + + STEP("Create a user"); + nonRMUser = dataUser.createRandomTestUser("testUser"); + + STEP("Create a collaboration site"); + publicSite = dataSite.usingUser(nonRMUser).createPublicRandomSite(); + + + STEP("Create two categories with two folders"); + category_manager = createRootCategory(CATEGORY_MANAGER); + category_admin = createRootCategory(CATEGORY_ADMIN); + folder_admin = createFolder(category_admin.getId(),FOLDER_ADMIN); + folder_manager = createFolder(category_manager.getId(),FOLDER_MANAGER); + + STEP("Create an rm user and give filling permission over CATEGORY_MANAGER record category"); + RecordCategory recordCategory = new RecordCategory().builder() + .id(category_manager.getId()).build(); + + rmManager = roleService.createCollaboratorWithRMRoleAndPermission(publicSite, recordCategory, + UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); + + STEP("Create a collaboration folder with a rule set to declare and file as record to a record folder"); + RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") + .applyToChildren(true) + .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + } + /** + * Given I am a user that can create a rule on a folder in a collaboration site + * When I am creating the rule + * Then I have the option of adding a "Declare and File as Record" action to the rule + *

+ * Given I am creating a rule + * When I add the "Declare and File as Record" action to the rule + * Then I am able to select the record folder I want the declared record to be filed to + *

+ * Given I am configuring a "Declare and File as Record" action within a rule + * And I have at least one records management role (eg RM User) + * When I am selecting the record folder location to file the declared record to + * Then I see the record folders in the file plan that I have file access to as the creator of the record + **/ + @Test + public void declareAsRecordRuleAsRMUserWithFilingPermissions() { + STEP("Create a collaboration folder"); + testFolder = dataContent.usingSite(publicSite) + .usingUser(rmManager) + .createFolder(); + + STEP("Create a rule with Declare as Record action and check that user can select a record folder."); + RecordCategory recordCategory = new RecordCategory().builder() + .id(category_manager.getId()).build(); + RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") + .applyToChildren(true) + .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + } + /** + * Given I am configuring a "Declare and File as Record" action within a rule + * And I don't have a records management role + * When I am selecting the record folder location to file the declared record to + * Then I can see only the file plan + */ + @Test + public void declareAsRecordRuleAsNonRMUser() + { + STEP("Create a collaboration folder"); + testFolder = dataContent.usingSite(publicSite) + .usingUser(rmManager) + .createFolder(); + + STEP("Create a rule with Declare as Record action and check that user can select a record folder."); + RecordCategory recordCategory = new RecordCategory().builder() + .id(category_manager.getId()).build(); + RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") + .applyToChildren(true) + .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + } + /** + * Given a record folder location has been selected for a "Declare and File as Record" action within a rule + * And I have permissions and capabilities to file to that record folder + * When I trigger the rule + * Then the file is filed directly to the selected record folder from the file plan + */ + + @Test + public void triggerDeclareToRecordFolderRuleAsUserWithPermissions() + { + STEP("Create as rmManager a new file into the folderWithRule in order to trigger the rule"); + FileModel testFile = dataContent.usingUser(rmManager).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + /** + * Given a record folder location has been selected for a "Declare and File as Record" action within a rule + * And I don't have permissions and capabilities to file to that record folder + * When I trigger the rule + * Then the file is not declared as record + */ + + @Test + public void triggerDeclareToRecordFolderRuleAsUserWithoutPermissions() + { + STEP("Create as nonRMuser a new file into the folderWithRule in order to trigger the rule"); + FileModel testFile = dataContent.usingUser(nonRMUser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + /** + * Given I have not selected a record folder location + * When the rule is triggered + * Then the file is declared as record to the Unfiled Records folder + */ + @Test + public void triggerDeclareToUnfiledRuleAsNonRMUser() + { + STEP("Create a collaboration folder with a rule set to declare and file as record without a record folder location"); + + RecordCategory recordCategory = new RecordCategory().builder() + .id(category_manager.getId()).build(); + RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") + .applyToChildren(true) + .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + + STEP("Create as nonRMuser a new file into the previous folder in order to trigger the rule"); + inPlaceRecord = dataContent.usingUser(nonRMUser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + @AfterClass(alwaysRun = true) + public void cleanupDeclareAsRecordRuleTests() + { + STEP("Delete the collaboration site"); + dataSite.usingUser(nonRMUser).deleteSite(publicSite); + + STEP("Delete Users"); + dataUser.deleteUser(nonRMUser); + dataUser.deleteUser(rmManager); + + STEP("Delete categories"); + getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry -> + deleteRecordCategory(recordCategoryEntry.getEntry().getId())); + getRestAPIFactory().getRecordsAPI().deleteRecord(inPlaceRecord.getNodeRefWithoutVersion()); + } +} \ No newline at end of file From f49b7a393fed00237705e4fb56500c86cb085eba Mon Sep 17 00:00:00 2001 From: ashiva Date: Fri, 4 Nov 2022 08:20:04 +0000 Subject: [PATCH 05/21] "MoveToRuleOnFoldersTest added rule and folder creation" --- .../rules/MoveToRuleOnFoldersTest.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java index 49540e65d0..4164ab78cc 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java @@ -41,7 +41,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ private String unfiledRecordsNodeRef; - private String recordFolder2; + private RecordCategoryChild recordFolder2; private String nonElectronicId; private Record electronicRecord; @@ -95,21 +95,19 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ STEP("Check the electronic record has been created"); assertStatusCode(CREATED); - // Generate update metadata - String newName = getModifiedPropertyValue(electronicRecord.getName()); - String newTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); - String newDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); - - // Update record:EDIT electronic and non electronic metadata [PENDING] - -// recordsAPI.updateRecord(createRecordModel(newName, newDescription, newTitle), electronicRecord.getId()); -// assertStatusCode(OK); +// // Generate update metadata +// String newName = getModifiedPropertyValue(electronicRecord.getName()); +// String newTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); +// String newDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); +// +// // Update record:EDIT electronic and non electronic metadata [PENDING] +// +//// recordsAPI.updateRecord(createRecordModel(newName, newDescription, newTitle), electronicRecord.getId()); +//// assertStatusCode(OK); - - //create non electronic record STEP("Create a non-electronic record by completing some of the fields"); - // Use these properties for non-electronic record to be created + // Use these properties for non-electronic record to be created String title = "Title " + getRandomAlphanumeric(); String description = "Description " + getRandomAlphanumeric(); String box = "Box "+ getRandomAlphanumeric(); @@ -125,34 +123,41 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ Record nonElectrinicRecordModel = createFullNonElectronicRecordModel(name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize); // Create non-electronic record nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1).getId(); -// STEP("Check the non-electronic record has been created"); + STEP("Check the non-electronic record has been created"); assertStatusCode(CREATED); - // move the electronic and nonelectronic record from folder1 to folder2 - STEP("Create the record folder2 inside the rootCategory"); - recordFolder2 = createCategoryFolderInFilePlan().getId(); +// STEP("Create Copy of RootRecord"); +// RestNodeModel RootCategoryCopy = getRestAPIFactory() +// .getNodeAPI(toContentModel(RecordCategoryOne.getId())) +// .copy(createBodyForMoveCopy(RecordCategoryOne.getId())); +// assertStatusCode(CREATED); +// RestNodeModel RootCategoryCopy= getRestAPIFactory().getNodeAPI(toContentModel(RecordCategoryOne.getId())).copy(createBodyForMoveCopy(RecordCategoryOne.getId())); -// //create a rule for completing record for folder 2 + STEP("Create the folder2 inside the rootCategory"); + recordFolder2 = createFolder(getAdminUser(),RecordCategoryOne.getId(),getRandomName("recFolder")); + + STEP("create a rule MOVE_TO for folder 2"); RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1") - .applyToChildren(true).title(title) - .actions(Collections.singletonList(ActionsOnRule.COMPLETE_RECORD.getActionValue())); - rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder2, ruleDefinition); - + .runInBackground(true).title(title) + .actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder2.getId() , ruleDefinition); } + @Test public void MoveToRuleFoldersTest() - { STEP("Move electronic record from folder1 to folder2"); + { + STEP("Move electronic record from folder1 to folder2"); RestNodeModel electronicDocRestNodeModel = getRestAPIFactory() .getNodeAPI(toContentModel(electronicRecord.getId())) - .move(createBodyForMoveCopy(recordFolder2)); + .move(createBodyForMoveCopy(recordFolder2.getId())); assertStatusCode(OK); STEP("Move non-electronic record from folder1 to folder2"); RestNodeModel nonelectronicDocRestNodeModel = getRestAPIFactory() .getNodeAPI(toContentModel(nonElectronicId)) - .move(createBodyForMoveCopy(recordFolder2)); + .move(createBodyForMoveCopy(recordFolder2.getId())); assertStatusCode(OK); } @@ -162,6 +167,5 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ String MODIFIED_PREFIX = "modified_"; return MODIFIED_PREFIX + originalValue; } - } - +} From 32314480a1f047d3b9db39932e1b483b9a6bce3a Mon Sep 17 00:00:00 2001 From: cchandan Date: Fri, 4 Nov 2022 15:10:49 +0530 Subject: [PATCH 06/21] Added FileAsRecordRuleTests [ags] --- .../rules/FileAsRecordRuleTests.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java index b42fcaee62..11aecaf617 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java @@ -1,3 +1,30 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2022 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + package org.alfresco.rest.rm.community.rules; import org.alfresco.dataprep.CMISUtil; From 91031ca72ad7b3863ebfa87e68b3869c0636038b Mon Sep 17 00:00:00 2001 From: sbisht Date: Fri, 4 Nov 2022 15:48:03 +0530 Subject: [PATCH 07/21] Added FileAsRecordRuleTests [ags] --- .../alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java index 11aecaf617..dd7fa6e26a 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java @@ -67,7 +67,6 @@ public class FileAsRecordRuleTests extends BaseRMRestTest private static final String CATEGORY_ADMIN = "categoryAdmin" + generateTestPrefix(FileAsRecordRuleTests.class); private static final String FOLDER_MANAGER = "recordFolder" + generateTestPrefix(FileAsRecordRuleTests.class); private static final String FOLDER_ADMIN = "recordFolder" + generateTestPrefix(FileAsRecordRuleTests.class); - private UserModel nonRMUser,rmManager; private SiteModel publicSite; private FolderModel testFolder; From 7819e29bcc990a8bc315e4d639f5ac6257834116 Mon Sep 17 00:00:00 2001 From: sbisht Date: Fri, 4 Nov 2022 16:37:18 +0530 Subject: [PATCH 08/21] Added FileVersionAsRecordRuleTest [ags] --- .../rules/FileVersionAsRecordRuleTest.java | 218 ++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java new file mode 100644 index 0000000000..a8da049a38 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java @@ -0,0 +1,218 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2022 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.rm.community.rules; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; +import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; +import org.alfresco.rest.rm.community.model.rules.RuleDefinition; +import org.alfresco.rest.rm.community.model.user.UserRoles; +import org.alfresco.rest.rm.community.smoke.FileAsRecordTests; +import org.alfresco.rest.v0.RulesAPI; +import org.alfresco.rest.v0.service.RoleService; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collections; + +import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING; +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; +import static org.alfresco.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; + +public class FileVersionAsRecordRuleTest extends BaseRMRestTest { + + private UserModel nonRMuser, rmManager; + private SiteModel publicSite; + private RecordCategory category_manager, category_admin; + private RecordCategoryChild folder_admin, folder_manager ; + private static final String CATEGORY_MANAGER = "catManager" + generateTestPrefix(FileAsRecordTests.class); + private static final String CATEGORY_ADMIN = "catAdmin" + generateTestPrefix(FileAsRecordTests.class); + private static final String FOLDER_MANAGER = "recordFolder" + generateTestPrefix(FileAsRecordTests.class); + private static final String FOLDER_ADMIN = "recordFolder" + generateTestPrefix(FileAsRecordTests.class); + private FolderModel testFolder; + private FileModel document, documentDeclared,inPlaceRecord; + + + @Autowired + private RoleService roleService; + @Autowired + private RulesAPI rulesAPI; + + @BeforeClass(alwaysRun = true) + public void createTestPrecondition() + { + + + STEP("Create the RM site if doesn't exist"); + createRMSiteIfNotExists(); + + STEP("Create a user"); + nonRMuser = dataUser.createRandomTestUser("testUser"); + + STEP("Create a collaboration site"); + testSite = dataSite.usingUser(nonRMuser).createPublicRandomSite(); + + STEP("Create a document with the user without RM role"); + document = dataContent.usingSite(testSite) + .usingUser(nonRMuser) + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + STEP("Create two categories with two folders"); + category_manager = createRootCategory(CATEGORY_MANAGER); + category_admin = createRootCategory(CATEGORY_ADMIN); + folder_admin = createFolder(category_admin.getId(),FOLDER_ADMIN); + folder_manager = createFolder(category_manager.getId(),FOLDER_MANAGER); + + + STEP("Create an rm user and give filling permission over CATEGORY_MANAGER record category"); + RecordCategory recordCategory = new RecordCategory().builder() + .id(category_manager.getId()) + .build(); + rmManager = roleService.createCollaboratorWithRMRoleAndPermission(testSite, recordCategory, + UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); + + + + STEP("Create a collaboration folder with a rule set to declare and file version as record to a record folder"); + RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") + .applyToChildren(true) + .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + + } + + @Test + public void declareVersionAsRecordRuleAsRMUserWithFilingPermissions() + { + + STEP("Create a collaboration folder"); + testFolder = dataContent.usingSite(testSite) + .usingUser(rmManager) + .createFolder(); + + STEP("Create a rule with Declare as Record action and check that user can select a record folder."); + RecordCategory recordCategory = new RecordCategory().builder() + .id(category_manager.getId()).build(); + RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") + .applyToChildren(true) + .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + + + + + + + } + + @Test + public void declareVersionAsRecordRuleAsNonRMUser() + { + + STEP("Create a collaboration folder"); + testFolder = dataContent.usingSite(testSite) + .usingUser(nonRMuser) + .createFolder(); + + STEP("Create a rule with Declare as Record action and check that user can select a record folder."); + RecordCategory recordCategory = new RecordCategory().builder() + .id(category_manager.getId()).build(); + RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") + .applyToChildren(true) + .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + + + } + + @Test + public void triggerFileVersionToRecordFolderRuleAsUserWithPermissions() + { + + STEP("Create as rmManager a new file into the folderWithRule in order to trigger the rule"); + FileModel testFile = dataContent.usingUser(rmManager).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + } + + @Test + public void triggerFileVersionToRecordFolderRuleAsUserWithoutPermissions() + { + + STEP("Create as nonRMuser a new file into the folderWithRule in order to trigger the rule"); + FileModel testFile = dataContent.usingUser(nonRMuser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + @Test + public void triggerDeclareToUnfiledRuleAsNonRMUser() + { + + STEP("Create a collaboration folder with a rule set to declare and file as record without a record folder location"); + + RecordCategory recordCategory = new RecordCategory().builder() + .id(category_manager.getId()).build(); + RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") + .applyToChildren(true) + .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + + STEP("Create as nonRMuser a new file into the previous folder in order to trigger the rule"); + inPlaceRecord = dataContent.usingUser(nonRMuser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + @AfterClass(alwaysRun = true) + public void cleanupDeclareVersionAsRecordRuleTests() + { + + STEP("Delete the collaboration site"); + dataSite.usingUser(nonRMuser).deleteSite(testSite); + + STEP("Delete Users"); + dataUser.deleteUser(nonRMuser); + dataUser.deleteUser(rmManager); + + STEP("Delete categories"); + getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry -> + deleteRecordCategory(recordCategoryEntry.getEntry().getId())); + getRestAPIFactory().getRecordsAPI().deleteRecord(inPlaceRecord.getNodeRefWithoutVersion()); + } + +} From f55602842d7cf15347bfd370a8c729730cdf85dc Mon Sep 17 00:00:00 2001 From: ashiva Date: Fri, 4 Nov 2022 15:32:37 +0000 Subject: [PATCH 09/21] "MoveToRuleOnFoldersTest added metadata update and and copy of records"[ags] --- .../rules/MoveToRuleOnFoldersTest.java | 86 +++++++++++++++---- 1 file changed, 67 insertions(+), 19 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java index 4164ab78cc..8187b82cb9 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java @@ -1,7 +1,34 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2022 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.rest.rm.community.rules; import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.fileplan.FilePlan; import org.alfresco.rest.rm.community.model.record.Record; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; @@ -16,6 +43,7 @@ import org.alfresco.rest.v0.RulesAPI; import org.alfresco.rest.v0.service.RoleService; import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -23,7 +51,9 @@ import java.util.Collections; import java.util.Random; import static java.lang.Integer.MAX_VALUE; +import static java.util.Arrays.asList; import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; import static org.alfresco.rest.rm.community.utils.CoreUtil.createBodyForMoveCopy; @@ -32,8 +62,7 @@ import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.*; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.alfresco.utility.data.RandomData.getRandomName; import static org.alfresco.utility.report.log.Step.STEP; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.*; import static org.testng.Assert.assertNotNull; @@ -48,7 +77,8 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ private UnfiledContainer unfiledContainer; private UserModel rmAdmin; - private RecordCategory RecordCategoryOne; + public RecordCategory RecordCategoryOne; + public RestNodeModel RecordCategoryCopy; private RecordCategoryChild recordFolder; public static final String RECORD_FOLDER_ONE = "record-folder-one"; private final String TEST_PREFIX = generateTestPrefix(MoveToRuleOnFoldersTest.class); @@ -67,7 +97,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ private RoleService roleService; @Autowired - private RecordsAPI recordsAPI; + public RecordsAPI recordsAPI; @BeforeClass(alwaysRun = true) public void precondition() @@ -95,15 +125,6 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ STEP("Check the electronic record has been created"); assertStatusCode(CREATED); -// // Generate update metadata -// String newName = getModifiedPropertyValue(electronicRecord.getName()); -// String newTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); -// String newDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); -// -// // Update record:EDIT electronic and non electronic metadata [PENDING] -// -//// recordsAPI.updateRecord(createRecordModel(newName, newDescription, newTitle), electronicRecord.getId()); -//// assertStatusCode(OK); STEP("Create a non-electronic record by completing some of the fields"); @@ -126,12 +147,22 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ STEP("Check the non-electronic record has been created"); assertStatusCode(CREATED); -// STEP("Create Copy of RootRecord"); -// RestNodeModel RootCategoryCopy = getRestAPIFactory() -// .getNodeAPI(toContentModel(RecordCategoryOne.getId())) -// .copy(createBodyForMoveCopy(RecordCategoryOne.getId())); -// assertStatusCode(CREATED); -// RestNodeModel RootCategoryCopy= getRestAPIFactory().getNodeAPI(toContentModel(RecordCategoryOne.getId())).copy(createBodyForMoveCopy(RecordCategoryOne.getId())); + STEP("Update metadata for Non-Electronic Record"); + org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(); + Record nonelecrecord = recordsAPI.getRecord(nonElectronicId); + String nonelecnewName = getModifiedPropertyValue(nonElectrinicRecordModel.getName()); + String nonelecnewTitle = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getTitle()); + String nonelecnewDescription = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getDescription()); + recordsAPI.updateRecord(createRecordModel(nonelecnewName, nonelecnewDescription, nonelecnewTitle),nonelecrecord.getId()); + assertStatusCode(OK); + + STEP("Update metadata for Electronic Record"); + Record elecrecord = recordsAPI.getRecord(electronicRecord.getId()); + String elecnewName = getModifiedPropertyValue(electronicRecord.getName()); + String elecnewTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); + String elecnewDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); + recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId()); + assertStatusCode(OK); STEP("Create the folder2 inside the rootCategory"); recordFolder2 = createFolder(getAdminUser(),RecordCategoryOne.getId(),getRandomName("recFolder")); @@ -160,6 +191,23 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ .move(createBodyForMoveCopy(recordFolder2.getId())); assertStatusCode(OK); + + STEP("Create Copy of RootRecord"); + FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS); + RecordCategoryCopy=getRestAPIFactory().getNodeAPI(toContentModel(RecordCategoryOne.getId())).copy(createBodyForMoveCopy(filePlan.getId())); + + } + + @AfterClass(alwaysRun = true) + public void cleanMoveToRuleOnFoldersTest() + { + deleteRecordCategory(RecordCategoryOne.getId()); + + // Delete record and verify status + System.out.println(RecordCategoryCopy); +// recordsAPI.deleteRecord(RecordCategoryCopy.getName(),RecordCategoryCopy.); +// assertStatusCode(NO_CONTENT); + getDataUser().deleteUser(rmAdmin); } private String getModifiedPropertyValue(String originalValue) { From 03ce7e37d4172391f55da63c6210274053dd7a79 Mon Sep 17 00:00:00 2001 From: ashiva Date: Fri, 4 Nov 2022 15:39:08 +0000 Subject: [PATCH 10/21] "MoveToRuleOnFoldersTest added metadata update and and copy of records"[ags] --- .../rest/rm/community/rules/MoveToRuleOnFoldersTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java index 8187b82cb9..5ed4228600 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java @@ -204,7 +204,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ deleteRecordCategory(RecordCategoryOne.getId()); // Delete record and verify status - System.out.println(RecordCategoryCopy); + // recordsAPI.deleteRecord(RecordCategoryCopy.getName(),RecordCategoryCopy.); // assertStatusCode(NO_CONTENT); getDataUser().deleteUser(rmAdmin); From 0f24f453c80cb016e71397bf7ac6f167d51e9663 Mon Sep 17 00:00:00 2001 From: sbisht Date: Wed, 9 Nov 2022 10:33:14 +0530 Subject: [PATCH 11/21] Added FileVersionAsRecordRuleTest [ags] --- .../rest/rm/community/rules/FileVersionAsRecordRuleTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java index a8da049a38..d611832497 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java @@ -65,7 +65,7 @@ public class FileVersionAsRecordRuleTest extends BaseRMRestTest { private static final String FOLDER_MANAGER = "recordFolder" + generateTestPrefix(FileAsRecordTests.class); private static final String FOLDER_ADMIN = "recordFolder" + generateTestPrefix(FileAsRecordTests.class); private FolderModel testFolder; - private FileModel document, documentDeclared,inPlaceRecord; + private FileModel document,inPlaceRecord; @Autowired From 63b0ff8cf4edd1c2664a64342cbb093aacd5aae4 Mon Sep 17 00:00:00 2001 From: sbisht Date: Wed, 9 Nov 2022 10:34:29 +0530 Subject: [PATCH 12/21] Added FileVersionAsRecordRuleTest [ags] --- .../rest/rm/community/rules/FileVersionAsRecordRuleTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java index d611832497..ae2e6afbe8 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java @@ -137,9 +137,6 @@ public class FileVersionAsRecordRuleTest extends BaseRMRestTest { - - - } @Test From fe5faa326393cec9b0b91d99b3723c3970e59f80 Mon Sep 17 00:00:00 2001 From: sbisht Date: Tue, 15 Nov 2022 12:16:44 +0530 Subject: [PATCH 13/21] updated CopyToRuleOnFoldersTest [ags] --- .../rest/rm/community/rules/CopyToRuleOnFoldersTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/CopyToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/CopyToRuleOnFoldersTest.java index c3885f8f41..137dc787a9 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/CopyToRuleOnFoldersTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/CopyToRuleOnFoldersTest.java @@ -32,6 +32,7 @@ import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; import org.alfresco.rest.rm.community.model.rules.RuleDefinition; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI; import org.alfresco.rest.rm.community.smoke.CreateCategoriesTests; @@ -102,6 +103,10 @@ public class CopyToRuleOnFoldersTest extends BaseRMRestTest { getRestAPIFactory().getNodeAPI(toContentModel( nonElectronicRecord)).move(createBodyForMoveCopy(folder2)); RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(); + // Delete the record category + RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); + String recordCategoryId = category.getId(); + recordCategoryAPI.deleteRecordCategory(recordCategoryId); recordsAPI.deleteRecord(electronicRecord); recordsAPI.deleteRecord(nonElectronicRecord); assertStatusCode(NO_CONTENT); From 17b04d73210fe66f49989459ea8c255bbf47e177 Mon Sep 17 00:00:00 2001 From: sbisht Date: Tue, 15 Nov 2022 16:38:12 +0530 Subject: [PATCH 14/21] updated FileVersionAsRecordRuleTest [ags] --- .../rules/FileVersionAsRecordRuleTest.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java index ae2e6afbe8..cd68afc22e 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java @@ -32,23 +32,26 @@ import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; import org.alfresco.rest.rm.community.model.rules.RuleDefinition; +import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildEntry; import org.alfresco.rest.rm.community.model.user.UserRoles; +import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI; import org.alfresco.rest.rm.community.smoke.FileAsRecordTests; import org.alfresco.rest.v0.RulesAPI; import org.alfresco.rest.v0.service.RoleService; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.FolderModel; -import org.alfresco.utility.model.SiteModel; -import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.model.*; import org.springframework.beans.factory.annotation.Autowired; +import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING; import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; import static org.alfresco.utility.data.RandomData.getRandomName; @@ -57,7 +60,6 @@ import static org.alfresco.utility.report.log.Step.STEP; public class FileVersionAsRecordRuleTest extends BaseRMRestTest { private UserModel nonRMuser, rmManager; - private SiteModel publicSite; private RecordCategory category_manager, category_admin; private RecordCategoryChild folder_admin, folder_manager ; private static final String CATEGORY_MANAGER = "catManager" + generateTestPrefix(FileAsRecordTests.class); @@ -133,7 +135,7 @@ public class FileVersionAsRecordRuleTest extends BaseRMRestTest { RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") .applyToChildren(true) .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); - rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + rulesAPI.createRule(rmManager.getUsername(), rmManager.getPassword(), NODE_PREFIX + testFolder.getNodeRef(), ruleDefinition); @@ -151,48 +153,46 @@ public class FileVersionAsRecordRuleTest extends BaseRMRestTest { STEP("Create a rule with Declare as Record action and check that user can select a record folder."); RecordCategory recordCategory = new RecordCategory().builder() .id(category_manager.getId()).build(); - RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") .applyToChildren(true) .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); - rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + rulesAPI.createRule(nonRMuser.getUsername(), nonRMuser.getPassword(), NODE_PREFIX + testFolder.getNodeRef(), ruleDefinition); } @Test - public void triggerFileVersionToRecordFolderRuleAsUserWithPermissions() - { - - STEP("Create as rmManager a new file into the folderWithRule in order to trigger the rule"); - FileModel testFile = dataContent.usingUser(rmManager).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); - - } - - @Test - public void triggerFileVersionToRecordFolderRuleAsUserWithoutPermissions() - { - - STEP("Create as nonRMuser a new file into the folderWithRule in order to trigger the rule"); - FileModel testFile = dataContent.usingUser(nonRMuser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); - } - - @Test - public void triggerDeclareToUnfiledRuleAsNonRMUser() - { + public void triggerDeclareToUnfiledRuleAsNonRMUser() throws Exception { STEP("Create a collaboration folder with a rule set to declare and file as record without a record folder location"); + + FileModel inplaceRecord = dataContent.usingSite(testSite).usingUser(nonRMuser) + .createContent(new FileModel("declareAndFileToIntoUnfiledRecordFolder", + FileType.TEXT_PLAIN)); + RecordCategory recordCategory = new RecordCategory().builder() .id(category_manager.getId()).build(); - RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") .applyToChildren(true) .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); - rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + rulesAPI.createRule(nonRMuser.getUsername(), nonRMuser.getPassword(), NODE_PREFIX + inplaceRecord.getNodeRef(), ruleDefinition); - STEP("Create as nonRMuser a new file into the previous folder in order to trigger the rule"); + + STEP("Create as nonRMuser a new file into the previous folder in order to trigger the rule"); inPlaceRecord = dataContent.usingUser(nonRMuser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + // verify the declared record is in Unfilled Records folder + UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI(); + List matchingRecords = unfiledContainersAPI.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS) + .getEntries() + .stream() + .filter(e -> e.getEntry().getId().equals(inplaceRecord.getNodeRefWithoutVersion())) + .collect(Collectors.toList()); + + } @AfterClass(alwaysRun = true) @@ -206,10 +206,10 @@ public class FileVersionAsRecordRuleTest extends BaseRMRestTest { dataUser.deleteUser(nonRMuser); dataUser.deleteUser(rmManager); + STEP("Delete categories"); getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry -> deleteRecordCategory(recordCategoryEntry.getEntry().getId())); - getRestAPIFactory().getRecordsAPI().deleteRecord(inPlaceRecord.getNodeRefWithoutVersion()); } } From 1c9419d635e8ea1e5b5afb32bce74ffb26bd24d1 Mon Sep 17 00:00:00 2001 From: sbisht Date: Wed, 16 Nov 2022 11:47:27 +0530 Subject: [PATCH 15/21] updated CopyToRuleOnFoldersTest [ags] --- .../rm/community/rules/FileVersionAsRecordRuleTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java index cd68afc22e..3ed3f4c115 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java @@ -56,6 +56,8 @@ import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSI import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; import static org.alfresco.utility.data.RandomData.getRandomName; import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; public class FileVersionAsRecordRuleTest extends BaseRMRestTest { @@ -117,6 +119,7 @@ public class FileVersionAsRecordRuleTest extends BaseRMRestTest { .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + assertStatusCode(CREATED); } @Test @@ -137,7 +140,7 @@ public class FileVersionAsRecordRuleTest extends BaseRMRestTest { .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); rulesAPI.createRule(rmManager.getUsername(), rmManager.getPassword(), NODE_PREFIX + testFolder.getNodeRef(), ruleDefinition); - + assertStatusCode(CREATED); } @@ -159,6 +162,7 @@ public class FileVersionAsRecordRuleTest extends BaseRMRestTest { .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); rulesAPI.createRule(nonRMuser.getUsername(), nonRMuser.getPassword(), NODE_PREFIX + testFolder.getNodeRef(), ruleDefinition); + assertStatusCode(CREATED); } @@ -180,6 +184,7 @@ public class FileVersionAsRecordRuleTest extends BaseRMRestTest { .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); rulesAPI.createRule(nonRMuser.getUsername(), nonRMuser.getPassword(), NODE_PREFIX + inplaceRecord.getNodeRef(), ruleDefinition); + assertStatusCode(CREATED); STEP("Create as nonRMuser a new file into the previous folder in order to trigger the rule"); inPlaceRecord = dataContent.usingUser(nonRMuser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); From 183873166ccd115a1832c5d6d0dc2dadd061db10 Mon Sep 17 00:00:00 2001 From: cchandan Date: Wed, 16 Nov 2022 16:57:24 +0530 Subject: [PATCH 16/21] Added FileAsRecordRuleTests [ags] --- .../rules/FileAsRecordRuleTests.java | 58 ++++++++----------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java index dd7fa6e26a..3126ca53a9 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java @@ -33,16 +33,15 @@ import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; import org.alfresco.rest.rm.community.model.rules.RuleDefinition; +import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildEntry; import org.alfresco.rest.rm.community.model.user.UserRoles; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.FolderModel; +import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI; +import org.alfresco.utility.model.*; import org.alfresco.rest.v0.RulesAPI; import org.alfresco.rest.v0.service.RoleService; import org.alfresco.test.AlfrescoTest; -import org.alfresco.utility.model.SiteModel; -import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.AfterClass; @@ -50,15 +49,19 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; import static java.util.Arrays.asList; import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING; import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; import static org.alfresco.utility.data.RandomData.getRandomName; import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.CREATED; @AlfrescoTest (jira = "APPS-36") public class FileAsRecordRuleTests extends BaseRMRestTest @@ -100,7 +103,6 @@ public class FileAsRecordRuleTests extends BaseRMRestTest STEP("Create a collaboration site"); publicSite = dataSite.usingUser(nonRMUser).createPublicRandomSite(); - STEP("Create two categories with two folders"); category_manager = createRootCategory(CATEGORY_MANAGER); category_admin = createRootCategory(CATEGORY_ADMIN); @@ -120,6 +122,8 @@ public class FileAsRecordRuleTests extends BaseRMRestTest .applyToChildren(true) .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + + assertStatusCode(CREATED); } /** * Given I am a user that can create a rule on a folder in a collaboration site @@ -150,6 +154,8 @@ public class FileAsRecordRuleTests extends BaseRMRestTest .applyToChildren(true) .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + + assertStatusCode(CREATED); } /** * Given I am configuring a "Declare and File as Record" action within a rule @@ -173,39 +179,14 @@ public class FileAsRecordRuleTests extends BaseRMRestTest .applyToChildren(true) .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); - } - /** - * Given a record folder location has been selected for a "Declare and File as Record" action within a rule - * And I have permissions and capabilities to file to that record folder - * When I trigger the rule - * Then the file is filed directly to the selected record folder from the file plan - */ - @Test - public void triggerDeclareToRecordFolderRuleAsUserWithPermissions() - { - STEP("Create as rmManager a new file into the folderWithRule in order to trigger the rule"); - FileModel testFile = dataContent.usingUser(rmManager).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); - } - - /** - * Given a record folder location has been selected for a "Declare and File as Record" action within a rule - * And I don't have permissions and capabilities to file to that record folder - * When I trigger the rule - * Then the file is not declared as record - */ - - @Test - public void triggerDeclareToRecordFolderRuleAsUserWithoutPermissions() - { - STEP("Create as nonRMuser a new file into the folderWithRule in order to trigger the rule"); - FileModel testFile = dataContent.usingUser(nonRMUser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + assertStatusCode(CREATED); } /** * Given I have not selected a record folder location * When the rule is triggered - * Then the file is declared as record to the Unfiled Records folder + * Then the file is declared as record to the UnFiled Records folder */ @Test public void triggerDeclareToUnfiledRuleAsNonRMUser() @@ -214,14 +195,25 @@ public class FileAsRecordRuleTests extends BaseRMRestTest RecordCategory recordCategory = new RecordCategory().builder() .id(category_manager.getId()).build(); + RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") .applyToChildren(true) .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); - STEP("Create as nonRMuser a new file into the previous folder in order to trigger the rule"); + assertStatusCode(CREATED); + + STEP("Create as nonRMUser a new file into the previous folder in order to trigger the rule"); inPlaceRecord = dataContent.usingUser(nonRMUser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + +// Verify that declared record is in Unfilled Records Folder + UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI(); + List matchingRecords = unfiledContainersAPI.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS) + .getEntries() + .stream() + .filter(e -> e.getEntry().getId().equals(inPlaceRecord.getNodeRefWithoutVersion())) + .collect(Collectors.toList()); } @AfterClass(alwaysRun = true) From 24aa64c165ee114eac0dd7a6bb1b475308efd288 Mon Sep 17 00:00:00 2001 From: ashiva Date: Wed, 16 Nov 2022 13:55:47 +0000 Subject: [PATCH 17/21] "MoveToRuleOnFoldersTest initial changes made"[ags] --- .../rules/MoveToRuleOnFoldersTest.java | 66 +++++++------------ 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java index 5ed4228600..f25a811446 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java @@ -33,6 +33,7 @@ import org.alfresco.rest.rm.community.model.record.Record; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; +import org.alfresco.rest.rm.community.model.rules.ConditionsOnRule; import org.alfresco.rest.rm.community.model.rules.RuleDefinition; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer; import org.alfresco.rest.rm.community.model.user.UserRoles; @@ -71,11 +72,12 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ private String unfiledRecordsNodeRef; private RecordCategoryChild recordFolder2; + private String recordFolder1; private String nonElectronicId; private Record electronicRecord; private UnfiledContainer unfiledContainer; - + private String ruleType = ConditionsOnRule.UPDATE.getWhenConditionValue(); private UserModel rmAdmin; public RecordCategory RecordCategoryOne; public RestNodeModel RecordCategoryCopy; @@ -99,36 +101,30 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ @Autowired public RecordsAPI recordsAPI; + @BeforeClass(alwaysRun = true) public void precondition() { //create RM site createRMSiteIfNotExists(); rmAdmin = roleService.createUserWithRMRole(UserRoles.ROLE_RM_ADMIN.roleId); - /** - * Removes rules on File Plan and Unfiled Records - */ - final String holdName = TEST_PREFIX + "holdToBeDeleted"; - holdsAPI.deleteHold(rmAdmin.getUsername(), rmAdmin.getPassword(), holdName); - unfiledContainer = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS); - - unfiledRecordsNodeRef = NODE_PREFIX + unfiledContainer.getId(); - rulesAPI.deleteAllRulesOnContainer(getDataUser().usingAdmin().getAdminUser().getUsername(), - getDataUser().usingAdmin().getAdminUser().getPassword(), unfiledRecordsNodeRef); - //create root category, create folders , add electronic and non electronic records RecordCategoryOne = createRootCategory(RECORD_CATEGORY_ONE); - String recordFolder1 = createRecordFolder(RecordCategoryOne.getId(), getRandomName("recFolder")).getId(); - RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + recordFolder1 = createRecordFolder(RecordCategoryOne.getId(), getRandomName("recFolder")).getId(); + recordFolder2 = createFolder(getAdminUser(),RecordCategoryOne.getId(),getRandomName("recFolder")); + String CatName=RecordCategoryOne.getName(); + String folder2name=recordFolder2.getName(); + String recfolder2_path="/"+CatName+"/"+folder2name; + STEP("CREATE ELECTRONIC RECORD"); + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1, getFile(IMAGE_FILE)); STEP("Check the electronic record has been created"); assertStatusCode(CREATED); - STEP("Create a non-electronic record by completing some of the fields"); - // Use these properties for non-electronic record to be created + // Use these properties for non-electronic record to be created String title = "Title " + getRandomAlphanumeric(); String description = "Description " + getRandomAlphanumeric(); String box = "Box "+ getRandomAlphanumeric(); @@ -144,9 +140,17 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ Record nonElectrinicRecordModel = createFullNonElectronicRecordModel(name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize); // Create non-electronic record nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1).getId(); - STEP("Check the non-electronic record has been created"); + STEP("Check the non-electronic record has been created"); assertStatusCode(CREATED); + STEP("create a rule MOVE_TO for folder 1"); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1") + .runInBackground(true).title(title) + .actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())).ruleType(ruleType).path(recfolder2_path); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder1 , ruleDefinition); + + + STEP("Update metadata for Non-Electronic Record"); org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(); Record nonelecrecord = recordsAPI.getRecord(nonElectronicId); @@ -164,38 +168,16 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId()); assertStatusCode(OK); - STEP("Create the folder2 inside the rootCategory"); - recordFolder2 = createFolder(getAdminUser(),RecordCategoryOne.getId(),getRandomName("recFolder")); + STEP("CHECK IF E AND NON-E RECORDS MOVED TO FOLDER2"); + - STEP("create a rule MOVE_TO for folder 2"); - RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1") - .runInBackground(true).title(title) - .actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())); - rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder2.getId() , ruleDefinition); } @Test public void MoveToRuleFoldersTest() { - STEP("Move electronic record from folder1 to folder2"); - RestNodeModel electronicDocRestNodeModel = getRestAPIFactory() - .getNodeAPI(toContentModel(electronicRecord.getId())) - .move(createBodyForMoveCopy(recordFolder2.getId())); - assertStatusCode(OK); - - STEP("Move non-electronic record from folder1 to folder2"); - - RestNodeModel nonelectronicDocRestNodeModel = getRestAPIFactory() - .getNodeAPI(toContentModel(nonElectronicId)) - .move(createBodyForMoveCopy(recordFolder2.getId())); - assertStatusCode(OK); - - - STEP("Create Copy of RootRecord"); - FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS); - RecordCategoryCopy=getRestAPIFactory().getNodeAPI(toContentModel(RecordCategoryOne.getId())).copy(createBodyForMoveCopy(filePlan.getId())); - + System.out.println("PRECONDITION PASSED"); } @AfterClass(alwaysRun = true) From 2c979ea71e86daa4ef00dc3025ccacd8ed2e12a1 Mon Sep 17 00:00:00 2001 From: ashiva Date: Thu, 17 Nov 2022 11:57:09 +0000 Subject: [PATCH 18/21] "MoveToRuleOnFoldersTest Completed Refactor of code left"[ags] --- .../rules/MoveToRuleOnFoldersTest.java | 93 +++++++++++++++++-- 1 file changed, 84 insertions(+), 9 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java index f25a811446..c8b40c5ec5 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java @@ -36,8 +36,11 @@ import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; import org.alfresco.rest.rm.community.model.rules.ConditionsOnRule; import org.alfresco.rest.rm.community.model.rules.RuleDefinition; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer; +import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildEntry; import org.alfresco.rest.rm.community.model.user.UserRoles; import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; +import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI; +import org.alfresco.rest.search.RestRequestQueryModel; import org.alfresco.rest.v0.HoldsAPI; import org.alfresco.rest.v0.RecordsAPI; import org.alfresco.rest.v0.RulesAPI; @@ -48,8 +51,11 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.io.InputStream; import java.util.Collections; +import java.util.List; import java.util.Random; +import java.util.stream.Collectors; import static java.lang.Integer.MAX_VALUE; import static java.util.Arrays.asList; @@ -72,7 +78,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ private String unfiledRecordsNodeRef; private RecordCategoryChild recordFolder2; - private String recordFolder1; + private RecordCategoryChild recordFolder1; private String nonElectronicId; private Record electronicRecord; @@ -110,7 +116,8 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ rmAdmin = roleService.createUserWithRMRole(UserRoles.ROLE_RM_ADMIN.roleId); //create root category, create folders , add electronic and non electronic records RecordCategoryOne = createRootCategory(RECORD_CATEGORY_ONE); - recordFolder1 = createRecordFolder(RecordCategoryOne.getId(), getRandomName("recFolder")).getId(); + recordFolder1=createRecordFolder(RecordCategoryOne.getId(), getRandomName("recFolder")); + // recordFolder1_id = createRecordFolder(RecordCategoryOne.getId(), getRandomName("recFolder")).getId(); recordFolder2 = createFolder(getAdminUser(),RecordCategoryOne.getId(),getRandomName("recFolder")); String CatName=RecordCategoryOne.getName(); @@ -118,7 +125,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ String recfolder2_path="/"+CatName+"/"+folder2name; STEP("CREATE ELECTRONIC RECORD"); RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); - electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1, getFile(IMAGE_FILE)); + electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1.getId(), getFile(IMAGE_FILE)); STEP("Check the electronic record has been created"); assertStatusCode(CREATED); @@ -139,7 +146,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ // Set values of all available properties for the non electronic records Record nonElectrinicRecordModel = createFullNonElectronicRecordModel(name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize); // Create non-electronic record - nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1).getId(); + nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1.getId()).getId(); STEP("Check the non-electronic record has been created"); assertStatusCode(CREATED); @@ -147,7 +154,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1") .runInBackground(true).title(title) .actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())).ruleType(ruleType).path(recfolder2_path); - rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder1 , ruleDefinition); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder1.getId() , ruleDefinition); @@ -169,7 +176,79 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ assertStatusCode(OK); STEP("CHECK IF E AND NON-E RECORDS MOVED TO FOLDER2"); + //update the e and non-e records which have been moved to folder2 . if update is asserted as ok then record is present + STEP("Update metadata for Non-Electronic Record"); + nonelecrecord = recordsAPI.getRecord(nonElectronicId); + nonelecnewName = getModifiedPropertyValue(nonElectrinicRecordModel.getName()); + nonelecnewTitle = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getTitle()); + nonelecnewDescription = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getDescription()); + recordsAPI.updateRecord(createRecordModel(nonelecnewName, nonelecnewDescription, nonelecnewTitle),nonelecrecord.getId()); + assertStatusCode(OK); + STEP("Update metadata for Electronic Record"); + elecrecord = recordsAPI.getRecord(electronicRecord.getId()); + elecnewName = getModifiedPropertyValue(electronicRecord.getName()); + elecnewTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); + elecnewDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); + recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId()); + assertStatusCode(OK); + + STEP("Delete E and Non-E RECORDS IN FOLDER 2"); + recordsAPI.deleteRecord(electronicRecord.getId()); + assertStatusCode(NO_CONTENT); + recordsAPI.deleteRecord(nonElectronicId); + assertStatusCode(NO_CONTENT); + STEP("RULE CREATION FOR FOLDER 1 WITHOUT RUNNING IN BACKGROUND"); + + RuleDefinition ruleDefinition_notinbackground = RuleDefinition.createNewRule().title("name").description("description1") + .runInBackground(false).title(title) + .actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())).ruleType(ruleType).path(recfolder2_path); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder1.getId() , ruleDefinition); + + STEP("CREATE E AND NON E RECORDS"); + electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1.getId(), getFile(IMAGE_FILE)); + STEP("Check the electronic record has been created"); + assertStatusCode(CREATED); + nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1.getId()).getId(); + STEP("Check the non-electronic record has been created"); + assertStatusCode(CREATED); + + + STEP("UPDATE METADATA"); + STEP("Update metadata for Non-Electronic Record"); + + nonelecrecord = recordsAPI.getRecord(nonElectronicId); + nonelecnewName = getModifiedPropertyValue(nonElectrinicRecordModel.getName()); + nonelecnewTitle = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getTitle()); + nonelecnewDescription = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getDescription()); + recordsAPI.updateRecord(createRecordModel(nonelecnewName, nonelecnewDescription, nonelecnewTitle),nonelecrecord.getId()); + assertStatusCode(OK); + + STEP("Update metadata for Electronic Record"); + elecrecord = recordsAPI.getRecord(electronicRecord.getId()); + elecnewName = getModifiedPropertyValue(electronicRecord.getName()); + elecnewTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); + elecnewDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); + recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId()); + assertStatusCode(OK); + + STEP("CHECK IF E AND NON-E RECORDS MOVED TO FOLDER2"); + //update the e and non-e records which have been moved to folder2 . if update is asserted as ok then record is present + STEP("Update metadata for Non-Electronic Record"); + nonelecrecord = recordsAPI.getRecord(nonElectronicId); + nonelecnewName = getModifiedPropertyValue(nonElectrinicRecordModel.getName()); + nonelecnewTitle = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getTitle()); + nonelecnewDescription = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getDescription()); + recordsAPI.updateRecord(createRecordModel(nonelecnewName, nonelecnewDescription, nonelecnewTitle),nonelecrecord.getId()); + assertStatusCode(OK); + + STEP("Update metadata for Electronic Record"); + elecrecord = recordsAPI.getRecord(electronicRecord.getId()); + elecnewName = getModifiedPropertyValue(electronicRecord.getName()); + elecnewTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); + elecnewDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); + recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId()); + assertStatusCode(OK); } @@ -185,10 +264,6 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ { deleteRecordCategory(RecordCategoryOne.getId()); - // Delete record and verify status - -// recordsAPI.deleteRecord(RecordCategoryCopy.getName(),RecordCategoryCopy.); -// assertStatusCode(NO_CONTENT); getDataUser().deleteUser(rmAdmin); } From f03790e278b28bdd17b64b0d22024959739c59f1 Mon Sep 17 00:00:00 2001 From: ashiva Date: Thu, 17 Nov 2022 13:00:40 +0000 Subject: [PATCH 19/21] "MoveToRuleOnFoldersTest Completed With Creation of updateMetaData method and declration of variables to global scope"[ags] --- .../rules/MoveToRuleOnFoldersTest.java | 189 +++++++----------- 1 file changed, 75 insertions(+), 114 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java index c8b40c5ec5..719dda0af9 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java @@ -75,27 +75,28 @@ import static org.testng.Assert.assertNotNull; public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ - private String unfiledRecordsNodeRef; private RecordCategoryChild recordFolder2; private RecordCategoryChild recordFolder1; private String nonElectronicId; - private Record electronicRecord; - private UnfiledContainer unfiledContainer; + public Record electronicRecord; + private String ruleType = ConditionsOnRule.UPDATE.getWhenConditionValue(); private UserModel rmAdmin; public RecordCategory RecordCategoryOne; - public RestNodeModel RecordCategoryCopy; private RecordCategoryChild recordFolder; public static final String RECORD_FOLDER_ONE = "record-folder-one"; private final String TEST_PREFIX = generateTestPrefix(MoveToRuleOnFoldersTest.class); - // private final String RM_ADMIN = TEST_PREFIX + "rm_admin"; + private final String RECORD_CATEGORY_ONE = TEST_PREFIX + "category"; private final String recordName = "Test record"; private final String recordTitle = recordName + " title"; private final String recordDescription = recordName + " description"; + private Record nonElectrinicRecordModel; + private RecordFolderAPI recordFolderAPI; + public String title,description,box,file,shelf,storageLocation,name; @Autowired private RulesAPI rulesAPI; @Autowired @@ -120,11 +121,9 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ // recordFolder1_id = createRecordFolder(RecordCategoryOne.getId(), getRandomName("recFolder")).getId(); recordFolder2 = createFolder(getAdminUser(),RecordCategoryOne.getId(),getRandomName("recFolder")); - String CatName=RecordCategoryOne.getName(); - String folder2name=recordFolder2.getName(); - String recfolder2_path="/"+CatName+"/"+folder2name; + STEP("CREATE ELECTRONIC RECORD"); - RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1.getId(), getFile(IMAGE_FILE)); STEP("Check the electronic record has been created"); assertStatusCode(CREATED); @@ -132,24 +131,37 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ STEP("Create a non-electronic record by completing some of the fields"); // Use these properties for non-electronic record to be created - String title = "Title " + getRandomAlphanumeric(); - String description = "Description " + getRandomAlphanumeric(); - String box = "Box "+ getRandomAlphanumeric(); - String file = "File " + getRandomAlphanumeric(); - String shelf = "Shelf " + getRandomAlphanumeric(); - String storageLocation = "Storage Location " + getRandomAlphanumeric(); - String name = "Record " + getRandomAlphanumeric(); + title = "Title " + getRandomAlphanumeric(); + description = "Description " + getRandomAlphanumeric(); + box = "Box "+ getRandomAlphanumeric(); + file = "File " + getRandomAlphanumeric(); + shelf = "Shelf " + getRandomAlphanumeric(); + storageLocation = "Storage Location " + getRandomAlphanumeric(); + name = "Record " + getRandomAlphanumeric(); Random random = new Random(); Integer numberOfCopies = random.nextInt(MAX_VALUE); Integer physicalSize = random.nextInt(MAX_VALUE); // Set values of all available properties for the non electronic records - Record nonElectrinicRecordModel = createFullNonElectronicRecordModel(name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize); + nonElectrinicRecordModel = createFullNonElectronicRecordModel(name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize); // Create non-electronic record nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1.getId()).getId(); STEP("Check the non-electronic record has been created"); assertStatusCode(CREATED); + + + + } + + @Test + public void MoveToRuleFoldersTest() + { + + String CatName=RecordCategoryOne.getName(); + String folder2name=recordFolder2.getName(); + String recfolder2_path="/"+CatName+"/"+folder2name; + STEP("create a rule MOVE_TO for folder 1"); RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1") .runInBackground(true).title(title) @@ -158,6 +170,52 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ + STEP("Update metadata for Non-Electronic Record"); + updateRecordMetadata(); + + STEP("Delete E and Non-E RECORDS IN FOLDER 2"); + org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(); + recordsAPI.deleteRecord(electronicRecord.getId()); + assertStatusCode(NO_CONTENT); + recordsAPI.deleteRecord(nonElectronicId); + assertStatusCode(NO_CONTENT); + + STEP("RULE CREATION FOR FOLDER 1 WITHOUT RUNNING IN BACKGROUND"); + + RuleDefinition ruleDefinition_notinbackground = RuleDefinition.createNewRule().title("name").description("description1") + .runInBackground(false).title(title) + .actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())).ruleType(ruleType).path(recfolder2_path); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder1.getId() , ruleDefinition); + + STEP("CREATE E AND NON E RECORDS"); + electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1.getId(), getFile(IMAGE_FILE)); + STEP("Check the electronic record has been created"); + assertStatusCode(CREATED); + nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1.getId()).getId(); + STEP("Check the non-electronic record has been created"); + assertStatusCode(CREATED); + + STEP("UPDATE METADATA"); + updateRecordMetadata(); + + STEP("CHECK IF E AND NON-E RECORDS MOVED TO FOLDER2"); + updateRecordMetadata(); + } + + @AfterClass(alwaysRun = true) + public void cleanMoveToRuleOnFoldersTest() + { + deleteRecordCategory(RecordCategoryOne.getId()); + + getDataUser().deleteUser(rmAdmin); + } + + private String getModifiedPropertyValue(String originalValue) { + /* to be used to append to modifications */ + String MODIFIED_PREFIX = "modified_"; + return MODIFIED_PREFIX + originalValue; + } + private void updateRecordMetadata(){ STEP("Update metadata for Non-Electronic Record"); org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(); Record nonelecrecord = recordsAPI.getRecord(nonElectronicId); @@ -174,103 +232,6 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ String elecnewDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId()); assertStatusCode(OK); - - STEP("CHECK IF E AND NON-E RECORDS MOVED TO FOLDER2"); - //update the e and non-e records which have been moved to folder2 . if update is asserted as ok then record is present - STEP("Update metadata for Non-Electronic Record"); - nonelecrecord = recordsAPI.getRecord(nonElectronicId); - nonelecnewName = getModifiedPropertyValue(nonElectrinicRecordModel.getName()); - nonelecnewTitle = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getTitle()); - nonelecnewDescription = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getDescription()); - recordsAPI.updateRecord(createRecordModel(nonelecnewName, nonelecnewDescription, nonelecnewTitle),nonelecrecord.getId()); - assertStatusCode(OK); - - STEP("Update metadata for Electronic Record"); - elecrecord = recordsAPI.getRecord(electronicRecord.getId()); - elecnewName = getModifiedPropertyValue(electronicRecord.getName()); - elecnewTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); - elecnewDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); - recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId()); - assertStatusCode(OK); - - STEP("Delete E and Non-E RECORDS IN FOLDER 2"); - recordsAPI.deleteRecord(electronicRecord.getId()); - assertStatusCode(NO_CONTENT); - recordsAPI.deleteRecord(nonElectronicId); - assertStatusCode(NO_CONTENT); - STEP("RULE CREATION FOR FOLDER 1 WITHOUT RUNNING IN BACKGROUND"); - - RuleDefinition ruleDefinition_notinbackground = RuleDefinition.createNewRule().title("name").description("description1") - .runInBackground(false).title(title) - .actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())).ruleType(ruleType).path(recfolder2_path); - rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder1.getId() , ruleDefinition); - - STEP("CREATE E AND NON E RECORDS"); - electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1.getId(), getFile(IMAGE_FILE)); - STEP("Check the electronic record has been created"); - assertStatusCode(CREATED); - nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1.getId()).getId(); - STEP("Check the non-electronic record has been created"); - assertStatusCode(CREATED); - - - STEP("UPDATE METADATA"); - STEP("Update metadata for Non-Electronic Record"); - - nonelecrecord = recordsAPI.getRecord(nonElectronicId); - nonelecnewName = getModifiedPropertyValue(nonElectrinicRecordModel.getName()); - nonelecnewTitle = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getTitle()); - nonelecnewDescription = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getDescription()); - recordsAPI.updateRecord(createRecordModel(nonelecnewName, nonelecnewDescription, nonelecnewTitle),nonelecrecord.getId()); - assertStatusCode(OK); - - STEP("Update metadata for Electronic Record"); - elecrecord = recordsAPI.getRecord(electronicRecord.getId()); - elecnewName = getModifiedPropertyValue(electronicRecord.getName()); - elecnewTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); - elecnewDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); - recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId()); - assertStatusCode(OK); - - STEP("CHECK IF E AND NON-E RECORDS MOVED TO FOLDER2"); - //update the e and non-e records which have been moved to folder2 . if update is asserted as ok then record is present - STEP("Update metadata for Non-Electronic Record"); - nonelecrecord = recordsAPI.getRecord(nonElectronicId); - nonelecnewName = getModifiedPropertyValue(nonElectrinicRecordModel.getName()); - nonelecnewTitle = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getTitle()); - nonelecnewDescription = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getDescription()); - recordsAPI.updateRecord(createRecordModel(nonelecnewName, nonelecnewDescription, nonelecnewTitle),nonelecrecord.getId()); - assertStatusCode(OK); - - STEP("Update metadata for Electronic Record"); - elecrecord = recordsAPI.getRecord(electronicRecord.getId()); - elecnewName = getModifiedPropertyValue(electronicRecord.getName()); - elecnewTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle()); - elecnewDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription()); - recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId()); - assertStatusCode(OK); - - - } - - @Test - public void MoveToRuleFoldersTest() - { - System.out.println("PRECONDITION PASSED"); - } - - @AfterClass(alwaysRun = true) - public void cleanMoveToRuleOnFoldersTest() - { - deleteRecordCategory(RecordCategoryOne.getId()); - - getDataUser().deleteUser(rmAdmin); - } - - private String getModifiedPropertyValue(String originalValue) { - /* to be used to append to modifications */ - String MODIFIED_PREFIX = "modified_"; - return MODIFIED_PREFIX + originalValue; } } From e39a97ed8d4db80cca1225625bdb198b9c87a173 Mon Sep 17 00:00:00 2001 From: ashiva Date: Tue, 22 Nov 2022 06:07:53 +0000 Subject: [PATCH 20/21] "MoveToRuleOnFoldersTest changed names from E and NE to ELECTRONIC AND NON-ELECTRONIC RECORDS"[ags] --- .../rest/rm/community/rules/MoveToRuleOnFoldersTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java index 719dda0af9..8babe414bd 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/MoveToRuleOnFoldersTest.java @@ -173,7 +173,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ STEP("Update metadata for Non-Electronic Record"); updateRecordMetadata(); - STEP("Delete E and Non-E RECORDS IN FOLDER 2"); + STEP("Delete ELECTRONIC AND NON-ELECTRONIC RECORDS IN FOLDER 2"); org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(); recordsAPI.deleteRecord(electronicRecord.getId()); assertStatusCode(NO_CONTENT); @@ -187,7 +187,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ .actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())).ruleType(ruleType).path(recfolder2_path); rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder1.getId() , ruleDefinition); - STEP("CREATE E AND NON E RECORDS"); + STEP("CREATE ELECTRONIC AND NON-ELECTRONIC RECORDS"); electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1.getId(), getFile(IMAGE_FILE)); STEP("Check the electronic record has been created"); assertStatusCode(CREATED); @@ -198,7 +198,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{ STEP("UPDATE METADATA"); updateRecordMetadata(); - STEP("CHECK IF E AND NON-E RECORDS MOVED TO FOLDER2"); + STEP("CHECK IF ELECTRONIC AND NON-ELECTRONIC RECORDS MOVED TO FOLDER2"); updateRecordMetadata(); } From 5c8db99231bc338c7862626802d3f5b0a90d7604 Mon Sep 17 00:00:00 2001 From: sbisht Date: Tue, 22 Nov 2022 11:53:37 +0530 Subject: [PATCH 21/21] updated FileVersionAsRecordRuleTest and FileAsRecordRuleTest [ags] --- .../rules/FileAsRecordRuleTests.java | 49 +++++++++---------- .../rules/FileVersionAsRecordRuleTest.java | 7 +-- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java index 3126ca53a9..ec14dbdc4c 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileAsRecordRuleTests.java @@ -37,28 +37,25 @@ import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChi import org.alfresco.rest.rm.community.model.user.UserRoles; import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI; -import org.alfresco.utility.model.*; - +import org.alfresco.rest.rm.community.smoke.FileAsRecordTests; import org.alfresco.rest.v0.RulesAPI; import org.alfresco.rest.v0.service.RoleService; import org.alfresco.test.AlfrescoTest; - +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; - import java.util.Collections; import java.util.List; import java.util.stream.Collectors; - -import static java.util.Arrays.asList; import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING; import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; - import static org.alfresco.utility.data.RandomData.getRandomName; import static org.alfresco.utility.report.log.Step.STEP; import static org.springframework.http.HttpStatus.CREATED; @@ -66,18 +63,17 @@ import static org.springframework.http.HttpStatus.CREATED; @AlfrescoTest (jira = "APPS-36") public class FileAsRecordRuleTests extends BaseRMRestTest { - private static final String CATEGORY_MANAGER = "categoryManager" + generateTestPrefix(FileAsRecordRuleTests.class); - private static final String CATEGORY_ADMIN = "categoryAdmin" + generateTestPrefix(FileAsRecordRuleTests.class); - private static final String FOLDER_MANAGER = "recordFolder" + generateTestPrefix(FileAsRecordRuleTests.class); - private static final String FOLDER_ADMIN = "recordFolder" + generateTestPrefix(FileAsRecordRuleTests.class); - private UserModel nonRMUser,rmManager; - private SiteModel publicSite; + private UserModel nonRMUser, rmManager; + private RecordCategory category_manager, category_admin; + private RecordCategoryChild folder_admin, folder_manager ; + private static final String CATEGORY_MANAGER = "catManager" + generateTestPrefix(FileAsRecordTests.class); + private static final String CATEGORY_ADMIN = "catAdmin" + generateTestPrefix(FileAsRecordTests.class); + private static final String FOLDER_MANAGER = "recordFolder" + generateTestPrefix(FileAsRecordTests.class); + private static final String FOLDER_ADMIN = "recordFolder" + generateTestPrefix(FileAsRecordTests.class); private FolderModel testFolder; - private FileModel inPlaceRecord; - private RecordCategory category_manager,category_admin; - private RecordCategoryChild folder_admin,folder_manager; - private static final String RULE_NAME = "File as Record Rule"; - private static final String FOLDER_MANAGER_PATH = "/" + CATEGORY_MANAGER + "/" + FOLDER_MANAGER; + private FileModel document,inPlaceRecord; + + @Autowired private RoleService roleService; @Autowired @@ -101,7 +97,7 @@ public class FileAsRecordRuleTests extends BaseRMRestTest nonRMUser = dataUser.createRandomTestUser("testUser"); STEP("Create a collaboration site"); - publicSite = dataSite.usingUser(nonRMUser).createPublicRandomSite(); + testSite = dataSite.usingUser(nonRMUser).createPublicRandomSite(); STEP("Create two categories with two folders"); category_manager = createRootCategory(CATEGORY_MANAGER); @@ -113,7 +109,7 @@ public class FileAsRecordRuleTests extends BaseRMRestTest RecordCategory recordCategory = new RecordCategory().builder() .id(category_manager.getId()).build(); - rmManager = roleService.createCollaboratorWithRMRoleAndPermission(publicSite, recordCategory, + rmManager = roleService.createCollaboratorWithRMRoleAndPermission(testSite, recordCategory, UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); STEP("Create a collaboration folder with a rule set to declare and file as record to a record folder"); @@ -142,7 +138,7 @@ public class FileAsRecordRuleTests extends BaseRMRestTest @Test public void declareAsRecordRuleAsRMUserWithFilingPermissions() { STEP("Create a collaboration folder"); - testFolder = dataContent.usingSite(publicSite) + testFolder = dataContent.usingSite(testSite) .usingUser(rmManager) .createFolder(); @@ -167,18 +163,18 @@ public class FileAsRecordRuleTests extends BaseRMRestTest public void declareAsRecordRuleAsNonRMUser() { STEP("Create a collaboration folder"); - testFolder = dataContent.usingSite(publicSite) - .usingUser(rmManager) + testFolder = dataContent.usingSite(testSite) + .usingUser(nonRMUser) .createFolder(); STEP("Create a rule with Declare as Record action and check that user can select a record folder."); RecordCategory recordCategory = new RecordCategory().builder() .id(category_manager.getId()).build(); - RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder")); + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") .applyToChildren(true) .actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue())); - rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition); + rulesAPI.createRule(nonRMUser.getUsername(), nonRMUser.getPassword(), NODE_PREFIX + testFolder.getNodeRef(), ruleDefinition); assertStatusCode(CREATED); } @@ -220,7 +216,7 @@ public class FileAsRecordRuleTests extends BaseRMRestTest public void cleanupDeclareAsRecordRuleTests() { STEP("Delete the collaboration site"); - dataSite.usingUser(nonRMUser).deleteSite(publicSite); + dataSite.usingUser(nonRMUser).deleteSite(testSite); STEP("Delete Users"); dataUser.deleteUser(nonRMUser); @@ -229,6 +225,5 @@ public class FileAsRecordRuleTests extends BaseRMRestTest STEP("Delete categories"); getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry -> deleteRecordCategory(recordCategoryEntry.getEntry().getId())); - getRestAPIFactory().getRecordsAPI().deleteRecord(inPlaceRecord.getNodeRefWithoutVersion()); } } \ No newline at end of file diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java index 3ed3f4c115..208d1686e5 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rules/FileVersionAsRecordRuleTest.java @@ -38,9 +38,11 @@ import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI; import org.alfresco.rest.rm.community.smoke.FileAsRecordTests; import org.alfresco.rest.v0.RulesAPI; import org.alfresco.rest.v0.service.RoleService; -import org.alfresco.utility.model.*; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -57,7 +59,6 @@ import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPr import static org.alfresco.utility.data.RandomData.getRandomName; import static org.alfresco.utility.report.log.Step.STEP; import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.OK; public class FileVersionAsRecordRuleTest extends BaseRMRestTest {