Merge changes from 2.6.1 release to 3.0

This commit is contained in:
cagache
2018-08-31 17:27:59 +03:00
9 changed files with 186 additions and 48 deletions

View File

@@ -217,9 +217,9 @@ public class BaseRMRestTest extends RestTest
* @param userModel The user under whose privileges this structure is going to be created
* @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(UserModel userModel, String categoryName) throws Exception
public RecordCategory createRootCategory(UserModel userModel, String categoryName)
{
return createRootCategory(userModel, categoryName, RECORD_CATEGORY_TITLE);
}
@@ -244,9 +244,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(UserModel userModel, String categoryName, String categoryTitle) throws Exception
public RecordCategory createRootCategory(UserModel userModel, String categoryName, String categoryTitle)
{
RecordCategory recordCategoryModel = createRecordCategoryModel(categoryName, categoryTitle);
return getRestAPIFactory().getFilePlansAPI(userModel).createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS);
@@ -315,9 +315,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(UserModel user, String recordCategoryId, String name) throws Exception
public RecordCategoryChild createFolder(UserModel user, String recordCategoryId, String name)
{
RecordCategoryChild recordFolderModel = createRecordCategoryChildModel(name, RECORD_FOLDER_TYPE);
return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordFolderModel, recordCategoryId);
@@ -455,13 +455,13 @@ public class BaseRMRestTest extends RestTest
}
/**
* Helper method to create a randomly-named <category>/<folder> structure in file plan
* Helper method to create a randomly-named [category]/[folder] structure in file plan
*
* @param user The user under whose privileges this structure is going to be created
* @return {@link RecordCategoryChild} which represents the record folder
* @throws Exception on failed creation
* @throws RuntimeException on failed creation
*/
public RecordCategoryChild createCategoryFolderInFilePlan(UserModel user) throws Exception
public RecordCategoryChild createCategoryFolderInFilePlan(UserModel user)
{
// create root category
RecordCategory recordCategory = createRootCategory(user, "Category " + getRandomAlphanumeric());
@@ -471,12 +471,12 @@ public class BaseRMRestTest extends RestTest
}
/**
* Helper method to create a randomly-named <category>/<folder> structure in file plan as the admin user
* Helper method to create a randomly-named [category]/[folder] structure in file plan as the admin user
*
* @return {@link RecordCategoryChild} which represents the record folder
* @throws Exception on failed creation
* @throws RuntimeException on failed creation
*/
public RecordCategoryChild createCategoryFolderInFilePlan() throws Exception
public RecordCategoryChild createCategoryFolderInFilePlan()
{
return createCategoryFolderInFilePlan(getAdminUser());
}

View File

@@ -46,6 +46,10 @@ import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
import org.alfresco.rest.core.RestResponse;
import org.alfresco.rest.model.RestNodeBodyMoveCopyModel;
import org.alfresco.rest.model.RestNodeModel;
import org.alfresco.rest.requests.Node;
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.RecordCategoryChild;
@@ -55,8 +59,10 @@ 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.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.RepoTestModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.log.Step;
import org.testng.annotations.Test;
/**
@@ -245,6 +251,40 @@ public class DeleteRecordTests extends BaseRMRestTest
assertStatusCode(FORBIDDEN);
}
/**
* <pre>
* Given a record
* And a copy of that record
* When I delete the copy
* Then it is still possible to view the content of the original record
* </pre>
*/
@Test(description = "Deleting copy of record doesn't delete original content")
@AlfrescoTest(jira="MNT-18806")
public void deleteCopyOfRecord()
{
Step.STEP("Create two record categories and folders.");
RecordCategoryChild recordFolderA = createCategoryFolderInFilePlan();
RecordCategoryChild recordFolderB = createCategoryFolderInFilePlan();
Step.STEP("Create a record in folder A and copy it into folder B.");
String recordId = getRestAPIFactory().getRecordFolderAPI()
.createRecord(createElectronicRecordModel(), recordFolderA.getId(), getFile(IMAGE_FILE)).getId();
String copyId = copyRecord(recordId, recordFolderB.getId()).getId();
assertStatusCode(CREATED);
Step.STEP("Check that it's possible to load the original content.");
getNodeContent(recordId);
assertStatusCode(OK);
Step.STEP("Delete the copy.");
deleteAndVerify(copyId);
Step.STEP("Check that the original record node and content still exist.");
checkNodeExists(recordId);
getNodeContent(recordId);
}
/**
* Utility method to delete a record and verify successful deletion
*
@@ -263,4 +303,73 @@ public class DeleteRecordTests extends BaseRMRestTest
assertStatusCode(NOT_FOUND);
}
/**
* Copy a record to a record folder.
*
* @param recordId The id of the record to copy.
* @param destinationFolder The id of the record folder to copy it to.
* @return The model returned by the copy API.
*/
private RestNodeModel copyRecord(String recordId, String destinationFolder)
{
Node node = getNode(recordId);
RestNodeBodyMoveCopyModel copyBody = new RestNodeBodyMoveCopyModel();
copyBody.setTargetParentId(destinationFolder);
try
{
return node.copy(copyBody);
}
catch (Exception e)
{
throw new RuntimeException("Problem copying record.", e);
}
}
/**
* Get the content from a node.
*
* @param nodeId
* @return The response containing the node content.
*/
private RestResponse getNodeContent(String nodeId)
{
try
{
return getNode(nodeId).getNodeContent();
}
catch (Exception e)
{
throw new RuntimeException("Failed to load content for node.", e);
}
}
/**
* Check that the given node exists.
*
* @param nodeId The node to check.
*/
private void checkNodeExists(String nodeId)
{
try
{
getNode(nodeId).getNode();
}
catch (Exception e)
{
throw new RuntimeException("Node does not exist.", e);
}
}
/**
* Get the node from a record id.
*
* @param recordId The record to get.
* @return The node object.
*/
private Node getNode(String recordId)
{
RepoTestModel repoTestModel = new RepoTestModel() {};
repoTestModel.setNodeRef(recordId);
return getRestAPIFactory().getNodeAPI(repoTestModel);
}
}