File Plan CRUD API tests

This commit is contained in:
Rodica Sutu
2016-10-31 08:33:41 +02:00
parent 7d39b799d8
commit d146c4454b
7 changed files with 359 additions and 4 deletions

View File

@@ -26,4 +26,6 @@ public class FilePlanComponentFields
public static final String PROPERTIES_TITLE = "cm:title";
public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator";
public static final String PROPERTIES_HOLD_REASON = "rma:holdReason";
public static final String PROPERTIES_DESCRIPTION = "cm:description";
public static final String ALLOWABLE_OPERATIONS = "allowableOperations";
}

View File

@@ -23,7 +23,10 @@ public enum FilePlanComponentType
RECORD_CATEGORY_TYPE("rma:recordCategory"),
RECORD_FOLDER_TYPE("rma:recordFolder"),
HOLD_TYPE("rma:hold"),
UNFILED_RECORD_FOLDER_TYPE("rma:unfiledRecordFolder");
UNFILED_RECORD_FOLDER_TYPE("rma:unfiledRecordFolder"),
HOLD_CONTAINER_TYPE("rma:holdContainer"),
TRANSFER_CONTAINER_TYPE("rma:transferContainer"),
UNFILED_CONTAINER_TYPE("rma:unfiledRecordContainer");
private String type;
@@ -46,6 +49,12 @@ public enum FilePlanComponentType
return HOLD_TYPE;
case "rma:unfiledRecordFolder":
return UNFILED_RECORD_FOLDER_TYPE;
case "rma:holdContainer":
return HOLD_CONTAINER_TYPE;
case "rma:transferContainer":
return TRANSFER_CONTAINER_TYPE;
case "rma:unfiledRecordContainer":
return UNFILED_CONTAINER_TYPE;
}
throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'.");

View File

@@ -11,6 +11,7 @@
*/
package org.alfresco.rest.model.fileplancomponents;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import java.util.List;
@@ -51,6 +52,8 @@ public class FilePlanComponent
private FilePlanComponentCreatedByUser createdByUser;
@JsonProperty (ALLOWABLE_OPERATIONS)
private List<String> allowableOperations;
/**
* @return the id
*/
@@ -226,4 +229,12 @@ public class FilePlanComponent
{
this.createdByUser = createdByUser;
}
/**
* @return the allowableOperations
*/
public List<String> getAllowableOperations()
{
return this.allowableOperations;
}
}

View File

@@ -11,6 +11,7 @@
*/
package org.alfresco.rest.model.fileplancomponents;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
@@ -37,6 +38,8 @@ public class FilePlanComponentProperties
@JsonProperty(PROPERTIES_HOLD_REASON)
private String holdReason;
@JsonProperty (PROPERTIES_DESCRIPTION)
private String description;
/**
* @return the vitalRecord
*/
@@ -84,4 +87,21 @@ public class FilePlanComponentProperties
{
this.holdReason = holdReason;
}
/**
* @param description the description to set
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return the description
*/
public String getDescription()
{
return this.description;
}
}

View File

