mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-02 11:24:04 +08:00
Reformat code
Format code using a pre-release version of the spring-javaformat plugin.
This commit is contained in:
@@ -58,12 +58,11 @@ import org.springframework.web.servlet.resource.ResourceUrlProvider;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
* Auto-configuration} to configure Spring initializr. In a web environment,
|
||||
* configures the necessary controller to serve the applications from the
|
||||
* root context.
|
||||
* Auto-configuration} to configure Spring initializr. In a web environment, configures
|
||||
* the necessary controller to serve the applications from the root context.
|
||||
*
|
||||
* <p>Project generation can be customized by defining a custom
|
||||
* {@link ProjectGenerator}.
|
||||
* <p>
|
||||
* Project generation can be customized by defining a custom {@link ProjectGenerator}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@@ -111,13 +110,12 @@ public class InitializrAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(InitializrMetadataProvider.class)
|
||||
public InitializrMetadataProvider initializrMetadataProvider(
|
||||
InitializrProperties properties,
|
||||
ObjectMapper objectMapper,
|
||||
InitializrProperties properties, ObjectMapper objectMapper,
|
||||
RestTemplateBuilder restTemplateBuilder) {
|
||||
InitializrMetadata metadata = InitializrMetadataBuilder
|
||||
.fromInitializrProperties(properties).build();
|
||||
return new DefaultInitializrMetadataProvider(metadata,
|
||||
objectMapper, restTemplateBuilder.build());
|
||||
return new DefaultInitializrMetadataProvider(metadata, objectMapper,
|
||||
restTemplateBuilder.build());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -130,7 +128,6 @@ public class InitializrAutoConfiguration {
|
||||
@ConditionalOnWebApplication
|
||||
static class InitializrWebConfiguration {
|
||||
|
||||
|
||||
@Bean
|
||||
public InitializrWebConfig initializrWebConfig() {
|
||||
return new InitializrWebConfig();
|
||||
@@ -144,8 +141,8 @@ public class InitializrAutoConfiguration {
|
||||
ResourceUrlProvider resourceUrlProvider,
|
||||
ProjectGenerator projectGenerator,
|
||||
DependencyMetadataProvider dependencyMetadataProvider) {
|
||||
return new MainController(metadataProvider, templateRenderer, resourceUrlProvider
|
||||
, projectGenerator, dependencyMetadataProvider);
|
||||
return new MainController(metadataProvider, templateRenderer,
|
||||
resourceUrlProvider, projectGenerator, dependencyMetadataProvider);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -172,8 +169,7 @@ public class InitializrAutoConfiguration {
|
||||
}
|
||||
|
||||
private MutableConfiguration<Object, Object> config() {
|
||||
return new MutableConfiguration<>()
|
||||
.setStoreByValue(false)
|
||||
return new MutableConfiguration<>().setStoreByValue(false)
|
||||
.setManagementEnabled(true).setStatisticsEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ public class InitializrWebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
||||
configurer.defaultContentTypeStrategy(new CommandLineContentNegotiationStrategy());
|
||||
configurer
|
||||
.defaultContentTypeStrategy(new CommandLineContentNegotiationStrategy());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +67,7 @@ public class InitializrWebConfig implements WebMvcConfigurer {
|
||||
throws HttpMediaTypeNotAcceptableException {
|
||||
String path = urlPathHelper.getPathWithinApplication(
|
||||
request.getNativeRequest(HttpServletRequest.class));
|
||||
if (!StringUtils.hasText(path) || !path.equals("/")) { // Only care about "/"
|
||||
if (!StringUtils.hasText(path) || !path.equals("/")) { // Only care about "/"
|
||||
return MEDIA_TYPE_ALL_LIST;
|
||||
}
|
||||
String userAgent = request.getHeader(HttpHeaders.USER_AGENT);
|
||||
@@ -81,7 +82,7 @@ public class InitializrWebConfig implements WebMvcConfigurer {
|
||||
}
|
||||
return Collections.singletonList(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,8 @@ public class DependencyMetadataV21JsonMapper implements DependencyMetadataJsonMa
|
||||
mapNode(metadata.getRepositories().entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey,
|
||||
entry -> mapRepository(entry.getValue())))));
|
||||
json.set("boms",
|
||||
mapNode(metadata.getBoms().entrySet().stream().collect(Collectors
|
||||
.toMap(Map.Entry::getKey, entry -> mapBom(entry.getValue())))));
|
||||
json.set("boms", mapNode(metadata.getBoms().entrySet().stream().collect(
|
||||
Collectors.toMap(Map.Entry::getKey, entry -> mapBom(entry.getValue())))));
|
||||
return json.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@ import org.springframework.hateoas.UriTemplate;
|
||||
/**
|
||||
* A {@link InitializrMetadataJsonMapper} handling the metadata format for v2.1
|
||||
* <p>
|
||||
* Version 2.1 brings the "versionRange" attribute for a dependency to restrict
|
||||
* the Spring Boot versions that can be used against it. That version also adds
|
||||
* an additional `dependencies` endpoint.
|
||||
* Version 2.1 brings the "versionRange" attribute for a dependency to restrict the Spring
|
||||
* Boot versions that can be used against it. That version also adds an additional
|
||||
* `dependencies` endpoint.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@@ -40,10 +40,8 @@ public class InitializrMetadataV21JsonMapper extends InitializrMetadataV2JsonMap
|
||||
private final TemplateVariables dependenciesVariables;
|
||||
|
||||
public InitializrMetadataV21JsonMapper() {
|
||||
this.dependenciesVariables = new TemplateVariables(
|
||||
new TemplateVariable("bootVersion",
|
||||
TemplateVariable.VariableType.REQUEST_PARAM)
|
||||
);
|
||||
this.dependenciesVariables = new TemplateVariables(new TemplateVariable(
|
||||
"bootVersion", TemplateVariable.VariableType.REQUEST_PARAM));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,9 +31,9 @@ public enum InitializrMetadataVersion {
|
||||
V2("application/vnd.initializr.v2+json"),
|
||||
|
||||
/**
|
||||
* Add "versionRange" attribute to any dependency to specify which
|
||||
* Spring Boot versions are compatible with it. Also provide a
|
||||
* separate "dependencies" endpoint to query dependencies metadata.
|
||||
* Add "versionRange" attribute to any dependency to specify which Spring Boot
|
||||
* versions are compatible with it. Also provide a separate "dependencies" endpoint to
|
||||
* query dependencies metadata.
|
||||
*/
|
||||
V2_1("application/vnd.initializr.v2.1+json");
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ public class LinkMapper {
|
||||
public static ObjectNode mapLinks(List<Link> links) {
|
||||
ObjectNode result = nodeFactory.objectNode();
|
||||
Map<String, List<Link>> byRel = new LinkedHashMap<>();
|
||||
links.forEach(it -> byRel.computeIfAbsent(it.getRel(),
|
||||
k -> new ArrayList<>()).add(it));
|
||||
links.forEach(
|
||||
it -> byRel.computeIfAbsent(it.getRel(), k -> new ArrayList<>()).add(it));
|
||||
byRel.forEach((rel, l) -> {
|
||||
if (l.size() == 1) {
|
||||
ObjectNode root = JsonNodeFactory.instance.objectNode();
|
||||
|
||||
@@ -42,7 +42,9 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
public abstract class AbstractInitializrController {
|
||||
|
||||
protected final InitializrMetadataProvider metadataProvider;
|
||||
|
||||
private final Function<String, String> linkTo;
|
||||
|
||||
private Boolean forceSsl;
|
||||
|
||||
protected AbstractInitializrController(InitializrMetadataProvider metadataProvider,
|
||||
|
||||
@@ -44,4 +44,3 @@ public class LegacyStsController extends AbstractInitializrController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,9 @@ public class MainController extends AbstractInitializrController {
|
||||
.parseMediaType("application/hal+json");
|
||||
|
||||
private final ProjectGenerator projectGenerator;
|
||||
|
||||
private final DependencyMetadataProvider dependencyMetadataProvider;
|
||||
|
||||
private final CommandLineHelpGenerator commandLineHelpGenerator;
|
||||
|
||||
public MainController(InitializrMetadataProvider metadataProvider,
|
||||
@@ -183,10 +185,10 @@ public class MainController extends AbstractInitializrController {
|
||||
private static InitializrMetadataJsonMapper getJsonMapper(
|
||||
InitializrMetadataVersion version) {
|
||||
switch (version) {
|
||||
case V2:
|
||||
return new InitializrMetadataV2JsonMapper();
|
||||
default:
|
||||
return new InitializrMetadataV21JsonMapper();
|
||||
case V2:
|
||||
return new InitializrMetadataV2JsonMapper();
|
||||
default:
|
||||
return new InitializrMetadataV21JsonMapper();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,7 +311,7 @@ public class MainController extends AbstractInitializrController {
|
||||
zip.setDestFile(download.getCanonicalFile());
|
||||
Tar.TarCompressionMethod method = new Tar.TarCompressionMethod();
|
||||
method.setValue("gzip");
|
||||
zip.setCompression(method );
|
||||
zip.setCompression(method);
|
||||
zip.execute();
|
||||
return upload(download, dir, generateFileName(request, "tar.gz"),
|
||||
"application/x-compress");
|
||||
@@ -327,8 +329,8 @@ public class MainController extends AbstractInitializrController {
|
||||
|
||||
private static String getWrapperScript(ProjectRequest request) {
|
||||
String script = "gradle".equals(request.getBuild()) ? "gradlew" : "mvnw";
|
||||
return request.getBaseDir() != null
|
||||
? request.getBaseDir() + "/" + script : script;
|
||||
return request.getBaseDir() != null ? request.getBaseDir() + "/" + script
|
||||
: script;
|
||||
}
|
||||
|
||||
private ResponseEntity<byte[]> upload(File download, File dir, String fileName,
|
||||
@@ -356,5 +358,3 @@ public class MainController extends AbstractInitializrController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,23 +49,23 @@ public class DefaultDependencyMetadataProvider implements DependencyMetadataProv
|
||||
Map<String, Repository> repositories = new LinkedHashMap<>();
|
||||
for (Dependency d : dependencies.values()) {
|
||||
if (d.getRepository() != null) {
|
||||
repositories.put(d.getRepository(), metadata.getConfiguration()
|
||||
.getEnv().getRepositories().get(d.getRepository()));
|
||||
repositories.put(d.getRepository(), metadata.getConfiguration().getEnv()
|
||||
.getRepositories().get(d.getRepository()));
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, BillOfMaterials> boms = new LinkedHashMap<>();
|
||||
for (Dependency d : dependencies.values()) {
|
||||
if (d.getBom() != null) {
|
||||
boms.put(d.getBom(), metadata.getConfiguration().getEnv()
|
||||
.getBoms().get(d.getBom()).resolve(bootVersion));
|
||||
boms.put(d.getBom(), metadata.getConfiguration().getEnv().getBoms()
|
||||
.get(d.getBom()).resolve(bootVersion));
|
||||
}
|
||||
}
|
||||
// Each resolved bom may require additional repositories
|
||||
for (BillOfMaterials b : boms.values()) {
|
||||
for (String id : b.getRepositories()) {
|
||||
repositories.put(id, metadata.getConfiguration().getEnv()
|
||||
.getRepositories().get(id));
|
||||
repositories.put(id,
|
||||
metadata.getConfiguration().getEnv().getRepositories().get(id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* A default {@link InitializrMetadataProvider} that is able to refresh
|
||||
* the metadata with the status of the main spring.io site.
|
||||
* A default {@link InitializrMetadataProvider} that is able to refresh the metadata with
|
||||
* the status of the main spring.io site.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@@ -41,7 +41,9 @@ public class DefaultInitializrMetadataProvider implements InitializrMetadataProv
|
||||
.getLogger(DefaultInitializrMetadataProvider.class);
|
||||
|
||||
private final InitializrMetadata metadata;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public DefaultInitializrMetadataProvider(InitializrMetadata metadata,
|
||||
|
||||
@@ -40,10 +40,10 @@ public class SpringBootMetadataReader {
|
||||
/**
|
||||
* Parse the content of the metadata at the specified url
|
||||
*/
|
||||
public SpringBootMetadataReader(ObjectMapper objectMapper,
|
||||
RestTemplate restTemplate, String url) throws IOException {
|
||||
this.content = objectMapper.readTree(
|
||||
restTemplate.getForObject(url, String.class));
|
||||
public SpringBootMetadataReader(ObjectMapper objectMapper, RestTemplate restTemplate,
|
||||
String url) throws IOException {
|
||||
this.content = objectMapper
|
||||
.readTree(restTemplate.getForObject(url, String.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,8 @@ public class SpringBootMetadataReader {
|
||||
DefaultMetadataElement version = new DefaultMetadataElement();
|
||||
version.setId(it.get("version").textValue());
|
||||
String name = it.get("versionDisplayName").textValue();
|
||||
version.setName(it.get("snapshot").booleanValue() ? name + " (SNAPSHOT)" : name);
|
||||
version.setName(
|
||||
it.get("snapshot").booleanValue() ? name + " (SNAPSHOT)" : name);
|
||||
version.setDefault(it.get("current").booleanValue());
|
||||
list.add(version);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ public class UiController {
|
||||
@GetMapping(path = "/ui/dependencies", produces = "application/json")
|
||||
public ResponseEntity<String> dependencies(
|
||||
@RequestParam(required = false) String version) {
|
||||
List<DependencyGroup> dependencyGroups = metadataProvider.get()
|
||||
.getDependencies().getContent();
|
||||
List<DependencyGroup> dependencyGroups = metadataProvider.get().getDependencies()
|
||||
.getContent();
|
||||
List<DependencyItem> content = new ArrayList<>();
|
||||
Version v = StringUtils.isEmpty(version) ? null : Version.parse(version);
|
||||
dependencyGroups.forEach(g -> g.getContent().forEach(d -> {
|
||||
@@ -69,8 +69,8 @@ public class UiController {
|
||||
}
|
||||
}));
|
||||
String json = writeDependencies(content);
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).
|
||||
eTag(createUniqueId(json)).body(json);
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON)
|
||||
.eTag(createUniqueId(json)).body(json);
|
||||
}
|
||||
|
||||
private static String writeDependencies(List<DependencyItem> items) {
|
||||
@@ -93,7 +93,8 @@ public class UiController {
|
||||
if (d.getWeight() > 0) {
|
||||
node.put("weight", d.getWeight());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(d.getKeywords()) || !CollectionUtils.isEmpty(d.getAliases())) {
|
||||
if (!CollectionUtils.isEmpty(d.getKeywords())
|
||||
|| !CollectionUtils.isEmpty(d.getAliases())) {
|
||||
List<String> all = new ArrayList<>(d.getKeywords());
|
||||
all.addAll(d.getAliases());
|
||||
node.put("keywords", StringUtils.collectionToCommaDelimitedString(all));
|
||||
@@ -102,18 +103,22 @@ public class UiController {
|
||||
}
|
||||
|
||||
private static class DependencyItem {
|
||||
|
||||
private final String group;
|
||||
|
||||
private final Dependency dependency;
|
||||
|
||||
DependencyItem(String group, Dependency dependency) {
|
||||
this.group = group;
|
||||
this.dependency = dependency;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String createUniqueId(String content) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
DigestUtils.appendMd5DigestAsHex(content.getBytes(StandardCharsets.UTF_8), builder);
|
||||
DigestUtils.appendMd5DigestAsHex(content.getBytes(StandardCharsets.UTF_8),
|
||||
builder);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -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