Merge branch 'feature/RM-4195_CreateRMSite2' into 'master'

Feature/rm 4195 create rm site2

See merge request !1
This commit is contained in:
Rodica Sutu
2016-10-27 14:52:53 +01:00
11 changed files with 463 additions and 14 deletions

View File

@@ -9,7 +9,7 @@
* agreement is prohibited. * agreement is prohibited.
* #L% * #L%
*/ */
package org.alfresco.com; package org.alfresco.com.fileplancomponents;
/** /**
* File plan component alias enumeration * File plan component alias enumeration

View File

@@ -9,7 +9,7 @@
* agreement is prohibited. * agreement is prohibited.
* #L% * #L%
*/ */
package org.alfresco.com; package org.alfresco.com.fileplancomponents;
/** /**
* FIXME: Document me :) * FIXME: Document me :)

View File

@@ -9,7 +9,7 @@
* agreement is prohibited. * agreement is prohibited.
* #L% * #L%
*/ */
package org.alfresco.com; package org.alfresco.com.fileplancomponents;
/** /**
* File plan component type enumeration * File plan component type enumeration

View File

@@ -0,0 +1,24 @@
/*
* #%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.com.site;
/**
* RM Site compliance
*
* @author Tuna Aksoy
* @since 1.0
*/
public enum RMSiteCompliance
{
STANDARD,
DOD5015
}

View File

@@ -0,0 +1,37 @@
/*
* #%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.com.site;
/**
*RM Site properties from the RM Model Schema
*"entry": {
* "id": "string",
* "guid": "string",
* "title": "string",
* "description": "string",
* "visibility": "{@link org.springframework.social.alfresco.api.entities.Site.Visibility}",
* "compliance": "{@link RMSiteCompliance}",
* "role": "{@link org.alfresco.utility.constants.UserRole}"
*}
* @author Tuna Aksoy
* @author Rodica Sutu
* @since 1.0
*/
public class RMSiteFields
{
public static final String ID = "id";
public static final String COMPLIANCE = "compliance";
public static final String TITLE = "title";
public static final String DESCRIPTION = "description";
public static final String VISIBILITY ="visibility";
public static final String ROLE = "role";
}

View File

@@ -9,9 +9,9 @@
* agreement is prohibited. * agreement is prohibited.
* #L% * #L%
*/ */
package org.alfresco.rest.model; package org.alfresco.rest.model.fileplancomponents;
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES; import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;

View File

@@ -9,11 +9,11 @@
* agreement is prohibited. * agreement is prohibited.
* #L% * #L%
*/ */
package org.alfresco.rest.model; package org.alfresco.rest.model.fileplancomponents;
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_HOLD_REASON; import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON;
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;

View File

@@ -0,0 +1,47 @@
/*
* #%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.model.site;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.alfresco.com.site.RMSiteCompliance;
import org.alfresco.rest.model.RestSiteModel;
/**
* POJO for RM Site component
*
* @author Rodica Sutu
* @since 1.0
*/
public class RMSite extends RestSiteModel
{
@JsonProperty (required = true)
private RMSiteCompliance compliance;
/**
* Helper method to set RM site compliance
* @param compliance {@link RMSiteCompliance} the compliance to set
*/
public void setCompliance(RMSiteCompliance compliance)
{
this.compliance = compliance;
}
/**
* Helper method to get RM site compliance
* @return compliance the RM Site compliance to get
*/
public RMSiteCompliance getCompliance()
{
return compliance;
}
}

View File

