mirror of
https://gitee.com/dcren/initializr.git
synced 2025-04-05 17:38:06 +08:00
Polish contribution
Closes gh-295
This commit is contained in:
parent
b356e233a2
commit
e8dd74b8ed
@ -17,9 +17,7 @@
|
||||
package io.spring.initializr.actuate.stat
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests
|
||||
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
@ -48,7 +46,8 @@ import static org.junit.Assert.fail
|
||||
*/
|
||||
@Import(StatsMockController)
|
||||
@ActiveProfiles(['test-default', 'test-custom-stats'])
|
||||
class MainControllerStatsIntegrationTests extends AbstractFullStackInitializrIntegrationTests {
|
||||
class MainControllerStatsIntegrationTests
|
||||
extends AbstractFullStackInitializrIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private StatsMockController statsMockController
|
||||
|
@ -16,14 +16,12 @@
|
||||
|
||||
package io.spring.initializr.web
|
||||
|
||||
import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config
|
||||
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.springframework.boot.context.embedded.LocalServerPort
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.test.context.junit4.SpringRunner
|
||||
|
||||
import static org.junit.Assert.assertTrue
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
|
||||
|
||||
/**
|
||||
@ -32,11 +30,12 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Config.class, webEnvironment = RANDOM_PORT)
|
||||
abstract class AbstractFullStackInitializrIntegrationTests extends AbstractInitializrIntegrationTests {
|
||||
|
||||
abstract class AbstractFullStackInitializrIntegrationTests
|
||||
extends AbstractInitializrIntegrationTests {
|
||||
|
||||
@LocalServerPort
|
||||
int port
|
||||
|
||||
|
||||
String host = "localhost"
|
||||
|
||||
String createUrl(String context) {
|
||||
|
@ -30,17 +30,17 @@ import org.springframework.test.context.ContextConfiguration
|
||||
import org.springframework.test.context.TestExecutionListeners
|
||||
import org.springframework.test.context.TestExecutionListeners.MergeMode
|
||||
|
||||
import static org.junit.Assert.assertTrue
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ContextConfiguration(classes = RestTemplateConfig)
|
||||
@TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS, listeners = MockMvcClientHttpRequestFactoryTestExecutionListener)
|
||||
@TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS,
|
||||
listeners = MockMvcClientHttpRequestFactoryTestExecutionListener)
|
||||
@AutoConfigureMockMvc
|
||||
@AutoConfigureRestDocs(outputDir="target/snippets", uriPort=80, uriHost="start.spring.io")
|
||||
abstract class AbstractInitializrControllerIntegrationTests extends AbstractInitializrIntegrationTests {
|
||||
@AutoConfigureRestDocs(outputDir = "target/snippets", uriPort = 80,
|
||||
uriHost = "start.spring.io")
|
||||
abstract class AbstractInitializrControllerIntegrationTests
|
||||
extends AbstractInitializrIntegrationTests {
|
||||
|
||||
String host = "start.spring.io"
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package io.spring.initializr.web
|
||||
|
||||
import java.nio.charset.Charset
|
||||
|
||||
import io.spring.initializr.metadata.InitializrMetadata
|
||||
import io.spring.initializr.metadata.InitializrMetadataBuilder
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider
|
||||
@ -23,7 +25,6 @@ import io.spring.initializr.metadata.InitializrProperties
|
||||
import io.spring.initializr.test.generator.ProjectAssert
|
||||
import io.spring.initializr.web.mapper.InitializrMetadataVersion
|
||||
import io.spring.initializr.web.support.DefaultInitializrMetadataProvider
|
||||
|
||||
import org.json.JSONObject
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
@ -31,6 +32,7 @@ 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.Autowired
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
@ -46,10 +48,7 @@ import org.springframework.test.context.junit4.SpringRunner
|
||||
import org.springframework.util.StreamUtils
|
||||
import org.springframework.web.client.RestTemplate
|
||||
|
||||
import java.nio.charset.Charset
|
||||
|
||||
import static org.junit.Assert.assertTrue
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@ -234,4 +233,5 @@ abstract class AbstractInitializrIntegrationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
@Test
|
||||
void dependencyInRange() {
|
||||
def biz = new Dependency(id: 'biz', groupId: 'org.acme',
|
||||
artifactId: 'biz', version: '1.3.5', scope: 'runtime')
|
||||
artifactId: 'biz', version: '1.3.5', scope: 'runtime')
|
||||
downloadTgz('/starter.tgz?style=org.acme:biz&bootVersion=1.2.1.RELEASE').isJavaProject().isMavenProject()
|
||||
.hasStaticAndTemplatesResources(false).pomAssert()
|
||||
.hasDependenciesCount(2)
|
||||
@ -153,8 +153,7 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
}
|
||||
|
||||
@Test
|
||||
void metadataWithNoAcceptHeader() {
|
||||
// rest template sets application/json by default
|
||||
void metadataWithNoAcceptHeader() { // rest template sets application/json by default
|
||||
ResponseEntity<String> response = invokeHome(null, '*/*')
|
||||
validateCurrentMetadata(response)
|
||||
}
|
||||
@ -163,7 +162,7 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
@Ignore("Need a comparator that does not care about the number of elements in an array")
|
||||
void currentMetadataCompatibleWithV2() {
|
||||
ResponseEntity<String> response = invokeHome(null, '*/*')
|
||||
validateMetadata(response, AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE, '2.0.0', JSONCompareMode.LENIENT)
|
||||
validateMetadata(response, CURRENT_METADATA_MEDIA_TYPE, '2.0.0', JSONCompareMode.LENIENT)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -187,7 +186,7 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
void metadataWithSeveralAcceptHeader() {
|
||||
ResponseEntity<String> response = invokeHome(null,
|
||||
'application/vnd.initializr.v2.1+json', 'application/vnd.initializr.v2+json')
|
||||
validateContentType(response, AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE)
|
||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE)
|
||||
validateCurrentMetadata(new JSONObject(response.body))
|
||||
}
|
||||
|
||||
|
@ -16,16 +16,15 @@
|
||||
|
||||
package io.spring.initializr.web.project
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import io.spring.initializr.metadata.InitializrMetadata
|
||||
import io.spring.initializr.metadata.InitializrMetadataBuilder
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider
|
||||
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests
|
||||
|
||||
import org.json.JSONObject
|
||||
import org.junit.Test
|
||||
import org.skyscreamer.jsonassert.JSONAssert
|
||||
import org.skyscreamer.jsonassert.JSONCompareMode
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.core.io.UrlResource
|
||||
import org.springframework.http.HttpStatus
|
||||
@ -34,11 +33,14 @@ import org.springframework.http.ResponseEntity
|
||||
import org.springframework.test.context.ActiveProfiles
|
||||
import org.springframework.web.client.HttpClientErrorException
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ActiveProfiles('test-default')
|
||||
class MainControllerServiceMetadataIntegrationTests extends AbstractFullStackInitializrIntegrationTests {
|
||||
class MainControllerServiceMetadataIntegrationTests
|
||||
extends AbstractFullStackInitializrIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private InitializrMetadataProvider metadataProvider
|
||||
@ -70,7 +72,7 @@ class MainControllerServiceMetadataIntegrationTests extends AbstractFullStackIni
|
||||
void validateJson() {
|
||||
ResponseEntity<String> response = execute('/metadata/config', String, null, 'application/json')
|
||||
validateContentType(response, MediaType.APPLICATION_JSON)
|
||||
JSONObject json = new JSONObject(response.body)
|
||||
JSONObject json = new JSONObject(response.body)
|
||||
def expected = readJsonFrom("metadata/config/test-default.json")
|
||||
JSONAssert.assertEquals(expected, json, JSONCompareMode.STRICT)
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ import static org.junit.Assert.assertTrue
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ActiveProfiles('test-default')
|
||||
class ProjectGenerationSmokeTests extends AbstractFullStackInitializrIntegrationTests {
|
||||
class ProjectGenerationSmokeTests
|
||||
extends AbstractFullStackInitializrIntegrationTests {
|
||||
|
||||
private File downloadDir
|
||||
private WebDriver driver
|
||||
@ -388,7 +389,7 @@ class ProjectGenerationSmokeTests extends AbstractFullStackInitializrIntegration
|
||||
def projectAssert = zipProjectAssert(from('demo.zip'))
|
||||
projectAssert.hasBaseDir('demo')
|
||||
.isMavenProject()
|
||||
.isGroovyProject('com.example.acme', ProjectAssert.DEFAULT_APPLICATION_NAME )
|
||||
.isGroovyProject('com.example.acme', ProjectAssert.DEFAULT_APPLICATION_NAME)
|
||||
.hasStaticAndTemplatesResources(false)
|
||||
.pomAssert().hasDependenciesCount(3)
|
||||
.hasSpringBootStarterRootDependency().hasSpringBootStarterTest()
|
||||
@ -419,7 +420,7 @@ class ProjectGenerationSmokeTests extends AbstractFullStackInitializrIntegration
|
||||
def projectAssert = zipProjectAssert(from('my-project.zip'))
|
||||
projectAssert.hasBaseDir('my-project')
|
||||
.isMavenProject()
|
||||
.isJavaProject('com.example.acme', 'MyProjectApplication' )
|
||||
.isJavaProject('com.example.acme', 'MyProjectApplication')
|
||||
.hasStaticAndTemplatesResources(false)
|
||||
.pomAssert()
|
||||
.hasGroupId('com.example.acme')
|
||||
|
@ -27,7 +27,6 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Jeremy Rickard
|
||||
*
|
||||
*/
|
||||
//Copied from RestDocs to make it visible
|
||||
final class JsonFieldPath {
|
||||
@ -127,4 +126,5 @@ final class JsonFieldPath {
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
* extracted and removed.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*
|
||||
*/
|
||||
// Copied from RestDocs to make it visible
|
||||
final class JsonFieldProcessor {
|
||||
|
@ -16,6 +16,14 @@
|
||||
|
||||
package io.spring.initializr.web.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -31,23 +39,12 @@ import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class MockMvcClientHttpRequestFactory implements ClientHttpRequestFactory {
|
||||
|
||||
@ -132,7 +129,7 @@ public class MockMvcClientHttpRequestFactory implements ClientHttpRequestFactory
|
||||
public void setTest(Class<?> testClass, Method testMethod) {
|
||||
this.label = testMethod.getName();
|
||||
}
|
||||
|
||||
|
||||
public void setFields(String... fields) {
|
||||
this.fields = Arrays.asList(fields);
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public final class MockMvcClientHttpRequestFactoryTestExecutionListener
|
||||
extends AbstractTestExecutionListener {
|
||||
@ -39,7 +38,8 @@ public final class MockMvcClientHttpRequestFactoryTestExecutionListener
|
||||
beanFactory.getBean(MockMvc.class));
|
||||
beanFactory.registerSingleton("mockMvcClientHttpRequestFactory",
|
||||
this.factory);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
factory = beanFactory.getBean("mockMvcClientHttpRequestFactory", MockMvcClientHttpRequestFactory.class);
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,6 @@
|
||||
|
||||
package io.spring.initializr.web.test;
|
||||
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.restdocs.operation.Operation;
|
||||
import org.springframework.restdocs.snippet.TemplatedSnippet;
|
||||
import org.springframework.restdocs.snippet.WriterResolver;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Collections;
|
||||
@ -31,16 +25,21 @@ import java.util.Map;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.restdocs.operation.Operation;
|
||||
import org.springframework.restdocs.snippet.TemplatedSnippet;
|
||||
import org.springframework.restdocs.snippet.WriterResolver;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
|
||||
/**
|
||||
* Creates a separate snippet for a single field in a larger payload. The output comes in
|
||||
* a sub-directory ("response-fields") of one containing the request and response
|
||||
* snippets, with a file name the same as the path. An exception to the last rule is if
|
||||
* you pick a single array element by using a path like `foo.bar[0]`, the snippet file
|
||||
* name is then just the array name (because asciidoctor cannot import snippets with
|
||||
* brackets in the name).
|
||||
*
|
||||
* @author Dave Syer
|
||||
* Creates a separate snippet for a single field in a larger payload. The output
|
||||
* comes in a sub-directory ("response-fields") of one containing the request and
|
||||
* response snippets, with a file name the same as the path. An exception to the last
|
||||
* rule is if you pick a single array element by using a path like `foo.bar[0]`, the
|
||||
* snippet file name is then just the array name (because asciidoctor cannot import
|
||||
* snippets with brackets in the name).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class ResponseFieldSnippet extends TemplatedSnippet {
|
||||
|
||||
@ -51,7 +50,7 @@ public class ResponseFieldSnippet extends TemplatedSnippet {
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final Integer index;
|
||||
|
||||
|
||||
private final String file;
|
||||
|
||||
public ResponseFieldSnippet(String path) {
|
||||
@ -66,7 +65,8 @@ public class ResponseFieldSnippet extends TemplatedSnippet {
|
||||
this.index = Integer.valueOf(index);
|
||||
path = path.substring(0, path.lastIndexOf("["));
|
||||
file = file.replace("]", "").replace("[", ".");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.index = null;
|
||||
}
|
||||
this.file = file;
|
||||
|
@ -17,11 +17,11 @@
|
||||
package io.spring.initializr.web.ui
|
||||
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests
|
||||
|
||||
import org.json.JSONObject
|
||||
import org.junit.Test
|
||||
import org.skyscreamer.jsonassert.JSONAssert
|
||||
import org.skyscreamer.jsonassert.JSONCompareMode
|
||||
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.test.context.ActiveProfiles
|
||||
@ -30,7 +30,8 @@ import org.springframework.test.context.ActiveProfiles
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ActiveProfiles('test-default')
|
||||
class UiControllerIntegrationTests extends AbstractInitializrControllerIntegrationTests {
|
||||
class UiControllerIntegrationTests
|
||||
extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
@Test
|
||||
void dependenciesNoVersion() {
|
||||
@ -50,4 +51,5 @@ class UiControllerIntegrationTests extends AbstractInitializrControllerIntegrati
|
||||
def expected = readJsonFrom("metadata/ui/test-dependencies-$version" + ".json")
|
||||
JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user