Merged in feature/tag_endpoints_v2 (pull request #65)

add tag endpoints
This commit is contained in:
Philipp Czora
2018-09-06 08:44:04 +00:00
17 changed files with 468 additions and 50 deletions

View File

@@ -1,5 +1,7 @@
package sonia.scm.it;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.junit.Assume;
import org.junit.Before;
@@ -8,18 +10,22 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.client.api.ClientCommand;
import sonia.scm.repository.client.api.RepositoryClient;
import sonia.scm.web.VndMediaType;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static java.lang.Thread.sleep;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static sonia.scm.it.RestUtil.ADMIN_PASSWORD;
import static sonia.scm.it.RestUtil.ADMIN_USERNAME;
import static sonia.scm.it.RestUtil.given;
import static sonia.scm.it.ScmTypes.availableScmTypes;
@@ -74,6 +80,85 @@ public class RepositoryAccessITCase {
assertNotNull(branchName);
}
@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()
.isNotBlank();
RepositoryUtil.addTag(repositoryClient, changeset.getId(), tagName);
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()
.isNotBlank();
assertThat(response.body().jsonPath().getString("_links.self.href"))
.as("assert tags self link")
.isNotNull()
.contains(repositoryUrl + "/tags/");
assertThat(response.body().jsonPath().getList("_embedded.tags"))
.as("assert tag size")
.isNotNull()
.size()
.isGreaterThan(0);
assertThat(response.body().jsonPath().getMap("_embedded.tags.find{it.name=='" + tagName + "'}"))
.as("assert tag name and revision")
.isNotNull()
.hasSize(3)
.containsEntry("name", tagName)
.containsEntry("revision", changeset.getId());
assertThat(response.body().jsonPath().getString("_embedded.tags.find{it.name=='" + tagName + "'}._links.self.href"))
.as("assert single tag self link")
.isNotNull()
.contains(String.format("%s/tags/%s", repositoryUrl, tagName));
assertThat(response.body().jsonPath().getString("_embedded.tags.find{it.name=='" + tagName + "'}._links.sources.href"))
.as("assert single tag source link")
.isNotNull()
.contains(String.format("%s/sources/%s", repositoryUrl, changeset.getId()));
assertThat(response.body().jsonPath().getString("_embedded.tags.find{it.name=='" + tagName + "'}._links.changesets.href"))
.as("assert single tag changesets link")
.isNotNull()
.contains(String.format("%s/changesets/%s", repositoryUrl, changeset.getId()));
}
@Test
public void shouldReadContent() throws IOException, InterruptedException {
RepositoryClient repositoryClient = RepositoryUtil.createRepositoryClient(repositoryType, folder);
@@ -112,6 +197,7 @@ public class RepositoryAccessITCase {
.statusCode(HttpStatus.SC_OK)
.extract()
.path("files.find{it.name=='subfolder'}._links.self.href");
String subfolderContentUrl= given()
.when()
.get(subfolderSourceUrl)
@@ -119,6 +205,7 @@ public class RepositoryAccessITCase {
.statusCode(HttpStatus.SC_OK)
.extract()
.path("files[0]._links.self.href");
given()
.when()
.get(subfolderContentUrl)

View File

@@ -7,6 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.Person;
import sonia.scm.repository.Tag;
import sonia.scm.repository.client.api.ClientCommand;
import sonia.scm.repository.client.api.RepositoryClient;
import sonia.scm.repository.client.api.RepositoryClientFactory;
@@ -40,11 +41,11 @@ public class RepositoryUtil {
return name;
}
static void createAndCommitFile(RepositoryClient repositoryClient, String username, String fileName, String content) throws IOException {
static Changeset createAndCommitFile(RepositoryClient repositoryClient, String username, String fileName, String content) throws IOException {
File file = new File(repositoryClient.getWorkingCopy(), fileName);
Files.write(content, file, Charsets.UTF_8);
addWithParentDirectories(repositoryClient, file);
commit(repositoryClient, username, "added " + fileName);
return commit(repositoryClient, username, "added " + fileName);
}
private static String addWithParentDirectories(RepositoryClient repositoryClient, File file) throws IOException {
@@ -69,4 +70,16 @@ public class RepositoryUtil {
}
return changeset;
}
static Tag addTag(RepositoryClient repositoryClient, String revision, String tagName) throws IOException {
if (repositoryClient.isCommandSupported(ClientCommand.TAG)) {
Tag tag = repositoryClient.getTagCommand().setRevision(revision).tag(tagName, TestData.USER_SCM_ADMIN);
if (repositoryClient.isCommandSupported(ClientCommand.PUSH)) {
repositoryClient.getPushCommand().pushTags();
}
return tag;
}
return null;
}
}