Merge branch 'feature/RM-4159_EnterpriseReSTTests' into 'master'

feature/RM-4159_EnterpriseReSTTests

See merge request !29
This commit is contained in:
Tom Page
2017-03-13 16:21:00 +00:00
9 changed files with 176 additions and 42 deletions

View File

@@ -30,6 +30,17 @@
<descriptionTemplate>${project.parent.parent.basedir}/license/description.ftl</descriptionTemplate> <descriptionTemplate>${project.parent.parent.basedir}/license/description.ftl</descriptionTemplate>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@@ -26,10 +26,19 @@
*/ */
package org.alfresco.rest.core; 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;
import org.alfresco.rest.requests.coreAPI.RestCoreAPI;
import org.alfresco.rest.rm.community.requests.igCoreAPI.RestIGCoreAPI; 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.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@@ -38,11 +47,13 @@ import org.springframework.stereotype.Service;
* @author Tuna Aksoy * @author Tuna Aksoy
* @since 2.6 * @since 2.6
*/ */
@Primary
@Service @Service
@Scope(value = "prototype") @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 @Autowired
private RMRestProperties rmRestProperties; private RMRestProperties rmRestProperties;
@@ -51,6 +62,131 @@ public class RMRestWrapper extends RestWrapper
return new RestIGCoreAPI(this, rmRestProperties); return new RestIGCoreAPI(this, rmRestProperties);
} }
/** 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);
}
/** 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> T processModels(Class<T> classz, RestRequest simpleRequest)
{
try
{
return restWrapper.processModels(classz, simpleRequest);
}
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 responses for a single model as {@link RestSiteModel}. */
public <T> T processModel(Class<T> 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();
}
/** Get the Alfresco Core API. */
public RestCoreAPI withCoreAPI()
{
return restWrapper.withCoreAPI();
}
/**
* You can handle the request sent to server by calling this method.
* If for example you want to sent multipart form data you can use: <pre>
* restClient.configureRequestSpec()
* .addMultiPart("filedata", Utility.getResourceTestDataFile("restapi-resource"))
* .addFormParam("renditions", "doclib")
* .addFormParam("autoRename", true);
*
* restClient.withCoreAPI().usingNode(ContentModel.my()).createNode();
* </pre> This will create the node using the multipart data defined.
*/
public RequestSpecBuilder configureRequestSpec()
{
return restWrapper.configureRequestSpec();
}
/**
* Process a response that returns a html
*
* @throws EmptyJsonResponseException If there is no response from the server.
*/
public RestHtmlResponse processHtmlResponse(RestRequest simpleRequest)
{
return restWrapper.processHtmlResponse(simpleRequest);
}
/** /**
* @return the rmRestProperties * @return the rmRestProperties
*/ */

View File

@@ -26,6 +26,8 @@
*/ */
package org.alfresco.rest.core; package org.alfresco.rest.core;
import javax.annotation.Resource;
import org.alfresco.rest.requests.Node; import org.alfresco.rest.requests.Node;
import org.alfresco.rest.requests.coreAPI.RestCoreAPI; import org.alfresco.rest.requests.coreAPI.RestCoreAPI;
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
@@ -54,7 +56,7 @@ public class RestAPIFactory
@Autowired @Autowired
private DataUser dataUser; private DataUser dataUser;
@Autowired @Resource(name = "RMRestWrapper")
private RMRestWrapper rmRestWrapper; private RMRestWrapper rmRestWrapper;
/** /**
@@ -65,6 +67,11 @@ public class RestAPIFactory
return this.rmRestWrapper; return this.rmRestWrapper;
} }
public void setRmRestWrapper(RMRestWrapper rmRestWrapper)
{
this.rmRestWrapper = rmRestWrapper;
}
private RestIGCoreAPI getRestIGCoreAPI(UserModel userModel) private RestIGCoreAPI getRestIGCoreAPI(UserModel userModel)
{ {
getRmRestWrapper().authenticateUser(userModel != null ? userModel : dataUser.getAdminUser()); getRmRestWrapper().authenticateUser(userModel != null ? userModel : dataUser.getAdminUser());

View File

@@ -42,17 +42,17 @@ public abstract class RMModelRequest extends ModelRequest<RMModelRequest>
/** /**
* @return the rmRestWrapper * @return the rmRestWrapper
*/ */
protected RMRestWrapper getRMRestWrapper() public RMRestWrapper getRMRestWrapper()
{ {
return this.rmRestWrapper; return this.rmRestWrapper;
} }
/** /**
* @param restWrapper * @param rmRestWrapper
*/ */
public RMModelRequest(RMRestWrapper rmRestWrapper) public RMModelRequest(RMRestWrapper rmRestWrapper)
{ {
super(rmRestWrapper); super(rmRestWrapper.getRestWrapper());
this.rmRestWrapper = rmRestWrapper; this.rmRestWrapper = rmRestWrapper;
} }
} }

View File

@@ -26,6 +26,8 @@
*/ */
package org.alfresco.rest.rm.community.requests.igCoreAPI; 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.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest; import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;

View File

@@ -26,6 +26,7 @@
*/ */
package org.alfresco.rest.rm.community.requests.igCoreAPI; 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.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest; import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject; import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject;

View File

@@ -26,12 +26,8 @@
*/ */
package org.alfresco.rest.rm.community.util; package org.alfresco.rest.rm.community.util;
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
@@ -48,9 +44,8 @@ public class PojoUtility
* Converting object to JSON string * Converting object to JSON string
* *
* @param model The java object model to convert * @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(); ObjectMapper mapper = new ObjectMapper();
//include only values that differ from default settings to be included //include only values that differ from default settings to be included
@@ -60,15 +55,7 @@ public class PojoUtility
//return the json object //return the json object
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model);
} }
catch (JsonGenerationException e) catch (JsonProcessingException e)
{
return e.toString();
}
catch (JsonMappingException e)
{
return e.toString();
}
catch (IOException e)
{ {
return e.toString(); return e.toString();
} }
@@ -81,7 +68,7 @@ public class PojoUtility
* @param model The java object model to convert * @param model The java object model to convert
* @throws JsonProcessingException Throws exceptions if the given object doesn't match to the POJO class model * @throws JsonProcessingException Throws exceptions if the given object doesn't match to the POJO class model
*/ */
public static String toJsonElectronicRecord(Object model) throws JsonProcessingException public static String toJsonElectronicRecord(Object model)
{ {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
@@ -93,20 +80,10 @@ public class PojoUtility
mapper.setSerializationInclusion(Include.NON_DEFAULT); mapper.setSerializationInclusion(Include.NON_DEFAULT);
try try
{ {
//return the json object //return the json object
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model);
} }
catch (JsonGenerationException e) catch (JsonProcessingException e)
{
return e.toString();
}
catch (JsonMappingException e)
{
return e.toString();
}
catch (IOException e)
{ {
return e.toString(); return e.toString();
} }

View File

@@ -100,7 +100,7 @@ public class BaseRMRestTest extends RestTest
*/ */
protected void assertStatusCode(HttpStatus statusCode) 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 public void createRMSiteIfNotExists() throws Exception
{ {
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI(); RMSiteAPI rmSiteAPI = restAPIFactory.getRMSiteAPI();
// Check RM site doesn't exist // Check RM site doesn't exist
if (!rmSiteAPI.existsRMSite()) if (!rmSiteAPI.existsRMSite())