Merged remote tracking branch RM REST API Automation

This commit is contained in:
Tuna Aksoy
2016-11-14 19:31:27 +00:00
14 changed files with 861 additions and 21 deletions

View File

@@ -13,6 +13,14 @@ package org.alfresco.rest.rm.base;
import static java.lang.Integer.parseInt;
import static org.alfresco.rest.rm.base.TestData.CATEGORY_TITLE;
import static org.alfresco.rest.rm.base.TestData.FOLDER_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.model.site.RMSiteCompliance.STANDARD;
import static org.alfresco.rest.rm.model.site.RMSiteFields.COMPLIANCE;
import static org.alfresco.rest.rm.model.site.RMSiteFields.DESCRIPTION;
@@ -26,6 +34,9 @@ import com.jayway.restassured.RestAssured;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.requests.FilePlanComponentAPI;
import org.alfresco.rest.rm.requests.RMSiteAPI;
import org.alfresco.utility.data.DataUser;
import org.springframework.beans.factory.annotation.Autowired;
@@ -58,12 +69,18 @@ public class BaseRestTest extends RestTest
@Value ("${rest.rmPath}")
private String restRmPath;
@Value ("${rest.basePath}")
private String restCorePath;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
@Autowired
public FilePlanComponentAPI filePlanComponentAPI;
// Constants
public static final String RM_ID = "rm";
public static final String RM_TITLE = "Records Management";
@@ -73,7 +90,7 @@ public class BaseRestTest extends RestTest
* @see org.alfresco.rest.RestTest#checkServerHealth()
*/
@Override
@BeforeClass(alwaysRun = true)
@BeforeClass (alwaysRun = true)
public void checkServerHealth() throws Exception
{
RestAssured.baseURI = scheme + "://" + server;
@@ -119,4 +136,57 @@ public class BaseRestTest extends RestTest
rmSiteAPI.getSite();
return restWrapper.getStatusCode().equals(OK.toString());
}
/**
* Helper method to create child category
*
* @param parentCategoryId The id of the parent category
* @param categoryName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
{
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE, CATEGORY_TITLE);
}
/**
* Helper method to create child folder
*
* @param parentCategoryId The id of the parent category
* @param folderName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createFolder(String parentCategoryId, String folderName) throws Exception
{
return createComponent(parentCategoryId, folderName, RECORD_FOLDER_TYPE, FOLDER_TITLE);
}
/**
* Helper method to create generic child component
*
* @param parentComponentId The id of the parent file plan component
* @param componentName The name of the file plan component
* @param componentType The name of the file plan component
* @param componentTitle
* @return The created file plan component
* @throws Exception
*/
private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType, String componentTitle) throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
JsonObject componentProperties = buildObject().add(NAME, componentName)
.add(NODE_TYPE, componentType.toString())
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, componentTitle)
.end()
.getJson();
FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(componentProperties, parentComponentId);
restWrapper.assertStatusCodeIs(CREATED);
return fpc;
}
}

View File

@@ -19,6 +19,7 @@ import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentTyp
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import org.testng.annotations.DataProvider;
@@ -77,4 +78,24 @@ public interface TestData
{ UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE },
};
}
/**
* The default CATEGORY name used when creating categories
*/
public static String CATEGORY_NAME = "CATEGORY NAME"+ getRandomAlphanumeric();
/**
* The default CATEGORY title used when creating categories
*/
public static String CATEGORY_TITLE = "CATEGORY TITLE" + getRandomAlphanumeric();
/**
* The default FOLDER name used when creating categories
*/
public static String FOLDER_NAME = "FOLDER NAME" + getRandomAlphanumeric();
/**
* The default FOLDER title used when creating categories
*/
public static String FOLDER_TITLE = "FOLDER TITLE" + getRandomAlphanumeric();
}

View File

@@ -27,6 +27,7 @@ import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.OK;
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;
@@ -254,15 +255,15 @@ public class FilePlanTests extends BaseRestTest
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the special containers into RM site - parent folder
filePlanComponentAPI.createFilePlanComponent(componentProperties, rmSiteId);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
// Create the special containers into RM site - parent folder
filePlanComponentAPI.createFilePlanComponent(componentProperties, FILE_PLAN_ALIAS.toString());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
// Create the special containers into the root of special containers containers
filePlanComponentAPI.createFilePlanComponent(componentProperties, filePlanAlias.toString());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**

View File

