mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
refactoring of the added rest api tests for SQL queries
new tests added for sql queries for: record categories, record folders and records
This commit is contained in:
@@ -84,6 +84,7 @@ public class RMUserAPI extends RMModelRequest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign RM role to user
|
* Assign RM role to user
|
||||||
|
*
|
||||||
* @param userName User's username
|
* @param userName User's username
|
||||||
* @param userRole User's RM role, one of {@link UserRoles} roles
|
* @param userRole User's RM role, one of {@link UserRoles} roles
|
||||||
* @throws Exception for failed requests
|
* @throws Exception for failed requests
|
||||||
@@ -97,29 +98,30 @@ public class RMUserAPI extends RMModelRequest
|
|||||||
|
|
||||||
// override v1 baseURI and basePath
|
// override v1 baseURI and basePath
|
||||||
RequestSpecification spec = new RequestSpecBuilder()
|
RequestSpecification spec = new RequestSpecBuilder()
|
||||||
.setBaseUri(client.getApiUrl())
|
.setBaseUri(client.getApiUrl())
|
||||||
.setBasePath("/")
|
.setBasePath("/")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Response response = given()
|
Response response = given()
|
||||||
.spec(spec)
|
.spec(spec)
|
||||||
.log().all()
|
.log().all()
|
||||||
.pathParam("role", userRole)
|
.pathParam("role", userRole)
|
||||||
.pathParam("authority", userName)
|
.pathParam("authority", userName)
|
||||||
.param("alf_ticket", client.getAlfTicket(adminUser.getUsername(),
|
.param("alf_ticket", client.getAlfTicket(adminUser.getUsername(),
|
||||||
adminUser.getPassword()))
|
adminUser.getPassword()))
|
||||||
.when()
|
.when()
|
||||||
.post("/rm/roles/{role}/authorities/{authority}")
|
.post("/rm/roles/{role}/authorities/{authority}")
|
||||||
.prettyPeek()
|
.prettyPeek()
|
||||||
.andReturn();
|
.andReturn();
|
||||||
getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
|
getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to add permission on a component to user
|
* Helper method to add permission on a component to user
|
||||||
* @param component The id of the file plan component on which permission should be given
|
*
|
||||||
* @param user {@link UserModel} for a user to be granted permission
|
* @param filePlanComponentId The id of the file plan component on which permission should be given
|
||||||
* @param permission {@link UserPermissions} to be granted
|
* @param user {@link UserModel} for a user to be granted permission
|
||||||
|
* @param permission {@link UserPermissions} to be granted
|
||||||
*/
|
*/
|
||||||
public void addUserPermission(String filePlanComponentId, UserModel user, String permission)
|
public void addUserPermission(String filePlanComponentId, UserModel user, String permission)
|
||||||
{
|
{
|
||||||
@@ -129,34 +131,75 @@ public class RMUserAPI extends RMModelRequest
|
|||||||
AlfrescoHttpClient client = getAlfrescoHttpClient();
|
AlfrescoHttpClient client = getAlfrescoHttpClient();
|
||||||
|
|
||||||
JsonObject bodyJson = buildObject()
|
JsonObject bodyJson = buildObject()
|
||||||
.addArray("permissions")
|
.addArray("permissions")
|
||||||
.addObject()
|
.addObject()
|
||||||
.add("authority", user.getUsername())
|
.add("authority", (user != null ? user.getUsername() : null))
|
||||||
.add("role", permission)
|
.add("role", permission)
|
||||||
.end()
|
.end()
|
||||||
.getJson();
|
.getJson();
|
||||||
|
|
||||||
// override v1 baseURI and basePath
|
// override v1 baseURI and basePath
|
||||||
RequestSpecification spec = new RequestSpecBuilder()
|
RequestSpecification spec = new RequestSpecBuilder()
|
||||||
.setBaseUri(client.getApiUrl())
|
.setBaseUri(client.getApiUrl())
|
||||||
.setBasePath("/")
|
.setBasePath("/")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// execute an "old-style" API call
|
// execute an "old-style" API call
|
||||||
Response response = given()
|
Response response = given()
|
||||||
.spec(spec)
|
.spec(spec)
|
||||||
.auth().basic(adminUser.getUsername(), adminUser.getPassword())
|
.auth().basic(adminUser.getUsername(), adminUser.getPassword())
|
||||||
.contentType(ContentType.JSON)
|
.contentType(ContentType.JSON)
|
||||||
.body(bodyJson.toString())
|
.body(bodyJson.toString())
|
||||||
.pathParam("nodeId", filePlanComponentId)
|
.pathParam("nodeId", filePlanComponentId)
|
||||||
.log().all()
|
.log().all()
|
||||||
.when()
|
.when()
|
||||||
.post("/node/workspace/SpacesStore/{nodeId}/rmpermissions")
|
.post("/node/workspace/SpacesStore/{nodeId}/rmpermissions")
|
||||||
.prettyPeek()
|
.prettyPeek()
|
||||||
.andReturn();
|
.andReturn();
|
||||||
getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
|
getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to add permission on a component to user
|
||||||
|
*
|
||||||
|
* @param filePlanComponentId The id of the file plan component on which permission should be given
|
||||||
|
* @param permission {@link UserPermissions} to be granted
|
||||||
|
*/
|
||||||
|
public void setUserPermissionInheritance(String filePlanComponentId, Boolean isInherited)
|
||||||
|
{
|
||||||
|
UserModel adminUser = getRmRestWrapper().getTestUser();
|
||||||
|
|
||||||
|
// get an "old-style" REST API client
|
||||||
|
AlfrescoHttpClient client = getAlfrescoHttpClient();
|
||||||
|
|
||||||
|
JsonObject bodyJson = buildObject()
|
||||||
|
.addArray("permissions")
|
||||||
|
.end()
|
||||||
|
.add("isInherited", isInherited)
|
||||||
|
.getJson();
|
||||||
|
|
||||||
|
// override v1 baseURI and basePath
|
||||||
|
RequestSpecification spec = new RequestSpecBuilder()
|
||||||
|
.setBaseUri(client.getApiUrl())
|
||||||
|
.setBasePath("/")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// execute an "old-style" API call
|
||||||
|
Response response = given()
|
||||||
|
.spec(spec)
|
||||||
|
.auth().basic(adminUser.getUsername(), adminUser.getPassword())
|
||||||
|
.contentType(ContentType.JSON)
|
||||||
|
.body(bodyJson.toString())
|
||||||
|
.pathParam("nodeId", filePlanComponentId)
|
||||||
|
.log().all()
|
||||||
|
.when()
|
||||||
|
.post("/node/workspace/SpacesStore/{nodeId}/rmpermissions")
|
||||||
|
.prettyPeek()
|
||||||
|
.andReturn();
|
||||||
|
getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a user with the given name using the old APIs
|
* Creates a user with the given name using the old APIs
|
||||||
*
|
*
|
||||||
|
@@ -48,6 +48,7 @@ import org.alfresco.dataprep.ContentService;
|
|||||||
import org.alfresco.dataprep.UserService;
|
import org.alfresco.dataprep.UserService;
|
||||||
import org.alfresco.rest.core.v0.BaseAPI;
|
import org.alfresco.rest.core.v0.BaseAPI;
|
||||||
import org.alfresco.rest.core.v0.RMEvents;
|
import org.alfresco.rest.core.v0.RMEvents;
|
||||||
|
import org.alfresco.utility.Utility;
|
||||||
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
@@ -73,6 +74,8 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
public class RMRolesAndActionsAPI extends BaseAPI
|
public class RMRolesAndActionsAPI extends BaseAPI
|
||||||
{
|
{
|
||||||
|
public static final String HOLDS_CONTAINER = "Holds";
|
||||||
|
|
||||||
/** The URI to view the configured roles and capabilities. */
|
/** The URI to view the configured roles and capabilities. */
|
||||||
private static final String RM_ROLES = "{0}rma/admin/rmroles";
|
private static final String RM_ROLES = "{0}rma/admin/rmroles";
|
||||||
/** The URI for REST requests about a particular configured role. */
|
/** The URI for REST requests about a particular configured role. */
|
||||||
@@ -83,6 +86,8 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RMRolesAndActionsAPI.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(RMRolesAndActionsAPI.class);
|
||||||
private static final String MOVE_ACTIONS_API = "action/rm-move-to/site/rm/documentLibrary/{0}";
|
private static final String MOVE_ACTIONS_API = "action/rm-move-to/site/rm/documentLibrary/{0}";
|
||||||
private static final String CREATE_HOLDS_API = "{0}type/rma:hold/formprocessor";
|
private static final String CREATE_HOLDS_API = "{0}type/rma:hold/formprocessor";
|
||||||
|
/** The URI to add items to hold.*/
|
||||||
|
private static final String RM_HOLDS_API = "{0}rma/holds";
|
||||||
|
|
||||||
/** http client factory */
|
/** http client factory */
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -447,9 +452,9 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
public HttpResponse createHold(String user, String password, String holdName, String reason, String description)
|
public HttpResponse createHold(String user, String password, String holdName, String reason, String description)
|
||||||
{
|
{
|
||||||
// if the hold already exists don't try to create it again
|
// if the hold already exists don't try to create it again
|
||||||
String holdsContainerPath = getFilePlanPath() + "/Holds";
|
final String holdsContainerPath = Utility.buildPath(getFilePlanPath(), HOLDS_CONTAINER);
|
||||||
String fullHoldPath = holdsContainerPath + "/" + holdName;
|
final String fullHoldPath = holdsContainerPath + holdName;
|
||||||
CmisObject hold = getObjectByPath(user, password, fullHoldPath);
|
final CmisObject hold = getObjectByPath(user, password, fullHoldPath);
|
||||||
if (hold != null)
|
if (hold != null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -457,19 +462,41 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
// retrieve the Holds container nodeRef
|
// retrieve the Holds container nodeRef
|
||||||
String parentNodeRef = getItemNodeRef(user, password, "/Holds");
|
String parentNodeRef = getItemNodeRef(user, password, "/Holds");
|
||||||
|
|
||||||
JSONObject requestParams = new JSONObject();
|
final JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef);
|
requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef);
|
||||||
requestParams.put("prop_cm_name", holdName);
|
requestParams.put("prop_cm_name", holdName);
|
||||||
requestParams.put("prop_cm_description", description);
|
requestParams.put("prop_cm_description", description);
|
||||||
requestParams.put("prop_rma_holdReason", reason);
|
requestParams.put("prop_rma_holdReason", reason);
|
||||||
|
|
||||||
// Make the POST request and throw an assertion error if it fails.
|
// Make the POST request and throw an assertion error if it fails.
|
||||||
HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API);
|
final HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API);
|
||||||
assertNotNull("Expected object to have been created at " + fullHoldPath,
|
assertNotNull("Expected object to have been created at " + fullHoldPath,
|
||||||
getObjectByPath(user, password, fullHoldPath));
|
getObjectByPath(user, password, fullHoldPath));
|
||||||
return httpResponse;
|
return httpResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds item (record/ record folder) to the hold
|
||||||
|
*
|
||||||
|
* @param user the user who adds the item to the hold
|
||||||
|
* @param password the user's password
|
||||||
|
* @param itemNodeRef the nodeRef of the item to be added to hold
|
||||||
|
* @param holdName the hold name
|
||||||
|
* @return The HTTP response
|
||||||
|
*/
|
||||||
|
public HttpResponse addItemToHold(String user, String password, String itemNodeRef, String holdName)
|
||||||
|
{
|
||||||
|
final JSONArray nodeRefs = new JSONArray().put(getNodeRefSpacesStore() + itemNodeRef);
|
||||||
|
final String holdNodeRef = getItemNodeRef(user, password, String.format("/%s/%s", HOLDS_CONTAINER, holdName));
|
||||||
|
final JSONArray holds = new JSONArray().put(getNodeRefSpacesStore() + holdNodeRef);
|
||||||
|
final JSONObject requestParams = new JSONObject();
|
||||||
|
requestParams.put("nodeRefs", nodeRefs);
|
||||||
|
requestParams.put("holds", holds);
|
||||||
|
|
||||||
|
return doPostJsonRequest(user, password, SC_OK, requestParams, RM_HOLDS_API);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates metadata, can be used on records, folders and categories
|
* Updates metadata, can be used on records, folders and categories
|
||||||
*
|
*
|
||||||
|
@@ -0,0 +1,7 @@
|
|||||||
|
log4j.rootLogger=info, console
|
||||||
|
|
||||||
|
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
||||||
|
|
||||||
|
log4j.logger.com.example=debug
|
Reference in New Issue
Block a user