Update init to new metadata format
Spring initializr now declares an improved metadata format (v2). InitializrServiceMetadata has been updated to parse this format. Note that the client could be further improved by using HAL generated links. Closes gh-1953
This commit is contained in:
@@ -49,7 +49,7 @@ public abstract class AbstractHttpClientMockTests {
|
||||
protected final CloseableHttpClient http = mock(CloseableHttpClient.class);
|
||||
|
||||
protected void mockSuccessfulMetadataGet() throws IOException {
|
||||
mockSuccessfulMetadataGet("1.1.0");
|
||||
mockSuccessfulMetadataGet("2.0.0");
|
||||
}
|
||||
|
||||
protected void mockSuccessfulMetadataGet(String version) throws IOException {
|
||||
@@ -57,9 +57,9 @@ public abstract class AbstractHttpClientMockTests {
|
||||
Resource resource = new ClassPathResource("metadata/service-metadata-" + version
|
||||
+ ".json");
|
||||
byte[] content = StreamUtils.copyToByteArray(resource.getInputStream());
|
||||
mockHttpEntity(response, content, "application/json");
|
||||
mockHttpEntity(response, content, "application/vnd.initializr.v2+json");
|
||||
mockStatus(response, 200);
|
||||
given(this.http.execute(argThat(getForJsonData()))).willReturn(response);
|
||||
given(this.http.execute(argThat(getForJsonMetadata()))).willReturn(response);
|
||||
}
|
||||
|
||||
protected void mockSuccessfulProjectGeneration(
|
||||
@@ -72,7 +72,7 @@ public abstract class AbstractHttpClientMockTests {
|
||||
String header = (request.fileName != null ? contentDispositionValue(request.fileName)
|
||||
: null);
|
||||
mockHttpHeader(response, "Content-Disposition", header);
|
||||
given(this.http.execute(argThat(getForNonJsonData()))).willReturn(response);
|
||||
given(this.http.execute(argThat(getForNonJsonMetadata()))).willReturn(response);
|
||||
}
|
||||
|
||||
protected void mockProjectGenerationError(int status, String message)
|
||||
@@ -122,12 +122,12 @@ public abstract class AbstractHttpClientMockTests {
|
||||
given(response.getFirstHeader(headerName)).willReturn(header);
|
||||
}
|
||||
|
||||
protected Matcher<HttpGet> getForJsonData() {
|
||||
return new HasAcceptHeader("application/json", true);
|
||||
protected Matcher<HttpGet> getForJsonMetadata() {
|
||||
return new HasAcceptHeader("application/vnd.initializr.v2+json", true);
|
||||
}
|
||||
|
||||
protected Matcher<HttpGet> getForNonJsonData() {
|
||||
return new HasAcceptHeader("application/json", false);
|
||||
protected Matcher<HttpGet> getForNonJsonMetadata() {
|
||||
return new HasAcceptHeader("application/vnd.initializr.v2+json", false);
|
||||
}
|
||||
|
||||
private String contentDispositionValue(String fileName) {
|
||||
|
||||
@@ -38,15 +38,24 @@ public class InitializrServiceMetadataTests {
|
||||
|
||||
@Test
|
||||
public void parseDefaults() {
|
||||
InitializrServiceMetadata metadata = createInstance("1.0.0");
|
||||
assertEquals("maven-project", metadata.getDefaults().get("type"));
|
||||
InitializrServiceMetadata metadata = createInstance("2.0.0");
|
||||
assertEquals("1.1.8.RELEASE", metadata.getDefaults().get("bootVersion"));
|
||||
assertEquals("1.7", metadata.getDefaults().get("javaVersion"));
|
||||
assertEquals("org.test", metadata.getDefaults().get("groupId"));
|
||||
assertEquals("demo", metadata.getDefaults().get("name"));
|
||||
assertEquals("Demo project for Spring Boot", metadata.getDefaults().get("description"));
|
||||
assertEquals("jar", metadata.getDefaults().get("packaging"));
|
||||
assertEquals("java", metadata.getDefaults().get("language"));
|
||||
assertEquals("demo", metadata.getDefaults().get("artifactId"));
|
||||
assertEquals("demo", metadata.getDefaults().get("packageName"));
|
||||
assertEquals("maven-project", metadata.getDefaults().get("type"));
|
||||
assertEquals("0.0.1-SNAPSHOT", metadata.getDefaults().get("version"));
|
||||
assertEquals("Wrong number of defaults", 11, metadata.getDefaults().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseDependencies() {
|
||||
InitializrServiceMetadata metadata = createInstance("1.0.0");
|
||||
InitializrServiceMetadata metadata = createInstance("2.0.0");
|
||||
assertEquals(5, metadata.getDependencies().size());
|
||||
|
||||
// Security description
|
||||
@@ -60,16 +69,8 @@ public class InitializrServiceMetadataTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTypesNoTag() {
|
||||
InitializrServiceMetadata metadata = createInstance("1.0.0");
|
||||
ProjectType projectType = metadata.getProjectTypes().get("maven-project");
|
||||
assertNotNull(projectType);
|
||||
assertEquals(0, projectType.getTags().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTypesWithTags() {
|
||||
InitializrServiceMetadata metadata = createInstance("1.1.0");
|
||||
public void parseTypes() {
|
||||
InitializrServiceMetadata metadata = createInstance("2.0.0");
|
||||
ProjectType projectType = metadata.getProjectTypes().get("maven-project");
|
||||
assertNotNull(projectType);
|
||||
assertEquals("maven", projectType.getTags().get("build"));
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ProjectGenerationRequestTests {
|
||||
this.request.setServiceUrl(customServerUrl);
|
||||
this.request.getDependencies().add("security");
|
||||
assertEquals(new URI(customServerUrl
|
||||
+ "/starter.zip?style=security&type=test-type"),
|
||||
+ "/starter.zip?dependencies=security&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ProjectGenerationRequestTests {
|
||||
@Test
|
||||
public void singleDependency() {
|
||||
this.request.getDependencies().add("web");
|
||||
assertEquals(createDefaultUrl("?style=web&type=test-type"),
|
||||
assertEquals(createDefaultUrl("?dependencies=web&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ProjectGenerationRequestTests {
|
||||
public void multipleDependencies() {
|
||||
this.request.getDependencies().add("web");
|
||||
this.request.getDependencies().add("data-jpa");
|
||||
assertEquals(createDefaultUrl("?style=web&style=data-jpa&type=test-type"),
|
||||
assertEquals(createDefaultUrl("?dependencies=web%2Cdata-jpa&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public class ProjectGenerationRequestTests {
|
||||
this.request.setType("custom");
|
||||
this.request.getDependencies().add("data-rest");
|
||||
assertEquals(new URI(ProjectGenerationRequest.DEFAULT_SERVICE_URL
|
||||
+ "/foo?style=data-rest&type=custom"), this.request.generateUrl(metadata));
|
||||
+ "/foo?dependencies=data-rest&type=custom"), this.request.generateUrl(metadata));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,7 +187,7 @@ public class ProjectGenerationRequestTests {
|
||||
}
|
||||
|
||||
private static InitializrServiceMetadata readMetadata() {
|
||||
return readMetadata("1.1.0");
|
||||
return readMetadata("2.0.0");
|
||||
}
|
||||
|
||||
private static InitializrServiceMetadata readMetadata(String version) {
|
||||
|
||||
Reference in New Issue
Block a user