@@ -35,8 +35,8 @@ import java.util.NoSuchElementException;
import com.google.gson.JsonObject;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.base.BaseRestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType;
@@ -341,7 +341,7 @@ public class RecordCategoryTest extends BaseRestTest
* @return The created category
* @throws Exception on unsuccessful component creation
*/
private FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
{
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE);
}

View File

@@ -0,0 +1,368 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an
* agreement is prohibited.
* #L%
*/
package org.alfresco.rest.rm.fileplancomponents;
import static org.alfresco.rest.rm.base.TestData.CATEGORY_NAME;
import static org.alfresco.rest.rm.base.TestData.FOLDER_NAME;
import static org.alfresco.rest.rm.base.TestData.FOLDER_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_REVIEW_PERIOD;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
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.assertNotNull;
import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertTrue;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import com.google.gson.JsonObject;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.base.BaseRestTest;
import org.alfresco.rest.rm.base.TestData;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.requests.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
/**
* This class contains the tests for the
* the Record Folder CRUD API
*
* @author Rodica Sutu
* @since 1.0
*/
public class RecordFolderTests extends BaseRestTest
{
@Autowired
public FilePlanComponentAPI filePlanComponentAPI;
@Autowired
public DataUser dataUser;
private static final int NUMBER_OF_FOLDERS= 5;
/**
* Given that a record category exists
* When I use the API to create a new record folder
* Then it is created within the record category
*/
@Test
(
description = "Create a folder into a record category"
)
public void createFolderTest() throws Exception
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent filePlanComponent=createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
// Build the record category properties
JsonObject recordFolderProperties = buildObject()
.add(NAME, FOLDER_NAME)
.add(NODE_TYPE, RECORD_FOLDER_TYPE.toString())
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, FOLDER_TITLE)
.end()
.getJson();
// Create the record folder
FilePlanComponent folder = filePlanComponentAPI.createFilePlanComponent(recordFolderProperties, filePlanComponent.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
// Check folder has been created within the category created
assertEquals(filePlanComponent.getId(),folder.getParentId());
// Verify the returned properties for the file plan component - record folder
assertFalse(folder.isIsCategory());
assertFalse(folder.isIsFile());
assertTrue(folder.isIsRecordFolder());
assertEquals(folder.getName(), FOLDER_NAME);
assertEquals(folder.getNodeType(), RECORD_FOLDER_TYPE.toString());
assertEquals(folder.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Verify the returned file plan component properties
FilePlanComponentProperties folderProperties = folder.getProperties();
assertEquals(folderProperties.getTitle(), FOLDER_TITLE);
}
/**
* Given that RM site is created
* When I use the API to create a new record folder into transfers container/holds container/unfiled
* Then the operation fails
*/
@Test
(
description = "Create a folder into hold/transfers/unfiled/file plan container",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
@Bug(id="RM-4327")
public void createFolderIntoSpecialContainers(String filePlanComponent) throws Exception
{
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String componentID = filePlanComponentAPI.getFilePlanComponent(filePlanComponent).getId();
// Build the record category properties
JsonObject recordFolderProperties = buildObject()
.add(NAME, FOLDER_NAME)
.add(NODE_TYPE, RECORD_FOLDER_TYPE.toString())
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, FOLDER_TITLE)
.end()
.getJson();
// Create a record folder
filePlanComponentAPI.createFilePlanComponent(recordFolderProperties, componentID);
// Check the API Response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
* Given that a record folder exists
* When I ask for the details of a record folder
* Then I am given the details of a record folder
*/
@Test
(
description = "Check the details returned for a record folder"
)
public void checkTheRecordFolderProperties() throws Exception
{
String CATEGORY=CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponent folder =createFolder(category.getId(),FOLDER_NAME);
FilePlanComponent folderDetails=filePlanComponentAPI.withParams("include="+IS_CLOSED).getFilePlanComponent(folder.getId());
// Verify the returned properties for the file plan component - record folder
assertEquals(RECORD_FOLDER_TYPE.toString(),folderDetails.getNodeType());
assertTrue(folderDetails.isIsRecordFolder());
assertFalse(folderDetails.isIsCategory());
assertFalse(folderDetails.isIsFile());
assertFalse(folderDetails.isClosed());
assertEquals(FOLDER_NAME,folderDetails.getName());
assertEquals(dataUser.getAdminUser().getUsername(),folderDetails.getCreatedByUser().getId());
assertEquals(dataUser.getAdminUser().getUsername(), folderDetails.getModifiedByUser().getId());
assertEquals(FOLDER_TITLE,folderDetails.getProperties().getTitle());
}
/**
* Given that a record folder exists
* When I use the API to update its details
* Then the details of the record folder are updated
* The above test does treat any custom metadata
* Note: the details of the record folder includes any custom meta-data
*/
@Test
(
description = "Update the details returned for a record folder"
)
public void updateTheRecordFolderProperties() throws Exception
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
// Create record category first
String folderDescription = "The folder description is updated" + getRandomAlphanumeric();
String folderName= "The folder name is updated" + getRandomAlphanumeric();
String folderTitle = "Update title " + getRandomAlphanumeric();
String location="Location"+getRandomAlphanumeric();
String review_period="month|1";
// Build the file plan root properties
JsonObject folderProperties = buildObject()
.add(NAME, folderName)
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, folderTitle)
.add(PROPERTIES_DESCRIPTION, folderDescription)
.add(PROPERTIES_VITAL_RECORD_INDICATOR,true)
.add(PROPERTIES_REVIEW_PERIOD, review_period)
.add(PROPERTIES_LOCATION, location)
.end()
.getJson();
// Update the record category
FilePlanComponent folderUpdated = filePlanComponentAPI.updateFilePlanComponent(folderProperties, folder.getId());
// Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
// Verify the returned properties for the file plan component - record folder
assertEquals(folderName, folderUpdated.getName());
assertEquals(folderDescription, folderUpdated.getProperties().getDescription());
assertEquals(folderTitle, folderUpdated.getProperties().getTitle());
assertTrue(folderUpdated.getProperties().isVitalRecord());
assertEquals(location, folderUpdated.getProperties().getLocation());
assertNotNull(folderUpdated.getProperties().getReviewPeriod().getPeriodType());
assertNotNull(folderUpdated.getProperties().getReviewPeriod().getExpression());
}
/**
* Given that a record folder exists
* When I use the API to delete the record folder
* Then it deleted according to the normal rules governing the deletion of record folders
*/
@Test
(
description = "Delete record folder"
)
public void deleteRecordFolder() throws Exception
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
// Delete the Record folder
filePlanComponentAPI.deleteFilePlanComponent(folder.getId());
// Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NO_CONTENT);
// Check the File Plan Component is not found
filePlanComponentAPI.getFilePlanComponent(folder.getId());
// Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND);
}
/**
* Given that a record category exists
* And contains several record folders
* When I use the APi to get the file plan component children for the existing category
* Then I am provided with a list of the contained record folders
* And their details
*/
@Test
(
description = "List children of a category"
)
public void listFolders() throws Exception
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
// Add child olders
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
for (int i = 0; i < NUMBER_OF_FOLDERS; i++)
{
// Create a child
FilePlanComponent child = createFolder(category.getId(),
getRandomAlphanumeric());
assertNotNull(child.getId());
children.add(child);
}
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// List children from API
FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(category.getId());
// Check status code
restWrapper.assertStatusCodeIs(OK);
// Check listed children against created list
apiChildren.getEntries().forEach(c ->
{
FilePlanComponent filePlanComponent = c.getFilePlanComponent();
assertNotNull(filePlanComponent.getId());
logger.info("Checking child " + filePlanComponent.getId());
try
{
// Find this child in created children list
FilePlanComponent createdComponent = children.stream()
.filter(child -> child.getId().equals(filePlanComponent.getId()))
.findFirst()
.get();
// Created by
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Is parent Id set correctly
assertEquals(filePlanComponent.getParentId(), category.getId());
assertFalse(filePlanComponent.isIsFile());
// Boolean properties related to node type
assertTrue(filePlanComponent.isIsRecordFolder());
assertFalse(filePlanComponent.isIsCategory());
assertEquals(createdComponent.getName(), filePlanComponent.getName());
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
}
catch (NoSuchElementException e)
{
fail("No child element for " + filePlanComponent.getId());
}
}
);
}
@AfterClass (alwaysRun = true)
public void tearDown() throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
filePlanComponentAPI.listChildComponents(FILE_PLAN_ALIAS.toString()).getEntries().forEach(filePlanComponentEntry ->
{
try
{
filePlanComponentAPI.deleteFilePlanComponent(filePlanComponentEntry.getFilePlanComponent().getId());
}
catch (Exception e)
{
e.printStackTrace();
}
});
}
}

View File

@@ -34,8 +34,8 @@ import static org.testng.Assert.assertNotNull;
import com.google.gson.JsonObject;
import org.alfresco.dataprep.UserService;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.base.BaseRestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.model.site.RMSite;
import org.alfresco.rest.rm.requests.RMSiteAPI;
import org.alfresco.utility.constants.UserRole;