mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-21 02:58:08 +08:00
Polish contribution
Closes gh-349
This commit is contained in:
@@ -42,7 +42,7 @@ public class CloudfoundryEnvironmentPostProcessor
|
||||
|
||||
private static final String PROPERTY_SOURCE_NAME = "defaultProperties";
|
||||
|
||||
private final int order = ConfigFileApplicationListener.DEFAULT_ORDER + 1;
|
||||
private static final int ORDER = ConfigFileApplicationListener.DEFAULT_ORDER + 1;
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
@@ -58,8 +58,8 @@ public class CloudfoundryEnvironmentPostProcessor
|
||||
map.put("initializr.stats.elastic.username", credentials[0]);
|
||||
map.put("initializr.stats.elastic.password", credentials[1]);
|
||||
}
|
||||
map.put("initializr.stats.elastic.uri", UriComponentsBuilder.fromUriString(uri)
|
||||
.userInfo(null).build().toString());
|
||||
map.put("initializr.stats.elastic.uri", UriComponentsBuilder
|
||||
.fromUriString(uri).userInfo(null).build().toString());
|
||||
|
||||
addOrReplace(environment.getPropertySources(), map);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class CloudfoundryEnvironmentPostProcessor
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
return ORDER;
|
||||
}
|
||||
|
||||
private static void addOrReplace(MutablePropertySources propertySources,
|
||||
|
@@ -37,7 +37,7 @@ import io.spring.initializr.web.support.DefaultDependencyMetadataProvider;
|
||||
import io.spring.initializr.web.support.DefaultInitializrMetadataProvider;
|
||||
import io.spring.initializr.web.ui.UiController;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -69,8 +69,13 @@ import org.springframework.web.servlet.resource.ResourceUrlProvider;
|
||||
@EnableConfigurationProperties(InitializrProperties.class)
|
||||
public class InitializrAutoConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
private List<ProjectRequestPostProcessor> postProcessors = new ArrayList<>();
|
||||
private final List<ProjectRequestPostProcessor> postProcessors;
|
||||
|
||||
public InitializrAutoConfiguration(
|
||||
ObjectProvider<List<ProjectRequestPostProcessor>> postProcessors) {
|
||||
List<ProjectRequestPostProcessor> list = postProcessors.getIfAvailable();
|
||||
this.postProcessors = list != null ? list : new ArrayList<>();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebConfig webConfig() {
|
||||
@@ -79,7 +84,8 @@ public class InitializrAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MainController initializrMainController(InitializrMetadataProvider metadataProvider,
|
||||
public MainController initializrMainController(
|
||||
InitializrMetadataProvider metadataProvider,
|
||||
TemplateRenderer templateRenderer,
|
||||
ResourceUrlProvider resourceUrlProvider,
|
||||
ProjectGenerator projectGenerator,
|
||||
@@ -90,8 +96,9 @@ public class InitializrAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public UiController initializrUiController() {
|
||||
return new UiController();
|
||||
public UiController initializrUiController(
|
||||
InitializrMetadataProvider metadataProvider) {
|
||||
return new UiController(metadataProvider);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -103,7 +110,8 @@ public class InitializrAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public TemplateRenderer templateRenderer(Environment environment) {
|
||||
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.mustache.");
|
||||
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
|
||||
"spring.mustache.");
|
||||
boolean cache = resolver.getProperty("cache", Boolean.class, true);
|
||||
TemplateRenderer templateRenderer = new TemplateRenderer();
|
||||
templateRenderer.setCache(cache);
|
||||
@@ -123,8 +131,10 @@ public class InitializrAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(InitializrMetadataProvider.class)
|
||||
public InitializrMetadataProvider initializrMetadataProvider(InitializrProperties properties) {
|
||||
InitializrMetadata metadata = InitializrMetadataBuilder.fromInitializrProperties(properties).build();
|
||||
public InitializrMetadataProvider initializrMetadataProvider(
|
||||
InitializrProperties properties) {
|
||||
InitializrMetadata metadata = InitializrMetadataBuilder
|
||||
.fromInitializrProperties(properties).build();
|
||||
return new DefaultInitializrMetadataProvider(metadata, new RestTemplate());
|
||||
}
|
||||
|
||||
|
@@ -50,12 +50,14 @@ public class WebConfig extends WebMvcConfigurerAdapter {
|
||||
* A command-line aware {@link ContentNegotiationStrategy} that forces the media type
|
||||
* to "text/plain" for compatible agents.
|
||||
*/
|
||||
private static class CommandLineContentNegotiationStrategy implements ContentNegotiationStrategy {
|
||||
private static class CommandLineContentNegotiationStrategy
|
||||
implements ContentNegotiationStrategy {
|
||||
|
||||
private final UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||
|
||||
@Override
|
||||
public List<MediaType> resolveMediaTypes(NativeWebRequest request) throws HttpMediaTypeNotAcceptableException {
|
||||
public List<MediaType> resolveMediaTypes(NativeWebRequest request)
|
||||
throws HttpMediaTypeNotAcceptableException {
|
||||
String path = urlPathHelper.getPathWithinApplication(
|
||||
request.getNativeRequest(HttpServletRequest.class));
|
||||
if (!StringUtils.hasText(path) || !path.equals("/")) { // Only care about "/"
|
||||
@@ -65,7 +67,8 @@ public class WebConfig extends WebMvcConfigurerAdapter {
|
||||
if (userAgent != null) {
|
||||
Agent agent = Agent.fromUserAgent(userAgent);
|
||||
if (agent != null) {
|
||||
if (AgentId.CURL.equals(agent.getId()) || AgentId.HTTPIE.equals(agent.getId())) {
|
||||
if (AgentId.CURL.equals(agent.getId())
|
||||
|| AgentId.HTTPIE.equals(agent.getId())) {
|
||||
return Collections.singletonList(MediaType.TEXT_PLAIN);
|
||||
}
|
||||
}
|
||||
|
@@ -39,14 +39,14 @@ public class DependencyMetadataV21JsonMapper implements DependencyMetadataJsonMa
|
||||
json.put("bootVersion", metadata.getBootVersion().toString());
|
||||
json.put("dependencies",
|
||||
metadata.getDependencies().entrySet().stream()
|
||||
.collect(Collectors.toMap(entry -> entry.getKey(),
|
||||
.collect(Collectors.toMap(Map.Entry::getKey,
|
||||
entry -> mapDependency(entry.getValue()))));
|
||||
json.put("repositories",
|
||||
metadata.getRepositories().entrySet().stream()
|
||||
.collect(Collectors.toMap(entry -> entry.getKey(),
|
||||
.collect(Collectors.toMap(Map.Entry::getKey,
|
||||
entry -> mapRepository(entry.getValue()))));
|
||||
json.put("boms", metadata.getBoms().entrySet().stream().collect(Collectors
|
||||
.toMap(entry -> entry.getKey(), entry -> mapBom(entry.getValue()))));
|
||||
.toMap(Map.Entry::getKey, entry -> mapBom(entry.getValue()))));
|
||||
return json.toString();
|
||||
}
|
||||
|
||||
|
@@ -43,12 +43,14 @@ public class InitializrMetadataV21JsonMapper extends InitializrMetadataV2JsonMap
|
||||
|
||||
public InitializrMetadataV21JsonMapper() {
|
||||
this.dependenciesVariables = new TemplateVariables(
|
||||
new TemplateVariable("bootVersion", TemplateVariable.VariableType.REQUEST_PARAM)
|
||||
new TemplateVariable("bootVersion",
|
||||
TemplateVariable.VariableType.REQUEST_PARAM)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> links(JSONObject parent, List<Type> types, String appUrl) {
|
||||
protected Map<String, Object> links(JSONObject parent, List<Type> types,
|
||||
String appUrl) {
|
||||
Map<String, Object> links = super.links(parent, types, appUrl);
|
||||
links.put("dependencies", dependenciesLink(appUrl));
|
||||
parent.put("_links", links);
|
||||
@@ -75,4 +77,5 @@ public class InitializrMetadataV21JsonMapper extends InitializrMetadataV2JsonMap
|
||||
result.put("templated", true);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -95,9 +95,7 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
|
||||
|
||||
protected Map<String, Object> links(JSONObject parent, List<Type> types, String appUrl) {
|
||||
Map<String, Object> content = new LinkedHashMap<>();
|
||||
types.forEach(it -> {
|
||||
content.put(it.getId(), link(appUrl, it));
|
||||
});
|
||||
types.forEach(it -> content.put(it.getId(), link(appUrl, it)));
|
||||
parent.put("_links", content);
|
||||
return content;
|
||||
}
|
||||
@@ -120,7 +118,8 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("type", capability.getType().getName());
|
||||
map.put("values",
|
||||
capability.getContent().stream().map(it -> mapDependencyGroup(it)).collect(Collectors.toList()));
|
||||
capability.getContent().stream().map(this::mapDependencyGroup)
|
||||
.collect(Collectors.toList()));
|
||||
parent.put(capability.getId(), map);
|
||||
}
|
||||
|
||||
@@ -131,7 +130,7 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
|
||||
if (defaultType != null) {
|
||||
map.put("default", defaultType.getId());
|
||||
}
|
||||
map.put("values", capability.getContent().stream().map(it -> mapType(it))
|
||||
map.put("values", capability.getContent().stream().map(this::mapType)
|
||||
.collect(Collectors.toList()));
|
||||
parent.put("type", map);
|
||||
}
|
||||
@@ -143,7 +142,7 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
|
||||
if (defaultType != null) {
|
||||
map.put("default", defaultType.getId());
|
||||
}
|
||||
map.put("values", capability.getContent().stream().map(it -> mapValue(it))
|
||||
map.put("values", capability.getContent().stream().map(this::mapValue)
|
||||
.collect(Collectors.toList()));
|
||||
parent.put(capability.getId(), map);
|
||||
}
|
||||
@@ -161,7 +160,8 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
|
||||
protected Map<String, Object> mapDependencyGroup(DependencyGroup group) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("name", group.getName());
|
||||
if ((group instanceof Describable) && ((Describable) group).getDescription() != null) {
|
||||
if ((group instanceof Describable)
|
||||
&& ((Describable) group).getDescription() != null) {
|
||||
result.put("description", ((Describable) group).getDescription());
|
||||
}
|
||||
List<Object> items = new ArrayList<>();
|
||||
@@ -194,7 +194,8 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("id", value.getId());
|
||||
result.put("name", value.getName());
|
||||
if ((value instanceof Describable) && ((Describable) value).getDescription() != null) {
|
||||
if ((value instanceof Describable)
|
||||
&& ((Describable) value).getDescription() != null) {
|
||||
result.put("description", ((Describable) value).getDescription());
|
||||
}
|
||||
return result;
|
||||
|
@@ -39,7 +39,7 @@ public enum InitializrMetadataVersion {
|
||||
|
||||
private final MediaType mediaType;
|
||||
|
||||
private InitializrMetadataVersion(String mediaType) {
|
||||
InitializrMetadataVersion(String mediaType) {
|
||||
this.mediaType = MediaType.parseMediaType(mediaType);
|
||||
}
|
||||
|
||||
|
@@ -39,9 +39,8 @@ public class LinkMapper {
|
||||
public static Map<String, Object> mapLinks(List<Link> links) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
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) {
|
||||
Map<String, Object> root = new LinkedHashMap<>();
|
||||
|
@@ -72,7 +72,7 @@ public abstract class AbstractInitializrController {
|
||||
/**
|
||||
* Render the home page with the specified template.
|
||||
*/
|
||||
protected void renderHome(Map<String, Object> model) throws Exception {
|
||||
protected void renderHome(Map<String, Object> model) {
|
||||
InitializrMetadata metadata = metadataProvider.get();
|
||||
|
||||
model.put("serviceUrl", generateAppUrl());
|
||||
@@ -82,7 +82,8 @@ public abstract class AbstractInitializrController {
|
||||
model.put("types", removeTypes(metadata.getTypes()));
|
||||
}
|
||||
else {
|
||||
model.put(descriptor.getName(), wrapper.getPropertyValue(descriptor.getName()));
|
||||
model.put(descriptor.getName(),
|
||||
wrapper.getPropertyValue(descriptor.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +112,8 @@ public abstract class AbstractInitializrController {
|
||||
* @see io.spring.initializr.metadata.InitializrConfiguration.Env#forceSsl
|
||||
*/
|
||||
protected String generateAppUrl() {
|
||||
ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentServletMapping();
|
||||
ServletUriComponentsBuilder builder = ServletUriComponentsBuilder
|
||||
.fromCurrentServletMapping();
|
||||
if (isForceSsl()) {
|
||||
builder.scheme("https");
|
||||
}
|
||||
|
@@ -32,12 +32,13 @@ import org.springframework.web.servlet.resource.ResourceUrlProvider;
|
||||
@Controller
|
||||
public class LegacyStsController extends AbstractInitializrController {
|
||||
|
||||
public LegacyStsController(InitializrMetadataProvider metadataProvider, ResourceUrlProvider resourceUrlProvider) {
|
||||
public LegacyStsController(InitializrMetadataProvider metadataProvider,
|
||||
ResourceUrlProvider resourceUrlProvider) {
|
||||
super(metadataProvider, resourceUrlProvider);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sts", produces = "text/html")
|
||||
public String stsHome(Map<String, Object> model) throws Exception {
|
||||
public String stsHome(Map<String, Object> model) {
|
||||
renderHome(model);
|
||||
return "sts-home";
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package io.spring.initializr.web.project;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -207,13 +208,11 @@ public class MainController extends AbstractInitializrController {
|
||||
|
||||
@ModelAttribute("linkTo")
|
||||
public Mustache.Lambda linkTo() {
|
||||
return (frag, out) -> {
|
||||
out.write(this.getLinkTo().apply(frag.execute()));
|
||||
};
|
||||
return (frag, out) -> out.write(this.getLinkTo().apply(frag.execute()));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/", produces = "text/html")
|
||||
public String home(Map<String, Object> model) throws Exception {
|
||||
public String home(Map<String, Object> model) {
|
||||
renderHome(model);
|
||||
return "home";
|
||||
}
|
||||
@@ -251,7 +250,7 @@ public class MainController extends AbstractInitializrController {
|
||||
@RequestMapping("/starter.zip")
|
||||
@ResponseBody
|
||||
public ResponseEntity<byte[]> springZip(BasicProjectRequest basicRequest)
|
||||
throws Exception {
|
||||
throws IOException {
|
||||
ProjectRequest request = (ProjectRequest) basicRequest;
|
||||
File dir = projectGenerator.generateProjectStructure(request);
|
||||
|
||||
@@ -268,7 +267,7 @@ public class MainController extends AbstractInitializrController {
|
||||
@RequestMapping(value = "/starter.tgz", produces = "application/x-compress")
|
||||
@ResponseBody
|
||||
public ResponseEntity<byte[]> springTgz(BasicProjectRequest basicRequest)
|
||||
throws Exception {
|
||||
throws IOException {
|
||||
ProjectRequest request = (ProjectRequest) basicRequest;
|
||||
File dir = projectGenerator.generateProjectStructure(request);
|
||||
|
||||
@@ -295,13 +294,12 @@ public class MainController extends AbstractInitializrController {
|
||||
|
||||
private static String getWrapperScript(ProjectRequest request) {
|
||||
String script = "gradle".equals(request.getBuild()) ? "gradlew" : "mvnw";
|
||||
String wrapperScript = request.getBaseDir() != null
|
||||
return request.getBaseDir() != null
|
||||
? request.getBaseDir() + "/" + script : script;
|
||||
return wrapperScript;
|
||||
}
|
||||
|
||||
private ResponseEntity<byte[]> upload(File download, File dir, String fileName,
|
||||
String contentType) throws Exception {
|
||||
String contentType) throws IOException {
|
||||
byte[] bytes = StreamUtils.copyToByteArray(new FileInputStream(download));
|
||||
log.info("Uploading: {} ({} bytes)", download, bytes.length);
|
||||
ResponseEntity<byte[]> result = createResponseEntity(bytes, contentType,
|
||||
|
@@ -49,20 +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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,8 @@ public class DefaultInitializrMetadataProvider implements InitializrMetadataProv
|
||||
private final InitializrMetadata metadata;
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public DefaultInitializrMetadataProvider(InitializrMetadata metadata, RestTemplate restTemplate) {
|
||||
public DefaultInitializrMetadataProvider(InitializrMetadata metadata,
|
||||
RestTemplate restTemplate) {
|
||||
this.metadata = metadata;
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
@@ -57,7 +58,8 @@ public class DefaultInitializrMetadataProvider implements InitializrMetadataProv
|
||||
protected void updateInitializrMetadata(InitializrMetadata metadata) {
|
||||
List<DefaultMetadataElement> bootVersions = fetchBootVersions();
|
||||
if (bootVersions != null && !bootVersions.isEmpty()) {
|
||||
if (bootVersions.stream().noneMatch(it -> it.isDefault())) { // No default specified
|
||||
if (bootVersions.stream().noneMatch(DefaultMetadataElement::isDefault)) {
|
||||
// No default specified
|
||||
bootVersions.get(0).setDefault(true);
|
||||
}
|
||||
metadata.updateSpringBootVersions(bootVersions);
|
||||
|
@@ -26,9 +26,8 @@ import org.json.JSONObject;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* Reads metadata from the main spring.io website. This is a stateful
|
||||
* service: creates a new instance whenever you need to refresh the
|
||||
* content.
|
||||
* Reads metadata from the main spring.io website. This is a stateful service: create a
|
||||
* new instance whenever you need to refresh the content.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
|
@@ -28,7 +28,6 @@ import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
import io.spring.initializr.util.Version;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -46,26 +45,29 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class UiController {
|
||||
|
||||
@Autowired
|
||||
protected InitializrMetadataProvider metadataProvider;
|
||||
protected final InitializrMetadataProvider metadataProvider;
|
||||
|
||||
public UiController(InitializrMetadataProvider metadataProvider) {
|
||||
this.metadataProvider = metadataProvider;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/ui/dependencies", produces = "application/json")
|
||||
public ResponseEntity<String> dependencies(@RequestParam(required = false) String version) {
|
||||
List<DependencyGroup> dependencyGroups = metadataProvider.get().getDependencies().getContent();
|
||||
public ResponseEntity<String> dependencies(
|
||||
@RequestParam(required = false) String version) {
|
||||
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 -> {
|
||||
if (v != null && d.getVersionRange() != null) {
|
||||
if (d.match(v)) {
|
||||
content.add(new DependencyItem(g.getName(), d));
|
||||
}
|
||||
}
|
||||
else {
|
||||
dependencyGroups.forEach(g -> g.getContent().forEach(d -> {
|
||||
if (v != null && d.getVersionRange() != null) {
|
||||
if (d.match(v)) {
|
||||
content.add(new DependencyItem(g.getName(), d));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
content.add(new DependencyItem(g.getName(), d));
|
||||
}
|
||||
}));
|
||||
String json = writeDependencies(content);
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).
|
||||
eTag(createUniqueId(json)).body(json);
|
||||
|
@@ -39,6 +39,7 @@ public abstract class AbstractFullStackInitializrIntegrationTests
|
||||
|
||||
protected String host = "localhost";
|
||||
|
||||
@Override
|
||||
protected String createUrl(String context) {
|
||||
return "http://" + host + ":" + port
|
||||
+ (context.startsWith("/") ? context : "/" + context);
|
||||
|
@@ -35,7 +35,8 @@ 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
|
||||
@@ -47,6 +48,7 @@ public abstract class AbstractInitializrControllerIntegrationTests
|
||||
private
|
||||
MockMvcClientHttpRequestFactory requests;
|
||||
|
||||
@Override
|
||||
protected String createUrl(String context) {
|
||||
return context.startsWith("/") ? context : "/" + context;
|
||||
}
|
||||
@@ -60,10 +62,8 @@ public abstract class AbstractInitializrControllerIntegrationTests
|
||||
|
||||
@Bean
|
||||
RestTemplateCustomizer mockMvcCustomizer(BeanFactory beanFactory) {
|
||||
return template -> {
|
||||
template.setRequestFactory(
|
||||
beanFactory.getBean(MockMvcClientHttpRequestFactory.class));
|
||||
};
|
||||
return template -> template.setRequestFactory(
|
||||
beanFactory.getBean(MockMvcClientHttpRequestFactory.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -67,8 +66,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();
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder folder = new TemporaryFolder();
|
||||
@@ -87,7 +86,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
|
||||
protected String htmlHome() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
||||
headers.setAccept(Collections.singletonList(MediaType.TEXT_HTML));
|
||||
return restTemplate.exchange(createUrl("/"), HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class).getBody();
|
||||
}
|
||||
@@ -199,28 +198,24 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
|
||||
protected File writeArchive(byte[] body) throws IOException {
|
||||
File archiveFile = folder.newFile();
|
||||
FileOutputStream stream = new FileOutputStream(archiveFile);
|
||||
try {
|
||||
try (FileOutputStream stream = new FileOutputStream(archiveFile)) {
|
||||
stream.write(body);
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
return archiveFile;
|
||||
}
|
||||
|
||||
protected JSONObject readJsonFrom(String path) {
|
||||
try {
|
||||
ClassPathResource resource = new ClassPathResource(path);
|
||||
InputStream stream = resource.getInputStream();
|
||||
try {
|
||||
try (InputStream stream = resource.getInputStream()) {
|
||||
String json = StreamUtils.copyToString(stream, Charset.forName("UTF-8"));
|
||||
String placeholder = "";
|
||||
if (this instanceof AbstractInitializrControllerIntegrationTests) {
|
||||
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
|
||||
@@ -228,9 +223,6 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
String content = json.replaceAll("@host@", placeholder);
|
||||
return new JSONObject(content);
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Cannot read JSON from path=" + path);
|
||||
@@ -244,7 +236,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
private enum ArchiveType {
|
||||
ZIP,
|
||||
|
||||
TGZ;
|
||||
TGZ
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
@@ -21,16 +21,15 @@ import org.junit.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
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();
|
||||
|
||||
@@ -40,10 +39,12 @@ public class CloudfoundryEnvironmentPostProcessorTests {
|
||||
"http://user:pass@example.com/bar/biz?param=one");
|
||||
postProcessor.postProcessEnvironment(environment, application);
|
||||
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.uri"),
|
||||
is("http://example.com/bar/biz?param=one"));
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.username"), is("user"));
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.password"), is("pass"));
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.uri"))
|
||||
.isEqualTo("http://example.com/bar/biz?param=one");
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.username"))
|
||||
.isEqualTo("user");
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.password"))
|
||||
.isEqualTo("pass");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,19 +53,19 @@ public class CloudfoundryEnvironmentPostProcessorTests {
|
||||
"http://example.com/bar/biz?param=one");
|
||||
postProcessor.postProcessEnvironment(environment, application);
|
||||
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.uri"),
|
||||
is("http://example.com/bar/biz?param=one"));
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.username"), is(nullValue()));
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.password"), is(nullValue()));
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.uri"))
|
||||
.isEqualTo("http://example.com/bar/biz?param=one");
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.username")).isNull();
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.password")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseNoVcapUri() {
|
||||
postProcessor.postProcessEnvironment(environment, application);
|
||||
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.uri"), is(nullValue()));
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.username"), is(nullValue()));
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.password"), is(nullValue()));
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.uri")).isNull();
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.username")).isNull();
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.password")).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -34,7 +34,8 @@ 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 {
|
||||
|
@@ -31,11 +31,13 @@ import static org.junit.Assert.assertTrue;
|
||||
*/
|
||||
public class InitializrMetadataJsonMapperTests {
|
||||
|
||||
private final InitializrMetadataJsonMapper jsonMapper = new InitializrMetadataV21JsonMapper();
|
||||
private final InitializrMetadataJsonMapper jsonMapper =
|
||||
new InitializrMetadataV21JsonMapper();
|
||||
|
||||
@Test
|
||||
public void withNoAppUrl() {
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder().addType("foo", true, "/foo.zip", "none", "test")
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
|
||||
.addType("foo", true, "/foo.zip", "none", "test")
|
||||
.addDependencyGroup("foo", "one", "two").build();
|
||||
String json = jsonMapper.write(metadata, null);
|
||||
JSONObject result = new JSONObject(json);
|
||||
@@ -45,7 +47,8 @@ public class InitializrMetadataJsonMapperTests {
|
||||
|
||||
@Test
|
||||
public void withAppUrl() {
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder().addType("foo", true, "/foo.zip", "none", "test")
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
|
||||
.addType("foo", true, "/foo.zip", "none", "test")
|
||||
.addDependencyGroup("foo", "one", "two").build();
|
||||
String json = jsonMapper.write(metadata, "http://server:8080/my-app");
|
||||
JSONObject result = new JSONObject(json);
|
||||
|
@@ -35,9 +35,9 @@ public class LinkMapperTests {
|
||||
|
||||
@Test
|
||||
public void mapSimpleRel() {
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
List<Link> links = new ArrayList<>();
|
||||
links.add(Link.create("a", "https://example.com", "some description"));
|
||||
Map<String, Object> model = (Map<String, Object>) LinkMapper.mapLinks(links);
|
||||
Map<String, Object> model = LinkMapper.mapLinks(links);
|
||||
assertEquals(1, model.size());
|
||||
assertTrue(model.containsKey("a"));
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -49,9 +49,9 @@ public class LinkMapperTests {
|
||||
|
||||
@Test
|
||||
public void mapTemplatedRel() {
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
List<Link> links = new ArrayList<>();
|
||||
links.add(Link.create("a", "https://example.com/{bootVersion}/a", true));
|
||||
Map<String, Object> model = (Map<String, Object>) LinkMapper.mapLinks(links);
|
||||
Map<String, Object> model = LinkMapper.mapLinks(links);
|
||||
assertEquals(1, model.size());
|
||||
assertTrue(model.containsKey("a"));
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -63,10 +63,10 @@ public class LinkMapperTests {
|
||||
|
||||
@Test
|
||||
public void mergeSeveralLinksInArray() {
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
List<Link> links = new ArrayList<>();
|
||||
links.add(Link.create("a", "https://example.com", "some description"));
|
||||
links.add(Link.create("a", "https://example.com/2"));
|
||||
Map<String, Object> model = (Map<String, Object>) LinkMapper.mapLinks(links);
|
||||
Map<String, Object> model = LinkMapper.mapLinks(links);
|
||||
assertEquals(1, model.size());
|
||||
assertTrue(model.containsKey("a"));
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -78,20 +78,20 @@ public class LinkMapperTests {
|
||||
|
||||
@Test
|
||||
public void keepOrdering() {
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
List<Link> links = new ArrayList<>();
|
||||
links.add(Link.create("a", "https://example.com"));
|
||||
links.add(Link.create("b", "https://example.com"));
|
||||
Map<String, Object> model = (Map<String, Object>) LinkMapper.mapLinks(links);
|
||||
Map<String, Object> model = LinkMapper.mapLinks(links);
|
||||
assertEquals("[a, b]", model.keySet().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keepOrderingWithMultipleUrlForSameRel() {
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
List<Link> links = new ArrayList<>();
|
||||
links.add(Link.create("a", "https://example.com"));
|
||||
links.add(Link.create("b", "https://example.com"));
|
||||
links.add(Link.create("a", "https://example.com"));
|
||||
Map<String, Object> model = (Map<String, Object>) LinkMapper.mapLinks(links);
|
||||
Map<String, Object> model = LinkMapper.mapLinks(links);
|
||||
assertEquals("[a, b]", model.keySet().toString());
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,8 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ActiveProfiles("test-default")
|
||||
public class CommandLineExampleIntegrationTests extends AbstractInitializrControllerIntegrationTests {
|
||||
public class CommandLineExampleIntegrationTests
|
||||
extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void generateDefaultProject() {
|
||||
@@ -67,7 +68,8 @@ public class CommandLineExampleIntegrationTests extends AbstractInitializrContro
|
||||
|
||||
@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");
|
||||
}
|
||||
|
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.web.project;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
import org.openqa.selenium.support.PageFactory;
|
||||
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) {
|
||||
this.driver = driver;
|
||||
PageFactory.initElements(driver, this);
|
||||
}
|
||||
|
||||
public Object value(String id) {
|
||||
return getInputValue(form.findElement(By.id(id)));
|
||||
}
|
||||
|
||||
private Object getInputValue(WebElement input) {
|
||||
Object value = null;
|
||||
String type = input.getAttribute("type");
|
||||
if ("select".equals(input.getTagName())) {
|
||||
Select select = new Select(input);
|
||||
if (select.isMultiple()) {
|
||||
value = select.getAllSelectedOptions().stream().map(this::getValue)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
else {
|
||||
value = getValue(select.getFirstSelectedOption());
|
||||
}
|
||||
}
|
||||
else if (Arrays.asList("checkbox", "radio").contains(type)) {
|
||||
if (input.isSelected()) {
|
||||
value = getValue(input);
|
||||
}
|
||||
else {
|
||||
if (Objects.equals(type, "checkbox")) {
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
value = getValue(input);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private String getValue(WebElement input) {
|
||||
return input.getAttribute("value");
|
||||
}
|
||||
|
||||
public WebElement dependency(String value) {
|
||||
for (WebElement element : form.findElements(By.name("style"))) {
|
||||
if (value.equals(element.getAttribute("value"))) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("Dependency not found: " + value);
|
||||
}
|
||||
|
||||
public void advanced() {
|
||||
form.findElement(By.cssSelector(".tofullversion"))
|
||||
.findElement(By.tagName("a")).click();
|
||||
}
|
||||
|
||||
public void simple() {
|
||||
form.findElement(By.cssSelector(".tosimpleversion")).click();
|
||||
}
|
||||
|
||||
public void artifactId(String text) {
|
||||
form.findElement(By.id("artifactId")).clear();
|
||||
form.findElement(By.id("artifactId")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void autocomplete(String text) {
|
||||
form.findElement(By.id("autocomplete")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void bootVersion(String text) {
|
||||
form.findElement(By.id("bootVersion")).sendKeys(text);
|
||||
form.click();
|
||||
}
|
||||
|
||||
public void description(String text) {
|
||||
form.findElement(By.id("description")).clear();
|
||||
form.findElement(By.id("description")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void groupId(String text) {
|
||||
form.findElement(By.id("groupId")).clear();
|
||||
form.findElement(By.id("groupId")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void language(String text) {
|
||||
form.findElement(By.id("language")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void name(String text) {
|
||||
form.findElement(By.id("name")).clear();
|
||||
form.findElement(By.id("name")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void packaging(String text) {
|
||||
form.findElement(By.id("packaging")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void packageName(String text) {
|
||||
form.findElement(By.id("packageName")).clear();
|
||||
form.findElement(By.id("packageName")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void type(String text) {
|
||||
form.findElement(By.id("type")).sendKeys(text);
|
||||
}
|
||||
|
||||
public HomePage submit() {
|
||||
String url = driver.getCurrentUrl();
|
||||
form.findElement(By.name("generate-project")).click();
|
||||
assertThat(driver.getCurrentUrl()).isEqualTo(url);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package io.spring.initializr.web.project;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
|
||||
@@ -48,14 +48,18 @@ public class LegacyStsControllerIntegrationTests
|
||||
String body = htmlHome();
|
||||
assertTrue("groupId not found", body.contains("com.example"));
|
||||
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("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\"/>"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String htmlHome() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
||||
headers.setAccept(Collections.singletonList(MediaType.TEXT_HTML));
|
||||
return getRestTemplate().exchange(createUrl("/sts"), HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class).getBody();
|
||||
}
|
||||
|
@@ -28,15 +28,18 @@ import static org.junit.Assert.assertTrue;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ActiveProfiles({ "test-default", "test-custom-defaults" })
|
||||
public class MainControllerDefaultsIntegrationTests extends AbstractInitializrControllerIntegrationTests {
|
||||
public class MainControllerDefaultsIntegrationTests
|
||||
extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
// see defaults customization
|
||||
|
||||
@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")
|
||||
pomAssert.hasGroupId("org.foo").hasArtifactId("foo-bar")
|
||||
.hasVersion("1.2.4-SNAPSHOT").hasPackaging("jar")
|
||||
.hasName("FooBar").hasDescription("FooBar Project");
|
||||
}
|
||||
|
||||
|
@@ -34,13 +34,15 @@ import static org.junit.Assert.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ActiveProfiles("test-default")
|
||||
public class MainControllerDependenciesTests extends AbstractInitializrControllerIntegrationTests {
|
||||
public class MainControllerDependenciesTests
|
||||
extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void noBootVersion() {
|
||||
ResponseEntity<String> response = execute("/dependencies", String.class, null, "application/json");
|
||||
ResponseEntity<String> response = execute("/dependencies", String.class, null,
|
||||
"application/json");
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
validateContentType(response, AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateDependenciesOutput("1.1.4", new JSONObject(response.getBody()));
|
||||
}
|
||||
|
||||
@@ -49,12 +51,13 @@ public class MainControllerDependenciesTests extends AbstractInitializrControlle
|
||||
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, AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateDependenciesOutput("1.2.1", new JSONObject(response.getBody()));
|
||||
}
|
||||
|
||||
protected void validateDependenciesOutput(String version, JSONObject actual) {
|
||||
JSONObject expected = readJsonFrom("metadata/dependencies/test-dependencies-" + version + ".json");
|
||||
JSONObject expected = readJsonFrom(
|
||||
"metadata/dependencies/test-dependencies-" + version + ".json");
|
||||
JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT);
|
||||
}
|
||||
|
||||
|
@@ -34,11 +34,13 @@ import static org.junit.Assert.assertTrue;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ActiveProfiles({ "test-default", "test-custom-env" })
|
||||
public class MainControllerEnvIntegrationTests extends AbstractInitializrControllerIntegrationTests {
|
||||
public class MainControllerEnvIntegrationTests
|
||||
extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
@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());
|
||||
@@ -55,7 +57,7 @@ public class MainControllerEnvIntegrationTests extends AbstractInitializrControl
|
||||
@Test
|
||||
public void generateProjectWithInvalidName() {
|
||||
downloadZip("/starter.zip?style=data-jpa&name=Invalid")
|
||||
.isJavaProject((String) ProjectAssert.DEFAULT_PACKAGE_NAME, "FooBarApplication")
|
||||
.isJavaProject(ProjectAssert.DEFAULT_PACKAGE_NAME, "FooBarApplication")
|
||||
.isMavenProject()
|
||||
.hasStaticAndTemplatesResources(false).pomAssert()
|
||||
.hasDependenciesCount(2)
|
||||
@@ -66,7 +68,8 @@ public class MainControllerEnvIntegrationTests extends AbstractInitializrControl
|
||||
@Test
|
||||
public void googleAnalytics() {
|
||||
String body = htmlHome();
|
||||
assertTrue("google analytics should be enabled", body.contains("ga('create', 'UA-1234567-89', 'auto');"));
|
||||
assertTrue("google analytics should be enabled",
|
||||
body.contains("ga('create', 'UA-1234567-89', 'auto');"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -270,7 +270,6 @@ public class MainControllerIntegrationTests
|
||||
validateContentType(response,
|
||||
AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateCurrentMetadata(new JSONObject(response.getBody()));
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -379,33 +378,36 @@ public class MainControllerIntegrationTests
|
||||
assertFalse("Wrong body:\n" + body, body.contains("{{"));
|
||||
assertFalse("Wrong body:\n" + body, body.contains("}}"));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("<option value=\"groovy\">"));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("<option value=\"java\" selected>"));
|
||||
assertTrue("Wrong body:\n" + body,
|
||||
body.contains("<option value=\"java\" selected>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void homeIsJson() {
|
||||
String body = invokeHome(null, (String[]) null).getBody();
|
||||
assertTrue("Wrong body:\n$body", body.contains("\"dependencies\""));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("\"dependencies\""));
|
||||
}
|
||||
|
||||
@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);
|
||||
assertTrue("Wrong body:\n$body", body.contains("spring-boot-starter-web"));
|
||||
assertTrue("Wrong body:\n$body", body.contains("providedRuntime"));
|
||||
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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void homeHasWebStyle() {
|
||||
String body = htmlHome();
|
||||
assertTrue("Wrong body:\n$body", body.contains("name=\"style\" value=\"web\""));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("name=\"style\" value=\"web\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -419,12 +421,14 @@ public class MainControllerIntegrationTests
|
||||
public void homeHasOnlyProjectFormatTypes() {
|
||||
String body = htmlHome();
|
||||
assertTrue("maven project not found", body.contains("Maven Project"));
|
||||
assertFalse("maven pom type should have been filtered", body.contains("Maven POM"));
|
||||
assertFalse("maven pom type should have been filtered",
|
||||
body.contains("Maven POM"));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
@@ -54,7 +54,8 @@ public class MainControllerServiceMetadataIntegrationTests
|
||||
// Basic assertions
|
||||
assertEquals(localMetadata.getDependencies().getContent().size(),
|
||||
metadata.getDependencies().getContent().size());
|
||||
assertEquals(localMetadata.getTypes().getContent().size(), metadata.getTypes().getContent().size());
|
||||
assertEquals(localMetadata.getTypes().getContent().size(),
|
||||
metadata.getTypes().getContent().size());
|
||||
assertEquals(localMetadata.getBootVersions().getContent().size(),
|
||||
metadata.getBootVersions().getContent().size());
|
||||
assertEquals(localMetadata.getPackagings().getContent().size(),
|
||||
|
@@ -32,7 +32,8 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
@ActiveProfiles("test-default")
|
||||
@Import(ProjectRequestPostProcessorConfiguration.class)
|
||||
public class ProjectGenerationPostProcessorTests extends AbstractInitializrControllerIntegrationTests {
|
||||
public class ProjectGenerationPostProcessorTests
|
||||
extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
|
||||
@Test
|
||||
|
@@ -19,8 +19,6 @@ package io.spring.initializr.web.project;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.spring.initializr.test.generator.ProjectAssert;
|
||||
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
|
||||
@@ -28,17 +26,12 @@ import org.junit.After;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.Keys;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxProfile;
|
||||
import org.openqa.selenium.interactions.Action;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
import org.openqa.selenium.support.PageFactory;
|
||||
import org.openqa.selenium.support.ui.Select;
|
||||
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.util.StreamUtils;
|
||||
@@ -49,13 +42,14 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ActiveProfiles("test-default")
|
||||
public class NewGenerationSmokeTests extends AbstractFullStackInitializrIntegrationTests {
|
||||
public class ProjectGenerationSmokeTests
|
||||
extends AbstractFullStackInitializrIntegrationTests {
|
||||
|
||||
private File downloadDir;
|
||||
private WebDriver driver;
|
||||
private Actions actions;
|
||||
|
||||
private Action enterAction;
|
||||
|
||||
@@ -73,7 +67,7 @@ public class NewGenerationSmokeTests extends AbstractFullStackInitializrIntegrat
|
||||
"application/zip,application/x-compress,application/octet-stream");
|
||||
|
||||
driver = new FirefoxDriver(fxProfile);
|
||||
actions = new Actions(driver);
|
||||
Actions actions = new Actions(driver);
|
||||
|
||||
enterAction = actions.sendKeys(Keys.ENTER).build();
|
||||
}
|
||||
@@ -314,7 +308,7 @@ public class NewGenerationSmokeTests extends AbstractFullStackInitializrIntegrat
|
||||
ProjectAssert projectAssert = zipProjectAssert(from("demo.zip"));
|
||||
projectAssert.hasBaseDir("demo").isMavenProject()
|
||||
.isGroovyProject("com.example.acme",
|
||||
(String) ProjectAssert.DEFAULT_APPLICATION_NAME)
|
||||
ProjectAssert.DEFAULT_APPLICATION_NAME)
|
||||
.hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(3)
|
||||
.hasSpringBootStarterRootDependency().hasSpringBootStarterTest()
|
||||
.hasDependency("org.codehaus.groovy", "groovy");
|
||||
@@ -352,8 +346,7 @@ public class NewGenerationSmokeTests extends AbstractFullStackInitializrIntegrat
|
||||
|
||||
private HomePage toHome(String path) {
|
||||
driver.get("http://localhost:" + port + path);
|
||||
HomePage page = new HomePage(driver);
|
||||
return page;
|
||||
return new HomePage(driver);
|
||||
}
|
||||
|
||||
private ProjectAssert assertSimpleProject() throws Exception {
|
||||
@@ -378,123 +371,3 @@ public class NewGenerationSmokeTests extends AbstractFullStackInitializrIntegrat
|
||||
|
||||
}
|
||||
|
||||
class HomePage {
|
||||
|
||||
@FindBy(id = "form")
|
||||
private WebElement form;
|
||||
private WebDriver driver;
|
||||
|
||||
public HomePage(WebDriver driver) {
|
||||
this.driver = driver;
|
||||
PageFactory.initElements(driver, this);
|
||||
}
|
||||
|
||||
public Object value(String id) {
|
||||
return getInputValue(form.findElement(By.id(id)));
|
||||
}
|
||||
|
||||
private Object getInputValue(WebElement input) {
|
||||
Object value = null;
|
||||
String type = input.getAttribute("type");
|
||||
if ("select".equals(input.getTagName())) {
|
||||
Select select = new Select(input);
|
||||
if (select.isMultiple()) {
|
||||
value = select.getAllSelectedOptions().stream().map(it -> getValue(it))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
else {
|
||||
value = getValue(select.getFirstSelectedOption());
|
||||
}
|
||||
}
|
||||
else if (Arrays.asList("checkbox", "radio").contains(type)) {
|
||||
if (input.isSelected()) {
|
||||
value = getValue(input);
|
||||
}
|
||||
else {
|
||||
if (type == "checkbox") {
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
value = getValue(input);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private String getValue(WebElement input) {
|
||||
return input.getAttribute("value");
|
||||
}
|
||||
|
||||
public WebElement dependency(String value) {
|
||||
for (WebElement element : form.findElements(By.name("style"))) {
|
||||
if (value.equals(element.getAttribute("value"))) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("Dependency not found: " + value);
|
||||
}
|
||||
|
||||
public void advanced() {
|
||||
form.findElement(By.cssSelector(".tofullversion"))
|
||||
.findElement(By.tagName("a")).click();
|
||||
}
|
||||
|
||||
public void simple() {
|
||||
form.findElement(By.cssSelector(".tosimpleversion")).click();
|
||||
}
|
||||
|
||||
public void artifactId(String text) {
|
||||
form.findElement(By.id("artifactId")).clear();
|
||||
form.findElement(By.id("artifactId")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void autocomplete(String text) {
|
||||
form.findElement(By.id("autocomplete")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void bootVersion(String text) {
|
||||
form.findElement(By.id("bootVersion")).sendKeys(text);
|
||||
form.click();
|
||||
}
|
||||
|
||||
public void description(String text) {
|
||||
form.findElement(By.id("description")).clear();
|
||||
form.findElement(By.id("description")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void groupId(String text) {
|
||||
form.findElement(By.id("groupId")).clear();
|
||||
form.findElement(By.id("groupId")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void language(String text) {
|
||||
form.findElement(By.id("language")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void name(String text) {
|
||||
form.findElement(By.id("name")).clear();
|
||||
form.findElement(By.id("name")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void packaging(String text) {
|
||||
form.findElement(By.id("packaging")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void packageName(String text) {
|
||||
form.findElement(By.id("packageName")).clear();
|
||||
form.findElement(By.id("packageName")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void type(String text) {
|
||||
form.findElement(By.id("type")).sendKeys(text);
|
||||
}
|
||||
|
||||
public HomePage submit() {
|
||||
String url = driver.getCurrentUrl();
|
||||
form.findElement(By.name("generate-project")).click();
|
||||
assertThat(driver.getCurrentUrl()).isEqualTo(url);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@@ -33,7 +33,8 @@ 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() {
|
||||
@@ -180,7 +181,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)
|
||||
|
@@ -56,15 +56,19 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
@Test
|
||||
public void bootVersionsAreReplaced() {
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
|
||||
.addBootVersion("0.0.9.RELEASE", true).addBootVersion("0.0.8.RELEASE", false).build();
|
||||
.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, restTemplate);
|
||||
DefaultInitializrMetadataProvider provider =
|
||||
new DefaultInitializrMetadataProvider(metadata, 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);
|
||||
@@ -75,15 +79,18 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
@Test
|
||||
public void defaultBootVersionIsAlwaysSet() {
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
|
||||
.addBootVersion("0.0.9.RELEASE", true).addBootVersion("0.0.8.RELEASE", false).build();
|
||||
.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, restTemplate);
|
||||
DefaultInitializrMetadataProvider provider =
|
||||
new DefaultInitializrMetadataProvider(metadata, 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);
|
||||
@@ -91,7 +98,8 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
assertBootVersion(updatedBootVersions.get(3), "1.2.5", false);
|
||||
}
|
||||
|
||||
private static void assertBootVersion(DefaultMetadataElement actual, String name, boolean defaultVersion) {
|
||||
private static void assertBootVersion(DefaultMetadataElement actual, String name,
|
||||
boolean defaultVersion) {
|
||||
assertEquals(name, actual.getName());
|
||||
assertEquals(defaultVersion, actual.isDefault());
|
||||
}
|
||||
|
@@ -40,18 +40,23 @@ 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 RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
private final MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
|
||||
private final MockRestServiceServer server =
|
||||
MockRestServiceServer.bindTo(restTemplate).build();
|
||||
|
||||
@Test
|
||||
public void readAvailableVersions() {
|
||||
server.expect(requestTo("https://spring.io/project_metadata/spring-boot")).andRespond(
|
||||
withSuccess(new ClassPathResource("metadata/sagan/spring-boot.json"), MediaType.APPLICATION_JSON));
|
||||
server.expect(requestTo("https://spring.io/project_metadata/spring-boot"))
|
||||
.andRespond(withSuccess(
|
||||
new ClassPathResource("metadata/sagan/spring-boot.json"),
|
||||
MediaType.APPLICATION_JSON));
|
||||
List<DefaultMetadataElement> versions = new SpringBootMetadataReader(restTemplate,
|
||||
metadata.getConfiguration().getEnv().getSpringBootMetadataUrl()).getBootVersions();
|
||||
metadata.getConfiguration().getEnv()
|
||||
.getSpringBootMetadataUrl()).getBootVersions();
|
||||
assertNotNull("spring boot versions should not be null", versions);
|
||||
AtomicBoolean defaultFound = new AtomicBoolean(false);
|
||||
versions.forEach(it -> {
|
||||
@@ -59,7 +64,7 @@ public class SpringBootMetadataReaderTests {
|
||||
assertNotNull("Name must be set", it.getName());
|
||||
if (it.isDefault()) {
|
||||
if (defaultFound.get()) {
|
||||
fail("One default version was already found $it.id");
|
||||
fail("One default version was already found " + it.getId());
|
||||
}
|
||||
defaultFound.set(true);
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ import org.springframework.restdocs.templates.TemplateEngine;
|
||||
*/
|
||||
public class ResponseFieldSnippet extends TemplatedSnippet {
|
||||
|
||||
private String path;
|
||||
private final String path;
|
||||
|
||||
private final JsonFieldProcessor fieldProcessor = new JsonFieldProcessor();
|
||||
|
||||
@@ -96,7 +96,6 @@ public class ResponseFieldSnippet extends TemplatedSnippet {
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> createModel(Operation operation) {
|
||||
String value = "{}";
|
||||
try {
|
||||
Object object = objectMapper.readValue(
|
||||
operation.getResponse().getContentAsString(), Object.class);
|
||||
@@ -104,12 +103,12 @@ public class ResponseFieldSnippet extends TemplatedSnippet {
|
||||
if (field instanceof List && index != null) {
|
||||
field = ((List<?>) field).get(index);
|
||||
}
|
||||
value = objectMapper.writeValueAsString(field);
|
||||
return Collections.singletonMap("value",
|
||||
objectMapper.writeValueAsString(field));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
return Collections.singletonMap("value", value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -30,7 +30,8 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ActiveProfiles("test-default")
|
||||
public class UiControllerIntegrationTests extends AbstractInitializrControllerIntegrationTests {
|
||||
public class UiControllerIntegrationTests
|
||||
extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void dependenciesNoVersion() {
|
||||
@@ -41,13 +42,15 @@ public class UiControllerIntegrationTests extends AbstractInitializrControllerIn
|
||||
|
||||
@Test
|
||||
public void dependenciesSpecificVersion() {
|
||||
ResponseEntity<String> response = execute("/ui/dependencies?version=1.1.2.RELEASE", String.class, null);
|
||||
ResponseEntity<String> response = execute(
|
||||
"/ui/dependencies?version=1.1.2.RELEASE", String.class, null);
|
||||
validateContentType(response, MediaType.APPLICATION_JSON);
|
||||
validateDependenciesOutput("1.1.2", new JSONObject(response.getBody()));
|
||||
}
|
||||
|
||||
protected void validateDependenciesOutput(String version, JSONObject actual) {
|
||||
JSONObject expected = readJsonFrom("metadata/ui/test-dependencies-" + version + ".json");
|
||||
JSONObject expected = readJsonFrom(
|
||||
"metadata/ui/test-dependencies-" + version + ".json");
|
||||
JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user