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:
Rodica Sutu
2019-07-02 10:29:21 +03:00
parent 9314432beb
commit 11a638c827
3 changed files with 116 additions and 39 deletions

View File

@@ -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
@@ -117,7 +118,8 @@ public class RMUserAPI extends RMModelRequest
/** /**
* 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 filePlanComponentId 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 user {@link UserModel} for a user to be granted permission
* @param permission {@link UserPermissions} to be granted * @param permission {@link UserPermissions} to be granted
*/ */
@@ -131,7 +133,7 @@ public class RMUserAPI extends RMModelRequest
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();
@@ -157,6 +159,47 @@ public class RMUserAPI extends RMModelRequest
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
* *

View File

@@ -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
* *

View File

@@ -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