@@ -0,0 +1,123 @@
/*
* #%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.requests;
import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.springframework.http.HttpMethod.DELETE;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpMethod.PUT;
import com.google.gson.JsonObject;
import org.alfresco.rest.core.RestAPI;
import org.alfresco.rest.model.site.RMSite;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* File plan component REST API Wrapper
*
* @author Tuna Aksoy
* @author Rodica Sutu
* @since 1.0
*/
@Component
@Scope (value = "prototype")
public class RMSiteAPI extends RestAPI
{
/**
* Get the RM site
*
* @return The {@link RMSite} for the given file plan component id
* @throws Exception for the following cases:
* <ul>
* <li>Api Response code 400 Invalid parameter: GET request is supported only for the RM site</li>
* <li>Api Response code 401 If authentication failed</li>
* <li>Api Response code 409 If RM Site does not exist</li>
* <li>Api Response code default Unexpected error</li>
* </ul>
*/
public RMSite getSite() throws Exception
{
return usingRestWrapper().processModel(RMSite.class, simpleRequest(
GET,
"sites/rm"
));
}
/**
* Create the RM site
*
* @param rmSiteProperties The properties of the rm site to be created
* @return The {@link RMSite} with the given properties
* @throws Exception for the following cases:
* <ul>
* <li>Api Response code 400 Invalid parameter: title, or description exceed the maximum length; or siteBodyCreate invalid</li>
* <li>Api Response code 401 If authentication failed</
* <li>Api Response code 409 RM Site already exists</li>
* <li>Api Response code default Unexpected error</li>
* </ul>
*/
public RMSite createRMSite(JsonObject rmSiteProperties) throws Exception
{
return usingRestWrapper().processModel(RMSite.class, requestWithBody(
POST,
rmSiteProperties.toString(),
"sites"
));
}
/**
* Delete RM site
* @throws Exception for the following cases:
* <ul>
* <li>Api Response code 400 Invalid parameter: DELETE request is supported only for the RM site</li>
* <li>Api Response code 401 If authentication failed</
* <li>Api Response code 403 Current user does not have permission to delete the site that is visible to them.</li>
* <li>Api Response code 404 RM site does not exist</li>
* <li>Api Response code default Unexpected error</li>
* </ul>
*/
public void deleteRMSite() throws Exception
{
usingRestWrapper().processEmptyModel(simpleRequest(
DELETE,
"sites/rm"
));
}
/**
* Update RM site
*
* @param rmSiteProperties The properties to be updated
* @return The updated {@link RMSite}
* @throws Exception for the following cases:
* <ul>
* <li>Api Response code 400 the update request is invalid {@code rmSiteProperties} is invalid</li>
* <li>Api Response code 401 If authentication fails</li>
* <li>Api Response code 403 does not have permission to update {@code RMSite}</li>
* <li>Api Response code 404 {@code RMSite} does not exist</li>
* <li>Api Response code default Unexpected error,model integrity exception</li>
* </ul>
*/
public RMSite updateRMSite(JsonObject rmSiteProperties) throws Exception
{
return usingRestWrapper().processModel(RMSite.class, requestWithBody(
PUT,
rmSiteProperties.toString(),
"sites/rm"
));
}
}

View File

@@ -13,11 +13,25 @@ package org.alfresco.rest;
import static java.lang.Integer.parseInt; 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.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.CREATED;
import com.google.gson.JsonObject;
import com.jayway.restassured.RestAssured; import com.jayway.restassured.RestAssured;
import org.alfresco.dataprep.SiteService;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.requests.RMSiteAPI;
import org.alfresco.utility.data.DataUser;
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.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
/** /**
@@ -44,6 +58,17 @@ public class BaseRestTest extends RestTest
@Value ("${alfresco.rm.basePath}") @Value ("${alfresco.rm.basePath}")
private String basePath; private String basePath;
@Autowired
public RMSiteAPI rmSiteAPI;
@Autowired
public DataUser dataUser;
private static final String RM_ID = "rm";
@Autowired
private SiteService siteService;
/** /**
* @see org.alfresco.rest.RestTest#checkServerHealth() * @see org.alfresco.rest.RestTest#checkServerHealth()
*/ */
@@ -54,5 +79,43 @@ public class BaseRestTest extends RestTest
RestAssured.baseURI = scheme + "://" + host; RestAssured.baseURI = scheme + "://" + host;
RestAssured.port = parseInt(port); RestAssured.port = parseInt(port);
RestAssured.basePath = basePath; RestAssured.basePath = basePath;
//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
{
final String RM_TITLE = "Records Management";
final String RM_DESCRIPTION = "Records Management Site";
//check RM site doesn't exist
if (!siteRMExist())
{
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Build the RM site properties
JsonObject rmSiteProperties = buildObject()
.add(TITLE, RM_TITLE)
.add(DESCRIPTION, RM_DESCRIPTION)
.add(COMPLIANCE, STANDARD.toString())
.getJson();
// Create the RM site
rmSiteAPI.createRMSite(rmSiteProperties);
// Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
}
}
/**
* Check the RM site exist via the GET request
*/
public boolean siteRMExist() throws Exception
{
RestWrapper restWrapper=rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
rmSiteAPI.getSite();
return restWrapper.getStatusCode().equals(HttpStatus.OK.toString());
} }
} }

