2018-08-15 11:44:20 +02:00
|
|
|
package sonia.scm.it;
|
|
|
|
|
|
2018-09-04 17:38:28 +02:00
|
|
|
import io.restassured.response.ExtractableResponse;
|
|
|
|
|
import io.restassured.response.Response;
|
2018-08-15 11:44:20 +02:00
|
|
|
import org.apache.http.HttpStatus;
|
2018-09-13 17:29:52 +02:00
|
|
|
import org.assertj.core.util.Lists;
|
2018-08-24 07:57:13 +02:00
|
|
|
import org.junit.Assume;
|
2018-08-15 11:44:20 +02:00
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.rules.TemporaryFolder;
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.junit.runners.Parameterized;
|
2018-09-10 09:51:59 +02:00
|
|
|
import sonia.scm.repository.Changeset;
|
2018-08-24 07:57:13 +02:00
|
|
|
import sonia.scm.repository.client.api.ClientCommand;
|
2018-08-22 09:18:17 +02:00
|
|
|
import sonia.scm.repository.client.api.RepositoryClient;
|
2018-09-04 17:38:28 +02:00
|
|
|
import sonia.scm.web.VndMediaType;
|
2018-08-15 11:44:20 +02:00
|
|
|
|
2018-08-22 09:18:17 +02:00
|
|
|
import java.io.File;
|
2018-08-15 11:44:20 +02:00
|
|
|
import java.io.IOException;
|
2018-09-13 17:29:52 +02:00
|
|
|
import java.util.ArrayList;
|
2018-08-15 11:44:20 +02:00
|
|
|
import java.util.Collection;
|
2018-09-13 17:29:52 +02:00
|
|
|
import java.util.HashMap;
|
2018-08-29 13:34:53 +02:00
|
|
|
import java.util.List;
|
2018-09-13 17:29:52 +02:00
|
|
|
import java.util.Map;
|
2018-08-15 11:44:20 +02:00
|
|
|
|
2018-08-17 09:33:45 +02:00
|
|
|
import static java.lang.Thread.sleep;
|
2018-09-10 09:51:59 +02:00
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
2018-08-17 09:33:45 +02:00
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
2018-08-15 11:44:20 +02:00
|
|
|
import static org.junit.Assert.assertNotNull;
|
2018-09-10 09:51:59 +02:00
|
|
|
import static sonia.scm.it.RestUtil.ADMIN_PASSWORD;
|
|
|
|
|
import static sonia.scm.it.RestUtil.ADMIN_USERNAME;
|
2018-08-15 11:44:20 +02:00
|
|
|
import static sonia.scm.it.RestUtil.given;
|
|
|
|
|
import static sonia.scm.it.ScmTypes.availableScmTypes;
|
|
|
|
|
|
|
|
|
|
@RunWith(Parameterized.class)
|
|
|
|
|
public class RepositoryAccessITCase {
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
|
public TemporaryFolder tempFolder = new TemporaryFolder();
|
|
|
|
|
|
|
|
|
|
private final String repositoryType;
|
2018-08-22 09:18:17 +02:00
|
|
|
private File folder;
|
2018-09-10 09:51:59 +02:00
|
|
|
private RepositoryRequests.AppliedRepositoryGetRequest repositoryGetRequest;
|
2018-08-15 11:44:20 +02:00
|
|
|
|
|
|
|
|
public RepositoryAccessITCase(String repositoryType) {
|
|
|
|
|
this.repositoryType = repositoryType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Parameterized.Parameters(name = "{0}")
|
|
|
|
|
public static Collection<String> createParameters() {
|
|
|
|
|
return availableScmTypes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Before
|
2018-09-10 09:51:59 +02:00
|
|
|
public void init() {
|
2018-08-15 11:44:20 +02:00
|
|
|
TestData.createDefault();
|
2018-08-22 09:18:17 +02:00
|
|
|
folder = tempFolder.getRoot();
|
2018-09-10 09:51:59 +02:00
|
|
|
repositoryGetRequest = RepositoryRequests.start()
|
|
|
|
|
.given()
|
|
|
|
|
.url(TestData.getDefaultRepositoryUrl(repositoryType))
|
|
|
|
|
.usernameAndPassword(ADMIN_USERNAME, ADMIN_PASSWORD)
|
|
|
|
|
.get()
|
|
|
|
|
.assertStatusCode(HttpStatus.SC_OK);
|
2018-08-15 11:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void shouldFindBranches() throws IOException {
|
2018-08-22 10:59:46 +02:00
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
2018-08-15 11:44:20 +02:00
|
|
|
|
2018-08-24 07:57:13 +02:00
|
|
|
Assume.assumeTrue("There are no branches for " + repositoryType, repositoryClient.isCommandSupported(ClientCommand.BRANCH));
|
|
|
|
|
|
2018-08-22 10:59:46 +02:00
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, "scmadmin", "a.txt", "a");
|
2018-08-15 11:44:20 +02:00
|
|
|
|
|
|
|
|
String branchesUrl = given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(TestData.getDefaultRepositoryUrl(repositoryType))
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
|
|
|
|
.path("_links.branches.href");
|
|
|
|
|
|
|
|
|
|
Object branchName = given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(branchesUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
|
|
|
|
.path("_embedded.branches[0].name");
|
|
|
|
|
|
|
|
|
|
assertNotNull(branchName);
|
|
|
|
|
}
|
2018-08-17 09:33:45 +02:00
|
|
|
|
2018-09-04 17:38:28 +02:00
|
|
|
@Test
|
|
|
|
|
public void shouldFindTags() throws IOException {
|
|
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
|
|
|
|
|
|
|
|
|
Assume.assumeTrue("There are no tags for " + repositoryType, repositoryClient.isCommandSupported(ClientCommand.TAG));
|
|
|
|
|
|
|
|
|
|
Changeset changeset = RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, "a.txt", "a");
|
|
|
|
|
|
|
|
|
|
String tagName = "v1.0";
|
|
|
|
|
String repositoryUrl = TestData.getDefaultRepositoryUrl(repositoryType);
|
|
|
|
|
String tagsUrl = given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(repositoryUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
|
|
|
|
.path("_links.tags.href");
|
|
|
|
|
|
|
|
|
|
ExtractableResponse<Response> response = given(VndMediaType.TAG_COLLECTION, ADMIN_USERNAME, ADMIN_PASSWORD)
|
|
|
|
|
.when()
|
|
|
|
|
.get(tagsUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract();
|
|
|
|
|
|
|
|
|
|
assertThat(response).isNotNull();
|
|
|
|
|
assertThat(response.body()).isNotNull();
|
|
|
|
|
assertThat(response.body().asString())
|
|
|
|
|
.isNotNull()
|
2018-09-06 10:41:49 +02:00
|
|
|
.isNotBlank();
|
2018-09-04 17:38:28 +02:00
|
|
|
|
|
|
|
|
RepositoryUtil.addTag(repositoryClient, changeset.getId(), tagName);
|
|
|
|
|
response = given(VndMediaType.TAG_COLLECTION, ADMIN_USERNAME, ADMIN_PASSWORD)
|
|
|
|
|
.when()
|
|
|
|
|
.get(tagsUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
2018-09-06 10:41:49 +02:00
|
|
|
.extract();
|
2018-09-04 17:38:28 +02:00
|
|
|
|
|
|
|
|
assertThat(response).isNotNull();
|
|
|
|
|
assertThat(response.body()).isNotNull();
|
|
|
|
|
assertThat(response.body().asString())
|
|
|
|
|
.isNotNull()
|
2018-09-06 10:41:49 +02:00
|
|
|
.isNotBlank();
|
|
|
|
|
|
2018-09-04 17:38:28 +02:00
|
|
|
assertThat(response.body().jsonPath().getString("_links.self.href"))
|
|
|
|
|
.as("assert tags self link")
|
|
|
|
|
.isNotNull()
|
2018-09-06 10:41:49 +02:00
|
|
|
.contains(repositoryUrl + "/tags/");
|
|
|
|
|
|
2018-09-04 17:38:28 +02:00
|
|
|
assertThat(response.body().jsonPath().getList("_embedded.tags"))
|
|
|
|
|
.as("assert tag size")
|
|
|
|
|
.isNotNull()
|
|
|
|
|
.size()
|
2018-09-06 10:41:49 +02:00
|
|
|
.isGreaterThan(0);
|
|
|
|
|
|
2018-09-04 17:38:28 +02:00
|
|
|
assertThat(response.body().jsonPath().getMap("_embedded.tags.find{it.name=='" + tagName + "'}"))
|
|
|
|
|
.as("assert tag name and revision")
|
|
|
|
|
.isNotNull()
|
|
|
|
|
.hasSize(3)
|
|
|
|
|
.containsEntry("name", tagName)
|
2018-09-06 10:41:49 +02:00
|
|
|
.containsEntry("revision", changeset.getId());
|
|
|
|
|
|
2018-09-04 17:38:28 +02:00
|
|
|
assertThat(response.body().jsonPath().getString("_embedded.tags.find{it.name=='" + tagName + "'}._links.self.href"))
|
|
|
|
|
.as("assert single tag self link")
|
|
|
|
|
.isNotNull()
|
2018-09-06 10:41:49 +02:00
|
|
|
.contains(String.format("%s/tags/%s", repositoryUrl, tagName));
|
|
|
|
|
|
2018-09-04 17:38:28 +02:00
|
|
|
assertThat(response.body().jsonPath().getString("_embedded.tags.find{it.name=='" + tagName + "'}._links.sources.href"))
|
|
|
|
|
.as("assert single tag source link")
|
|
|
|
|
.isNotNull()
|
2018-09-06 10:41:49 +02:00
|
|
|
.contains(String.format("%s/sources/%s", repositoryUrl, changeset.getId()));
|
|
|
|
|
|
2018-09-04 17:38:28 +02:00
|
|
|
assertThat(response.body().jsonPath().getString("_embedded.tags.find{it.name=='" + tagName + "'}._links.changesets.href"))
|
|
|
|
|
.as("assert single tag changesets link")
|
|
|
|
|
.isNotNull()
|
2018-09-06 10:41:49 +02:00
|
|
|
.contains(String.format("%s/changesets/%s", repositoryUrl, changeset.getId()));
|
2018-09-04 17:38:28 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-17 09:33:45 +02:00
|
|
|
@Test
|
|
|
|
|
public void shouldReadContent() throws IOException, InterruptedException {
|
2018-08-28 12:43:56 +02:00
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, "scmadmin", "a.txt", "a");
|
2018-08-23 15:52:02 +02:00
|
|
|
tempFolder.newFolder("subfolder");
|
2018-08-28 12:43:56 +02:00
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, "scmadmin", "subfolder/a.txt", "sub-a");
|
2018-08-17 09:33:45 +02:00
|
|
|
|
|
|
|
|
sleep(1000);
|
|
|
|
|
|
|
|
|
|
String sourcesUrl = given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(TestData.getDefaultRepositoryUrl(repositoryType))
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
|
|
|
|
.path("_links.sources.href");
|
|
|
|
|
|
2018-08-23 15:52:02 +02:00
|
|
|
String rootContentUrl = given()
|
2018-08-17 09:33:45 +02:00
|
|
|
.when()
|
|
|
|
|
.get(sourcesUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
2018-09-05 15:17:49 +02:00
|
|
|
.path("_embedded.files.find{it.name=='a.txt'}._links.self.href");
|
2018-09-03 15:36:09 +02:00
|
|
|
|
2018-08-17 09:33:45 +02:00
|
|
|
given()
|
|
|
|
|
.when()
|
2018-08-23 15:52:02 +02:00
|
|
|
.get(rootContentUrl)
|
2018-08-17 09:33:45 +02:00
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.body(equalTo("a"));
|
2018-08-23 15:52:02 +02:00
|
|
|
|
|
|
|
|
String subfolderSourceUrl = given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(sourcesUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
2018-09-05 15:17:49 +02:00
|
|
|
.path("_embedded.files.find{it.name=='subfolder'}._links.self.href");
|
2018-09-03 15:36:09 +02:00
|
|
|
String selfOfSubfolderUrl = given()
|
2018-08-23 15:52:02 +02:00
|
|
|
.when()
|
|
|
|
|
.get(subfolderSourceUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
2018-09-03 15:36:09 +02:00
|
|
|
.path("_links.self.href");
|
|
|
|
|
assertThat(subfolderSourceUrl).isEqualTo(selfOfSubfolderUrl);
|
|
|
|
|
String subfolderContentUrl = given()
|
2018-08-23 15:52:02 +02:00
|
|
|
.when()
|
|
|
|
|
.get(subfolderSourceUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
2018-09-05 15:17:49 +02:00
|
|
|
.path("_embedded.files[0]._links.self.href");
|
2018-08-23 15:52:02 +02:00
|
|
|
given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(subfolderContentUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.body(equalTo("sub-a"));
|
2018-08-17 09:33:45 +02:00
|
|
|
}
|
2018-08-29 13:34:53 +02:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void shouldFindChangesets() throws IOException {
|
|
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
|
|
|
|
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, "scmadmin", "a.txt", "a");
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, "scmadmin", "b.txt", "b");
|
|
|
|
|
|
|
|
|
|
String changesetsUrl = given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(TestData.getDefaultRepositoryUrl(repositoryType))
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
|
|
|
|
.path("_links.changesets.href");
|
|
|
|
|
|
|
|
|
|
List changesets = given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(changesetsUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
|
|
|
|
.path("_embedded.changesets.id");
|
|
|
|
|
|
|
|
|
|
assertThat(changesets).size().isBetween(2, 3); // svn has an implicit root revision '0' that is extra to the two commits
|
|
|
|
|
}
|
2018-09-10 09:51:59 +02:00
|
|
|
|
2018-09-05 17:06:21 +02:00
|
|
|
@Test
|
|
|
|
|
public void shouldFindDiffs() throws IOException {
|
|
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
|
|
|
|
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, "scmadmin", "a.txt", "a");
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, "scmadmin", "b.txt", "b");
|
|
|
|
|
|
|
|
|
|
String changesetsUrl = given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(TestData.getDefaultRepositoryUrl(repositoryType))
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
|
|
|
|
.path("_links.changesets.href");
|
|
|
|
|
|
|
|
|
|
String diffUrl = given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(changesetsUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
|
|
|
|
.path("_embedded.changesets[0]._links.diff.href");
|
|
|
|
|
|
|
|
|
|
given()
|
|
|
|
|
.when()
|
|
|
|
|
.get(diffUrl)
|
|
|
|
|
.then()
|
|
|
|
|
.statusCode(HttpStatus.SC_OK)
|
|
|
|
|
.extract()
|
|
|
|
|
.body()
|
|
|
|
|
.asString()
|
|
|
|
|
.contains("diff");
|
|
|
|
|
|
|
|
|
|
}
|
2018-09-10 15:51:29 +02:00
|
|
|
|
2018-09-10 09:51:59 +02:00
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void shouldFindFileHistory() throws IOException {
|
|
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
2018-09-10 11:13:36 +02:00
|
|
|
Changeset changeset = RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, "folder/subfolder/a.txt", "a");
|
2018-09-10 09:51:59 +02:00
|
|
|
repositoryGetRequest
|
|
|
|
|
.usingRepositoryResponse()
|
|
|
|
|
.requestSources()
|
|
|
|
|
.usingSourcesResponse()
|
2018-09-10 11:13:36 +02:00
|
|
|
.requestSelf("folder")
|
|
|
|
|
.usingSourcesResponse()
|
|
|
|
|
.requestSelf("subfolder")
|
|
|
|
|
.usingSourcesResponse()
|
|
|
|
|
.requestFileHistory("a.txt")
|
2018-09-10 09:51:59 +02:00
|
|
|
.assertStatusCode(HttpStatus.SC_OK)
|
|
|
|
|
.usingChangesetsResponse()
|
|
|
|
|
.assertChangesets(changesets -> {
|
|
|
|
|
assertThat(changesets).hasSize(1);
|
2018-09-10 11:13:36 +02:00
|
|
|
assertThat(changesets.get(0)).containsEntry("id", changeset.getId());
|
|
|
|
|
assertThat(changesets.get(0)).containsEntry("description", changeset.getDescription());
|
2018-09-10 09:51:59 +02:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-09-13 17:29:52 +02:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void shouldFindAddedModifications() throws IOException {
|
|
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
|
|
|
|
String fileName = "a.txt";
|
|
|
|
|
Changeset changeset = RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, fileName, "a");
|
|
|
|
|
String revision = changeset.getId();
|
|
|
|
|
repositoryGetRequest
|
|
|
|
|
.usingRepositoryResponse()
|
|
|
|
|
.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)
|
|
|
|
|
.containsExactly(fileName))
|
|
|
|
|
.assertRemoved(removedFiles -> assertThat(removedFiles)
|
|
|
|
|
.hasSize(0))
|
|
|
|
|
.assertModified(files -> assertThat(files)
|
|
|
|
|
.hasSize(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void shouldFindRemovedModifications() throws IOException {
|
|
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
|
|
|
|
String fileName = "a.txt";
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, fileName, "a");
|
|
|
|
|
Changeset changeset = RepositoryUtil.removeAndCommitFile(repositoryClient, ADMIN_USERNAME, fileName);
|
|
|
|
|
|
|
|
|
|
String revision = changeset.getId();
|
|
|
|
|
repositoryGetRequest
|
|
|
|
|
.usingRepositoryResponse()
|
|
|
|
|
.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)
|
|
|
|
|
.containsExactly(fileName))
|
|
|
|
|
.assertAdded(addedFiles -> assertThat(addedFiles)
|
|
|
|
|
.hasSize(0))
|
|
|
|
|
.assertModified(files -> assertThat(files)
|
|
|
|
|
.hasSize(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void shouldFindUpdateModifications() throws IOException {
|
|
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
|
|
|
|
String fileName = "a.txt";
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, fileName, "a");
|
|
|
|
|
Changeset changeset = RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, fileName, "new Content");
|
|
|
|
|
|
|
|
|
|
String revision = changeset.getId();
|
|
|
|
|
repositoryGetRequest
|
|
|
|
|
.usingRepositoryResponse()
|
|
|
|
|
.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)
|
|
|
|
|
.containsExactly(fileName))
|
|
|
|
|
.assertRemoved(removedFiles -> assertThat(removedFiles)
|
|
|
|
|
.hasSize(0))
|
|
|
|
|
.assertAdded(addedFiles -> assertThat(addedFiles)
|
|
|
|
|
.hasSize(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void shouldFindMultipleModifications() throws IOException {
|
|
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, "b.txt", "b");
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, "c.txt", "c");
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, "d.txt", "d");
|
|
|
|
|
Map<String, String> addedFiles = new HashMap<String, String>()
|
|
|
|
|
{{
|
|
|
|
|
put("a.txt", "bla bla");
|
|
|
|
|
}};
|
|
|
|
|
Map<String, String> modifiedFiles = new HashMap<String, String>()
|
|
|
|
|
{{
|
|
|
|
|
put("b.txt", "new content");
|
|
|
|
|
}};
|
|
|
|
|
ArrayList<String> removedFiles = Lists.newArrayList("c.txt", "d.txt");
|
|
|
|
|
Changeset changeset = RepositoryUtil.commitMultipleFileModifications(repositoryClient, ADMIN_USERNAME, addedFiles, modifiedFiles, removedFiles);
|
|
|
|
|
|
|
|
|
|
String revision = changeset.getId();
|
|
|
|
|
repositoryGetRequest
|
|
|
|
|
.usingRepositoryResponse()
|
|
|
|
|
.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)
|
|
|
|
|
.containsExactly("a.txt"))
|
|
|
|
|
.assertModified(m-> assertThat(m)
|
|
|
|
|
.hasSize(1)
|
|
|
|
|
.containsExactly("b.txt"))
|
|
|
|
|
.assertRemoved(r -> assertThat(r)
|
|
|
|
|
.hasSize(2)
|
|
|
|
|
.containsExactly("c.txt", "d.txt"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void svnShouldCreateOneModificationPerFolder() throws IOException {
|
|
|
|
|
Assume.assumeThat(repositoryType, equalTo("svn"));
|
|
|
|
|
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, "bbb/bb/b.txt", "b");
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, "ccc/cc/c.txt", "c");
|
|
|
|
|
RepositoryUtil.createAndCommitFile(repositoryClient, ADMIN_USERNAME, "ddd/dd/d.txt", "d");
|
|
|
|
|
Map<String, String> addedFiles = new HashMap<String, String>()
|
|
|
|
|
{{
|
|
|
|
|
put("aaa/aa/a.txt", "bla bla");
|
|
|
|
|
}};
|
|
|
|
|
Map<String, String> modifiedFiles = new HashMap<String, String>()
|
|
|
|
|
{{
|
|
|
|
|
put("bbb/bb/b.txt", "new content");
|
|
|
|
|
}};
|
|
|
|
|
ArrayList<String> removedFiles = Lists.newArrayList("ccc/cc/c.txt", "ddd/dd/d.txt");
|
|
|
|
|
Changeset changeset = RepositoryUtil.commitMultipleFileModifications(repositoryClient, ADMIN_USERNAME, addedFiles, modifiedFiles, removedFiles);
|
|
|
|
|
|
|
|
|
|
String revision = changeset.getId();
|
|
|
|
|
repositoryGetRequest
|
|
|
|
|
.usingRepositoryResponse()
|
|
|
|
|
.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)
|
|
|
|
|
.containsExactly("aaa/aa/a.txt", "aaa", "aaa/aa"))
|
|
|
|
|
.assertModified(m-> assertThat(m)
|
|
|
|
|
.hasSize(1)
|
|
|
|
|
.containsExactly("bbb/bb/b.txt"))
|
|
|
|
|
.assertRemoved(r -> assertThat(r)
|
|
|
|
|
.hasSize(2)
|
|
|
|
|
.containsExactly("ccc/cc/c.txt", "ddd/dd/d.txt"));
|
|
|
|
|
}
|
2018-08-15 11:44:20 +02:00
|
|
|
}
|
2018-08-29 13:34:53 +02:00
|
|
|
|