diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RMRestWrapper.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RMRestWrapper.java index d4830e6910..1f978dbba4 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RMRestWrapper.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RMRestWrapper.java @@ -26,10 +26,15 @@ */ package org.alfresco.rest.core; +import org.alfresco.rest.exception.EmptyJsonResponseException; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.rest.model.RestSiteModelsCollection; +import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection; import org.alfresco.rest.rm.community.requests.igCoreAPI.RestIGCoreAPI; +import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Scope; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; /** @@ -38,11 +43,13 @@ import org.springframework.stereotype.Service; * @author Tuna Aksoy * @since 2.6 */ -@Primary @Service @Scope(value = "prototype") -public class RMRestWrapper extends RestWrapper +public class RMRestWrapper { + /** The class that wraps the ReST APIs from core. */ + @Autowired + private RestWrapper restWrapper; @Autowired private RMRestProperties rmRestProperties; @@ -51,12 +58,25 @@ public class RMRestWrapper extends RestWrapper return new RestIGCoreAPI(this, rmRestProperties); } - @Override - public T processModel(Class classz, RestRequest restRequest) + /** Get the core class that wraps the ReST APIs. */ + public RestWrapper getRestWrapper() + { + return restWrapper; + } + + /** Authenticate specific user to Alfresco REST API */ + public void authenticateUser(UserModel userModel) + { + restWrapper.authenticateUser(userModel); + } + + /** Process responses for a collection of models as {@link RestSiteModelsCollection}. */ + public FilePlanComponentsCollection processModels(Class classz, + RestRequest simpleRequest) { try { - return super.processModel(classz, restRequest); + return restWrapper.processModels(classz, simpleRequest); } catch (Exception e) { @@ -65,4 +85,64 @@ public class RMRestWrapper extends RestWrapper throw new RuntimeException(e); } } + + /** Process responses for a single model as {@link RestSiteModel}. */ + public T processModel(Class classz, RestRequest restRequest) + { + try + { + return restWrapper.processModel(classz, restRequest); + } + catch (Exception e) + { + // TODO Hopefully remove this check when TAS stops using checked exceptions. + // See https://gitlab.alfresco.com/tas/alfresco-tas-restapi-test/merge_requests/392 + throw new RuntimeException(e); + } + } + + /** Process a response that has no body - basically will need only the status code from it. */ + public void processEmptyModel(RestRequest simpleRequest) + { + try + { + restWrapper.processEmptyModel(simpleRequest); + } + catch (EmptyJsonResponseException e) + { + // TODO Hopefully remove this check when TAS stops using checked exceptions. + // See https://gitlab.alfresco.com/tas/alfresco-tas-restapi-test/merge_requests/392 + throw new RuntimeException(e); + } + } + + /** Get the most recently returned status code. */ + public String getStatusCode() + { + return restWrapper.getStatusCode(); + } + + /** Set the status code. This should only be needed when calling APIs without using the TAS framework. */ + public void setStatusCode(String statusCode) + { + restWrapper.setStatusCode(statusCode); + } + + /** Assert that a specific status code is returned. */ + public void assertStatusCodeIs(HttpStatus statusCode) + { + restWrapper.assertStatusCodeIs(statusCode); + } + + /** @return A parameters string that you could pass on the request ?param=value */ + public String getParameters() + { + return restWrapper.getParameters(); + } + + /** Create a {@link UserModel} for a new test user. */ + public UserModel getTestUser() + { + return restWrapper.getTestUser(); + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RMModelRequest.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RMModelRequest.java index 5f05822e3e..ea3ef56ab5 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RMModelRequest.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RMModelRequest.java @@ -52,7 +52,7 @@ public abstract class RMModelRequest extends ModelRequest */ public RMModelRequest(RMRestWrapper rmRestWrapper) { - super(rmRestWrapper); + super(rmRestWrapper.getRestWrapper()); this.rmRestWrapper = rmRestWrapper; } }