@@ -37,7 +37,7 @@ import org.springframework.stereotype.Component;
*/
@Component
@Scope(value = "prototype")
public class FilePlanComponentApi extends RestAPI
public class FilePlanComponentApi extends RestAPI<FilePlanComponentApi>
{
/**
* Get a file plan component
@@ -57,8 +57,8 @@ public class FilePlanComponentApi extends RestAPI
return usingRestWrapper().processModel(FilePlanComponent.class, simpleRequest(
GET,
"fileplan-components/{fileplanComponentId}",
filePlanComponentId
"fileplan-components/{fileplanComponentId}?{parameters}",
filePlanComponentId, getParameters()
));
}

View File

@@ -1,5 +1,27 @@
/*
* #%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;
import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.com.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE;
import static org.alfresco.com.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE;
import static org.alfresco.com.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
import static org.alfresco.com.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
import org.testng.annotations.DataProvider;
/**
* Test data used in tests
*
@@ -18,4 +40,36 @@ public interface TestData
*/
public static final String DEFAULT_PASSWORD = "password";
public static final String DEFAULT_EMAIL = "default@alfresco.com";
/**
* Data Provider with the special file plan components alias
* @return file plan component alias
*/
@DataProvider
public static Object[][] getContainers()
{
return new Object[][] {
{ FILE_PLAN_ALIAS.toString() },
{ TRANSFERS_ALIAS.toString() },
{ HOLDS_ALIAS.toString() },
{ UNFILED_RECORDS_CONTAINER_ALIAS.toString() },
};
}
/**
* Data Provider with:
* the special file plan components alias
* file plan component node type
* @return file plan component alias
*/
@DataProvider
public static Object[][] getContainersAndTypes()
{
return new Object[][] {
{ FILE_PLAN_ALIAS, FILE_PLAN_TYPE },
{ TRANSFERS_ALIAS, TRANSFER_CONTAINER_TYPE },
{ HOLDS_ALIAS, HOLD_CONTAINER_TYPE },
{ UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE },
};
}
}

View File

