mirror of
https://gitee.com/dcren/initializr.git
synced 2025-11-09 02:45:00 +08:00
Rename /metadata/service to /metadata/config
Also exposing a link for the client metadata at /metadata/client Fixes gh-115
This commit is contained in:
@@ -63,12 +63,18 @@ class MainController extends AbstractInitializrController {
|
|||||||
request
|
request
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/metadata/service", produces = ["application/json"])
|
@RequestMapping(value = "/metadata/config", produces = ["application/json"])
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
InitializrMetadata config() {
|
InitializrMetadata config() {
|
||||||
metadataProvider.get()
|
metadataProvider.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/metadata/client")
|
||||||
|
String client() {
|
||||||
|
'redirect:/'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/", produces = ["text/plain"])
|
@RequestMapping(value = "/", produces = ["text/plain"])
|
||||||
ResponseEntity<String> serviceCapabilities(
|
ResponseEntity<String> serviceCapabilities(
|
||||||
@RequestHeader(value = HttpHeaders.USER_AGENT, required = false) String userAgent) {
|
@RequestHeader(value = HttpHeaders.USER_AGENT, required = false) String userAgent) {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class InitializrMetadataBuilderTests {
|
|||||||
@Test
|
@Test
|
||||||
void mergeMetadata() {
|
void mergeMetadata() {
|
||||||
def metadata = InitializrMetadataBuilder.create().withInitializrMetadata(
|
def metadata = InitializrMetadataBuilder.create().withInitializrMetadata(
|
||||||
new ClassPathResource('metadata/service/test-min.json')).build()
|
new ClassPathResource('metadata/config/test-min.json')).build()
|
||||||
assertEquals false, metadata.configuration.env.forceSsl
|
assertEquals false, metadata.configuration.env.forceSsl
|
||||||
assertEquals 1, metadata.dependencies.content.size()
|
assertEquals 1, metadata.dependencies.content.size()
|
||||||
Dependency dependency = metadata.dependencies.get('test')
|
Dependency dependency = metadata.dependencies.get('test')
|
||||||
@@ -88,7 +88,7 @@ class InitializrMetadataBuilderTests {
|
|||||||
@Test
|
@Test
|
||||||
void mergeMetadataWithBom() {
|
void mergeMetadataWithBom() {
|
||||||
def metadata = InitializrMetadataBuilder.create().withInitializrMetadata(
|
def metadata = InitializrMetadataBuilder.create().withInitializrMetadata(
|
||||||
new ClassPathResource('metadata/service/test-bom.json')).build()
|
new ClassPathResource('metadata/config/test-bom.json')).build()
|
||||||
|
|
||||||
def boms = metadata.configuration.env.boms
|
def boms = metadata.configuration.env.boms
|
||||||
assertEquals 2, boms.size()
|
assertEquals 2, boms.size()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package io.spring.initializr.web
|
|||||||
|
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
|
import io.spring.initializr.mapper.InitializrMetadataVersion
|
||||||
import io.spring.initializr.metadata.DefaultMetadataElement
|
import io.spring.initializr.metadata.DefaultMetadataElement
|
||||||
import io.spring.initializr.metadata.InitializrMetadata
|
import io.spring.initializr.metadata.InitializrMetadata
|
||||||
import io.spring.initializr.support.DefaultInitializrMetadataProvider
|
import io.spring.initializr.support.DefaultInitializrMetadataProvider
|
||||||
@@ -27,6 +28,8 @@ import org.json.JSONObject
|
|||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert
|
||||||
|
import org.skyscreamer.jsonassert.JSONCompareMode
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||||
@@ -56,6 +59,9 @@ import static org.junit.Assert.assertTrue
|
|||||||
@IntegrationTest('server.port=0')
|
@IntegrationTest('server.port=0')
|
||||||
abstract class AbstractInitializrControllerIntegrationTests {
|
abstract class AbstractInitializrControllerIntegrationTests {
|
||||||
|
|
||||||
|
static final MediaType CURRENT_METADATA_MEDIA_TYPE = InitializrMetadataVersion.V2_1.mediaType
|
||||||
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final TemporaryFolder folder = new TemporaryFolder()
|
public final TemporaryFolder folder = new TemporaryFolder()
|
||||||
|
|
||||||
@@ -85,6 +91,29 @@ abstract class AbstractInitializrControllerIntegrationTests {
|
|||||||
'UTF-8', actual.getParameter('charset')
|
'UTF-8', actual.getParameter('charset')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void validateMetadata(ResponseEntity<String> response, MediaType mediaType,
|
||||||
|
String version, JSONCompareMode compareMode) {
|
||||||
|
validateContentType(response, mediaType)
|
||||||
|
def json = new JSONObject(response.body)
|
||||||
|
def expected = readMetadataJson(version)
|
||||||
|
JSONAssert.assertEquals(expected, json, compareMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void validateCurrentMetadata(ResponseEntity<String> response) {
|
||||||
|
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE)
|
||||||
|
validateCurrentMetadata(new JSONObject(response.body))
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void validateCurrentMetadata(JSONObject json) {
|
||||||
|
def expected = readMetadataJson('2.1.0')
|
||||||
|
JSONAssert.assertEquals(expected, json, JSONCompareMode.STRICT)
|
||||||
|
}
|
||||||
|
|
||||||
|
private JSONObject readMetadataJson(String version) {
|
||||||
|
readJsonFrom("metadata/test-default-$version" + ".json")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a {@link ProjectAssert} for the following archive content.
|
* Return a {@link ProjectAssert} for the following archive content.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,29 +16,28 @@
|
|||||||
|
|
||||||
package io.spring.initializr.web
|
package io.spring.initializr.web
|
||||||
|
|
||||||
import java.nio.charset.Charset
|
|
||||||
|
|
||||||
import groovy.json.JsonSlurper
|
import groovy.json.JsonSlurper
|
||||||
import io.spring.initializr.mapper.InitializrMetadataVersion
|
import io.spring.initializr.mapper.InitializrMetadataVersion
|
||||||
import io.spring.initializr.metadata.Dependency
|
import io.spring.initializr.metadata.Dependency
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.junit.Ignore
|
import org.junit.Ignore
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.skyscreamer.jsonassert.JSONAssert
|
|
||||||
import org.skyscreamer.jsonassert.JSONCompareMode
|
import org.skyscreamer.jsonassert.JSONCompareMode
|
||||||
|
|
||||||
import org.springframework.core.io.ClassPathResource
|
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
import org.springframework.test.context.ActiveProfiles
|
import org.springframework.test.context.ActiveProfiles
|
||||||
import org.springframework.util.StreamUtils
|
|
||||||
import org.springframework.web.client.HttpClientErrorException
|
import org.springframework.web.client.HttpClientErrorException
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.allOf
|
import static org.hamcrest.CoreMatchers.allOf
|
||||||
import static org.hamcrest.CoreMatchers.containsString
|
import static org.hamcrest.CoreMatchers.containsString
|
||||||
import static org.hamcrest.core.IsNot.not
|
import static org.hamcrest.core.IsNot.not
|
||||||
import static org.junit.Assert.*
|
import static org.junit.Assert.assertEquals
|
||||||
|
import static org.junit.Assert.assertFalse
|
||||||
|
import static org.junit.Assert.assertNotNull
|
||||||
|
import static org.junit.Assert.assertThat
|
||||||
|
import static org.junit.Assert.assertTrue
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
@@ -46,7 +45,6 @@ import static org.junit.Assert.*
|
|||||||
@ActiveProfiles('test-default')
|
@ActiveProfiles('test-default')
|
||||||
class MainControllerIntegrationTests extends AbstractInitializrControllerIntegrationTests {
|
class MainControllerIntegrationTests extends AbstractInitializrControllerIntegrationTests {
|
||||||
|
|
||||||
private static final MediaType CURRENT_METADATA_MEDIA_TYPE = InitializrMetadataVersion.V2_1.mediaType
|
|
||||||
|
|
||||||
private final def slurper = new JsonSlurper()
|
private final def slurper = new JsonSlurper()
|
||||||
|
|
||||||
@@ -210,7 +208,8 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
|||||||
tgzProjectAssert(response.body).isMavenProject().isJavaProject()
|
tgzProjectAssert(response.body).isMavenProject().isJavaProject()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // make sure curl can still receive metadata with json
|
@Test
|
||||||
|
// make sure curl can still receive metadata with json
|
||||||
void curlWithAcceptHeaderJson() {
|
void curlWithAcceptHeaderJson() {
|
||||||
ResponseEntity<String> response = invokeHome('curl/1.2.4', "application/json")
|
ResponseEntity<String> response = invokeHome('curl/1.2.4', "application/json")
|
||||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE)
|
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE)
|
||||||
@@ -235,7 +234,8 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
|||||||
validateHttpIeHelpContent(response)
|
validateHttpIeHelpContent(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // make sure curl can still receive metadata with json
|
@Test
|
||||||
|
// make sure curl can still receive metadata with json
|
||||||
void httpieWithAcceptHeaderJson() {
|
void httpieWithAcceptHeaderJson() {
|
||||||
ResponseEntity<String> response = invokeHome('HTTPie/0.8.0', "application/json")
|
ResponseEntity<String> response = invokeHome('HTTPie/0.8.0', "application/json")
|
||||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE)
|
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE)
|
||||||
@@ -273,23 +273,6 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
|||||||
validateCurrentMetadata(json)
|
validateCurrentMetadata(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateMetadata(ResponseEntity<String> response, MediaType mediaType,
|
|
||||||
String version, JSONCompareMode compareMode) {
|
|
||||||
validateContentType(response, mediaType)
|
|
||||||
def json = new JSONObject(response.body)
|
|
||||||
def expected = readJson(version)
|
|
||||||
JSONAssert.assertEquals(expected, json, compareMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateCurrentMetadata(ResponseEntity<String> response) {
|
|
||||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE)
|
|
||||||
validateCurrentMetadata(new JSONObject(response.body))
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateCurrentMetadata(JSONObject json) {
|
|
||||||
def expected = readJson('2.1.0')
|
|
||||||
JSONAssert.assertEquals(expected, json, JSONCompareMode.STRICT)
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateCurlHelpContent(ResponseEntity<String> response) {
|
private void validateCurlHelpContent(ResponseEntity<String> response) {
|
||||||
validateContentType(response, MediaType.TEXT_PLAIN)
|
validateContentType(response, MediaType.TEXT_PLAIN)
|
||||||
@@ -448,8 +431,5 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
|||||||
return new JSONObject(json)
|
return new JSONObject(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject readJson(String version) {
|
|
||||||
readJsonFrom("metadata/test-default-$version" + ".json")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class MainControllerServiceMetadataIntegrationTests extends AbstractInitializrCo
|
|||||||
void initializeRemoteConfig() {
|
void initializeRemoteConfig() {
|
||||||
InitializrMetadata localMetadata = metadataProvider.get()
|
InitializrMetadata localMetadata = metadataProvider.get()
|
||||||
InitializrMetadata metadata = InitializrMetadataBuilder.create().withInitializrMetadata(
|
InitializrMetadata metadata = InitializrMetadataBuilder.create().withInitializrMetadata(
|
||||||
new UrlResource(createUrl('/metadata/service'))).build()
|
new UrlResource(createUrl('/metadata/config'))).build()
|
||||||
// Basic assertions
|
// Basic assertions
|
||||||
assertEquals(localMetadata.dependencies.content.size(), metadata.dependencies.content.size())
|
assertEquals(localMetadata.dependencies.content.size(), metadata.dependencies.content.size())
|
||||||
assertEquals(localMetadata.types.content.size(), metadata.types.content.size())
|
assertEquals(localMetadata.types.content.size(), metadata.types.content.size())
|
||||||
@@ -60,7 +60,7 @@ class MainControllerServiceMetadataIntegrationTests extends AbstractInitializrCo
|
|||||||
@Test
|
@Test
|
||||||
void textPlainNotAccepted() {
|
void textPlainNotAccepted() {
|
||||||
try {
|
try {
|
||||||
execute('/metadata/service', String, null, 'text/plain')
|
execute('/metadata/config', String, null, 'text/plain')
|
||||||
} catch (HttpClientErrorException ex) {
|
} catch (HttpClientErrorException ex) {
|
||||||
assertEquals HttpStatus.NOT_ACCEPTABLE, ex.statusCode
|
assertEquals HttpStatus.NOT_ACCEPTABLE, ex.statusCode
|
||||||
}
|
}
|
||||||
@@ -68,11 +68,17 @@ class MainControllerServiceMetadataIntegrationTests extends AbstractInitializrCo
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void validateJson() {
|
void validateJson() {
|
||||||
ResponseEntity<String> response = execute('/metadata/service', String, null, 'application/json')
|
ResponseEntity<String> response = execute('/metadata/config', String, null, 'application/json')
|
||||||
validateContentType(response, MediaType.APPLICATION_JSON)
|
validateContentType(response, MediaType.APPLICATION_JSON)
|
||||||
JSONObject json = new JSONObject(response.body)
|
JSONObject json = new JSONObject(response.body)
|
||||||
def expected = readJsonFrom("metadata/service/test-default.json")
|
def expected = readJsonFrom("metadata/config/test-default.json")
|
||||||
JSONAssert.assertEquals(expected, json, JSONCompareMode.STRICT)
|
JSONAssert.assertEquals(expected, json, JSONCompareMode.STRICT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void metadataClientRedirect() {
|
||||||
|
ResponseEntity<String> response = execute('/metadata/client', String, null, 'application/json')
|
||||||
|
validateCurrentMetadata(response)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user