View File

@@ -0,0 +1,155 @@
/*
* #%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 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.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.CONFLICT;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.social.alfresco.api.entities.Site.Visibility.PUBLIC;
import static org.testng.Assert.assertEquals;
import com.google.gson.JsonObject;
import org.alfresco.rest.BaseRestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.model.site.RMSite;
import org.testng.annotations.Test;
/**
* FIXME: Document me :)
* FIXME: Should we use dependent tests or not?
* They were removed here but there is no guarantee for the test execution order.
* In {@link RecordCategoryTest} we create a record category first to delete it.
* Probbaly something to think about again.
*
* @author Rodica Sutu
* @since 1.0
*/
public class RMSiteTests extends BaseRestTest
{
// Constants
private static final String RM_ID = "rm";
private static final String RM_TITLE = "Records Management";
private static final String RM_DESCRIPTION = "Records Management Site";
@Test
(
description = "Create RM site as admin user with standard Compliance"
)
public void createRMSiteAsAdminUser() throws Exception
{
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
if (siteRMExist())
{
//Delete the RM site
rmSiteAPI.deleteRMSite();
}
// Build the RM site properties
JsonObject rmSiteProperties = buildObject().
add(TITLE, RM_TITLE).
add(DESCRIPTION, RM_DESCRIPTION).
add(COMPLIANCE, STANDARD.toString()).
getJson();
// Create the RM site
RMSite rmSite = rmSiteAPI.createRMSite(rmSiteProperties);
// Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
// Verify the returned file plan component
assertEquals(rmSite.getId(), RM_ID);
assertEquals(rmSite.getTitle(), RM_TITLE);
assertEquals(rmSite.getDescription(), RM_DESCRIPTION);
assertEquals(rmSite.getCompliance(), STANDARD);
assertEquals(rmSite.getVisibility(), PUBLIC);
}
@Test
(
description = "Create RM site when site already exist with admin user"
)
public void createRMSiteWhenSiteExists() throws Exception
{
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
createRMSiteIfNotExists();
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Construct new properties
String newTitle = RM_TITLE + "createRMSiteWhenSiteExists";
String newDescription = RM_DESCRIPTION + "createRMSiteWhenSiteExists";
// Build the RM site properties
JsonObject rmSiteProperties = buildObject().
add(TITLE, newTitle).
add(DESCRIPTION, newDescription).
add(COMPLIANCE, STANDARD.toString()).
getJson();
// Create the RM site
rmSiteAPI.createRMSite(rmSiteProperties);
// Verify the status code
restWrapper.assertStatusCodeIs(CONFLICT);
}
@Test
(
description = "Delete RM site as admin user"
)
public void deleteRMSite() throws Exception
{
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Delete the RM site
rmSiteAPI.deleteRMSite();
// Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT);
}
@Test
(
description = "GET RM site as admin user"
)
public void getRMSite() throws Exception
{
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the RM site
RMSite rmSite=rmSiteAPI.getSite();
if (!siteRMExist())
{
// Verify the status code
restWrapper.assertStatusCodeIs(NOT_FOUND);
}
else
{
// Verify the status code
restWrapper.assertStatusCodeIs(OK);
assertEquals(rmSite.getId(), RM_ID);
assertEquals(rmSite.getDescription(), RM_DESCRIPTION);
assertEquals(rmSite.getCompliance(), STANDARD);
assertEquals(rmSite.getVisibility(), PUBLIC);
}
}
}