REPO-2266 / REPO-2275: Implement tests in TAS project for 'Trashcan' RestApi endpoint - part 1/2

- implement sanity tests for  GET /deleted-nodes, GET /deleted-nodes/{nodeId}, DELETE /deleted-nodes/{nodeId}, POST /deleted-nodes/{nodeId}/restore endpoints
- code formatting
This commit is contained in:
Andrei Forascu
2017-12-08 16:21:27 +02:00
parent b00811bd99
commit 19056c5c83
@@ -15,74 +15,142 @@
package org.alfresco.rest.trashcan;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestNodeModel;
import org.alfresco.rest.model.RestNodeModelsCollection;
import org.alfresco.utility.exception.DataPreparationException;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.TestGroup;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;
import org.springframework.http.HttpStatus;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Tests for /api-explorer/#!/trashcan/listDeletedNodes
* /api-explorer/#!/trashcan/deleteDeletedNode
* /api-explorer/#!/trashcan/getDeletedNode
* /api-explorer/#!/trashcan/restoreDeletedNode
*
* @author jcule
*
*/
public class GetDeletedNodesTests extends RestTest
public class GetDeletedNodesTests extends RestTest
{
private UserModel adminUserModel;
private SiteModel deleteNodesSiteModel;
private FolderModel deleteNodesFolder1, deleteNodesFolder2, deleteNodesFolder3;
@BeforeClass(alwaysRun=true)
private UserModel adminUserModel;
private SiteModel deleteNodesSiteModel;
private FolderModel deleteNodesFolder1, deleteNodesFolder2, deleteNodesFolder3, deleteNodesFolder4, deleteNodesFolder5;
private FileModel file, file1;
private RestNodeModelsCollection deletedNodes, deletedNodesMaxItem;
private RestNodeModel node;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUserModel = dataUser.getAdminUser();
restClient.authenticateUser(adminUserModel);
restClient.authenticateUser(adminUserModel);
deleteNodesSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
}
@AfterClass(alwaysRun=true)
@AfterClass(alwaysRun = true)
public void cleanup() throws Exception
{
dataSite.usingAdmin().deleteSite(deleteNodesSiteModel);
}
@Test(groups = { TestGroup.REST_API, TestGroup.REGRESSION })
public void testDeletedNodesBiggerThanMaxCount() throws Exception
{
//get the number of item in the trashcan
RestNodeModelsCollection deletedNodes = restClient.withCoreAPI().usingTrashcan().findDeletedNodes();
int count = deletedNodes.getPagination().getCount();
int totalItems = deletedNodes.getPagination().getTotalItems();
//create folders
deleteNodesFolder1 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder();
deleteNodesFolder2 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder();
deleteNodesFolder3 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder();
//delete folders
// get the number of item in the trashcan
deletedNodes = restClient.withCoreAPI().usingTrashcan().findDeletedNodes();
int count = deletedNodes.getPagination().getCount();
int totalItems = deletedNodes.getPagination().getTotalItems();
// create folders
deleteNodesFolder1 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder();
deleteNodesFolder2 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder();
deleteNodesFolder3 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder();
// delete folders
dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder1).deleteContent();
dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder2).deleteContent();
dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder3).deleteContent();
int maxItems = count + 1;
RestNodeModelsCollection deletedNodesMaxItem = restClient.withCoreAPI().usingTrashcan().usingParams(String.format("maxItems=%s", maxItems)).findDeletedNodes();
String countMaxItem = Integer.toString(maxItems);
String totalItemsMaxItem = Integer.toString(totalItems + 3);
String hasMoreItemsMaxItem = Boolean.toString(deletedNodesMaxItem.getPagination().isHasMoreItems());
String skipCount = Integer.toString(deletedNodesMaxItem.getPagination().getSkipCount());
deletedNodesMaxItem = restClient.withCoreAPI().usingTrashcan().usingParams(String.format("maxItems=%s", maxItems)).findDeletedNodes();
String countMaxItem = Integer.toString(maxItems);
String totalItemsMaxItem = Integer.toString(totalItems + 3);
String hasMoreItemsMaxItem = Boolean.toString(deletedNodesMaxItem.getPagination().isHasMoreItems());
String skipCount = Integer.toString(deletedNodesMaxItem.getPagination().getSkipCount());
restClient.assertStatusCodeIs(HttpStatus.OK);
deletedNodesMaxItem.getPagination().assertThat().field("totalItems").is(totalItemsMaxItem).and().field("count").is(countMaxItem);
deletedNodesMaxItem.getPagination().assertThat().field("hasMoreItems").is(hasMoreItemsMaxItem).and().field("skipCount").is(skipCount);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TRASHCAN }, executionType = ExecutionType.SANITY, description = "Sanity tests for GET /deleted-nodes and GET /deleted-nodes/{nodeId}")
@Test(groups = { TestGroup.REST_API, TestGroup.TRASHCAN, TestGroup.SANITY })
public void testGetDeletedNodesFromTrashcan() throws Exception
{
// Create a folder and a file
deleteNodesFolder4 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder();
file = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createContent(DocumentType.TEXT_PLAIN);
// Delete file and folder
dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder4).deleteContent();
dataContent.usingUser(adminUserModel).usingResource(file).deleteContent();
// GET /deleted-nodes: deleted file and folder are in the trashcan list
deletedNodes = restClient.withCoreAPI().usingTrashcan().findDeletedNodes();
restClient.assertStatusCodeIs(HttpStatus.OK);
deletedNodes.getEntryByIndex(0).assertThat().field("name").is(file.getName()).and()
.field("id").is(file.getNodeRefWithoutVersion());
deletedNodes.getEntryByIndex(1).assertThat().field("name").is(deleteNodesFolder4.getName()).and()
.field("id").is(deleteNodesFolder4.getNodeRefWithoutVersion());
// GET /deleted-nodes/{nodeId}: check a single deleted object
node = restClient.withCoreAPI().usingTrashcan().findDeletedNode(deleteNodesFolder4);
restClient.assertStatusCodeIs(HttpStatus.OK);
node.assertThat().field("name").is(deleteNodesFolder4.getName()).and()
.field("id").is(deleteNodesFolder4.getNodeRefWithoutVersion());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TRASHCAN }, executionType = ExecutionType.SANITY, description = "Sanity tests for DELETE /deleted-nodes/{nodeId} and POST /deleted-nodes/{nodeId}/restore")
@Test(groups = { TestGroup.REST_API, TestGroup.TRASHCAN, TestGroup.SANITY })
public void testDeleteAndRestoreNodeFromTrashcan() throws Exception
{
// Create a folder and a file
deleteNodesFolder5 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder();
String docLibNodeRef = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).getNodeRef();
file1 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createContent(DocumentType.TEXT_PLAIN);
// Delete file and folder
dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder5).deleteContent();
dataContent.usingUser(adminUserModel).usingResource(file1).deleteContent();
// DELETE /deleted-nodes/{nodeId}: delete an object from trashcan
restClient.withCoreAPI().usingTrashcan().deleteNodeFromTrashcan(file1);
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingTrashcan().findDeletedNode(file1);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
// POST /deleted-nodes/{nodeId}/restore: restore to repository a deleted object
node = restClient.withCoreAPI().usingTrashcan().restoreNodeFromTrashcan(deleteNodesFolder5);
restClient.assertStatusCodeIs(HttpStatus.OK);
node.assertThat().field("id").is(deleteNodesFolder5.getNodeRefWithoutVersion()).and()
.field("parentId").is(docLibNodeRef);
// Checks that the node was removed from trashcan
restClient.withCoreAPI().usingTrashcan().findDeletedNode(deleteNodesFolder5);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
}