2018-09-19 15:54:24 +02:00
|
|
|
package sonia.scm.it.utils;
|
|
|
|
|
|
|
|
|
|
import io.restassured.RestAssured;
|
|
|
|
|
import io.restassured.response.Response;
|
2018-10-17 11:58:37 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-10-17 13:25:07 +02:00
|
|
|
import sonia.scm.user.User;
|
2018-09-19 15:54:24 +02:00
|
|
|
import sonia.scm.web.VndMediaType;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
|
|
import static sonia.scm.it.utils.TestData.createPasswordChangeJson;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encapsulate rest requests of a repository in builder pattern
|
|
|
|
|
* <p>
|
|
|
|
|
* A Get Request can be applied with the methods request*()
|
|
|
|
|
* These methods return a AppliedGet*Request object
|
|
|
|
|
* This object can be used to apply general assertions over the rest Assured response
|
|
|
|
|
* In the AppliedGet*Request classes there is a using*Response() method
|
|
|
|
|
* that return the *Response class containing specific operations related to the specific response
|
|
|
|
|
* the *Response class contains also the request*() method to apply the next GET request from a link in the response.
|
|
|
|
|
*/
|
|
|
|
|
public class ScmRequests {
|
|
|
|
|
|
2018-10-17 11:58:37 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(ScmRequests.class);
|
|
|
|
|
|
2018-09-19 15:54:24 +02:00
|
|
|
private String username;
|
|
|
|
|
private String password;
|
|
|
|
|
|
|
|
|
|
public static ScmRequests start() {
|
|
|
|
|
return new ScmRequests();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public IndexResponse requestIndexResource(String username, String password) {
|
|
|
|
|
setUsername(username);
|
|
|
|
|
setPassword(password);
|
|
|
|
|
return new IndexResponse(applyGETRequest(RestUtil.REST_BASE_URL.toString()));
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-17 13:25:07 +02:00
|
|
|
public <SELF extends UserResponse<SELF, T>, T extends ModelResponse> UserResponse<SELF,T> requestUser(String username, String password, String pathParam) {
|
2018-10-16 15:58:54 +02:00
|
|
|
setUsername(username);
|
|
|
|
|
setPassword(password);
|
|
|
|
|
return new UserResponse<>(applyGETRequest(RestUtil.REST_BASE_URL.resolve("users/"+pathParam).toString()), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ChangePasswordResponse<ChangePasswordResponse> requestUserChangePassword(String username, String password, String userPathParam, String newPassword) {
|
|
|
|
|
setUsername(username);
|
|
|
|
|
setPassword(password);
|
2018-10-17 11:58:37 +02:00
|
|
|
return new ChangePasswordResponse<>(applyPUTRequest(RestUtil.REST_BASE_URL.resolve("users/"+userPathParam+"/password").toString(), VndMediaType.PASSWORD_OVERWRITE, TestData.createPasswordChangeJson(password,newPassword)), null);
|
2018-10-16 15:58:54 +02:00
|
|
|
|
|
|
|
|
}
|
2018-09-19 15:54:24 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Apply a GET Request to the extracted url from the given link
|
|
|
|
|
*
|
|
|
|
|
* @param linkPropertyName the property name of link
|
|
|
|
|
* @param response the response containing the link
|
|
|
|
|
* @return the response of the GET request using the given link
|
|
|
|
|
*/
|
|
|
|
|
private Response applyGETRequestFromLink(Response response, String linkPropertyName) {
|
2018-10-15 08:41:46 +02:00
|
|
|
return applyGETRequestFromLinkWithParams(response, linkPropertyName, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Apply a GET Request to the extracted url from the given link
|
|
|
|
|
*
|
|
|
|
|
* @param linkPropertyName the property name of link
|
|
|
|
|
* @param response the response containing the link
|
2018-10-15 18:35:45 +02:00
|
|
|
* @param params query params eg. ?q=xyz&count=12 or path params eg. namespace/name
|
2018-10-15 08:41:46 +02:00
|
|
|
* @return the response of the GET request using the given link
|
|
|
|
|
*/
|
2018-10-15 18:35:45 +02:00
|
|
|
private Response applyGETRequestFromLinkWithParams(Response response, String linkPropertyName, String params) {
|
2018-10-15 08:41:46 +02:00
|
|
|
return applyGETRequestWithQueryParams(response
|
2018-09-19 15:54:24 +02:00
|
|
|
.then()
|
|
|
|
|
.extract()
|
2018-10-15 18:35:45 +02:00
|
|
|
.path(linkPropertyName), params);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Apply a GET Request to the given <code>url</code> and return the response.
|
|
|
|
|
*
|
2018-10-15 18:35:45 +02:00
|
|
|
* @param url the url of the GET request
|
|
|
|
|
* @param params query params eg. ?q=xyz&count=12 or path params eg. namespace/name
|
2018-09-19 15:54:24 +02:00
|
|
|
* @return the response of the GET request using the given <code>url</code>
|
|
|
|
|
*/
|
2018-10-15 18:35:45 +02:00
|
|
|
private Response applyGETRequestWithQueryParams(String url, String params) {
|
2018-10-17 11:58:37 +02:00
|
|
|
LOG.info("GET {}", url);
|
2018-09-19 15:54:24 +02:00
|
|
|
return RestAssured.given()
|
|
|
|
|
.auth().preemptive().basic(username, password)
|
|
|
|
|
.when()
|
2018-10-15 18:35:45 +02:00
|
|
|
.get(url + params);
|
2018-10-15 08:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Apply a GET Request to the given <code>url</code> and return the response.
|
|
|
|
|
*
|
|
|
|
|
* @param url the url of the GET request
|
|
|
|
|
* @return the response of the GET request using the given <code>url</code>
|
|
|
|
|
**/
|
|
|
|
|
private Response applyGETRequest(String url) {
|
|
|
|
|
return applyGETRequestWithQueryParams(url, "");
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Apply a PUT Request to the extracted url from the given link
|
|
|
|
|
*
|
|
|
|
|
* @param response the response containing the link
|
|
|
|
|
* @param linkPropertyName the property name of link
|
|
|
|
|
* @param body
|
|
|
|
|
* @return the response of the PUT request using the given link
|
|
|
|
|
*/
|
|
|
|
|
private Response applyPUTRequestFromLink(Response response, String linkPropertyName, String content, String body) {
|
|
|
|
|
return applyPUTRequest(response
|
|
|
|
|
.then()
|
|
|
|
|
.extract()
|
|
|
|
|
.path(linkPropertyName), content, body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Apply a PUT Request to the given <code>url</code> and return the response.
|
|
|
|
|
*
|
|
|
|
|
* @param url the url of the PUT request
|
|
|
|
|
* @param mediaType
|
|
|
|
|
* @param body
|
|
|
|
|
* @return the response of the PUT request using the given <code>url</code>
|
|
|
|
|
*/
|
|
|
|
|
private Response applyPUTRequest(String url, String mediaType, String body) {
|
2018-10-17 11:58:37 +02:00
|
|
|
LOG.info("PUT {}", url);
|
2018-09-19 15:54:24 +02:00
|
|
|
return RestAssured.given()
|
|
|
|
|
.auth().preemptive().basic(username, password)
|
|
|
|
|
.when()
|
|
|
|
|
.contentType(mediaType)
|
|
|
|
|
.accept(mediaType)
|
|
|
|
|
.body(body)
|
|
|
|
|
.put(url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setUsername(String username) {
|
|
|
|
|
this.username = username;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setPassword(String password) {
|
|
|
|
|
this.password = password;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public class IndexResponse extends ModelResponse<IndexResponse, IndexResponse> {
|
|
|
|
|
public static final String LINK_AUTOCOMPLETE_USERS = "_links.autocomplete.find{it.name=='users'}.href";
|
|
|
|
|
public static final String LINK_AUTOCOMPLETE_GROUPS = "_links.autocomplete.find{it.name=='groups'}.href";
|
|
|
|
|
public static final String LINK_REPOSITORIES = "_links.repositories.href";
|
|
|
|
|
private static final String LINK_ME = "_links.me.href";
|
|
|
|
|
private static final String LINK_USERS = "_links.users.href";
|
2018-09-19 15:54:24 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public IndexResponse(Response response) {
|
|
|
|
|
super(response, null);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public AutoCompleteResponse<IndexResponse> requestAutoCompleteUsers(String q) {
|
|
|
|
|
return new AutoCompleteResponse<>(applyGETRequestFromLinkWithParams(response, LINK_AUTOCOMPLETE_USERS, "?q=" + q), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public AutoCompleteResponse<IndexResponse> requestAutoCompleteGroups(String q) {
|
|
|
|
|
return new AutoCompleteResponse<>(applyGETRequestFromLinkWithParams(response, LINK_AUTOCOMPLETE_GROUPS, "?q=" + q), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public RepositoryResponse<IndexResponse> requestRepository(String namespace, String name) {
|
|
|
|
|
return new RepositoryResponse<>(applyGETRequestFromLinkWithParams(response, LINK_REPOSITORIES, namespace + "/" + name), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public MeResponse<IndexResponse> requestMe() {
|
|
|
|
|
return new MeResponse<>(applyGETRequestFromLink(response, LINK_ME), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-17 13:25:07 +02:00
|
|
|
public UserResponse<? extends UserResponse, IndexResponse> requestUser(String username) {
|
2018-10-15 18:35:45 +02:00
|
|
|
return new UserResponse<>(applyGETRequestFromLinkWithParams(response, LINK_USERS, username), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-16 15:58:54 +02:00
|
|
|
public IndexResponse assertUsersLinkDoesNotExists() {
|
|
|
|
|
return super.assertPropertyPathDoesNotExists(LINK_USERS);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public class RepositoryResponse<PREV extends ModelResponse> extends ModelResponse<RepositoryResponse<PREV>, PREV> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public static final String LINKS_SOURCES = "_links.sources.href";
|
|
|
|
|
public static final String LINKS_CHANGESETS = "_links.changesets.href";
|
2018-09-19 15:54:24 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public RepositoryResponse(Response response, PREV previousResponse) {
|
|
|
|
|
super(response, previousResponse);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public SourcesResponse<RepositoryResponse> requestSources() {
|
|
|
|
|
return new SourcesResponse<>(applyGETRequestFromLink(response, LINKS_SOURCES), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ChangesetsResponse<RepositoryResponse> requestChangesets() {
|
|
|
|
|
return new ChangesetsResponse<>(applyGETRequestFromLink(response, LINKS_CHANGESETS), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public class ChangesetsResponse<PREV extends ModelResponse> extends ModelResponse<ChangesetsResponse<PREV>, PREV> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ChangesetsResponse(Response response, PREV previousResponse) {
|
|
|
|
|
super(response, previousResponse);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ChangesetsResponse assertChangesets(Consumer<List<Map>> changesetsConsumer) {
|
2018-10-15 18:35:45 +02:00
|
|
|
List<Map> changesets = response.then().extract().path("_embedded.changesets");
|
2018-09-19 15:54:24 +02:00
|
|
|
changesetsConsumer.accept(changesets);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public DiffResponse<ChangesetsResponse> requestDiff(String revision) {
|
|
|
|
|
return new DiffResponse<>(applyGETRequestFromLink(response, "_embedded.changesets.find{it.id=='" + revision + "'}._links.diff.href"), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ModificationsResponse<ChangesetsResponse> requestModifications(String revision) {
|
|
|
|
|
return new ModificationsResponse<>(applyGETRequestFromLink(response, "_embedded.changesets.find{it.id=='" + revision + "'}._links.modifications.href"), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public class SourcesResponse<PREV extends ModelResponse> extends ModelResponse<SourcesResponse<PREV>, PREV> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public SourcesResponse(Response response, PREV previousResponse) {
|
|
|
|
|
super(response, previousResponse);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SourcesResponse assertRevision(Consumer<String> assertRevision) {
|
2018-10-15 18:35:45 +02:00
|
|
|
String revision = response.then().extract().path("revision");
|
2018-09-19 15:54:24 +02:00
|
|
|
assertRevision.accept(revision);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SourcesResponse assertFiles(Consumer<List> assertFiles) {
|
2018-10-15 18:35:45 +02:00
|
|
|
List files = response.then().extract().path("files");
|
2018-09-19 15:54:24 +02:00
|
|
|
assertFiles.accept(files);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ChangesetsResponse<SourcesResponse> requestFileHistory(String fileName) {
|
|
|
|
|
return new ChangesetsResponse<>(applyGETRequestFromLink(response, "_embedded.files.find{it.name=='" + fileName + "'}._links.history.href"), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public SourcesResponse<SourcesResponse> requestSelf(String fileName) {
|
|
|
|
|
return new SourcesResponse<>(applyGETRequestFromLink(response, "_embedded.files.find{it.name=='" + fileName + "'}._links.self.href"), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public class ModificationsResponse<PREV extends ModelResponse> extends ModelResponse<ModificationsResponse<PREV>, PREV> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ModificationsResponse(Response response, PREV previousResponse) {
|
|
|
|
|
super(response, previousResponse);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ModificationsResponse<PREV> assertRevision(Consumer<String> assertRevision) {
|
|
|
|
|
String revision = response.then().extract().path("revision");
|
2018-09-19 15:54:24 +02:00
|
|
|
assertRevision.accept(revision);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ModificationsResponse<PREV> assertAdded(Consumer<List<String>> assertAdded) {
|
|
|
|
|
List<String> added = response.then().extract().path("added");
|
2018-09-19 15:54:24 +02:00
|
|
|
assertAdded.accept(added);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ModificationsResponse<PREV> assertRemoved(Consumer<List<String>> assertRemoved) {
|
|
|
|
|
List<String> removed = response.then().extract().path("removed");
|
2018-09-19 15:54:24 +02:00
|
|
|
assertRemoved.accept(removed);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ModificationsResponse<PREV> assertModified(Consumer<List<String>> assertModified) {
|
|
|
|
|
List<String> modified = response.then().extract().path("modified");
|
2018-09-19 15:54:24 +02:00
|
|
|
assertModified.accept(modified);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 13:25:07 +02:00
|
|
|
public class MeResponse<PREV extends ModelResponse> extends UserResponse<MeResponse<PREV>, PREV> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public MeResponse(Response response, PREV previousResponse) {
|
|
|
|
|
super(response, previousResponse);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-17 11:58:37 +02:00
|
|
|
public ChangePasswordResponse<UserResponse> requestChangePassword(String oldPassword, String newPassword) {
|
|
|
|
|
return new ChangePasswordResponse<>(applyPUTRequestFromLink(super.response, LINKS_PASSWORD_HREF, VndMediaType.PASSWORD_CHANGE, createPasswordChangeJson(oldPassword, newPassword)), this);
|
|
|
|
|
}
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-17 13:25:07 +02:00
|
|
|
public class UserResponse<SELF extends UserResponse<SELF, PREV>, PREV extends ModelResponse> extends ModelResponse<SELF, PREV> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
|
|
|
|
public static final String LINKS_PASSWORD_HREF = "_links.password.href";
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public UserResponse(Response response, PREV previousResponse) {
|
|
|
|
|
super(response, previousResponse);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-17 13:25:07 +02:00
|
|
|
public SELF assertPassword(Consumer<String> assertPassword) {
|
2018-09-19 15:54:24 +02:00
|
|
|
return super.assertSingleProperty(assertPassword, "password");
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 13:25:07 +02:00
|
|
|
public SELF assertType(Consumer<String> assertType) {
|
2018-09-19 15:54:24 +02:00
|
|
|
return assertSingleProperty(assertType, "type");
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 13:25:07 +02:00
|
|
|
public SELF assertAdmin(Consumer<Boolean> assertAdmin) {
|
2018-09-19 15:54:24 +02:00
|
|
|
return assertSingleProperty(assertAdmin, "admin");
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 13:25:07 +02:00
|
|
|
public SELF assertPasswordLinkDoesNotExists() {
|
2018-09-19 15:54:24 +02:00
|
|
|
return assertPropertyPathDoesNotExists(LINKS_PASSWORD_HREF);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 13:25:07 +02:00
|
|
|
public SELF assertPasswordLinkExists() {
|
2018-09-19 15:54:24 +02:00
|
|
|
return assertPropertyPathExists(LINKS_PASSWORD_HREF);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ChangePasswordResponse<UserResponse> requestChangePassword(String newPassword) {
|
2018-10-17 13:25:07 +02:00
|
|
|
return new ChangePasswordResponse<>(applyPUTRequestFromLink(super.response, LINKS_PASSWORD_HREF, VndMediaType.PASSWORD_OVERWRITE, createPasswordChangeJson(null, newPassword)), this);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* encapsulate standard assertions over model properties
|
|
|
|
|
*/
|
2018-10-15 18:35:45 +02:00
|
|
|
public class ModelResponse<SELF extends ModelResponse<SELF, PREV>, PREV extends ModelResponse> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
protected PREV previousResponse;
|
2018-09-19 15:54:24 +02:00
|
|
|
protected Response response;
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ModelResponse(Response response, PREV previousResponse) {
|
2018-09-19 15:54:24 +02:00
|
|
|
this.response = response;
|
2018-10-15 18:35:45 +02:00
|
|
|
this.previousResponse = previousResponse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PREV returnToPrevious() {
|
|
|
|
|
return previousResponse;
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <T> SELF assertSingleProperty(Consumer<T> assertSingleProperty, String propertyJsonPath) {
|
|
|
|
|
T propertyValue = response.then().extract().path(propertyJsonPath);
|
|
|
|
|
assertSingleProperty.accept(propertyValue);
|
|
|
|
|
return (SELF) this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SELF assertPropertyPathExists(String propertyJsonPath) {
|
|
|
|
|
response.then().assertThat().body("any { it.containsKey('" + propertyJsonPath + "')}", is(true));
|
|
|
|
|
return (SELF) this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SELF assertPropertyPathDoesNotExists(String propertyJsonPath) {
|
|
|
|
|
response.then().assertThat().body("this.any { it.containsKey('" + propertyJsonPath + "')}", is(false));
|
|
|
|
|
return (SELF) this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SELF assertArrayProperty(Consumer<List> assertProperties, String propertyJsonPath) {
|
|
|
|
|
List properties = response.then().extract().path(propertyJsonPath);
|
|
|
|
|
assertProperties.accept(properties);
|
|
|
|
|
return (SELF) this;
|
|
|
|
|
}
|
2018-10-12 11:06:53 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
/**
|
|
|
|
|
* special assertion of the status code
|
|
|
|
|
*
|
|
|
|
|
* @param expectedStatusCode the expected status code
|
|
|
|
|
* @return the self object
|
|
|
|
|
*/
|
|
|
|
|
public SELF assertStatusCode(int expectedStatusCode) {
|
|
|
|
|
this.response.then().assertThat().statusCode(expectedStatusCode);
|
|
|
|
|
return (SELF) this;
|
2018-10-12 11:06:53 +02:00
|
|
|
}
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public class AutoCompleteResponse<PREV extends ModelResponse> extends ModelResponse<AutoCompleteResponse<PREV>, PREV> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public AutoCompleteResponse(Response response, PREV previousResponse) {
|
|
|
|
|
super(response, previousResponse);
|
2018-10-12 11:06:53 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public AutoCompleteResponse<PREV> assertAutoCompleteResults(Consumer<List<Map>> checker) {
|
2018-10-12 11:06:53 +02:00
|
|
|
List<Map> result = response.then().extract().path("");
|
|
|
|
|
checker.accept(result);
|
|
|
|
|
return this;
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public class DiffResponse<PREV extends ModelResponse> extends ModelResponse<DiffResponse<PREV>, PREV> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public DiffResponse(Response response, PREV previousResponse) {
|
|
|
|
|
super(response, previousResponse);
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
2018-10-15 18:35:45 +02:00
|
|
|
}
|
2018-10-15 08:41:46 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public class ChangePasswordResponse<PREV extends ModelResponse> extends ModelResponse<ChangePasswordResponse<PREV>, PREV> {
|
2018-09-19 15:54:24 +02:00
|
|
|
|
2018-10-15 18:35:45 +02:00
|
|
|
public ChangePasswordResponse(Response response, PREV previousResponse) {
|
|
|
|
|
super(response, previousResponse);
|
2018-10-15 08:41:46 +02:00
|
|
|
}
|
2018-09-19 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
}
|