From f62ad8768a5a9bf995d5ae8b9e37d21035677240 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Fri, 20 Jan 2017 16:50:25 +0000 Subject: [PATCH 1/6] RM-4159 Getting enterprise UI tests to run. There's still currently an issue because we have two @Autowired @Primary beans of the same type. --- .../rm-automation-community-rest-api/pom.xml | 11 +++++++++++ .../org/alfresco/rest/core/RMRestWrapper.java | 15 +++++++++++++++ .../org/alfresco/rest/core/RestAPIFactory.java | 6 ++++-- .../requests/igCoreAPI/FilePlanComponentAPI.java | 1 - .../rm/community/requests/igCoreAPI/FilesAPI.java | 4 ++-- .../community/requests/igCoreAPI/RecordsAPI.java | 1 - .../rest/rm/community/util/PojoUtility.java | 4 +--- 7 files changed, 33 insertions(+), 9 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index 3a53363b14..5da82a250c 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -30,6 +30,17 @@ ${project.parent.parent.basedir}/license/description.ftl + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + 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 706efef8d7..d4830e6910 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 @@ -50,4 +50,19 @@ public class RMRestWrapper extends RestWrapper { return new RestIGCoreAPI(this, rmRestProperties); } + + @Override + public T processModel(Class classz, RestRequest restRequest) + { + try + { + return super.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); + } + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java index d2edca7279..bcbb97e875 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java @@ -26,6 +26,8 @@ */ package org.alfresco.rest.core; +import javax.annotation.Resource; + import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilesAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI; @@ -50,7 +52,7 @@ public class RestAPIFactory @Autowired private DataUser dataUser; - @Autowired + @Resource(name = "RMRestWrapper") private RMRestWrapper rmRestWrapper; /** @@ -96,7 +98,7 @@ public class RestAPIFactory { return getRestIGCoreAPI(userModel).usingRecords(); } - + public FilesAPI getFilesAPI() { return getRestIGCoreAPI(null).usingFiles(); diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java index cdd8530dc1..bfb00548ff 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java @@ -28,7 +28,6 @@ package org.alfresco.rest.rm.community.requests.igCoreAPI; import static com.jayway.restassured.RestAssured.basic; import static com.jayway.restassured.RestAssured.given; - import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.alfresco.rest.core.RestRequest.simpleRequest; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilesAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilesAPI.java index 83df47ab11..afa93ac2f8 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilesAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilesAPI.java @@ -65,7 +65,7 @@ public class FilesAPI extends RMModelRequest public FilePlanComponent declareAsRecord(String fileId, String parameters) throws Exception { mandatoryString("fileId", fileId); - + return getRMRestWrapper().processModel(FilePlanComponent.class, simpleRequest( POST, "/files/{fileId}/declare?{parameters}", @@ -73,7 +73,7 @@ public class FilesAPI extends RMModelRequest parameters )); } - + /** * A no-parameter version of {@link FilesAPI#declareAsRecord} * @param fileId The Id of a file to declare as record diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RecordsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RecordsAPI.java index efcaca97ef..2eab707885 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RecordsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RecordsAPI.java @@ -27,7 +27,6 @@ package org.alfresco.rest.rm.community.requests.igCoreAPI; import static com.jayway.restassured.RestAssured.given; - import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject; import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString; diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/PojoUtility.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/PojoUtility.java index 7653f8ffc0..3ca50bec8a 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/PojoUtility.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/PojoUtility.java @@ -30,7 +30,6 @@ import java.io.IOException; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -46,9 +45,8 @@ public class PojoUtility * Converting object to JSON string * * @param model The java object model to convert - * @throws JsonProcessingException Throws exceptions if the given object doesn't match to the POJO class model */ - public static String toJson(Object model) throws JsonProcessingException + public static String toJson(Object model) { ObjectMapper mapper = new ObjectMapper(); //include only values that differ from default settings to be included From c7aaa7b2e91d8937bea72faff8ab23577435b435 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 25 Jan 2017 11:07:11 +0000 Subject: [PATCH 2/6] RM-4159 Wrap the RestWrapper rather than extending it. Previously we were hitting an issue where there were three beans all of the type RestWrapper. This meant that Spring could not determine which bean should be used when autowiring. By wrapping the RestWrapper we ensure there is only one bean of that type, and so Spring knows which bean to use (in the TAS code). After some debate I decided against renaming the RMRestWrapper as RestWrapperWrapper. --- .../org/alfresco/rest/core/RMRestWrapper.java | 92 +++++++++++++++++-- .../rm/community/requests/RMModelRequest.java | 2 +- 2 files changed, 87 insertions(+), 7 deletions(-) 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; } } From 7a0a0954e973052f93469c55c40a20ca235e5810 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Mon, 30 Jan 2017 08:26:37 +0000 Subject: [PATCH 3/6] RM-4159 Create tests for paged get guides and delete guide. --- .../src/main/java/org/alfresco/rest/core/RMRestWrapper.java | 4 +--- .../alfresco/rest/rm/community/requests/RMModelRequest.java | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) 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 1f978dbba4..c59d078dc9 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 @@ -29,7 +29,6 @@ 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; @@ -71,8 +70,7 @@ public class RMRestWrapper } /** Process responses for a collection of models as {@link RestSiteModelsCollection}. */ - public FilePlanComponentsCollection processModels(Class classz, - RestRequest simpleRequest) + public T processModels(Class classz, RestRequest simpleRequest) { try { 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 ea3ef56ab5..f05854f61f 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 @@ -42,7 +42,7 @@ public abstract class RMModelRequest extends ModelRequest /** * @return the rmRestWrapper */ - protected RMRestWrapper getRMRestWrapper() + public RMRestWrapper getRMRestWrapper() { return this.rmRestWrapper; } From 5de74bc2d7195725864ae352700d97559e85c661 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 8 Mar 2017 08:12:30 +0000 Subject: [PATCH 4/6] RM-4159 Add wrapper method for assertLastError. --- .../main/java/org/alfresco/rest/core/RMRestWrapper.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 4296d9fda5..d955094c73 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 @@ -29,6 +29,7 @@ package org.alfresco.rest.core; import com.jayway.restassured.builder.RequestSpecBuilder; import org.alfresco.rest.exception.EmptyJsonResponseException; +import org.alfresco.rest.model.RestErrorModel; import org.alfresco.rest.model.RestHtmlResponse; import org.alfresco.rest.model.RestSiteModel; import org.alfresco.rest.model.RestSiteModelsCollection; @@ -73,6 +74,12 @@ public class RMRestWrapper restWrapper.authenticateUser(userModel); } + /** Get the last error thrown (if any). */ + public RestErrorModel assertLastError() + { + return restWrapper.assertLastError(); + } + /** Process responses for a collection of models as {@link RestSiteModelsCollection}. */ public T processModels(Class classz, RestRequest simpleRequest) { From 4d71d6d2b52d4dd000aaee32b3ec1a0b6b0cd4a8 Mon Sep 17 00:00:00 2001 From: Oana Nechiforescu Date: Wed, 8 Mar 2017 12:53:58 +0200 Subject: [PATCH 5/6] Some changes. --- .../org/alfresco/rest/rm/community/requests/RMModelRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9b9c3be208..bf0648a60c 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 @@ -48,7 +48,7 @@ public abstract class RMModelRequest extends ModelRequest } /** - * @param restWrapper + * @param rmRestWrapper */ public RMModelRequest(RMRestWrapper rmRestWrapper) { From fe45e852f55f1a9cd99919988be2e04f934944b5 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Mon, 13 Mar 2017 08:14:48 +0000 Subject: [PATCH 6/6] RM-4159 Ensure there's exactly one RMRestWrapper. Use @PostConstruct to fix the hierarchy after initialisation. --- .../java/org/alfresco/rest/core/RestAPIFactory.java | 5 +++++ .../rest/rm/community/base/BaseRMRestTest.java | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java index cec4bf63f1..41370c7a55 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java @@ -67,6 +67,11 @@ public class RestAPIFactory return this.rmRestWrapper; } + public void setRmRestWrapper(RMRestWrapper rmRestWrapper) + { + this.rmRestWrapper = rmRestWrapper; + } + private RestIGCoreAPI getRestIGCoreAPI(UserModel userModel) { getRmRestWrapper().authenticateUser(userModel != null ? userModel : dataUser.getAdminUser()); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java index ebef9ce32c..cb25fcd074 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java @@ -100,7 +100,7 @@ public class BaseRMRestTest extends RestTest */ protected void assertStatusCode(HttpStatus statusCode) { - getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(statusCode); + restAPIFactory.getRmRestWrapper().assertStatusCodeIs(statusCode); } /** @@ -145,7 +145,7 @@ public class BaseRMRestTest extends RestTest */ public void createRMSiteIfNotExists() throws Exception { - RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI(); + RMSiteAPI rmSiteAPI = restAPIFactory.getRMSiteAPI(); // Check RM site doesn't exist if (!rmSiteAPI.existsRMSite()) @@ -294,16 +294,16 @@ public class BaseRMRestTest extends RestTest assertTrue(aspects.contains(RECORD_TYPE)); // a record mustn't be closed assertFalse(aspects.contains(ASPECTS_CLOSED_RECORD)); - + // add closed record aspect aspects.add(ASPECTS_CLOSED_RECORD); - - FilePlanComponent updatedComponent = filePlanComponentsAPI.updateFilePlanComponent(FilePlanComponent.builder().aspectNames(aspects).build(), + + FilePlanComponent updatedComponent = filePlanComponentsAPI.updateFilePlanComponent(FilePlanComponent.builder().aspectNames(aspects).build(), recordToClose.getId()); assertStatusCode(OK); return updatedComponent; } - + /** * Helper method to create a randomly-named / structure in file plan *