mirror of
https://gitee.com/dcren/initializr.git
synced 2025-11-08 02:14:55 +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
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/metadata/service", produces = ["application/json"])
|
||||
@RequestMapping(value = "/metadata/config", produces = ["application/json"])
|
||||
@ResponseBody
|
||||
InitializrMetadata config() {
|
||||
metadataProvider.get()
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/metadata/client")
|
||||
String client() {
|
||||
'redirect:/'
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/", produces = ["text/plain"])
|
||||
ResponseEntity<String> serviceCapabilities(
|
||||
@RequestHeader(value = HttpHeaders.USER_AGENT, required = false) String userAgent) {
|
||||
|
||||
@@ -66,7 +66,7 @@ class InitializrMetadataBuilderTests {
|
||||
@Test
|
||||
void mergeMetadata() {
|
||||
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 1, metadata.dependencies.content.size()
|
||||
Dependency dependency = metadata.dependencies.get('test')
|
||||
@@ -88,7 +88,7 @@ class InitializrMetadataBuilderTests {
|
||||
@Test
|
||||
void mergeMetadataWithBom() {
|
||||
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
|
||||
assertEquals 2, boms.size()
|
||||
|
||||
@@ -18,6 +18,7 @@ package io.spring.initializr.web
|
||||
|
||||
import java.nio.charset.Charset
|
||||
|
||||
import io.spring.initializr.mapper.InitializrMetadataVersion
|
||||
import io.spring.initializr.metadata.DefaultMetadataElement
|
||||
import io.spring.initializr.metadata.InitializrMetadata
|
||||
import io.spring.initializr.support.DefaultInitializrMetadataProvider
|
||||
@@ -27,6 +28,8 @@ import org.json.JSONObject
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TemporaryFolder
|
||||
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.boot.autoconfigure.EnableAutoConfiguration
|
||||
@@ -56,6 +59,9 @@ import static org.junit.Assert.assertTrue
|
||||
@IntegrationTest('server.port=0')
|
||||
abstract class AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
static final MediaType CURRENT_METADATA_MEDIA_TYPE = InitializrMetadataVersion.V2_1.mediaType
|
||||
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder folder = new TemporaryFolder()
|
||||
|
||||
@@ -85,6 +91,29 @@ abstract class AbstractInitializrControllerIntegrationTests {
|
||||
'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.
|
||||
*/
|
||||
|
||||
@@ -16,29 +16,28 @@
|
||||
|
||||
package io.spring.initializr.web
|
||||
|
||||
import java.nio.charset.Charset
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
import io.spring.initializr.mapper.InitializrMetadataVersion
|
||||
import io.spring.initializr.metadata.Dependency
|
||||
import org.json.JSONObject
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import org.skyscreamer.jsonassert.JSONAssert
|
||||
import org.skyscreamer.jsonassert.JSONCompareMode
|
||||
|
||||
import org.springframework.core.io.ClassPathResource
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.test.context.ActiveProfiles
|
||||
import org.springframework.util.StreamUtils
|
||||
import org.springframework.web.client.HttpClientErrorException
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf
|
||||
import static org.hamcrest.CoreMatchers.containsString
|
||||
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
|
||||
@@ -46,7 +45,6 @@ import static org.junit.Assert.*
|
||||
@ActiveProfiles('test-default')
|
||||
class MainControllerIntegrationTests extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
private static final MediaType CURRENT_METADATA_MEDIA_TYPE = InitializrMetadataVersion.V2_1.mediaType
|
||||
|
||||
private final def slurper = new JsonSlurper()
|
||||
|
||||
@@ -210,7 +208,8 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
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() {
|
||||
ResponseEntity<String> response = invokeHome('curl/1.2.4', "application/json")
|
||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE)
|
||||
@@ -235,7 +234,8 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
validateHttpIeHelpContent(response)
|
||||
}
|
||||
|
||||
@Test // make sure curl can still receive metadata with json
|
||||
@Test
|
||||
// make sure curl can still receive metadata with json
|
||||
void httpieWithAcceptHeaderJson() {
|
||||
ResponseEntity<String> response = invokeHome('HTTPie/0.8.0', "application/json")
|
||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE)
|
||||
@@ -273,23 +273,6 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
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) {
|
||||
validateContentType(response, MediaType.TEXT_PLAIN)
|
||||
@@ -448,8 +431,5 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
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() {
|
||||
InitializrMetadata localMetadata = metadataProvider.get()
|
||||
InitializrMetadata metadata = InitializrMetadataBuilder.create().withInitializrMetadata(
|
||||
new UrlResource(createUrl('/metadata/service'))).build()
|
||||
new UrlResource(createUrl('/metadata/config'))).build()
|
||||
// Basic assertions
|
||||
assertEquals(localMetadata.dependencies.content.size(), metadata.dependencies.content.size())
|
||||
assertEquals(localMetadata.types.content.size(), metadata.types.content.size())
|
||||
@@ -60,7 +60,7 @@ class MainControllerServiceMetadataIntegrationTests extends AbstractInitializrCo
|
||||
@Test
|
||||
void textPlainNotAccepted() {
|
||||
try {
|
||||
execute('/metadata/service', String, null, 'text/plain')
|
||||
execute('/metadata/config', String, null, 'text/plain')
|
||||
} catch (HttpClientErrorException ex) {
|
||||
assertEquals HttpStatus.NOT_ACCEPTABLE, ex.statusCode
|
||||
}
|
||||
@@ -68,11 +68,17 @@ class MainControllerServiceMetadataIntegrationTests extends AbstractInitializrCo
|
||||
|
||||
@Test
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
||||
@Test
|
||||
void metadataClientRedirect() {
|
||||
ResponseEntity<String> response = execute('/metadata/client', String, null, 'application/json')
|
||||
validateCurrentMetadata(response)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user