Refactored code

This commit is contained in:
Tuna Aksoy
2016-11-01 19:42:39 +00:00
parent f0655e004a
commit 43e483d0bc
22 changed files with 417 additions and 285 deletions

2
README
View File

@@ -1,3 +1,3 @@
FIXME: DOCUMENT ME BETTER :)
FIXME: Add more info to the README file
In order to change the value of a property in "config.properties" create a file called "local.properties" under src/test/resources and redefine the property with the new value.

View File

@@ -11,8 +11,8 @@
*/
package org.alfresco.rest.model.fileplancomponents;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS;
import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import java.util.List;
@@ -28,32 +28,22 @@ import com.fasterxml.jackson.annotation.JsonProperty;
//FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed
@JsonIgnoreProperties(ignoreUnknown = true)
public class FilePlanComponent
{
{
private String id;
private String parentId;
private String name;
private String nodeType;
private boolean isCategory;
private boolean isRecordFolder;
private boolean isFile;
private boolean hasRetentionSchedule;
private List<String> aspectNames;
private FilePlanComponentCreatedByUser createdByUser;
@JsonProperty(PROPERTIES)
private FilePlanComponentProperties properties;
private FilePlanComponentCreatedByUser createdByUser;
@JsonProperty (ALLOWABLE_OPERATIONS)
private List<String> allowableOperations;
/**
* @return the id
*/

View File

@@ -9,7 +9,9 @@
* agreement is prohibited.
* #L%
*/
package org.alfresco.com.fileplancomponents;
package org.alfresco.rest.model.fileplancomponents;
import static org.alfresco.rest.util.ParameterCheck.mandatoryString;
/**
* File plan component alias enumeration
@@ -33,19 +35,26 @@ public enum FilePlanComponentAlias
public static final FilePlanComponentAlias getFilePlanComponentAlias(String alias)
{
switch (alias)
mandatoryString("alias", alias);
FilePlanComponentAlias result = null;
FilePlanComponentAlias[] values = values();
for (FilePlanComponentAlias filePlanComponentAlias : values)
{
case "-filePlan-":
return FILE_PLAN_ALIAS;
case "-transfers-":
return TRANSFERS_ALIAS;
case "-unfiled-":
return UNFILED_RECORDS_CONTAINER_ALIAS;
case "-holds-":
return HOLDS_ALIAS;
if (filePlanComponentAlias.toString().equals(alias))
{
result = filePlanComponentAlias;
break;
}
}
throw new IllegalArgumentException("Invalid file plan component alias enum value: '" + alias + "'.");
if (result == null)
{
throw new IllegalArgumentException("Invalid file plan component alias enum value: '" + alias + "'.");
}
return result;
}
/**

View File

@@ -13,6 +13,7 @@ package org.alfresco.rest.model.fileplancomponents;
/**
* POJO for file plan component created by object
*
* @author Kristijan Conkas
* @since 1.0
*/
@@ -20,6 +21,7 @@ public class FilePlanComponentCreatedByUser
{
private String id;
private String displayName;
/**
* @return the id
*/
@@ -27,6 +29,7 @@ public class FilePlanComponentCreatedByUser
{
return this.id;
}
/**
* @param id the id to set
*/
@@ -34,6 +37,7 @@ public class FilePlanComponentCreatedByUser
{
this.id = id;
}
/**
* @return the displayName
*/
@@ -41,6 +45,7 @@ public class FilePlanComponentCreatedByUser
{
return this.displayName;
}
/**
* @param displayName the displayName to set
*/

View File

@@ -11,10 +11,11 @@
*/
package org.alfresco.rest.model.fileplancomponents;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.ENTRY;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.alfresco.rest.core.RestModels;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponent;
/**
* POJO for file plan component entry
@@ -24,7 +25,7 @@ import org.alfresco.rest.model.fileplancomponents.FilePlanComponent;
*/
public class FilePlanComponentEntry extends RestModels<FilePlanComponent, FilePlanComponentEntry>
{
@JsonProperty(value = "entry")
@JsonProperty(ENTRY)
FilePlanComponent filePlanComponent;
public FilePlanComponent getFilePlanComponent()

View File

@@ -9,7 +9,7 @@
* agreement is prohibited.
* #L%
*/
package org.alfresco.com.fileplancomponents;
package org.alfresco.rest.model.fileplancomponents;
/**
* File plan component field names constants
@@ -22,6 +22,7 @@ public class FilePlanComponentFields
public static final String NAME = "name";
public static final String NODE_TYPE = "nodeType";
public static final String NODE_PARENT_ID = "parentId";
public static final String ENTRY = "entry";
public static final String PROPERTIES = "properties";
public static final String PROPERTIES_TITLE = "cm:title";
public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator";

View File

@@ -11,10 +11,10 @@
*/
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;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -38,8 +38,9 @@ public class FilePlanComponentProperties
@JsonProperty(PROPERTIES_HOLD_REASON)
private String holdReason;
@JsonProperty (PROPERTIES_DESCRIPTION)
@JsonProperty(PROPERTIES_DESCRIPTION)
private String description;
/**
* @return the vitalRecord
*/
@@ -103,5 +104,4 @@ public class FilePlanComponentProperties
{
return this.description;
}
}

View File

@@ -9,7 +9,9 @@
* agreement is prohibited.
* #L%
*/
package org.alfresco.com.fileplancomponents;
package org.alfresco.rest.model.fileplancomponents;
import static org.alfresco.rest.util.ParameterCheck.mandatoryString;
/**
* File plan component type enumeration
@@ -37,27 +39,26 @@ public enum FilePlanComponentType
public static final FilePlanComponentType getFilePlanComponentType(String type)
{
switch (type)
mandatoryString("type", type);
FilePlanComponentType result = null;
FilePlanComponentType[] values = values();
for (FilePlanComponentType filePlanComponentType : values)
{
case "rma:filePlan":
return FILE_PLAN_TYPE;
case "rma:recordCategory":
return RECORD_CATEGORY_TYPE;
case "rma:recordFolder":
return RECORD_FOLDER_TYPE;
case "rma:hold":
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;
if (filePlanComponentType.toString().equals(filePlanComponentType))
{
result = filePlanComponentType;
break;
}
}
throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'.");
if (result == null)
{
throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'.");
}
return result;
}
/**

View File

@@ -15,6 +15,7 @@ import org.alfresco.rest.core.RestModels;
/**
* Handle collection of FilePlanComponents
*
* @author Kristijan Conkas
* @since 1.0
*/

View File

@@ -13,7 +13,6 @@ package org.alfresco.rest.model.site;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.alfresco.com.site.RMSiteCompliance;
import org.alfresco.rest.model.RestSiteModel;
/**
@@ -29,6 +28,7 @@ public class RMSite extends RestSiteModel
/**
* Helper method to set RM site compliance
*
* @param compliance {@link RMSiteCompliance} the compliance to set
*/
public void setCompliance(RMSiteCompliance compliance)
@@ -38,6 +38,7 @@ public class RMSite extends RestSiteModel
/**
* Helper method to get RM site compliance
*
* @return compliance the RM Site compliance to get
*/
public RMSiteCompliance getCompliance()

View File

@@ -9,7 +9,7 @@
* agreement is prohibited.
* #L%
*/
package org.alfresco.com.site;
package org.alfresco.rest.model.site;
/**
* RM Site compliance

View File

@@ -9,7 +9,7 @@
* agreement is prohibited.
* #L%
*/
package org.alfresco.com.site;
package org.alfresco.rest.model.site;
/**
*RM Site properties from the RM Model Schema

View File

@@ -11,10 +11,10 @@
*/
package org.alfresco.rest.requests;
import static org.alfresco.com.util.ParameterCheck.mandatoryObject;
import static org.alfresco.com.util.ParameterCheck.mandatoryString;
import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.alfresco.rest.util.ParameterCheck.mandatoryObject;
import static org.alfresco.rest.util.ParameterCheck.mandatoryString;
import static org.springframework.http.HttpMethod.DELETE;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
@@ -37,7 +37,7 @@ import org.springframework.stereotype.Component;
*/
@Component
@Scope(value = "prototype")
public class FilePlanComponentApi extends RestAPI<FilePlanComponentApi>
public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
{
/**
* Get a file plan component

View File

@@ -13,6 +13,7 @@ package org.alfresco.rest.requests;
import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.alfresco.rest.util.ParameterCheck.mandatoryObject;
import static org.springframework.http.HttpMethod.DELETE;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
@@ -34,7 +35,7 @@ import org.springframework.stereotype.Component;
*/
@Component
@Scope (value = "prototype")
public class RMSiteAPI extends RestAPI
public class RMSiteAPI extends RestAPI<RMSiteAPI>
{
/**
* Get the RM site
@@ -71,6 +72,8 @@ public class RMSiteAPI extends RestAPI
*/
public RMSite createRMSite(JsonObject rmSiteProperties) throws Exception
{
mandatoryObject("rmSiteProperties", rmSiteProperties);
return usingRestWrapper().processModel(RMSite.class, requestWithBody(
POST,
rmSiteProperties.toString(),
@@ -113,11 +116,12 @@ public class RMSiteAPI extends RestAPI
*/
public RMSite updateRMSite(JsonObject rmSiteProperties) throws Exception
{
mandatoryObject("rmSiteProperties", rmSiteProperties);
return usingRestWrapper().processModel(RMSite.class, requestWithBody(
PUT,
rmSiteProperties.toString(),
"sites/rm"
));
}
}

View File

@@ -9,7 +9,7 @@
* agreement is prohibited.
* #L%
*/
package org.alfresco.com.util;
package org.alfresco.rest.util;
import static org.apache.commons.lang3.StringUtils.isBlank;
@@ -27,11 +27,11 @@ public class ParameterCheck
}
/**
* FIXME: Document me :)
* Checks if a given {@link String} is blank or not, i.e. not <code>null<code>, "" or " ".
*
* @param paramName FIXME: Document me :)
* @param paramValue FIXME: Document me :)
* @throws IllegalArgumentException FIXME: Document me :)
* @param paramName The name of the parameter to check
* @param paramValue The value of the parameter to check
* @throws IllegalArgumentException Throws an exception if the given value is blank
*/
public static void mandatoryString(final String paramName, final String paramValue) throws IllegalArgumentException
{
@@ -42,12 +42,13 @@ public class ParameterCheck
}
/**
* FIXME: Document me :)
* Checks if a given {@link Object} is null or not
*
* @param paramName FIXME: Document me :)
* @param object FIXME: Document me :)
* @param paramName The name of the parameter to check
* @param object The value of the parameter to check
* @throws IllegalArgumentException Throws an exception if the given value is null
*/
public static void mandatoryObject(final String paramName, final Object object)
public static void mandatoryObject(final String paramName, final Object object) throws IllegalArgumentException
{
if (object == null)
{

View File

@@ -0,0 +1,25 @@
/*
* #%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.base;
/**
* List of allowable operations
*
* @author Tuna Aksoy
* @since 1.0
*/
public class AllowableOperations
{
public static final String CREATE = "create";
public static final String UPDATE = "update";
public static final String DELETE = "delete";
}

View File

@@ -9,14 +9,14 @@
* agreement is prohibited.
* #L%
*/
package org.alfresco.rest;
package org.alfresco.rest.base;
import static java.lang.Integer.parseInt;
import static org.alfresco.com.site.RMSiteCompliance.STANDARD;
import static org.alfresco.com.site.RMSiteFields.COMPLIANCE;
import static org.alfresco.com.site.RMSiteFields.DESCRIPTION;
import static org.alfresco.com.site.RMSiteFields.TITLE;
import static org.alfresco.rest.model.site.RMSiteCompliance.STANDARD;
import static org.alfresco.rest.model.site.RMSiteFields.COMPLIANCE;
import static org.alfresco.rest.model.site.RMSiteFields.DESCRIPTION;
import static org.alfresco.rest.model.site.RMSiteFields.TITLE;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
@@ -24,6 +24,7 @@ import static org.springframework.http.HttpStatus.OK;
import com.google.gson.JsonObject;
import com.jayway.restassured.RestAssured;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.requests.RMSiteAPI;
import org.alfresco.utility.data.DataUser;
@@ -58,10 +59,10 @@ public class BaseRestTest extends RestTest
private String restRmPath;
@Autowired
public RMSiteAPI rmSiteAPI;
private RMSiteAPI rmSiteAPI;
@Autowired
public DataUser dataUser;
private DataUser dataUser;
// Constants
public static final String RM_ID = "rm";
@@ -79,17 +80,18 @@ public class BaseRestTest extends RestTest
RestAssured.port = parseInt(port);
RestAssured.basePath = restRmPath;
//create RM Site if not exist
// Create RM Site if not exist
createRMSiteIfNotExists();
}
/**
* Helper method to create the RM Site via the POST request
* if the site doesn't exist
*/
public void createRMSiteIfNotExists() throws Exception
{
//check RM site doesn't exist
if (!siteRMExist())
// Check RM site doesn't exist
if (!siteRMExists())
{
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
@@ -109,9 +111,9 @@ public class BaseRestTest extends RestTest
}
/**
* Check the RM site exist via the GET request
* Check if the RM site exists via the GET request
*/
public boolean siteRMExist() throws Exception
public boolean siteRMExists() throws Exception
{
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
rmSiteAPI.getSite();

View File

@@ -9,16 +9,16 @@
* agreement is prohibited.
* #L%
*/
package org.alfresco.rest;
package org.alfresco.rest.base;
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 static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
import org.testng.annotations.DataProvider;
@@ -26,6 +26,7 @@ import org.testng.annotations.DataProvider;
* Test data used in tests
*
* @author Rodica Sutu
* @since 1.0
*/
public interface TestData
{
@@ -39,6 +40,10 @@ public interface TestData
* The default password used when creating test users.
*/
public static final String DEFAULT_PASSWORD = "password";
/**
* The default email address used when creating test users.
*/
public static final String DEFAULT_EMAIL = "default@alfresco.com";
/**

View File

@@ -11,14 +11,18 @@
*/
package org.alfresco.rest.fileplancomponents;
import static java.util.UUID.randomUUID;
import static java.util.Arrays.asList;
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.alfresco.rest.base.AllowableOperations.CREATE;
import static org.alfresco.rest.base.AllowableOperations.DELETE;
import static org.alfresco.rest.base.AllowableOperations.UPDATE;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.HttpStatus.NOT_FOUND;
@@ -27,16 +31,15 @@ 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.base.BaseRestTest;
import org.alfresco.rest.base.TestData;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.requests.FilePlanComponentApi;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.requests.FilePlanComponentAPI;
import org.alfresco.rest.requests.RMSiteAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
@@ -53,14 +56,17 @@ import org.testng.annotations.Test;
public class FilePlanTests extends BaseRestTest
{
@Autowired
private FilePlanComponentApi filePlanComponentApi;
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private RMSiteAPI rmSiteAPI;
@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
* When I use the API to get the File Plan/Holds/Unfiled Records Container/Transfers
* Then I get the 404 response code
*/
@Test
@@ -71,17 +77,21 @@ public class FilePlanTests extends BaseRestTest
)
public void getFilePlanComponentWhenRMIsNotCreated(String filePlanAlias) throws Exception
{
//check RM Site Exist
if (siteRMExist())
// Check RM Site Exist
if (siteRMExists())
{
//delete RM Site
// Delete RM Site
rmSiteAPI.deleteRMSite();
}
filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//get the file plan component
filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString());
// Authenticate with admin user
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);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND);
}
/**
@@ -97,15 +107,19 @@ public class FilePlanTests extends BaseRestTest
)
public void getFilePlanComponentWhenRMIsCreated(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception
{
//create RM Site if doesn't exist
// 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
// 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());
}
@@ -122,17 +136,22 @@ public class FilePlanTests extends BaseRestTest
)
public void includeAllowableOperations(String specialContainerAlias) throws Exception
{
//create RM Site if doesn't exist
// 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(specialContainerAlias);
//Check the list of allowableOperations returned
assertTrue(filePlanComponent.getAllowableOperations().containsAll(Arrays.asList("update", "create")),
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the file plan special containers with the optional parameter allowableOperations
FilePlanComponent filePlanComponent = filePlanComponentAPI.withParams("include=allowableOperations").getFilePlanComponent(specialContainerAlias);
// Check the list of allowableOperations returned
assertTrue(filePlanComponent.getAllowableOperations().containsAll(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());
// 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());
}
/**
@@ -145,12 +164,16 @@ public class FilePlanTests extends BaseRestTest
@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
String FILE_PLAN_DESCRIPTION = "Description updated " + getRandomAlphanumeric();
String FILE_PLAN_TITLE = "Title updated " + getRandomAlphanumeric();
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//Build the file plan root properties
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Build the file plan root properties
JsonObject filePlanProperties = buildObject()
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, FILE_PLAN_TITLE)
@@ -158,15 +181,15 @@ public class FilePlanTests extends BaseRestTest
.end()
.getJson();
// Update the record category
FilePlanComponent renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(filePlanProperties,FILE_PLAN_ALIAS.toString());
FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(filePlanProperties,FILE_PLAN_ALIAS.toString());
// Verify the response status code
filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(OK);
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);
}
@@ -184,12 +207,17 @@ public class FilePlanTests extends BaseRestTest
)
public void deleteFilePlanSpecialComponents(String filePlanAlias) throws Exception
{
// Create RM Site if doesn't exist
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);
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Delete the file plan component
filePlanComponentAPI.deleteFilePlanComponent(filePlanAlias.toString());
// Check the DELETE response status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
}
/**
@@ -206,28 +234,33 @@ public class FilePlanTests extends BaseRestTest
@Bug(id="RM-4296")
public void createFilePlanSpecialContainerWhenExists(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception
{
String rmSiteId=rmSiteAPI.getSite().getGuid();
String rmSiteId = rmSiteAPI.getSite().getGuid();
//create RM Site if doesn't exist
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String COMPONENT_TITLE = filePlanAlias + randomUUID().toString().substring(0, 4);
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String name = filePlanAlias + getRandomAlphanumeric();
//Build the file plan root properties
JsonObject componentProperties = buildObject()
.add(NAME, COMPONENT_TITLE)
.add(NAME, name)
.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 RM site - parent folder
filePlanComponentAPI.createFilePlanComponent(componentProperties, rmSiteId);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
//create the special containers into the root of special containers containers
filePlanComponentApi.createFilePlanComponent(componentProperties, filePlanAlias.toString());
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);
}
/**
@@ -243,17 +276,25 @@ public class FilePlanTests extends BaseRestTest
)
public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanAlias) throws Exception
{
//create RM Site if doesn't exist
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Disconnect user from REST API session
rmSiteAPI.usingRestWrapper().disconnect();
// Authenticate admin user to Alfresco REST API
restClient.authenticateUser(dataUser.getAdminUser());
//create a random user
// 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);
// Authenticate using the random user
filePlanComponentAPI.usingRestWrapper().authenticateUser(nonRMuser);
// Get the special file plan components
filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString());
// Check the response status code is FORBIDDEN
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
}
}

View File

@@ -11,15 +11,14 @@
*/
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_TITLE;
import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
import static org.alfresco.rest.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;
@@ -36,20 +35,19 @@ import java.util.NoSuchElementException;
import com.google.gson.JsonObject;
import org.alfresco.com.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.BaseRestTest;
import org.alfresco.rest.base.BaseRestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.requests.FilePlanComponentApi;
import org.alfresco.rest.requests.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;
/**
* FIXME: Document me :)
* Record category related API tests
*
* @author Kristijan Conkas
* @author Tuna Aksoy
@@ -58,12 +56,12 @@ import org.testng.annotations.Test;
public class RecordCategoryTest extends BaseRestTest
{
@Autowired
private FilePlanComponentApi filePlanComponentApi;
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
// for children creation test
// Number of children (for children creation test)
private static final int NUMBER_OF_CHILDREN = 10;
/**
@@ -78,10 +76,11 @@ public class RecordCategoryTest extends BaseRestTest
)
public void createCategoryTest() throws Exception
{
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties
JsonObject recordCategoryProperties = buildObject().
@@ -93,7 +92,7 @@ public class RecordCategoryTest extends BaseRestTest
getJson();
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
// Verify the status code
restWrapper.assertStatusCodeIs(CREATED);
@@ -102,18 +101,18 @@ public class RecordCategoryTest extends BaseRestTest
assertTrue(filePlanComponent.isIsCategory());
assertFalse(filePlanComponent.isIsFile());
assertFalse(filePlanComponent.isIsRecordFolder());
assertEquals(filePlanComponent.getName(), categoryName);
assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString());
assertFalse(filePlanComponent.isHasRetentionSchedule());
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Verify the returned file plan component properties
FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties();
assertEquals(filePlanComponentProperties.getTitle(), categoryTitle);
logger.info("aspects: " + filePlanComponent.getAspectNames());
logger.info("Aspects: " + filePlanComponent.getAspectNames());
}
/**
@@ -128,11 +127,12 @@ public class RecordCategoryTest extends BaseRestTest
)
public void renameCategory() throws Exception
{
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create record category first
String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties
JsonObject recordCategoryProperties = buildObject().
@@ -144,7 +144,7 @@ public class RecordCategoryTest extends BaseRestTest
getJson();
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
String newCategoryName = "Rename " + categoryName;
@@ -154,16 +154,17 @@ public class RecordCategoryTest extends BaseRestTest
getJson();
// Update the record category
FilePlanComponent renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(updateRecordCategoryProperties, filePlanComponent.getId());
FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(updateRecordCategoryProperties, filePlanComponent.getId());
// Verify the status code
restWrapper.assertStatusCodeIs(OK);
// Verify the returned file plan component
assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
// get actual FILE_PLAN_ALIAS id
FilePlanComponent parentComponent = filePlanComponentApi.getFilePlanComponent(FILE_PLAN_ALIAS.toString());
// Get actual FILE_PLAN_ALIAS id
FilePlanComponent parentComponent = filePlanComponentAPI.getFilePlanComponent(FILE_PLAN_ALIAS.toString());
// verify renamed component still has this parent
assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId());
}
@@ -180,11 +181,12 @@ public class RecordCategoryTest extends BaseRestTest
)
public void deleteCategory() throws Exception
{
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create record category first
String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties
JsonObject recordCategoryProperties = buildObject().
@@ -196,16 +198,16 @@ public class RecordCategoryTest extends BaseRestTest
getJson();
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
// Delete the record category
filePlanComponentApi.deleteFilePlanComponent(filePlanComponent.getId());
filePlanComponentAPI.deleteFilePlanComponent(filePlanComponent.getId());
// Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT);
// deleted component should no longer be retrievable
filePlanComponentApi.getFilePlanComponent(filePlanComponent.getId());
// Deleted component should no longer be retrievable
filePlanComponentAPI.getFilePlanComponent(filePlanComponent.getId());
restWrapper.assertStatusCodeIs(NOT_FOUND);
}
@@ -221,17 +223,17 @@ public class RecordCategoryTest extends BaseRestTest
)
public void createSubcategory() throws Exception
{
// create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
// Create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric());
assertNotNull(rootCategory.getId());
// create subcategory as a child of rootCategory
FilePlanComponent childCategory = createCategory(rootCategory.getId(), RandomData.getRandomAlphanumeric());
// Create subcategory as a child of rootCategory
FilePlanComponent childCategory = createCategory(rootCategory.getId(), getRandomAlphanumeric());
// child category created?
// Child category created?
assertNotNull(childCategory.getId());
// verify child category
// Verify child category
assertEquals(childCategory.getParentId(), rootCategory.getId());
assertTrue(childCategory.isIsCategory());
assertFalse(childCategory.isIsFile());
@@ -253,57 +255,61 @@ public class RecordCategoryTest extends BaseRestTest
)
public void listChildren() throws Exception
{
// create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
assertNotNull(rootCategory.getId());
// Create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric());
assertNotNull(rootCategory.getId());
// add child categories/folders
// Add child categories/folders
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
for (int i=0; i < NUMBER_OF_CHILDREN; i++)
{
// create a child
// Create a child
FilePlanComponent child = createComponent(rootCategory.getId(),
RandomData.getRandomAlphanumeric(),
getRandomAlphanumeric(),
// half of the children should be subcategories, the other subfolders
(i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE);
assertNotNull(child.getId());
children.add(child);
}
// list children from API
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId());
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// List children from API
FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(rootCategory.getId());
// Check status code
restWrapper.assertStatusCodeIs(OK);
logger.info("parent: " + rootCategory.getId());
// check listed children against created list
apiChildren.getEntries().forEach(c ->
// Check listed children against created list
apiChildren.getEntries().forEach(c ->
{
FilePlanComponent filePlanComponent = c.getFilePlanComponent();
assertNotNull(filePlanComponent.getId());
logger.info("checking child " + filePlanComponent.getId());
try
logger.info("Checking child " + filePlanComponent.getId());
try
{
// find this child in created children list
// Find this child in created children list
FilePlanComponent createdComponent = children.stream()
.filter(child -> child.getId().equals(filePlanComponent.getId()))
.findFirst()
.get();
// created by
// Created by
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// is parent Id set correctly?
// Is parent Id set correctly?
assertEquals(filePlanComponent.getParentId(), rootCategory.getId());
// only categories or folders have been created
// Only categories or folders have been created
assertFalse(filePlanComponent.isIsFile());
// boolean properties related to node type
// only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created
// Boolean properties related to node type
// Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created
if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE.toString()))
{
{
assertTrue(filePlanComponent.isIsCategory());
assertFalse(filePlanComponent.isIsRecordFolder());
}
@@ -313,12 +319,13 @@ public class RecordCategoryTest extends BaseRestTest
assertFalse(filePlanComponent.isIsCategory());
}
// does returned object have the same contents as the created one?
// Does returned object have the same contents as the created one?
assertEquals(createdComponent.getName(), filePlanComponent.getName());
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
// verify properties
}
// Verify properties
// FIXME: Verify properties
}
catch (NoSuchElementException e)
{
fail("No child element for " + filePlanComponent.getId());
@@ -328,8 +335,10 @@ public class RecordCategoryTest extends BaseRestTest
/**
* Helper method to create child category
* @param parentCategoryId
* @param categoryName
*
* @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
*/
private FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
@@ -339,15 +348,16 @@ public class RecordCategoryTest extends BaseRestTest
/**
* Helper method to create generic child component
* @param parentComponentId
* @param componentName
* @param componentType
* @return
*
* @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
* @return The created file plan component
* @throws Exception
*/
private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType) throws Exception
{
RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
JsonObject componentProperties = buildObject().
add(NAME, componentName).
@@ -357,7 +367,7 @@ public class RecordCategoryTest extends BaseRestTest
end().
getJson();
FilePlanComponent fpc = filePlanComponentApi.createFilePlanComponent(componentProperties, parentComponentId);
FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(componentProperties, parentComponentId);
restWrapper.assertStatusCodeIs(CREATED);
return fpc;
}

View File

@@ -11,14 +11,14 @@
*/
package org.alfresco.rest.site;
import static org.alfresco.com.site.RMSiteCompliance.DOD5015;
import static org.alfresco.com.site.RMSiteCompliance.STANDARD;
import static org.alfresco.com.site.RMSiteFields.COMPLIANCE;
import static org.alfresco.com.site.RMSiteFields.DESCRIPTION;
import static org.alfresco.com.site.RMSiteFields.TITLE;
import static org.alfresco.rest.TestData.ANOTHER_ADMIN;
import static org.alfresco.rest.TestData.DEFAULT_EMAIL;
import static org.alfresco.rest.TestData.DEFAULT_PASSWORD;
import static org.alfresco.rest.base.TestData.ANOTHER_ADMIN;
import static org.alfresco.rest.base.TestData.DEFAULT_EMAIL;
import static org.alfresco.rest.base.TestData.DEFAULT_PASSWORD;
import static org.alfresco.rest.model.site.RMSiteCompliance.DOD5015;
import static org.alfresco.rest.model.site.RMSiteCompliance.STANDARD;
import static org.alfresco.rest.model.site.RMSiteFields.COMPLIANCE;
import static org.alfresco.rest.model.site.RMSiteFields.DESCRIPTION;
import static org.alfresco.rest.model.site.RMSiteFields.TITLE;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CONFLICT;
@@ -34,10 +34,12 @@ import static org.testng.Assert.assertNotNull;
import com.google.gson.JsonObject;
import org.alfresco.dataprep.UserService;
import org.alfresco.rest.BaseRestTest;
import org.alfresco.rest.base.BaseRestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.model.site.RMSite;
import org.alfresco.rest.requests.RMSiteAPI;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
@@ -56,12 +58,16 @@ public class RMSiteTests extends BaseRestTest
@Autowired
private UserService userService;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
/**
* Given that RM module is installed
* When I want to create the rm site with specific title, description and compliance
* When I want to create the RM site with specific title, description and compliance
* Then the RM site is created
*
*/
@Test
(
@@ -69,12 +75,16 @@ public class RMSiteTests extends BaseRestTest
)
public void createRMSiteAsAdminUser() throws Exception
{
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
if (siteRMExist())
// Check if the RM site exists
if (siteRMExists())
{
// Delete the RM site
rmSiteAPI.deleteRMSite();
}
// Build the RM site properties
JsonObject rmSiteProperties = buildObject()
.add(TITLE, RM_TITLE)
@@ -108,8 +118,10 @@ public class RMSiteTests extends BaseRestTest
)
public void createRMSiteWhenSiteExists() throws Exception
{
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the RM site if it does not exist
createRMSiteIfNotExists();
// Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Construct new properties
@@ -141,6 +153,7 @@ public class RMSiteTests extends BaseRestTest
)
public void deleteRMSite() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Delete the RM site
@@ -161,13 +174,14 @@ public class RMSiteTests extends BaseRestTest
)
public void getRMSite() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the RM site
RMSite rmSite = rmSiteAPI.getSite();
if (!siteRMExist())
if (!siteRMExists())
{
// Verify the status code when rm site doesn't exist
// Verify the status code when RM site doesn't exist
restWrapper.assertStatusCodeIs(NOT_FOUND);
createRMSiteIfNotExists();
}
@@ -194,13 +208,20 @@ public class RMSiteTests extends BaseRestTest
@Bug (id="RM-4289")
public void createRMSiteAsAnotherAdminUser() throws Exception
{
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
if (siteRMExist())
// Check if the RM site exists
if (siteRMExists())
{
//Delete the RM site
// Delete the RM site
rmSiteAPI.deleteRMSite();
}
// Disconnect the current user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Create user
userService.create(dataUser.getAdminUser().getUsername(),
dataUser.getAdminUser().getPassword(),
ANOTHER_ADMIN,
@@ -208,8 +229,13 @@ public class RMSiteTests extends BaseRestTest
DEFAULT_EMAIL,
ANOTHER_ADMIN,
ANOTHER_ADMIN);
UserModel userModel=new UserModel(ANOTHER_ADMIN,DEFAULT_PASSWORD);
// Build the user model
UserModel userModel = new UserModel(ANOTHER_ADMIN,DEFAULT_PASSWORD);
// Authenticate as that new user
rmSiteAPI.usingRestWrapper().authenticateUser(userModel);
// Build the RM site properties
JsonObject rmSiteProperties = buildObject()
.add(TITLE, RM_TITLE)
@@ -251,14 +277,19 @@ public class RMSiteTests extends BaseRestTest
.add(DESCRIPTION, NEW_DESCRIPTION)
.getJson();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
if (!siteRMExist())
{
createRMSiteIfNotExists();
}
// Create the site if it does not exist
createRMSiteIfNotExists();
// Disconnect the user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Create a random user
UserModel nonRMuser = dataUser.createRandomTestUser("testUser");
// Authenticate as that random user
rmSiteAPI.usingRestWrapper().authenticateUser(nonRMuser);
// Create the RM site
@@ -267,7 +298,10 @@ public class RMSiteTests extends BaseRestTest
// Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
// Disconnect the user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Update the RM Site
@@ -284,7 +318,6 @@ public class RMSiteTests extends BaseRestTest
assertEquals(rmSite.getVisibility(), PUBLIC);
}
/**
* Given that RM site exist
* When the admin user wants to update the RM site compliance
@@ -293,19 +326,21 @@ public class RMSiteTests extends BaseRestTest
@Test
public void updateRMSiteComplianceAsAdmin() throws Exception
{
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
if (!siteRMExist())
{
createRMSiteIfNotExists();
}
// Create the RM site if it does not exist
createRMSiteIfNotExists();
// Build the RM site properties
JsonObject rmSiteToUpdate = buildObject()
.add(COMPLIANCE, DOD5015.toString())
.getJson();
// Update the RM site
RMSite rmSite = rmSiteAPI.updateRMSite(rmSiteToUpdate);
rmSiteAPI.updateRMSite(rmSiteToUpdate);
// Verify the response status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST);
}
}
}

View File

@@ -2,16 +2,16 @@
# Original property values from default.properties #
#########################################################################
# dataprep related
# Dataprep related
alfresco.scheme=http
alfresco.server=localhost
alfresco.port=8080
# credentials
# Credentials
admin.user=admin
admin.password=admin
# rest related
# Rest related
rest.basePath=alfresco/api/-default-/public/alfresco/versions/1
rest.workflowPath=alfresco/api/-default-/public/workflow/versions/1