mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-10 14:11:58 +00:00
Compare commits
13 Commits
tas-restap
...
tas-restap
Author | SHA1 | Date | |
---|---|---|---|
|
4629c20b51 | ||
|
ee88946b1c | ||
|
b1faf15806 | ||
|
367ad20fb7 | ||
|
80e770f2da | ||
|
e8cf525792 | ||
|
a594341bb5 | ||
|
058e8d6302 | ||
|
91fcbb0b59 | ||
|
830898c605 | ||
|
d214040bc8 | ||
|
1b071cb555 | ||
|
37e04ee2fc |
@@ -4,7 +4,7 @@
|
||||
<groupId>org.alfresco.tas</groupId>
|
||||
<artifactId>restapi</artifactId>
|
||||
<name>alfresco-tas-restapi</name>
|
||||
<version>1.107</version>
|
||||
<version>1.111</version>
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-super-pom</artifactId>
|
||||
@@ -67,7 +67,7 @@
|
||||
<connection>scm:git:https://github.com/Alfresco/alfresco-tas-restapi.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/Alfresco/alfresco-tas-restapi.git</developerConnection>
|
||||
<url>https://github.com/Alfresco/alfresco-tas-restapi</url>
|
||||
<tag>v1.107</tag>
|
||||
<tag>v1.111</tag>
|
||||
</scm>
|
||||
|
||||
<issueManagement>
|
||||
|
@@ -27,16 +27,21 @@ package org.alfresco.rest.core;
|
||||
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import java.util.MissingFormatArgumentException;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
/**
|
||||
* @author Paul Brodner
|
||||
*/
|
||||
public class RestRequest
|
||||
{
|
||||
private String body = "";
|
||||
private static final String TOKEN_REGEX = "\\{.*?}";
|
||||
private String body;
|
||||
private HttpMethod httpMethod;
|
||||
private String path;
|
||||
private Object[] pathParams;
|
||||
@@ -44,10 +49,7 @@ public class RestRequest
|
||||
|
||||
private RestRequest(HttpMethod httpMethod, String path, String... pathParams)
|
||||
{
|
||||
setHttpMethod(httpMethod);
|
||||
setPath(path);
|
||||
setPathParams(pathParams);
|
||||
STEP(toString());
|
||||
this(httpMethod, "", path, pathParams);
|
||||
}
|
||||
|
||||
private RestRequest(HttpMethod httpMethod, String body, String path, String... pathParams)
|
||||
@@ -56,7 +58,8 @@ public class RestRequest
|
||||
setPath(path);
|
||||
setPathParams(pathParams);
|
||||
setBody(body);
|
||||
STEP(toString());
|
||||
// Validate that the supplied path and pathParams are compatible.
|
||||
constructPath();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,6 +117,7 @@ public class RestRequest
|
||||
public void setPath(String path)
|
||||
{
|
||||
this.path = path;
|
||||
addQueryParamsIfNeeded();
|
||||
}
|
||||
|
||||
public Object[] getPathParams()
|
||||
@@ -124,6 +128,32 @@ public class RestRequest
|
||||
public void setPathParams(Object[] pathParams)
|
||||
{
|
||||
this.pathParams = pathParams;
|
||||
addQueryParamsIfNeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add query parameters to the path if needed.
|
||||
* <p>
|
||||
* e.g. For a path of "api/{fruit}" and params ["apple", "size=10", "colour=red"] then this will
|
||||
* update the path to be "api/{fruit}?{param0}&{param1}" so that the tokens will be populated by
|
||||
* RestAssured to make "api/apple?size=10&colour=red".
|
||||
*/
|
||||
private void addQueryParamsIfNeeded()
|
||||
{
|
||||
// Don't do anything if the path or path params haven't been set yet.
|
||||
if (path == null || path.length() == 0 || pathParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int groupCount = (int) Pattern.compile(TOKEN_REGEX).matcher(path).results().count();
|
||||
if (pathParams.length > groupCount)
|
||||
{
|
||||
// Add the remaining parameters to the URL query.
|
||||
String queryParams = IntStream.range(0, pathParams.length - groupCount)
|
||||
.mapToObj(index -> "{parameter" + index + "}")
|
||||
.collect(Collectors.joining("&"));
|
||||
path += (path.contains("?") ? "&" : "?") + queryParams;
|
||||
}
|
||||
}
|
||||
|
||||
public String getContentType()
|
||||
@@ -136,6 +166,10 @@ public class RestRequest
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @throws MissingFormatArgumentException If there are not enough pathParams for the path.
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@@ -144,19 +178,13 @@ public class RestRequest
|
||||
.append(getHttpMethod())
|
||||
.append(" ")
|
||||
.append(RestAssured.baseURI)
|
||||
.append(":")
|
||||
.append("://")
|
||||
.append(RestAssured.port)
|
||||
.append("/")
|
||||
.append(RestAssured.basePath)
|
||||
.append("/");
|
||||
|
||||
String getPathFormatted = getPath();
|
||||
if(getPath().contains("{"))
|
||||
{
|
||||
getPathFormatted = getPath().replaceAll("\\{.*?}", "%s");
|
||||
getPathFormatted = String.format(getPathFormatted, getPathParams());
|
||||
}
|
||||
sb.append(getPathFormatted);
|
||||
|
||||
sb.append(constructPath());
|
||||
|
||||
if(!getBody().isEmpty())
|
||||
{
|
||||
@@ -168,4 +196,21 @@ public class RestRequest
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the path with the pathParams.
|
||||
*
|
||||
* @return The path with tokens replaced with values.
|
||||
* @throws MissingFormatArgumentException If there are not enough pathParams for the path.
|
||||
*/
|
||||
private String constructPath()
|
||||
{
|
||||
String getPathFormatted = getPath();
|
||||
if(getPath().contains("{"))
|
||||
{
|
||||
getPathFormatted = getPath().replaceAll(TOKEN_REGEX, "%s");
|
||||
getPathFormatted = String.format(getPathFormatted, getPathParams());
|
||||
}
|
||||
return getPathFormatted;
|
||||
}
|
||||
}
|
||||
|
@@ -77,6 +77,7 @@ import org.alfresco.utility.dsl.DSLWrapper;
|
||||
import org.alfresco.utility.model.StatusModel;
|
||||
import org.alfresco.utility.model.TestModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.apache.xml.serialize.OutputFormat;
|
||||
@@ -620,7 +621,16 @@ public class RestWrapper extends DSLWrapper<RestWrapper>
|
||||
*/
|
||||
protected Response sendRequest(RestRequest restRequest)
|
||||
{
|
||||
Response returnedResponse = null;
|
||||
// If there are unused parameters then include them in the request.
|
||||
String parameters = getParameters();
|
||||
if (parameters != null && !parameters.isEmpty())
|
||||
{
|
||||
restRequest.setPathParams(ArrayUtils.addAll(restRequest.getPathParams(), parameters));
|
||||
}
|
||||
|
||||
STEP(restRequest.toString());
|
||||
|
||||
Response returnedResponse;
|
||||
switch (restRequest.getHttpMethod())
|
||||
{
|
||||
case GET:
|
||||
@@ -629,7 +639,6 @@ public class RestWrapper extends DSLWrapper<RestWrapper>
|
||||
case DELETE:
|
||||
returnedResponse = onRequest().delete(restRequest.getPath(), restRequest.getPathParams()).andReturn();
|
||||
break;
|
||||
|
||||
case HEAD:
|
||||
returnedResponse = onRequest().head(restRequest.getPath(), restRequest.getPathParams()).andReturn();
|
||||
break;
|
||||
@@ -867,6 +876,8 @@ public class RestWrapper extends DSLWrapper<RestWrapper>
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and clear the stored parameters.
|
||||
*
|
||||
* @return parameters that you could pass on the request ?param=value
|
||||
*/
|
||||
public String getParameters()
|
||||
|
@@ -33,14 +33,16 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import io.restassured.path.json.JsonPath;
|
||||
import org.alfresco.utility.exception.TestConfigurationException;
|
||||
import org.alfresco.utility.model.TestModel;
|
||||
import org.testng.Assert;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.restassured.path.json.JsonPath;
|
||||
|
||||
/**
|
||||
* Assertion on Rest Model
|
||||
* Just pass your rest model as constructor
|
||||
@@ -57,7 +59,7 @@ public class ModelAssertion<T>
|
||||
Assert.fail(String.format("Field {%s} was not found in returned response.",fieldNameToBeRetuned));
|
||||
}
|
||||
}
|
||||
private Object model;
|
||||
private final Object model;
|
||||
|
||||
public ModelAssertion(Object model)
|
||||
{
|
||||
@@ -66,10 +68,11 @@ public class ModelAssertion<T>
|
||||
|
||||
/**
|
||||
* Use this DSL for asserting particular fields of your model if your model
|
||||
* is like this (basic POJO) public class Person extends
|
||||
* ModelAssertion<Person> { private String id = "1234"; you can use assert
|
||||
* the id of this person as:
|
||||
* Person p = new Person(); p.assertField("id").is("1234")
|
||||
* is like this (basic POJO)
|
||||
* public class Person extends ModelAssertion<Person>
|
||||
* { private String id = "1234"; }
|
||||
* you can use assert the id of this person as:
|
||||
* Person p = new Person(); p.assertThat().field("id").is("1234")
|
||||
*
|
||||
* @param fieldName
|
||||
* @return
|
||||
@@ -120,6 +123,24 @@ public class ModelAssertion<T>
|
||||
return new AssertionItemVerbs(model, actualSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method for asserting whole model with different model object. Method allows to ignore particular fields during the comparison.
|
||||
*
|
||||
* WARNING: For proper work model should implement {@code toString()} and {@code equals()} methods.
|
||||
*
|
||||
* @param expected - expected model.
|
||||
* @param ignoreFields - fields which should be ignored during assertion.
|
||||
* @return model.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T isEqualTo(T expected, String... ignoreFields)
|
||||
{
|
||||
T modelCopy = createCopyIgnoringFields((T) model, ignoreFields);
|
||||
T expectedCopy = createCopyIgnoringFields(expected, ignoreFields);
|
||||
Assert.assertEquals(modelCopy, expectedCopy, String.format("Compared objects of type: %s are not equal!", model.getClass()));
|
||||
return (T) model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all fields declared from all classes hierarchy
|
||||
*
|
||||
@@ -144,6 +165,18 @@ public class ModelAssertion<T>
|
||||
return fields;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private T createCopyIgnoringFields(T model, String... ignoreFields)
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
JsonObject jsonObject = gson.fromJson(gson.toJson(model), JsonObject.class);
|
||||
for (String ignoreField : ignoreFields)
|
||||
{
|
||||
jsonObject.remove(ignoreField);
|
||||
}
|
||||
return gson.fromJson(gson.toJson(jsonObject), (Class<? extends T>) model.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* DSL assertion on Rest Model fields
|
||||
*
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.alfresco.rest.core.IRestModel;
|
||||
import org.alfresco.rest.core.assertion.ModelAssertion;
|
||||
@@ -85,6 +85,29 @@ public class RestActionBodyExecTemplateModel extends TestModel implements IRestM
|
||||
public void setParams(Object params)
|
||||
{
|
||||
this.params = params;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "RestActionBodyExecTemplateModel{" + "actionDefinitionId='" + actionDefinitionId + '\'' + ", params=" + params + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
RestActionBodyExecTemplateModel that = (RestActionBodyExecTemplateModel) o;
|
||||
return Objects.equals(actionDefinitionId, that.actionDefinitionId) && Objects.equals(params, that.params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(actionDefinitionId, params);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.alfresco.rest.core.IRestModel;
|
||||
import org.alfresco.rest.core.assertion.ModelAssertion;
|
||||
@@ -120,6 +121,31 @@ public class RestCompositeConditionDefinitionModel extends TestModel implements
|
||||
public void setSimpleConditions(List<RestSimpleConditionDefinitionModel> simpleConditions)
|
||||
{
|
||||
this.simpleConditions = simpleConditions;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "RestCompositeConditionDefinitionModel{" + "inverted=" + inverted + ", booleanMode='" + booleanMode + '\'' + ", compositeConditions=" + compositeConditions
|
||||
+ ", simpleConditions=" + simpleConditions + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
RestCompositeConditionDefinitionModel that = (RestCompositeConditionDefinitionModel) o;
|
||||
return inverted == that.inverted && Objects.equals(booleanMode, that.booleanMode) && Objects.equals(compositeConditions, that.compositeConditions) && Objects.equals(
|
||||
simpleConditions, that.simpleConditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(inverted, booleanMode, compositeConditions, simpleConditions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.alfresco.rest.core.IRestModel;
|
||||
import org.alfresco.rest.core.assertion.ModelAssertion;
|
||||
@@ -98,12 +99,10 @@ public class RestRuleModel extends TestModel implements IRestModel<RestRuleModel
|
||||
*/
|
||||
|
||||
private String errorScript;
|
||||
/**
|
||||
Whether the rule has been shared with more than one folder
|
||||
*/
|
||||
/** True if the rule set is linked to, or if the rule is inheritable and the rule set is inherited by a folder with inheriting enabled. */
|
||||
@JsonProperty
|
||||
private Boolean isShared;
|
||||
|
||||
@JsonProperty(required = true)
|
||||
private boolean shared;
|
||||
/**
|
||||
The set of triggers that cause the rule to be activated.
|
||||
* inbound - The rule should be activated when an item enters the folder
|
||||
@@ -200,14 +199,14 @@ If the field is omitted then the rule will apply to all nodes.
|
||||
this.errorScript = errorScript;
|
||||
}
|
||||
|
||||
public boolean getShared()
|
||||
public Boolean getIsShared()
|
||||
{
|
||||
return this.shared;
|
||||
return this.isShared;
|
||||
}
|
||||
|
||||
public void setShared(boolean shared)
|
||||
public void setIsShared(Boolean shared)
|
||||
{
|
||||
this.shared = shared;
|
||||
this.isShared = shared;
|
||||
}
|
||||
|
||||
public List<String> getTriggers()
|
||||
@@ -238,6 +237,33 @@ If the field is omitted then the rule will apply to all nodes.
|
||||
public void setActions(List<RestActionBodyExecTemplateModel> actions)
|
||||
{
|
||||
this.actions = actions;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "RestRuleModel{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", description='" + description + '\'' + ", enabled=" + enabled + ", cascade=" + cascade
|
||||
+ ", asynchronous=" + asynchronous + ", errorScript='" + errorScript + '\'' + ", isShared=" + isShared + ", triggers=" + triggers + ", conditions=" + conditions
|
||||
+ ", actions=" + actions + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
RestRuleModel ruleModel = (RestRuleModel) o;
|
||||
return enabled == ruleModel.enabled && cascade == ruleModel.cascade && asynchronous == ruleModel.asynchronous && Objects.equals(id, ruleModel.id) && name.equals(
|
||||
ruleModel.name) && Objects.equals(description, ruleModel.description) && Objects.equals(errorScript, ruleModel.errorScript) && Objects.equals(
|
||||
isShared, ruleModel.isShared) && Objects.equals(triggers, ruleModel.triggers) && Objects.equals(conditions, ruleModel.conditions) && actions.equals(ruleModel.actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(id, name, description, enabled, cascade, asynchronous, errorScript, isShared, triggers, conditions, actions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.alfresco.rest.core.IRestModel;
|
||||
import org.alfresco.rest.core.assertion.ModelAssertion;
|
||||
@@ -128,6 +128,29 @@ Where a property is multivalued then the condition is true if it is satisfied by
|
||||
public void setParameter(String parameter)
|
||||
{
|
||||
this.parameter = parameter;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "RestSimpleConditionDefinitionModel{" + "field='" + field + '\'' + ", comparator='" + comparator + '\'' + ", parameter='" + parameter + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
RestSimpleConditionDefinitionModel that = (RestSimpleConditionDefinitionModel) o;
|
||||
return Objects.equals(field, that.field) && Objects.equals(comparator, that.comparator) && Objects.equals(parameter, that.parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(field, comparator, parameter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1018,8 +1018,8 @@ public class Node extends ModelRequest<Node>
|
||||
*/
|
||||
public RestRuleSetModelsCollection getListOfRuleSets()
|
||||
{
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, RULE_SETS_URI + "?{parameters}",
|
||||
repoModel.getNodeRef(), restWrapper.getParameters());
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, RULE_SETS_URI,
|
||||
repoModel.getNodeRef());
|
||||
return restWrapper.processModels(RestRuleSetModelsCollection.class, request);
|
||||
}
|
||||
|
||||
@@ -1031,8 +1031,8 @@ public class Node extends ModelRequest<Node>
|
||||
*/
|
||||
public RestRuleSetModel getRuleSet(String ruleSetId)
|
||||
{
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, RULE_SET_BY_ID + "?{parameters}",
|
||||
repoModel.getNodeRef(), ruleSetId, restWrapper.getParameters());
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, RULE_SET_BY_ID,
|
||||
repoModel.getNodeRef(), ruleSetId);
|
||||
return restWrapper.processModel(RestRuleSetModel.class, request);
|
||||
}
|
||||
|
||||
@@ -1043,8 +1043,8 @@ public class Node extends ModelRequest<Node>
|
||||
*/
|
||||
public RestRuleSetModel getDefaultRuleSet()
|
||||
{
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, RULE_SET_BY_ID + "?{parameters}",
|
||||
repoModel.getNodeRef(), "-default-", restWrapper.getParameters());
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, RULE_SET_BY_ID,
|
||||
repoModel.getNodeRef(), "-default-");
|
||||
return restWrapper.processModel(RestRuleSetModel.class, request);
|
||||
}
|
||||
}
|
||||
|
@@ -54,7 +54,6 @@ public class Sync extends ModelRequest<RestPrivateAPI>
|
||||
RestSyncNodeSubscriptionModel subscription;
|
||||
String requestSyncURL = "subscribers/{deviceSubscriptionId}/subscriptions/{nodeSubscriptionId}/sync";
|
||||
String syncSetURL = requestSyncURL + "/{syncId}";
|
||||
String params = "?{parameters}";
|
||||
|
||||
public Sync(RestSyncNodeSubscriptionModel subscription, RestWrapper restWrapper)
|
||||
{
|
||||
@@ -82,7 +81,7 @@ public class Sync extends ModelRequest<RestPrivateAPI>
|
||||
|
||||
String postBody = JsonBodyGenerator.defineJSON().add("changes", array.build()).add("clientVersion", clientVersion).build().toString();
|
||||
|
||||
RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, requestSyncURL + params, this.subscriber, nodeSubscriptionModel.getId(),
|
||||
RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, requestSyncURL, this.subscriber, nodeSubscriptionModel.getId(),
|
||||
restWrapper.getParameters());
|
||||
|
||||
// This step is necessary for this request. Without it, empty json response is returned
|
||||
@@ -94,7 +93,7 @@ public class Sync extends ModelRequest<RestPrivateAPI>
|
||||
|
||||
public RestWrapper endSync(RestSyncNodeSubscriptionModel nodeSubscriptionModel, RestSyncSetRequestModel sync)
|
||||
{
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, syncSetURL + params, this.subscriber, nodeSubscriptionModel.getId(),
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, syncSetURL, this.subscriber, nodeSubscriptionModel.getId(),
|
||||
sync.getSyncId(), restWrapper.getParameters());
|
||||
|
||||
restWrapper.processEmptyModel(request);
|
||||
@@ -111,7 +110,7 @@ public class Sync extends ModelRequest<RestPrivateAPI>
|
||||
*/
|
||||
public RestSyncSetGetModel getSync(RestSyncNodeSubscriptionModel nodeSubscriptionModel, RestSyncSetRequestModel sync)
|
||||
{
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, syncSetURL + params, this.subscriber, nodeSubscriptionModel.getId(), sync.getSyncId(),
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, syncSetURL, this.subscriber, nodeSubscriptionModel.getId(), sync.getSyncId(),
|
||||
restWrapper.getParameters());
|
||||
|
||||
RestSyncSetGetModel model = restWrapper.processModelWithoutEntryObject(RestSyncSetGetModel.class, request);
|
||||
|
@@ -0,0 +1,129 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.core;
|
||||
|
||||
import static org.alfresco.rest.core.RestRequest.requestWithBody;
|
||||
import static org.alfresco.rest.core.RestRequest.simpleRequest;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.MissingFormatArgumentException;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/** Unit tests for {@link RestRequest}. */
|
||||
public class RestRequestTest
|
||||
{
|
||||
@Test
|
||||
public void testSimpleRequest_emptyPathAndParams()
|
||||
{
|
||||
RestRequest restRequest = simpleRequest(GET, "");
|
||||
|
||||
assertEquals(restRequest.getPath(), "", "Unexpected path");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleRequest_pathWithEqualParamsAndGroups()
|
||||
{
|
||||
RestRequest restRequest = simpleRequest(GET, "nodes/{nodeId}", "nodeId");
|
||||
|
||||
assertEquals(restRequest.getPath(), "nodes/{nodeId}", "Unexpected path");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleRequest_pathWithMoreParamsThanGroups()
|
||||
{
|
||||
RestRequest restRequest = simpleRequest(GET, "nodes/{nodeId}", "nodeId", "key1=value1", "key2=value2");
|
||||
|
||||
assertEquals(restRequest.getPath(), "nodes/{nodeId}?{parameter0}&{parameter1}", "Unexpected path");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = MissingFormatArgumentException.class)
|
||||
public void testSimpleRequest_pathWithFewerParamsThanGroups()
|
||||
{
|
||||
simpleRequest(GET, "nodes/{nodeId}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPath()
|
||||
{
|
||||
RestRequest restRequest = simpleRequest(GET, "nodes/{nodeId}", "nodeId");
|
||||
|
||||
restRequest.setPath("nodes");
|
||||
|
||||
assertEquals(restRequest.getPath(), "nodes?{parameter0}", "Unexpected path");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPathParams()
|
||||
{
|
||||
RestRequest restRequest = simpleRequest(GET, "nodes/{nodeId}", "nodeId");
|
||||
|
||||
Object[] pathParams = {"nodeId", "key=value"};
|
||||
restRequest.setPathParams(pathParams);
|
||||
|
||||
assertEquals(restRequest.getPath(), "nodes/{nodeId}?{parameter0}", "Unexpected path");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestWithBody_pathWithEqualParamsAndGroups()
|
||||
{
|
||||
RestRequest restRequest = requestWithBody(POST, "BODY", "nodes/{nodeId}", "nodeId");
|
||||
|
||||
assertEquals(restRequest.getPath(), "nodes/{nodeId}", "Unexpected path");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestWithBody_pathWithMoreParamsThanGroups()
|
||||
{
|
||||
RestRequest restRequest = requestWithBody(GET, "BODY", "nodes/{nodeId}", "nodeId", "key1=value1", "key2=value2");
|
||||
|
||||
assertEquals(restRequest.getPath(), "nodes/{nodeId}?{parameter0}&{parameter1}", "Unexpected path");
|
||||
}
|
||||
|
||||
@Test (expectedExceptions = MissingFormatArgumentException.class)
|
||||
public void testRequestWithBody_pathWithFewerParamsThanGroups()
|
||||
{
|
||||
requestWithBody(POST, "BODY", "nodes/{nodeId}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString()
|
||||
{
|
||||
RestAssured.baseURI = "BASE";
|
||||
RestAssured.port = 1234;
|
||||
RestAssured.basePath = "BASE_PATH";
|
||||
|
||||
RestRequest restRequest = requestWithBody(GET, "BODY", "nodes/{nodeId}", "nodeId", "key1=value1", "key2=value2");
|
||||
|
||||
String expected = "Request: GET BASE://1234/BASE_PATH/nodes/nodeId?key1=value1&key2=value2\nbody:BODY\n";
|
||||
assertEquals(restRequest.toString(), expected, "Unexpected toString representation");
|
||||
|
||||
RestAssured.reset();
|
||||
}
|
||||
}
|
@@ -25,32 +25,36 @@
|
||||
*/
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.alfresco.rest.core.IRestModel;
|
||||
import org.alfresco.rest.core.assertion.ModelAssertion;
|
||||
import org.alfresco.rest.model.RestPersonModel;
|
||||
import org.junit.Ignore;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.alfresco.rest.core.IRestModel;
|
||||
import org.alfresco.rest.core.assertion.ModelAssertion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class ModelAssertionTest {
|
||||
private static final String DEFAULT_ID = "1234";
|
||||
private static final String DEFAULT_NAME = "test";
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void iCanAssertExistingProperty() {
|
||||
Person p = new Person();
|
||||
Person p = new Person(DEFAULT_ID);
|
||||
p.assertThat().field("id").is("1234");
|
||||
}
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void iCanAssertExistingPropertyNegative() {
|
||||
Person p = new Person();
|
||||
Person p = new Person(DEFAULT_ID);
|
||||
p.assertThat().field("id").isNot("12342");
|
||||
RestPersonModel rp = new RestPersonModel();
|
||||
|
||||
@@ -66,7 +70,7 @@ public class ModelAssertionTest {
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void iCanTakeTheValueOfFieldsThatDoesntHaveGetters() {
|
||||
Person p = new Person();
|
||||
Person p = new Person(DEFAULT_ID, DEFAULT_NAME);
|
||||
|
||||
p.assertThat().field("name").is("test");
|
||||
|
||||
@@ -74,7 +78,7 @@ public class ModelAssertionTest {
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void iCanAssertStringIsEmpty() {
|
||||
Person p = new Person();
|
||||
Person p = new Person(DEFAULT_ID);
|
||||
|
||||
// Check no exception when field is empty.
|
||||
p.assertThat().field("nickname").isEmpty();
|
||||
@@ -89,7 +93,7 @@ public class ModelAssertionTest {
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void iCanAssertStringIsNotEmpty() {
|
||||
Person p = new Person();
|
||||
Person p = new Person(DEFAULT_ID);
|
||||
|
||||
// Check no exception when field is not empty.
|
||||
p.assertThat().field("id").isNotEmpty();
|
||||
@@ -169,10 +173,108 @@ public class ModelAssertionTest {
|
||||
p.assertThat().field("age").isNotEmpty();
|
||||
}
|
||||
|
||||
public class Person implements IRestModel<Person> {
|
||||
private String id = "1234";
|
||||
private String name = "test";
|
||||
public String getName() { return name;}
|
||||
@Test(groups = "unit")
|
||||
public void testIsEqualTo_noDifferencesNonIgnoredFields()
|
||||
{
|
||||
Person person = new Person(DEFAULT_ID, DEFAULT_NAME);
|
||||
Person otherPerson = new Person(DEFAULT_ID, DEFAULT_NAME);
|
||||
|
||||
person.assertThat().isEqualTo(otherPerson);
|
||||
}
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void testIsEqualTo_differentNameIgnoreName()
|
||||
{
|
||||
Person person = new Person(DEFAULT_ID);
|
||||
Person otherPerson = new Person(DEFAULT_ID, DEFAULT_NAME);
|
||||
|
||||
person.assertThat().isEqualTo(otherPerson, "name");
|
||||
}
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void testIsEqualTo_differentIdAndNameIgnoreIdAndName()
|
||||
{
|
||||
Person person = new Person();
|
||||
Person otherPerson = new Person(DEFAULT_ID, DEFAULT_NAME);
|
||||
|
||||
person.assertThat().isEqualTo(otherPerson, "id", "name");
|
||||
}
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void testIsEqualTo_differentNameNonIgnoredFields()
|
||||
{
|
||||
Person person = new Person(DEFAULT_ID, DEFAULT_NAME);
|
||||
Person otherPerson = new Person(DEFAULT_ID, "otherName");
|
||||
|
||||
try {
|
||||
person.assertThat().isEqualTo(otherPerson);
|
||||
fail("Expected exception to be raised.");
|
||||
} catch (AssertionError e) {
|
||||
assertTrue(e.getMessage().contains("are not equal"), "Expected exception to be about a not equal objects.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void testIsEqualTo_differentIdNonIgnoredFields()
|
||||
{
|
||||
Person person = new Person();
|
||||
Person otherPerson = new Person(DEFAULT_ID);
|
||||
|
||||
try {
|
||||
person.assertThat().isEqualTo(otherPerson);
|
||||
fail("Expected exception to be raised.");
|
||||
} catch (AssertionError e) {
|
||||
assertTrue(e.getMessage().contains("are not equal"), "Expected exception to be about a not equal objects.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void testIsEqualTo_differentIdAndNameIgnoreName()
|
||||
{
|
||||
Person person = new Person();
|
||||
Person otherPerson = new Person(DEFAULT_ID, DEFAULT_NAME);
|
||||
|
||||
try {
|
||||
person.assertThat().isEqualTo(otherPerson, "name");
|
||||
fail("Expected exception to be raised.");
|
||||
} catch (AssertionError e) {
|
||||
assertTrue(e.getMessage().contains("are not equal"), "Expected exception to be about a not equal objects.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void testIsEqualTo_differentNicknameIgnoreIdAndName()
|
||||
{
|
||||
Person person = new Person();
|
||||
Person otherPerson = new Person();
|
||||
otherPerson.setNickname("Shaggy");
|
||||
|
||||
try {
|
||||
person.assertThat().isEqualTo(otherPerson, "id", "name");
|
||||
fail("Expected exception to be raised.");
|
||||
} catch (AssertionError e) {
|
||||
assertTrue(e.getMessage().contains("are not equal"), "Expected exception to be about a not equal objects.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(groups = "unit")
|
||||
public void testIsEqualTo_differentPreviousNamesIgnoreId()
|
||||
{
|
||||
Person person = new Person();
|
||||
Person otherPerson = new Person();
|
||||
otherPerson.setPreviousNames(List.of("Paul"));
|
||||
|
||||
try {
|
||||
person.assertThat().isEqualTo(otherPerson, "id");
|
||||
fail("Expected exception to be raised.");
|
||||
} catch (AssertionError e) {
|
||||
assertTrue(e.getMessage().contains("are not equal"), "Expected exception to be about a not equal objects.");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Person implements IRestModel<Person> {
|
||||
private String id;
|
||||
private String name;
|
||||
private String nickname = "";
|
||||
private int age = 42;
|
||||
private Set<String> legs = newHashSet("left", "right");
|
||||
@@ -180,16 +282,44 @@ public class ModelAssertionTest {
|
||||
private Map<String, String> clothing = ImmutableMap.of("head", "hat");
|
||||
private Map<String, String> carrying = Collections.emptyMap();
|
||||
|
||||
public Person()
|
||||
{
|
||||
}
|
||||
|
||||
public Person(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Person(String id, String name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() { return name;}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
public String getNickname() { return nickname; }
|
||||
public void setNickname(String nickname)
|
||||
{
|
||||
this.nickname = nickname;
|
||||
}
|
||||
public int getAge() { return age; }
|
||||
public Set<String> getLegs() { return legs; }
|
||||
public List<String> getPreviousNames() { return previousNames; }
|
||||
public void setPreviousNames(List<String> previousNames)
|
||||
{
|
||||
this.previousNames = previousNames;
|
||||
}
|
||||
public Map<String, String> getClothing() { return clothing; }
|
||||
public Map<String, String> getCarrying() { return carrying; }
|
||||
|
||||
@@ -208,6 +338,30 @@ public class ModelAssertionTest {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Person{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", nickname='" + nickname + '\'' + ", age=" + age + ", legs=" + legs + ", previousNames="
|
||||
+ previousNames + ", clothing=" + clothing + ", carrying=" + carrying + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Person person = (Person) o;
|
||||
return age == person.age && Objects.equals(id, person.id) && Objects.equals(name, person.name) && Objects.equals(nickname, person.nickname) && Objects.equals(
|
||||
legs, person.legs) && Objects.equals(previousNames, person.previousNames) && Objects.equals(clothing, person.clothing) && Objects.equals(carrying, person.carrying);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(id, name, nickname, age, legs, previousNames, clothing, carrying);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user