@@ -0,0 +1,259 @@
/*
* #%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.fileplancomponents;
import static java.util.UUID.randomUUID;
import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
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.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.util.Arrays;
import com.google.gson.JsonObject;
import org.alfresco.com.fileplancomponents.FilePlanComponentAlias;
import org.alfresco.com.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.BaseRestTest;
import org.alfresco.rest.TestData;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.requests.FilePlanComponentApi;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;
/**
* This class contains the test for testing
* the File Plan CRUD API
*
* @author Rodica Sutu
* @since 1.0
*/
public class FilePlanTests extends BaseRestTest
{
@Autowired
private FilePlanComponentApi filePlanComponentApi;
@Autowired
private DataUser dataUser;
/**
* Given that the RM site doesn't exist
* When I use the API to get the File Plan/holds/unfiled/transfers
* Then I get the 404 response code
*/
@Test
(
description = "Check the GET response code when the RM site doesn't exist",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void getFilePlanComponentWhenRMIsNotCreated(String filePlanAlias) throws Exception
{
//check RM Site Exist
if (siteRMExist())
{
//delete RM Site
rmSiteAPI.deleteRMSite();
}
filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//get the file plan component
filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString());
//check the response code is NOT_FOUND
filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(NOT_FOUND);
}
/**
* Given that a file plan exists
* When I ask the API for the details of the file plan
* Then I am given the details of the file plan
*/
@Test
(
description = "Check the GET response for special file plan components when the RM site exit",
dataProviderClass = TestData.class,
dataProvider = "getContainersAndTypes"
)
public void getFilePlanComponentWhenRMIsCreated(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception
{
//create RM Site if doesn't exist
createRMSiteIfNotExists();
//authenticate with admin user
filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//get the file plan special container
FilePlanComponent filePlanComponent=filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString());
//check the response code
filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(OK);
//check the response contains the right node type
assertEquals(filePlanComponent.getNodeType(), rmType.toString());
}
/**
* Given that a file plan exists
* When I ask the API for the details of the file plan to include the allowableOperations property
* Then I am given the allowableOperations property with the update and create operations.
*/
@Test
(
description = "Check the allowableOperations list returned ",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void includeAllowableOperations(FilePlanComponentAlias filePlanAlias) throws Exception
{
//create RM Site if doesn't exist
createRMSiteIfNotExists();
filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//GET the file plan special containers with the optional parameter allowableOperations
FilePlanComponent filePlanComponent = filePlanComponentApi.withParams("include=allowableOperations").getFilePlanComponent(filePlanAlias.toString());
//Check the list of allowableOperations returned
assertTrue(filePlanComponent.getAllowableOperations().containsAll(Arrays.asList("update", "create")),
"Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString());
//check the list of allowableOperations doesn't contains DELETE operation
assertFalse(filePlanComponent.getAllowableOperations().contains("delete"),
"The list of allowable operations contains delete option"+ filePlanComponent.getAllowableOperations().toString());
}
/**
* Given that a file plan exists
* When I ask the API to modify the details of the file plan
* Then the details of the file are modified
* Note: the details of the file plan are limited to title and description.
*/
@Test
@Bug (id = "RM-4295")
public void updateFilePlan() throws Exception
{
String FILE_PLAN_DESCRIPTION="Description updated " +randomUUID().toString().substring(0, 4);
String FILE_PLAN_TITLE = "Title updated " + randomUUID().toString().substring(0, 4);
//create RM Site if doesn't exist
createRMSiteIfNotExists();
filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//Build the file plan root properties
JsonObject filePlanProperties = buildObject()
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, FILE_PLAN_TITLE)
.add(PROPERTIES_DESCRIPTION, FILE_PLAN_DESCRIPTION)
.end()
.getJson();
// Update the record category
FilePlanComponent renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(filePlanProperties,FILE_PLAN_ALIAS.toString());
// Verify the response status code
filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(OK);
// Verify the returned description field for the file plan component
assertEquals(renamedFilePlanComponent.getProperties().getDescription(), FILE_PLAN_DESCRIPTION);
// Verify the returned title field for the file plan component
assertEquals(renamedFilePlanComponent.getProperties().getTitle(), FILE_PLAN_TITLE);
}
/**
* Given that a file plan exists
* When I ask the API to delete the file plan
* Then the 405 response code is returned. (see https://docs.google.com/document/d/1l4tcAnZotJR6qTHI4LFi62dy_i5Zuk-9ImDXDHpD_rA/edit?ts=578f7b64# page 20 and36)
*/
@Test
(
description = "Check the response code when deleting the special file plan components",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void deleteFilePlanSpecialComponents(String filePlanAlias) throws Exception
{
createRMSiteIfNotExists();
filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//get the file plan component
filePlanComponentApi.deleteFilePlanComponent(filePlanAlias.toString());
//check the DELETE response status code
filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
}
/**
* Given that RM site exists
* When I ask to create the file plan
* Then the 405 response code is returned. (see https://docs.google.com/document/d/1l4tcAnZotJR6qTHI4LFi62dy_i5Zuk-9ImDXDHpD_rA/edit?ts=578f7b64# page 20)
*/
@Test
(
description = "Check the response code when creating the special file plan components",
dataProviderClass = TestData.class,
dataProvider = "getContainersAndTypes"
)
@Bug(id="RM-4296")
public void createFilePlanSpecialContainerWhenExists(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception
{
String rmSiteId=rmSiteAPI.getSite().getGuid();
//create RM Site if doesn't exist
createRMSiteIfNotExists();
filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String COMPONENT_TITLE = filePlanAlias + randomUUID().toString().substring(0, 4);
//Build the file plan root properties
JsonObject componentProperties = buildObject()
.add(NAME, COMPONENT_TITLE)
.add(NODE_TYPE, rmType.toString())
.getJson();
//create the special containers into RM site - parent folder
filePlanComponentApi.createFilePlanComponent(componentProperties, rmSiteId);
filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
//create the special containers into RM site - parent folder
filePlanComponentApi.createFilePlanComponent(componentProperties, FILE_PLAN_ALIAS.toString());
filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
//create the special containers into the root of special containers containers
filePlanComponentApi.createFilePlanComponent(componentProperties, filePlanAlias.toString());
filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
}
/**
* Given that RM exists
* When a non-RM user ask the API for the details of the file plan
* Then the status code 403 (Permission denied) is return
*/
@Test
(
description = "Check the response code when the RM site containers are get with non rm users",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanAlias) throws Exception
{
//create RM Site if doesn't exist
createRMSiteIfNotExists();
rmSiteAPI.usingRestWrapper().disconnect();
restClient.authenticateUser(dataUser.getAdminUser());
//create a random user
UserModel nonRMuser = dataUser.createRandomTestUser("testUser");
//authenticate using the random user
filePlanComponentApi.usingRestWrapper().authenticateUser(nonRMuser);
//get the special file plan components
filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString());
//check the response status code -FORBIDDEN
filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
}
}