mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-05-06 10:16:57 +02:00
Merge with 2.0.0-m3
This commit is contained in:
73
scm-it/src/test/java/sonia/scm/it/AutoCompleteITCase.java
Normal file
73
scm-it/src/test/java/sonia/scm/it/AutoCompleteITCase.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package sonia.scm.it;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.it.utils.ScmRequests;
|
||||
import sonia.scm.it.utils.TestData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class AutoCompleteITCase {
|
||||
|
||||
|
||||
public static final String CREATED_USER_PREFIX = "user_";
|
||||
public static final String CREATED_GROUP_PREFIX = "group_";
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
TestData.cleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adminShouldAutoComplete() {
|
||||
shouldAutocomplete(TestData.USER_SCM_ADMIN, TestData.USER_SCM_ADMIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userShouldAutoComplete() {
|
||||
String username = "nonAdmin";
|
||||
String password = "pass";
|
||||
TestData.createUser(username, password, false, "xml", "email@e.de");
|
||||
shouldAutocomplete(username, password);
|
||||
}
|
||||
|
||||
public void shouldAutocomplete(String username, String password) {
|
||||
createUsers();
|
||||
createGroups();
|
||||
ScmRequests.start()
|
||||
.requestIndexResource(username, password)
|
||||
.assertStatusCode(200)
|
||||
.requestAutoCompleteGroups("group*")
|
||||
.assertStatusCode(200)
|
||||
.assertAutoCompleteResults(assertAutoCompleteResult(CREATED_GROUP_PREFIX))
|
||||
.returnToPrevious()
|
||||
.requestAutoCompleteUsers("user*")
|
||||
.assertStatusCode(200)
|
||||
.assertAutoCompleteResults(assertAutoCompleteResult(CREATED_USER_PREFIX));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Consumer<List<Map>> assertAutoCompleteResult(String id) {
|
||||
return autoCompleteDtos -> {
|
||||
IntStream.range(0, 5).forEach(i -> {
|
||||
assertThat(autoCompleteDtos).as("return maximum 5 entries").hasSize(5);
|
||||
assertThat(autoCompleteDtos.get(i)).containsEntry("id", id + (i + 1));
|
||||
assertThat(autoCompleteDtos.get(i)).containsEntry("displayName", id + (i + 1));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private void createUsers() {
|
||||
IntStream.range(0, 6).forEach(i -> TestData.createUser(CREATED_USER_PREFIX + (i + 1), "pass", false, "xml", CREATED_USER_PREFIX + (i + 1) + "@scm-manager.org"));
|
||||
}
|
||||
|
||||
private void createGroups() {
|
||||
IntStream.range(0, 6).forEach(i -> TestData.createGroup(CREATED_GROUP_PREFIX + (i + 1), CREATED_GROUP_PREFIX + (i + 1)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,12 +20,9 @@ public class MeITCase {
|
||||
String newPassword = TestData.USER_SCM_ADMIN + "1";
|
||||
// admin change the own password
|
||||
ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getMeUrl())
|
||||
.usernameAndPassword(TestData.USER_SCM_ADMIN, TestData.USER_SCM_ADMIN)
|
||||
.getMeResource()
|
||||
.requestIndexResource(TestData.USER_SCM_ADMIN, TestData.USER_SCM_ADMIN)
|
||||
.requestMe()
|
||||
.assertStatusCode(200)
|
||||
.usingMeResponse()
|
||||
.assertAdmin(aBoolean -> assertThat(aBoolean).isEqualTo(Boolean.TRUE))
|
||||
.assertPassword(Assert::assertNull)
|
||||
.assertType(s -> assertThat(s).isEqualTo("xml"))
|
||||
@@ -33,12 +30,9 @@ public class MeITCase {
|
||||
.assertStatusCode(204);
|
||||
// assert password is changed -> login with the new Password than undo changes
|
||||
ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getUserUrl(TestData.USER_SCM_ADMIN))
|
||||
.usernameAndPassword(TestData.USER_SCM_ADMIN, newPassword)
|
||||
.getMeResource()
|
||||
.requestIndexResource(TestData.USER_SCM_ADMIN, newPassword)
|
||||
.requestMe()
|
||||
.assertStatusCode(200)
|
||||
.usingMeResponse()
|
||||
.assertAdmin(aBoolean -> assertThat(aBoolean).isEqualTo(Boolean.TRUE))// still admin
|
||||
.requestChangePassword(newPassword, TestData.USER_SCM_ADMIN)
|
||||
.assertStatusCode(204);
|
||||
@@ -49,14 +43,11 @@ public class MeITCase {
|
||||
String newUser = "user";
|
||||
String password = "pass";
|
||||
String type = "not XML Type";
|
||||
TestData.createUser(newUser, password, true, type);
|
||||
TestData.createUser(newUser, password, true, type, "user@scm-manager.org");
|
||||
ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getMeUrl())
|
||||
.usernameAndPassword(newUser, password)
|
||||
.getMeResource()
|
||||
.requestIndexResource(newUser, password)
|
||||
.requestMe()
|
||||
.assertStatusCode(200)
|
||||
.usingMeResponse()
|
||||
.assertAdmin(aBoolean -> assertThat(aBoolean).isEqualTo(Boolean.TRUE))
|
||||
.assertPassword(Assert::assertNull)
|
||||
.assertType(s -> assertThat(s).isEqualTo(type))
|
||||
|
||||
@@ -87,13 +87,13 @@ public class PermissionsITCase {
|
||||
@Before
|
||||
public void prepareEnvironment() {
|
||||
TestData.createDefault();
|
||||
TestData.createUser(USER_READ, USER_PASS);
|
||||
TestData.createNotAdminUser(USER_READ, USER_PASS);
|
||||
TestData.createUserPermission(USER_READ, PermissionType.READ, repositoryType);
|
||||
TestData.createUser(USER_WRITE, USER_PASS);
|
||||
TestData.createNotAdminUser(USER_WRITE, USER_PASS);
|
||||
TestData.createUserPermission(USER_WRITE, PermissionType.WRITE, repositoryType);
|
||||
TestData.createUser(USER_OWNER, USER_PASS);
|
||||
TestData.createNotAdminUser(USER_OWNER, USER_PASS);
|
||||
TestData.createUserPermission(USER_OWNER, PermissionType.OWNER, repositoryType);
|
||||
TestData.createUser(USER_OTHER, USER_PASS);
|
||||
TestData.createNotAdminUser(USER_OTHER, USER_PASS);
|
||||
createdPermissions = 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class RepositoryAccessITCase {
|
||||
|
||||
private final String repositoryType;
|
||||
private File folder;
|
||||
private ScmRequests.AppliedRepositoryRequest repositoryGetRequest;
|
||||
private ScmRequests.RepositoryResponse<ScmRequests.IndexResponse> repositoryResponse;
|
||||
|
||||
public RepositoryAccessITCase(String repositoryType) {
|
||||
this.repositoryType = repositoryType;
|
||||
@@ -59,17 +59,13 @@ public class RepositoryAccessITCase {
|
||||
public void init() {
|
||||
TestData.createDefault();
|
||||
folder = tempFolder.getRoot();
|
||||
repositoryGetRequest = ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getDefaultRepositoryUrl(repositoryType))
|
||||
.usernameAndPassword(ADMIN_USERNAME, ADMIN_PASSWORD)
|
||||
.getRepositoryResource()
|
||||
String namespace = ADMIN_USERNAME;
|
||||
String repo = TestData.getDefaultRepoName(repositoryType);
|
||||
repositoryResponse =
|
||||
ScmRequests.start()
|
||||
.requestIndexResource(ADMIN_USERNAME, ADMIN_PASSWORD)
|
||||
.requestRepository(namespace, repo)
|
||||
.assertStatusCode(HttpStatus.SC_OK);
|
||||
ScmRequests.AppliedMeRequest meGetRequest = ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getMeUrl())
|
||||
.usernameAndPassword(ADMIN_USERNAME, ADMIN_PASSWORD)
|
||||
.getMeResource();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -306,17 +302,12 @@ public class RepositoryAccessITCase {
|
||||
public void shouldFindFileHistory() throws IOException {
|
||||
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
||||
Changeset changeset = RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, "folder/subfolder/a.txt", "a");
|
||||
repositoryGetRequest
|
||||
.usingRepositoryResponse()
|
||||
repositoryResponse
|
||||
.requestSources()
|
||||
.usingSourcesResponse()
|
||||
.requestSelf("folder")
|
||||
.usingSourcesResponse()
|
||||
.requestSelf("subfolder")
|
||||
.usingSourcesResponse()
|
||||
.requestFileHistory("a.txt")
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingChangesetsResponse()
|
||||
.assertChangesets(changesets -> {
|
||||
assertThat(changesets).hasSize(1);
|
||||
assertThat(changesets.get(0)).containsEntry("id", changeset.getId());
|
||||
@@ -332,14 +323,11 @@ public class RepositoryAccessITCase {
|
||||
String fileName = "a.txt";
|
||||
Changeset changeset = RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, fileName, "a");
|
||||
String revision = changeset.getId();
|
||||
repositoryGetRequest
|
||||
.usingRepositoryResponse()
|
||||
repositoryResponse
|
||||
.requestChangesets()
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingChangesetsResponse()
|
||||
.requestModifications(revision)
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingModificationsResponse()
|
||||
.assertRevision(actualRevision -> assertThat(actualRevision).isEqualTo(revision))
|
||||
.assertAdded(addedFiles -> assertThat(addedFiles)
|
||||
.hasSize(1)
|
||||
@@ -359,14 +347,11 @@ public class RepositoryAccessITCase {
|
||||
Changeset changeset = RepositoryUtil.removeAndCommitFile(repositoryClient, ADMIN_USERNAME, fileName);
|
||||
|
||||
String revision = changeset.getId();
|
||||
repositoryGetRequest
|
||||
.usingRepositoryResponse()
|
||||
repositoryResponse
|
||||
.requestChangesets()
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingChangesetsResponse()
|
||||
.requestModifications(revision)
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingModificationsResponse()
|
||||
.assertRevision(actualRevision -> assertThat(actualRevision).isEqualTo(revision))
|
||||
.assertRemoved(removedFiles -> assertThat(removedFiles)
|
||||
.hasSize(1)
|
||||
@@ -386,14 +371,11 @@ public class RepositoryAccessITCase {
|
||||
Changeset changeset = RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, fileName, "new Content");
|
||||
|
||||
String revision = changeset.getId();
|
||||
repositoryGetRequest
|
||||
.usingRepositoryResponse()
|
||||
repositoryResponse
|
||||
.requestChangesets()
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingChangesetsResponse()
|
||||
.requestModifications(revision)
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingModificationsResponse()
|
||||
.assertRevision(actualRevision -> assertThat(actualRevision).isEqualTo(revision))
|
||||
.assertModified(modifiedFiles -> assertThat(modifiedFiles)
|
||||
.hasSize(1)
|
||||
@@ -423,14 +405,11 @@ public class RepositoryAccessITCase {
|
||||
Changeset changeset = RepositoryUtil.commitMultipleFileModifications(repositoryClient, ADMIN_USERNAME, addedFiles, modifiedFiles, removedFiles);
|
||||
|
||||
String revision = changeset.getId();
|
||||
repositoryGetRequest
|
||||
.usingRepositoryResponse()
|
||||
repositoryResponse
|
||||
.requestChangesets()
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingChangesetsResponse()
|
||||
.requestModifications(revision)
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingModificationsResponse()
|
||||
.assertRevision(actualRevision -> assertThat(actualRevision).isEqualTo(revision))
|
||||
.assertAdded(a -> assertThat(a)
|
||||
.hasSize(1)
|
||||
@@ -463,14 +442,11 @@ public class RepositoryAccessITCase {
|
||||
Changeset changeset = RepositoryUtil.commitMultipleFileModifications(repositoryClient, ADMIN_USERNAME, addedFiles, modifiedFiles, removedFiles);
|
||||
|
||||
String revision = changeset.getId();
|
||||
repositoryGetRequest
|
||||
.usingRepositoryResponse()
|
||||
repositoryResponse
|
||||
.requestChangesets()
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingChangesetsResponse()
|
||||
.requestModifications(revision)
|
||||
.assertStatusCode(HttpStatus.SC_OK)
|
||||
.usingModificationsResponse()
|
||||
.assertRevision(actualRevision -> assertThat(actualRevision).isEqualTo(revision))
|
||||
.assertAdded(a -> assertThat(a)
|
||||
.hasSize(3)
|
||||
|
||||
@@ -19,57 +19,48 @@ public class UserITCase {
|
||||
public void adminShouldChangeOwnPassword() {
|
||||
String newUser = "user";
|
||||
String password = "pass";
|
||||
TestData.createUser(newUser, password, true, "xml");
|
||||
TestData.createUser(newUser, password, true, "xml", "user@scm-manager.org");
|
||||
String newPassword = "new_password";
|
||||
// admin change the own password
|
||||
ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getUserUrl(newUser))
|
||||
.usernameAndPassword(newUser, password)
|
||||
.getUserResource()
|
||||
.requestIndexResource(newUser, password)
|
||||
.assertStatusCode(200)
|
||||
.requestUser(newUser)
|
||||
.assertStatusCode(200)
|
||||
.usingUserResponse()
|
||||
.assertAdmin(aBoolean -> assertThat(aBoolean).isEqualTo(Boolean.TRUE))
|
||||
.assertPassword(Assert::assertNull)
|
||||
.requestChangePassword(newPassword) // the oldPassword is not needed in the user resource
|
||||
.assertStatusCode(204);
|
||||
// assert password is changed -> login with the new Password
|
||||
ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getUserUrl(newUser))
|
||||
.usernameAndPassword(newUser, newPassword)
|
||||
.getUserResource()
|
||||
.requestIndexResource(newUser, newPassword)
|
||||
.assertStatusCode(200)
|
||||
.usingUserResponse()
|
||||
.requestUser(newUser)
|
||||
.assertAdmin(isAdmin -> assertThat(isAdmin).isEqualTo(Boolean.TRUE))
|
||||
.assertPassword(Assert::assertNull);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adminShouldChangePasswordOfOtherUser() {
|
||||
String newUser = "user";
|
||||
String password = "pass";
|
||||
TestData.createUser(newUser, password, true, "xml");
|
||||
TestData.createUser(newUser, password, true, "xml", "user@scm-manager.org");
|
||||
String newPassword = "new_password";
|
||||
// admin change the password of the user
|
||||
ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getUserUrl(newUser))// the admin get the user object
|
||||
.usernameAndPassword(TestData.USER_SCM_ADMIN, TestData.USER_SCM_ADMIN)
|
||||
.getUserResource()
|
||||
.requestIndexResource(TestData.USER_SCM_ADMIN, TestData.USER_SCM_ADMIN)
|
||||
.assertStatusCode(200)
|
||||
.requestUser(newUser)
|
||||
.assertStatusCode(200)
|
||||
.usingUserResponse()
|
||||
.assertAdmin(aBoolean -> assertThat(aBoolean).isEqualTo(Boolean.TRUE)) // the user anonymous is not an admin
|
||||
.assertPassword(Assert::assertNull)
|
||||
.requestChangePassword(newPassword) // the oldPassword is not needed in the user resource
|
||||
.assertStatusCode(204);
|
||||
// assert password is changed
|
||||
ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getUserUrl(newUser))
|
||||
.usernameAndPassword(newUser, newPassword)
|
||||
.getUserResource()
|
||||
.requestIndexResource(newUser, newPassword)
|
||||
.assertStatusCode(200)
|
||||
.requestUser(newUser)
|
||||
.assertStatusCode(200);
|
||||
|
||||
}
|
||||
@@ -80,14 +71,12 @@ public class UserITCase {
|
||||
String newUser = "user";
|
||||
String password = "pass";
|
||||
String type = "not XML Type";
|
||||
TestData.createUser(newUser, password, true, type);
|
||||
TestData.createUser(newUser, password, true, type, "user@scm-manager.org");
|
||||
ScmRequests.start()
|
||||
.given()
|
||||
.url(TestData.getMeUrl())
|
||||
.usernameAndPassword(newUser, password)
|
||||
.getUserResource()
|
||||
.requestIndexResource(newUser, password)
|
||||
.assertStatusCode(200)
|
||||
.requestUser(newUser)
|
||||
.assertStatusCode(200)
|
||||
.usingUserResponse()
|
||||
.assertAdmin(aBoolean -> assertThat(aBoolean).isEqualTo(Boolean.TRUE))
|
||||
.assertPassword(Assert::assertNull)
|
||||
.assertType(s -> assertThat(s).isEqualTo(type))
|
||||
|
||||
@@ -2,11 +2,10 @@ package sonia.scm.it.utils;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.Response;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.junit.Assert;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.ConnectException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
@@ -27,8 +26,6 @@ import static sonia.scm.it.utils.TestData.createPasswordChangeJson;
|
||||
*/
|
||||
public class ScmRequests {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ScmRequests.class);
|
||||
|
||||
private String url;
|
||||
private String username;
|
||||
private String password;
|
||||
@@ -37,8 +34,10 @@ public class ScmRequests {
|
||||
return new ScmRequests();
|
||||
}
|
||||
|
||||
public Given given() {
|
||||
return new Given();
|
||||
public IndexResponse requestIndexResource(String username, String password) {
|
||||
setUsername(username);
|
||||
setPassword(password);
|
||||
return new IndexResponse(applyGETRequest(RestUtil.REST_BASE_URL.toString()));
|
||||
}
|
||||
|
||||
|
||||
@@ -50,26 +49,53 @@ public class ScmRequests {
|
||||
* @return the response of the GET request using the given link
|
||||
*/
|
||||
private Response applyGETRequestFromLink(Response response, String linkPropertyName) {
|
||||
String result = response
|
||||
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
|
||||
* @param params query params eg. ?q=xyz&count=12 or path params eg. namespace/name
|
||||
* @return the response of the GET request using the given link
|
||||
*/
|
||||
private Response applyGETRequestFromLinkWithParams(Response response, String linkPropertyName, String params) {
|
||||
String url = response
|
||||
.then()
|
||||
.extract()
|
||||
.path(linkPropertyName);
|
||||
LOG.info("Extracted result {} from response: {}", linkPropertyName, result);
|
||||
return applyGETRequest(result);
|
||||
Assert.assertNotNull("no url found for link " + linkPropertyName, url);
|
||||
return applyGETRequestWithQueryParams(url, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a GET Request to the given <code>url</code> and return the response.
|
||||
*
|
||||
* @param url the url of the GET request
|
||||
* @param params query params eg. ?q=xyz&count=12 or path params eg. namespace/name
|
||||
* @return the response of the GET request using the given <code>url</code>
|
||||
*/
|
||||
private Response applyGETRequestWithQueryParams(String url, String params) {
|
||||
try {
|
||||
return RestAssured.given()
|
||||
.auth().preemptive().basic(username, password)
|
||||
.when()
|
||||
.get(url + params);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 RestAssured.given()
|
||||
.auth().preemptive().basic(username, password)
|
||||
.when()
|
||||
.get(url);
|
||||
return applyGETRequestWithQueryParams(url, "");
|
||||
}
|
||||
|
||||
|
||||
@@ -107,11 +133,6 @@ public class ScmRequests {
|
||||
.put(url);
|
||||
}
|
||||
|
||||
|
||||
private void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
private void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
@@ -120,284 +141,185 @@ public class ScmRequests {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
private String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
private String getUsername() {
|
||||
return username;
|
||||
}
|
||||
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";
|
||||
|
||||
private String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public class Given {
|
||||
|
||||
public GivenUrl url(String url) {
|
||||
setUrl(url);
|
||||
return new GivenUrl();
|
||||
public IndexResponse(Response response) {
|
||||
super(response, null);
|
||||
}
|
||||
|
||||
public GivenUrl url(URI url) {
|
||||
setUrl(url.toString());
|
||||
return new GivenUrl();
|
||||
public AutoCompleteResponse<IndexResponse> requestAutoCompleteUsers(String q) {
|
||||
return new AutoCompleteResponse<>(applyGETRequestFromLinkWithParams(response, LINK_AUTOCOMPLETE_USERS, "?q=" + q), this);
|
||||
}
|
||||
|
||||
public AutoCompleteResponse<IndexResponse> requestAutoCompleteGroups(String q) {
|
||||
return new AutoCompleteResponse<>(applyGETRequestFromLinkWithParams(response, LINK_AUTOCOMPLETE_GROUPS, "?q=" + q), this);
|
||||
}
|
||||
|
||||
public RepositoryResponse<IndexResponse> requestRepository(String namespace, String name) {
|
||||
return new RepositoryResponse<>(applyGETRequestFromLinkWithParams(response, LINK_REPOSITORIES, namespace + "/" + name), this);
|
||||
}
|
||||
|
||||
public MeResponse<IndexResponse> requestMe() {
|
||||
return new MeResponse<>(applyGETRequestFromLink(response, LINK_ME), this);
|
||||
}
|
||||
|
||||
public UserResponse<IndexResponse> requestUser(String username) {
|
||||
return new UserResponse<>(applyGETRequestFromLinkWithParams(response, LINK_USERS, username), this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class GivenWithUrlAndAuth {
|
||||
public AppliedMeRequest getMeResource() {
|
||||
return new AppliedMeRequest(applyGETRequest(url));
|
||||
public class RepositoryResponse<PREV extends ModelResponse> extends ModelResponse<RepositoryResponse<PREV>, PREV> {
|
||||
|
||||
|
||||
public static final String LINKS_SOURCES = "_links.sources.href";
|
||||
public static final String LINKS_CHANGESETS = "_links.changesets.href";
|
||||
|
||||
public RepositoryResponse(Response response, PREV previousResponse) {
|
||||
super(response, previousResponse);
|
||||
}
|
||||
|
||||
public AppliedUserRequest getUserResource() {
|
||||
return new AppliedUserRequest(applyGETRequest(url));
|
||||
public SourcesResponse<RepositoryResponse> requestSources() {
|
||||
return new SourcesResponse<>(applyGETRequestFromLink(response, LINKS_SOURCES), this);
|
||||
}
|
||||
|
||||
public AppliedRepositoryRequest getRepositoryResource() {
|
||||
return new AppliedRepositoryRequest(
|
||||
applyGETRequest(url)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class AppliedRequest<SELF extends AppliedRequest> {
|
||||
private Response response;
|
||||
|
||||
public AppliedRequest(Response response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
/**
|
||||
* apply custom assertions to the actual response
|
||||
*
|
||||
* @param consumer consume the response in order to assert the content. the header, the payload etc..
|
||||
* @return the self object
|
||||
*/
|
||||
public SELF assertResponse(Consumer<Response> consumer) {
|
||||
consumer.accept(response);
|
||||
return (SELF) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
public ChangesetsResponse<RepositoryResponse> requestChangesets() {
|
||||
return new ChangesetsResponse<>(applyGETRequestFromLink(response, LINKS_CHANGESETS), this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AppliedRepositoryRequest extends AppliedRequest<AppliedRepositoryRequest> {
|
||||
public class ChangesetsResponse<PREV extends ModelResponse> extends ModelResponse<ChangesetsResponse<PREV>, PREV> {
|
||||
|
||||
public AppliedRepositoryRequest(Response response) {
|
||||
super(response);
|
||||
}
|
||||
|
||||
public RepositoryResponse usingRepositoryResponse() {
|
||||
return new RepositoryResponse(super.response);
|
||||
}
|
||||
}
|
||||
|
||||
public class RepositoryResponse {
|
||||
|
||||
private Response repositoryResponse;
|
||||
|
||||
public RepositoryResponse(Response repositoryResponse) {
|
||||
this.repositoryResponse = repositoryResponse;
|
||||
}
|
||||
|
||||
public AppliedSourcesRequest requestSources() {
|
||||
return new AppliedSourcesRequest(applyGETRequestFromLink(repositoryResponse, "_links.sources.href"));
|
||||
}
|
||||
|
||||
public AppliedChangesetsRequest requestChangesets() {
|
||||
return new AppliedChangesetsRequest(applyGETRequestFromLink(repositoryResponse, "_links.changesets.href"));
|
||||
}
|
||||
}
|
||||
|
||||
public class AppliedChangesetsRequest extends AppliedRequest<AppliedChangesetsRequest> {
|
||||
|
||||
public AppliedChangesetsRequest(Response response) {
|
||||
super(response);
|
||||
}
|
||||
|
||||
public ChangesetsResponse usingChangesetsResponse() {
|
||||
return new ChangesetsResponse(super.response);
|
||||
}
|
||||
}
|
||||
|
||||
public class ChangesetsResponse {
|
||||
private Response changesetsResponse;
|
||||
|
||||
public ChangesetsResponse(Response changesetsResponse) {
|
||||
this.changesetsResponse = changesetsResponse;
|
||||
public ChangesetsResponse(Response response, PREV previousResponse) {
|
||||
super(response, previousResponse);
|
||||
}
|
||||
|
||||
public ChangesetsResponse assertChangesets(Consumer<List<Map>> changesetsConsumer) {
|
||||
List<Map> changesets = changesetsResponse.then().extract().path("_embedded.changesets");
|
||||
List<Map> changesets = response.then().extract().path("_embedded.changesets");
|
||||
changesetsConsumer.accept(changesets);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AppliedDiffRequest requestDiff(String revision) {
|
||||
return new AppliedDiffRequest(applyGETRequestFromLink(changesetsResponse, "_embedded.changesets.find{it.id=='" + revision + "'}._links.diff.href"));
|
||||
public DiffResponse<ChangesetsResponse> requestDiff(String revision) {
|
||||
return new DiffResponse<>(applyGETRequestFromLink(response, "_embedded.changesets.find{it.id=='" + revision + "'}._links.diff.href"), this);
|
||||
}
|
||||
|
||||
public AppliedModificationsRequest requestModifications(String revision) {
|
||||
return new AppliedModificationsRequest(applyGETRequestFromLink(changesetsResponse, "_embedded.changesets.find{it.id=='" + revision + "'}._links.modifications.href"));
|
||||
public ModificationsResponse<ChangesetsResponse> requestModifications(String revision) {
|
||||
return new ModificationsResponse<>(applyGETRequestFromLink(response, "_embedded.changesets.find{it.id=='" + revision + "'}._links.modifications.href"), this);
|
||||
}
|
||||
}
|
||||
|
||||
public class AppliedSourcesRequest extends AppliedRequest<AppliedSourcesRequest> {
|
||||
|
||||
public AppliedSourcesRequest(Response sourcesResponse) {
|
||||
super(sourcesResponse);
|
||||
public class SourcesResponse<PREV extends ModelResponse> extends ModelResponse<SourcesResponse<PREV>, PREV> {
|
||||
|
||||
public SourcesResponse(Response response, PREV previousResponse) {
|
||||
super(response, previousResponse);
|
||||
}
|
||||
|
||||
public SourcesResponse usingSourcesResponse() {
|
||||
return new SourcesResponse(super.response);
|
||||
}
|
||||
}
|
||||
|
||||
public class SourcesResponse {
|
||||
|
||||
private Response sourcesResponse;
|
||||
|
||||
public SourcesResponse(Response sourcesResponse) {
|
||||
this.sourcesResponse = sourcesResponse;
|
||||
}
|
||||
|
||||
public AppliedChangesetsRequest requestFileHistory(String fileName) {
|
||||
return new AppliedChangesetsRequest(applyGETRequestFromLink(sourcesResponse, "_embedded.children.find{it.name=='" + fileName + "'}._links.history.href"));
|
||||
}
|
||||
|
||||
public AppliedSourcesRequest requestSelf(String fileName) {
|
||||
return new AppliedSourcesRequest(applyGETRequestFromLink(sourcesResponse, "_embedded.children.find{it.name=='" + fileName + "'}._links.self.href"));
|
||||
}
|
||||
}
|
||||
|
||||
public class AppliedDiffRequest extends AppliedRequest<AppliedDiffRequest> {
|
||||
|
||||
public AppliedDiffRequest(Response response) {
|
||||
super(response);
|
||||
}
|
||||
}
|
||||
|
||||
public class GivenUrl {
|
||||
|
||||
public GivenWithUrlAndAuth usernameAndPassword(String username, String password) {
|
||||
setUsername(username);
|
||||
setPassword(password);
|
||||
return new GivenWithUrlAndAuth();
|
||||
}
|
||||
}
|
||||
|
||||
public class AppliedModificationsRequest extends AppliedRequest<AppliedModificationsRequest> {
|
||||
public AppliedModificationsRequest(Response response) {
|
||||
super(response);
|
||||
}
|
||||
|
||||
public ModificationsResponse usingModificationsResponse() {
|
||||
return new ModificationsResponse(super.response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ModificationsResponse {
|
||||
private Response resource;
|
||||
|
||||
public ModificationsResponse(Response resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public ModificationsResponse assertRevision(Consumer<String> assertRevision) {
|
||||
String revision = resource.then().extract().path("revision");
|
||||
public SourcesResponse assertRevision(Consumer<String> assertRevision) {
|
||||
String revision = response.then().extract().path("revision");
|
||||
assertRevision.accept(revision);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModificationsResponse assertAdded(Consumer<List<String>> assertAdded) {
|
||||
List<String> added = resource.then().extract().path("added");
|
||||
public SourcesResponse assertFiles(Consumer<List> assertFiles) {
|
||||
List files = response.then().extract().path("files");
|
||||
assertFiles.accept(files);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChangesetsResponse<SourcesResponse> requestFileHistory(String fileName) {
|
||||
return new ChangesetsResponse<>(applyGETRequestFromLink(response, "_embedded.children.find{it.name=='" + fileName + "'}._links.history.href"), this);
|
||||
}
|
||||
|
||||
public SourcesResponse<SourcesResponse> requestSelf(String fileName) {
|
||||
return new SourcesResponse<>(applyGETRequestFromLink(response, "_embedded.children.find{it.name=='" + fileName + "'}._links.self.href"), this);
|
||||
}
|
||||
}
|
||||
|
||||
public class ModificationsResponse<PREV extends ModelResponse> extends ModelResponse<ModificationsResponse<PREV>, PREV> {
|
||||
|
||||
public ModificationsResponse(Response response, PREV previousResponse) {
|
||||
super(response, previousResponse);
|
||||
}
|
||||
|
||||
public ModificationsResponse<PREV> assertRevision(Consumer<String> assertRevision) {
|
||||
String revision = response.then().extract().path("revision");
|
||||
assertRevision.accept(revision);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModificationsResponse<PREV> assertAdded(Consumer<List<String>> assertAdded) {
|
||||
List<String> added = response.then().extract().path("added");
|
||||
assertAdded.accept(added);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModificationsResponse assertRemoved(Consumer<List<String>> assertRemoved) {
|
||||
List<String> removed = resource.then().extract().path("removed");
|
||||
public ModificationsResponse<PREV> assertRemoved(Consumer<List<String>> assertRemoved) {
|
||||
List<String> removed = response.then().extract().path("removed");
|
||||
assertRemoved.accept(removed);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModificationsResponse assertModified(Consumer<List<String>> assertModified) {
|
||||
List<String> modified = resource.then().extract().path("modified");
|
||||
public ModificationsResponse<PREV> assertModified(Consumer<List<String>> assertModified) {
|
||||
List<String> modified = response.then().extract().path("modified");
|
||||
assertModified.accept(modified);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AppliedMeRequest extends AppliedRequest<AppliedMeRequest> {
|
||||
|
||||
public AppliedMeRequest(Response response) {
|
||||
super(response);
|
||||
}
|
||||
|
||||
public MeResponse usingMeResponse() {
|
||||
return new MeResponse(super.response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MeResponse extends UserResponse<MeResponse> {
|
||||
public class MeResponse<PREV extends ModelResponse> extends UserResponse<PREV> {
|
||||
|
||||
|
||||
public MeResponse(Response response) {
|
||||
super(response);
|
||||
}
|
||||
|
||||
public AppliedChangePasswordRequest requestChangePassword(String oldPassword, String newPassword) {
|
||||
return new AppliedChangePasswordRequest(applyPUTRequestFromLink(super.response, "_links.password.href", VndMediaType.PASSWORD_CHANGE, createPasswordChangeJson(oldPassword, newPassword)));
|
||||
public MeResponse(Response response, PREV previousResponse) {
|
||||
super(response, previousResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class UserResponse<SELF extends UserResponse> extends ModelResponse<SELF> {
|
||||
public class UserResponse<PREV extends ModelResponse> extends ModelResponse<UserResponse<PREV>, PREV> {
|
||||
|
||||
public static final String LINKS_PASSWORD_HREF = "_links.password.href";
|
||||
|
||||
public UserResponse(Response response) {
|
||||
super(response);
|
||||
public UserResponse(Response response, PREV previousResponse) {
|
||||
super(response, previousResponse);
|
||||
}
|
||||
|
||||
public SELF assertPassword(Consumer<String> assertPassword) {
|
||||
public UserResponse<PREV> assertPassword(Consumer<String> assertPassword) {
|
||||
return super.assertSingleProperty(assertPassword, "password");
|
||||
}
|
||||
|
||||
public SELF assertType(Consumer<String> assertType) {
|
||||
public UserResponse<PREV> assertType(Consumer<String> assertType) {
|
||||
return assertSingleProperty(assertType, "type");
|
||||
}
|
||||
|
||||
public SELF assertAdmin(Consumer<Boolean> assertAdmin) {
|
||||
public UserResponse<PREV> assertAdmin(Consumer<Boolean> assertAdmin) {
|
||||
return assertSingleProperty(assertAdmin, "admin");
|
||||
}
|
||||
|
||||
public SELF assertPasswordLinkDoesNotExists() {
|
||||
public UserResponse<PREV> assertPasswordLinkDoesNotExists() {
|
||||
return assertPropertyPathDoesNotExists(LINKS_PASSWORD_HREF);
|
||||
}
|
||||
|
||||
public SELF assertPasswordLinkExists() {
|
||||
public UserResponse<PREV> assertPasswordLinkExists() {
|
||||
return assertPropertyPathExists(LINKS_PASSWORD_HREF);
|
||||
}
|
||||
|
||||
public AppliedChangePasswordRequest requestChangePassword(String newPassword) {
|
||||
return new AppliedChangePasswordRequest(applyPUTRequestFromLink(super.response, LINKS_PASSWORD_HREF, VndMediaType.PASSWORD_CHANGE, createPasswordChangeJson(null, newPassword)));
|
||||
public ChangePasswordResponse<UserResponse> requestChangePassword(String newPassword) {
|
||||
return requestChangePassword(null, newPassword);
|
||||
}
|
||||
|
||||
public ChangePasswordResponse<UserResponse> requestChangePassword(String oldPassword, String newPassword) {
|
||||
return new ChangePasswordResponse<>(applyPUTRequestFromLink(super.response, LINKS_PASSWORD_HREF, VndMediaType.PASSWORD_CHANGE, createPasswordChangeJson(oldPassword, newPassword)), this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -406,12 +328,18 @@ public class ScmRequests {
|
||||
/**
|
||||
* encapsulate standard assertions over model properties
|
||||
*/
|
||||
public class ModelResponse<SELF extends ModelResponse> {
|
||||
public class ModelResponse<SELF extends ModelResponse<SELF, PREV>, PREV extends ModelResponse> {
|
||||
|
||||
protected PREV previousResponse;
|
||||
protected Response response;
|
||||
|
||||
public ModelResponse(Response response) {
|
||||
public ModelResponse(Response response, PREV previousResponse) {
|
||||
this.response = response;
|
||||
this.previousResponse = previousResponse;
|
||||
}
|
||||
|
||||
public PREV returnToPrevious() {
|
||||
return previousResponse;
|
||||
}
|
||||
|
||||
public <T> SELF assertSingleProperty(Consumer<T> assertSingleProperty, String propertyJsonPath) {
|
||||
@@ -435,25 +363,45 @@ public class ScmRequests {
|
||||
assertProperties.accept(properties);
|
||||
return (SELF) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
public class AppliedChangePasswordRequest extends AppliedRequest<AppliedChangePasswordRequest> {
|
||||
public class AutoCompleteResponse<PREV extends ModelResponse> extends ModelResponse<AutoCompleteResponse<PREV>, PREV> {
|
||||
|
||||
public AppliedChangePasswordRequest(Response response) {
|
||||
super(response);
|
||||
public AutoCompleteResponse(Response response, PREV previousResponse) {
|
||||
super(response, previousResponse);
|
||||
}
|
||||
|
||||
public AutoCompleteResponse<PREV> assertAutoCompleteResults(Consumer<List<Map>> checker) {
|
||||
List<Map> result = response.then().extract().path("");
|
||||
checker.accept(result);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AppliedUserRequest extends AppliedRequest<AppliedUserRequest> {
|
||||
|
||||
public AppliedUserRequest(Response response) {
|
||||
super(response);
|
||||
public class DiffResponse<PREV extends ModelResponse> extends ModelResponse<DiffResponse<PREV>, PREV> {
|
||||
|
||||
public DiffResponse(Response response, PREV previousResponse) {
|
||||
super(response, previousResponse);
|
||||
}
|
||||
}
|
||||
|
||||
public UserResponse usingUserResponse() {
|
||||
return new UserResponse(super.response);
|
||||
public class ChangePasswordResponse<PREV extends ModelResponse> extends ModelResponse<ChangePasswordResponse<PREV>, PREV> {
|
||||
|
||||
public ChangePasswordResponse(Response response, PREV previousResponse) {
|
||||
super(response, previousResponse);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,11 +46,11 @@ public class TestData {
|
||||
return DEFAULT_REPOSITORIES.get(repositoryType);
|
||||
}
|
||||
|
||||
public static void createUser(String username, String password) {
|
||||
createUser(username, password, false, "xml");
|
||||
public static void createNotAdminUser(String username, String password) {
|
||||
createUser(username, password, false, "xml", "user1@scm-manager.org");
|
||||
}
|
||||
|
||||
public static void createUser(String username, String password, boolean isAdmin, String type) {
|
||||
public static void createUser(String username, String password, boolean isAdmin, String type, final String email) {
|
||||
LOG.info("create user with username: {}", username);
|
||||
String admin = isAdmin ? "true" : "false";
|
||||
given(VndMediaType.USER)
|
||||
@@ -61,7 +61,7 @@ public class TestData {
|
||||
.append(" \"admin\": ").append(admin).append(",\n")
|
||||
.append(" \"creationDate\": \"2018-08-21T12:26:46.084Z\",\n")
|
||||
.append(" \"displayName\": \"").append(username).append("\",\n")
|
||||
.append(" \"mail\": \"user1@scm-manager.org\",\n")
|
||||
.append(" \"mail\": \"" + email + "\",\n")
|
||||
.append(" \"name\": \"").append(username).append("\",\n")
|
||||
.append(" \"password\": \"").append(password).append("\",\n")
|
||||
.append(" \"type\": \"").append(type).append("\"\n")
|
||||
@@ -71,6 +71,16 @@ public class TestData {
|
||||
.statusCode(HttpStatus.SC_CREATED)
|
||||
;
|
||||
}
|
||||
public static void createGroup(String groupName, String desc) {
|
||||
LOG.info("create group with group name: {} and description {}", groupName, desc);
|
||||
given(VndMediaType.GROUP)
|
||||
.when()
|
||||
.content(getGroupJson(groupName,desc))
|
||||
.post(getGroupsUrl())
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_CREATED)
|
||||
;
|
||||
}
|
||||
|
||||
public static void createUserPermission(String name, PermissionType permissionType, String repositoryType) {
|
||||
String defaultPermissionUrl = TestData.getDefaultPermissionUrl(USER_SCM_ADMIN, USER_SCM_ADMIN, repositoryType);
|
||||
@@ -193,28 +203,31 @@ public class TestData {
|
||||
return JSON_BUILDER
|
||||
.add("contact", "zaphod.beeblebrox@hitchhiker.com")
|
||||
.add("description", "Heart of Gold")
|
||||
.add("name", "HeartOfGold-" + repositoryType)
|
||||
.add("name", getDefaultRepoName(repositoryType))
|
||||
.add("archived", false)
|
||||
.add("type", repositoryType)
|
||||
.build().toString();
|
||||
}
|
||||
|
||||
public static URI getMeUrl() {
|
||||
return RestUtil.createResourceUrl("me/");
|
||||
public static String getDefaultRepoName(String repositoryType) {
|
||||
return "HeartOfGold-" + repositoryType;
|
||||
}
|
||||
|
||||
public static String getGroupJson(String groupname , String desc) {
|
||||
return JSON_BUILDER
|
||||
.add("name", groupname)
|
||||
.add("description", desc)
|
||||
.build().toString();
|
||||
}
|
||||
|
||||
public static URI getGroupsUrl() {
|
||||
return RestUtil.createResourceUrl("groups/");
|
||||
}
|
||||
|
||||
public static URI getUsersUrl() {
|
||||
return RestUtil.createResourceUrl("users/");
|
||||
|
||||
}
|
||||
|
||||
public static URI getUserUrl(String username) {
|
||||
return getUsersUrl().resolve(username);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String createPasswordChangeJson(String oldPassword, String newPassword) {
|
||||
return JSON_BUILDER
|
||||
.add("oldPassword", oldPassword)
|
||||
@@ -225,4 +238,5 @@ public class TestData {
|
||||
public static void main(String[] args) {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user