mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merge branch 'feature/RM-4405_Electronic_Records_API_Tests' into 'master'
Feature/rm 4405 electronic records api tests API automation tests for RM-4359. See merge request !689
This commit is contained in:
@@ -33,6 +33,11 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.jayway.restassured</groupId>
|
||||||
|
<artifactId>rest-assured</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.alfresco.tas</groupId>
|
<groupId>org.alfresco.tas</groupId>
|
||||||
<artifactId>restapi-test</artifactId>
|
<artifactId>restapi-test</artifactId>
|
||||||
|
@@ -26,6 +26,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.rm.community.requests;
|
package org.alfresco.rest.rm.community.requests;
|
||||||
|
|
||||||
|
import static com.jayway.restassured.RestAssured.given;
|
||||||
|
|
||||||
import static org.alfresco.rest.core.RestRequest.requestWithBody;
|
import static org.alfresco.rest.core.RestRequest.requestWithBody;
|
||||||
import static org.alfresco.rest.core.RestRequest.simpleRequest;
|
import static org.alfresco.rest.core.RestRequest.simpleRequest;
|
||||||
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject;
|
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject;
|
||||||
@@ -35,10 +37,19 @@ import static org.springframework.http.HttpMethod.DELETE;
|
|||||||
import static org.springframework.http.HttpMethod.GET;
|
import static org.springframework.http.HttpMethod.GET;
|
||||||
import static org.springframework.http.HttpMethod.POST;
|
import static org.springframework.http.HttpMethod.POST;
|
||||||
import static org.springframework.http.HttpMethod.PUT;
|
import static org.springframework.http.HttpMethod.PUT;
|
||||||
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import com.google.common.io.Resources;
|
||||||
|
import com.jayway.restassured.http.ContentType;
|
||||||
|
import com.jayway.restassured.response.Response;
|
||||||
|
|
||||||
import org.alfresco.rest.core.RestAPI;
|
import org.alfresco.rest.core.RestAPI;
|
||||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||||
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
|
||||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
|
||||||
|
import org.alfresco.utility.model.UserModel;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -119,14 +130,62 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
|
|||||||
{
|
{
|
||||||
mandatoryObject("filePlanComponentProperties", filePlanComponentModel);
|
mandatoryObject("filePlanComponentProperties", filePlanComponentModel);
|
||||||
mandatoryString("parentId", parentId);
|
mandatoryString("parentId", parentId);
|
||||||
|
|
||||||
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
|
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
|
||||||
POST,
|
POST,
|
||||||
toJson(filePlanComponentModel),
|
toJson(filePlanComponentModel),
|
||||||
"fileplan-components/{fileplanComponentId}/children?{parameters}",
|
"fileplan-components/{fileplanComponentId}/children?{parameters}",
|
||||||
parentId,
|
parentId,
|
||||||
getParameters()
|
getParameters()));
|
||||||
));
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create electronic record from file resource
|
||||||
|
* @param electronicRecordModel {@link FilePlanComponent} for electronic record to be created
|
||||||
|
* @param fileName the name of the resource file
|
||||||
|
* @param parentId parent container id
|
||||||
|
* @return newly created {@link FilePlanComponent}
|
||||||
|
* @throws Exception if operation failed
|
||||||
|
*/
|
||||||
|
public FilePlanComponent createElectronicRecord(FilePlanComponent electronicRecordModel, String fileName, String parentId) throws Exception
|
||||||
|
{
|
||||||
|
return createElectronicRecord(electronicRecordModel, new File(Resources.getResource(fileName).getFile()), parentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create electronic record from file resource
|
||||||
|
* @param electronicRecordModel {@link FilePlanComponent} for electronic record to be created
|
||||||
|
* @param recordContent {@link File} pointing to the content of the electronic record to be created
|
||||||
|
* @param parentId parent container id
|
||||||
|
* @return newly created {@link FilePlanComponent}
|
||||||
|
* @throws Exception if operation failed
|
||||||
|
*/
|
||||||
|
public FilePlanComponent createElectronicRecord(FilePlanComponent electronicRecordModel, File recordContent, String parentId) throws Exception
|
||||||
|
{
|
||||||
|
mandatoryObject("filePlanComponentProperties", electronicRecordModel);
|
||||||
|
mandatoryString("parentId", parentId);
|
||||||
|
if (!electronicRecordModel.getNodeType().equals(FilePlanComponentType.CONTENT_TYPE.toString()))
|
||||||
|
{
|
||||||
|
fail("Only electronic records are supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RestWrapper adds some headers which break multipart/form-data uploads and also assumes json POST requests.
|
||||||
|
* Upload the file using RestAssured library.
|
||||||
|
*/
|
||||||
|
UserModel currentUser = usingRestWrapper().getTestUser();
|
||||||
|
Response response = given()
|
||||||
|
.auth().basic(currentUser.getUsername(), currentUser.getPassword())
|
||||||
|
.multiPart("nodeBodyCreate", toJson(electronicRecordModel), ContentType.JSON.name())
|
||||||
|
.multiPart("filedata", recordContent, ContentType.BINARY.name())
|
||||||
|
.when()
|
||||||
|
.post("fileplan-components/{fileplanComponentId}/children?{parameters}", parentId, getParameters())
|
||||||
|
.andReturn();
|
||||||
|
usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
|
||||||
|
LOG.info("electronic record created: " + response.getBody().prettyPrint());
|
||||||
|
|
||||||
|
/* return a FilePlanComponent object representing Response */
|
||||||
|
return response.jsonPath().getObject("entry", FilePlanComponent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -30,10 +30,13 @@ import static java.lang.Integer.parseInt;
|
|||||||
|
|
||||||
import static org.alfresco.rest.rm.community.base.TestData.CATEGORY_TITLE;
|
import static org.alfresco.rest.rm.community.base.TestData.CATEGORY_TITLE;
|
||||||
import static org.alfresco.rest.rm.community.base.TestData.FOLDER_TITLE;
|
import static org.alfresco.rest.rm.community.base.TestData.FOLDER_TITLE;
|
||||||
|
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.RECORD_CATEGORY_TYPE;
|
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;
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||||
import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.STANDARD;
|
import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.STANDARD;
|
||||||
|
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||||
import static org.springframework.http.HttpStatus.CREATED;
|
import static org.springframework.http.HttpStatus.CREATED;
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
@@ -48,11 +51,13 @@ import org.alfresco.rest.rm.community.model.site.RMSite;
|
|||||||
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
|
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
|
||||||
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
|
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
|
||||||
import org.alfresco.utility.data.DataUser;
|
import org.alfresco.utility.data.DataUser;
|
||||||
|
import org.alfresco.utility.model.UserModel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.DataProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all IG REST API Tests
|
* Base class for all IG REST API Tests
|
||||||
@@ -96,6 +101,19 @@ public class BaseRestTest extends RestTest
|
|||||||
public static final String RM_TITLE = "Records Management";
|
public static final String RM_TITLE = "Records Management";
|
||||||
public static final String RM_DESCRIPTION = "Records Management Site";
|
public static final String RM_DESCRIPTION = "Records Management Site";
|
||||||
|
|
||||||
|
/** Valid root containers where electronic and non-electronic records can be created */
|
||||||
|
@DataProvider(name = "validRootContainers")
|
||||||
|
public Object[][] getValidRootContainers() throws Exception {
|
||||||
|
return new Object[][] {
|
||||||
|
// an arbitrary record folder
|
||||||
|
{ createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()) },
|
||||||
|
// unfiled records root
|
||||||
|
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), UNFILED_RECORDS_CONTAINER_ALIAS.toString()) },
|
||||||
|
// an arbitrary unfiled records folder
|
||||||
|
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()) }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.rest.RestTest#checkServerHealth()
|
* @see org.alfresco.rest.RestTest#checkServerHealth()
|
||||||
*/
|
*/
|
||||||
@@ -212,4 +230,34 @@ public class BaseRestTest extends RestTest
|
|||||||
return updatedComponent;
|
return updatedComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to create a randomly-named <category>/<folder> structure in fileplan
|
||||||
|
* @param user user under whose privileges this structure is going to be created
|
||||||
|
* @param parentId parent container id
|
||||||
|
* @return record folder
|
||||||
|
* @throws Exception on failed creation
|
||||||
|
*/
|
||||||
|
public FilePlanComponent createCategoryFolderInFilePlan(UserModel user, String parentId) throws Exception
|
||||||
|
{
|
||||||
|
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
|
||||||
|
|
||||||
|
// create root category
|
||||||
|
FilePlanComponent recordCategory = createCategory(parentId, "Category " + getRandomAlphanumeric());
|
||||||
|
|
||||||
|
// and return a folder underneath
|
||||||
|
return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to retieve a fileplan component with user's privilege
|
||||||
|
* @param user user under whose privileges a component is to be read
|
||||||
|
* @param componentId id of the component to read
|
||||||
|
* @return {@link FilePlanComponent} for given componentId
|
||||||
|
* @throws Exception if user doesn't have sufficient privileges
|
||||||
|
*/
|
||||||
|
public FilePlanComponent getFilePlanComponentAsUser(UserModel user, String componentId) throws Exception
|
||||||
|
{
|
||||||
|
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
|
||||||
|
return filePlanComponentAPI.getFilePlanComponent(componentId);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -50,7 +50,7 @@ import org.testng.annotations.DataProvider;
|
|||||||
* @since 2.6
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
public interface TestData
|
public interface TestData
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A user with ALFRESCO_ADMINISTRATORS role.
|
* A user with ALFRESCO_ADMINISTRATORS role.
|
||||||
* <p>"GROUP_ANOTHER_ADMIN_EXISTS" The ANOTHER_ADMIN user has been created.
|
* <p>"GROUP_ANOTHER_ADMIN_EXISTS" The ANOTHER_ADMIN user has been created.
|
||||||
@@ -141,5 +141,4 @@ public interface TestData
|
|||||||
{ CONTENT_TYPE.toString()}
|
{ CONTENT_TYPE.toString()}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,232 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Records Management Module
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||||
|
|
||||||
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||||
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
|
||||||
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
|
||||||
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
|
||||||
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||||
|
import static org.alfresco.rest.rm.community.util.PojoUtility.toJson;
|
||||||
|
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.assertFalse;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.alfresco.rest.rm.community.base.BaseRestTest;
|
||||||
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||||
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||||
|
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
|
||||||
|
import org.alfresco.utility.data.DataUser;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.testng.annotations.DataProvider;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create/File electronic records tests
|
||||||
|
* <br>
|
||||||
|
* These tests only test the creation and filing of electronic records, update at
|
||||||
|
* present isn't implemented in the API under test.
|
||||||
|
* <p>
|
||||||
|
* @author Kristijan Conkas
|
||||||
|
* @since 2.6
|
||||||
|
*/
|
||||||
|
public class ElectronicRecordTests extends BaseRestTest
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private FilePlanComponentAPI filePlanComponentAPI;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataUser dataUser;
|
||||||
|
|
||||||
|
/** image resource file to be used for records body */
|
||||||
|
private static final String IMAGE_FILE = "money.JPG";
|
||||||
|
|
||||||
|
/** Valid root containers where electronic records can be created */
|
||||||
|
@DataProvider(name = "invalidParentContainers")
|
||||||
|
public Object[][] invalidContainers() throws Exception {
|
||||||
|
return new Object[][] {
|
||||||
|
// record category
|
||||||
|
{ getFilePlanComponentAsUser(dataUser.getAdminUser(),
|
||||||
|
createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()).getParentId()) },
|
||||||
|
// file plan root
|
||||||
|
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()) },
|
||||||
|
// transfers
|
||||||
|
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), TRANSFERS_ALIAS.toString()) },
|
||||||
|
// holds
|
||||||
|
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), HOLDS_ALIAS.toString()) },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Given a parent container that is NOT a record folder or an unfiled record folder
|
||||||
|
* When I try to create an electronic record within the parent container
|
||||||
|
* Then nothing happens
|
||||||
|
* And an error is reported
|
||||||
|
* </pre>
|
||||||
|
* @param container
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
(
|
||||||
|
dataProvider = "invalidParentContainers",
|
||||||
|
description = "Electronic records can't be created in invalid parent containers"
|
||||||
|
)
|
||||||
|
public void cantCreateElectronicRecordsInInvalidContainers(FilePlanComponent container) throws Exception
|
||||||
|
{
|
||||||
|
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
||||||
|
|
||||||
|
FilePlanComponent record = new FilePlanComponent("Record " + getRandomAlphanumeric(), CONTENT_TYPE.toString(),
|
||||||
|
new FilePlanComponentProperties());
|
||||||
|
filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId());
|
||||||
|
|
||||||
|
// verify the create request status code
|
||||||
|
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Given a parent container that is a record folder
|
||||||
|
* And the record folder is closed
|
||||||
|
* When I try to create an electronic record within the parent container
|
||||||
|
* Then nothing happens
|
||||||
|
* And an error is reported
|
||||||
|
* </pre>
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Test(description = "Electronic record can't be created in closed record folder")
|
||||||
|
public void cantCreateElectronicRecordInClosedFolder() throws Exception
|
||||||
|
{
|
||||||
|
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
||||||
|
FilePlanComponent recordFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString());
|
||||||
|
|
||||||
|
// the folder should be open
|
||||||
|
assertFalse(recordFolder.getProperties().getIsClosed());
|
||||||
|
|
||||||
|
// close the folder
|
||||||
|
closeFolder(recordFolder.getId());
|
||||||
|
|
||||||
|
// try to create it, this should fail
|
||||||
|
FilePlanComponent record = new FilePlanComponent("Record " + getRandomAlphanumeric(), CONTENT_TYPE.toString(),
|
||||||
|
new FilePlanComponentProperties());
|
||||||
|
filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, recordFolder.getId());
|
||||||
|
|
||||||
|
// verify the status code
|
||||||
|
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Given a parent container that is a record folder
|
||||||
|
* And the record folder is open
|
||||||
|
* When I try to create an electronic record within the parent container
|
||||||
|
* And I do not provide all the required mandatory property values
|
||||||
|
* Then nothing happens
|
||||||
|
* And an error is reported
|
||||||
|
* </pre>
|
||||||
|
* and
|
||||||
|
* <pre>
|
||||||
|
* Given a parent container that is an unfiled record folder or the root unfiled record container
|
||||||
|
* When I try to create an electronic record within the parent container
|
||||||
|
* And I do not provide all the required mandatory property values
|
||||||
|
* Then nothing happens
|
||||||
|
* And an error is reported
|
||||||
|
* </pre>
|
||||||
|
* @param container
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
(
|
||||||
|
dataProvider = "validRootContainers",
|
||||||
|
description = "Electronic record can only be created if all mandatory properties are given"
|
||||||
|
)
|
||||||
|
public void canCreateElectronicRecordOnlyWithMandatoryProperties(FilePlanComponent container) throws Exception
|
||||||
|
{
|
||||||
|
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
||||||
|
|
||||||
|
logger.info("Root container:\n" + toJson(container));
|
||||||
|
if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString()))
|
||||||
|
{
|
||||||
|
// only record folders can be open or closed
|
||||||
|
assertFalse(container.getProperties().getIsClosed());
|
||||||
|
}
|
||||||
|
|
||||||
|
// component without name
|
||||||
|
FilePlanComponent record = new FilePlanComponent();
|
||||||
|
record.setNodeType(CONTENT_TYPE.toString());
|
||||||
|
record.setProperties(new FilePlanComponentProperties());
|
||||||
|
|
||||||
|
// try to create it
|
||||||
|
filePlanComponentAPI.createFilePlanComponent(record, container.getId());
|
||||||
|
|
||||||
|
// verify the status code is BAD_REQUEST
|
||||||
|
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Given a parent container that is a record folder
|
||||||
|
* And the record folder is open
|
||||||
|
* When I try to create an electronic record within the parent container
|
||||||
|
* Then the electronic record is created
|
||||||
|
* And the details of the new record are returned
|
||||||
|
* </pre>
|
||||||
|
* and
|
||||||
|
* <pre>
|
||||||
|
* Given a parent container that is an unfiled record folder or the root unfiled record container
|
||||||
|
* When I try to create an electronic record within the parent container
|
||||||
|
* Then the electronic record is created
|
||||||
|
* And the details of the new record are returned
|
||||||
|
* </pre>
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
(
|
||||||
|
dataProvider = "validRootContainers",
|
||||||
|
description = "Electronic records can be created in unfiled record folder or unfiled record root"
|
||||||
|
)
|
||||||
|
public void canCreateElectronicRecordsInValidContainers(FilePlanComponent container) throws Exception
|
||||||
|
{
|
||||||
|
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
||||||
|
|
||||||
|
FilePlanComponent record = new FilePlanComponent("Record " + getRandomAlphanumeric(), CONTENT_TYPE.toString(),
|
||||||
|
new FilePlanComponentProperties());
|
||||||
|
String newRecordId = filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
|
||||||
|
|
||||||
|
// verify the create request status code
|
||||||
|
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
|
||||||
|
|
||||||
|
// get newly created electonic record and verify its properties
|
||||||
|
FilePlanComponent electronicRecord = filePlanComponentAPI.getFilePlanComponent(newRecordId);
|
||||||
|
// record will have record identifier inserted in its name but will for sure start with file name
|
||||||
|
// and end with its extension
|
||||||
|
assertTrue(electronicRecord.getName().startsWith(IMAGE_FILE.substring(0, IMAGE_FILE.indexOf("."))));
|
||||||
|
}
|
||||||
|
}
|
@@ -31,7 +31,6 @@ import static java.util.Arrays.asList;
|
|||||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
|
||||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_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.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
|
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_CATEGORY_TYPE;
|
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;
|
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||||
@@ -56,7 +55,6 @@ import org.alfresco.utility.data.DataUser;
|
|||||||
import org.alfresco.utility.model.SiteModel;
|
import org.alfresco.utility.model.SiteModel;
|
||||||
import org.alfresco.utility.model.UserModel;
|
import org.alfresco.utility.model.UserModel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.testng.annotations.DataProvider;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,20 +73,7 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RMSiteAPI rmSiteAPI;
|
private RMSiteAPI rmSiteAPI;
|
||||||
|
|
||||||
/** Valid root containers where non-electronic records can be created */
|
|
||||||
@DataProvider(name = "validContainers")
|
|
||||||
public Object[][] rootContainers() throws Exception {
|
|
||||||
return new Object[][] {
|
|
||||||
// an arbitrary record folder
|
|
||||||
{ createFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()) },
|
|
||||||
// unfiled records root
|
|
||||||
{ filePlanComponentAPI.getFilePlanComponent(UNFILED_RECORDS_CONTAINER_ALIAS.toString()) },
|
|
||||||
// an arbitrary unfiled records folder
|
|
||||||
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()) }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* Given a parent container that is NOT a record folder or an unfiled record folder
|
* Given a parent container that is NOT a record folder or an unfiled record folder
|
||||||
@@ -153,7 +138,7 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
(
|
(
|
||||||
dataProvider = "validContainers",
|
dataProvider = "validRootContainers",
|
||||||
description = "Non-electronic records can be created in valid containers"
|
description = "Non-electronic records can be created in valid containers"
|
||||||
)
|
)
|
||||||
public void canCreateInValidContainers(FilePlanComponent container) throws Exception
|
public void canCreateInValidContainers(FilePlanComponent container) throws Exception
|
||||||
@@ -225,7 +210,7 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
public void cantCreateInClosedFolder() throws Exception
|
public void cantCreateInClosedFolder() throws Exception
|
||||||
{
|
{
|
||||||
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
||||||
FilePlanComponent recordFolder = createFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString());
|
FilePlanComponent recordFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString());
|
||||||
|
|
||||||
// the folder should be open
|
// the folder should be open
|
||||||
assertFalse(recordFolder.getProperties().getIsClosed());
|
assertFalse(recordFolder.getProperties().getIsClosed());
|
||||||
@@ -266,7 +251,7 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
(
|
(
|
||||||
dataProvider = "validContainers",
|
dataProvider = "validRootContainers",
|
||||||
description = "Non-electronic record can only be created if all mandatory properties are given"
|
description = "Non-electronic record can only be created if all mandatory properties are given"
|
||||||
)
|
)
|
||||||
public void allMandatoryPropertiesRequired(FilePlanComponent container) throws Exception
|
public void allMandatoryPropertiesRequired(FilePlanComponent container) throws Exception
|
||||||
@@ -325,7 +310,7 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
(
|
(
|
||||||
dataProvider = "validContainers",
|
dataProvider = "validRootContainers",
|
||||||
description = "Non-electronic record can't be created if user doesn't have RM privileges"
|
description = "Non-electronic record can't be created if user doesn't have RM privileges"
|
||||||
)
|
)
|
||||||
public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception
|
public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception
|
||||||
@@ -363,22 +348,6 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to create a randomly-named <category>/<folder> structure in fileplan
|
|
||||||
* @return record folder
|
|
||||||
* @throws Exception on failed creation
|
|
||||||
*/
|
|
||||||
private FilePlanComponent createFolderInFilePlan(UserModel user, String parentId) throws Exception
|
|
||||||
{
|
|
||||||
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
|
|
||||||
|
|
||||||
// create root category
|
|
||||||
FilePlanComponent recordCategory = createCategory(parentId, "Category " + getRandomAlphanumeric());
|
|
||||||
|
|
||||||
// and return a folder underneath
|
|
||||||
return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create user with given role and add it to RM site
|
* Create user with given role and add it to RM site
|
||||||
* <br>
|
* <br>
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 528 KiB |
Reference in New Issue
Block a user