Merge branch 'master' of https://github.com/Alfresco/governance-services into feature/APPS-908_RecordSearchResultLimit

This commit is contained in:
rodicasutu
2021-04-22 10:30:18 +03:00
35 changed files with 694 additions and 1008 deletions

View File

@@ -94,12 +94,12 @@ public class AuditAddToHoldTests extends BaseRMRestTest
private RecordCategory recordCategory;
private RecordCategoryChild recordFolder;
private List<AuditEntry> auditEntries;
private List<String> holdsList = asList(HOLD1, HOLD2);
private final List<String> holdsList = asList(HOLD1, HOLD2);
private List<String> holdsListRef = new ArrayList<>();
private String hold1NodeRef;
@BeforeClass (alwaysRun = true)
public void preconditionForAuditAddToHoldTests() throws Exception
public void preconditionForAuditAddToHoldTests()
{
STEP("Create 2 holds.");
hold1NodeRef = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(),
@@ -128,10 +128,9 @@ public class AuditAddToHoldTests extends BaseRMRestTest
* Data provider with valid nodes that can be added to a hold
*
* @return the node id, the node name and the node path
* @throws Exception
*/
@DataProvider (name = "validNodesForAddToHold")
public Object[][] getValidNodesForAddToHold() throws Exception
public Object[][] getValidNodesForAddToHold()
{
FileModel contentToBeAdded = dataContent.usingAdmin().usingSite(privateSite)
.createContent(CMISUtil.DocumentType.TEXT_PLAIN);
@@ -184,7 +183,7 @@ public class AuditAddToHoldTests extends BaseRMRestTest
* Then the add to hold event isn't audited
*/
@Test
public void unsuccessfulAddToHoldIsNotAudited() throws Exception
public void unsuccessfulAddToHoldIsNotAudited()
{
STEP("Create a new record");
Record recordToBeAdded = createElectronicRecord(recordFolder.getId(), PREFIX + "record");
@@ -207,7 +206,7 @@ public class AuditAddToHoldTests extends BaseRMRestTest
* Then only an entry has been created in the audit log for the record folder added
*/
@Test
public void addToHoldIsNotAuditedForRecordFolderChildren() throws Exception
public void addToHoldIsNotAuditedForRecordFolderChildren()
{
STEP("Create a new record folder with a record inside");
RecordCategoryChild notEmptyRecFolder = createRecordFolder(recordCategory.getId(), PREFIX + "notEmptyRecFolder");
@@ -232,7 +231,7 @@ public class AuditAddToHoldTests extends BaseRMRestTest
* Then multiple entries have been created in the audit log for each add to hold event
*/
@Test
public void addToHoldIsAuditedInBulkAddition() throws Exception
public void addToHoldIsAuditedInBulkAddition()
{
STEP("Create a new record");
Record recordToBeAdded = createElectronicRecord(recordFolder.getId(), PREFIX + "record");
@@ -308,6 +307,6 @@ public class AuditAddToHoldTests extends BaseRMRestTest
holdsListRef.forEach(holdRef -> holdsAPI.deleteHold(getAdminUser(), holdRef));
dataSite.usingAdmin().deleteSite(privateSite);
asList(rmAdmin, rmManagerNoReadOnHold, rmManagerNoReadOnNode).forEach(user -> getDataUser().usingAdmin().deleteUser(user));
getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(recordCategory.getId());
deleteRecordCategory(recordCategory.getId());
}
}

View File

@@ -68,7 +68,7 @@ public class AuditCreateHoldTests extends BaseRMRestTest
private final String HOLD1 = PREFIX + "createHold";
private final String HOLD2 = PREFIX + "createHold2";
private final String HOLD3 = PREFIX + "createHold3";
private List<String> holdsListRef = new ArrayList<>();
private final List<String> holdsListRef = new ArrayList<>();
@Autowired
private RMAuditService rmAuditService;

View File

@@ -42,7 +42,6 @@ import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -83,7 +82,6 @@ public class AuditRemoveFromHoldTests extends BaseRMRestTest
private final String HOLD1 = PREFIX + "hold1";
private final String HOLD2 = PREFIX + "hold2";
private final String HOLD3 = PREFIX + "hold3";
private final String DELETED_HOLD = PREFIX + "deletedHold";
@Autowired
private RMAuditService rmAuditService;
@@ -98,13 +96,13 @@ public class AuditRemoveFromHoldTests extends BaseRMRestTest
private RecordCategoryChild recordFolder, heldRecordFolder;
private Record heldRecord;
private List<AuditEntry> auditEntries;
private List<String> holdsList = asList(HOLD1, HOLD2, HOLD3);
private final List<String> holdsList = asList(HOLD1, HOLD2, HOLD3);
private List<String> holdsListRef = new ArrayList<>();
private FileModel heldContent;
private String hold1NodeRef;
@BeforeClass (alwaysRun = true)
public void preconditionForAuditRemoveFromHoldTests() throws Exception
public void preconditionForAuditRemoveFromHoldTests()
{
STEP("Create an user with full rights to remove content from a hold.");
rmAdmin = roleService.createUserWithRMRole(UserRoles.ROLE_RM_ADMIN.roleId);
@@ -117,7 +115,6 @@ public class AuditRemoveFromHoldTests extends BaseRMRestTest
HOLD1, HOLD_REASON, HOLD_DESCRIPTION);
String hold2NodeRef = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD2, HOLD_REASON, HOLD_DESCRIPTION);
String hold3NodeRef = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD3, HOLD_REASON, HOLD_DESCRIPTION);
String deleteNodeRef = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser().getPassword(), DELETED_HOLD, HOLD_REASON, HOLD_DESCRIPTION);
holdsListRef = asList(hold1NodeRef, hold2NodeRef, hold3NodeRef);
STEP("Create a new record category with a record folder.");
@@ -216,7 +213,7 @@ public class AuditRemoveFromHoldTests extends BaseRMRestTest
* Then only an entry has been created in the audit log for the record folder removed
*/
@Test
public void removeFromHoldNotAuditedForRecordFolderChildren() throws Exception
public void removeFromHoldNotAuditedForRecordFolderChildren()
{
STEP("Create a new record folder with a record inside");
RecordCategoryChild notEmptyRecFolder = createRecordFolder(recordCategory.getId(), PREFIX + "notEmptyRecFolder");
@@ -324,6 +321,6 @@ public class AuditRemoveFromHoldTests extends BaseRMRestTest
holdsListRef.forEach(holdRef -> holdsAPI.deleteHold(getAdminUser(), holdRef));
dataSite.usingAdmin().deleteSite(privateSite);
asList(rmAdmin, rmManagerNoReadOnHold, rmManagerNoReadOnNode).forEach(user -> getDataUser().usingAdmin().deleteUser(user));
getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(recordCategory.getId());
deleteRecordCategory(recordCategory.getId());
}
}

View File

@@ -59,8 +59,6 @@ public class AuditUserEventsTests extends BaseRMRestTest
* Given I have created a new user
* When I view the RM audit
* Then there is an entry showing that I created a user
*
* @throws Exception
*/
@Test
@AlfrescoTest(jira = "RM-6223")

View File

