ACS-9652 [Es Connector] Prepare ACS 23.N for release (with ES Connector 5.1.0) (#3354)

Co-authored-by: Belal Ansari <belal.ansari@hyland.com>
This commit is contained in:
Gerard Olenski
2025-05-16 12:05:27 +02:00
committed by GitHub
parent 87e365df7e
commit ac62c52a33

View File

@@ -26,13 +26,6 @@
*/ */
package org.alfresco.rest.rm.community.hold; package org.alfresco.rest.rm.community.hold;
import static org.alfresco.rest.rm.community.base.TestData.HOLD_DESCRIPTION;
import static org.alfresco.rest.rm.community.base.TestData.HOLD_REASON;
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.model.user.UserPermissions.PERMISSION_READ_RECORDS;
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
import static org.alfresco.utility.report.log.Step.STEP;
import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@@ -44,12 +37,25 @@ import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.HttpStatus.UNAUTHORIZED; import static org.springframework.http.HttpStatus.UNAUTHORIZED;
import static org.alfresco.rest.rm.community.base.TestData.HOLD_DESCRIPTION;
import static org.alfresco.rest.rm.community.base.TestData.HOLD_REASON;
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.model.user.UserPermissions.PERMISSION_READ_RECORDS;
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
import static org.alfresco.utility.report.log.Step.STEP;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.alfresco.dataprep.CMISUtil; import org.alfresco.dataprep.CMISUtil;
import org.alfresco.dataprep.ContentActions; import org.alfresco.dataprep.ContentActions;
import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.base.BaseRMRestTest;
@@ -71,10 +77,6 @@ import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel; import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.UserModel; 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;
/** /**
* API tests for adding items to holds via the bulk process * API tests for adding items to holds via the bulk process
@@ -82,7 +84,7 @@ import org.testng.annotations.Test;
public class AddToHoldsBulkV1Tests extends BaseRMRestTest public class AddToHoldsBulkV1Tests extends BaseRMRestTest
{ {
private static final String ACCESS_DENIED_ERROR_MESSAGE = "Access Denied. You do not have the appropriate " + private static final String ACCESS_DENIED_ERROR_MESSAGE = "Access Denied. You do not have the appropriate " +
"permissions to perform this operation."; "permissions to perform this operation.";
private static final int NUMBER_OF_FILES = 5; private static final int NUMBER_OF_FILES = 5;
private final List<FileModel> addedFiles = new ArrayList<>(); private final List<FileModel> addedFiles = new ArrayList<>();
private final List<UserModel> users = new ArrayList<>(); private final List<UserModel> users = new ArrayList<>();
@@ -102,8 +104,9 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
{ {
STEP("Create a hold."); STEP("Create a hold.");
hold = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold( hold = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold(
Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION) Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION)
.reason(HOLD_REASON).build(), FILE_PLAN_ALIAS); .reason(HOLD_REASON).build(),
FILE_PLAN_ALIAS);
holds.add(hold); holds.add(hold);
STEP("Create test files."); STEP("Create test files.");
@@ -117,8 +120,8 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
for (int i = 0; i < NUMBER_OF_FILES; i++) for (int i = 0; i < NUMBER_OF_FILES; i++)
{ {
FileModel documentHeld = dataContent.usingAdmin() FileModel documentHeld = dataContent.usingAdmin()
.usingResource(i % 2 == 0 ? folder1 : folder2) .usingResource(i % 2 == 0 ? folder1 : folder2)
.createContent(CMISUtil.DocumentType.TEXT_PLAIN); .createContent(CMISUtil.DocumentType.TEXT_PLAIN);
addedFiles.add(documentHeld); addedFiles.add(documentHeld);
} }
@@ -128,29 +131,36 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
STEP("Wait until all files are searchable."); STEP("Wait until all files are searchable.");
await().atMost(30, TimeUnit.SECONDS) await().atMost(30, TimeUnit.SECONDS)
.until(() -> getRestAPIFactory().getSearchAPI(null).search(searchRequest).getPagination() .until(() -> getRestAPIFactory().getSearchAPI(null).search(searchRequest).getPagination()
.getTotalItems() == NUMBER_OF_FILES); .getTotalItems() == NUMBER_OF_FILES);
RestRequestQueryModel ancestorReq = getContentFromFolderAndAllSubfoldersQuery(rootFolder.getNodeRefWithoutVersion());
SearchRequest ancestorSearchRequest = new SearchRequest();
ancestorSearchRequest.setQuery(ancestorReq);
STEP("Wait until paths are indexed.");
await().atMost(30, TimeUnit.SECONDS)
.until(() -> getRestAPIFactory().getSearchAPI(null).search(ancestorSearchRequest).getPagination()
.getTotalItems() == NUMBER_OF_FILES);
holdBulkOperation = HoldBulkOperation.builder() holdBulkOperation = HoldBulkOperation.builder()
.query(queryReq) .query(queryReq)
.op(HoldBulkOperationType.ADD).build(); .op(HoldBulkOperationType.ADD).build();
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from a site to a hold using the bulk API Then the content is added to the hold and the status of the bulk operation is DONE
* When the user adds content from a site to a hold using the bulk API
* Then the content is added to the hold and the status of the bulk operation is DONE
*/ */
@Test @Test
public void addContentFromTestSiteToHoldUsingBulkAPI() public void addContentFromTestSiteToHoldUsingBulkAPI()
{ {
UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite,
UserRole.SiteCollaborator, hold.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); UserRole.SiteCollaborator, hold.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
users.add(userAddHoldPermission); users.add(userAddHoldPermission);
STEP("Add content from the site to the hold using the bulk API."); STEP("Add content from the site to the hold using the bulk API.");
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.startBulkProcess(holdBulkOperation, hold.getId()); .startBulkProcess(holdBulkOperation, hold.getId());
// Verify the status code // Verify the status code
assertStatusCode(ACCEPTED); assertStatusCode(ACCEPTED);
@@ -158,50 +168,49 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
STEP("Wait until all files are added to the hold."); STEP("Wait until all files are added to the hold.");
await().atMost(20, TimeUnit.SECONDS).until( await().atMost(20, TimeUnit.SECONDS).until(
() -> getRestAPIFactory().getHoldsAPI(getAdminUser()).getChildren(hold.getId()).getEntries().size() () -> getRestAPIFactory().getHoldsAPI(getAdminUser()).getChildren(hold.getId()).getEntries().size() == NUMBER_OF_FILES);
== NUMBER_OF_FILES);
List<String> holdChildrenNodeRefs = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) List<String> holdChildrenNodeRefs = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getChildren(hold.getId()).getEntries().stream().map(HoldChildEntry::getEntry).map( .getChildren(hold.getId()).getEntries().stream().map(HoldChildEntry::getEntry).map(
HoldChild::getId).toList(); HoldChild::getId)
.toList();
assertEquals(addedFiles.stream().map(FileModel::getNodeRefWithoutVersion).sorted().toList(), assertEquals(addedFiles.stream().map(FileModel::getNodeRefWithoutVersion).sorted().toList(),
holdChildrenNodeRefs.stream().sorted().toList()); holdChildrenNodeRefs.stream().sorted().toList());
STEP("Check the bulk status."); STEP("Check the bulk status.");
HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId()); .getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId());
assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, 0, null, holdBulkOperation); assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, 0, null, holdBulkOperation);
STEP("Check the bulk statuses."); STEP("Check the bulk statuses.");
HoldBulkStatusCollection holdBulkStatusCollection = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkStatusCollection holdBulkStatusCollection = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getBulkStatuses(hold.getId()); .getBulkStatuses(hold.getId());
assertEquals(Arrays.asList(holdBulkStatus), assertEquals(Arrays.asList(holdBulkStatus),
holdBulkStatusCollection.getEntries().stream().map(HoldBulkStatusEntry::getEntry).toList()); holdBulkStatusCollection.getEntries().stream().map(HoldBulkStatusEntry::getEntry).toList());
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from a folder and all subfolders to a hold using the bulk API Then the content is added to the hold and the status of the bulk operation is DONE
* When the user adds content from a folder and all subfolders to a hold using the bulk API
* Then the content is added to the hold and the status of the bulk operation is DONE
*/ */
@Test @Test
public void addContentFromFolderAndAllSubfoldersToHoldUsingBulkAPI() public void addContentFromFolderAndAllSubfoldersToHoldUsingBulkAPI()
{ {
hold3 = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold( hold3 = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold(
Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION) Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION)
.reason(HOLD_REASON).build(), FILE_PLAN_ALIAS); .reason(HOLD_REASON).build(),
FILE_PLAN_ALIAS);
holds.add(hold3); holds.add(hold3);
UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite,
UserRole.SiteCollaborator, hold3.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); UserRole.SiteCollaborator, hold3.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
users.add(userAddHoldPermission); users.add(userAddHoldPermission);
STEP("Add content from the site to the hold using the bulk API."); STEP("Add content from the site to the hold using the bulk API.");
// Get content from folder and all subfolders of the root folder // Get content from folder and all subfolders of the root folder
HoldBulkOperation bulkOperation = HoldBulkOperation.builder() HoldBulkOperation bulkOperation = HoldBulkOperation.builder()
.query(getContentFromFolderAndAllSubfoldersQuery(rootFolder.getNodeRefWithoutVersion())) .query(getContentFromFolderAndAllSubfoldersQuery(rootFolder.getNodeRefWithoutVersion()))
.op(HoldBulkOperationType.ADD).build(); .op(HoldBulkOperationType.ADD).build();
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.startBulkProcess(bulkOperation, hold3.getId()); .startBulkProcess(bulkOperation, hold3.getId());
// Verify the status code // Verify the status code
assertStatusCode(ACCEPTED); assertStatusCode(ACCEPTED);
@@ -209,43 +218,40 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
STEP("Wait until all files are added to the hold."); STEP("Wait until all files are added to the hold.");
await().atMost(20, TimeUnit.SECONDS).until( await().atMost(20, TimeUnit.SECONDS).until(
() -> getRestAPIFactory().getHoldsAPI(getAdminUser()).getChildren(hold3.getId()).getEntries().size() () -> getRestAPIFactory().getHoldsAPI(getAdminUser()).getChildren(hold3.getId()).getEntries().size() == NUMBER_OF_FILES);
== NUMBER_OF_FILES);
List<String> holdChildrenNodeRefs = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) List<String> holdChildrenNodeRefs = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getChildren(hold3.getId()).getEntries().stream().map(HoldChildEntry::getEntry).map( .getChildren(hold3.getId()).getEntries().stream().map(HoldChildEntry::getEntry).map(
HoldChild::getId).toList(); HoldChild::getId)
.toList();
assertEquals(addedFiles.stream().map(FileModel::getNodeRefWithoutVersion).sorted().toList(), assertEquals(addedFiles.stream().map(FileModel::getNodeRefWithoutVersion).sorted().toList(),
holdChildrenNodeRefs.stream().sorted().toList()); holdChildrenNodeRefs.stream().sorted().toList());
STEP("Check the bulk status."); STEP("Check the bulk status.");
HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getBulkStatus(hold3.getId(), bulkOperationEntry.getBulkStatusId()); .getBulkStatus(hold3.getId(), bulkOperationEntry.getBulkStatusId());
assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, 0, null, bulkOperation); assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, 0, null, bulkOperation);
STEP("Check the bulk statuses."); STEP("Check the bulk statuses.");
HoldBulkStatusCollection holdBulkStatusCollection = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkStatusCollection holdBulkStatusCollection = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getBulkStatuses(hold3.getId()); .getBulkStatuses(hold3.getId());
assertEquals(List.of(holdBulkStatus), assertEquals(List.of(holdBulkStatus),
holdBulkStatusCollection.getEntries().stream().map(HoldBulkStatusEntry::getEntry).toList()); holdBulkStatusCollection.getEntries().stream().map(HoldBulkStatusEntry::getEntry).toList());
} }
/** /**
* Given a user without the add to hold capability * Given a user without the add to hold capability When the user adds content from a site to a hold using the bulk API Then the user receives access denied error
* When the user adds content from a site to a hold using the bulk API
* Then the user receives access denied error
*/ */
@Test @Test
public void testBulkProcessWithUserWithoutAddToHoldCapability() public void testBulkProcessWithUserWithoutAddToHoldCapability()
{ {
UserModel userWithoutAddToHoldCapability = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserModel userWithoutAddToHoldCapability = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite,
UserRole UserRole.SiteCollaborator,
.SiteCollaborator, hold.getId(), UserRoles.ROLE_RM_POWER_USER, PERMISSION_FILING);
hold.getId(), UserRoles.ROLE_RM_POWER_USER, PERMISSION_FILING);
users.add(userWithoutAddToHoldCapability); users.add(userWithoutAddToHoldCapability);
STEP("Add content from the site to the hold using the bulk API."); STEP("Add content from the site to the hold using the bulk API.");
getRestAPIFactory().getHoldsAPI(userWithoutAddToHoldCapability) getRestAPIFactory().getHoldsAPI(userWithoutAddToHoldCapability)
.startBulkProcess(holdBulkOperation, hold.getId()); .startBulkProcess(holdBulkOperation, hold.getId());
STEP("Verify the response status code and the error message."); STEP("Verify the response status code and the error message.");
assertStatusCode(FORBIDDEN); assertStatusCode(FORBIDDEN);
@@ -253,21 +259,19 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
} }
/** /**
* Given a user without the filing permission on a hold * Given a user without the filing permission on a hold When the user adds content from a site to a hold using the bulk API Then the user receives access denied error
* When the user adds content from a site to a hold using the bulk API
* Then the user receives access denied error
*/ */
@Test @Test
public void testBulkProcessWithUserWithoutFilingPermissionOnAHold() public void testBulkProcessWithUserWithoutFilingPermissionOnAHold()
{ {
// User without filing permission on a hold // User without filing permission on a hold
UserModel userWithoutPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserModel userWithoutPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite,
UserRole.SiteCollaborator, hold.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_READ_RECORDS); UserRole.SiteCollaborator, hold.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_READ_RECORDS);
users.add(userWithoutPermission); users.add(userWithoutPermission);
STEP("Add content from the site to the hold using the bulk API."); STEP("Add content from the site to the hold using the bulk API.");
getRestAPIFactory().getHoldsAPI(userWithoutPermission) getRestAPIFactory().getHoldsAPI(userWithoutPermission)
.startBulkProcess(holdBulkOperation, hold.getId()); .startBulkProcess(holdBulkOperation, hold.getId());
STEP("Verify the response status code and the error message."); STEP("Verify the response status code and the error message.");
assertStatusCode(FORBIDDEN); assertStatusCode(FORBIDDEN);
@@ -276,68 +280,63 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
} }
/** /**
* Given a user without the write permission on all the content * Given a user without the write permission on all the content When the user adds content from a site to a hold using the bulk API Then all processed items are marked as errors and the last error message contains access denied error
* When the user adds content from a site to a hold using the bulk API
* Then all processed items are marked as errors and the last error message contains access denied error
*/ */
@Test @Test
public void testBulkProcessWithUserWithoutWritePermissionOnTheContent() public void testBulkProcessWithUserWithoutWritePermissionOnTheContent()
{ {
// User without write permission on the content // User without write permission on the content
UserModel userWithoutPermission = roleService.createUserWithSiteRoleRMRoleAndPermission( UserModel userWithoutPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(
testSite, UserRole.SiteConsumer, testSite, UserRole.SiteConsumer,
hold.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); hold.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
users.add(userWithoutPermission); users.add(userWithoutPermission);
// Wait until permissions are reverted // Wait until permissions are reverted
SearchRequest searchRequest = new SearchRequest(); SearchRequest searchRequest = new SearchRequest();
searchRequest.setQuery(holdBulkOperation.getQuery()); searchRequest.setQuery(holdBulkOperation.getQuery());
await().atMost(30, TimeUnit.SECONDS) await().atMost(30, TimeUnit.SECONDS)
.until(() -> getRestAPIFactory().getSearchAPI(userWithoutPermission).search(searchRequest).getPagination() .until(() -> getRestAPIFactory().getSearchAPI(userWithoutPermission).search(searchRequest).getPagination()
.getTotalItems() == NUMBER_OF_FILES); .getTotalItems() == NUMBER_OF_FILES);
STEP("Add content from the site to the hold using the bulk API."); STEP("Add content from the site to the hold using the bulk API.");
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI( HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(
userWithoutPermission).startBulkProcess(holdBulkOperation, hold.getId()); userWithoutPermission).startBulkProcess(holdBulkOperation, hold.getId());
STEP("Verify the response."); STEP("Verify the response.");
assertStatusCode(ACCEPTED); assertStatusCode(ACCEPTED);
await().atMost(20, TimeUnit.SECONDS).until(() -> await().atMost(20, TimeUnit.SECONDS).until(() -> Objects.equals(getRestAPIFactory().getHoldsAPI(userWithoutPermission)
Objects.equals(getRestAPIFactory().getHoldsAPI(userWithoutPermission)
.getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId()).getStatus(), "DONE")); .getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId()).getStatus(), "DONE"));
HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userWithoutPermission) HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userWithoutPermission)
.getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId()); .getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId());
assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, NUMBER_OF_FILES, ACCESS_DENIED_ERROR_MESSAGE, assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, NUMBER_OF_FILES, ACCESS_DENIED_ERROR_MESSAGE,
holdBulkOperation); holdBulkOperation);
} }
/** /**
* Given a user without the write permission on one file * Given a user without the write permission on one file When the user adds content from a site to a hold using the bulk API Then all processed items are added to the hold except the one that the user does not have write permission And the status of the bulk operation is DONE, contains the error message and the number of errors is 1
* When the user adds content from a site to a hold using the bulk API
* Then all processed items are added to the hold except the one that the user does not have write permission
* And the status of the bulk operation is DONE, contains the error message and the number of errors is 1
*/ */
@Test @Test
public void testBulkProcessWithUserWithoutWritePermissionOnOneFile() public void testBulkProcessWithUserWithoutWritePermissionOnOneFile()
{ {
hold2 = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold( hold2 = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold(
Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION) Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION)
.reason(HOLD_REASON).build(), FILE_PLAN_ALIAS); .reason(HOLD_REASON).build(),
FILE_PLAN_ALIAS);
holds.add(hold2); holds.add(hold2);
UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite,
UserRole.SiteCollaborator, hold2.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); UserRole.SiteCollaborator, hold2.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
users.add(userAddHoldPermission); users.add(userAddHoldPermission);
contentActions.setPermissionForUser(getAdminUser().getUsername(), getAdminUser().getPassword(), contentActions.setPermissionForUser(getAdminUser().getUsername(), getAdminUser().getPassword(),
testSite.getId(), addedFiles.get(0).getName(), userAddHoldPermission.getUsername(), testSite.getId(), addedFiles.get(0).getName(), userAddHoldPermission.getUsername(),
UserRole.SiteConsumer.getRoleId(), false); UserRole.SiteConsumer.getRoleId(), false);
STEP("Add content from the site to the hold using the bulk API."); STEP("Add content from the site to the hold using the bulk API.");
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.startBulkProcess(holdBulkOperation, hold2.getId()); .startBulkProcess(holdBulkOperation, hold2.getId());
// Verify the status code // Verify the status code
assertStatusCode(ACCEPTED); assertStatusCode(ACCEPTED);
@@ -345,56 +344,50 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
STEP("Wait until all files are added to the hold."); STEP("Wait until all files are added to the hold.");
await().atMost(30, TimeUnit.SECONDS).until( await().atMost(30, TimeUnit.SECONDS).until(
() -> getRestAPIFactory().getHoldsAPI(getAdminUser()).getChildren(hold2.getId()).getEntries().size() () -> getRestAPIFactory().getHoldsAPI(getAdminUser()).getChildren(hold2.getId()).getEntries().size() == NUMBER_OF_FILES - 1);
== NUMBER_OF_FILES - 1);
await().atMost(30, TimeUnit.SECONDS).until( await().atMost(30, TimeUnit.SECONDS).until(
() -> getRestAPIFactory().getHoldsAPI(userAddHoldPermission) () -> getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getBulkStatus(hold2.getId(), bulkOperationEntry.getBulkStatusId()).getProcessedItems() .getBulkStatus(hold2.getId(), bulkOperationEntry.getBulkStatusId()).getProcessedItems() == NUMBER_OF_FILES);
== NUMBER_OF_FILES);
List<String> holdChildrenNodeRefs = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) List<String> holdChildrenNodeRefs = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getChildren(hold2.getId()).getEntries().stream().map(HoldChildEntry::getEntry).map( .getChildren(hold2.getId()).getEntries().stream().map(HoldChildEntry::getEntry).map(
HoldChild::getId).toList(); HoldChild::getId)
.toList();
assertEquals(addedFiles.stream().skip(1).map(FileModel::getNodeRefWithoutVersion).sorted().toList(), assertEquals(addedFiles.stream().skip(1).map(FileModel::getNodeRefWithoutVersion).sorted().toList(),
holdChildrenNodeRefs.stream().sorted().toList()); holdChildrenNodeRefs.stream().sorted().toList());
STEP("Check the bulk status."); STEP("Check the bulk status.");
HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getBulkStatus(hold2.getId(), bulkOperationEntry.getBulkStatusId()); .getBulkStatus(hold2.getId(), bulkOperationEntry.getBulkStatusId());
assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, 1, ACCESS_DENIED_ERROR_MESSAGE, holdBulkOperation); assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, 1, ACCESS_DENIED_ERROR_MESSAGE, holdBulkOperation);
STEP("Check the bulk statuses."); STEP("Check the bulk statuses.");
HoldBulkStatusCollection holdBulkStatusCollection = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkStatusCollection holdBulkStatusCollection = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.getBulkStatuses(hold2.getId()); .getBulkStatuses(hold2.getId());
assertEquals(List.of(holdBulkStatus), assertEquals(List.of(holdBulkStatus),
holdBulkStatusCollection.getEntries().stream().map(HoldBulkStatusEntry::getEntry).toList()); holdBulkStatusCollection.getEntries().stream().map(HoldBulkStatusEntry::getEntry).toList());
// Revert the permissions // Revert the permissions
contentActions.setPermissionForUser(getAdminUser().getUsername(), getAdminUser().getPassword(), contentActions.setPermissionForUser(getAdminUser().getUsername(), getAdminUser().getPassword(),
testSite.getId(), addedFiles.get(0).getName(), userAddHoldPermission.getUsername(), testSite.getId(), addedFiles.get(0).getName(), userAddHoldPermission.getUsername(),
UserRole.SiteCollaborator.getRoleId(), true); UserRole.SiteCollaborator.getRoleId(), true);
} }
/** /**
* Given an unauthenticated user * Given an unauthenticated user When the user adds content from a site to a hold using the bulk API Then the user receives unauthorized error
* When the user adds content from a site to a hold using the bulk API
* Then the user receives unauthorized error
*/ */
@Test @Test
public void testBulkProcessAsUnauthenticatedUser() public void testBulkProcessAsUnauthenticatedUser()
{ {
STEP("Start bulk process as unauthenticated user"); STEP("Start bulk process as unauthenticated user");
getRestAPIFactory().getHoldsAPI(new UserModel(getAdminUser().getUsername(), "wrongPassword")) getRestAPIFactory().getHoldsAPI(new UserModel(getAdminUser().getUsername(), "wrongPassword"))
.startBulkProcess(holdBulkOperation, hold.getId()); .startBulkProcess(holdBulkOperation, hold.getId());
STEP("Verify the response status code."); STEP("Verify the response status code.");
assertStatusCode(UNAUTHORIZED); assertStatusCode(UNAUTHORIZED);
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from a site to a hold using the bulk API And the hold does not exist Then the user receives not found error
* When the user adds content from a site to a hold using the bulk API
* And the hold does not exist
* Then the user receives not found error
*/ */
@Test @Test
public void testBulkProcessForNonExistentHold() public void testBulkProcessForNonExistentHold()
@@ -407,10 +400,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from a site to a hold using the bulk API and the bulk operation is invalid Then the user receives bad request error
* When the user adds content from a site to a hold using the bulk API
* and the bulk operation is invalid
* Then the user receives bad request error
*/ */
@Test @Test
public void testGetBulkStatusesForInvalidOperation() public void testGetBulkStatusesForInvalidOperation()
@@ -418,7 +408,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
STEP("Start bulk process for non existent hold"); STEP("Start bulk process for non existent hold");
HoldBulkOperation invalidHoldBulkOperation = HoldBulkOperation.builder().op(null) HoldBulkOperation invalidHoldBulkOperation = HoldBulkOperation.builder().op(null)
.query(holdBulkOperation.getQuery()).build(); .query(holdBulkOperation.getQuery()).build();
getRestAPIFactory().getHoldsAPI(getAdminUser()).startBulkProcess(invalidHoldBulkOperation, hold.getId()); getRestAPIFactory().getHoldsAPI(getAdminUser()).startBulkProcess(invalidHoldBulkOperation, hold.getId());
STEP("Verify the response status code."); STEP("Verify the response status code.");
@@ -426,10 +416,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from a site to a hold using the bulk API And the hold does not exist Then the user receives not found error
* When the user adds content from a site to a hold using the bulk API
* And the hold does not exist
* Then the user receives not found error
*/ */
@Test @Test
public void testGetBulkStatusForNonExistentHold() public void testGetBulkStatusForNonExistentHold()
@@ -442,10 +429,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from a site to a hold using the bulk API And the bulk status does not exist Then the user receives not found error
* When the user adds content from a site to a hold using the bulk API
* And the bulk status does not exist
* Then the user receives not found error
*/ */
@Test @Test
public void testGetBulkStatusForNonExistentBulkStatus() public void testGetBulkStatusForNonExistentBulkStatus()
@@ -458,10 +442,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from a site to a hold using the bulk API And the hold does not exist Then the user receives not found error
* When the user adds content from a site to a hold using the bulk API
* And the hold does not exist
* Then the user receives not found error
*/ */
@Test @Test
public void testGetBulkStatusesForNonExistentHold() public void testGetBulkStatusesForNonExistentHold()
@@ -474,9 +455,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from all sites to a hold using the bulk API to exceed the limit (30 items) Then the user receives bad request error
* When the user adds content from all sites to a hold using the bulk API to exceed the limit (30 items)
* Then the user receives bad request error
*/ */
@Test @Test
public void testExceedingBulkOperationLimit() public void testExceedingBulkOperationLimit()
@@ -486,8 +465,8 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
queryReq.setLanguage("afts"); queryReq.setLanguage("afts");
HoldBulkOperation exceedLimitOp = HoldBulkOperation.builder() HoldBulkOperation exceedLimitOp = HoldBulkOperation.builder()
.query(queryReq) .query(queryReq)
.op(HoldBulkOperationType.ADD).build(); .op(HoldBulkOperationType.ADD).build();
STEP("Start bulk process to exceed the limit"); STEP("Start bulk process to exceed the limit");
getRestAPIFactory().getHoldsAPI(getAdminUser()).startBulkProcess(exceedLimitOp, hold.getId()); getRestAPIFactory().getHoldsAPI(getAdminUser()).startBulkProcess(exceedLimitOp, hold.getId());
@@ -497,26 +476,24 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from a site to a hold using the bulk API And then the user cancels the bulk operation Then the user receives OK status code
* When the user adds content from a site to a hold using the bulk API
* And then the user cancels the bulk operation
* Then the user receives OK status code
*/ */
@Test @Test
public void testBulkProcessCancellationWithAllowedUser() public void testBulkProcessCancellationWithAllowedUser()
{ {
Hold hold4 = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold( Hold hold4 = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold(
Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION) Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION)
.reason(HOLD_REASON).build(), FILE_PLAN_ALIAS); .reason(HOLD_REASON).build(),
FILE_PLAN_ALIAS);
holds.add(hold4); holds.add(hold4);
UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite,
UserRole.SiteCollaborator, hold4.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); UserRole.SiteCollaborator, hold4.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
users.add(userAddHoldPermission); users.add(userAddHoldPermission);
STEP("Add content from the site to the hold using the bulk API."); STEP("Add content from the site to the hold using the bulk API.");
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.startBulkProcess(holdBulkOperation, hold4.getId()); .startBulkProcess(holdBulkOperation, hold4.getId());
// Verify the status code // Verify the status code
assertStatusCode(ACCEPTED); assertStatusCode(ACCEPTED);
@@ -524,47 +501,44 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
STEP("Cancel the bulk operation."); STEP("Cancel the bulk operation.");
getRestAPIFactory().getHoldsAPI(userAddHoldPermission) getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.cancelBulkOperation(hold4.getId(), bulkOperationEntry.getBulkStatusId(), new BulkBodyCancel()); .cancelBulkOperation(hold4.getId(), bulkOperationEntry.getBulkStatusId(), new BulkBodyCancel());
// Verify the status code // Verify the status code
assertStatusCode(OK); assertStatusCode(OK);
} }
/** /**
* Given a user with the add to hold capability and hold filing permission * Given a user with the add to hold capability and hold filing permission When the user adds content from a site to a hold using the bulk API And a 2nd user without the add to hold capability cancels the bulk operation Then the 2nd user receives access denied error
* When the user adds content from a site to a hold using the bulk API
* And a 2nd user without the add to hold capability cancels the bulk operation
* Then the 2nd user receives access denied error
*/ */
@Test @Test
public void testBulkProcessCancellationWithUserWithoutAddToHoldCapability() public void testBulkProcessCancellationWithUserWithoutAddToHoldCapability()
{ {
Hold hold5 = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold( Hold hold5 = getRestAPIFactory().getFilePlansAPI(getAdminUser()).createHold(
Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION) Hold.builder().name("HOLD" + generateTestPrefix(AddToHoldsV1Tests.class)).description(HOLD_DESCRIPTION)
.reason(HOLD_REASON).build(), FILE_PLAN_ALIAS); .reason(HOLD_REASON).build(),
FILE_PLAN_ALIAS);
holds.add(hold5); holds.add(hold5);
UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserModel userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite,
UserRole.SiteCollaborator, hold5.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); UserRole.SiteCollaborator, hold5.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
users.add(userAddHoldPermission); users.add(userAddHoldPermission);
STEP("Add content from the site to the hold using the bulk API."); STEP("Add content from the site to the hold using the bulk API.");
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission) HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.startBulkProcess(holdBulkOperation, hold5.getId()); .startBulkProcess(holdBulkOperation, hold5.getId());
// Verify the status code // Verify the status code
assertStatusCode(ACCEPTED); assertStatusCode(ACCEPTED);
assertEquals(NUMBER_OF_FILES, bulkOperationEntry.getTotalItems()); assertEquals(NUMBER_OF_FILES, bulkOperationEntry.getTotalItems());
UserModel userWithoutAddToHoldCapability = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserModel userWithoutAddToHoldCapability = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite,
UserRole UserRole.SiteCollaborator,
.SiteCollaborator, hold5.getId(), UserRoles.ROLE_RM_POWER_USER, PERMISSION_FILING);
hold5.getId(), UserRoles.ROLE_RM_POWER_USER, PERMISSION_FILING);
users.add(userWithoutAddToHoldCapability); users.add(userWithoutAddToHoldCapability);
STEP("Cancel the bulk operation."); STEP("Cancel the bulk operation.");
getRestAPIFactory().getHoldsAPI(userWithoutAddToHoldCapability) getRestAPIFactory().getHoldsAPI(userWithoutAddToHoldCapability)
.cancelBulkOperation(hold5.getId(), bulkOperationEntry.getBulkStatusId(), new BulkBodyCancel()); .cancelBulkOperation(hold5.getId(), bulkOperationEntry.getBulkStatusId(), new BulkBodyCancel());
STEP("Verify the response status code and the error message."); STEP("Verify the response status code and the error message.");
assertStatusCode(FORBIDDEN); assertStatusCode(FORBIDDEN);
@@ -572,7 +546,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
} }
private void assertBulkProcessStatus(HoldBulkStatus holdBulkStatus, long expectedProcessedItems, private void assertBulkProcessStatus(HoldBulkStatus holdBulkStatus, long expectedProcessedItems,
int expectedErrorsCount, String expectedErrorMessage, HoldBulkOperation holdBulkOperation) int expectedErrorsCount, String expectedErrorMessage, HoldBulkOperation holdBulkOperation)
{ {
assertEquals("DONE", holdBulkStatus.getStatus()); assertEquals("DONE", holdBulkStatus.getStatus());
assertEquals(expectedProcessedItems, holdBulkStatus.getTotalItems()); assertEquals(expectedProcessedItems, holdBulkStatus.getTotalItems());