mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-26 22:25:51 +08:00
Reformat code
Format code using a pre-release version of the spring-javaformat plugin.
This commit is contained in:
@@ -35,8 +35,7 @@ import org.springframework.test.context.TestExecutionListeners.MergeMode;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ContextConfiguration(classes = RestTemplateConfig.class)
|
||||
@TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS,
|
||||
listeners = MockMvcClientHttpRequestFactoryTestExecutionListener.class)
|
||||
@TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS, listeners = MockMvcClientHttpRequestFactoryTestExecutionListener.class)
|
||||
@AutoConfigureMockMvc
|
||||
@AutoConfigureRestDocs(outputDir = "target/snippets", uriPort = 80, uriHost = "start.spring.io")
|
||||
public abstract class AbstractInitializrControllerIntegrationTests
|
||||
@@ -45,8 +44,7 @@ public abstract class AbstractInitializrControllerIntegrationTests
|
||||
protected String host = "start.spring.io";
|
||||
|
||||
@Autowired
|
||||
private
|
||||
MockMvcClientHttpRequestFactory requests;
|
||||
private MockMvcClientHttpRequestFactory requests;
|
||||
|
||||
@Override
|
||||
protected String createUrl(String context) {
|
||||
@@ -65,5 +63,7 @@ public abstract class AbstractInitializrControllerIntegrationTests
|
||||
return template -> template.setRequestFactory(
|
||||
beanFactory.getBean(MockMvcClientHttpRequestFactory.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,8 +71,8 @@ import static org.junit.Assert.assertTrue;
|
||||
@SpringBootTest(classes = Config.class)
|
||||
public abstract class AbstractInitializrIntegrationTests {
|
||||
|
||||
protected static final MediaType CURRENT_METADATA_MEDIA_TYPE =
|
||||
InitializrMetadataVersion.V2_1.getMediaType();
|
||||
protected static final MediaType CURRENT_METADATA_MEDIA_TYPE = InitializrMetadataVersion.V2_1
|
||||
.getMediaType();
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@@ -138,7 +138,8 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
protected void validateCurrentMetadata(String json) {
|
||||
try {
|
||||
JSONObject expected = readMetadataJson("2.1.0");
|
||||
JSONAssert.assertEquals(expected, new JSONObject(json), JSONCompareMode.STRICT);
|
||||
JSONAssert.assertEquals(expected, new JSONObject(json),
|
||||
JSONCompareMode.STRICT);
|
||||
}
|
||||
catch (JSONException ex) {
|
||||
throw new IllegalArgumentException("Invalid json", ex);
|
||||
@@ -208,12 +209,12 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
|
||||
File project = folder.newFolder();
|
||||
switch (archiveType) {
|
||||
case ZIP:
|
||||
unzip(archiveFile, project);
|
||||
break;
|
||||
case TGZ:
|
||||
untar(archiveFile, project);
|
||||
break;
|
||||
case ZIP:
|
||||
unzip(archiveFile, project);
|
||||
break;
|
||||
case TGZ:
|
||||
untar(archiveFile, project);
|
||||
break;
|
||||
}
|
||||
return new ProjectAssert(project);
|
||||
}
|
||||
@@ -259,8 +260,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
placeholder = ((AbstractInitializrControllerIntegrationTests) this).host;
|
||||
}
|
||||
if (this instanceof AbstractFullStackInitializrIntegrationTests) {
|
||||
AbstractFullStackInitializrIntegrationTests test =
|
||||
(AbstractFullStackInitializrIntegrationTests) this;
|
||||
AbstractFullStackInitializrIntegrationTests test = (AbstractFullStackInitializrIntegrationTests) this;
|
||||
placeholder = test.host + ":" + test.port;
|
||||
}
|
||||
// Let's parse the port as it is random
|
||||
@@ -279,9 +279,11 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
}
|
||||
|
||||
private enum ArchiveType {
|
||||
|
||||
ZIP,
|
||||
|
||||
TGZ
|
||||
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@@ -301,4 +303,5 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,9 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class CloudfoundryEnvironmentPostProcessorTests {
|
||||
|
||||
private final CloudfoundryEnvironmentPostProcessor postProcessor =
|
||||
new CloudfoundryEnvironmentPostProcessor();
|
||||
private final CloudfoundryEnvironmentPostProcessor postProcessor = new CloudfoundryEnvironmentPostProcessor();
|
||||
|
||||
private final MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
private final SpringApplication application = new SpringApplication();
|
||||
|
||||
@Test
|
||||
|
||||
@@ -42,9 +42,7 @@ public class InitializrAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(RestTemplateAutoConfiguration.class,
|
||||
JacksonAutoConfiguration.class,
|
||||
InitializrAutoConfiguration.class));
|
||||
|
||||
JacksonAutoConfiguration.class, InitializrAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void customRestTemplateBuilderIsUsed() {
|
||||
@@ -53,16 +51,17 @@ public class InitializrAutoConfigurationTests {
|
||||
assertThat(context).hasSingleBean(InitializrMetadataProvider.class);
|
||||
RestTemplate restTemplate = (RestTemplate) new DirectFieldAccessor(
|
||||
context.getBean(InitializrMetadataProvider.class))
|
||||
.getPropertyValue("restTemplate");
|
||||
assertThat(restTemplate.getErrorHandler()).isSameAs(
|
||||
CustomRestTemplateConfiguration.errorHandler);
|
||||
.getPropertyValue("restTemplate");
|
||||
assertThat(restTemplate.getErrorHandler())
|
||||
.isSameAs(CustomRestTemplateConfiguration.errorHandler);
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomRestTemplateConfiguration {
|
||||
|
||||
private static final ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class);
|
||||
private static final ResponseErrorHandler errorHandler = mock(
|
||||
ResponseErrorHandler.class);
|
||||
|
||||
@Bean
|
||||
public RestTemplateCustomizer testRestTemplateCustomizer() {
|
||||
|
||||
@@ -34,8 +34,7 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class DependencyMetadataJsonMapperTests {
|
||||
|
||||
private final DependencyMetadataJsonMapper mapper =
|
||||
new DependencyMetadataV21JsonMapper();
|
||||
private final DependencyMetadataJsonMapper mapper = new DependencyMetadataV21JsonMapper();
|
||||
|
||||
@Test
|
||||
public void mapDependency() throws Exception {
|
||||
|
||||
@@ -36,8 +36,7 @@ public class InitializrMetadataJsonMapperTests {
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final InitializrMetadataJsonMapper jsonMapper =
|
||||
new InitializrMetadataV21JsonMapper();
|
||||
private final InitializrMetadataJsonMapper jsonMapper = new InitializrMetadataV21JsonMapper();
|
||||
|
||||
@Test
|
||||
public void withNoAppUrl() throws IOException {
|
||||
@@ -46,8 +45,10 @@ public class InitializrMetadataJsonMapperTests {
|
||||
.addDependencyGroup("foo", "one", "two").build();
|
||||
String json = jsonMapper.write(metadata, null);
|
||||
JsonNode result = objectMapper.readTree(json);
|
||||
assertEquals("/foo.zip?type=foo{&dependencies,packaging,javaVersion,language,bootVersion," +
|
||||
"groupId,artifactId,version,name,description,packageName}", get(result, "_links.foo.href"));
|
||||
assertEquals(
|
||||
"/foo.zip?type=foo{&dependencies,packaging,javaVersion,language,bootVersion,"
|
||||
+ "groupId,artifactId,version,name,description,packageName}",
|
||||
get(result, "_links.foo.href"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,8 +58,9 @@ public class InitializrMetadataJsonMapperTests {
|
||||
.addDependencyGroup("foo", "one", "two").build();
|
||||
String json = jsonMapper.write(metadata, "http://server:8080/my-app");
|
||||
JsonNode result = objectMapper.readTree(json);
|
||||
assertEquals("http://server:8080/my-app/foo.zip?type=foo{&dependencies,packaging,javaVersion," +
|
||||
"language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
assertEquals(
|
||||
"http://server:8080/my-app/foo.zip?type=foo{&dependencies,packaging,javaVersion,"
|
||||
+ "language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
get(result, "_links.foo.href"));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,10 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
/**
|
||||
* Validate that the "raw" HTTP commands that are described in the
|
||||
* command-line help works. If anything needs to be updated here, please
|
||||
* double check the "curl-examples.txt" as it may need an update
|
||||
* as well. This is also a good indicator of a non backward compatible
|
||||
* change.
|
||||
* Validate that the "raw" HTTP commands that are described in the command-line help
|
||||
* works. If anything needs to be updated here, please double check the
|
||||
* "curl-examples.txt" as it may need an update as well. This is also a good indicator of
|
||||
* a non backward compatible change.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@@ -38,10 +37,9 @@ public class CommandLineExampleIntegrationTests
|
||||
|
||||
@Test
|
||||
public void generateDefaultProject() {
|
||||
downloadZip("/starter.zip").isJavaProject()
|
||||
.isMavenProject().hasStaticAndTemplatesResources(false).pomAssert()
|
||||
.hasSpringBootStarterRootDependency()
|
||||
.hasSpringBootStarterTest()
|
||||
downloadZip("/starter.zip").isJavaProject().isMavenProject()
|
||||
.hasStaticAndTemplatesResources(false).pomAssert()
|
||||
.hasSpringBootStarterRootDependency().hasSpringBootStarterTest()
|
||||
.hasDependenciesCount(2);
|
||||
}
|
||||
|
||||
@@ -49,27 +47,24 @@ public class CommandLineExampleIntegrationTests
|
||||
public void generateWebProjectWithJava8() {
|
||||
downloadZip("/starter.zip?dependencies=web&javaVersion=1.8").isJavaProject()
|
||||
.isMavenProject().hasStaticAndTemplatesResources(true).pomAssert()
|
||||
.hasJavaVersion("1.8")
|
||||
.hasSpringBootStarterDependency("web")
|
||||
.hasSpringBootStarterTest()
|
||||
.hasDependenciesCount(2);
|
||||
.hasJavaVersion("1.8").hasSpringBootStarterDependency("web")
|
||||
.hasSpringBootStarterTest().hasDependenciesCount(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateWebDataJpaGradleProject() {
|
||||
downloadTgz("/starter.tgz?dependencies=web,data-jpa&type=gradle-project&baseDir=my-dir")
|
||||
.hasBaseDir("my-dir")
|
||||
.isJavaProject()
|
||||
.isGradleProject().hasStaticAndTemplatesResources(true)
|
||||
.gradleBuildAssert()
|
||||
.contains("spring-boot-starter-web")
|
||||
.contains("spring-boot-starter-data-jpa");
|
||||
downloadTgz(
|
||||
"/starter.tgz?dependencies=web,data-jpa&type=gradle-project&baseDir=my-dir")
|
||||
.hasBaseDir("my-dir").isJavaProject().isGradleProject()
|
||||
.hasStaticAndTemplatesResources(true).gradleBuildAssert()
|
||||
.contains("spring-boot-starter-web")
|
||||
.contains("spring-boot-starter-data-jpa");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateMavenPomWithWarPackaging() {
|
||||
ResponseEntity<String> response = getRestTemplate().getForEntity(
|
||||
createUrl("/pom.xml?packaging=war"), String.class);
|
||||
ResponseEntity<String> response = getRestTemplate()
|
||||
.getForEntity(createUrl("/pom.xml?packaging=war"), String.class);
|
||||
PomAssert pomAssert = new PomAssert(response.getBody());
|
||||
pomAssert.hasPackaging("war");
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ import org.openqa.selenium.support.ui.Select;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class HomePage {
|
||||
|
||||
@FindBy(id = "form")
|
||||
private WebElement form;
|
||||
|
||||
private final WebDriver driver;
|
||||
|
||||
public HomePage(WebDriver driver) {
|
||||
@@ -91,8 +91,8 @@ class HomePage {
|
||||
}
|
||||
|
||||
public void advanced() {
|
||||
form.findElement(By.cssSelector(".tofullversion"))
|
||||
.findElement(By.tagName("a")).click();
|
||||
form.findElement(By.cssSelector(".tofullversion")).findElement(By.tagName("a"))
|
||||
.click();
|
||||
}
|
||||
|
||||
public void simple() {
|
||||
|
||||
@@ -50,10 +50,10 @@ public class LegacyStsControllerIntegrationTests
|
||||
assertTrue("artifactId not found", body.contains("demo"));
|
||||
assertTrue("custom description not found",
|
||||
body.contains("Demo project for Spring Boot"));
|
||||
assertTrue("Wrong body:\n" + body,
|
||||
body.contains("<input type=\"radio\" name=\"language\" value=\"groovy\"/>"));
|
||||
assertTrue("Wrong body:\n" + body,
|
||||
body.contains("<input type=\"radio\" name=\"language\" value=\"java\" checked=\"true\"/>"));
|
||||
assertTrue("Wrong body:\n" + body, body
|
||||
.contains("<input type=\"radio\" name=\"language\" value=\"groovy\"/>"));
|
||||
assertTrue("Wrong body:\n" + body, body.contains(
|
||||
"<input type=\"radio\" name=\"language\" value=\"java\" checked=\"true\"/>"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,12 +35,12 @@ public class MainControllerDefaultsIntegrationTests
|
||||
|
||||
@Test
|
||||
public void generateDefaultPom() {
|
||||
String content = getRestTemplate().getForObject(
|
||||
createUrl("/pom.xml?style=web"), String.class);
|
||||
String content = getRestTemplate().getForObject(createUrl("/pom.xml?style=web"),
|
||||
String.class);
|
||||
PomAssert pomAssert = new PomAssert(content);
|
||||
pomAssert.hasGroupId("org.foo").hasArtifactId("foo-bar")
|
||||
.hasVersion("1.2.4-SNAPSHOT").hasPackaging("jar")
|
||||
.hasName("FooBar").hasDescription("FooBar Project");
|
||||
.hasVersion("1.2.4-SNAPSHOT").hasPackaging("jar").hasName("FooBar")
|
||||
.hasDescription("FooBar Project");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -49,8 +49,9 @@ public class MainControllerDependenciesTests
|
||||
|
||||
@Test
|
||||
public void filteredDependencies() throws JSONException {
|
||||
ResponseEntity<String> response = execute("/dependencies?bootVersion=1.2.1.RELEASE",
|
||||
String.class, null, "application/json");
|
||||
ResponseEntity<String> response = execute(
|
||||
"/dependencies?bootVersion=1.2.1.RELEASE", String.class, null,
|
||||
"application/json");
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateDependenciesOutput("1.2.1", response.getBody());
|
||||
|
||||
@@ -39,8 +39,8 @@ public class MainControllerEnvIntegrationTests
|
||||
|
||||
@Test
|
||||
public void downloadCliWithCustomRepository() throws Exception {
|
||||
ResponseEntity<?> entity = getRestTemplate().getForEntity(
|
||||
createUrl("/spring"), String.class);
|
||||
ResponseEntity<?> entity = getRestTemplate().getForEntity(createUrl("/spring"),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
String expected = "https://repo.spring.io/lib-release/org/springframework/boot/spring-boot-cli/1.1.4.RELEASE/spring-boot-cli-1.1.4.RELEASE-bin.zip";
|
||||
assertEquals(new URI(expected), entity.getHeaders().getLocation());
|
||||
@@ -58,10 +58,8 @@ public class MainControllerEnvIntegrationTests
|
||||
public void generateProjectWithInvalidName() {
|
||||
downloadZip("/starter.zip?style=data-jpa&name=Invalid")
|
||||
.isJavaProject(ProjectAssert.DEFAULT_PACKAGE_NAME, "FooBarApplication")
|
||||
.isMavenProject()
|
||||
.hasStaticAndTemplatesResources(false).pomAssert()
|
||||
.hasDependenciesCount(2)
|
||||
.hasSpringBootStarterDependency("data-jpa")
|
||||
.isMavenProject().hasStaticAndTemplatesResources(false).pomAssert()
|
||||
.hasDependenciesCount(2).hasSpringBootStarterDependency("data-jpa")
|
||||
.hasSpringBootStarterTest();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,7 @@ public class MainControllerIntegrationTests
|
||||
@Test
|
||||
public void simpleZipProject() {
|
||||
downloadZip("/starter.zip?style=web&style=jpa").isJavaProject()
|
||||
.hasFile(".gitignore")
|
||||
.hasExecutableFile("mvnw").isMavenProject()
|
||||
.hasFile(".gitignore").hasExecutableFile("mvnw").isMavenProject()
|
||||
.hasStaticAndTemplatesResources(true).pomAssert().hasDependenciesCount(3)
|
||||
.hasSpringBootStarterDependency("web")
|
||||
.hasSpringBootStarterDependency("data-jpa") // alias jpa -> data-jpa
|
||||
@@ -67,8 +66,7 @@ public class MainControllerIntegrationTests
|
||||
@Test
|
||||
public void simpleTgzProject() {
|
||||
downloadTgz("/starter.tgz?style=org.acme:foo").isJavaProject()
|
||||
.hasFile(".gitignore")
|
||||
.hasExecutableFile("mvnw").isMavenProject()
|
||||
.hasFile(".gitignore").hasExecutableFile("mvnw").isMavenProject()
|
||||
.hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(2)
|
||||
.hasDependency("org.acme", "foo", "1.3.5");
|
||||
}
|
||||
@@ -84,7 +82,8 @@ public class MainControllerIntegrationTests
|
||||
@Test
|
||||
public void dependencyNotInRange() {
|
||||
try {
|
||||
execute("/starter.tgz?style=org.acme:bur", byte[].class, null, (String[]) null);
|
||||
execute("/starter.tgz?style=org.acme:bur", byte[].class, null,
|
||||
(String[]) null);
|
||||
}
|
||||
catch (HttpClientErrorException ex) {
|
||||
assertEquals(HttpStatus.NOT_ACCEPTABLE, ex.getStatusCode());
|
||||
@@ -96,8 +95,7 @@ public class MainControllerIntegrationTests
|
||||
downloadZip("/starter.zip").isJavaProject().isMavenProject()
|
||||
.hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(2)
|
||||
// the root dep is added if none is specified
|
||||
.hasSpringBootStarterRootDependency()
|
||||
.hasSpringBootStarterTest();
|
||||
.hasSpringBootStarterRootDependency().hasSpringBootStarterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,8 +119,7 @@ public class MainControllerIntegrationTests
|
||||
@Test
|
||||
public void kotlinRange() {
|
||||
downloadZip("/starter.zip?style=web&language=kotlin&bootVersion=1.2.1.RELEASE")
|
||||
.isKotlinProject().isMavenProject()
|
||||
.pomAssert().hasDependenciesCount(4)
|
||||
.isKotlinProject().isMavenProject().pomAssert().hasDependenciesCount(4)
|
||||
.hasProperty("kotlin.version", "1.1");
|
||||
}
|
||||
|
||||
@@ -318,39 +315,32 @@ public class MainControllerIntegrationTests
|
||||
private void validateCurlHelpContent(ResponseEntity<String> response) {
|
||||
validateContentType(response, MediaType.TEXT_PLAIN);
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getBody(), allOf(
|
||||
containsString("Spring Initializr"),
|
||||
containsString("Examples:"),
|
||||
containsString("curl")));
|
||||
assertThat(response.getBody(), allOf(containsString("Spring Initializr"),
|
||||
containsString("Examples:"), containsString("curl")));
|
||||
}
|
||||
|
||||
private void validateHttpIeHelpContent(ResponseEntity<String> response) {
|
||||
validateContentType(response, MediaType.TEXT_PLAIN);
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getBody(), allOf(
|
||||
containsString("Spring Initializr"),
|
||||
containsString("Examples:"),
|
||||
not(containsString("curl")),
|
||||
containsString("http")));
|
||||
assertThat(response.getBody(),
|
||||
allOf(containsString("Spring Initializr"), containsString("Examples:"),
|
||||
not(containsString("curl")), containsString("http")));
|
||||
}
|
||||
|
||||
private void validateGenericHelpContent(ResponseEntity<String> response) {
|
||||
validateContentType(response, MediaType.TEXT_PLAIN);
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getBody(), allOf(
|
||||
containsString("Spring Initializr"),
|
||||
not(containsString("Examples:")),
|
||||
not(containsString("curl"))));
|
||||
assertThat(response.getBody(), allOf(containsString("Spring Initializr"),
|
||||
not(containsString("Examples:")), not(containsString("curl"))));
|
||||
}
|
||||
|
||||
private void validateSpringBootHelpContent(ResponseEntity<String> response) {
|
||||
validateContentType(response, MediaType.TEXT_PLAIN);
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getBody(), allOf(
|
||||
containsString("Service capabilities"),
|
||||
containsString("Supported dependencies"),
|
||||
not(containsString("Examples:")),
|
||||
not(containsString("curl"))));
|
||||
assertThat(response.getBody(),
|
||||
allOf(containsString("Service capabilities"),
|
||||
containsString("Supported dependencies"),
|
||||
not(containsString("Examples:")), not(containsString("curl"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -387,16 +377,16 @@ public class MainControllerIntegrationTests
|
||||
|
||||
@Test
|
||||
public void webIsAddedPom() {
|
||||
String body = getRestTemplate().getForObject(
|
||||
createUrl("/pom.xml?packaging=war"), String.class);
|
||||
String body = getRestTemplate().getForObject(createUrl("/pom.xml?packaging=war"),
|
||||
String.class);
|
||||
assertTrue("Wrong body:\n" + body, body.contains("spring-boot-starter-web"));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("provided"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webIsAddedGradle() {
|
||||
String body = getRestTemplate().getForObject(
|
||||
createUrl("/build.gradle?packaging=war"), String.class);
|
||||
String body = getRestTemplate()
|
||||
.getForObject(createUrl("/build.gradle?packaging=war"), String.class);
|
||||
assertTrue("Wrong body:\n" + body, body.contains("spring-boot-starter-web"));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("providedRuntime"));
|
||||
}
|
||||
@@ -424,15 +414,16 @@ public class MainControllerIntegrationTests
|
||||
|
||||
@Test
|
||||
public void downloadStarter() {
|
||||
byte[] body = getRestTemplate().getForObject(
|
||||
createUrl("starter.zip"), byte[].class);
|
||||
byte[] body = getRestTemplate().getForObject(createUrl("starter.zip"),
|
||||
byte[].class);
|
||||
assertNotNull(body);
|
||||
assertTrue(body.length > 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void installer() {
|
||||
ResponseEntity<String> response = getRestTemplate().getForEntity(createUrl("install.sh"), String.class);
|
||||
ResponseEntity<String> response = getRestTemplate()
|
||||
.getForEntity(createUrl("install.sh"), String.class);
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
}
|
||||
@@ -440,7 +431,8 @@ public class MainControllerIntegrationTests
|
||||
@Test
|
||||
public void googleAnalyticsDisabledByDefault() {
|
||||
String body = htmlHome();
|
||||
assertFalse("google analytics should be disabled", body.contains("GoogleAnalyticsObject"));
|
||||
assertFalse("google analytics should be disabled",
|
||||
body.contains("GoogleAnalyticsObject"));
|
||||
}
|
||||
|
||||
private String getMetadataJson() {
|
||||
|
||||
@@ -34,17 +34,13 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
public class ProjectGenerationPostProcessorTests
|
||||
extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void postProcessorsInvoked() {
|
||||
downloadZip("/starter.zip?bootVersion=1.2.4.RELEASE&javaVersion=1.6")
|
||||
.isJavaProject()
|
||||
.isMavenProject().pomAssert()
|
||||
.hasSpringBootParent("1.2.3.RELEASE")
|
||||
.hasProperty("java.version", "1.7");
|
||||
.isJavaProject().isMavenProject().pomAssert()
|
||||
.hasSpringBootParent("1.2.3.RELEASE").hasProperty("java.version", "1.7");
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class ProjectRequestPostProcessorConfiguration {
|
||||
|
||||
@@ -53,7 +49,8 @@ public class ProjectGenerationPostProcessorTests
|
||||
ProjectRequestPostProcessor secondPostProcessor() {
|
||||
return new ProjectRequestPostProcessor() {
|
||||
@Override
|
||||
public void postProcessBeforeResolution(ProjectRequest request, InitializrMetadata metadata) {
|
||||
public void postProcessBeforeResolution(ProjectRequest request,
|
||||
InitializrMetadata metadata) {
|
||||
request.setJavaVersion("1.7");
|
||||
}
|
||||
};
|
||||
@@ -64,7 +61,8 @@ public class ProjectGenerationPostProcessorTests
|
||||
ProjectRequestPostProcessor firstPostProcessor() {
|
||||
return new ProjectRequestPostProcessor() {
|
||||
@Override
|
||||
public void postProcessBeforeResolution(ProjectRequest request, InitializrMetadata metadata) {
|
||||
public void postProcessBeforeResolution(ProjectRequest request,
|
||||
InitializrMetadata metadata) {
|
||||
request.setJavaVersion("1.2");
|
||||
request.setBootVersion("1.2.3.RELEASE");
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class ProjectGenerationSmokeTests
|
||||
extends AbstractFullStackInitializrIntegrationTests {
|
||||
|
||||
private File downloadDir;
|
||||
|
||||
private WebDriver driver;
|
||||
|
||||
private Action enterAction;
|
||||
@@ -379,4 +380,3 @@ public class ProjectGenerationSmokeTests
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ import static org.junit.Assert.assertSame;
|
||||
*/
|
||||
public class DefaultDependencyMetadataProviderTests {
|
||||
|
||||
private final DependencyMetadataProvider provider =
|
||||
new DefaultDependencyMetadataProvider();
|
||||
private final DependencyMetadataProvider provider = new DefaultDependencyMetadataProvider();
|
||||
|
||||
@Test
|
||||
public void filterDependencies() {
|
||||
@@ -181,8 +180,8 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
"2.0.0.RELEASE", "repo-foo", "repo-bar"));
|
||||
bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.0.RELEASE",
|
||||
"3.0.0.RELEASE", "repo-biz"));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder
|
||||
.withDefaults().addBom("bom-foo", bom)
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addBom("bom-foo", bom)
|
||||
.addRepository("repo-foo", "foo", "http://localhost", false)
|
||||
.addRepository("repo-bar", "bar", "http://localhost", false)
|
||||
.addRepository("repo-biz", "biz", "http://localhost", false)
|
||||
|
||||
@@ -60,19 +60,17 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
public void bootVersionsAreReplaced() {
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
|
||||
.addBootVersion("0.0.9.RELEASE", true)
|
||||
.addBootVersion("0.0.8.RELEASE", false)
|
||||
.build();
|
||||
.addBootVersion("0.0.8.RELEASE", false).build();
|
||||
assertEquals("0.0.9.RELEASE", metadata.getBootVersions().getDefault().getId());
|
||||
DefaultInitializrMetadataProvider provider =
|
||||
new DefaultInitializrMetadataProvider(metadata, objectMapper,
|
||||
restTemplate);
|
||||
DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider(
|
||||
metadata, objectMapper, restTemplate);
|
||||
expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(),
|
||||
"metadata/sagan/spring-boot.json");
|
||||
|
||||
InitializrMetadata updatedMetadata = provider.get();
|
||||
assertNotNull(updatedMetadata.getBootVersions());
|
||||
List<DefaultMetadataElement> updatedBootVersions =
|
||||
updatedMetadata.getBootVersions().getContent();
|
||||
List<DefaultMetadataElement> updatedBootVersions = updatedMetadata
|
||||
.getBootVersions().getContent();
|
||||
assertEquals(4, updatedBootVersions.size());
|
||||
assertBootVersion(updatedBootVersions.get(0), "1.4.1 (SNAPSHOT)", false);
|
||||
assertBootVersion(updatedBootVersions.get(1), "1.4.0", true);
|
||||
@@ -86,16 +84,15 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
.addBootVersion("0.0.9.RELEASE", true)
|
||||
.addBootVersion("0.0.8.RELEASE", false).build();
|
||||
assertEquals("0.0.9.RELEASE", metadata.getBootVersions().getDefault().getId());
|
||||
DefaultInitializrMetadataProvider provider =
|
||||
new DefaultInitializrMetadataProvider(metadata, objectMapper,
|
||||
restTemplate);
|
||||
DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider(
|
||||
metadata, objectMapper, restTemplate);
|
||||
expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(),
|
||||
"metadata/sagan/spring-boot-no-default.json");
|
||||
|
||||
InitializrMetadata updatedMetadata = provider.get();
|
||||
assertNotNull(updatedMetadata.getBootVersions());
|
||||
List<DefaultMetadataElement> updatedBootVersions =
|
||||
updatedMetadata.getBootVersions().getContent();
|
||||
List<DefaultMetadataElement> updatedBootVersions = updatedMetadata
|
||||
.getBootVersions().getContent();
|
||||
assertEquals(4, updatedBootVersions.size());
|
||||
assertBootVersion(updatedBootVersions.get(0), "1.3.1 (SNAPSHOT)", true);
|
||||
assertBootVersion(updatedBootVersions.get(1), "1.3.0", false);
|
||||
@@ -112,11 +109,9 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
private void expectJson(String url, String bodyPath) {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
this.mockServer.expect(requestTo(url))
|
||||
.andExpect(method(HttpMethod.GET))
|
||||
this.mockServer.expect(requestTo(url)).andExpect(method(HttpMethod.GET))
|
||||
.andRespond(withStatus(HttpStatus.OK)
|
||||
.body(new ClassPathResource(bodyPath))
|
||||
.headers(httpHeaders));
|
||||
.body(new ClassPathResource(bodyPath)).headers(httpHeaders));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,15 +42,15 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
*/
|
||||
public class SpringBootMetadataReaderTests {
|
||||
|
||||
private final InitializrMetadata metadata =
|
||||
InitializrMetadataBuilder.create().build();
|
||||
private final InitializrMetadata metadata = InitializrMetadataBuilder.create()
|
||||
.build();
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
private final MockRestServiceServer server =
|
||||
MockRestServiceServer.bindTo(restTemplate).build();
|
||||
private final MockRestServiceServer server = MockRestServiceServer
|
||||
.bindTo(restTemplate).build();
|
||||
|
||||
@Test
|
||||
public void readAvailableVersions() throws IOException {
|
||||
@@ -59,8 +59,9 @@ public class SpringBootMetadataReaderTests {
|
||||
new ClassPathResource("metadata/sagan/spring-boot.json"),
|
||||
MediaType.APPLICATION_JSON));
|
||||
List<DefaultMetadataElement> versions = new SpringBootMetadataReader(objectMapper,
|
||||
restTemplate, metadata.getConfiguration().getEnv()
|
||||
.getSpringBootMetadataUrl()).getBootVersions();
|
||||
restTemplate,
|
||||
metadata.getConfiguration().getEnv().getSpringBootMetadataUrl())
|
||||
.getBootVersions();
|
||||
assertNotNull("spring boot versions should not be null", versions);
|
||||
AtomicBoolean defaultFound = new AtomicBoolean(false);
|
||||
versions.forEach(it -> {
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.regex.Pattern;
|
||||
* @author Andy Wilkinson
|
||||
* @author Jeremy Rickard
|
||||
*/
|
||||
//Copied from RestDocs to make it visible
|
||||
// Copied from RestDocs to make it visible
|
||||
final class JsonFieldPath {
|
||||
|
||||
private static final Pattern BRACKETS_AND_ARRAY_PATTERN = Pattern
|
||||
|
||||
@@ -39,7 +39,8 @@ final class JsonFieldProcessor {
|
||||
|
||||
Object extract(JsonFieldPath path, Object payload) {
|
||||
final List<Object> matches = new ArrayList<>();
|
||||
traverse(new ProcessingContext(payload, path), match -> matches.add(match.getValue()));
|
||||
traverse(new ProcessingContext(payload, path),
|
||||
match -> matches.add(match.getValue()));
|
||||
if (matches.isEmpty()) {
|
||||
throw new IllegalArgumentException("Field does not exist: " + path);
|
||||
}
|
||||
@@ -179,6 +180,7 @@ final class JsonFieldProcessor {
|
||||
Object getValue();
|
||||
|
||||
void remove();
|
||||
|
||||
}
|
||||
|
||||
private static final class ProcessingContext {
|
||||
@@ -224,6 +226,7 @@ final class JsonFieldProcessor {
|
||||
return new ProcessingContext(payload, this.path,
|
||||
this.segments.subList(1, this.segments.size()), match);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,8 @@ public class MockMvcClientHttpRequestFactory implements ClientHttpRequestFactory
|
||||
for (String field : this.fields) {
|
||||
snippets.add(new ResponseFieldSnippet(field));
|
||||
}
|
||||
actions.andDo(document(label, preprocessResponse(prettyPrint()), snippets.toArray(new Snippet[0])));
|
||||
actions.andDo(document(label, preprocessResponse(prettyPrint()),
|
||||
snippets.toArray(new Snippet[0])));
|
||||
this.fields = new ArrayList<>();
|
||||
return actions;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ public final class MockMvcClientHttpRequestFactoryTestExecutionListener
|
||||
this.factory);
|
||||
}
|
||||
else {
|
||||
factory = beanFactory.getBean("mockMvcClientHttpRequestFactory", MockMvcClientHttpRequestFactory.class);
|
||||
factory = beanFactory.getBean("mockMvcClientHttpRequestFactory",
|
||||
MockMvcClientHttpRequestFactory.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ 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).
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -55,4 +55,5 @@ public class UiControllerIntegrationTests
|
||||
"metadata/ui/test-dependencies-" + version + ".json");
|
||||
JSONAssert.assertEquals(expected, new JSONObject(actual), JSONCompareMode.STRICT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user