diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java index 04b321664b..2d2807a9ed 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordFoldersAPI.java @@ -74,4 +74,27 @@ public class RecordFoldersAPI extends BaseAPI return null; } + public HttpResponse postFolderAction(String user, String password, JSONObject requestParams, String recordFolder) { + String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordFolder); + try { + requestParams.put("nodeRef", recNodeRef); + return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API); + } + catch (Exception error) { + LOGGER.error("Unable to extract response parameter", error); + } + return null; + } + + public HttpResponse postRecordAction(String user, String password, JSONObject requestParams, String recordId) { + try { + requestParams.put("nodeRef", recordId); + return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API); + } + catch (JSONException error) { + LOGGER.error("Unable to extract response parameter", error); + } + return null; + } + } diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java index ac2f98da76..560a39b4c8 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java @@ -53,9 +53,12 @@ import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.Date; +import java.util.TimeZone; import java.util.stream.Collectors; import lombok.Getter; @@ -91,6 +94,7 @@ 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.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; @@ -121,6 +125,8 @@ public class BaseRMRestTest extends RestTest @Getter(value = PROTECTED) private SearchAPI searchApi; + protected static final String iso8601_DateFormat="yyyy-MM-dd'T'HH:mm:ss.SSSXXX"; + /** * Asserts the given status code * @@ -628,8 +634,8 @@ public class BaseRMRestTest extends RestTest * Returns search results for the given search term * * @param user - * @param term - * @param query language + * @param q + * @param queryLanguage language * @return * @throws Exception */ @@ -956,5 +962,34 @@ public class BaseRMRestTest extends RestTest return false; } } + /** + * Helper method to get the Previous Date in the YYYY-MM-ddTHH:mm:ss.SSSXXX format + * @param previousDays number of previous days while calculating the date as output + * @return previousDate as String in the ISO 8601 Date Format + */ + protected String getIso8601Date(int previousDays) { + Date date = new Date(System.currentTimeMillis()); + Date previousDate = new Date(date.getTime() - previousDays); + // Conversion + SimpleDateFormat sdf= new SimpleDateFormat(iso8601_DateFormat);; + sdf.setTimeZone(TimeZone.getDefault()); + return sdf.format(previousDate); + } + /** + * Helper method to provide the Edited Disposition Date Json + * The Edited Disposition Date is modified to previous date so that CUTOFF & DESTROY Steps will be enabled + * @return JsonObject with the format {"name":"editDispositionActionAsOfDate","params":{"asOfDate":{"iso8601":"Previous Date"}}} + */ + protected JSONObject editDispositionDateJson() { + JSONObject requestParams = new JSONObject(); + requestParams.put("name","editDispositionActionAsOfDate"); + JSONObject params = new JSONObject(); + requestParams.put("params",params); + + JSONObject asOfDate = new JSONObject(); + params.put("asOfDate",asOfDate); + asOfDate.put("iso8601",getIso8601Date(1)); + return requestParams; + } } diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/AuditAccessTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/AuditAccessTests.java new file mode 100644 index 0000000000..f2ad183915 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/AuditAccessTests.java @@ -0,0 +1,211 @@ +/* + * #%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.smoke; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.core.v0.BaseAPI; +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.audit.AuditEntry; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; +import org.alfresco.rest.v0.RMRolesAndActionsAPI; +import org.alfresco.rest.v0.RecordsAPI; +import org.alfresco.rest.v0.service.RMAuditService; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.model.UserModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX; +import static org.alfresco.rest.core.v0.BaseAPI.RM_SITE_ID; +import static org.alfresco.rest.rm.community.model.audit.AuditEvents.DELETE_PERSON; +import static org.alfresco.rest.rm.community.model.audit.AuditEvents.LOGIN_SUCCESSFUL; +import static org.alfresco.rest.rm.community.records.SearchRecordsTests.*; +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; +import static org.junit.Assert.assertFalse; +import static org.testng.AssertJUnit.assertTrue; + +/** + * Audit Access tests + * @author Kavit Shah + */ +public class AuditAccessTests extends BaseRMRestTest { + + private Optional deletedUser; + private final String TEST_PREFIX = generateTestPrefix(AuditAccessTests.class); + private static final String DELETE_USER_EVENT = "Delete User"; + private final String record1 = TEST_PREFIX + "RM-2967 uploaded record"; + private final String classifiedRecord = TEST_PREFIX + "RM-2967 classified record"; + private final String folderName = TEST_PREFIX + "RM-2967 folder"; + private final String categoryName = TEST_PREFIX + "RM-2967 category"; + private final String editedCategoryName = "edited " + categoryName; + private final String editedFolderName = "edited " + folderName; + private final String editedRecordName = "edited " + record1; + private final String login_successfull = "Login Successful"; + private RecordCategory categoryAll; + + @Autowired + private RMRolesAndActionsAPI rmRolesAndActionsAPI; + @Autowired + private RecordsAPI recordsAPI; + @Autowired + private RMAuditService rmAuditService; + + @Test(priority = 1) + @AlfrescoTest(jira = "RM-2967") + public void deleteRMUsersShowFullAuditTest() { + + createTestPrecondition(); + updateCategoryMetadata(); + updateFolderMetadata(); + updateRecordMetadata(); + + // delete record category and folder with rm_admin_deleted + rmRolesAndActionsAPI.deleteAllItemsInContainer(deletedUser.get().getUsername(), deletedUser.get().getPassword(), + RM_SITE_ID, editedFolderName); + rmRolesAndActionsAPI.deleteAllItemsInContainer(deletedUser.get().getUsername(), deletedUser.get().getPassword(), + RM_SITE_ID, editedCategoryName); + + // delete the user + Optional.of(deletedUser).ifPresent(x -> getDataUser().deleteUser(x.get())); + + //check for RM-5235 fix + List auditEntries = rmAuditService.getAuditEntriesFilteredByEvent(getDataUser().usingAdmin().getAdminUser(), + DELETE_PERSON); + + assertTrue("Delete user event not found in the audit log.", auditEntries.stream().anyMatch( + auditEntry -> auditEntry.getEvent().equals(DELETE_USER_EVENT))); + } + + + @Test(priority = 2) + public void filterEventsByLoginSuccessful() + { + createRMSiteIfNotExists(); + List auditEntries = rmAuditService.getAuditEntriesFilteredByEvent(getDataUser().usingAdmin().getAdminUser(), + LOGIN_SUCCESSFUL); + + assertFalse("Audit results should contain at least one Login Successful event", + auditEntries.isEmpty()); + + assertTrue("Audit results contain only Login Successful events", + auditEntries.stream() + .allMatch(e -> e.getEvent().startsWith(LOGIN_SUCCESSFUL.toString()) || e.getEvent().startsWith(login_successfull))); + } + /** + * Creates the required precondition for the test + *

+ * See Precondition in current class JavaDoc + */ + private void createTestPrecondition() { + createRMSiteIfNotExists(); + + // create "rm deleted user" user if it does not exist and assign it to RM Administrator role + createDeletedUser(); + + // create category and folder + categoryAll = createCategoryIfDoesNotExist(categoryName,deletedUser.get()); + createRecordFolderInCategory(folderName,categoryAll,deletedUser.get()); + // upload an electronic record + + recordsAPI.uploadElectronicRecord(deletedUser.get().getUsername(), deletedUser.get().getPassword(), getDefaultElectronicRecordProperties(record1), folderName, CMISUtil.DocumentType.TEXT_PLAIN); + // upload another electronic record and classify it + recordsAPI.uploadElectronicRecord(deletedUser.get().getUsername(), deletedUser.get().getPassword(), getDefaultElectronicRecordProperties(classifiedRecord), folderName, CMISUtil.DocumentType.TEXT_PLAIN); + } + + private void createDeletedUser() { + // create Deleted User + deletedUser = Optional.ofNullable(getDataUser().createRandomTestUser()); + rmRolesAndActionsAPI.assignRoleToUser( + getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), + deletedUser.get().getUsername(), + ADMIN + ); + } + + private void updateCategoryMetadata() { + HashMap categoryProperties = new HashMap<>(); + categoryProperties.put(BaseAPI.RMProperty.NAME, editedCategoryName); + categoryProperties.put(BaseAPI.RMProperty.TITLE, "edited " + TITLE); + categoryProperties.put(BaseAPI.RMProperty.DESCRIPTION, "edited " + DESCRIPTION); + + // edit some category's properties + String categoryNodeRef = NODE_PREFIX + rmRolesAndActionsAPI.getItemNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), "/" + categoryName); + rmRolesAndActionsAPI.updateMetadata(deletedUser.get().getUsername(), deletedUser.get().getPassword(), categoryNodeRef, categoryProperties); + } + + private void updateFolderMetadata() { + HashMap folderProperties = new HashMap<>(); + folderProperties.put(BaseAPI.RMProperty.NAME, editedFolderName); + folderProperties.put(BaseAPI.RMProperty.TITLE, "edited " + TITLE); + folderProperties.put(BaseAPI.RMProperty.DESCRIPTION, "edited " + DESCRIPTION); + + // edit some folder's properties + String folderNodeRef = NODE_PREFIX + rmRolesAndActionsAPI.getItemNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), "/" + editedCategoryName + "/" + folderName); + rmRolesAndActionsAPI.updateMetadata(deletedUser.get().getUsername(), deletedUser.get().getPassword(), folderNodeRef, folderProperties); + } + + private void updateRecordMetadata() { + HashMap recordProperties = new HashMap<>(); + recordProperties.put(BaseAPI.RMProperty.NAME, editedRecordName); + recordProperties.put(BaseAPI.RMProperty.TITLE, "edited " + TITLE); + recordProperties.put(BaseAPI.RMProperty.AUTHOR, "edited author"); + recordProperties.put(BaseAPI.RMProperty.DESCRIPTION, "edited " + DESCRIPTION); + + // edit some record's properties + String recordName = recordsAPI.getRecordFullName(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), editedFolderName, record1); + String recordNodeRef = NODE_PREFIX + rmRolesAndActionsAPI.getItemNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), "/" + editedCategoryName + "/" + editedFolderName + "/" + recordName); + rmRolesAndActionsAPI.updateMetadata(deletedUser.get().getUsername(), deletedUser.get().getPassword(), recordNodeRef, recordProperties); + } + + + private RecordCategory createCategoryIfDoesNotExist(String CATEGORY_ALL, UserModel deletedUser) { + return createRootCategory(deletedUser, CATEGORY_ALL); + } + + private RecordCategoryChild createRecordFolderInCategory(String FOLDER_SEARCH, RecordCategory recordCategory, UserModel deletedUser) { + return createFolder(deletedUser, recordCategory.getId(), FOLDER_SEARCH); + } + + private Map getDefaultElectronicRecordProperties(String recordName) { + Map defaultProperties = new HashMap<>(); + defaultProperties.put(BaseAPI.RMProperty.NAME, recordName); + defaultProperties.put(BaseAPI.RMProperty.TITLE, TITLE); + defaultProperties.put(BaseAPI.RMProperty.DESCRIPTION, DESCRIPTION); + defaultProperties.put(BaseAPI.RMProperty.CONTENT, TEST_CONTENT); + return defaultProperties; + } +} diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/BasicRulesIntegrationTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/BasicRulesIntegrationTests.java new file mode 100644 index 0000000000..b8224a31e9 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/BasicRulesIntegrationTests.java @@ -0,0 +1,104 @@ +/* + * #%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.smoke; +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.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.v0.RMRolesAndActionsAPI; +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.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 BasicRulesIntegrationTests extends BaseRMRestTest { + + @Autowired + private RMRolesAndActionsAPI rmRolesAndActionsAPI; + private final static String title = "Rule to complete"; + private final static String description = "Rule to describe"; + private final String TEST_PREFIX = generateTestPrefix(CreateCategoriesTests.class); + private final String RM_ADMIN = TEST_PREFIX + "rm_admin"; + @Autowired + private RulesAPI rulesAPI; + + @Test + @AlfrescoTest(jira = "RM-2794") + public void basicRulesIntegration() { + + + STEP("Create the RM site if doesn't exist"); + createRMSiteIfNotExists(); + + STEP("Create RM Admin user"); + rmRolesAndActionsAPI.createUserAndAssignToRole(getAdminUser().getUsername(), getAdminUser().getPassword(), RM_ADMIN, + getAdminUser().getPassword(), + "Administrator"); + + STEP("Create record categories and record folders"); + RecordCategory Category = createRootCategory(getRandomName("recordCategory")); + String recordFolder1 = createRecordFolder(Category.getId(), getRandomName("recFolder")).getId(); + + + //create a rule for completing a record + 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 + Category.getId(), ruleDefinition); + + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + + //create two electronic record in record folder + String electronicRecordId1 = createElectronicRecord(recordFolder1, ELECTRONIC_RECORD_NAME).getId(); + String electronicRecordId2 = createElectronicRecord(recordFolder1, ELECTRONIC_RECORD_NAME).getId(); + assertStatusCode(CREATED); + + + + // Update the rules for record Category + rulesAPI.updateRule(getAdminUser().getUsername(), getAdminUser().getPassword(), + NODE_PREFIX + Category.getId(), ruleDefinition.description("description").id(description)); + + //Delete the root category and rules + deleteRecordCategory(Category.getId()); + rulesAPI.deleteAllRulesOnContainer(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + Category.getId()); + } + + +} diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/CreateCategoriesTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/CreateCategoriesTests.java new file mode 100644 index 0000000000..38a0e111ad --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/CreateCategoriesTests.java @@ -0,0 +1,125 @@ +/* + * #%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.smoke; + +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.fileplan.FilePlan; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; +import org.alfresco.rest.v0.RMRolesAndActionsAPI; +import org.alfresco.test.AlfrescoTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_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.utility.data.RandomData.getRandomAlphanumeric; +import static org.alfresco.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.junit.Assert.assertFalse; +import static org.springframework.http.HttpStatus.OK; +import static org.testng.Assert.assertEquals; + +public class CreateCategoriesTests extends BaseRMRestTest { + + @Autowired + private RMRolesAndActionsAPI rmRolesAndActionsAPI; + private RecordCategory rootCategory; + private final String TEST_PREFIX = generateTestPrefix(CreateCategoriesTests.class); + private final String RM_ADMIN = TEST_PREFIX + "rm_admin"; + private RecordCategory Category1; + private RecordCategory Category2; + private RecordCategory SubCategory1; + private RecordCategory SubCategory2; + + @BeforeClass(alwaysRun = true) + public void preconditionForCreateCategoriesTests() + { + STEP("Create the RM site if doesn't exist"); + createRMSiteIfNotExists(); + + STEP("Create RM Admin user"); + rmRolesAndActionsAPI.createUserAndAssignToRole(getAdminUser().getUsername(), getAdminUser().getPassword(), RM_ADMIN, + getAdminUser().getPassword(), + "Administrator"); + + STEP("Create two category"); + Category1 = createRootCategory(getRandomName("Category1")); + + Category2= createRootCategory(getRandomName("Category2")); + + STEP("Create Sub category"); + RecordCategoryChild subCategory1 = createRecordCategory(Category1.getId(), getRandomName("subCategory1")); + RecordCategoryChild subCategory2 = createRecordCategory(Category2.getId(), getRandomName("subCategory2")); + + } + + + @Test @AlfrescoTest(jira = "RM-2756") + public void createCategories() throws Exception { + + FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS); + + STEP("copy category 1 to File Plan."); + getRestAPIFactory().getNodeAPI(toContentModel(Category1.getId())).copy(createBodyForMoveCopy(filePlan.getId())); + + STEP("copy category 1 to category 2"); + getRestAPIFactory().getNodeAPI(toContentModel(Category1.getId())).copy(createBodyForMoveCopy(Category2.getId())); + + String categoryName = "Category name " + getRandomAlphanumeric(); + String categoryTitle = "Category title " + getRandomAlphanumeric(); + + + // Create the root record category + RecordCategory Category1 = createRootCategory(categoryName, categoryTitle); + + String newCategoryName = "Rename " + categoryName; + + // Build the properties which will be updated + RecordCategory recordCategoryUpdated = Category1.builder().name(newCategoryName).build(); + + // Update the record category + RecordCategory renamedRecordCategory = getRestAPIFactory().getRecordCategoryAPI().updateRecordCategory(recordCategoryUpdated,Category1.getId()); + // Verify the status code + assertStatusCode(OK); + + // verify renamed component and editTitle component still has this parent + assertEquals(renamedRecordCategory.getParentId(), filePlan.getId()); + + STEP("move category 1 edited copy to File Plan"); + getRestAPIFactory().getNodeAPI(toContentModel(renamedRecordCategory.getId())).move(createBodyForMoveCopy(filePlan.getId())); + assertStatusCode(OK); + + // delete All the categories + deleteRecordCategory(Category1.getId()); + deleteRecordCategory(Category2.getId()); + } +} \ 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/smoke/CreateFoldersTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/CreateFoldersTests.java new file mode 100644 index 0000000000..35335584d9 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/CreateFoldersTests.java @@ -0,0 +1,147 @@ +/* + * #%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.smoke; + +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.common.ReviewPeriod; +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.recordfolder.RecordFolder; +import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderProperties; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; +import org.alfresco.rest.v0.RMRolesAndActionsAPI; +import org.alfresco.test.AlfrescoTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +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.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.*; + +public class CreateFoldersTests extends BaseRMRestTest { + + @Autowired + private RMRolesAndActionsAPI rmRolesAndActionsAPI; + + private final String TEST_PREFIX = generateTestPrefix(CreateCategoriesTests.class); + private final String RM_ADMIN = TEST_PREFIX + "rm_admin"; + private RecordCategory Category1; + private RecordCategory Category2; + private RecordCategoryChild recordCategoryChild; + + @BeforeClass(alwaysRun = true) + public void preconditionForCreateFolderTests() { + STEP("Create the RM site if doesn't exist"); + createRMSiteIfNotExists(); + + STEP("Create RM Admin user"); + rmRolesAndActionsAPI.createUserAndAssignToRole(getAdminUser().getUsername(), getAdminUser().getPassword(), RM_ADMIN, + getAdminUser().getPassword(), + "Administrator"); + + STEP("Create two category"); + Category1 = createRootCategory(getRandomName("Category1")); + + Category2 = createRootCategory(getRandomName("Category2")); + + // Create a record folder inside the category 1 + recordCategoryChild = createRecordFolder(Category1.getId(), getRandomName("recFolder")); + + } + + @Test + @AlfrescoTest(jira = "RM-2757") + public void createFolders() throws Exception { + + // Create record category first + String folderDescription = "The folder description is updated" + getRandomAlphanumeric(); + String folderName = "The folder name is updated" + getRandomAlphanumeric(); + String folderTitle = "Update title " + getRandomAlphanumeric(); + String location = "Location "+ getRandomAlphanumeric(); + + // Create the record folder properties to update + RecordFolder recordFolder = RecordFolder.builder() + .name(folderName) + .properties(RecordFolderProperties.builder() + .title(folderTitle) + .description(folderDescription) + .vitalRecordIndicator(true) + .reviewPeriod(new ReviewPeriod("month","1")) + .location(location) + .build()) + .build(); + + // Update the record folder + RecordFolder updatedRecordFolder = getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(recordFolder, recordCategoryChild.getId()); + + // Check the Response Status Code + assertStatusCode(OK); + + STEP("copy updated Record in category 1 and category 2"); + getRestAPIFactory().getNodeAPI(toContentModel(updatedRecordFolder.getId())).copy(createBodyForMoveCopy(Category1.getId())); + //assertStatusCode(OK); + getRestAPIFactory().getNodeAPI(toContentModel(updatedRecordFolder.getId())).copy(createBodyForMoveCopy(Category2.getId())); + //assertStatusCode(OK); + + + // Delete the Updated folder + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + String recordFolderId = updatedRecordFolder.getId(); + recordFolderAPI.deleteRecordFolder(recordFolderId); + + // Check the response status code + assertStatusCode(NO_CONTENT); + + // Check the record folder is not found + recordFolderAPI.getRecordFolder(recordFolderId); + + // Check the response status code + assertStatusCode(NOT_FOUND); + + STEP("move updated Record from category 1 to category 2"); + getRestAPIFactory().getNodeAPI(toContentModel(updatedRecordFolder.getId())).move(createBodyForMoveCopy(Category2.getId())); + + // move category 2 to category 1 + getRestAPIFactory().getNodeAPI(toContentModel(Category2.getId())).move(createBodyForMoveCopy(Category1.getId())); + + // Delete the record category + RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); + String recordCategoryId = Category1.getId(); + recordCategoryAPI.deleteRecordCategory(recordCategoryId); + + // Verify the status code + assertStatusCode(NO_CONTENT); + + } + +} diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/DeclareDocsAsRecordsOnUpdateRuleNewVersionTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/DeclareDocsAsRecordsOnUpdateRuleNewVersionTests.java new file mode 100644 index 0000000000..f4bcd7a7b5 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/DeclareDocsAsRecordsOnUpdateRuleNewVersionTests.java @@ -0,0 +1,122 @@ +/* + * #%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.smoke; + +import lombok.Getter; +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.unfiledcontainer.UnfiledContainerChildEntry; +import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI; +import org.alfresco.rest.v0.RulesAPI; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.data.DataContent; +import org.alfresco.utility.data.DataSite; +import org.alfresco.utility.data.DataUserAIS; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.SiteModel; +import org.springframework.beans.factory.annotation.Autowired; +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 lombok.AccessLevel.PROTECTED; +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.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.CREATED; + +public class DeclareDocsAsRecordsOnUpdateRuleNewVersionTests extends BaseRMRestTest { + + + @Autowired + private DataSite dataSite; + private SiteModel publicSite; + private RecordCategory recordCategory; + @Autowired + private RulesAPI rulesAPI; + @Autowired + protected DataContent dataContent; + @Autowired + @Getter(value = PROTECTED) + protected DataUserAIS dataUser; + private final static String title = "Rule to convert document as record"; + + @BeforeClass (alwaysRun = true) + public void setUp() + { + publicSite = dataSite.usingAdmin().createPublicRandomSite(); + recordCategory = createRootCategory(getRandomName("recordCategory")); + + } + + @Test + @AlfrescoTest(jira = "RM-1521") + public void declareDocsAsRecordsOnUpdateRuleNewVersion() { + FolderModel testFolder; + + STEP("Create test collaboration site to store documents in."); + publicSite = dataSite.usingAdmin().createPublicRandomSite(); + + STEP("Create a record folder with a DECLARE_AS_RECORD"); + 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 a document in the collaboration site"); + FileModel testFile = dataContent.usingSite(publicSite) + .usingAdmin() + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + assertStatusCode(CREATED); + + + // 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(testFile.getNodeRefWithoutVersion())) + .collect(Collectors.toList()); + + //delete rm items + deleteRecordCategory(recordCategory.getId()); + STEP("Delete the record."); + //delete created collaboration site + dataSite.deleteSite(publicSite); + + } +} diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/FileAsRecordTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/FileAsRecordTests.java new file mode 100644 index 0000000000..cdadcd5ceb --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/FileAsRecordTests.java @@ -0,0 +1,238 @@ +/* + * #%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.smoke; + +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.recordfolder.RecordFolderCollection; +import org.alfresco.rest.rm.community.model.user.UserRoles; +import org.alfresco.rest.v0.RecordCategoriesAPI; +import org.alfresco.rest.v0.service.RoleService; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.Utility; +import org.alfresco.utility.data.DataContent; +import org.alfresco.utility.data.DataSite; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.json.JSONObject; +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.concurrent.atomic.AtomicReference; +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.rest.rm.community.utils.CoreUtil.toContentModel; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.test.util.AssertionErrors.assertTrue; +import static org.testng.Assert.*; + +public class FileAsRecordTests extends BaseRMRestTest { + + 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 UserModel nonRMuser,rmManager; + private SiteModel testSite; + private FileModel document, documentDeclared; + private RecordCategory category_manager, category_admin; + private RecordCategoryChild folder_admin, folder_manager ; + @Autowired + private DataSite dataSite; + @Autowired + private DataContent dataContent; + @Autowired + private RoleService roleService; + @Autowired + private RecordCategoriesAPI recordCategoriesAPI; + /** + * 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
+     * 
+ */ + @BeforeClass(alwaysRun = true) + public void preconditionForFileAsRecordRecordTests() + { + 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); + } + + /** + * Given I have selected the record folder I want to file my declared record to + * When I confirm the action + * Then the dialog closes + * And the document is now shown as a record in the collaboration site + * And if I navigated to the record folder, as any user who had the right permissions, then I would see the + * record filed + */ + @Test + @AlfrescoTest(jira = "RM-6780") + public void checkFileAsRecordToRecordFolder() throws Exception { + + AtomicReference apiChildren = new AtomicReference<>(); + STEP("Create a document with the user with RM role"); + documentDeclared = dataContent.usingSite(testSite).usingUser(rmManager) + .createContent(new FileModel("checkDeclareAndFileToRecordFolder", FileType.TEXT_PLAIN)); + + STEP("Declare and file into a record folder the document uploaded"); + + getRestAPIFactory().getActionsAPI(rmManager).declareAndFile(documentDeclared, + Utility.buildPath(CATEGORY_MANAGER, FOLDER_MANAGER)); + + STEP("Check the file is a record within the collaboration site"); + + try + { + Utility.sleep(1000, 40000, () -> + { + JSONObject collaboratorSearchJson = getSearchApi().liveSearchForDocuments(rmManager.getUsername(), + rmManager.getPassword(), + documentDeclared.getName()); + assertTrue("Rm Manager not able to find the document.", collaboratorSearchJson.getJSONArray("items").length() != 0); + }); + } + catch (InterruptedException e) + { + fail("InterruptedException received while waiting for results."); + } + + STEP("Check the record is filed into the record folder."); + // Get children from API + // List children from API + try + { + Utility.sleep(1000, 40000, () -> + { + apiChildren.set((RecordFolderCollection) getRestAPIFactory() + .getRecordFolderAPI(rmManager).getRecordFolderChildren(folder_manager.getId(), "include=properties") + .assertThat().entriesListIsNotEmpty().assertThat().entriesListIsNotEmpty()); + }); + } + catch (InterruptedException e) + { + fail("InterruptedException received while waiting for results."); + } + + assertEquals(apiChildren.get() + .getEntries() + .get(0) + .getEntry() + .getProperties() + .getOriginalName(),documentDeclared.getName()); + } + + /** + * Given I have selected the "File As Record" action + * When I confirm the action without selecting a location to file to + * Then the record is declared in the unfiled folder + */ + @Test + @AlfrescoTest (jira = "RM-6780") + public void fileAsRecordToUnfiledRecordFolder() throws Exception { + STEP("Create a document with the user without RM role"); + FileModel inplaceRecord = dataContent.usingSite(testSite).usingUser(rmManager) + .createContent(new FileModel("declareAndFileToIntoUnfiledRecordFolder", + FileType.TEXT_PLAIN)); + + STEP("Click on Declare and file without selecting a record folder"); + getRestAPIFactory().getActionsAPI(rmManager).declareAndFile(inplaceRecord,""); + + STEP("Check the file is declared in unfiled record folder"); + Assert.assertTrue(isMatchingRecordInUnfiledRecords(inplaceRecord), "Record should be filed to Unfiled Records folder"); + } + + @AfterClass(alwaysRun = true) + public void cleanUpForFileAsRecordRecordTests() { + STEP("Delete the collaboration site"); + dataSite.usingUser(nonRMuser).deleteSite(testSite); + + STEP("Empty the trashcan."); + restClient.authenticateUser(nonRMuser).withCoreAPI().usingTrashcan().deleteNodeFromTrashcan(toContentModel(testSite.getId())); + + getRestAPIFactory() + .getUnfiledContainersAPI(rmManager) + .getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS) + .getEntries() + .stream() + .forEach(x -> getRestAPIFactory() + .getRecordsAPI() + .deleteRecord(x.getEntry().getId())); + + STEP("Cleanup Documents inside folders"); + + STEP("Delete folders"); + getRestAPIFactory().getRecordFolderAPI().deleteRecordFolder(folder_admin.getId()); + getRestAPIFactory().getRecordFolderAPI().deleteRecordFolder(folder_manager.getId()); + + STEP("Delete categories"); + recordCategoriesAPI.deleteCategory(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), category_manager.getName()); + recordCategoriesAPI.deleteCategory(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), category_admin.getName()); + + STEP("Delete Users"); + dataUser.deleteUser(nonRMuser); + dataUser.deleteUser(rmManager); + } +} diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/FoldersDispositionScheduleTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/FoldersDispositionScheduleTests.java new file mode 100644 index 0000000000..e2a9d7c6da --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/FoldersDispositionScheduleTests.java @@ -0,0 +1,108 @@ +/* + * #%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.smoke; + +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.v0.RecordFoldersAPI; +import org.alfresco.rest.v0.service.DispositionScheduleService; +import org.alfresco.test.AlfrescoTest; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import static org.alfresco.rest.rm.community.model.recordcategory.RetentionPeriodProperty.CREATED_DATE; +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 FoldersDispositionScheduleTests extends BaseRMRestTest { + + private RecordCategory Category1; + @Autowired + private DispositionScheduleService dispositionScheduleService; + @Autowired + private RecordFoldersAPI recordFoldersAPI; + private final String TEST_PREFIX = generateTestPrefix(FoldersDispositionScheduleTests.class); + private final String folderDisposition = TEST_PREFIX + "RM-2937 folder ghosting"; + private final String electronicRecord = "RM-2937 electronic 2 record"; + private final String nonElectronicRecord = "RM-2937 non-electronic record"; + + @BeforeClass(alwaysRun = true) + private void setUp(){ + + STEP("Create the RM site if doesn't exist"); + createRMSiteIfNotExists(); + + STEP("Create record category"); + Category1 = createRootCategory(getRandomName("Title")); + } + + @Test + @AlfrescoTest (jira = "RM-2937") + public void foldersDispositionScheduleWithGhosting() { + + //create retention schedule + dispositionScheduleService.createCategoryRetentionSchedule(Category1.getName(), false); + + // add cut off step + dispositionScheduleService.addCutOffAfterPeriodStep(Category1.getName(), "day|2", CREATED_DATE); + + // add destroy step with ghosting + dispositionScheduleService.addDestroyWithGhostingImmediatelyAfterCutOff(Category1.getName()); + + //create folders + RecordCategoryChild FOLDER_DESTROY = createFolder(getAdminUser(),Category1.getId(),folderDisposition); + + Record elRecord = createElectronicRecord(FOLDER_DESTROY.getId(),electronicRecord); + Record nonElRecord = createNonElectronicRecord(FOLDER_DESTROY.getId(),nonElectronicRecord); + + // complete records + completeRecord(elRecord.getId()); + completeRecord(nonElRecord.getId()); + + // edit disposition date + recordFoldersAPI.postFolderAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),editDispositionDateJson(),FOLDER_DESTROY.getName()); + + // cut off the FOLDER_DESTROY + recordFoldersAPI.postFolderAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","cutoff"),FOLDER_DESTROY.getName()); + + // Destroy the FOLDER_DESTROY + recordFoldersAPI.postFolderAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","destroy"),FOLDER_DESTROY.getName()); + } + + @AfterMethod(alwaysRun = true) + private void deletePreconditions() { + deleteRecordCategory(Category1.getId()); + } +} diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/FoldersDispositionScheduleWithoutGhostRecordTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/FoldersDispositionScheduleWithoutGhostRecordTests.java new file mode 100644 index 0000000000..4bec2fd08c --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/FoldersDispositionScheduleWithoutGhostRecordTests.java @@ -0,0 +1,116 @@ +/* + * #%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.smoke; + +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.v0.RecordFoldersAPI; +import org.alfresco.rest.v0.service.DispositionScheduleService; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.Utility; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import static org.alfresco.rest.rm.community.model.recordcategory.RetentionPeriodProperty.CREATED_DATE; +import static org.alfresco.rest.rm.community.model.recordcategory.RetentionPeriodProperty.CUT_OFF_DATE; +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 FoldersDispositionScheduleWithoutGhostRecordTests extends BaseRMRestTest { + + private RecordCategory Category1; + @Autowired + private DispositionScheduleService dispositionScheduleService; + @Autowired + private RecordFoldersAPI recordFoldersAPI; + private final String TEST_PREFIX = generateTestPrefix(FoldersDispositionScheduleWithoutGhostRecordTests.class); + private final String folderDisposition = TEST_PREFIX + "RM-2937 folder ghosting"; + private final String electronicRecord = "RM-2937 electronic 2 record"; + private final String nonElectronicRecord = "RM-2937 non-electronic record"; + + @BeforeClass(alwaysRun = true) + private void setUp(){ + + STEP("Create the RM site if doesn't exist"); + createRMSiteIfNotExists(); + + STEP("Create record category"); + Category1 = createRootCategory(getRandomName("Title")); + } + + @Test + @AlfrescoTest(jira="RM-2937") + public void foldersDispositionScheduleWithoutGhosting() { + + //create retention schedule + dispositionScheduleService.createCategoryRetentionSchedule(Category1.getName(), false); + + // add cut off step + dispositionScheduleService.addCutOffAfterPeriodStep(Category1.getName(), "day|2", CREATED_DATE); + + // add destroy step with ghosting + dispositionScheduleService.addDestroyWithoutGhostingAfterPeriodStep(Category1.getName(), "day|1", CUT_OFF_DATE); + + //create folders + RecordCategoryChild FOLDER_DESTROY = createFolder(getAdminUser(),Category1.getId(),folderDisposition); + + Record elRecord = createElectronicRecord(FOLDER_DESTROY.getId(),electronicRecord); + Record nonElRecord = createNonElectronicRecord(FOLDER_DESTROY.getId(),nonElectronicRecord); + + // complete records + completeRecord(elRecord.getId()); + completeRecord(nonElRecord.getId()); + + // edit disposition date + recordFoldersAPI.postFolderAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),editDispositionDateJson(),FOLDER_DESTROY.getName()); + + // cut off the FOLDER_DESTROY + recordFoldersAPI.postFolderAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","cutoff"),FOLDER_DESTROY.getName()); + + // edit disposition date + recordFoldersAPI.postFolderAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),editDispositionDateJson(),FOLDER_DESTROY.getName()); + + Utility.waitToLoopTime(5,"Waiting for Edit Disposition to be processed"); + + // Destroy the FOLDER_DESTROY + recordFoldersAPI.postFolderAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","destroy"),FOLDER_DESTROY.getName()); + } + + @AfterMethod(alwaysRun = true) + private void deletePreconditions() { + deleteRecordCategory(Category1.getId()); + } +} diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/RecordsDispositionScheduleTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/RecordsDispositionScheduleTests.java new file mode 100644 index 0000000000..90823b3514 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/RecordsDispositionScheduleTests.java @@ -0,0 +1,202 @@ +/* + * #%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.smoke; + +import org.alfresco.rest.core.v0.RMEvents; +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.v0.RMRolesAndActionsAPI; +import org.alfresco.rest.v0.RecordFoldersAPI; +import org.alfresco.rest.v0.RecordsAPI; +import org.alfresco.rest.v0.service.DispositionScheduleService; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.Utility; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; +import java.io.IOException; +import java.time.Instant; +import static org.alfresco.rest.rm.community.base.TestData.DEFAULT_PASSWORD; +import static org.alfresco.rest.rm.community.model.recordcategory.RetentionPeriodProperty.CUT_OFF_DATE; +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; +import static org.alfresco.utility.report.log.Step.STEP; + +/** + * Contains recordsDispositionScheduleWithoutGhosting test which checks disposition schedule cut off, transfer and destroy without maintaining metadata steps applied to records + *

+ * Precondition: + *

+ * RM site created, contains an empty category "RM-2801 disposition for records".

+ * RM user has RM admin role.

+ * A transfer location named "transferred files" is created to which RM user has access + *

+ * Records Disposition Schedule without ghosting + * + * @author Kavit Shah + */ + +public class RecordsDispositionScheduleTests extends BaseRMRestTest { + + /** data prep 6services */ + @Autowired + private RMRolesAndActionsAPI rmRolesAndActionsAPI; + @Autowired + private RecordsAPI recordsAPI; + @Autowired + private RecordFoldersAPI recordFoldersAPI; + @Autowired + private DispositionScheduleService dispositionScheduleService; + private RecordCategory Category1; + private final String TEST_PREFIX = generateTestPrefix(RecordsDispositionScheduleTests.class); + private final String RM_ADMIN = TEST_PREFIX + "rm_admin"; + private final String recordsCategory = TEST_PREFIX + "RM-2801 category"; + private final String folderDisposition = TEST_PREFIX + "RM-2801 folder"; + + @Test + @AlfrescoTest(jira="RM-2801") + public void recordsDispositionScheduleWithoutGhosting() { + + // create test precondition + createTestPrecondition(recordsCategory); + + // create disposition schedule + dispositionScheduleService.createCategoryRetentionSchedule(Category1.getName(), true); + + // add cut off step + dispositionScheduleService.addCutOffImmediatelyStep(Category1.getName()); + + // add transfer step + dispositionScheduleService.addTransferAfterEventStep(Category1.getName(),"transferred records","all_allowances_granted_are_terminated"); + + // add destroy step without retaining metadata + dispositionScheduleService.addDestroyWithoutGhostingAfterPeriodStep(Category1.getName(), "day|1", CUT_OFF_DATE); + + // create a folder and an electronic and a non-electronic record in it + RecordCategoryChild FOLDER_DESTROY = createFolder(getAdminUser(),Category1.getId(),folderDisposition); + + String electronicRecord = "RM-2801 electronic record"; + Record elRecord = createElectronicRecord(FOLDER_DESTROY.getId(), electronicRecord); + String nonElectronicRecord = "RM-2801 non-electronic record"; + Record nonElRecord = createNonElectronicRecord(FOLDER_DESTROY.getId(), nonElectronicRecord); + + // complete records and cut them off + String nonElRecordName = recordsAPI.getRecordFullName(getAdminUser().getUsername(), + getAdminUser().getPassword(), folderDisposition, nonElectronicRecord); + String elRecordName = recordsAPI.getRecordFullName(getAdminUser().getUsername(), + getAdminUser().getPassword(), folderDisposition, electronicRecord); + + // complete records and cut them off + completeRecord(elRecord.getId()); + completeRecord(nonElRecord.getId()); + + String nonElRecordNameNodeRef = recordsAPI.getRecordNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), nonElRecordName, "/" + Category1.getName() + "/" + folderDisposition); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","cutoff"),nonElRecordNameNodeRef); + + String elRecordNameNodeRef = recordsAPI.getRecordNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), elRecordName, "/" + Category1.getName() + "/" + folderDisposition); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","cutoff"),elRecordNameNodeRef); + + // ensure the complete event action is displayed for both events + rmRolesAndActionsAPI.completeEvent(getAdminUser().getUsername(), + getAdminUser().getPassword(), nonElRecordName, RMEvents.ALL_ALLOWANCES_GRANTED_ARE_TERMINATED, Instant.now()); + rmRolesAndActionsAPI.completeEvent(getAdminUser().getUsername(), + getAdminUser().getPassword(), elRecordName, RMEvents.ALL_ALLOWANCES_GRANTED_ARE_TERMINATED, Instant.now()); + + // Create and Complete transfer + HttpResponse nonElRecordNameHttpResponse = recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","transfer"),recordsAPI.getRecordNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), nonElRecordName, "/" + Category1.getName() + "/" + folderDisposition)); + + String nonElRecordNameTransferId = getTransferId(nonElRecordNameHttpResponse,nonElRecordNameNodeRef); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","transferComplete"),nonElRecordNameTransferId); + + HttpResponse elRecordNameHttpResponse = recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","transfer"),recordsAPI.getRecordNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), elRecordName, "/" + Category1.getName() + "/" + folderDisposition)); + + String elRecordNameTransferId = getTransferId(elRecordNameHttpResponse,elRecordNameNodeRef); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","transferComplete"),elRecordNameTransferId); + + // edit the disposition schedule date to current date + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),editDispositionDateJson(),nonElRecordNameNodeRef); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),editDispositionDateJson(),elRecordNameNodeRef); + + Utility.waitToLoopTime(5,"Waiting for Edit Disposition to be processed"); + + // destroy records + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","destroy"),nonElRecordNameNodeRef); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","destroy"),elRecordNameNodeRef); + + // delete category + deleteRecordCategory(Category1.getId()); + } + + private void createTestPrecondition(String categoryName) { + createRMSiteIfNotExists(); + + // create "rm admin" user if it does not exist and assign it to RM Administrator role + rmRolesAndActionsAPI.createUserAndAssignToRole( + getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), + RM_ADMIN, DEFAULT_PASSWORD, "Administrator"); + + // create category + STEP("Create two category"); + Category1 = createRootCategory(categoryName,"Title"); + } + + private String getTransferId(HttpResponse httpResponse,String nodeRef) { + HttpEntity entity = httpResponse.getEntity(); + String responseString = null; + try { + responseString = EntityUtils.toString(entity, "UTF-8"); + } catch (IOException e) { + throw new RuntimeException(e); + } + JSONObject result = new JSONObject(responseString); + return result + .getJSONObject("results") + .get(nodeRef) + .toString(); + + } +} diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/RecordsDispositionScheduleWithGhostingTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/RecordsDispositionScheduleWithGhostingTests.java new file mode 100644 index 0000000000..07742a0767 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/RecordsDispositionScheduleWithGhostingTests.java @@ -0,0 +1,200 @@ +/* + * #%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.smoke; + +import org.alfresco.rest.core.v0.RMEvents; +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.v0.RMRolesAndActionsAPI; +import org.alfresco.rest.v0.RecordFoldersAPI; +import org.alfresco.rest.v0.RecordsAPI; +import org.alfresco.rest.v0.service.DispositionScheduleService; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.Utility; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; +import java.io.IOException; +import java.time.Instant; +import static org.alfresco.rest.rm.community.base.TestData.DEFAULT_PASSWORD; +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; +import static org.alfresco.utility.report.log.Step.STEP; + +/** + * Contains recordsDispositionScheduleWithGhosting test which checks disposition schedule cut off, transfer and destroy with maintaining record metadata steps applied to records + *

+ * Precondition: + *

+ * RM site created, contains an empty category "RM-2937 disposition for records with ghosting".

+ * RM user has RM admin role.

+ * A transfer location named "transferred files with ghosting" is created to which RM user has access + *

+ * Records Disposition Schedule with ghosting + * + * @author Kavit Shah + */ +public class RecordsDispositionScheduleWithGhostingTests extends BaseRMRestTest { + + /** data prep 6services */ + @Autowired + private RMRolesAndActionsAPI rmRolesAndActionsAPI; + @Autowired + private RecordsAPI recordsAPI; + @Autowired + private RecordFoldersAPI recordFoldersAPI; + @Autowired + private DispositionScheduleService dispositionScheduleService; + private RecordCategory Category1; + private final String TEST_PREFIX = generateTestPrefix(RecordsDispositionScheduleTests.class); + private final String RM_ADMIN = TEST_PREFIX + "rm_admin"; + private final String recordsCategory = TEST_PREFIX + "RM-2801 category"; + private final String folderDisposition = TEST_PREFIX + "RM-2801 folder"; + + @Test + @AlfrescoTest(jira="RM-2801") + public void recordsDispositionScheduleWithGhosting() { + + // create test precondition + createTestPrecondition(recordsCategory); + + // create disposition schedule + dispositionScheduleService.createCategoryRetentionSchedule(Category1.getName(), true); + + // add cut off step + dispositionScheduleService.addCutOffImmediatelyStep(Category1.getName()); + + // add transfer step + dispositionScheduleService.addTransferAfterEventStep(Category1.getName(),"transferred records","all_allowances_granted_are_terminated"); + + // add destroy step without retaining metadata + dispositionScheduleService.addDestroyWithGhostingImmediatelyAfterCutOff(Category1.getName()); + + // create a folder and an electronic and a non-electronic record in it + RecordCategoryChild FOLDER_DESTROY = createFolder(getAdminUser(),Category1.getId(),folderDisposition); + + String electronicRecord = "RM-2801 electronic record"; + Record elRecord = createElectronicRecord(FOLDER_DESTROY.getId(), electronicRecord); + String nonElectronicRecord = "RM-2801 non-electronic record"; + Record nonElRecord = createNonElectronicRecord(FOLDER_DESTROY.getId(), nonElectronicRecord); + + // complete records and cut them off + String nonElRecordName = recordsAPI.getRecordFullName(getAdminUser().getUsername(), + getAdminUser().getPassword(), folderDisposition, nonElectronicRecord); + String elRecordName = recordsAPI.getRecordFullName(getAdminUser().getUsername(), + getAdminUser().getPassword(), folderDisposition, electronicRecord); + + // complete records and cut them off + completeRecord(elRecord.getId()); + completeRecord(nonElRecord.getId()); + + String nonElRecordNameNodeRef = recordsAPI.getRecordNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), nonElRecordName, "/" + Category1.getName() + "/" + folderDisposition); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","cutoff"),nonElRecordNameNodeRef); + + String elRecordNameNodeRef = recordsAPI.getRecordNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), elRecordName, "/" + Category1.getName() + "/" + folderDisposition); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","cutoff"),elRecordNameNodeRef); + + // ensure the complete event action is displayed for both events + rmRolesAndActionsAPI.completeEvent(getAdminUser().getUsername(), + getAdminUser().getPassword(), nonElRecordName, RMEvents.ALL_ALLOWANCES_GRANTED_ARE_TERMINATED, Instant.now()); + rmRolesAndActionsAPI.completeEvent(getAdminUser().getUsername(), + getAdminUser().getPassword(), elRecordName, RMEvents.ALL_ALLOWANCES_GRANTED_ARE_TERMINATED, Instant.now()); + + // Create and Complete transfer + HttpResponse nonElRecordNameHttpResponse = recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","transfer"),recordsAPI.getRecordNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), nonElRecordName, "/" + Category1.getName() + "/" + folderDisposition)); + + String nonElRecordNameTransferId = getTransferId(nonElRecordNameHttpResponse,nonElRecordNameNodeRef); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","transferComplete"),nonElRecordNameTransferId); + + HttpResponse elRecordNameHttpResponse = recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","transfer"),recordsAPI.getRecordNodeRef(getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), elRecordName, "/" + Category1.getName() + "/" + folderDisposition)); + + String elRecordNameTransferId = getTransferId(elRecordNameHttpResponse,elRecordNameNodeRef); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","transferComplete"),elRecordNameTransferId); + + // edit the disposition schedule date to current date + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),editDispositionDateJson(),nonElRecordNameNodeRef); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),editDispositionDateJson(),elRecordNameNodeRef); + + Utility.waitToLoopTime(5,"Waiting for Edit Disposition to be processed"); + + // destroy records + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","destroy"),nonElRecordNameNodeRef); + recordFoldersAPI.postRecordAction(getAdminUser().getUsername(), + getAdminUser().getPassword(),new JSONObject().put("name","destroy"),elRecordNameNodeRef); + + // delete category + deleteRecordCategory(Category1.getId()); + } + + private void createTestPrecondition(String categoryName) { + createRMSiteIfNotExists(); + + // create "rm admin" user if it does not exist and assign it to RM Administrator role + rmRolesAndActionsAPI.createUserAndAssignToRole( + getDataUser().usingAdmin().getAdminUser().getUsername(), + getDataUser().usingAdmin().getAdminUser().getPassword(), + RM_ADMIN, DEFAULT_PASSWORD, "Administrator"); + + // create category + STEP("Create two category"); + Category1 = createRootCategory(categoryName,"Title"); + } + + private String getTransferId(HttpResponse httpResponse,String nodeRef) { + HttpEntity entity = httpResponse.getEntity(); + String responseString = null; + try { + responseString = EntityUtils.toString(entity, "UTF-8"); + } catch (IOException e) { + throw new RuntimeException(e); + } + JSONObject result = new JSONObject(responseString); + return result + .getJSONObject("results") + .get(nodeRef) + .toString(); + + } +} diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/UnfiledRecordsRuleTests.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/UnfiledRecordsRuleTests.java new file mode 100644 index 0000000000..a7023a1723 --- /dev/null +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/smoke/UnfiledRecordsRuleTests.java @@ -0,0 +1,124 @@ +/* + * #%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.smoke; + + +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.record.RecordContent; +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.unfiledcontainer.UnfiledContainerChild; +import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties; +import org.alfresco.rest.v0.RMRolesAndActionsAPI; +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.ArrayList; +import java.util.Collections; +import java.util.List; +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.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.*; +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.*; +public class UnfiledRecordsRuleTests extends BaseRMRestTest { + + @Autowired + private RMRolesAndActionsAPI rmRolesAndActionsAPI; + private final String TEST_PREFIX = generateTestPrefix(CreateCategoriesTests.class); + private final String RM_ADMIN = TEST_PREFIX + "rm_admin"; + private RecordCategory Category2; + private RecordCategoryChild Folder2; + @Autowired + private RulesAPI rulesAPI; + + @Test + @AlfrescoTest(jira = "RM-2794") + public void unfiledRecordsRule() { + + + STEP("Create the RM site if doesn't exist"); + createRMSiteIfNotExists(); + + STEP("Create RM Admin user"); + rmRolesAndActionsAPI.createUserAndAssignToRole(getAdminUser().getUsername(), getAdminUser().getPassword(), RM_ADMIN, + getAdminUser().getPassword(), + "Administrator"); + + STEP("Create record categories and record folders"); + Category2 = createRootCategory(getRandomName("recordCategory")); + Folder2 = createFolder(Category2.getId(), getRandomName("recordFolder")); + + STEP("Get the unfiled records container"); + UnfiledContainer container = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS); + + // Check the response code + assertStatusCode(OK); + + //create a rule + RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description") + .applyToChildren(true) + .actions(Collections.singletonList(ActionsOnRule.FILE_TO.getActionValue())); + rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + container.getId(), ruleDefinition); + + //upload an electronic record + UnfiledContainerChild electronicRecord = UnfiledContainerChild.builder() + .name(ELECTRONIC_RECORD_NAME) + .nodeType(CONTENT_TYPE) + .content(RecordContent.builder().mimeType("text/plain").build()) + .build(); + assertStatusCode(OK); + + + // create a non-electronic record + UnfiledContainerChild nonelectronicRecord = UnfiledContainerChild.builder() + .properties(UnfiledContainerChildProperties.builder() + .description(NONELECTRONIC_RECORD_NAME) + .title("Title") + .build()) + .name(NONELECTRONIC_RECORD_NAME) + .nodeType(NON_ELECTRONIC_RECORD_TYPE) + .build(); + assertStatusCode(OK); + + //delete the record created, delete the rule from UnfilledRecord page, delete the category created + rulesAPI.deleteAllRulesOnContainer(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + container.getId()); + deleteRecordCategory(Category2.getId()); + assertStatusCode(NO_CONTENT); + + } + + }