Put is working

This commit is contained in:
Marcin Grzejszczak
2017-10-23 13:51:59 +02:00
parent d0c0f949f4
commit b1e6c2f301
10 changed files with 141 additions and 47 deletions

View File

@@ -3,9 +3,13 @@ package org.springframework.cloud.release.internal.sagan;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Marcin Grzejszczak
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Project {
public String id = "";
public String name = "";
@@ -15,7 +19,7 @@ public class Project {
public String stackOverflowTags;
public List<Release> projectReleases = new ArrayList<>();
public List<String> stackOverflowTagList = new ArrayList<>();
public boolean aggregator;
public Boolean aggregator;
@Override public String toString() {
return "Project{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", repoUrl='"

View File

@@ -1,8 +1,12 @@
package org.springframework.cloud.release.internal.sagan;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Marcin Grzejszczak
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Release {
public String releaseStatus = "";
public String refDocUrl = "";

View File

@@ -1,8 +1,12 @@
package org.springframework.cloud.release.internal.sagan;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Marcin Grzejszczak
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ReleaseUpdate {
public String groupId = "";
public String artifactId = "";
@@ -10,6 +14,7 @@ public class ReleaseUpdate {
public String releaseStatus = "";
public String refDocUrl = "";
public String apiDocUrl = "";
public Boolean current;
public Repository repository;
@Override public String toString() {

View File

@@ -1,13 +1,17 @@
package org.springframework.cloud.release.internal.sagan;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Marcin Grzejszczak
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Repository {
public String id;
public String name;
public String url;
public boolean snapshotsEnabled;
public Boolean snapshotsEnabled;
@Override public String toString() {
return "Repository{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", url='"

View File

@@ -1,9 +1,14 @@
package org.springframework.cloud.release.internal.sagan;
import java.net.URI;
import java.util.List;
import edu.emory.mathcs.backport.java.util.Collections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
@@ -15,7 +20,7 @@ import org.springframework.web.client.RestTemplate;
*/
class RestTemplateSaganClient implements SaganClient {
private static final org.slf4j.Logger log = LoggerFactory.getLogger(RestTemplateSaganClient.class);
private static final Logger log = LoggerFactory.getLogger(RestTemplateSaganClient.class);
private final RestTemplate restTemplate;
private final String baseUrl;
@@ -34,15 +39,15 @@ class RestTemplateSaganClient implements SaganClient {
}
@Override
public Release createOrUpdateRelease(String projectName, ReleaseUpdate releaseUpdate) {
RequestEntity<ReleaseUpdate> request = RequestEntity
public Project updateRelease(String projectName, List<ReleaseUpdate> releaseUpdates) {
RequestEntity<List<ReleaseUpdate>> request = RequestEntity
.put(URI.create(this.baseUrl +"/project_metadata/" + projectName + "/releases"))
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.body(releaseUpdate);
ResponseEntity<Release> entity = this.restTemplate
.exchange(request, Release.class);
Release release = entity.getBody();
log.info("Response from Sagan\n\n[{}] \n with body [{}]", entity, release);
return release;
.body(releaseUpdates);
ResponseEntity<Project> entity = this.restTemplate
.exchange(request, Project.class);
Project project = entity.getBody();
log.info("Response from Sagan\n\n[{}] \n with body [{}]", entity, project);
return project;
}
}

View File

@@ -1,5 +1,7 @@
package org.springframework.cloud.release.internal.sagan;
import java.util.List;
/**
* @author Marcin Grzejszczak
*/
@@ -8,5 +10,5 @@ public interface SaganClient {
Release getRelease(String projectName, String releaseVersion);
Release createOrUpdateRelease(String projectName, ReleaseUpdate releaseUpdate);
Project updateRelease(String projectName, List<ReleaseUpdate> releaseUpdate);
}

View File

@@ -1,5 +1,6 @@
package org.springframework.cloud.release.internal.sagan;
import edu.emory.mathcs.backport.java.util.Collections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
@@ -30,7 +31,7 @@ public class SaganUpdater {
update.apiDocUrl = referenceUrl(branch, version);
update.refDocUrl = referenceUrl(branch, version);
log.info("Updating Sagan with \n\n{}", update);
this.saganClient.createOrUpdateRelease(version.projectName, update);
this.saganClient.updateRelease(version.projectName, Collections.singletonList(update));
}
private String referenceUrl(String branch, ProjectVersion version) {

View File

@@ -1,7 +1,11 @@
package org.springframework.cloud.release.internal.sagan;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.BDDAssertions.then;
import edu.emory.mathcs.backport.java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -88,31 +92,93 @@ public class RestTemplateSaganClientTests {
@Test
public void should_update_a_release() {
ReleaseUpdate releaseUpdate = new ReleaseUpdate();
releaseUpdate.groupId = "org.springframework";
releaseUpdate.artifactId = "spring-context";
releaseUpdate.version = "1.2.8.RELEASE";
releaseUpdate.releaseStatus = "PRERELEASE";
releaseUpdate.refDocUrl = "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/";
releaseUpdate.apiDocUrl = "http://docs.spring.io/spring/docs/{version}/javadoc-api/";
Repository snapshots = snapshots();
Repository milestone = milestone();
List<ReleaseUpdate> updates = new ArrayList<>();
\n \"repository\" : {\n \"id\" : \"spring-milestones\",\n \"name\" : \"Spring Milestones\",\n \"url\" : \"https://repo.spring.io/libs-milestone\",\n \"snapshotsEnabled\" : false\n }\n}, {\n \"groupId\" : \"org.springframework\",\n \"artifactId\" : \"spring-context\",\n \"version\" : \"5.0.0.BUILD-SNAPSHOT\",\n \"releaseStatus\" : \"SNAPSHOT\",\n \"refDocUrl\" : \"http://docs.spring.io/spring/docs/{version}/spring-framework-reference/\",\n \"apiDocUrl\" : \"http://docs.spring.io/spring/docs/{version}/javadoc-api/\",\n \"repository\" : {\n \"id\" : \"spring-snapshots\",\n \"name\" : \"Spring Snapshots\",\n \"url\" : \"https://repo.spring.io/libs-snapshot\",\n \"snapshotsEnabled\" : true\n }\n}, {\n \"groupId\" : \"org.springframework\",\n \"artifactId\" : \"spring-context\",\n \"version\" : \"4.3.12.BUILD-SNAPSHOT\",\n \"releaseStatus\" : \"SNAPSHOT\",\n \"refDocUrl\" : \"http://docs.spring.io/spring/docs/{version}/spring-framework-reference/htmlsingle/\",\n \"apiDocUrl\" : \"http://docs.spring.io/spring/docs/{version}/javadoc-api/\",\n \"repository\" : {\n \"id\" : \"spring-snapshots\",\n \"name\" : \"Spring Snapshots\",\n \"url\" : \"https://repo.spring.io/libs-snapshot\",\n \"snapshotsEnabled\" : true\n }\n}, {\n \"groupId\" : \"org.springframework\",\n \"artifactId\" : \"spring-context\",\n \"version\" : \"4.3.11.RELEASE\",\n \"releaseStatus\" : \"GENERAL_AVAILABILITY\",\n \"current\" : true,\n \"refDocUrl\" : \"http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/\",\n \"apiDocUrl\" : \"http://docs.spring.io/spring/docs/current/javadoc-api/\"\n}, {\n \"groupId\" : \"org.springframework\",\n \"artifactId\" : \"spring-context\",\n \"version\" : \"4.2.9.RELEASE\",\n \"releaseStatus\" : \"GENERAL_AVAILABILITY\",\n \"refDocUrl\" : \"http://docs.spring.io/spring/docs/{version}/spring-framework-reference/htmlsingle/\",\n \"apiDocUrl\" : \"http://docs.spring.io/spring/docs/{version}/javadoc-api/\"\n}, {\n \"groupId\" : \"org.springframework\",\n \"artifactId\" : \"spring-context\",\n \"version\" : \"3.2.18.RELEASE\",\n \"releaseStatus\" : \"GENERAL_AVAILABILITY\",\n \"refDocUrl\" : \"http://docs.spring.io/spring/docs/{version}/spring-framework-reference/htmlsingle/\",\n \"apiDocUrl\" : \"http://docs.spring.io/spring/docs/{version}/javadoc-api/\"\n} ]"
ReleaseUpdate firstRelease = new ReleaseUpdate();
firstRelease.groupId = "org.springframework";
firstRelease.artifactId = "spring-context";
firstRelease.version = "1.2.8.RELEASE";
firstRelease.releaseStatus = "PRERELEASE";
firstRelease.refDocUrl = "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/";
firstRelease.apiDocUrl = "http://docs.spring.io/spring/docs/{version}/javadoc-api/";
firstRelease.repository = milestone;
ReleaseUpdate secondRelease = new ReleaseUpdate();
secondRelease.groupId = "org.springframework";
secondRelease.artifactId = "spring-context";
secondRelease.version = "5.0.0.BUILD-SNAPSHOT";
secondRelease.releaseStatus = "SNAPSHOT";
secondRelease.refDocUrl = "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/";
secondRelease.apiDocUrl = "http://docs.spring.io/spring/docs/{version}/javadoc-api/";
secondRelease.repository = snapshots;
Release release = this.client.createOrUpdateRelease("spring-framework", releaseUpdate);
ReleaseUpdate thirdRelease = new ReleaseUpdate();
thirdRelease.groupId = "org.springframework";
thirdRelease.artifactId = "spring-context";
thirdRelease.version = "4.3.12.BUILD-SNAPSHOT";
thirdRelease.releaseStatus = "SNAPSHOT";
thirdRelease.refDocUrl = "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/htmlsingle/";
thirdRelease.apiDocUrl = "http://docs.spring.io/spring/docs/{version}/javadoc-api/";
thirdRelease.repository = snapshots;
then(release.releaseStatus).isEqualTo("GENERAL_AVAILABILITY");
then(release.refDocUrl).isEqualTo("http://docs.spring.io/spring/docs/1.2.3.RELEASE/spring-framework-reference/");
then(release.apiDocUrl).isEqualTo("http://docs.spring.io/spring/docs/1.2.3.RELEASE/javadoc-api/");
then(release.groupId).isEqualTo("org.springframework");
then(release.artifactId).isEqualTo("spring-context");
then(release.version).isEqualTo("1.2.3.RELEASE");
then(release.current).isFalse();
then(release.generalAvailability).isTrue();
then(release.preRelease).isFalse();
then(release.versionDisplayName).isEqualTo("1.2.3");
then(release.snapshot).isFalse();
ReleaseUpdate fourthRelease = new ReleaseUpdate();
fourthRelease.groupId = "org.springframework";
fourthRelease.artifactId = "spring-context";
fourthRelease.version = "4.3.11.RELEASE";
fourthRelease.releaseStatus = "GENERAL_AVAILABILITY";
fourthRelease.current = true;
fourthRelease.refDocUrl = "http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/";
fourthRelease.apiDocUrl = "http://docs.spring.io/spring/docs/current/javadoc-api/";
ReleaseUpdate fithRelease = new ReleaseUpdate();
fithRelease.groupId = "org.springframework";
fithRelease.artifactId = "spring-context";
fithRelease.version = "4.2.9.RELEASE";
fithRelease.releaseStatus = "GENERAL_AVAILABILITY";
fithRelease.refDocUrl = "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/htmlsingle/";
fithRelease.apiDocUrl = "http://docs.spring.io/spring/docs/{version}/javadoc-api/";
ReleaseUpdate sithRelease = new ReleaseUpdate();
sithRelease.groupId = "org.springframework";
sithRelease.artifactId = "spring-context";
sithRelease.version = "3.2.18.RELEASE";
sithRelease.releaseStatus = "GENERAL_AVAILABILITY";
sithRelease.refDocUrl = "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/htmlsingle/";
sithRelease.apiDocUrl = "http://docs.spring.io/spring/docs/{version}/javadoc-api/";
updates.add(firstRelease);
updates.add(secondRelease);
updates.add(thirdRelease);
updates.add(fourthRelease);
updates.add(fithRelease);
updates.add(sithRelease);
Project project = this.client.updateRelease("spring-framework", updates);
then(project.id).isEqualTo("spring-framework");
then(project.name).isEqualTo("Spring Framework");
then(project.projectReleases).hasSize(7);
}
private Repository milestone() {
Repository milestone = new Repository();
milestone.id = "spring-milestones";
milestone.name = "Spring Milestones";
milestone.url = "https://repo.spring.io/libs-milestone";
milestone.snapshotsEnabled = false;
return milestone;
}
private Repository snapshots() {
Repository snapshots = new Repository();
snapshots.id = "spring-snapshots";
snapshots.name = "Spring Snapshots";
snapshots.url = "https://repo.spring.io/libs-snapshot";
snapshots.snapshotsEnabled = true;
return snapshots;
}
private SaganClient saganClient(ReleaserProperties properties) {

View File

@@ -1,5 +1,7 @@
package org.springframework.cloud.release.internal.sagan;
import java.util.List;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Test;
@@ -23,12 +25,12 @@ public class SaganUpdaterTest {
this.saganUpdater.updateSagan("master", version("1.0.0.M1"), version("1.0.0.M1"));
BDDMockito.then(this.saganClient).should(BDDMockito.never())
.createOrUpdateRelease(BDDMockito.anyString(), BDDMockito.any(ReleaseUpdate.class));
.updateRelease(BDDMockito.anyString(), BDDMockito.anyList());
this.saganUpdater.updateSagan("master", version("1.0.0.RC1"), version("1.0.0.RC1"));
BDDMockito.then(this.saganClient).should(BDDMockito.never())
.createOrUpdateRelease(BDDMockito.anyString(), BDDMockito.any(ReleaseUpdate.class));
.updateRelease(BDDMockito.anyString(), BDDMockito.anyList());
}
private ProjectVersion version(String version) {
@@ -40,7 +42,7 @@ public class SaganUpdaterTest {
this.saganUpdater.updateSagan("master", projectVersion, projectVersion);
BDDMockito.then(this.saganClient).should().createOrUpdateRelease(BDDMockito.eq("foo"),
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.0.BUILD-SNAPSHOT", "http://cloud.spring.io/foo/foo.html")));
}
@@ -49,7 +51,7 @@ public class SaganUpdaterTest {
this.saganUpdater.updateSagan("master", projectVersion, projectVersion);
BDDMockito.then(this.saganClient).should().createOrUpdateRelease(BDDMockito.eq("foo"),
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.0.RELEASE", "http://cloud.spring.io/spring-cloud-static/foo/{version}/")));
}
@@ -58,13 +60,14 @@ public class SaganUpdaterTest {
this.saganUpdater.updateSagan("1.1.x", projectVersion, projectVersion);
BDDMockito.then(this.saganClient).should().createOrUpdateRelease(BDDMockito.eq("foo"),
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.1.0.BUILD-SNAPSHOT", "http://cloud.spring.io/foo/1.1.x/")));
}
private TypeSafeMatcher<ReleaseUpdate> withReleaseUpdate(final String version, final String refDocUrl) {
return new TypeSafeMatcher<ReleaseUpdate>() {
@Override protected boolean matchesSafely(ReleaseUpdate item) {
private TypeSafeMatcher<List<ReleaseUpdate>> withReleaseUpdate(final String version, final String refDocUrl) {
return new TypeSafeMatcher<List<ReleaseUpdate>>() {
@Override protected boolean matchesSafely(List<ReleaseUpdate> items) {
ReleaseUpdate item = items.get(0);
return "foo".equals(item.artifactId) &&
version.equals(item.version) &&
refDocUrl.equals(item.apiDocUrl) &&

View File

@@ -99,8 +99,8 @@ public class AcceptanceTests {
.contains("Camden.SR5")
.contains("- Spring Cloud Config `1.2.2.RELEASE` ([issues](http://foo.bar.com/1.2.2.RELEASE))")
.contains("- Spring Cloud Aws `1.1.3.RELEASE` ([issues](http://foo.bar.com/1.1.3.RELEASE))");
BDDMockito.then(this.saganClient).should().createOrUpdateRelease(BDDMockito.eq("spring-cloud-consul"),
BDDMockito.any(ReleaseUpdate.class));
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("spring-cloud-consul"),
BDDMockito.anyList());
}
@Test
@@ -138,8 +138,8 @@ public class AcceptanceTests {
.contains("Dalston.RC1")
.contains("- Spring Cloud Build `1.3.1.RELEASE` ([issues](http://foo.bar.com/1.3.1.RELEASE))")
.contains("- Spring Cloud Bus `1.3.0.M1` ([issues](http://foo.bar.com/1.3.0.M1))");
BDDMockito.then(this.saganClient).should(BDDMockito.never()).createOrUpdateRelease(
BDDMockito.anyString(), BDDMockito.any(ReleaseUpdate.class));
BDDMockito.then(this.saganClient).should(BDDMockito.never()).updateRelease(
BDDMockito.anyString(), BDDMockito.anyList());
}
@Test
@@ -169,8 +169,8 @@ public class AcceptanceTests {
.contains("Dalston.RC1")
.contains("- Spring Cloud Build `1.3.1.RELEASE` ([issues](http://foo.bar.com/1.3.1.RELEASE))")
.contains("- Spring Cloud Bus `1.3.0.M1` ([issues](http://foo.bar.com/1.3.0.M1)");
BDDMockito.then(this.saganClient).should(BDDMockito.never()).createOrUpdateRelease(
BDDMockito.anyString(), BDDMockito.any(ReleaseUpdate.class));
BDDMockito.then(this.saganClient).should(BDDMockito.never()).updateRelease(
BDDMockito.anyString(), BDDMockito.anyList());
}
private Iterable<RevCommit> listOfCommits(File project) throws GitAPIException {