@@ -143,7 +143,7 @@ public class BaseRMRestTest extends RestTest
/** Valid root containers where electronic and non-electronic records can be created */
@DataProvider(name = "validRootContainers")
public Object[][] getValidRootContainers() throws Exception
public Object[][] getValidRootContainers()
{
return new String[][]
{
@@ -171,7 +171,7 @@ public class BaseRMRestTest extends RestTest
* Helper method to create the RM Site via the POST request
* if the site doesn't exist
*/
public void createRMSiteIfNotExists() throws Exception
public void createRMSiteIfNotExists()
{
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
@@ -189,7 +189,7 @@ public class BaseRMRestTest extends RestTest
/**
* Helper method to delete the RM site if exists and to create a new one
*/
public void createRMSite(RMSite rmSiteModel) throws Exception
public void createRMSite(RMSite rmSiteModel)
{
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
if (rmSiteAPI.existsRMSite())
@@ -207,9 +207,9 @@ public class BaseRMRestTest extends RestTest
*
* @param categoryName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
* @throws RuntimeException on unsuccessful component creation
*/
public RecordCategory createRootCategory(String categoryName) throws Exception
public RecordCategory createRootCategory(String categoryName)
{
return createRootCategory(getAdminUser(), categoryName, RECORD_CATEGORY_TITLE);
}
@@ -233,9 +233,9 @@ public class BaseRMRestTest extends RestTest
* @param categoryName The name of the category
* @param categoryTitle The title of the category
* @return The created category
* @throws Exception on unsuccessful component creation
* @throws RuntimeException on unsuccessful component creation
*/
public RecordCategory createRootCategory(String categoryName, String categoryTitle) throws Exception
public RecordCategory createRootCategory(String categoryName, String categoryTitle)
{
return createRootCategory(getAdminUser(), categoryName, categoryTitle);
}
@@ -263,9 +263,9 @@ public class BaseRMRestTest extends RestTest
* @param name The name of the record category child
* @param type The type of the record category child
* @return The created {@link RecordCategoryChild}
* @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)}
* @throws RuntimeException on unsuccessful component creation
*/
public RecordCategoryChild createRecordCategoryChild(UserModel user, String recordCategoryId, String name, String type) throws Exception
public RecordCategoryChild createRecordCategoryChild(UserModel user, String recordCategoryId, String name, String type)
{
RecordCategoryChild recordCategoryChildModel = createRecordCategoryChildModel(name, type);
return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordCategoryChildModel, recordCategoryId);
@@ -278,9 +278,9 @@ public class BaseRMRestTest extends RestTest
* @param name The name of the record category child
* @param type The type of the record category child
* @return The created {@link RecordCategoryChild}
* @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)}
* @throws RuntimeException on unsuccessful component creation
*/
public RecordCategoryChild createRecordCategoryChild(String recordCategoryId, String name, String type) throws Exception
public RecordCategoryChild createRecordCategoryChild(String recordCategoryId, String name, String type)
{
return createRecordCategoryChild(getAdminUser(), recordCategoryId, name, type);
}
@@ -291,9 +291,9 @@ public class BaseRMRestTest extends RestTest
* @param recordCategoryId The id of the record category
* @param name The name of the record category child
* @return The created {@link RecordCategoryChild}
* @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)}
* @throws RuntimeException on unsuccessful component creation
*/
public RecordCategoryChild createRecordCategory(String recordCategoryId, String name) throws Exception
public RecordCategoryChild createRecordCategory(String recordCategoryId, String name)
{
return createRecordCategoryChild(getAdminUser(), recordCategoryId, name, RECORD_CATEGORY_TYPE);
}
@@ -304,9 +304,9 @@ public class BaseRMRestTest extends RestTest
* @param recordCategoryId The id of the record category
* @param name The name of the record category child
* @return The created {@link RecordCategoryChild}
* @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)}
* @throws RuntimeException on unsuccessful component creation
*/
public RecordCategoryChild createRecordFolder(String recordCategoryId, String name) throws Exception
public RecordCategoryChild createRecordFolder(String recordCategoryId, String name)
{
return createRecordCategoryChild(getAdminUser(), recordCategoryId, name, RECORD_FOLDER_TYPE);
}
@@ -332,9 +332,9 @@ public class BaseRMRestTest extends RestTest
* @param recordCategoryId The id of the record category
* @param name The name of the folder
* @return The created folder
* @throws Exception on unsuccessful component creation
* @throws RuntimeException on unsuccessful component creation
*/
public RecordCategoryChild createFolder(String recordCategoryId, String name) throws Exception
public RecordCategoryChild createFolder(String recordCategoryId, String name)
{
return createFolder(getAdminUser(), recordCategoryId, name);
}
@@ -346,9 +346,9 @@ public class BaseRMRestTest extends RestTest
* @param parentId The id of the parent folder
* @param nodeType The child type
* @return The created folder
* @throws Exception on unsuccessful component creation
* @throws RuntimeException on unsuccessful component creation
*/
public UnfiledContainerChild createUnfiledRecordsFolderChild(UserModel user, String parentId, String childName, String nodeType) throws Exception
public UnfiledContainerChild createUnfiledRecordsFolderChild(UserModel user, String parentId, String childName, String nodeType)
{
UnfiledContainerChild childModel = createUnfiledContainerChildModel(childName, nodeType);
UnfiledContainerChild child = getRestAPIFactory().getUnfiledRecordFoldersAPI(user).createUnfiledRecordFolderChild(childModel, parentId);
@@ -363,9 +363,9 @@ public class BaseRMRestTest extends RestTest
* @param parentId The id of the parent folder
* @param nodeType The child type
* @return The created folder
* @throws Exception on unsuccessful component creation
* @throws RuntimeException on unsuccessful component creation
*/
public UnfiledContainerChild createUnfiledRecordsFolderChild(String parentId, String childName, String nodeType) throws Exception
public UnfiledContainerChild createUnfiledRecordsFolderChild(String parentId, String childName, String nodeType)
{
return createUnfiledRecordsFolderChild(getAdminUser(), parentId, childName, nodeType);
}
@@ -376,11 +376,11 @@ public class BaseRMRestTest extends RestTest
* @param user The user under whose privileges this structure is going to be created
* @param parentId The id of the parent container
* @param childName The name of the child
* @oaram nodeType the child type
* @param nodeType the child type
* @return The created chid
* @throws Exception on unsuccessful child creation
* @throws RuntimeException on unsuccessful child creation
*/
public UnfiledContainerChild createUnfiledContainerChild(UserModel user, String parentId, String childName, String nodeType) throws Exception
public UnfiledContainerChild createUnfiledContainerChild(UserModel user, String parentId, String childName, String nodeType)
{
UnfiledContainerChild child = null;
UnfiledContainerChild childModel = createUnfiledContainerChildModel(childName, nodeType);
@@ -403,11 +403,11 @@ public class BaseRMRestTest extends RestTest
*
* @param parentId The id of the parent container
* @param childName The name of the child
* @oaram nodeType the child type
* @param nodeType the child type
* @return The created chid
* @throws Exception on unsuccessful child creation
* @throws RuntimeException on unsuccessful child creation
*/
public UnfiledContainerChild createUnfiledContainerChild(String parentId, String childName, String nodeType) throws Exception
public UnfiledContainerChild createUnfiledContainerChild(String parentId, String childName, String nodeType)
{
return createUnfiledContainerChild(getAdminUser(), parentId, childName, nodeType);
}
@@ -417,9 +417,8 @@ public class BaseRMRestTest extends RestTest
*
* @param folderId The id of the folder
* @return The closed folder
* @throws Exception
*/
protected RecordFolder closeFolder(String folderId) throws Exception
protected RecordFolder closeFolder(String folderId)
{
RecordFolder recordFolderModel = RecordFolder.builder()
.properties(RecordFolderProperties.builder()
@@ -437,9 +436,8 @@ public class BaseRMRestTest extends RestTest
*
* @param recordId The id of the record to complete
* @return The completed record
* @throws Exception
*/
public Record completeRecord(String recordId) throws Exception
public Record completeRecord(String recordId)
{
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
List<String> aspects = recordsAPI.getRecord(recordId).getAspectNames();
@@ -532,7 +530,6 @@ public class BaseRMRestTest extends RestTest
* @param parentId the id of the parent
* @param name the name of the record
* @return the created record
* @throws Exception
*/
public Record createElectronicRecord(String parentId, String name)
{
@@ -546,7 +543,6 @@ public class BaseRMRestTest extends RestTest
* @param parentId the id of the parent
* @param name the name of the record
* @return the created record
* @throws Exception
*/
public Record createElectronicRecord(String parentId, String name, UserModel user)
{
@@ -561,9 +557,8 @@ public class BaseRMRestTest extends RestTest
* @param parentId the id of the parent
* @param name the name of the record
* @return the created record
* @throws Exception
*/
public Record createNonElectronicRecord(String parentId, String name) throws Exception
public Record createNonElectronicRecord(String parentId, String name)
{
return createNonElectronicRecord(parentId, name, null);
}
@@ -575,9 +570,8 @@ public class BaseRMRestTest extends RestTest
* @param name the name of the record
* @param user the user who creates the non-electronic record
* @return the created record
* @throws Exception
*/
public Record createNonElectronicRecord(String parentId, String name, UserModel user) throws Exception
public Record createNonElectronicRecord(String parentId, String name, UserModel user)
{
RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI(user);
Record recordModel = Record.builder().name(name).nodeType(NON_ELECTRONIC_RECORD_TYPE).build();
@@ -623,9 +617,8 @@ public class BaseRMRestTest extends RestTest
* @param user
* @param term
* @return
* @throws Exception
*/
public List<String> searchForContentAsUser(UserModel user, String term) throws Exception
public List<String> searchForContentAsUser(UserModel user, String term)
{
getRestAPIFactory().getRmRestWrapper().authenticateUser(user);
RestRequestQueryModel queryReq = new RestRequestQueryModel();
@@ -833,7 +826,7 @@ public class BaseRMRestTest extends RestTest
{
try
{
Utility.sleep(5000, 15000,
Utility.sleep(1000, 10000,
() -> {
Optional<UnfiledContainerChildEntry> matchingRecord = getRestAPIFactory().getUnfiledContainersAPI()
.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS)
@@ -863,7 +856,7 @@ public class BaseRMRestTest extends RestTest
{
try
{
Utility.sleep(5000, 15000,
Utility.sleep(1000, 10000,
() -> {
Optional<RecordFolderEntry> matchingRecord = getRestAPIFactory().getRecordFolderAPI()
.getRecordFolderChildren(recFolder.getId())
@@ -892,7 +885,7 @@ public class BaseRMRestTest extends RestTest
{
try
{
Utility.sleep(5000, 15000,
Utility.sleep(1000, 10000,
() -> {
UnfiledContainerChildEntry matchingRecord = getRestAPIFactory().getUnfiledContainersAPI()
.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS, "include=properties,aspectNames")
@@ -926,7 +919,7 @@ public class BaseRMRestTest extends RestTest
{
try
{
Utility.sleep(5000, 15000,
Utility.sleep(1000, 10000,
() -> {
RecordFolderEntry matchingRecord = getRestAPIFactory().getRecordFolderAPI()
.getRecordFolderChildren(recordFolder.getId(),"include=properties,aspectNames")

View File

@@ -45,6 +45,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_MANAGER;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.alfresco.utility.data.RandomData.getRandomName;
import static org.springframework.http.HttpStatus.CONFLICT;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.FORBIDDEN;
@@ -65,7 +66,6 @@ import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.base.DataProviderClass;
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
import org.alfresco.rest.rm.community.model.fileplan.FilePlanProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryCollection;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryProperties;
@@ -115,8 +115,10 @@ public class FilePlanTests extends BaseRMRestTest
* Then I get the 404 response code
* </pre>
*/
@Test
public void getFilePlanWhenRMIsNotCreated() throws Exception
@Test (priority = 1)
// Set priority to 1 in order for this test to run last one in this class. The rm site is created only once at the
// beginning of the class and because this test deletes the rm site, the other tests might be affected
public void getFilePlanWhenRMIsNotCreated()
{
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
@@ -141,19 +143,18 @@ public class FilePlanTests extends BaseRMRestTest
* </pre>
*/
@Test
public void getFilePlanWhenRMIsCreated() throws Exception
public void getFilePlanWhenRMIsCreated()
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS);
FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS);
// Check the response code
assertStatusCode(OK);
//check file plan details
assertTrue(filePlan.getNodeType().equals(FilePlanComponentType.FILE_PLAN_TYPE));
assertTrue(filePlan.getName().equals(ContainerName.documentLibrary.toString()));
assertEquals(FILE_PLAN_TYPE, filePlan.getNodeType());
assertEquals(ContainerName.documentLibrary.toString(), filePlan.getName());
}
/**
@@ -164,11 +165,8 @@ public class FilePlanTests extends BaseRMRestTest
* </pre>
*/
@Test
public void includeAllowableOperations() throws Exception
public void includeAllowableOperations()
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Check the list of allowableOperations returned
FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS, "include=" + ALLOWABLE_OPERATIONS);
@@ -178,7 +176,6 @@ public class FilePlanTests extends BaseRMRestTest
// Check the list of allowableOperations doesn't contain DELETE operation
assertFalse(filePlan.getAllowableOperations().contains(DELETE),
"The list of allowable operations contains delete option" + filePlan.getAllowableOperations().toString());
}
/**
@@ -189,11 +186,8 @@ public class FilePlanTests extends BaseRMRestTest
* </pre>
*/
@Test
public void getFilePlanWithNonRMuser() throws Exception
public void getFilePlanWithNonRMuser()
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Create a random user
UserModel nonRMuser = getDataUser().createRandomTestUser("testUser");
@@ -212,14 +206,11 @@ public class FilePlanTests extends BaseRMRestTest
*/
@Test
@Bug (id = "RM-4295")
public void updateFilePlan() throws Exception
public void updateFilePlan()
{
String FILE_PLAN_DESCRIPTION = "Description updated " + getRandomAlphanumeric();
String FILE_PLAN_TITLE = "Title updated " + getRandomAlphanumeric();
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Build object for updating the filePlan
FilePlan filePlanComponent = FilePlan.builder()
.properties(FilePlanProperties.builder()
@@ -256,16 +247,11 @@ public class FilePlanTests extends BaseRMRestTest
*/
@Test
@Bug (id = "RM-4295")
public void updateFilePlanName() throws Exception
public void updateFilePlanName()
{
String FILE_PLAN_NAME = "File Plan name updated " + getRandomAlphanumeric();
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Build object for updating the filePlan
FilePlan filePlanComponent = FilePlan.builder()
.name(FILE_PLAN_NAME)
.name(getRandomName("File Plan name updated "))
.build();
// Update the file plan
@@ -294,7 +280,7 @@ public class FilePlanTests extends BaseRMRestTest
dataProviderClass = DataProviderClass.class,
dataProvider = "categoryTypes"
)
public void createFilePlanChildren(String nodeType) throws Exception
public void createFilePlanChildren(String nodeType)
{
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
@@ -338,7 +324,7 @@ public class FilePlanTests extends BaseRMRestTest
*/
@Test
@Bug(id = "RM-5116")
public void createDuplicateCategories() throws Exception
public void createDuplicateCategories()
{
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
@@ -375,15 +361,13 @@ public class FilePlanTests extends BaseRMRestTest
}
@Test
public void listFilePlanChildren() throws Exception
public void listFilePlanChildren()
{
//delete all the root categories
getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry ->
{
getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(recordCategoryEntry.getEntry().getId());
});
deleteRecordCategory(recordCategoryEntry.getEntry().getId()));
// Add child folders
ArrayList<RecordCategory> children = new ArrayList<RecordCategory>();
ArrayList<RecordCategory> children = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_CHILDREN; i++)
{
String categoryName = "Category name " + getRandomAlphanumeric();
@@ -415,7 +399,7 @@ public class FilePlanTests extends BaseRMRestTest
RecordCategory createdComponent = children.stream()
.filter(child -> child.getId().equals(recordCategoryChildId))
.findFirst()
.get();
.orElseThrow();
// Created by
assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername());
@@ -444,7 +428,7 @@ public class FilePlanTests extends BaseRMRestTest
description = "Create a record folder/unfiled container/unfiled folder/record/file plan container",
dataProvider = "childrenNotAllowedForFilePlan"
)
public void createChildrenNotAllowedInFilePlan(String nodeType) throws Exception
public void createChildrenNotAllowedInFilePlan(String nodeType)
{
String componentName = "Component" + getRandomAlphanumeric();
@@ -468,16 +452,13 @@ public class FilePlanTests extends BaseRMRestTest
}
@Test
public void listChildrenUserPermission() throws Exception
public void listChildrenUserPermission()
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Create a random user
UserModel managerUser = getDataUser().createRandomTestUser("managerUser");
// Add child folders
ArrayList<RecordCategory> children = new ArrayList<RecordCategory>();
ArrayList<RecordCategory> children = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_CHILDREN/2; i++)
{
String categoryName = "Category name " + getRandomAlphanumeric();
@@ -493,7 +474,7 @@ public class FilePlanTests extends BaseRMRestTest
getRestAPIFactory().getFilePlansAPI(managerUser).getRootRecordCategories(FILE_PLAN_ALIAS)
.assertThat().entriesListIsEmpty().assertThat().paginationExist();
ArrayList<RecordCategory> childrenManager = new ArrayList<RecordCategory>();
ArrayList<RecordCategory> childrenManager = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_CHILDREN / 2; i++)
{
String categoryName = "Category for manager " + getRandomAlphanumeric();

View File

@@ -95,7 +95,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest
private FolderModel testFolder;
private FileModel testFile;
private RecordCategory recordCategory;
private RecordCategoryChild recordFolder, subcategoryRecordFolder, subCategory, closedRecordFolder, recordFolderWithSpacesInName;
private RecordCategoryChild recordFolder, subcategoryRecordFolder, closedRecordFolder, recordFolderWithSpacesInName;
private UnfiledContainerChild unfiledContainerFolder;
private String holdNodeRef;
@@ -154,7 +154,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest
}
@BeforeClass (alwaysRun = true)
public void declareAndFileDocumentAsRecordSetup() throws Exception
public void declareAndFileDocumentAsRecordSetup()
{
STEP("Create test collaboration site to store documents in.");
publicSite = dataSite.usingAdmin().createPublicRandomSite();
@@ -164,7 +164,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest
STEP("Create record categories and record folders");
recordCategory = createRootCategory(getRandomName("recordCategory"));
subCategory = createRecordCategory(recordCategory.getId(), getRandomName("subCategory"));
RecordCategoryChild subCategory = createRecordCategory(recordCategory.getId(), getRandomName("subCategory"));
recordFolder = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
subcategoryRecordFolder = createFolder(subCategory.getId(), getRandomName("recordFolder"));
unfiledContainerFolder = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS,
@@ -180,7 +180,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest
}
@BeforeMethod(alwaysRun = true)
public void createDocument() throws Exception
public void createDocument()
{
STEP("Create a document in the collaboration site");
testFile = dataContent.usingSite(publicSite)
@@ -429,7 +429,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest
* Then I get an invalid operation exception
*/
@Test
public void declareAndFileTwiceDifferentLocations() throws Exception
public void declareAndFileTwiceDifferentLocations()
{
STEP("Create a document in the collaboration site");
FileModel testFile = dataContent.usingSite(publicSite).usingAdmin()

View File

@@ -76,7 +76,7 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
RecordsAPI recordsAPI;
@BeforeClass(alwaysRun=true)
public void declareDocumentAsRecordSetup() throws Exception
public void declareDocumentAsRecordSetup()
{
// create test user and test collaboration site to store documents in
testUser = getDataUser().createRandomTestUser();
@@ -208,11 +208,10 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
* When I declare the record as a record
* Then I get a invalid operation exception
* </pre>
* @throws Exception for malformed JSON API response
*/
@Test(description = "Record can't be declared a record")
@AlfrescoTest(jira = "RM-4429")
public void recordCantBeDeclaredARecord() throws Exception
public void recordCantBeDeclaredARecord()
{
// create a non-electronic record in a random folder
Record nonelectronicRecord = Record.builder()
@@ -238,11 +237,10 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
* When I declare the node as a record
* Then I get a invalid operation exception
* </pre>
* @throws Exception for malformed JSON API response
*/
@Test(description = "Node that is not a document can't be declared a record")
@AlfrescoTest(jira = "RM-4429")
public void nonDocumentCantBeDeclaredARecord() throws Exception
public void nonDocumentCantBeDeclaredARecord()
{
FolderModel otherTestFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder();
@@ -258,7 +256,7 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
*/
@Test (description = "Declaring as record a file that already has its version declared as record is successful")
@AlfrescoTest (jira = "RM-6786")
public void declareAsRecordAFileWithARecordVersion() throws Exception
public void declareAsRecordAFileWithARecordVersion()
{
STEP("Create a file.");
FileModel testFile = dataContent.usingAdmin().usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN);

View File

@@ -99,7 +99,7 @@ public class FileVersionAsRecordTests extends BaseRMRestTest
private HoldsAPI holdsAPI;
@BeforeClass (alwaysRun = true)
public void declareAndFileVersionAsRecordSetup() throws Exception
public void declareAndFileVersionAsRecordSetup()
{
STEP("Create test collaboration site to store documents in.");
publicSite = dataSite.usingAdmin().createPublicRandomSite();
@@ -127,7 +127,7 @@ public class FileVersionAsRecordTests extends BaseRMRestTest
}
@BeforeMethod (alwaysRun = true)
public void createDocument() throws Exception
public void createDocument()
{
STEP("Create a document in the collaboration site");
testFile = dataContent.usingSite(publicSite)

View File

@@ -98,8 +98,8 @@ public class AddToHoldsTests extends BaseRMRestTest
private String holdNodeRef;
private FileModel documentHeld, contentToAddToHold, contentAddToHoldNoPermission;
private UserModel userAddHoldPermission;
private List<UserModel> users = new ArrayList<>();
private List<String> nodesToBeClean = new ArrayList<>();
private final List<UserModel> users = new ArrayList<>();
private final List<String> nodesToBeClean = new ArrayList<>();
@Autowired
private HoldsAPI holdsAPI;
@@ -233,7 +233,7 @@ public class AddToHoldsTests extends BaseRMRestTest
* @return object with user model and the node ref to be added to hold
*/
@DataProvider (name = "userWithoutPermissionForAddToHold")
public Object[][] getUserWithoutPermissionForAddToHold() throws Exception
public Object[][] getUserWithoutPermissionForAddToHold()
{
//create record folder
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
@@ -299,7 +299,7 @@ public class AddToHoldsTests extends BaseRMRestTest
* Data provider with invalid node types that can be added to a hold
*/
@DataProvider (name = "invalidNodesForAddToHold")
public Object[][] getInvalidNodesForAddToHold() throws Exception
public Object[][] getInvalidNodesForAddToHold()
{
//create locked file
FileModel contentLocked = dataContent.usingAdmin().usingSite(testSite)
@@ -360,6 +360,6 @@ public class AddToHoldsTests extends BaseRMRestTest
holdsAPI.deleteHold(getAdminUser(), holdNodeRef);
dataSite.usingAdmin().deleteSite(testSite);
users.forEach(user -> getDataUser().usingAdmin().deleteUser(user));
nodesToBeClean.forEach( category -> getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(category));
nodesToBeClean.forEach( category -> deleteRecordCategory(category));
}
}

View File

@@ -96,7 +96,7 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
@BeforeClass (alwaysRun = true)
public void preconditionForPreventActionsOnFrozenContent() throws Exception
public void preconditionForPreventActionsOnFrozenContent()
{
STEP("Create a hold.");
holdNodeRef = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser().getUsername(),
@@ -262,12 +262,10 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest
* When I add a disposition schedule
* Then I am successful
* And the record search disposition schedule properties are updated
*
* @throws Exception
*/
@Test
@AlfrescoTest (jira = "RM-6929")
public void createDispositionScheduleOnCategoryWithHeldChildren() throws Exception
public void createDispositionScheduleOnCategoryWithHeldChildren()
{
STEP("Create a retention schedule on the category with frozen children");
RecordCategory categoryWithRS = getRestAPIFactory().getRecordCategoryAPI()
@@ -290,12 +288,10 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest
* When I execute the retain action
* Then the action is executed
* And the record search disposition schedule properties are updated
*
* @throws Exception
*/
@Test
@AlfrescoTest (jira = "RM-6931")
public void retainActionOnFrozenHeldRecords() throws Exception
public void retainActionOnFrozenHeldRecords()
{
STEP("Add a category with a disposition schedule.");
categoryWithRS = createRootCategory(getRandomName("CategoryWithRS"));
@@ -326,8 +322,8 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest
{
holdsAPI.deleteHold(getAdminUser(), holdNodeRef);
dataSite.usingAdmin().deleteSite(testSite);
getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(recordFolder.getParentId());
getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(categoryWithRS.getId());
deleteRecordCategory(recordFolder.getParentId());
deleteRecordCategory(categoryWithRS.getId());
}
}

View File

@@ -88,8 +88,8 @@ public class RemoveFromHoldsTests extends BaseRMRestTest
private String holdNodeRefOne;
private String holdNodeRefTwo;
private FileModel contentHeld, contentAddToManyHolds;
private Set<UserModel> usersToBeClean = new HashSet<>();
private Set<String> nodesToBeClean = new HashSet<>();
private final Set<UserModel> usersToBeClean = new HashSet<>();
private final Set<String> nodesToBeClean = new HashSet<>();
@Autowired
private HoldsAPI holdsAPI;
@Autowired
@@ -202,10 +202,9 @@ public class RemoveFromHoldsTests extends BaseRMRestTest
/**
* Data provider with user without right permission or capability to remove from hold a specific node
* @return user model and the node ref to be removed from hold
* @throws Exception
*/
@DataProvider (name = "userWithoutPermissionForRemoveFromHold")
public Object[][] getUserWithoutPermissionForAddToHold() throws Exception
public Object[][] getUserWithoutPermissionForAddToHold()
{
//create record folder
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
@@ -277,10 +276,9 @@ public class RemoveFromHoldsTests extends BaseRMRestTest
* Data provider with user with right permission or capability to remove from hold a specific node
*
* @return user model and the node ref to be removed from hold
* @throws Exception
*/
@DataProvider (name = "userWithPermissionForRemoveFromHold")
public Object[][] getUserWithPermissionForAddToHold() throws Exception
public Object[][] getUserWithPermissionForAddToHold()
{
//create record folder
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
@@ -332,7 +330,7 @@ public class RemoveFromHoldsTests extends BaseRMRestTest
dataSite.usingAdmin().deleteSite(testSite);
dataSite.usingAdmin().deleteSite(privateSite);
usersToBeClean.forEach(user -> getDataUser().usingAdmin().deleteUser(user));
nodesToBeClean.forEach(category -> getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(category));
nodesToBeClean.forEach(category -> deleteRecordCategory(category));
}
}

View File

@@ -58,7 +58,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
*/
@AlfrescoTest (jira = "MNT-19967")
@Test
public void testRSInheritanceOnRecordsWhenOnlyACategoryHasRS() throws Exception
public void testRSInheritanceOnRecordsWhenOnlyACategoryHasRS()
{
STEP("Create record category with retention schedule and apply it to records.");
RecordCategory rootCategory = createRootCategory(getRandomName("rootCategory"));
@@ -94,7 +94,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
* Then recFolder should inherit the RS from rootCategory
*/
@Test
public void testRSInheritanceOnRecordFoldersWhenOnlyACategoryHasRS() throws Exception
public void testRSInheritanceOnRecordFoldersWhenOnlyACategoryHasRS()
{
STEP("Create record category with retention schedule and apply it to record folders.");
RecordCategory rootCategory = createRootCategory(getRandomName("rootCategory"));
@@ -126,7 +126,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
* Then both records should inherit the RS from subCategory1
*/
@Test
public void testRSInheritanceOnRecordsWhen2CategoriesHaveRS() throws Exception
public void testRSInheritanceOnRecordsWhen2CategoriesHaveRS()
{
STEP("Create record category with retention schedule and apply it to records.");
RecordCategory rootCategory = createRootCategory(getRandomName("rootCategory"));
@@ -174,7 +174,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
* Then recFolder should inherit the RS from subCategory1
*/
@Test
public void testRSInheritanceOnRecordFoldersWhen2CategoriesHaveRS() throws Exception
public void testRSInheritanceOnRecordFoldersWhen2CategoriesHaveRS()
{
STEP("Create record category with retention schedule and apply it to record folders.");
RecordCategory rootCategory = createRootCategory(getRandomName("rootCategory"));
@@ -213,7 +213,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
* Then both records should inherit the RS from subCategory
*/
@Test
public void testMixedRSInheritanceWhenFirstParentHasRSOnRecords() throws Exception
public void testMixedRSInheritanceWhenFirstParentHasRSOnRecords()
{
STEP("Create record category with retention schedule and apply it to folder records.");
RecordCategory rootCategory = createRootCategory(getRandomName("rootCategory"));
@@ -260,7 +260,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
* and record folder inherits the RS from subCategory
*/
@Test
public void testMixedRSInheritanceWhenFirstParentHasRSOnFolders() throws Exception
public void testMixedRSInheritanceWhenFirstParentHasRSOnFolders()
{
STEP("Create record category with retention schedule and apply it to records.");
RecordCategory rootCategory = createRootCategory(getRandomName("rootCategory"));

View File

@@ -28,12 +28,10 @@ package org.alfresco.rest.rm.community.recordcategories;
import static java.time.LocalDateTime.now;
import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME;
import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias
.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
@@ -87,6 +85,8 @@ import org.testng.annotations.Test;
*/
public class RecordCategoryTests extends BaseRMRestTest
{
public static final String RECORD_CATEGORY_NAME = "CATEGORY NAME" + getRandomAlphanumeric();
/** Number of children (for children creation test) */
private static final int NUMBER_OF_CHILDREN = 10;
private static final int NUMBER_OF_FOLDERS = 5;
@@ -98,7 +98,7 @@ public class RecordCategoryTests extends BaseRMRestTest
* Invalid containers that cannot be deleted with record category end-point
*/
@DataProvider (name = "invalidContainersToDelete")
public Object[][] getNodesToDelete() throws Exception
public Object[][] getNodesToDelete()
{
return new String[][] {
{ FILE_PLAN_ALIAS },
@@ -122,7 +122,7 @@ public class RecordCategoryTests extends BaseRMRestTest
(
description = "Rename root category"
)
public void renameCategory() throws Exception
public void renameCategory()
{
// Create record category first
String categoryName = "Category name " + getRandomAlphanumeric();
@@ -163,7 +163,7 @@ public class RecordCategoryTests extends BaseRMRestTest
(
description = "Delete category"
)
public void deleteCategory() throws Exception
public void deleteCategory()
{
// Create record category first
String categoryName = "Category name " + getRandomAlphanumeric();
@@ -201,7 +201,7 @@ public class RecordCategoryTests extends BaseRMRestTest
description = "Delete invalid nodes with delete category endpoint",
dataProvider = "invalidContainersToDelete"
)
public void deleteInvalidNodes(String nodeId) throws Exception
public void deleteInvalidNodes(String nodeId)
{
// Delete the record category
@@ -224,7 +224,7 @@ public class RecordCategoryTests extends BaseRMRestTest
(
description = "Create child category"
)
public void createSubcategory() throws Exception
public void createSubcategory()
{
// Create root level category
RecordCategory rootCategory = createRootCategory(getRandomAlphanumeric());
@@ -272,7 +272,7 @@ public class RecordCategoryTests extends BaseRMRestTest
dataProvider = "folderTypes"
)
@Bug (id = "RM-4572")
public void createFolderTest(String folderType) throws Exception
public void createFolderTest(String folderType)
{
// Authenticate with admin user
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
@@ -304,7 +304,7 @@ public class RecordCategoryTests extends BaseRMRestTest
dataProvider = "categoryChild"
)
@Bug(id = "RM-5116")
public void createdDuplicateChild(String childType)throws Exception
public void createdDuplicateChild(String childType)
{
// create a root category
String rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()).getId();
@@ -354,7 +354,7 @@ public class RecordCategoryTests extends BaseRMRestTest
description = "Get children of a record category excluding the disposition schedule"
)
@Bug (id="RM-5115")
public void getRecordCategoryChildren() throws Exception
public void getRecordCategoryChildren()
{
// Create root level category
RecordCategory rootRecordCategory = createRootCategory(getRandomAlphanumeric());
@@ -374,7 +374,7 @@ public class RecordCategoryTests extends BaseRMRestTest
recordCategoriesAPI.addDispositionScheduleSteps(userName, userPassword, categoryName, cutOffStep);
// Add record category children
List<RecordCategoryChild> children = new ArrayList<RecordCategoryChild>();
List<RecordCategoryChild> children = new ArrayList<>();
for (int i=0; i < NUMBER_OF_CHILDREN; i++)
{
// Create a record category child
@@ -408,7 +408,7 @@ public class RecordCategoryTests extends BaseRMRestTest
RecordCategoryChild createdComponent = children.stream()
.filter(child -> child.getId().equals(recordCategoryChildId))
.findFirst()
.get();
.orElseThrow();
// Created by
assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername());
@@ -457,7 +457,7 @@ public class RecordCategoryTests extends BaseRMRestTest
dataProvider = "childrenNotAllowedForCategory"
)
@Bug (id="RM-4367, RM-4572")
public void createTypesNotAllowedInCategory(String nodeType) throws Exception
public void createTypesNotAllowedInCategory(String nodeType)
{
String componentName = "Component" + getRandomAlphanumeric();
@@ -481,13 +481,13 @@ public class RecordCategoryTests extends BaseRMRestTest
(
description = "Get children of a record category"
)
public void getFolders() throws Exception
public void getFolders()
{
// Authenticate with admin user
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
// Add child folders
ArrayList<RecordCategoryChild> children = new ArrayList<RecordCategoryChild>();
ArrayList<RecordCategoryChild> children = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_FOLDERS; i++)
{
// Create a record folder
@@ -516,7 +516,7 @@ public class RecordCategoryTests extends BaseRMRestTest
RecordCategoryChild createdComponent = children.stream()
.filter(child -> child.getId().equals(recordCategoryChildId))
.findFirst()
.get();
.orElseThrow();
// Created by
assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername());
@@ -552,7 +552,7 @@ public class RecordCategoryTests extends BaseRMRestTest
description = "Create a folder using record-categories endpoint, based on the relativePath. " +
"Containers in the relativePath that do not exist are created before the node is created"
)
public void createRecordFolderWithRelativePath() throws Exception
public void createRecordFolderWithRelativePath()
{
// The record category to be created
RecordCategory recordCategoryModel = RecordCategory.builder()
@@ -600,7 +600,7 @@ public class RecordCategoryTests extends BaseRMRestTest
assertStatusCode(OK);
// Verify the returned details for the record folder
assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType()));
assertEquals(recordFolder.getNodeType(), RECORD_FOLDER_TYPE);
// Check the path return contains the relativePath
assertTrue(recordFolder.getPath().getName().contains(relativePath));
@@ -638,7 +638,7 @@ public class RecordCategoryTests extends BaseRMRestTest
assertStatusCode(OK);
// Verify the returned details for the record folder
assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType()));
assertEquals(recordFolder.getNodeType(), RECORD_FOLDER_TYPE);
// Check the path return contains the newRelativePath
assertTrue(newRecordFolder.getPath().getName().contains(newRelativePath));
@@ -657,7 +657,7 @@ public class RecordCategoryTests extends BaseRMRestTest
description = "Create a sub-category using record-categories endpoint, based on the relativePath. " +
"Containers in the relativePath that do not exist are created before the node is created"
)
public void createRecordSubCategoryWithRelativePath() throws Exception
public void createRecordSubCategoryWithRelativePath()
{
// The record category to be created
RecordCategory recordCategoryModel = RecordCategory.builder()
@@ -704,7 +704,7 @@ public class RecordCategoryTests extends BaseRMRestTest
assertStatusCode(OK);
// Verify the returned details for the record folder
assertTrue(RECORD_CATEGORY_TYPE.equals(recordSubCategory.getNodeType()));
assertEquals(recordSubCategory.getNodeType(), RECORD_CATEGORY_TYPE);
// Check the path return contains the relativePath
assertTrue(recordSubCategory.getPath().getName().contains(relativePath));
@@ -742,7 +742,7 @@ public class RecordCategoryTests extends BaseRMRestTest
assertStatusCode(OK);
// Verify the returned details for the record folder
assertTrue(RECORD_CATEGORY_TYPE.equals(recordSubCategory.getNodeType()));
assertEquals(recordSubCategory.getNodeType(), RECORD_CATEGORY_TYPE);
// Check the path return contains the newRelativePath
assertTrue(newRecordFolder.getPath().getName().contains(newRelativePath));
@@ -762,7 +762,7 @@ public class RecordCategoryTests extends BaseRMRestTest
dataProvider = "getContainers"
)
@Bug (id = "RM-4327")
public void createRecordFolderIntoSpecialContainers(String containerAlias) throws Exception
public void createRecordFolderIntoSpecialContainers(String containerAlias)
{
String containerId;
if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias))

View File

@@ -44,6 +44,7 @@ import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@@ -67,8 +68,6 @@ import org.testng.annotations.Test;
*/
public class ElectronicRecordTests extends BaseRMRestTest
{
private static final String TEXT_PLAIN_VALUE = "text/plain";
/** Invalid parent containers where electronic records can't be created */
@DataProvider(name = "invalidParentContainers")
public Object[][] invalidParentContainers()
@@ -92,7 +91,6 @@ public class ElectronicRecordTests extends BaseRMRestTest
* And an error is reported
* </pre>
* @param container The parent container
* @throws Exception if record can't be created
*/
@Test
(
@@ -116,13 +114,12 @@ public class ElectronicRecordTests extends BaseRMRestTest
* Then nothing happens
* And an error is reported
* </pre>
* @throws Exception if record can't be created
*/
@Test
(
description = "Electronic record can't be created in closed record folder"
)
public void cantCreateElectronicRecordInClosedFolder() throws Exception
public void cantCreateElectronicRecordInClosedFolder()
{
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
@@ -334,7 +331,7 @@ public class ElectronicRecordTests extends BaseRMRestTest
*/
@Test
@Bug (id = "RM-4568")
public void createElectronicRecordWithRelativePath() throws Exception
public void createElectronicRecordWithRelativePath()
{
// The containers specified on the relativePath parameter don't exist on server
String parentUbnfiledRecordFolderName = "ParentUnfiledRecordFolder" + getRandomAlphanumeric();
@@ -364,7 +361,7 @@ public class ElectronicRecordTests extends BaseRMRestTest
Record record = recordsAPI.getRecord(recordCreated.getId());
assertTrue(record.getName().startsWith(ELECTRONIC_RECORD_NAME));
assertTrue(unfiledRecordFoldersAPI.getUnfiledRecordFolder(record.getParentId()).getName().equals(unfiledRecordFolderPathEl3));
assertEquals(unfiledRecordFoldersAPI.getUnfiledRecordFolder(record.getParentId()).getName(), unfiledRecordFolderPathEl3);
// The first relative path element exists and the second one does not exist
String unfiledRecordFolderPathEl4 = "UnfiledRecordFolderPathEl4" + getRandomAlphanumeric();
@@ -399,9 +396,6 @@ public class ElectronicRecordTests extends BaseRMRestTest
* When I try to create a record with name1 and create another one with the same given name
* Then the second record is created with success
* </pre>
*
* @throws Exception
* if record can't be created
*/
@Test(description = "Electronic records can be created in record folder with duplicate name")
@Bug(id ="RM-5116, RM-5012")

View File

@@ -28,6 +28,7 @@ package org.alfresco.rest.rm.community.recordfolders;
import static java.lang.Integer.MAX_VALUE;
import static java.util.Arrays.asList;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
@@ -57,7 +58,6 @@ import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.testng.annotations.Test;
@@ -166,10 +166,9 @@ public class NonElectronicRecordTests extends BaseRMRestTest
* Then nothing happens
* And an error is reported
* </pre>
* @throws Exception if record can't be created
*/
@Test(description = "Non-electronic record can't be created in closed record folder")
public void cantCreateInClosedFolder() throws Exception
public void cantCreateInClosedFolder()
{
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
@@ -204,14 +203,13 @@ public class NonElectronicRecordTests extends BaseRMRestTest
* Then nothing happens
* And an error is reported
* </pre>
* @throws Exception if record can't be created
*/
@Test
(
dataProvider = "validRootContainers",
description = "Non-electronic record can only be created if all mandatory properties are given"
)
public void allMandatoryPropertiesRequired(String folderId, String type) throws Exception
public void allMandatoryPropertiesRequired(String folderId, String type)
{
logger.info("Root container:\n" + toJson(folderId));
@@ -232,25 +230,11 @@ public class NonElectronicRecordTests extends BaseRMRestTest
.build();
// Try to create invalid components
asList(noNameOrTitle, titleOnly).stream().forEach(c ->
asList(noNameOrTitle, titleOnly).forEach(c ->
{
try
{
logger.info("Creating non-electronic record with body:\n" + toJson(c));
}
catch (Exception error)
{
}
// This should fail and throw an exception
try
{
getRestAPIFactory().getRecordFolderAPI().createRecord(c, folderId);
}
catch (Exception e)
{
}
logger.info("Creating non-electronic record with body:\n" + toJson(c));
getRestAPIFactory().getRecordFolderAPI().createRecord(c, folderId);
// Verify the status code is BAD_REQUEST
assertStatusCode(BAD_REQUEST);
});
@@ -269,25 +253,11 @@ public class NonElectronicRecordTests extends BaseRMRestTest
.build();
// Try to create invalid components
asList(noNameOrTitle, titleOnly).stream().forEach(c ->
asList(noNameOrTitle, titleOnly).forEach(c ->
{
try
{
logger.info("Creating non-electronic record with body:\n" + toJson(c));
}
catch (Exception error)
{
}
// This should fail and throw an exception
try
{
getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(c, folderId);
}
catch (Exception e)
{
}
logger.info("Creating non-electronic record with body:\n" + toJson(c));
getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(c, folderId);
// Verify the status code is BAD_REQUEST
assertStatusCode(BAD_REQUEST);
});
@@ -307,24 +277,11 @@ public class NonElectronicRecordTests extends BaseRMRestTest
.build();
// Try to create invalid components
asList(noNameOrTitle, titleOnly).stream().forEach(c ->
asList(noNameOrTitle, titleOnly).forEach(c ->
{
try
{
logger.info("Creating non-electronic record with body:\n" + toJson(c));
}
catch (Exception error)
{
}
logger.info("Creating non-electronic record with body:\n" + toJson(c));
// This should fail and throw an exception
try
{
getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(c, folderId);
}
catch (Exception e)
{
}
getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(c, folderId);
// Verify the status code is BAD_REQUEST
assertStatusCode(BAD_REQUEST);
@@ -339,16 +296,15 @@ public class NonElectronicRecordTests extends BaseRMRestTest
* Then nothing happens
* And an error is reported
* </pre>
* @throws Exception if record can't be created
*/
@Test
(
dataProvider = "validRootContainers",
description = "Non-electronic record can't be created if user doesn't have RM privileges"
)
public void cantCreateIfNoRmPrivileges(String folderId, String type) throws Exception
public void cantCreateIfNoRmPrivileges(String folderId, String type)
{
UserModel user = createUserWithRole("zzzuser", SiteManager);
UserModel user = createSiteManager("zzzuser");
if (type.equals(RECORD_FOLDER_TYPE))
{
@@ -362,14 +318,7 @@ public class NonElectronicRecordTests extends BaseRMRestTest
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
// This should fail and throw an exception
try
{
getRestAPIFactory().getRecordFolderAPI(user).createRecord(recordModel, folderId);
}
catch (Exception e)
{
}
getRestAPIFactory().getRecordFolderAPI(user).createRecord(recordModel, folderId);
}
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
{
@@ -383,14 +332,7 @@ public class NonElectronicRecordTests extends BaseRMRestTest
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
// This should fail and throw an exception
try
{
getRestAPIFactory().getUnfiledContainersAPI(user).createUnfiledContainerChild(recordModel, folderId);
}
catch (Exception e)
{
}
getRestAPIFactory().getUnfiledContainersAPI(user).createUnfiledContainerChild(recordModel, folderId);
}
else
{
@@ -404,21 +346,14 @@ public class NonElectronicRecordTests extends BaseRMRestTest
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
// This should fail and throw an exception
try
{
getRestAPIFactory().getUnfiledRecordFoldersAPI(user).createUnfiledRecordFolderChild(recordModel, folderId);
}
catch (Exception e)
{
}
getRestAPIFactory().getUnfiledRecordFoldersAPI(user).createUnfiledRecordFolderChild(recordModel, folderId);
}
// User who isn't an RM site member can't access the container path
assertStatusCode(FORBIDDEN);
}
/**
* Create user with given role and add it to RM site
* Create user with site manager role and add it to RM site
* <br>
* Checks whether the user exists in RM site and creates it if required, with password identical
* to user name. Note the role is a Core API role, not an RM role.
@@ -426,23 +361,19 @@ public class NonElectronicRecordTests extends BaseRMRestTest
* For already existing users, no site membership or role verification is performed.
* <p>
* @param userName user name to add
* @param userRole user's role
* @throws Exception
*/
private UserModel createUserWithRole(String userName, UserRole userRole) throws Exception
private UserModel createSiteManager(String userName)
{
String siteId = getRestAPIFactory().getRMSiteAPI().getSite().getId();
// Check if user exists
UserModel user = new UserModel();
user.setUsername(userName);
user.setPassword(userName);
UserModel user = new UserModel(userName, userName);
if (!getDataUser().isUserInRepo(userName))
{
// User doesn't exist, create it
user = getDataUser().createUser(userName, userName);
getDataUser().addUserToSite(user, new SiteModel(siteId), userRole);
getDataUser().addUserToSite(user, new SiteModel(siteId), SiteManager);
}
return user;

View File

@@ -26,7 +26,6 @@
*/
package org.alfresco.rest.rm.community.recordfolders;
import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME;
import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
@@ -45,6 +44,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.TITLE_PREFIX;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.alfresco.utility.data.RandomData.getRandomName;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT;
@@ -56,7 +56,6 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.util.ArrayList;
import java.util.NoSuchElementException;
@@ -69,13 +68,11 @@ 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.RecordFolderCollection;
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderProperties;
import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
import org.alfresco.utility.report.Bug;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -89,7 +86,14 @@ public class RecordFolderTests extends BaseRMRestTest
{
public static final String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric();
public static final String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
public static final String RECORD_CATEGORY_NAME = "CATEGORY NAME" + getRandomAlphanumeric();
private RecordCategory rootCategory;
@BeforeClass (alwaysRun = true)
public void preconditionRecordFolderTests()
{
rootCategory = createRootCategory(RECORD_CATEGORY_NAME);
}
/**
* Data Provider with:
@@ -115,14 +119,14 @@ public class RecordFolderTests extends BaseRMRestTest
* Invalid containers that cannot be updated/deleted with record folder endpoint
*/
@DataProvider
public Object[][] getInvalidNodesForRecordFolders() throws Exception
public Object[][] getInvalidNodesForRecordFolders()
{
return new String[][] {
{ getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS).getId()},
{ getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId() },
{ getRestAPIFactory().getTransferContainerAPI().getTransferContainer(TRANSFERS_ALIAS).getId() },
// an arbitrary record category
{ createRootCategory(RECORD_CATEGORY_NAME+getRandomAlphanumeric()).getId()},
{ rootCategory.getId()},
// an arbitrary unfiled records folder
{ createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId() },
{ createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Record " + getRandomAlphanumeric(), CONTENT_TYPE).getId()}
@@ -133,7 +137,7 @@ public class RecordFolderTests extends BaseRMRestTest
/**
* <pre>
* Given that RM site is created
* When I use the API to create a children of wrong type inside a record folder
* When I use the API to create a children of wrong type inside a record folder
* Then the operation fails
* </pre>
*/
@@ -144,16 +148,15 @@ public class RecordFolderTests extends BaseRMRestTest
description = "Create invalid types as children for a record folder",
dataProvider = "childrenNotAllowedForFolder"
)
public void createInvalidChildrenForFolder(String nodeType) throws Exception
public void createInvalidChildrenForFolder(String nodeType)
{
//create a record folder
RecordCategoryChild folder = createCategoryFolderInFilePlan();
RecordCategoryChild folder = createRecordFolder(rootCategory.getId(), getRandomName("recFolder"));
Record record = Record.builder()
.name(ELECTRONIC_RECORD_NAME)
.nodeType(nodeType)
.build();
//create invalid child typefor the record folder
//create invalid child type for the record folder
getRestAPIFactory().getRecordFolderAPI().createRecord(record,folder.getId());
// Check the API Response code
assertStatusCode(UNPROCESSABLE_ENTITY);
@@ -170,20 +173,16 @@ public class RecordFolderTests extends BaseRMRestTest
(
description = "Check the details of a record folder"
)
public void checkRecordFolderDetails() throws Exception
public void checkRecordFolderDetails()
{
// Create a category
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
// Create a folder
RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME);
RecordCategoryChild recordCategoryChild = createRecordFolder(rootCategory.getId(), RECORD_FOLDER_NAME);
// Get the folder including extra information
RecordFolder recordFolder = getRestAPIFactory().getRecordFolderAPI().getRecordFolder(recordCategoryChild.getId(), "include=" + IS_CLOSED);
// Verify the returned record folder details
assertEquals(recordFolder.getNodeType(), RECORD_FOLDER_TYPE);
assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType()));
assertEquals(recordFolder.getName(), RECORD_FOLDER_NAME);
assertEquals(recordFolder.getCreatedByUser().getId(), getAdminUser().getUsername());
assertEquals(recordFolder.getModifiedByUser().getId(), getAdminUser().getUsername());
@@ -206,13 +205,10 @@ public class RecordFolderTests extends BaseRMRestTest
(
description = "Update the details of a record folder"
)
public void updateRecordFolderDetails() throws Exception
public void updateRecordFolderDetails()
{
// Create a record category
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
// Create a record folder
RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME);
RecordCategoryChild recordCategoryChild = createRecordFolder(rootCategory.getId(), getRandomName("recFolder"));
// Create record category first
String folderDescription = "The folder description is updated" + getRandomAlphanumeric();
@@ -261,7 +257,7 @@ public class RecordFolderTests extends BaseRMRestTest
description = "Update the details for other nodes than record folder with the request used for record-folders ",
dataProvider = "getInvalidNodesForRecordFolders"
)
public void updateOtherNodeTypesDetails(String nodeId) throws Exception
public void updateOtherNodeTypesDetails(String nodeId)
{
// Create record category first
String nodeDescription = "The folder description is updated" + getRandomAlphanumeric();
@@ -299,7 +295,7 @@ public class RecordFolderTests extends BaseRMRestTest
description = "Delete invalid nodes type with the DELETE record folders request",
dataProvider = "getInvalidNodesForRecordFolders"
)
public void deleteInvalidNodesRecordFolder(String nodeId) throws Exception
public void deleteInvalidNodesRecordFolder(String nodeId)
{
// Delete the nodes with record-folders end-point
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
@@ -320,13 +316,10 @@ public class RecordFolderTests extends BaseRMRestTest
(
description = "Delete record folder"
)
public void deleteRecordFolder() throws Exception
public void deleteRecordFolder()
{
// Create the record category
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
// Create the record folder
RecordCategoryChild recordFolder = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME);
RecordCategoryChild recordFolder = createRecordFolder(rootCategory.getId(), getRandomName("recFolder"));
// Delete the record folder
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
@@ -353,10 +346,10 @@ public class RecordFolderTests extends BaseRMRestTest
description = "A closed record folder can be reopened"
)
@Bug(id="RM-4808")
public void openClosedRecordFolder() throws Exception
public void openClosedRecordFolder()
{
// Create a record folder
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
RecordCategoryChild recordFolder = createRecordFolder(rootCategory.getId(), getRandomName("recFolder"));
// Assert that the record folder is not closed
assertFalse(recordFolder.getProperties().getIsClosed());
@@ -366,10 +359,10 @@ public class RecordFolderTests extends BaseRMRestTest
// Create a record folder model to close it
RecordFolder recordFolderModel = RecordFolder.builder()
.properties(RecordFolderProperties.builder()
.isClosed(true)
.build())
.build();
.properties(RecordFolderProperties.builder()
.isClosed(true)
.build())
.build();
// Make a request to close the record folder
RecordFolder updatedRecordFolder = recordFolderAPI.updateRecordFolder(recordFolderModel, recordFolder.getId());
@@ -379,10 +372,10 @@ public class RecordFolderTests extends BaseRMRestTest
// Create a record folder model to reopen it
recordFolderModel = RecordFolder.builder()
.properties(RecordFolderProperties.builder()
.isClosed(false)
.build())
.build();
.properties(RecordFolderProperties.builder()
.isClosed(false)
.build())
.build();
// Make a request to reopen the record folder
updatedRecordFolder = recordFolderAPI.updateRecordFolder(recordFolderModel, recordFolder.getId());
@@ -397,13 +390,13 @@ public class RecordFolderTests extends BaseRMRestTest
* Then I receive a list of all the records contained within the record folder
*/
@Test
public void listRecordsFromRecordFolder() throws Exception
public void listRecordsFromRecordFolder()
{
final int NUMBER_OF_RECORDS = 5;
String containerId = createCategoryFolderInFilePlan().getId();
String containerId = createRecordFolder(rootCategory.getId(), getRandomName("recFolder")).getId();
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
// Create Electronic Records
ArrayList<Record> children = new ArrayList<Record>();
ArrayList<Record> children = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_RECORDS; i++)
{
//build the electronic record
@@ -453,7 +446,7 @@ public class RecordFolderTests extends BaseRMRestTest
Record createdComponent = children.stream()
.filter(child -> child.getId().equals(record.getId()))
.findFirst()
.get();
.orElseThrow();
// Created by
assertEquals(record.getCreatedByUser().getId(), getAdminUser().getUsername());
@@ -462,8 +455,8 @@ public class RecordFolderTests extends BaseRMRestTest
assertEquals(record.getParentId(), containerId);
//check the record name
assertTrue(record.getName().equals(createdComponent.getName()),
"Record Name"+ record.getName()+" doesn't match the one returned on create");
assertEquals(createdComponent.getName(), record.getName(),
"Record Name" + record.getName() + " doesn't match the one returned on create");
assertTrue(createdComponent.getName().contains(createdComponent.getProperties().getIdentifier()),
"Record Name"+ createdComponent.getName()+" doesn't contain the record identifier in response when creating");
assertEquals(createdComponent.getNodeType(), record.getNodeType());
@@ -475,16 +468,9 @@ public class RecordFolderTests extends BaseRMRestTest
});
}
@AfterTest
@AfterClass (alwaysRun = true)
public void tearDown() throws Exception
public void tearDown()
{
FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI();
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
filePlansAPI.getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry ->
{
recordCategoryAPI.deleteRecordCategory(recordCategoryEntry.getEntry().getId());
});
deleteRecordCategory(rootCategory.getId());
}
}

View File

@@ -31,15 +31,11 @@ import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.create
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createDOD5015RMSiteModel;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createStandardRMSiteModel;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
import static org.testng.Assert.assertEquals;
import java.util.Arrays;
import java.util.List;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.record.Record;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
@@ -65,7 +61,7 @@ public class CompleteRecordTests extends BaseRMRestTest
* Incomplete records with mandatory meta-data missing
*/
@DataProvider (name = "IncompleteRecordsMandatoryMetadataMissing")
public Object[][] getIncompleteRecordsMandatoryMetadataMissing() throws Exception
public Object[][] getIncompleteRecordsMandatoryMetadataMissing()
{
//create RM site
createRMSite(createDOD5015RMSiteModel());
@@ -78,26 +74,12 @@ public class CompleteRecordTests extends BaseRMRestTest
* Incomplete records with mandatory meta-data present
*/
@DataProvider (name = "IncompleteRecordsMandatoryMetadataPresent")
public Object[][] getIncompleteRecordsMandatoryMetadataPresent() throws Exception
public Object[][] getIncompleteRecordsMandatoryMetadataPresent()
{
// create electronic and non-electronic records
return createAndVerifyRecordsInFolder();
}
/**
* Document to be completed is not a record
*/
@DataProvider (name = "Supplied node is not a record")
public Object[][] getNodesWhichAreNotRecords() throws Exception
{
createRMSite(createStandardRMSiteModel());
return new String[][]
{
{ createCategoryFolderInFilePlan().getId() },
};
}
/**
* <pre>
* Given the repository is configured to check mandatory data before completing a record
@@ -114,21 +96,15 @@ public class CompleteRecordTests extends BaseRMRestTest
priority = 1
)
@AlfrescoTest (jira = "RM-4431")
public void completeRecordWithMandatoryMetadataMissing(String electronicRecordId, String nonElectronicRecordId)
throws Exception
public void completeRecordWithMandatoryMetadataMissing(Record record)
{
List<Record> records = getRecordsList(electronicRecordId, nonElectronicRecordId);
verifyRecordCompletionStatus(record, INCOMPLETE);
for (Record record : records)
{
verifyRecordCompletionStatus(record, INCOMPLETE);
// Complete record
completeRecord(record);
assertStatusCode(UNPROCESSABLE_ENTITY);
// Complete record
completeRecord(record);
assertStatusCode(UNPROCESSABLE_ENTITY);
verifyRecordCompletionStatus(record, INCOMPLETE);
}
verifyRecordCompletionStatus(record, INCOMPLETE);
}
/**
@@ -145,21 +121,15 @@ public class CompleteRecordTests extends BaseRMRestTest
description = "Can complete electronic and non-electronic records with mandatory metadata present"
)
@AlfrescoTest (jira = "RM-4431")
public void completeRecordWithMandatoryMetadataPresent(String electronicRecordId, String nonElectronicRecordId)
throws Exception
public void completeRecordWithMandatoryMetadataPresent(Record record)
{
List<Record> records = getRecordsList(electronicRecordId, nonElectronicRecordId);
verifyRecordCompletionStatus(record, INCOMPLETE);
for (Record record : records)
{
verifyRecordCompletionStatus(record, INCOMPLETE);
// Complete record
completeRecord(record);
assertStatusCode(CREATED);
// Complete record
completeRecord(record);
assertStatusCode(CREATED);
verifyRecordCompletionStatus(record, COMPLETE);
}
verifyRecordCompletionStatus(record, COMPLETE);
}
/**
@@ -169,18 +139,13 @@ public class CompleteRecordTests extends BaseRMRestTest
* Then I receive an unsupported operation error
* </pre>
*/
@Test
(
dataProvider = "Supplied node is not a record",
description = "Cannot complete a document that is not a record",
priority = 2
)
@Test (description = "Cannot complete a document that is not a record")
@AlfrescoTest (jira = "RM-4431")
public void completeNonRecord(String nonRecordId) throws Exception
public void completeNonRecord()
{
// Get the recordsAPI
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
recordsAPI.completeRecord(nonRecordId, PARAMETERS);
getRestAPIFactory().getRecordsAPI()
.completeRecord(createCategoryFolderInFilePlan().getId(), PARAMETERS);
assertStatusCode(BAD_REQUEST);
}
@@ -194,35 +159,28 @@ public class CompleteRecordTests extends BaseRMRestTest
@Test
(
dataProvider = "IncompleteRecordsMandatoryMetadataPresent",
description = "Cannot complete a record that is already completed",
priority = 3
description = "Cannot complete a record that is already completed"
)
@AlfrescoTest (jira = "RM-4431")
public void completeAlreadyCompletedRecord(String electronicRecordId, String nonElectronicRecordId)
throws Exception
public void completeAlreadyCompletedRecord(Record record)
{
List<Record> records = getRecordsList(electronicRecordId, nonElectronicRecordId);
verifyRecordCompletionStatus(record, INCOMPLETE);
for (Record record : records)
{
verifyRecordCompletionStatus(record, INCOMPLETE);
// Complete record
completeRecord(record);
assertStatusCode(CREATED);
// Complete record
completeRecord(record);
assertStatusCode(CREATED);
verifyRecordCompletionStatus(record, COMPLETE);
verifyRecordCompletionStatus(record, COMPLETE);
// Complete record
completeRecord(record);
assertStatusCode(UNPROCESSABLE_ENTITY);
}
// Complete record
completeRecord(record);
assertStatusCode(UNPROCESSABLE_ENTITY);
}
/**
* Helper method to create records and and assert successful creation
*/
private String[][] createAndVerifyRecordsInFolder() throws Exception
private Record[][] createAndVerifyRecordsInFolder()
{
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
@@ -230,32 +188,18 @@ public class CompleteRecordTests extends BaseRMRestTest
String recordFolderId = createCategoryFolderInFilePlan().getId();
// create electronic record in record folder
Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId,
getFile(IMAGE_FILE));
Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId, getFile(IMAGE_FILE));
assertStatusCode(CREATED);
// create non-electronic record in record folder
Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolderId);
assertStatusCode(CREATED);
return new String[][]
{
{ electronicRecord.getId(), nonElectronicRecord.getId() },
};
}
/**
* Helper method to provide list of records from record Ids
*/
private List<Record> getRecordsList(String electronicRecordId, String nonElectronicRecordId)
{
// Get the recordsAPI
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
Record electronicRecord = recordsAPI.getRecord(electronicRecordId);
Record nonElectronicRecord = recordsAPI.getRecord(nonElectronicRecordId);
return Arrays.asList(electronicRecord,nonElectronicRecord);
return new Record[][]
{
{ electronicRecord },
{ nonElectronicRecord }
};
}
/**
@@ -271,7 +215,7 @@ public class CompleteRecordTests extends BaseRMRestTest
/**
* Helper method to complete a record
*/
private void completeRecord(Record record) throws Exception
private void completeRecord(Record record)
{
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
recordsAPI.completeRecord(record.getId(), PARAMETERS);

View File

@@ -28,10 +28,9 @@ package org.alfresco.rest.rm.community.records;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_MANAGER;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_POWER_USER;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel;
@@ -39,7 +38,6 @@ import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.create
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicUnfiledContainerChildModel;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile;
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
import static org.alfresco.utility.data.RandomData.getRandomName;
import static org.alfresco.utility.report.log.Step.STEP;
import static org.springframework.http.HttpStatus.CREATED;
@@ -71,9 +69,11 @@ import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.RepoTestModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
@@ -92,6 +92,35 @@ public class DeleteRecordTests extends BaseRMRestTest
private org.alfresco.rest.v0.RecordsAPI recordsAPI;
@Autowired
private RoleService roleService;
private RecordCategoryChild recordFolder;
private UnfiledContainerChild unfiledRecordFolder;
@BeforeClass (alwaysRun = true)
public void setupDeleteRecordTests()
{
testSite = dataSite.usingAdmin().createPublicRandomSite();
recordFolder = createCategoryFolderInFilePlan();
unfiledRecordFolder = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, getRandomName("Unfiled Folder "),
UNFILED_RECORD_FOLDER_TYPE);
}
/** Data provider with electronic and non-electronic records to be deleted */
@DataProvider (name = "recordsToBeDeleted")
public Object[][] getRecordsToBeDeleted()
{
return new String[][]
{
// records created in an arbitrary record folder
{getRestAPIFactory().getRecordFolderAPI().createRecord(createElectronicRecordModel(), recordFolder.getId(), getFile(IMAGE_FILE)).getId()},
{getRestAPIFactory().getRecordFolderAPI().createRecord(createNonElectronicRecordModel(), recordFolder.getId()).getId()},
// records created in unfiled records root
{getRestAPIFactory().getUnfiledContainersAPI().uploadRecord(createElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS, getFile(IMAGE_FILE)).getId()},
{getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(createNonElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS).getId()},
// records created in an arbitrary unfiled records folder
{getRestAPIFactory().getUnfiledRecordFoldersAPI().uploadRecord(createElectronicUnfiledContainerChildModel(), unfiledRecordFolder.getId(), getFile(IMAGE_FILE)).getId()},
{getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(createNonElectronicUnfiledContainerChildModel(), unfiledRecordFolder.getId()).getId()}
};
}
/**
* <pre>
@@ -104,83 +133,16 @@ public class DeleteRecordTests extends BaseRMRestTest
*/
@Test
(
dataProvider = "validRootContainers",
description = "Admin user can delete an electronic record"
dataProvider = "recordsToBeDeleted",
description = "Admin user can delete records"
)
@AlfrescoTest(jira="RM-4363")
public void adminCanDeleteElectronicRecord(String folderId, String type) throws Exception
public void adminCanDeleteRecords(String recordId)
{
// Create record
String recordId;
if(RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
{
recordId = getRestAPIFactory().getRecordFolderAPI().createRecord(createElectronicRecordModel(), folderId, getFile(IMAGE_FILE)).getId();
}
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
{
recordId = getRestAPIFactory().getUnfiledContainersAPI().uploadRecord(createElectronicUnfiledContainerChildModel(), folderId, getFile(IMAGE_FILE)).getId();
}
else if(UNFILED_RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
{
recordId = getRestAPIFactory().getUnfiledRecordFoldersAPI().uploadRecord(createElectronicUnfiledContainerChildModel(), folderId, getFile(IMAGE_FILE)).getId();
}
else
{
throw new Exception("Unsuported type = " + type);
}
// Assert status
assertStatusCode(CREATED);
// Delete record and verify successful deletion
deleteAndVerify(recordId);
}
/**
* <pre>
* Given a non-electronic record
* And that I have the "Delete Record" capability
* And write permissions
* When I delete the record
* Then it is deleted from the file plan
* </pre>
*/
@Test
(
dataProvider = "validRootContainers",
description = "Admin user can delete a non-electronic record"
)
@AlfrescoTest(jira="RM-4363")
public void adminCanDeleteNonElectronicRecord(String folderId, String type) throws Exception
{
// Create record
String nonElectronicRecordId;
if(RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
{
nonElectronicRecordId = getRestAPIFactory().getRecordFolderAPI().createRecord(createNonElectronicRecordModel(), folderId).getId();
}
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
{
nonElectronicRecordId = getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(createNonElectronicUnfiledContainerChildModel(), folderId).getId();
}
else if(UNFILED_RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
{
nonElectronicRecordId = getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(createNonElectronicUnfiledContainerChildModel(), folderId).getId();
}
else
{
throw new Exception("Unsuported type = " + type);
}
// Assert status
assertStatusCode(CREATED);
// Delete record and verify successful deletion
deleteAndVerify(nonElectronicRecordId);
}
/**
* <pre>
* Given a non-electronic record
@@ -195,7 +157,7 @@ public class DeleteRecordTests extends BaseRMRestTest
description = "User without write permissions can't delete a record"
)
@AlfrescoTest(jira="RM-4363")
public void userWithoutWritePermissionsCantDeleteRecord() throws Exception
public void userWithoutWritePermissionsCantDeleteRecord()
{
// Create a non-electronic record in unfiled records
UnfiledContainerChild nonElectronicRecord = UnfiledContainerChild.builder()
@@ -206,15 +168,8 @@ public class DeleteRecordTests extends BaseRMRestTest
assertStatusCode(CREATED);
// Create test user and add it with collaboration privileges
UserModel deleteUser = getDataUser().createRandomTestUser("delnoperm");
String username = deleteUser.getUsername();
logger.info("Test user: " + username);
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator);
// Add RM role to user
getRestAPIFactory().getRMUserAPI().assignRoleToUser(username, ROLE_RM_POWER_USER.roleId);
assertStatusCode(OK);
// Create test user with RM Manager role
UserModel deleteUser = roleService.createUserWithRMRole(ROLE_RM_MANAGER.roleId);
// Try to delete newRecord
getRestAPIFactory().getRecordsAPI(deleteUser).deleteRecord(newRecord.getId());
@@ -235,18 +190,11 @@ public class DeleteRecordTests extends BaseRMRestTest
description = "User without delete records capability can't delete a record"
)
@AlfrescoTest(jira="RM-4363")
public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception
public void userWithoutDeleteRecordsCapabilityCantDeleteRecord()
{
// Create test user and add it with collaboration privileges
// Add RM role to user, RM Power User doesn't have the "Delete Record" capabilities
UserModel deleteUser = roleService.createUserWithRMRole(ROLE_RM_POWER_USER.roleId);
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator);
String username = deleteUser.getUsername();
logger.info("Test user: " + username);
// Create random folder
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
logger.info("Random folder:" + recordFolder.getName());
// Grant "deleteUser" filing permissions on "randomFolder" parent, this will be inherited to randomFolder
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
@@ -280,13 +228,12 @@ public class DeleteRecordTests extends BaseRMRestTest
@AlfrescoTest(jira="MNT-18806")
public void deleteCopyOfRecord()
{
STEP("Create two record categories and folders.");
RecordCategoryChild recordFolderA = createCategoryFolderInFilePlan();
STEP("Create another record category with a folder.");
RecordCategoryChild recordFolderB = createCategoryFolderInFilePlan();
STEP("Create a record in folder A and copy it into folder B.");
STEP("Create a record in first folder and copy it into second folder.");
String recordId = getRestAPIFactory().getRecordFolderAPI()
.createRecord(createElectronicRecordModel(), recordFolderA.getId(), getFile(IMAGE_FILE)).getId();
.createRecord(createElectronicRecordModel(), recordFolder.getId(), getFile(IMAGE_FILE)).getId();
String copyId = copyNode(recordId, recordFolderB.getId()).getId();
assertStatusCode(CREATED);
@@ -313,10 +260,9 @@ public class DeleteRecordTests extends BaseRMRestTest
*/
@Test (description = "Deleting record doesn't delete the content for the copies")
@AlfrescoTest (jira = "MNT-20145")
public void deleteOriginOfRecord() throws Exception
public void deleteOriginOfRecord()
{
STEP("Create a file.");
testSite = dataSite.usingAdmin().createPublicRandomSite();
FileModel testFile = dataContent.usingAdmin().usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
STEP("Create a copy of the file.");
@@ -332,9 +278,6 @@ public class DeleteRecordTests extends BaseRMRestTest
STEP("Check that it's possible to load the copy content.");
getNodeContent(copyOfTestFile.getId());
assertStatusCode(OK);
STEP("Clean up.");
dataSite.deleteSite(testSite);
}
/**
@@ -348,10 +291,9 @@ public class DeleteRecordTests extends BaseRMRestTest
*/
@Test (description = "Destroying record doesn't delete the content for the associated copy")
@AlfrescoTest (jira = "MNT-20145")
public void destroyOfRecord() throws Exception
public void destroyOfRecord()
{
STEP("Create a file.");
testSite = dataSite.usingAdmin().createPublicRandomSite();
FileModel testFile = dataContent.usingAdmin().usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
FolderModel folderModel = dataContent.usingAdmin().usingSite(testSite).createFolder();
@@ -387,10 +329,6 @@ public class DeleteRecordTests extends BaseRMRestTest
STEP("Check that it's possible to load the copy content.");
getNodeContent(copy.getId());
assertStatusCode(OK);
STEP("Clean up.");
dataSite.deleteSite(testSite);
}
/**
@@ -402,10 +340,9 @@ public class DeleteRecordTests extends BaseRMRestTest
*/
@Test (description = "Deleting record made from version doesn't delete the content for the file")
@AlfrescoTest (jira = "MNT-20145")
public void deleteVersionDeclaredAsRecord() throws Exception
public void deleteVersionDeclaredAsRecord()
{
STEP("Create a file.");
testSite = dataSite.usingAdmin().createPublicRandomSite();
FileModel testFile = dataContent.usingAdmin().usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
STEP("Declare file version as record.");
@@ -425,10 +362,6 @@ public class DeleteRecordTests extends BaseRMRestTest
STEP("Check that it's possible to load the file declared version as record.");
getNodeContent(testFile.getNodeRefWithoutVersion());
assertStatusCode(OK);
STEP("Clean up.");
dataSite.deleteSite(testSite);
}
@@ -519,4 +452,12 @@ public class DeleteRecordTests extends BaseRMRestTest
repoTestModel.setNodeRef(recordId);
return getRestAPIFactory().getNodeAPI(repoTestModel);
}
@AfterClass(alwaysRun = true)
public void cleanupDeleteRecordTests()
{
dataSite.deleteSite(testSite);
deleteRecordCategory(recordFolder.getParentId());
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(unfiledRecordFolder.getId());
}
}

View File

@@ -86,7 +86,7 @@ public class FileRecordsTests extends BaseRMRestTest
private String targetFolderId, folderToLink, closedFolderId, unfiledRecordFolderId;
@BeforeClass (alwaysRun = true)
public void setupFileRecordsTests() throws Exception
public void setupFileRecordsTests()
{
// create 3 record folders and close one of them
targetFolderId = createCategoryFolderInFilePlan().getId();
@@ -103,7 +103,7 @@ public class FileRecordsTests extends BaseRMRestTest
* Invalid containers where electronic and non-electronic records can be filed
*/
@DataProvider (name = "invalidContainersToFile")
public Object[][] getFolderContainers() throws Exception
public Object[][] getFolderContainers()
{
return new String[][] {
{ FILE_PLAN_ALIAS},
@@ -123,13 +123,10 @@ public class FileRecordsTests extends BaseRMRestTest
public Object[][] getRecordsFromUnfiledRecordsContainer()
{
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
UnfiledContainerChild recordElectronic = unfiledContainersAPI.uploadRecord(electronicRecord,
UNFILED_RECORDS_CONTAINER_ALIAS, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
UnfiledContainerChild recordNonElect = unfiledContainersAPI.createUnfiledContainerChild(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
return new String[][] {
{ recordElectronic.getId()},
{ recordNonElect.getId()}
{ unfiledContainersAPI.uploadRecord(electronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS,
createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME)).getId()},
{ unfiledContainersAPI.createUnfiledContainerChild(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS).getId()}
};
}
@@ -140,13 +137,11 @@ public class FileRecordsTests extends BaseRMRestTest
public Object[][] getRecordsFromUnfiledRecordFolder()
{
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
UnfiledContainerChild recordElectronic = unfiledRecordFoldersAPI.uploadRecord(electronicRecord, unfiledRecordFolderId,
createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
UnfiledContainerChild recordNonElect = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonelectronicRecord, unfiledRecordFolderId);
return new String[][] {
{ recordElectronic.getId()},
{ recordNonElect.getId()}
{ unfiledRecordFoldersAPI.uploadRecord(electronicRecord, unfiledRecordFolderId,
createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME)).getId()},
{ unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonelectronicRecord, unfiledRecordFolderId).getId()}
};
}
@@ -264,7 +259,7 @@ public class FileRecordsTests extends BaseRMRestTest
// link the record to the second folder
Record recordLink = fileRecordToFolder(unfiledRecordId, folderToLink);
assertStatusCode(CREATED);
assertTrue(recordLink.getParentId().equals(targetFolderId));
assertEquals(recordLink.getParentId(), targetFolderId);
// check the record is added into the record folder
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();

View File

@@ -40,11 +40,13 @@ import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.create
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.alfresco.utility.data.RandomData.getRandomName;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.AssertJUnit.assertTrue;
import java.io.FileInputStream;
@@ -57,11 +59,14 @@ import org.alfresco.rest.rm.community.model.record.RecordContent;
import org.alfresco.rest.rm.community.model.record.RecordProperties;
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.recordcategory.RecordCategoryChildCollection;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
import org.alfresco.test.AlfrescoTest;
import org.apache.commons.codec.digest.DigestUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -92,27 +97,37 @@ public class ReadRecordTests extends BaseRMRestTest
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
private RecordCategory rootCategory, rootCategory2;
private RecordCategoryChild recordFolder;
@BeforeClass(alwaysRun = true)
public void setupReadRecordTests()
{
rootCategory = createRootCategory(getRandomName("rootCategory"));
rootCategory2 = createRootCategory(getRandomName("rootCategory2"));
recordFolder = createRecordFolder(rootCategory.getId(), getRandomName("recFolder"));
}
/**
* Given a record category or a container which can't contain records
* When I try to read the children filtering the results to records
* Then I receive an empty list
*/
@DataProvider(name="invalidContainersForRecords")
public Object[][] getInvalidContainersForRecords() throws Exception
@DataProvider (name = "invalidContainersForRecords")
public Object[][] getInvalidContainersForRecords()
{
return new String[][] {
{ FILE_PLAN_ALIAS },
{ TRANSFERS_ALIAS },
{ createCategoryFolderInFilePlan().getParentId()}
{ rootCategory.getId()}
};
}
@Test
(
dataProvider ="invalidContainersForRecords",
description ="Reading records from invalid containers"
dataProvider = "invalidContainersForRecords",
description = "Reading records from invalid containers"
)
@AlfrescoTest(jira="RM-4361")
public void readRecordsFromInvalidContainers(String container) throws Exception
public void readRecordsFromInvalidContainers(String container)
{
Record electronicRecord = Record.builder()
.name(ELECTRONIC_RECORD_NAME)
@@ -137,34 +152,30 @@ public class ReadRecordTests extends BaseRMRestTest
if(FILE_PLAN_ALIAS.equals(container))
{
getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(container, "")
.assertThat()//check the list returned is not empty
.entriesListIsNotEmpty().assertThat().paginationExist();
.assertThat()//check the list returned is not empty
.entriesListIsNotEmpty().assertThat().paginationExist();
//check response status code
assertStatusCode(OK);
}
else if(TRANSFERS_ALIAS.equals(container))
{
getRestAPIFactory().getTransferContainerAPI().getTransfers(container, "where=(isRecord=true)")
.assertThat()//check the list returned is empty
.entriesListIsEmpty().assertThat().paginationExist();
.assertThat()//check the list returned is empty
.entriesListIsEmpty().assertThat().paginationExist();
//check response status code
assertStatusCode(OK);
}
else
{
String recordCategoryId = getRestAPIFactory().getRecordCategoryAPI().getRecordCategory(container).getId();
assertStatusCode(OK);
getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(recordCategoryId)
.assertThat()//check the list returned is empty
.entriesListCountIs(1).assertThat().paginationExist();
String nodeType = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(recordCategoryId).getEntries().get(0).getEntry().getNodeType();
assertEquals(nodeType, RECORD_FOLDER_TYPE);
RecordCategoryChildCollection children = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(container);
//check response status code
assertStatusCode(OK);
children.assertThat() //check the list returned is not empty because there is a record folder created inside
.entriesListCountIs(1).assertThat().paginationExist();
assertEquals(children.getEntries().get(0).getEntry().getNodeType(), RECORD_FOLDER_TYPE);
}
}
/**
* Given a record
* When I try to read the meta-data
@@ -172,7 +183,7 @@ public class ReadRecordTests extends BaseRMRestTest
*/
@Test
@AlfrescoTest (jira = "RM-4361")
public void readRecordMetadata() throws Exception
public void readRecordMetadata()
{
String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder";
@@ -201,7 +212,7 @@ public class ReadRecordTests extends BaseRMRestTest
assertNotNull(recordWithContent.getContent().getEncoding());
assertNotNull(recordWithContent.getContent().getMimeType());
assertNotNull(recordWithContent.getAspectNames());
assertFalse(recordWithContent.getName().equals(ELECTRONIC_RECORD_NAME));
assertNotEquals(ELECTRONIC_RECORD_NAME, recordWithContent.getName());
assertTrue(recordWithContent.getName().contains(recordWithContent.getProperties().getIdentifier()));
assertStatusCode(OK);
@@ -212,11 +223,11 @@ public class ReadRecordTests extends BaseRMRestTest
//Check the metadata returned
assertTrue(nonElectronicRecord.getName().startsWith(NONELECTRONIC_RECORD_NAME));
assertEquals(nonElectronicRecord.getContent(), null);
assertNull(nonElectronicRecord.getContent());
assertEquals(nonElectronicRecord.getNodeType(), NON_ELECTRONIC_RECORD_TYPE);
assertNotNull(nonElectronicRecord.getAspectNames());
assertEquals(nonElectronicRecord.getProperties().getDescription(), NONELECTRONIC_RECORD_NAME);
assertFalse(nonElectronicRecord.getName().equals(NONELECTRONIC_RECORD_NAME));
assertNotEquals(NONELECTRONIC_RECORD_NAME, nonElectronicRecord.getName());
assertTrue(nonElectronicRecord.getName().contains(nonElectronicRecord.getProperties().getIdentifier()));
assertStatusCode(OK);
}
@@ -234,7 +245,6 @@ public class ReadRecordTests extends BaseRMRestTest
String RECORD_ELECTRONIC = "Record " + getRandomAlphanumeric();
String RECORD_ELECTRONIC_BINARY = "Binary Record" + getRandomAlphanumeric();
String existentRecordCategoryId = createCategoryFolderInFilePlan().getParentId();
String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder";
@@ -245,7 +255,7 @@ public class ReadRecordTests extends BaseRMRestTest
.relativePath(RELATIVE_PATH)
.build();
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
String folderId = recordCategoryAPI.createRecordCategoryChild(recordFolder, existentRecordCategoryId).getId();
String folderId = recordCategoryAPI.createRecordCategoryChild(recordFolder, rootCategory2.getId()).getId();
// text file as an electronic record
Record recordText = Record.builder()
@@ -292,18 +302,15 @@ public class ReadRecordTests extends BaseRMRestTest
*/
@Test
@AlfrescoTest (jira = "RM-4361")
public void readNonElectronicRecordContent() throws Exception
public void readNonElectronicRecordContent()
{
String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
String folderId = createCategoryFolderInFilePlan().getId();
Record record = Record.builder()
.name(NONELECTRONIC_RECORD_NAME)
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
.name(getRandomName("Record nonelectronic"))
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
String nonElectronicRecord = recordFolderAPI.createRecord(record, folderId).getId();
String nonElectronicRecord = recordFolderAPI.createRecord(record, recordFolder.getId()).getId();
getRestAPIFactory().getRecordsAPI().getRecordContent(nonElectronicRecord);
assertStatusCode(BAD_REQUEST);
@@ -315,12 +322,12 @@ public class ReadRecordTests extends BaseRMRestTest
* Then I receive an error
*/
@DataProvider(name="noContentNodes")
public Object[][] getNonRecordTypes() throws Exception
public Object[][] getNonRecordTypes()
{
return new String[][] {
{ getFilePlan(FILE_PLAN_ALIAS).getId() },
{ getTransferContainer(TRANSFERS_ALIAS).getId() },
{ createCategoryFolderInFilePlan().getParentId()}
{ rootCategory.getId()}
};
}
@Test
@@ -329,11 +336,17 @@ public class ReadRecordTests extends BaseRMRestTest
description = "Reading records from invalid containers"
)
@AlfrescoTest (jira = "RM-4361")
public void readContentFromInvalidContainers(String container) throws Exception
public void readContentFromInvalidContainers(String container)
{
getRestAPIFactory().getRecordsAPI().getRecordContent(container).asString();
assertStatusCode(BAD_REQUEST);
}
@AfterClass(alwaysRun = true)
public void cleanupReadRecordTests()
{
deleteRecordCategory(rootCategory.getId());
deleteRecordCategory(rootCategory2.getId());
}
}

View File

@@ -73,7 +73,7 @@ public class RejectRecordTests extends BaseRMRestTest
private RulesAPI rulesAPI;
@BeforeClass (alwaysRun = true)
public void setUp() throws Exception
public void setUp()
{
publicSite = dataSite.usingAdmin().createPublicRandomSite();
recordCategory = createRootCategory(getRandomName("recordCategory"));
@@ -121,7 +121,7 @@ public class RejectRecordTests extends BaseRMRestTest
*/
@Test
@AlfrescoTest(jira = "RM-6881")
public void rejectCompletedRecord() throws Exception
public void rejectCompletedRecord()
{
STEP("Create a document in the collaboration site");
FileModel testFile = dataContent.usingSite(publicSite)

View File

@@ -26,9 +26,9 @@
*/
package org.alfresco.rest.rm.community.records;
import static java.util.Arrays.asList;
import static org.alfresco.rest.rm.community.base.TestData.NONELECTRONIC_RECORD_NAME;
import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
@@ -40,7 +40,7 @@ import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.create
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicUnfiledContainerChildModel;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordModel;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.alfresco.utility.data.RandomData.getRandomName;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.HttpStatus.OK;
@@ -49,30 +49,26 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.record.Record;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildCollection;
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties;
import org.alfresco.rest.rm.community.model.user.UserPermissions;
import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RMUserAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
import org.alfresco.rest.v0.service.RoleService;
import org.alfresco.test.AlfrescoTest;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -86,18 +82,32 @@ import org.testng.annotations.Test;
*/
public class UpdateRecordsTests extends BaseRMRestTest
{
/* to be used to append to modifications */
private final String MODIFIED_PREFIX = "modified_";
@Autowired
private RoleService roleService;
private RecordCategory rootCategory;
private UnfiledContainerChild unfiledRecordFolder;
private final List<UnfiledContainerChild> unfiledRecords = new ArrayList<>();
private UserModel updateUser;
@BeforeClass (alwaysRun = true)
public void preconditionUpdateRecordsTests()
{
rootCategory = createRootCategory(getRandomName("CATEGORY NAME"));
unfiledRecordFolder = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS,
getRandomName("UnfiledRecordFolder"), UNFILED_RECORD_FOLDER_TYPE);
// RM Security Officer is the lowest role with Edit Record Metadata capabilities
// Grant updateUser Filing privileges on root category, this will be inherited to record folders
updateUser = roleService.createUserWithRMRoleAndCategoryPermission(ROLE_RM_SECURITY_OFFICER.roleId,
rootCategory, UserPermissions.PERMISSION_FILING);
}
/** Incomplete electronic and non electronic records created in one record folder, unfiled records container and one unfiled record folder */
@DataProvider(name = "incompleteRecords")
public Object[][] getIncompleteRecords() throws Exception
public Object[][] getIncompleteRecords()
{
//create electronic and nonElectronic record in record folder
String recordFolderId = createCategoryFolderInFilePlan().getId();
String recordFolderId = createRecordFolder(rootCategory.getId(), getRandomName("recFolder1")).getId();
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId, getFile(IMAGE_FILE));
@@ -110,36 +120,40 @@ public class UpdateRecordsTests extends BaseRMRestTest
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
UnfiledContainerChild electronicRecord1 = unfiledContainersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS, getFile(IMAGE_FILE));
assertStatusCode(CREATED);
unfiledRecords.add(electronicRecord1);
UnfiledContainerChild nonElectronicRecord1 = unfiledContainersAPI.createUnfiledContainerChild(createNonElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS);
assertStatusCode(CREATED);
unfiledRecords.add(nonElectronicRecord1);
//create electronic record and nonElectronic record in unfiled record folder
String unfiledRecordFolderId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId();
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
UnfiledContainerChild electronicRecord2 = unfiledRecordFoldersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), unfiledRecordFolderId, getFile(IMAGE_FILE));
UnfiledContainerChild electronicRecord2 = unfiledRecordFoldersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), unfiledRecordFolder.getId(), getFile(IMAGE_FILE));
assertStatusCode(CREATED);
UnfiledContainerChild nonElectronicRecord2 = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(createNonElectronicUnfiledContainerChildModel(), unfiledRecordFolderId);
UnfiledContainerChild nonElectronicRecord2 = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(createNonElectronicUnfiledContainerChildModel(), unfiledRecordFolder.getId());
assertStatusCode(CREATED);
return new String[][]
{
// an arbitrary record folder
{ electronicRecord.getId(), nonElectronicRecord.getId()},
// unfiled records root
{ electronicRecord1.getId(), nonElectronicRecord1.getId()},
// an arbitrary unfiled records folder
{ electronicRecord2.getId(), nonElectronicRecord2.getId()}
// an arbitrary record folder
{ electronicRecord.getId() },
{ nonElectronicRecord.getId() },
// unfiled records root
{ electronicRecord1.getId() },
{ nonElectronicRecord1.getId() },
// an arbitrary unfiled records folder
{ electronicRecord2.getId() },
{ nonElectronicRecord2.getId() }
};
}
/** Complete electronic and non electronic records created in one record folder, unfiled records container and one unfiled record folder */
@DataProvider(name = "completeRecords")
public Object[][] getCompleteRecords() throws Exception
public Object[][] getCompleteRecords()
{
//create electronic and nonElectronic record in record folder
String recordFolderId = createCategoryFolderInFilePlan().getId();
String recordFolderId = createRecordFolder(rootCategory.getId(), getRandomName("recFolder2")).getId();
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId, getFile(IMAGE_FILE));
@@ -155,19 +169,20 @@ public class UpdateRecordsTests extends BaseRMRestTest
UnfiledContainerChild electronicRecord1 = unfiledContainersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS, getFile(IMAGE_FILE));
assertStatusCode(CREATED);
completeRecord(electronicRecord1.getId());
unfiledRecords.add(electronicRecord1);
UnfiledContainerChild nonElectronicRecord1 = unfiledContainersAPI.createUnfiledContainerChild(createNonElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS);
assertStatusCode(CREATED);
completeRecord(nonElectronicRecord1.getId());
unfiledRecords.add(nonElectronicRecord1);
//create electronic record and nonElectronic record in unfiled record folder
String unfiledRecordFolderId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId();
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
UnfiledContainerChild electronicRecord2 = unfiledRecordFoldersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), unfiledRecordFolderId, getFile(IMAGE_FILE));
UnfiledContainerChild electronicRecord2 = unfiledRecordFoldersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), unfiledRecordFolder.getId(), getFile(IMAGE_FILE));
assertStatusCode(CREATED);
completeRecord(electronicRecord2.getId());
UnfiledContainerChild nonElectronicRecord2 = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(createNonElectronicUnfiledContainerChildModel(), unfiledRecordFolderId);
UnfiledContainerChild nonElectronicRecord2 = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(createNonElectronicUnfiledContainerChildModel(), unfiledRecordFolder.getId());
assertStatusCode(CREATED);
completeRecord(nonElectronicRecord2.getId());
@@ -188,7 +203,6 @@ public class UpdateRecordsTests extends BaseRMRestTest
* When I try to update the records meta-data
* Then the record is successfully updated
* </pre>
* @throws Exception
*/
@Test
(
@@ -196,30 +210,26 @@ public class UpdateRecordsTests extends BaseRMRestTest
description = "Incomplete records can be updated"
)
@AlfrescoTest(jira="RM-4362")
public void incompleteRecordsCanBeUpdated(String electronicRecordId, String nonElectronicRecordId) throws Exception
public void incompleteRecordsCanBeUpdated(String recordId)
{
// Get the recordsAPI
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
Record electronicRecord = recordsAPI.getRecord(electronicRecordId);
Record nonElectronicRecord = recordsAPI.getRecord(nonElectronicRecordId);
Record record = recordsAPI.getRecord(recordId);
for (Record record: Arrays.asList(electronicRecord, nonElectronicRecord)) {
// Generate update metadata
String newName = getModifiedPropertyValue(record.getName());
String newTitle = getModifiedPropertyValue(record.getProperties().getTitle());
String newDescription = getModifiedPropertyValue(record.getProperties().getDescription());
Record recordModel = createRecordModel(newName, newDescription, newTitle);
// Generate update metadata
String newName = getModifiedPropertyValue(record.getName());
String newTitle = getModifiedPropertyValue(record.getProperties().getTitle());
String newDescription = getModifiedPropertyValue(record.getProperties().getDescription());
// Update record
recordsAPI.updateRecord(recordModel, record.getId());
assertStatusCode(OK);
// Update record
recordsAPI.updateRecord(createRecordModel(newName, newDescription, newTitle), record.getId());
assertStatusCode(OK);
// Verify the original record meta data has been retained
Record updatedRecord = recordsAPI.getRecord(record.getId());
assertEquals(updatedRecord.getName(), newName);
assertEquals(updatedRecord.getProperties().getTitle(), newTitle);
assertEquals(updatedRecord.getProperties().getDescription(), newDescription);
}
// Verify the original record meta data has been retained
Record updatedRecord = recordsAPI.getRecord(record.getId());
assertEquals(updatedRecord.getName(), newName);
assertEquals(updatedRecord.getProperties().getTitle(), newTitle);
assertEquals(updatedRecord.getProperties().getDescription(), newDescription);
}
/**
@@ -229,44 +239,25 @@ public class UpdateRecordsTests extends BaseRMRestTest
* When I try to update the records meta-data
* Then the record is successfully updated
* </pre>
* @throws Exception
*/
@Test
(
description = "User with Edit Metadata capabilities can update incomplete record's metadata"
)
@Test (description = "User with Edit Metadata capabilities can update incomplete record's metadata")
@AlfrescoTest(jira="RM-4362")
public void userWithEditMetadataCapsCanUpdateMetadata() throws Exception
public void userWithEditMetadataCapsCanUpdateMetadata()
{
RMUserAPI rmUserAPI = getRestAPIFactory().getRMUserAPI();
// Create test user and add it with collab. privileges.
// RM Security Officer is the lowest role with Edit Record Metadata capabilities
UserModel updateUser = roleService.createUserWithRMRole(ROLE_RM_SECURITY_OFFICER.roleId);
updateUser.setUserRole(UserRole.SiteCollaborator);
getDataUser().addUserToSite(updateUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
// Create random folder
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
logger.info("random folder:" + recordFolder.getName());
// Grant updateUser Filing privileges on randomFolder category, this will be
// Inherited to randomFolder
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
rmUserAPI.addUserPermission(recordCategoryAPI.getRecordCategory(recordFolder.getParentId()).getId(),
updateUser, UserPermissions.PERMISSION_FILING);
assertStatusCode(OK);
RecordCategoryChild recFolder = createRecordFolder(rootCategory.getId(), getRandomName("recFolder"));
// Create electronic and non-electronic records in a folder
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder.getId(), getFile(IMAGE_FILE));
Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recFolder.getId(), getFile(IMAGE_FILE));
assertStatusCode(CREATED);
Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolder.getId());
Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recFolder.getId());
assertStatusCode(CREATED);
// Get recordsAPI instance initialised to updateUser
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(updateUser);
for (Record record: Arrays.asList(electronicRecord, nonElectronicRecord))
for (Record record: asList(electronicRecord, nonElectronicRecord))
{
recordsAPI.getRecord(record.getId());
assertStatusCode(OK);
@@ -275,10 +266,9 @@ public class UpdateRecordsTests extends BaseRMRestTest
String newName = getModifiedPropertyValue(record.getName());
String newTitle = getModifiedPropertyValue(record.getProperties().getTitle());
String newDescription = getModifiedPropertyValue(record.getProperties().getDescription());
Record recordModel = createRecordModel(newName, newDescription, newTitle);
// Update record
recordsAPI.updateRecord(recordModel, record.getId());
recordsAPI.updateRecord(createRecordModel(newName, newDescription, newTitle), record.getId());
assertStatusCode(OK);
// Verify the update got applied
@@ -295,9 +285,8 @@ public class UpdateRecordsTests extends BaseRMRestTest
* Given a complete record
* When I try to update the records meta-data
* Then it fails
* And and the records meta-data is unchanged
* And the records meta-data is unchanged
* </pre>
* @throws Exception
*/
@Test
(
@@ -305,14 +294,16 @@ public class UpdateRecordsTests extends BaseRMRestTest
description = "Complete records can't be updated"
)
@AlfrescoTest(jira="RM-4362")
public void completeRecordsCantBeUpdated(String electronicRecordId, String nonElectronicRecordId) throws Exception
@Bug (id = "APPS-132")
public void completeRecordsCantBeUpdated(String electronicRecordId, String nonElectronicRecordId)
{
// Get the recordsAPI
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
Record electronicRecord = recordsAPI.getRecord(electronicRecordId);
Record nonElectronicRecord = recordsAPI.getRecord(nonElectronicRecordId);
for (Record record: Arrays.asList(electronicRecord, nonElectronicRecord)) {
for (Record record: asList(electronicRecord, nonElectronicRecord))
{
// Generate update metadata
String newName = getModifiedPropertyValue(record.getName());
String newTitle = getModifiedPropertyValue(record.getProperties().getTitle());
@@ -338,6 +329,8 @@ public class UpdateRecordsTests extends BaseRMRestTest
*/
private String getModifiedPropertyValue(String originalValue)
{
/* to be used to append to modifications */
String MODIFIED_PREFIX = "modified_";
return MODIFIED_PREFIX + originalValue;
}
/**
@@ -346,89 +339,49 @@ public class UpdateRecordsTests extends BaseRMRestTest
* When I try to update the record aspects with an empty list
* Then it fails
* </pre>
* @throws Exception
*/
@Test(description = "Cannot remove mandatory aspects from record")
@AlfrescoTest(jira = "RM-4926")
public void electronicRecordMandatoryAspectsCannotBeRemoved() throws Exception
public void electronicRecordMandatoryAspectsCannotBeRemoved()
{
final List<String> expectedAspects = asList("rma:record", "rma:filePlanComponent",
"rma:recordComponentIdentifier", "rma:commonRecordDetails");
final List<String> emptyAspectList = new ArrayList<>();
Record recordModelToUpdate = Record.builder().aspectNames(emptyAspectList).build();
// Get the recordsAPI
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
// Create random folder
String recordFolderId = createRecordFolder(rootCategory.getId(), getRandomName("recordFolder")).getId();
// Create an electronic record
Record recordModel = createElectronicRecordModel();
String recordId = recordFolderAPI.createRecord(recordModel, recordFolder.getId(), getFile(IMAGE_FILE)).getId();
Record electronicRecord = recordsAPI.getRecord(recordId);
List<String> aspects = electronicRecord.getAspectNames();
// this operation is only valid for records
assertTrue(aspects.contains("rma:record"));
assertTrue(aspects.contains("rma:filePlanComponent"));
assertTrue(aspects.contains("rma:recordComponentIdentifier"));
assertTrue(aspects.contains("rma:commonRecordDetails"));
List<String> emptyAspectList = new ArrayList<String>();
Record recordModelToUpdate = Record.builder().aspectNames(emptyAspectList).build();
// Create an electronic record and check it has all the records aspects
Record electronicRecord = getRestAPIFactory().getRecordFolderAPI()
.createRecord(createElectronicRecordModel(), recordFolderId, getFile(IMAGE_FILE));
assertTrue( electronicRecord.getAspectNames().containsAll(expectedAspects));
// Update record
recordsAPI.updateRecord(recordModelToUpdate, electronicRecord.getId());
assertStatusCode(UNPROCESSABLE_ENTITY);
// Get the recordsAPI
UnfiledRecordFolderAPI unfiledRecordFolderAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
// Create root unfiled record folder
UnfiledContainerChild unfiledFolder = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, RECORD_FOLDER_NAME,
UNFILED_RECORD_FOLDER_TYPE);
// Create an electronic record
// Create an electronic record in the unfiled record folder and check it has all the records aspects
UnfiledContainerChild unfiledRecordModel = UnfiledContainerChild.builder()
.properties(UnfiledContainerChildProperties.builder().description(NONELECTRONIC_RECORD_NAME).title("Title").build())
.name(NONELECTRONIC_RECORD_NAME).nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()).build();
UnfiledContainerChild unfiledRecord = unfiledRecordFolderAPI.createUnfiledRecordFolderChild(unfiledRecordModel,
unfiledFolder.getId());
.name(NONELECTRONIC_RECORD_NAME).nodeType(NON_ELECTRONIC_RECORD_TYPE).build();
UnfiledContainerChild unfiledRecord = getRestAPIFactory().getUnfiledRecordFoldersAPI()
.createUnfiledRecordFolderChild(unfiledRecordModel, unfiledRecordFolder.getId());
assertTrue(unfiledRecord.getAspectNames().containsAll(expectedAspects));
aspects = unfiledRecord.getAspectNames();
assertTrue(aspects.contains("rma:record"));
assertTrue(aspects.contains("rma:filePlanComponent"));
assertTrue(aspects.contains("rma:recordComponentIdentifier"));
assertTrue(aspects.contains("rma:commonRecordDetails"));
Record recordModelToUpdateToUnfiled = Record.builder().aspectNames(emptyAspectList).build();
// Update record
recordsAPI.updateRecord(recordModelToUpdateToUnfiled, unfiledRecord.getId());
recordsAPI.updateRecord(recordModelToUpdate, unfiledRecord.getId());
assertStatusCode(UNPROCESSABLE_ENTITY);
}
@AfterClass (alwaysRun = true)
public void tearDown() throws Exception
public void tearDown()
{
FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI();
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
filePlansAPI.getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry ->
{
recordCategoryAPI.deleteRecordCategory(recordCategoryEntry.getEntry().getId());
});
UnfiledContainerChildCollection listedChildren = getRestAPIFactory().getUnfiledContainersAPI()
.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS);
listedChildren.getEntries().forEach(UnfiledContainerChildEntry ->
{
if (UnfiledContainerChildEntry.getEntry().getIsRecord())
{
getRestAPIFactory().getRecordsAPI().deleteRecord(UnfiledContainerChildEntry.getEntry().getId());
}
else
{
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(UnfiledContainerChildEntry.getEntry().getId());
}
});
deleteRecordCategory(rootCategory.getId());
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(unfiledRecordFolder.getId());
unfiledRecords.forEach(unfiledRecord -> getRestAPIFactory().getRecordsAPI().deleteRecord(unfiledRecord.getId()));
getDataUser().deleteUser(updateUser);
}
}

View File

@@ -36,7 +36,6 @@ import static org.testng.AssertJUnit.assertTrue;
import org.alfresco.dataprep.ContentActions;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
import org.alfresco.rest.rm.community.model.user.UserPermissions;
@@ -173,7 +172,7 @@ public class CmisQueryTests extends BaseRMRestTest
*/
@Test
@AlfrescoTest (jira = "MNT-19442")
public void getDocumentsWithSpecificNamesCmisQuery() throws Exception
public void getDocumentsWithSpecificNamesCmisQuery()
{
// execute the cmis query
ItemIterable<QueryResult> results =
@@ -196,7 +195,7 @@ public class CmisQueryTests extends BaseRMRestTest
*/
@Test
@AlfrescoTest (jira = "MNT-19442")
public void getDocumentsCmisQueryWithPagination() throws Exception
public void getDocumentsCmisQueryWithPagination()
{
OperationContext oc = new OperationContextImpl();
oc.setMaxItemsPerPage(10);
@@ -216,7 +215,7 @@ public class CmisQueryTests extends BaseRMRestTest
private void clearCmisQueryTests()
{
dataSite.usingAdmin().deleteSite(collaborationSite);
getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(recordFolder.getParentId());
deleteRecordCategory(recordFolder.getParentId());
getDataUser().usingAdmin().deleteUser(rmUser);
getDataUser().usingAdmin().deleteUser(nonRMUser);
}

View File

@@ -45,7 +45,6 @@ import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.SiteModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

View File

@@ -49,11 +49,10 @@ public class ShareLiveSearchTests extends BaseRMRestTest
*/
@Test
@AlfrescoTest(jira = "RM-5882")
public void liveSearchForVitalWord() throws Exception
public void liveSearchForVitalWord()
{
createRMSiteIfNotExists();
List<String> results = searchApi.liveSearchForDocumentsAsUser(getAdminUser().getUsername(), getAdminUser().getPassword(), "vital");
assertTrue(results.isEmpty() || !results.stream().anyMatch("Vital Records due for Review"::equalsIgnoreCase),
assertTrue(results.isEmpty() || results.stream().noneMatch("Vital Records due for Review"::equalsIgnoreCase),
"Share Live Search should return 0 results when searching for RM Saved Search filter words, but it returned:"
+ Arrays.toString(results.toArray()));
}

View File

@@ -71,11 +71,9 @@ public class RMSiteTests extends BaseRMRestTest
* When I want to create the RM site with specific title, description and compliance
* Then the RM site is created
*/
@Test
(
description = "Create RM site with Standard Compliance as admin user"
)
public void createRMSiteAsAdminUser() throws Exception
@Test (description = "Create RM site with Standard Compliance as admin user", priority = 2)
// Run after createRMSiteAsAnotherAdminUser. In this way the Dod site is deleted and standard site is created for the rest of the tests
public void createRMSiteAsAdminUser()
{
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
@@ -106,11 +104,9 @@ public class RMSiteTests extends BaseRMRestTest
* When I want to create the RM site
* Then the response code 409 (Site with the given identifier already exists) is return
*/
@Test
(
description = "Create RM site when site already exist with admin user"
)
public void createRMSiteWhenSiteExists() throws Exception
@Test (description = "Create RM site when site already exist with admin user", priority = 3)
// Run test after the other tests with priority 0, 1 or 2
public void createRMSiteWhenSiteExists()
{
// Create the RM site if it does not exist
createRMSiteIfNotExists();
@@ -132,11 +128,8 @@ public class RMSiteTests extends BaseRMRestTest
* When I want to delete the RM site
* Then RM site is successfully deleted
*/
@Test
(
description = "Delete RM site as admin user"
)
public void deleteRMSite() throws Exception
@Test (description = "Delete RM site as admin user")
public void deleteRMSite()
{
// Create the RM site if it does not exist
createRMSiteIfNotExists();
@@ -153,11 +146,9 @@ public class RMSiteTests extends BaseRMRestTest
* When I GET the retrieve the RM site details
* Then RM site details are returned
*/
@Test
(
description = "GET the RM site as admin user"
)
public void getRMSite() throws Exception
@Test (description = "GET the RM site as admin user", priority = 3)
// Run test after the tests with priority 0, 1 or 2
public void getRMSite()
{
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
@@ -187,12 +178,10 @@ public class RMSiteTests extends BaseRMRestTest
* When the user wants to create a RM site with DOD compliance
* Then RM site is created
*/
@Test
(
description = "Create RM site with DOD compliance as an another admin user"
)
// Run test after deleteRMSite. In this way rmSiteAPI.deleteRMSite isn't called because site is already deleted
@Test (description = "Create RM site with DOD compliance as an another admin user", priority = 1)
@Bug (id="RM-4289")
public void createRMSiteAsAnotherAdminUser() throws Exception
public void createRMSiteAsAnotherAdminUser()
{
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
@@ -228,8 +217,8 @@ public class RMSiteTests extends BaseRMRestTest
* When the admin user wants to update the RM site details (title or description)
* Then RM site details are updated
*/
@Test
public void updateRMSiteDetails() throws Exception
@Test(priority = 3) // Run test after the other tests with priority 0, 1 or 2
public void updateRMSiteDetails()
{
String NEW_TITLE = RM_TITLE + RandomData.getRandomAlphanumeric();
String NEW_DESCRIPTION = RM_DESCRIPTION + RandomData.getRandomAlphanumeric();
@@ -265,8 +254,8 @@ public class RMSiteTests extends BaseRMRestTest
* When the admin user wants to update the RM site compliance
* Then RM site compliance is not updated
*/
@Test
public void updateRMSiteComplianceAsAdmin() throws Exception
@Test(priority = 3) // Run test after the other tests with priority 0, 1 or 2
public void updateRMSiteComplianceAsAdmin()
{
// Create the RM site if it does not exist
createRMSiteIfNotExists();

View File

@@ -37,6 +37,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createUnfiledContainerChildModel;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.alfresco.utility.data.RandomData.getRandomName;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CONFLICT;
import static org.springframework.http.HttpStatus.CREATED;
@@ -48,6 +49,7 @@ import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
@@ -55,13 +57,11 @@ import java.util.NoSuchElementException;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.base.DataProviderClass;
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
import org.alfresco.rest.rm.community.model.record.RecordProperties;
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.UnfiledContainerChildCollection;
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties;
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledRecordFolder;
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
import org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil;
import org.alfresco.utility.report.Bug;
import org.springframework.http.HttpStatus;
@@ -79,6 +79,7 @@ public class UnfiledContainerTests extends BaseRMRestTest
{
/** Number of children (for children creation test) */
private static final int NUMBER_OF_CHILDREN = 10;
private final List<UnfiledContainerChild> unfiledChildren = new ArrayList<>();
/**
* Data Provider with:
@@ -101,13 +102,13 @@ public class UnfiledContainerTests extends BaseRMRestTest
* Given the RM site exists
* When I retrieve the unfiled record conteiner by placeholder
* Then the details of the unfiled record container is returned
* </pre>
* </pre>
*/
@Test
(
description = "Get the unfiled records container"
)
public void getUnfiledRecordsContainer() throws Exception
public void getUnfiledRecordsContainer()
{
// Get the unfiled records container
UnfiledContainer container = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
@@ -130,7 +131,7 @@ public class UnfiledContainerTests extends BaseRMRestTest
(
description = "Rename unfiled container"
)
public void renameUnfiledContainer() throws Exception
public void renameUnfiledContainer()
{
String newContainerName = "RenamedUnfiledContainer (" + getRandomAlphanumeric() + ")";
@@ -165,10 +166,11 @@ public class UnfiledContainerTests extends BaseRMRestTest
description = "Create unfiled record folder child in unfiled root container",
dataProvider = "unfiledFolderTypes"
)
public void createUnfiledRecordFolderChild(String folderType) throws Exception
public void createUnfiledRecordFolderChild(String folderType)
{
String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
UnfiledContainerChild unfiledRecordFolderChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName, folderType);
unfiledChildren.add(unfiledRecordFolderChild);
assertNotNull(unfiledRecordFolderChild.getId());
@@ -195,7 +197,7 @@ public class UnfiledContainerTests extends BaseRMRestTest
dataProvider = "unfiledFolderTypes"
)
@Bug(id ="RM-5116, RM-5148")
public void createDuplicateUnfiledFolderChild(String folderType) throws Exception
public void createDuplicateUnfiledFolderChild(String folderType)
{
String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
UnfiledContainerChild unfiledRecordFolderChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS,
@@ -203,26 +205,29 @@ public class UnfiledContainerTests extends BaseRMRestTest
// Verify the status code
assertStatusCode(CREATED);
unfiledChildren.add(unfiledRecordFolderChild);
assertEquals(unfiledRecordFolderChild.getName(), unfiledRecordFolderName);
// create the same unfiled folder
UnfiledContainerChild unfiledRecordFolderDuplicate = getRestAPIFactory().getUnfiledContainersAPI()
.createUnfiledContainerChild(createUnfiledContainerChildModel(unfiledRecordFolderName, folderType),
UNFILED_RECORDS_CONTAINER_ALIAS);
.createUnfiledContainerChild(createUnfiledContainerChildModel(unfiledRecordFolderName, folderType),
UNFILED_RECORDS_CONTAINER_ALIAS);
// Verify the status code
assertStatusCode(CONFLICT);
// create the same unfiled folder with the autoRename parameter on true
unfiledRecordFolderDuplicate = getRestAPIFactory().getUnfiledContainersAPI()
.createUnfiledContainerChild(createUnfiledContainerChildModel(unfiledRecordFolderName, folderType),UNFILED_RECORDS_CONTAINER_ALIAS,"autoRename=true");
.createUnfiledContainerChild(createUnfiledContainerChildModel(unfiledRecordFolderName, folderType),
UNFILED_RECORDS_CONTAINER_ALIAS, "autoRename=true");
//verify the response status code
assertStatusCode(CREATED);
unfiledChildren.add(unfiledRecordFolderDuplicate);
assertNotEquals(unfiledRecordFolderDuplicate.getName(), unfiledRecordFolderName);
assertTrue(unfiledRecordFolderDuplicate.getName().startsWith(unfiledRecordFolderName));
}
/**
* <pre>
* Given that an unfiled records container exists
@@ -234,21 +239,18 @@ public class UnfiledContainerTests extends BaseRMRestTest
(
description = "Create unfiled record folder child in unfiled root container"
)
public void createUnfiledRecordFolderChildWithRelativePathNotSuported() throws Exception
public void createUnfiledRecordFolderChildWithRelativePathNotSuported()
{
UnfiledContainerAPI unfiledContainerAPI = getRestAPIFactory().getUnfiledContainersAPI();
// relativePath specify the container structure to create relative to
// the record folder to be created
String relativePath = now().getYear() + "/" + now().getMonth() + "/" + now().getDayOfMonth();
String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
UnfiledContainerChild unfiledFolderModel = UnfiledContainerChild.builder()
.name(unfiledRecordFolderName)
.nodeType(UNFILED_RECORD_FOLDER_TYPE)
.relativePath(relativePath)
.build();
unfiledContainerAPI.createUnfiledContainerChild(unfiledFolderModel, UNFILED_RECORDS_CONTAINER_ALIAS);
.name(getRandomName("UnfiledRecordFolder"))
.nodeType(UNFILED_RECORD_FOLDER_TYPE)
.relativePath(relativePath)
.build();
getRestAPIFactory().getUnfiledContainersAPI()
.createUnfiledContainerChild(unfiledFolderModel, UNFILED_RECORDS_CONTAINER_ALIAS);
// Check the API response code
assertStatusCode(BAD_REQUEST);
@@ -265,10 +267,11 @@ public class UnfiledContainerTests extends BaseRMRestTest
(
description = "Create non-electronic record child in unfiled root container"
)
public void createNonElectronicRecordChild() throws Exception
public void createNonElectronicRecordChild()
{
String recordName = "NERecord-" + getRandomAlphanumeric();
UnfiledContainerChild unfiledRecord = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, recordName, NON_ELECTRONIC_RECORD_TYPE);
unfiledChildren.add(unfiledRecord);
assertNotNull(unfiledRecord.getId());
assertTrue(unfiledRecord.getIsRecord());
@@ -293,10 +296,11 @@ public class UnfiledContainerTests extends BaseRMRestTest
(
description = "Create electronic record child in unfiled root container"
)
public void createElectronicRecordChild() throws Exception
public void createElectronicRecordChild()
{
String recordName = "ERecord-" + getRandomAlphanumeric();
UnfiledContainerChild unfiledRecord = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, recordName, CONTENT_TYPE);
unfiledChildren.add(unfiledRecord);
assertNotNull(unfiledRecord.getId());
assertTrue(unfiledRecord.getIsRecord());
@@ -322,11 +326,11 @@ public class UnfiledContainerTests extends BaseRMRestTest
(
description = "Get children of the root unfiled root container"
)
public void getUnfiledRootContainerChildren() throws Exception
public void getUnfiledRootContainerChildren()
{
// Add unfiled root container children
List<UnfiledContainerChild> createdChildren = new LinkedList<>();
for (int i=0; i < NUMBER_OF_CHILDREN; i++)
for (int i = 0; i < NUMBER_OF_CHILDREN; i++)
{
String childType;
if (i % 3 == 0)
@@ -367,9 +371,8 @@ public class UnfiledContainerTests extends BaseRMRestTest
{
// Get the element from the created children list
UnfiledContainerChild createdComponent = createdChildren.stream()
.filter(child -> child.getId().equals(childId))
.findFirst()
.get();
.filter(child -> child.getId().equals(childId))
.findFirst().orElseThrow();
// Created by
assertEquals(containerChild.getCreatedByUser().getId(), getAdminUser().getUsername());
@@ -408,6 +411,7 @@ public class UnfiledContainerTests extends BaseRMRestTest
// check all the created elements have been returned
assertTrue(verifiedChildren.containsAll(createdChildren));
assertTrue(createdChildren.containsAll(verifiedChildren));
unfiledChildren.addAll(createdChildren);
}
/**
@@ -429,35 +433,28 @@ public class UnfiledContainerTests extends BaseRMRestTest
// Build unfiled records folder properties
UnfiledContainerChild unfiledFolderModel = createUnfiledContainerChildModel(unfiledRecordFolderName, filePlanComponentType);
try
{
getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(unfiledFolderModel, UNFILED_RECORDS_CONTAINER_ALIAS);
}
catch (Exception error)
{
}
getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(unfiledFolderModel, UNFILED_RECORDS_CONTAINER_ALIAS);
// Verify the status code
assertStatusCode(UNPROCESSABLE_ENTITY);
}
@Test(description = "Create a record with custom record identifier in unfiled container")
public void createRecordWithCustomIdentifier() throws Exception
public void createRecordWithCustomIdentifier()
{
String recordName = "customIdRecord-" + getRandomAlphanumeric();
String customIdentifier = "customId";
RecordProperties propertiesModel = RecordProperties.builder().identifier(customIdentifier).build();
UnfiledContainerChildProperties propertiesModel = UnfiledContainerChildProperties.builder().identifier(customIdentifier).build();
UnfiledContainerChild childModel = UnfiledContainerChild.builder()
.name(recordName)
.nodeType(CONTENT_TYPE)
.properties(UnfiledContainerChildProperties.builder()
.identifier(customIdentifier)
.build())
.build();
.name(recordName)
.nodeType(CONTENT_TYPE)
.properties(propertiesModel)
.build();
UnfiledContainerChild child = getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(childModel, UNFILED_RECORDS_CONTAINER_ALIAS);
assertStatusCode(HttpStatus.CREATED);
unfiledChildren.add(child);
assertEquals(child.getProperties().getIdentifier(), customIdentifier);
assertEquals(child.getName(), recordName + " (" + customIdentifier + ")");
}
@@ -465,18 +462,15 @@ public class UnfiledContainerTests extends BaseRMRestTest
@AfterClass (alwaysRun = true)
public void tearDown()
{
UnfiledContainerChildCollection listedChildren = getRestAPIFactory().getUnfiledContainersAPI()
.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS);
listedChildren.getEntries().forEach(UnfiledContainerChildEntry ->
unfiledChildren.forEach(unfiledChild ->
{
if (UnfiledContainerChildEntry.getEntry().getIsRecord())
if (unfiledChild.getIsRecord())
{
getRestAPIFactory().getRecordsAPI().deleteRecord(UnfiledContainerChildEntry.getEntry().getId());
getRestAPIFactory().getRecordsAPI().deleteRecord(unfiledChild.getId());
}
else
{
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(UnfiledContainerChildEntry.getEntry().getId());
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(unfiledChild.getId());
}
});
}

View File

@@ -28,11 +28,9 @@ package org.alfresco.rest.rm.community.unfiledrecordfolders;
import static java.time.LocalDateTime.now;
import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias
.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
@@ -40,6 +38,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createUnfiledContainerChildModel;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.alfresco.utility.data.RandomData.getRandomName;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NOT_FOUND;
@@ -59,6 +58,7 @@ import java.util.stream.Collectors;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.base.DataProviderClass;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildCollection;
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties;
@@ -66,7 +66,7 @@ import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledRecordFolder
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
import org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -78,13 +78,24 @@ import org.testng.annotations.Test;
*/
public class UnfiledRecordsFolderTests extends BaseRMRestTest
{
public static final String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric();
public static final String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
public static final String ELECTRONIC_RECORD_NAME = getRandomName("Record electronic");
public static final String NONELECTRONIC_RECORD_NAME = getRandomName("Record nonelectronic");
private RecordCategory rootCategory;
private UnfiledContainerChild unfiledRecordFolder, rootUnfiledRecordFolder, unfiledRecord;
@BeforeClass(alwaysRun = true)
public void preconditionUnfiledRecordsFolderTests()
{
rootCategory = createRootCategory(getRandomName("CATEGORY NAME"));
rootUnfiledRecordFolder = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS,
getRandomName("RootUnfiledRecFolder"), UNFILED_RECORD_FOLDER_TYPE);
unfiledRecord = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS,
getRandomName("Unfiled Record"), CONTENT_TYPE);
}
/**
* valid root level types, at unfiled record folder level these possible to create
*/
@DataProvider (name = "validChildren")
public Object[][] childrenForUnfiledRecord()
{
@@ -100,20 +111,20 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
* Invalid containers that cannot be updated/deleted with record folder endpoint
*/
@DataProvider (name = "invalidNodesForDelete")
public Object[][] getInvalidNodes() throws Exception
public Object[][] getInvalidNodes()
{
return new String[][] {
{ getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS).getId() },
{ getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId() },
{ getRestAPIFactory().getTransferContainerAPI().getTransferContainer(TRANSFERS_ALIAS).getId() },
// an arbitrary record category
{ createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()).getId() },
{ rootCategory.getId() },
// an arbitrary unfiled records folder
{createCategoryFolderInFilePlan().getId()},
{createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Record " + getRandomAlphanumeric(), CONTENT_TYPE).getId() }
{createRecordFolder(rootCategory.getId(), getRandomName("recFolder")).getId()},
{unfiledRecord.getId() }
};
}
/**
* <pre>
* Given that I want to create an unfiled record folder
@@ -127,49 +138,46 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
"Containers in the relativePath that do not exist are created before the node is created",
dataProvider = "validChildren"
)
public void createUnfiledRecordFolderWithRelativePath(String nodeType) throws Exception
public void createUnfiledRecordFolderWithRelativePath(String nodeType)
{
String unfiledRecordFolderName1 = "UnfiledRecordFolder-" + getRandomAlphanumeric();
UnfiledContainerChild unfiledRecordFolderChild1 = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName1, UNFILED_RECORD_FOLDER_TYPE);
String unfiledRecordFolderName2 = "UnfiledRecordFolder-" + getRandomAlphanumeric();
// relativePath specify the container structure to create relative to the record folder to be created
String relativePath = now().getYear() + "/" + now().getMonth() + "/" + now().getDayOfMonth();
// The record folder to be created
UnfiledContainerChild unfiledChildModel =UnfiledContainerChild.builder()
.name(unfiledRecordFolderName2)
.nodeType(nodeType)
.relativePath(relativePath)
.build();
UnfiledContainerChild unfiledRecordFolderChild = getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(unfiledChildModel, unfiledRecordFolderChild1.getId(), "include=" + PATH);
UnfiledContainerChild unfiledChildModel = UnfiledContainerChild.builder()
.name(getRandomName("UnfiledRecordFolder"))
.nodeType(nodeType)
.relativePath(relativePath)
.build();
UnfiledContainerChild unfiledRecordFolderChild = getRestAPIFactory().getUnfiledRecordFoldersAPI()
.createUnfiledRecordFolderChild(unfiledChildModel, rootUnfiledRecordFolder.getId(), "include=" + PATH);
// Check the API response code
assertStatusCode(CREATED);
// Verify the returned node type
assertTrue(nodeType.equals(unfiledRecordFolderChild.getNodeType()));
assertEquals(unfiledRecordFolderChild.getNodeType(), nodeType);
// Check the path return contains the relativePath
assertTrue(unfiledRecordFolderChild.getPath().getName().contains(relativePath));
// Check the parent is a folder, not a record
assertTrue(getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledRecordFolderChild.getParentId()).getNodeType().equals(UNFILED_RECORD_FOLDER_TYPE));
assertEquals(getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledRecordFolderChild.getParentId()).getNodeType(),
UNFILED_RECORD_FOLDER_TYPE);
// New relative path only a part of containers need to be created before the record folder
String newRelativePath = now().getYear() + "/" + now().getMonth() + "/" + (now().getDayOfMonth() + 1);
String unfiledRecordFolderName3 = "UnfiledRecordFolder-" + getRandomAlphanumeric();
// The record folder to be created
UnfiledContainerChild newUnfiledFolderModel =UnfiledContainerChild.builder()
.name(unfiledRecordFolderName3)
.nodeType(nodeType)
.relativePath(newRelativePath)
.build();
UnfiledContainerChild newUnfiledRecordFolderChild = getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(newUnfiledFolderModel, unfiledRecordFolderChild1.getId(), "include=" + PATH);
UnfiledContainerChild newUnfiledFolderModel = UnfiledContainerChild.builder()
.name(getRandomName("UnfiledRecordFolder"))
.nodeType(nodeType)
.relativePath(newRelativePath)
.build();
UnfiledContainerChild newUnfiledRecordFolderChild = getRestAPIFactory().getUnfiledRecordFoldersAPI()
.createUnfiledRecordFolderChild(newUnfiledFolderModel, rootUnfiledRecordFolder.getId(), "include=" + PATH);
// Check the API response code
assertStatusCode(CREATED);
@@ -180,8 +188,7 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
// Check the parent is a folder, not a record
assertFalse(getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(newUnfiledRecordFolderChild.getParentId()).equals(UNFILED_RECORD_FOLDER_TYPE));
// Verify the returned node type
assertTrue(nodeType.equals(newUnfiledRecordFolderChild.getNodeType()));
assertEquals(newUnfiledRecordFolderChild.getNodeType(), nodeType);
}
/**
@@ -194,22 +201,13 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
dataProviderClass = DataProviderClass.class,
description = "Only unfiled records folders and records can be created as children for unfiled container root"
)
public void createInvalidUnfiledChildren(String filePlanComponentType) throws Exception
public void createInvalidUnfiledChildren(String filePlanComponentType)
{
String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
UnfiledContainerChild unfiledRecordFolderChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName, UNFILED_RECORD_FOLDER_TYPE);
logger.info("creating " + filePlanComponentType);
// Build unfiled records folder properties
UnfiledContainerChild unfiledFolderModel = createUnfiledContainerChildModel(unfiledRecordFolderName, filePlanComponentType);
UnfiledContainerChild unfiledFolderModel = createUnfiledContainerChildModel(getRandomName("UnfiledRecFolder"), filePlanComponentType);
getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(unfiledFolderModel, rootUnfiledRecordFolder.getId());
try
{
getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(unfiledFolderModel, unfiledRecordFolderChild.getId());
}
catch (Exception error)
{
}
// Verify the status code
assertStatusCode(UNPROCESSABLE_ENTITY);
}
@@ -218,20 +216,15 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
* Given an unfiled record folder
* When I create an unfiled record folder via the ReST API
* Then an unfiled record folder is created within the unfiled record folder
*
* @throws Exception for failed actions
*/
@Test(description = "Child unfiled records folder can be created in a parent unfiled records folder")
public void childUnfiledRecordsFolderCanBeCreated() throws Exception
public void childUnfiledRecordsFolderCanBeCreated()
{
String unfiledParentFolderName = "UnfiledParentFolder" + getRandomAlphanumeric();
String unfiledChildFolderName = "UnfiledChildFolder " + getRandomAlphanumeric();
String rootUnfiledFolderName = "RootUnfiledFolder" + getRandomAlphanumeric();
//create root unfiled record folder
UnfiledContainerChild createUnfiledContainerChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, rootUnfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
// No need for fine control, create it using utility function
UnfiledContainerChild unfiledParentFolder = createUnfiledRecordsFolderChild(createUnfiledContainerChild.getId(),
UnfiledContainerChild unfiledParentFolder = createUnfiledRecordsFolderChild(rootUnfiledRecordFolder.getId(),
unfiledParentFolderName, UNFILED_RECORD_FOLDER_TYPE);
assertEquals(unfiledParentFolderName, unfiledParentFolder.getName());
@@ -291,20 +284,15 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
* Given an unfiled record folder
* When I modify the unfiled record folder details via the ReST API
* Then the details of the unfiled record folder are modified
*
* @throws Exception for failed actions
*/
@Test(description = "Unfiled record folder")
public void editUnfiledRecordsFolder() throws Exception
public void editUnfiledRecordsFolder()
{
String modified = "Modified ";
String unfiledFolderName = "UnfiledFolderToModify" + getRandomAlphanumeric();
String rootUnfiledFolderName = "RootUnfiledFolder" + getRandomAlphanumeric();
//create root unfiledRecordFolder
UnfiledContainerChild createUnfiledContainerChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS,rootUnfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
// No need for fine control, create it using utility function
UnfiledContainerChild unfiledFolderToModify = createUnfiledRecordsFolderChild(createUnfiledContainerChild.getId(),
UnfiledContainerChild unfiledFolderToModify = createUnfiledRecordsFolderChild(rootUnfiledRecordFolder.getId(),
unfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
assertEquals(unfiledFolderName, unfiledFolderToModify.getName());
@@ -348,33 +336,28 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
* Given an unfiled record folder and some records inside
* When I delete the unfiled record folder via the ReST API
* Then the unfiled record folder is deleted and its content too
*
* @throws Exception for failed actions
*/
@Test(description = "Delete unfiled record folder")
public void deleteUnfiledRecordsFolder() throws Exception
public void deleteUnfiledRecordsFolder()
{
String unfiledFolderName = "UnfiledFolderToDelete" + getRandomAlphanumeric();
String nonElectronicRecordName = "NonElectronicRecord" + getRandomAlphanumeric();
String electronicRecordName = "ElectronicRecord" + getRandomAlphanumeric();
String rootUnfiledFolderName = "RootUnfiledFolder" + getRandomAlphanumeric();
//create root unfiled record folder
UnfiledContainerChild createUnfiledContainerChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, rootUnfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
// Create unfiledFolderToDelete
UnfiledContainerChild unfiledFolderToDelete = createUnfiledRecordsFolderChild(createUnfiledContainerChild.getId(),
UnfiledContainerChild unfiledFolderToDelete = createUnfiledRecordsFolderChild(rootUnfiledRecordFolder.getId(),
unfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
assertEquals(unfiledFolderName, unfiledFolderToDelete.getName());
// Create a non electronic record under unfiledFolderToDelete
UnfiledContainerChild nonElectronicRecord = createUnfiledRecordsFolderChild(unfiledFolderToDelete.getId(),
nonElectronicRecordName, NON_ELECTRONIC_RECORD_TYPE);
assertTrue(nonElectronicRecord.getParentId().equals(unfiledFolderToDelete.getId()));
assertEquals(nonElectronicRecord.getParentId(), unfiledFolderToDelete.getId());
// Create an electronic record under unfiledFolderToDelete
UnfiledContainerChild electronicRecord = createUnfiledRecordsFolderChild(unfiledFolderToDelete.getId(),
electronicRecordName, CONTENT_TYPE);
assertTrue(electronicRecord.getParentId().equals(unfiledFolderToDelete.getId()));
assertEquals(electronicRecord.getParentId(), unfiledFolderToDelete.getId());
// Delete folderToDelete
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(unfiledFolderToDelete.getId());
@@ -399,11 +382,10 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
description = "Delete invalid nodes type with the DELETE unfiled record folders request",
dataProvider = "invalidNodesForDelete"
)
public void deleteInvalidNodesUnfiled(String nodeId) throws Exception
public void deleteInvalidNodesUnfiled(String nodeId)
{
// Delete the nodes with record-folders end-point
UnfiledRecordFolderAPI unfiledFolderAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
unfiledFolderAPI.deleteUnfiledRecordFolder(nodeId);
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(nodeId);
// Check the response status code
assertStatusCode(BAD_REQUEST);
@@ -415,29 +397,26 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
* Then I receive a list of all the records contained within the unfiled record folder
*/
@Test
public void readRecordsFromUnfiledRecordFolder() throws Exception
public void readRecordsFromUnfiledRecordFolder()
{
final int NUMBER_OF_RECORDS = 5;
String containerId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId();
unfiledRecordFolder = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, getRandomName("UnfiledRecordFolder"), UNFILED_RECORD_FOLDER_TYPE);
String containerId = unfiledRecordFolder.getId();
//we have unfiled record folder
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
// Create Electronic Records
ArrayList<UnfiledContainerChild> children = new ArrayList<UnfiledContainerChild>();
for (int i = 0; i < NUMBER_OF_RECORDS; i++)
ArrayList<UnfiledContainerChild> children = new ArrayList<>();
for (int i = 0; i < 5; i++)
{
//build the electronic record
// Create Electronic Records
UnfiledContainerChild record = UnfiledContainerChild.builder()
.name(ELECTRONIC_RECORD_NAME + i)
.nodeType(CONTENT_TYPE)
.build();
//create a child
UnfiledContainerChild child = unfiledRecordFoldersAPI.uploadRecord(record, containerId, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i));
children.add(child);
}
//Create NonElectronicRecords
for (int i = 0; i < NUMBER_OF_RECORDS; i++)
{
//Create NonElectronicRecords
UnfiledContainerChild nonelectronicRecord = UnfiledContainerChild.builder()
.properties(UnfiledContainerChildProperties.builder()
.description("Description")
@@ -446,9 +425,7 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
.name(NONELECTRONIC_RECORD_NAME + i)
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
//create records
UnfiledContainerChild child = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonelectronicRecord, containerId);
child = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonelectronicRecord, containerId);
children.add(child);
}
@@ -472,7 +449,7 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
UnfiledContainerChild createdComponent = children.stream()
.filter(child -> child.getId().equals(record.getId()))
.findFirst()
.get();
.orElseThrow();
// Created by
assertEquals(record.getCreatedByUser().getId(), getAdminUser().getUsername());
@@ -485,9 +462,8 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
assertFalse(record.getIsUnfiledRecordFolder());
//check the record name
assertTrue(record.getName().equals(createdComponent.getName()),
"The record name "+ record.getName()+" is not equal with the record name returned when creating the record " + createdComponent
.getName());
assertEquals(createdComponent.getName(), record.getName(),
"The record name " + record.getName() + " is not equal with the record name returned when creating the record " + createdComponent.getName());
String identifier = " \\(" + record.getProperties().getIdentifier() + "\\)";
String regex= "(" + NONELECTRONIC_RECORD_NAME + "|" + ELECTRONIC_RECORD_NAME + ")" + "[0-9]+" + identifier;
assertTrue(record.getName().matches(regex),
@@ -502,24 +478,13 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
}
});
}
@AfterTest
@AfterClass (alwaysRun = true)
public void tearDown() throws Exception
{
UnfiledContainerChildCollection listedChildren = getRestAPIFactory().getUnfiledContainersAPI()
.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS);
listedChildren.getEntries().forEach(UnfiledContainerChildEntry ->
{
if (UnfiledContainerChildEntry.getEntry().getIsRecord())
{
getRestAPIFactory().getRecordsAPI().deleteRecord(UnfiledContainerChildEntry.getEntry().getId());
}
else
{
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(UnfiledContainerChildEntry.getEntry().getId());
}
});
@AfterClass (alwaysRun = true)
public void tearDown()
{
deleteRecordCategory(rootCategory.getId());
getRestAPIFactory().getRecordsAPI().deleteRecord(unfiledRecord.getId());
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(rootUnfiledRecordFolder.getId());
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(unfiledRecordFolder.getId());
}
}

View File

@@ -63,7 +63,6 @@ public class CoreUtil
* Helper method to create a Content Model
*
* @return ContentModel
* @throws Exception
*/
public static ContentModel toContentModel(String nodeId)
{
@@ -74,7 +73,6 @@ public class CoreUtil
* Helper method to create a File Model
*
* @return ContentModel
* @throws Exception
*/
public static FileModel toFileModel(String nodeId)
{

View File

@@ -6,4 +6,4 @@
<package name="org.alfresco.rest.rm.community.*"/>
</packages>
</test>
</suite>
</suite>

View File

@@ -69,6 +69,11 @@ rm.autocompletesuggestion.nodeParameterSuggester.aspectsAndTypes=rma:record,cm:c
#
rm.dispositionlifecycletrigger.cronexpression=0 0/5 * * * ?
#
# Global RM retention lifecycle cron job execution batch size
#
rm.dispositionlifecycletrigger.batchsize=500
#
# Global RM notify of records due for review cron job expression
#

View File

@@ -80,6 +80,7 @@
<property name="searchService" ref="searchService" />
<property name="personService" ref="personService" />
<property name="recordsManagementActionService" ref="recordsManagementActionService" />
<property name="batchSize" value="${rm.dispositionlifecycletrigger.batchsize}"/>
</bean>
<bean id="scheduledDispositionLifecyceleSchedulerAccessor" class="org.alfresco.schedule.AlfrescoSchedulerAccessorBean">

View File

@@ -60,6 +60,9 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
/** logger */
private static Log logger = LogFactory.getLog(DispositionLifecycleJobExecuter.class);
/** batching properties */
private int batchSize;
/** list of disposition actions to automatically execute */
private List<String> dispositionActions;
@@ -88,6 +91,11 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
this.dispositionActions = dispositionActions;
}
public void setBatchSize(int batchSize)
{
this.batchSize = batchSize;
}
/**
* @param recordsManagementActionService records management action service
*/
@@ -167,13 +175,14 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
{
boolean hasMore = true;
int skipCount = 0;
while(hasMore)
while (hasMore)
{
SearchParameters params = new SearchParameters();
params.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
params.setQuery(getQuery());
params.setSkipCount(skipCount);
params.setMaxItems(batchSize);
// execute search
ResultSet results = searchService.query(params);
@@ -188,13 +197,12 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
}
// process search results
for (NodeRef node : resultNodes)
if (!resultNodes.isEmpty())
{
executeAction(node);
executeAction(resultNodes);
}
}
}
logger.debug("Job Finished");
}
catch (AlfrescoRuntimeException exception)
@@ -209,57 +217,52 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
/**
* Helper method that executes a disposition action
*
* @param actionNode - the disposition action to execute
* @param actionNodes - the disposition actions to execute
*/
private void executeAction(final NodeRef actionNode)
private void executeAction(final List<NodeRef> actionNodes)
{
RetryingTransactionCallback<Boolean> processTranCB = new RetryingTransactionCallback<Boolean>()
{
public Boolean execute()
RetryingTransactionCallback<Boolean> processTranCB = () -> {
for (NodeRef actionNode : actionNodes)
{
final String dispAction = (String) nodeService.getProperty(actionNode,
RecordsManagementModel.PROP_DISPOSITION_ACTION);
// Run disposition action
if (dispAction != null && dispositionActions.contains(dispAction))
if (nodeService.exists(actionNode))
{
ChildAssociationRef parent = nodeService.getPrimaryParent(actionNode);
if (parent.getTypeQName().equals(RecordsManagementModel.ASSOC_NEXT_DISPOSITION_ACTION))
final String dispAction = (String) nodeService
.getProperty(actionNode, RecordsManagementModel.PROP_DISPOSITION_ACTION);
// Run disposition action
if (dispAction != null && dispositionActions.contains(dispAction))
{
Map<String, Serializable> props = new HashMap<>(1);
props.put(RMDispositionActionExecuterAbstractBase.PARAM_NO_ERROR_CHECK,
Boolean.FALSE);
try
ChildAssociationRef parent = nodeService.getPrimaryParent(actionNode);
if (parent.getTypeQName().equals(RecordsManagementModel.ASSOC_NEXT_DISPOSITION_ACTION))
{
// execute disposition action
recordsManagementActionService.executeRecordsManagementAction(
parent.getParentRef(), dispAction, props);
Map<String, Serializable> props = new HashMap<>(1);
props.put(RMDispositionActionExecuterAbstractBase.PARAM_NO_ERROR_CHECK, Boolean.FALSE);
if (logger.isDebugEnabled())
try
{
logger.debug("Processed action: " + dispAction + "on" + parent);
// execute disposition action
recordsManagementActionService
.executeRecordsManagementAction(parent.getParentRef(), dispAction, props);
if (logger.isDebugEnabled())
{
logger.debug("Processed action: " + dispAction + "on" + parent);
}
}
}
catch (AlfrescoRuntimeException exception)
{
if (logger.isDebugEnabled())
catch (AlfrescoRuntimeException exception)
{
logger.debug(exception);
if (logger.isDebugEnabled())
{
logger.debug(exception);
}
}
}
}
}
return Boolean.TRUE;
}
return Boolean.TRUE;
};
// if exists
if (nodeService.exists(actionNode))
{
retryingTransactionHelper.doInTransaction(processTranCB);
}
retryingTransactionHelper.doInTransaction(processTranCB, false, true);
}
public PersonService getPersonService()

View File

@@ -33,6 +33,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -56,8 +57,8 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/**
@@ -73,7 +74,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
private static final String RETAIN = "retain";
private static final String DESTROY = "destroy";
/** test query snipit */
/** test query snippet */
private static final String QUERY = "\"" + CUTOFF + "\" OR \"" + RETAIN + "\"";
/** mocked result set */
@@ -91,9 +92,17 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
{
super.before();
Answer<Object> doInTransactionAnswer = invocation -> {
RetryingTransactionCallback callback = (RetryingTransactionCallback)invocation.getArguments()[0];
return callback.execute();
};
doAnswer(doInTransactionAnswer).when(mockedRetryingTransactionHelper).doInTransaction(any(RetryingTransactionCallback.class),
Matchers.anyBoolean(), Matchers.anyBoolean());
// setup data
List<String> dispositionActions = buildList(CUTOFF, RETAIN);
executer.setDispositionActions(dispositionActions);
executer.setBatchSize(1);
// setup interactions
doReturn(mockedResultSet).when(mockedSearchService).query(any(SearchParameters.class));
@@ -102,14 +111,15 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
/**
* Helper method to verify that the query has been executed and closed
* @param numberOfInvocation number of times the query has been executed and closed
*/
private void verifyQuery()
private void verifyQueryTimes(int numberOfInvocation)
{
ArgumentCaptor<SearchParameters> paramsCaptor = ArgumentCaptor.forClass(SearchParameters.class);
verify(mockedSearchService, times(1)).query(paramsCaptor.capture());
verify(mockedSearchService, times(numberOfInvocation)).query(paramsCaptor.capture());
assertTrue(paramsCaptor.getValue().getQuery().contains(QUERY));
verify(mockedResultSet, times(1)).getNodeRefs();
verify(mockedResultSet, times(1)).close();
verify(mockedResultSet, times(numberOfInvocation)).getNodeRefs();
verify(mockedResultSet, times(numberOfInvocation)).close();
}
/**
@@ -127,7 +137,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
// then
// ensure the query is executed and closed
verifyQuery();
verifyQueryTimes(1);
// ensure nothing else happens becuase we have no results
verifyZeroInteractions(mockedNodeService, mockedRecordFolderService, mockedRetryingTransactionHelper);
@@ -143,24 +153,31 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
// test data
NodeRef node1 = generateNodeRef();
NodeRef node2 = generateNodeRef();
List<NodeRef> nodeRefs = buildList(node1, node2);
// given
doReturn(nodeRefs).when(mockedResultSet).getNodeRefs();
doReturn(DESTROY).when(mockedNodeService).getProperty(node1, RecordsManagementModel.PROP_DISPOSITION_ACTION);
doReturn(DESTROY).when(mockedNodeService).getProperty(node2, RecordsManagementModel.PROP_DISPOSITION_ACTION);
when(mockedResultSet.getNodeRefs())
.thenReturn(buildList(node1))
.thenReturn(buildList(node2));
when(mockedResultSet.hasMore())
.thenReturn(true)
.thenReturn(false);
// when
executer.executeImpl();
// then
// ensure the query is executed and closed
verifyQuery();
verifyQueryTimes(2);
// ensure work is executed in transaction for each node processed
verify(mockedNodeService, times(2)).exists(any(NodeRef.class));
verify(mockedRetryingTransactionHelper, times(2)).<Object>doInTransaction(any(RetryingTransactionCallback.class));
verify(mockedRetryingTransactionHelper, times(2)).doInTransaction(any(RetryingTransactionCallback.class),
Matchers.anyBoolean(), Matchers.anyBoolean());
// ensure each node is process correctly
verify(mockedNodeService, times(1)).getProperty(node1, RecordsManagementModel.PROP_DISPOSITION_ACTION);
@@ -191,14 +208,14 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
// then
// ensure the query is executed and closed
verifyQuery();
verifyQueryTimes(1);
// ensure the node exist check is made for the node
verify(mockedNodeService, times(1)).exists(any(NodeRef.class));
// ensure no more interactions
verifyNoMoreInteractions(mockedNodeService);
verifyZeroInteractions(mockedRecordsManagementActionService, mockedRetryingTransactionHelper);
verifyZeroInteractions(mockedRecordsManagementActionService);
}
/**
@@ -211,27 +228,33 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
// test data
NodeRef node1 = generateNodeRef();
NodeRef node2 = generateNodeRef();
List<NodeRef> nodeRefs = buildList(node1, node2);
NodeRef parent = generateNodeRef();
ChildAssociationRef parentAssoc = new ChildAssociationRef(ASSOC_NEXT_DISPOSITION_ACTION, parent, generateQName(), generateNodeRef());
// given
doReturn(nodeRefs).when(mockedResultSet).getNodeRefs();
doReturn(CUTOFF).when(mockedNodeService).getProperty(node1, RecordsManagementModel.PROP_DISPOSITION_ACTION);
doReturn(RETAIN).when(mockedNodeService).getProperty(node2, RecordsManagementModel.PROP_DISPOSITION_ACTION);
doReturn(parentAssoc).when(mockedNodeService).getPrimaryParent(any(NodeRef.class));
when(mockedResultSet.getNodeRefs())
.thenReturn(buildList(node1))
.thenReturn(buildList(node2));
when(mockedResultSet.hasMore())
.thenReturn(true)
.thenReturn(false);
// when
executer.executeImpl();
// then
// ensure the query is executed and closed
verifyQuery();
verifyQueryTimes(2);
// ensure work is executed in transaction for each node processed
verify(mockedNodeService, times(2)).exists(any(NodeRef.class));
verify(mockedRetryingTransactionHelper, times(2)).<Object>doInTransaction(any(RetryingTransactionCallback.class));
verify(mockedRetryingTransactionHelper, times(2)).doInTransaction(any(RetryingTransactionCallback.class),
Matchers.anyBoolean(), Matchers.anyBoolean());
// ensure each node is process correctly
// node1
@@ -279,32 +302,26 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
final NodeRef node4 = generateNodeRef();
// mock the search service to return the right page
when(mockedSearchService.query(any(SearchParameters.class))).thenAnswer(
new Answer<ResultSet>()
when(mockedSearchService.query(any(SearchParameters.class))).thenAnswer((Answer<ResultSet>) invocation -> {
SearchParameters params = invocation.getArgumentAt(0, SearchParameters.class);
if (params.getSkipCount() == 0)
{
@Override
public ResultSet answer(InvocationOnMock invocation)
{
SearchParameters params = invocation.getArgumentAt(0, SearchParameters.class);
if (params.getSkipCount() == 0)
{
// mock first page
ResultSet result1 = mock(ResultSet.class);
when(result1.getNodeRefs()).thenReturn(Arrays.asList(node1, node2));
when(result1.hasMore()).thenReturn(true);
return result1;
}
else if (params.getSkipCount() == 2)
{
// mock second page
ResultSet result2 = mock(ResultSet.class);
when(result2.getNodeRefs()).thenReturn(Arrays.asList(node3, node4));
when(result2.hasMore()).thenReturn(false);
return result2;
}
throw new IndexOutOfBoundsException("Pagination did not stop after the second page!");
}
});
// mock first page
ResultSet result1 = mock(ResultSet.class);
when(result1.getNodeRefs()).thenReturn(Arrays.asList(node1, node2));
when(result1.hasMore()).thenReturn(true);
return result1;
}
else if (params.getSkipCount() == 2)
{
// mock second page
ResultSet result2 = mock(ResultSet.class);
when(result2.getNodeRefs()).thenReturn(Arrays.asList(node3, node4));
when(result2.hasMore()).thenReturn(false);
return result2;
}
throw new IndexOutOfBoundsException("Pagination did not stop after the second page!");
});
// call the service
executer.executeImpl();