This commit is contained in:
René Pfeuffer
2018-10-17 13:25:07 +02:00
parent 9bfb2cdadb
commit 3c7df066f0
5 changed files with 12 additions and 53 deletions

View File

@@ -4,6 +4,7 @@ import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.user.User;
import sonia.scm.web.VndMediaType;
import java.util.List;
@@ -41,7 +42,7 @@ public class ScmRequests {
return new IndexResponse(applyGETRequest(RestUtil.REST_BASE_URL.toString()));
}
public UserResponse<UserResponse> requestUser(String username, String password, String pathParam) {
public <SELF extends UserResponse<SELF, T>, T extends ModelResponse> UserResponse<SELF,T> requestUser(String username, String password, String pathParam) {
setUsername(username);
setPassword(password);
return new UserResponse<>(applyGETRequest(RestUtil.REST_BASE_URL.resolve("users/"+pathParam).toString()), null);
@@ -176,7 +177,7 @@ public class ScmRequests {
return new MeResponse<>(applyGETRequestFromLink(response, LINK_ME), this);
}
public UserResponse<IndexResponse> requestUser(String username) {
public UserResponse<? extends UserResponse, IndexResponse> requestUser(String username) {
return new UserResponse<>(applyGETRequestFromLinkWithParams(response, LINK_USERS, username), this);
}
@@ -288,7 +289,7 @@ public class ScmRequests {
}
public class MeResponse<PREV extends ModelResponse> extends UserResponse<PREV> {
public class MeResponse<PREV extends ModelResponse> extends UserResponse<MeResponse<PREV>, PREV> {
public MeResponse(Response response, PREV previousResponse) {
@@ -300,7 +301,7 @@ public class ScmRequests {
}
}
public class UserResponse<PREV extends ModelResponse> extends ModelResponse<UserResponse<PREV>, PREV> {
public class UserResponse<SELF extends UserResponse<SELF, PREV>, PREV extends ModelResponse> extends ModelResponse<SELF, PREV> {
public static final String LINKS_PASSWORD_HREF = "_links.password.href";
@@ -308,34 +309,29 @@ public class ScmRequests {
super(response, previousResponse);
}
public UserResponse<PREV> assertPassword(Consumer<String> assertPassword) {
public SELF assertPassword(Consumer<String> assertPassword) {
return super.assertSingleProperty(assertPassword, "password");
}
public UserResponse<PREV> assertType(Consumer<String> assertType) {
public SELF assertType(Consumer<String> assertType) {
return assertSingleProperty(assertType, "type");
}
public UserResponse<PREV> assertAdmin(Consumer<Boolean> assertAdmin) {
public SELF assertAdmin(Consumer<Boolean> assertAdmin) {
return assertSingleProperty(assertAdmin, "admin");
}
public UserResponse<PREV> assertPasswordLinkDoesNotExists() {
public SELF assertPasswordLinkDoesNotExists() {
return assertPropertyPathDoesNotExists(LINKS_PASSWORD_HREF);
}
public UserResponse<PREV> assertPasswordLinkExists() {
public SELF assertPasswordLinkExists() {
return assertPropertyPathExists(LINKS_PASSWORD_HREF);
}
public ChangePasswordResponse<UserResponse> requestChangePassword(String newPassword) {
return requestChangePassword(null, newPassword);
return new ChangePasswordResponse<>(applyPUTRequestFromLink(super.response, LINKS_PASSWORD_HREF, VndMediaType.PASSWORD_OVERWRITE, createPasswordChangeJson(null, newPassword)), this);
}
public ChangePasswordResponse<UserResponse> requestChangePassword(String oldPassword, String newPassword) {
return new ChangePasswordResponse<>(applyPUTRequestFromLink(super.response, LINKS_PASSWORD_HREF, VndMediaType.PASSWORD_OVERWRITE, createPasswordChangeJson(oldPassword, newPassword)), this);
}
}