mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-02 11:24:04 +08:00
Apply automatic cleanup rules
Apply code cleanup rules from Eclipse for better consistency.
This commit is contained in:
@@ -99,7 +99,7 @@ public class InitializrAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ProjectRequestResolver projectRequestResolver() {
|
||||
return new ProjectRequestResolver(postProcessors);
|
||||
return new ProjectRequestResolver(this.postProcessors);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -65,7 +65,7 @@ public class InitializrWebConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public List<MediaType> resolveMediaTypes(NativeWebRequest request)
|
||||
throws HttpMediaTypeNotAcceptableException {
|
||||
String path = urlPathHelper.getPathWithinApplication(
|
||||
String path = this.urlPathHelper.getPathWithinApplication(
|
||||
request.getNativeRequest(HttpServletRequest.class));
|
||||
if (!StringUtils.hasText(path) || !path.equals("/")) { // Only care about "/"
|
||||
return MEDIA_TYPE_ALL_LIST;
|
||||
|
||||
@@ -44,7 +44,7 @@ public enum InitializrMetadataVersion {
|
||||
}
|
||||
|
||||
public MediaType getMediaType() {
|
||||
return mediaType;
|
||||
return this.mediaType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public abstract class AbstractInitializrController {
|
||||
|
||||
public boolean isForceSsl() {
|
||||
if (this.forceSsl == null) {
|
||||
this.forceSsl = metadataProvider.get().getConfiguration().getEnv()
|
||||
this.forceSsl = this.metadataProvider.get().getConfiguration().getEnv()
|
||||
.isForceSsl();
|
||||
}
|
||||
return this.forceSsl;
|
||||
@@ -75,7 +75,7 @@ public abstract class AbstractInitializrController {
|
||||
* Render the home page with the specified template.
|
||||
*/
|
||||
protected void renderHome(Map<String, Object> model) {
|
||||
InitializrMetadata metadata = metadataProvider.get();
|
||||
InitializrMetadata metadata = this.metadataProvider.get();
|
||||
|
||||
model.put("serviceUrl", generateAppUrl());
|
||||
BeanWrapperImpl wrapper = new BeanWrapperImpl(metadata);
|
||||
@@ -96,7 +96,7 @@ public abstract class AbstractInitializrController {
|
||||
}
|
||||
|
||||
public Function<String, String> getLinkTo() {
|
||||
return linkTo;
|
||||
return this.linkTo;
|
||||
}
|
||||
|
||||
private TypeCapability removeTypes(TypeCapability types) {
|
||||
|
||||
@@ -105,14 +105,14 @@ public class MainController extends AbstractInitializrController {
|
||||
@RequestHeader Map<String, String> headers) {
|
||||
ProjectRequest request = new ProjectRequest();
|
||||
request.getParameters().putAll(headers);
|
||||
request.initialize(metadataProvider.get());
|
||||
request.initialize(this.metadataProvider.get());
|
||||
return request;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/metadata/config", produces = "application/json")
|
||||
@ResponseBody
|
||||
public InitializrMetadata config() {
|
||||
return metadataProvider.get();
|
||||
return this.metadataProvider.get();
|
||||
}
|
||||
|
||||
@RequestMapping("/metadata/client")
|
||||
@@ -124,31 +124,31 @@ public class MainController extends AbstractInitializrController {
|
||||
public ResponseEntity<String> serviceCapabilitiesText(
|
||||
@RequestHeader(value = HttpHeaders.USER_AGENT, required = false) String userAgent) {
|
||||
String appUrl = generateAppUrl();
|
||||
InitializrMetadata metadata = metadataProvider.get();
|
||||
InitializrMetadata metadata = this.metadataProvider.get();
|
||||
|
||||
BodyBuilder builder = ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN);
|
||||
if (userAgent != null) {
|
||||
Agent agent = Agent.fromUserAgent(userAgent);
|
||||
if (agent != null) {
|
||||
if (CURL.equals(agent.getId())) {
|
||||
String content = commandLineHelpGenerator
|
||||
String content = this.commandLineHelpGenerator
|
||||
.generateCurlCapabilities(metadata, appUrl);
|
||||
return builder.eTag(createUniqueId(content)).body(content);
|
||||
}
|
||||
if (HTTPIE.equals(agent.getId())) {
|
||||
String content = commandLineHelpGenerator
|
||||
String content = this.commandLineHelpGenerator
|
||||
.generateHttpieCapabilities(metadata, appUrl);
|
||||
return builder.eTag(createUniqueId(content)).body(content);
|
||||
}
|
||||
if (SPRING_BOOT_CLI.equals(agent.getId())) {
|
||||
String content = commandLineHelpGenerator
|
||||
String content = this.commandLineHelpGenerator
|
||||
.generateSpringBootCliCapabilities(metadata, appUrl);
|
||||
return builder.eTag(createUniqueId(content)).body(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
String content = commandLineHelpGenerator.generateGenericCapabilities(metadata,
|
||||
appUrl);
|
||||
String content = this.commandLineHelpGenerator
|
||||
.generateGenericCapabilities(metadata, appUrl);
|
||||
return builder.eTag(createUniqueId(content)).body(content);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,8 @@ public class MainController extends AbstractInitializrController {
|
||||
private ResponseEntity<String> serviceCapabilitiesFor(
|
||||
InitializrMetadataVersion version, MediaType contentType) {
|
||||
String appUrl = generateAppUrl();
|
||||
String content = getJsonMapper(version).write(metadataProvider.get(), appUrl);
|
||||
String content = getJsonMapper(version).write(this.metadataProvider.get(),
|
||||
appUrl);
|
||||
return ResponseEntity.ok().contentType(contentType).eTag(createUniqueId(content))
|
||||
.cacheControl(CacheControl.maxAge(7, TimeUnit.DAYS)).body(content);
|
||||
}
|
||||
@@ -201,11 +202,11 @@ public class MainController extends AbstractInitializrController {
|
||||
|
||||
private ResponseEntity<String> dependenciesFor(InitializrMetadataVersion version,
|
||||
String bootVersion) {
|
||||
InitializrMetadata metadata = metadataProvider.get();
|
||||
InitializrMetadata metadata = this.metadataProvider.get();
|
||||
Version v = bootVersion != null ? Version.parse(bootVersion)
|
||||
: Version.parse(metadata.getBootVersions().getDefault().getId());
|
||||
DependencyMetadata dependencyMetadata = dependencyMetadataProvider.get(metadata,
|
||||
v);
|
||||
DependencyMetadata dependencyMetadata = this.dependencyMetadataProvider
|
||||
.get(metadata, v);
|
||||
String content = new DependencyMetadataV21JsonMapper().write(dependencyMetadata);
|
||||
return ResponseEntity.ok().contentType(version.getMediaType())
|
||||
.eTag(createUniqueId(content))
|
||||
@@ -225,13 +226,13 @@ public class MainController extends AbstractInitializrController {
|
||||
|
||||
@RequestMapping(path = { "/spring", "/spring.zip" })
|
||||
public String spring() {
|
||||
String url = metadataProvider.get().createCliDistributionURl("zip");
|
||||
String url = this.metadataProvider.get().createCliDistributionURl("zip");
|
||||
return "redirect:" + url;
|
||||
}
|
||||
|
||||
@RequestMapping(path = { "/spring.tar.gz", "spring.tgz" })
|
||||
public String springTgz() {
|
||||
String url = metadataProvider.get().createCliDistributionURl("tar.gz");
|
||||
String url = this.metadataProvider.get().createCliDistributionURl("tar.gz");
|
||||
return "redirect:" + url;
|
||||
}
|
||||
|
||||
@@ -239,7 +240,8 @@ public class MainController extends AbstractInitializrController {
|
||||
@ResponseBody
|
||||
public ResponseEntity<byte[]> pom(BasicProjectRequest request) {
|
||||
request.setType("maven-build");
|
||||
byte[] mavenPom = projectGenerator.generateMavenPom((ProjectRequest) request);
|
||||
byte[] mavenPom = this.projectGenerator
|
||||
.generateMavenPom((ProjectRequest) request);
|
||||
return createResponseEntity(mavenPom, "application/octet-stream", "pom.xml");
|
||||
}
|
||||
|
||||
@@ -247,7 +249,7 @@ public class MainController extends AbstractInitializrController {
|
||||
@ResponseBody
|
||||
public ResponseEntity<byte[]> gradle(BasicProjectRequest request) {
|
||||
request.setType("gradle-build");
|
||||
byte[] gradleBuild = projectGenerator
|
||||
byte[] gradleBuild = this.projectGenerator
|
||||
.generateGradleBuild((ProjectRequest) request);
|
||||
return createResponseEntity(gradleBuild, "application/octet-stream",
|
||||
"build.gradle");
|
||||
@@ -258,9 +260,9 @@ public class MainController extends AbstractInitializrController {
|
||||
public ResponseEntity<byte[]> springZip(BasicProjectRequest basicRequest)
|
||||
throws IOException {
|
||||
ProjectRequest request = (ProjectRequest) basicRequest;
|
||||
File dir = projectGenerator.generateProjectStructure(request);
|
||||
File dir = this.projectGenerator.generateProjectStructure(request);
|
||||
|
||||
File download = projectGenerator.createDistributionFile(dir, ".zip");
|
||||
File download = this.projectGenerator.createDistributionFile(dir, ".zip");
|
||||
|
||||
String wrapperScript = getWrapperScript(request);
|
||||
new File(dir, wrapperScript).setExecutable(true);
|
||||
@@ -289,9 +291,9 @@ public class MainController extends AbstractInitializrController {
|
||||
public ResponseEntity<byte[]> springTgz(BasicProjectRequest basicRequest)
|
||||
throws IOException {
|
||||
ProjectRequest request = (ProjectRequest) basicRequest;
|
||||
File dir = projectGenerator.generateProjectStructure(request);
|
||||
File dir = this.projectGenerator.generateProjectStructure(request);
|
||||
|
||||
File download = projectGenerator.createDistributionFile(dir, ".tar.gz");
|
||||
File download = this.projectGenerator.createDistributionFile(dir, ".tar.gz");
|
||||
|
||||
String wrapperScript = getWrapperScript(request);
|
||||
new File(dir, wrapperScript).setExecutable(true);
|
||||
@@ -339,7 +341,7 @@ public class MainController extends AbstractInitializrController {
|
||||
log.info("Uploading: {} ({} bytes)", download, bytes.length);
|
||||
ResponseEntity<byte[]> result = createResponseEntity(bytes, contentType,
|
||||
fileName);
|
||||
projectGenerator.cleanTempFiles(dir);
|
||||
this.projectGenerator.cleanTempFiles(dir);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,8 @@ public class DefaultInitializrMetadataProvider implements InitializrMetadataProv
|
||||
@Override
|
||||
@Cacheable(value = "initializr.metadata", key = "'metadata'")
|
||||
public InitializrMetadata get() {
|
||||
updateInitializrMetadata(metadata);
|
||||
return metadata;
|
||||
updateInitializrMetadata(this.metadata);
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
protected void updateInitializrMetadata(InitializrMetadata metadata) {
|
||||
@@ -72,12 +72,12 @@ public class DefaultInitializrMetadataProvider implements InitializrMetadataProv
|
||||
}
|
||||
|
||||
protected List<DefaultMetadataElement> fetchBootVersions() {
|
||||
String url = metadata.getConfiguration().getEnv().getSpringBootMetadataUrl();
|
||||
String url = this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl();
|
||||
if (StringUtils.hasText(url)) {
|
||||
try {
|
||||
log.info("Fetching boot metadata from {}", url);
|
||||
return new SpringBootMetadataReader(objectMapper, restTemplate, url)
|
||||
.getBootVersions();
|
||||
return new SpringBootMetadataReader(this.objectMapper, this.restTemplate,
|
||||
url).getBootVersions();
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("Failed to fetch spring boot metadata", e);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SpringBootMetadataReader {
|
||||
* Return the boot versions parsed by this instance.
|
||||
*/
|
||||
public List<DefaultMetadataElement> getBootVersions() {
|
||||
ArrayNode array = (ArrayNode) content.get("projectReleases");
|
||||
ArrayNode array = (ArrayNode) this.content.get("projectReleases");
|
||||
List<DefaultMetadataElement> list = new ArrayList<>();
|
||||
for (JsonNode it : array) {
|
||||
DefaultMetadataElement version = new DefaultMetadataElement();
|
||||
|
||||
@@ -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 = this.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 -> {
|
||||
|
||||
@@ -41,7 +41,7 @@ public abstract class AbstractFullStackInitializrIntegrationTests
|
||||
|
||||
@Override
|
||||
protected String createUrl(String context) {
|
||||
return "http://" + host + ":" + port
|
||||
return "http://" + this.host + ":" + this.port
|
||||
+ (context.startsWith("/") ? context : "/" + context);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class AbstractInitializrControllerIntegrationTests
|
||||
}
|
||||
|
||||
public MockMvcClientHttpRequestFactory getRequests() {
|
||||
return requests;
|
||||
return this.requests;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -86,7 +86,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
restTemplate = restTemplateBuilder.build();
|
||||
this.restTemplate = this.restTemplateBuilder.build();
|
||||
}
|
||||
|
||||
protected abstract String createUrl(String context);
|
||||
@@ -94,7 +94,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
protected String htmlHome() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.TEXT_HTML));
|
||||
return restTemplate.exchange(createUrl("/"), HttpMethod.GET,
|
||||
return this.restTemplate.exchange(createUrl("/"), HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class).getBody();
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
}
|
||||
|
||||
protected byte[] downloadArchive(String context) {
|
||||
return restTemplate.getForObject(createUrl(context), byte[].class);
|
||||
return this.restTemplate.getForObject(createUrl(context), byte[].class);
|
||||
}
|
||||
|
||||
protected ResponseEntity<String> invokeHome(String userAgentHeader,
|
||||
@@ -199,7 +199,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
else {
|
||||
headers.setAccept(Collections.emptyList());
|
||||
}
|
||||
return restTemplate.exchange(createUrl(contextPath), HttpMethod.GET,
|
||||
return this.restTemplate.exchange(createUrl(contextPath), HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), responseType);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
try {
|
||||
File archiveFile = writeArchive(content);
|
||||
|
||||
File project = folder.newFolder();
|
||||
File project = this.folder.newFolder();
|
||||
switch (archiveType) {
|
||||
case ZIP:
|
||||
unzip(archiveFile, project);
|
||||
@@ -243,7 +243,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
}
|
||||
|
||||
protected File writeArchive(byte[] body) throws IOException {
|
||||
File archiveFile = folder.newFile();
|
||||
File archiveFile = this.folder.newFile();
|
||||
try (FileOutputStream stream = new FileOutputStream(archiveFile)) {
|
||||
stream.write(body);
|
||||
}
|
||||
@@ -275,7 +275,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
}
|
||||
|
||||
public RestTemplate getRestTemplate() {
|
||||
return restTemplate;
|
||||
return this.restTemplate;
|
||||
}
|
||||
|
||||
private enum ArchiveType {
|
||||
|
||||
@@ -36,37 +36,41 @@ public class CloudfoundryEnvironmentPostProcessorTests {
|
||||
|
||||
@Test
|
||||
public void parseCredentials() {
|
||||
environment.setProperty("vcap.services.stats-index.credentials.uri",
|
||||
this.environment.setProperty("vcap.services.stats-index.credentials.uri",
|
||||
"http://user:pass@example.com/bar/biz?param=one");
|
||||
postProcessor.postProcessEnvironment(environment, application);
|
||||
this.postProcessor.postProcessEnvironment(this.environment, this.application);
|
||||
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.uri"))
|
||||
assertThat(this.environment.getProperty("initializr.stats.elastic.uri"))
|
||||
.isEqualTo("http://example.com/bar/biz?param=one");
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.username"))
|
||||
assertThat(this.environment.getProperty("initializr.stats.elastic.username"))
|
||||
.isEqualTo("user");
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.password"))
|
||||
assertThat(this.environment.getProperty("initializr.stats.elastic.password"))
|
||||
.isEqualTo("pass");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseNoCredentials() {
|
||||
environment.setProperty("vcap.services.stats-index.credentials.uri",
|
||||
this.environment.setProperty("vcap.services.stats-index.credentials.uri",
|
||||
"http://example.com/bar/biz?param=one");
|
||||
postProcessor.postProcessEnvironment(environment, application);
|
||||
this.postProcessor.postProcessEnvironment(this.environment, this.application);
|
||||
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.uri"))
|
||||
assertThat(this.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();
|
||||
assertThat(this.environment.getProperty("initializr.stats.elastic.username"))
|
||||
.isNull();
|
||||
assertThat(this.environment.getProperty("initializr.stats.elastic.password"))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseNoVcapUri() {
|
||||
postProcessor.postProcessEnvironment(environment, application);
|
||||
this.postProcessor.postProcessEnvironment(this.environment, this.application);
|
||||
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.uri")).isNull();
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.username")).isNull();
|
||||
assertThat(environment.getProperty("initializr.stats.elastic.password")).isNull();
|
||||
assertThat(this.environment.getProperty("initializr.stats.elastic.uri")).isNull();
|
||||
assertThat(this.environment.getProperty("initializr.stats.elastic.username"))
|
||||
.isNull();
|
||||
assertThat(this.environment.getProperty("initializr.stats.elastic.password"))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class DependencyMetadataJsonMapperTests {
|
||||
Version.parse("1.2.0.RELEASE"), Collections.singletonMap(d.getId(), d),
|
||||
Collections.singletonMap("repo-id", repository),
|
||||
Collections.singletonMap("bom-id", bom));
|
||||
JSONObject content = new JSONObject(mapper.write(metadata));
|
||||
JSONObject content = new JSONObject(this.mapper.write(metadata));
|
||||
assertEquals("my-bom", content.getJSONObject("dependencies").getJSONObject("foo")
|
||||
.getString("bom"));
|
||||
assertEquals("my-repo", content.getJSONObject("dependencies").getJSONObject("foo")
|
||||
|
||||
@@ -43,7 +43,7 @@ public class InitializrMetadataJsonMapperTests {
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
|
||||
.addType("foo", true, "/foo.zip", "none", "test")
|
||||
.addDependencyGroup("foo", "one", "two").build();
|
||||
String json = jsonMapper.write(metadata, null);
|
||||
String json = this.jsonMapper.write(metadata, null);
|
||||
JsonNode result = objectMapper.readTree(json);
|
||||
assertEquals(
|
||||
"/foo.zip?type=foo{&dependencies,packaging,javaVersion,language,bootVersion,"
|
||||
@@ -56,7 +56,7 @@ public class InitializrMetadataJsonMapperTests {
|
||||
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");
|
||||
String json = this.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,"
|
||||
@@ -71,7 +71,7 @@ public class InitializrMetadataJsonMapperTests {
|
||||
dependency.getLinks().add(Link.create("reference", "https://example.com/doc"));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", dependency).build();
|
||||
String json = jsonMapper.write(metadata, null);
|
||||
String json = this.jsonMapper.write(metadata, null);
|
||||
int first = json.indexOf("https://example.com/how-to");
|
||||
int second = json.indexOf("https://example.com/doc");
|
||||
// JSON objects are not ordered
|
||||
|
||||
@@ -45,7 +45,7 @@ class HomePage {
|
||||
}
|
||||
|
||||
public Object value(String id) {
|
||||
return getInputValue(form.findElement(By.id(id)));
|
||||
return getInputValue(this.form.findElement(By.id(id)));
|
||||
}
|
||||
|
||||
private Object getInputValue(WebElement input) {
|
||||
@@ -82,7 +82,7 @@ class HomePage {
|
||||
}
|
||||
|
||||
public WebElement dependency(String value) {
|
||||
for (WebElement element : form.findElements(By.name("style"))) {
|
||||
for (WebElement element : this.form.findElements(By.name("style"))) {
|
||||
if (value.equals(element.getAttribute("value"))) {
|
||||
return element;
|
||||
}
|
||||
@@ -91,64 +91,64 @@ class HomePage {
|
||||
}
|
||||
|
||||
public void advanced() {
|
||||
form.findElement(By.cssSelector(".tofullversion")).findElement(By.tagName("a"))
|
||||
.click();
|
||||
this.form.findElement(By.cssSelector(".tofullversion"))
|
||||
.findElement(By.tagName("a")).click();
|
||||
}
|
||||
|
||||
public void simple() {
|
||||
form.findElement(By.cssSelector(".tosimpleversion")).click();
|
||||
this.form.findElement(By.cssSelector(".tosimpleversion")).click();
|
||||
}
|
||||
|
||||
public void artifactId(String text) {
|
||||
form.findElement(By.id("artifactId")).clear();
|
||||
form.findElement(By.id("artifactId")).sendKeys(text);
|
||||
this.form.findElement(By.id("artifactId")).clear();
|
||||
this.form.findElement(By.id("artifactId")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void autocomplete(String text) {
|
||||
form.findElement(By.id("autocomplete")).sendKeys(text);
|
||||
this.form.findElement(By.id("autocomplete")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void bootVersion(String text) {
|
||||
form.findElement(By.id("bootVersion")).sendKeys(text);
|
||||
form.click();
|
||||
this.form.findElement(By.id("bootVersion")).sendKeys(text);
|
||||
this.form.click();
|
||||
}
|
||||
|
||||
public void description(String text) {
|
||||
form.findElement(By.id("description")).clear();
|
||||
form.findElement(By.id("description")).sendKeys(text);
|
||||
this.form.findElement(By.id("description")).clear();
|
||||
this.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);
|
||||
this.form.findElement(By.id("groupId")).clear();
|
||||
this.form.findElement(By.id("groupId")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void language(String text) {
|
||||
form.findElement(By.id("language")).sendKeys(text);
|
||||
this.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);
|
||||
this.form.findElement(By.id("name")).clear();
|
||||
this.form.findElement(By.id("name")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void packaging(String text) {
|
||||
form.findElement(By.id("packaging")).sendKeys(text);
|
||||
this.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);
|
||||
this.form.findElement(By.id("packageName")).clear();
|
||||
this.form.findElement(By.id("packageName")).sendKeys(text);
|
||||
}
|
||||
|
||||
public void type(String text) {
|
||||
form.findElement(By.id("type")).sendKeys(text);
|
||||
this.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);
|
||||
String url = this.driver.getCurrentUrl();
|
||||
this.form.findElement(By.name("generate-project")).click();
|
||||
assertThat(this.driver.getCurrentUrl()).isEqualTo(url);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
|
||||
|
||||
import io.spring.initializr.metadata.Dependency;
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
|
||||
import io.spring.initializr.web.AbstractInitializrIntegrationTests;
|
||||
import io.spring.initializr.web.mapper.InitializrMetadataVersion;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -171,8 +172,8 @@ public class MainControllerIntegrationTests
|
||||
public void currentMetadataCompatibleWithV2() {
|
||||
ResponseEntity<String> response = invokeHome(null, "*/*");
|
||||
validateMetadata(response,
|
||||
AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE,
|
||||
"2.0.0", JSONCompareMode.LENIENT);
|
||||
AbstractInitializrIntegrationTests.CURRENT_METADATA_MEDIA_TYPE, "2.0.0",
|
||||
JSONCompareMode.LENIENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,7 +193,7 @@ public class MainControllerIntegrationTests
|
||||
"application/vnd.initializr.v2.1+json");
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
validateContentType(response,
|
||||
AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
AbstractInitializrIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateCurrentMetadata(response.getBody());
|
||||
}
|
||||
|
||||
@@ -202,7 +203,7 @@ public class MainControllerIntegrationTests
|
||||
"application/vnd.initializr.v2.1+json",
|
||||
"application/vnd.initializr.v2+json");
|
||||
validateContentType(response,
|
||||
AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
AbstractInitializrIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateCurrentMetadata(response.getBody());
|
||||
}
|
||||
|
||||
@@ -249,7 +250,7 @@ public class MainControllerIntegrationTests
|
||||
public void curlWithAcceptHeaderJson() {
|
||||
ResponseEntity<String> response = invokeHome("curl/1.2.4", "application/json");
|
||||
validateContentType(response,
|
||||
AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
AbstractInitializrIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateCurrentMetadata(response.getBody());
|
||||
}
|
||||
|
||||
@@ -276,7 +277,7 @@ public class MainControllerIntegrationTests
|
||||
public void httpieWithAcceptHeaderJson() {
|
||||
ResponseEntity<String> response = invokeHome("HTTPie/0.8.0", "application/json");
|
||||
validateContentType(response,
|
||||
AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
AbstractInitializrIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateCurrentMetadata(response.getBody());
|
||||
}
|
||||
|
||||
@@ -296,7 +297,7 @@ public class MainControllerIntegrationTests
|
||||
public void springBootCliReceivesJsonByDefault() {
|
||||
ResponseEntity<String> response = invokeHome("SpringBootCli/1.2.0", "*/*");
|
||||
validateContentType(response,
|
||||
AbstractInitializrControllerIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
AbstractInitializrIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateCurrentMetadata(response.getBody());
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MainControllerServiceMetadataIntegrationTests
|
||||
|
||||
@Test
|
||||
public void initializeRemoteConfig() throws Exception {
|
||||
InitializrMetadata localMetadata = metadataProvider.get();
|
||||
InitializrMetadata localMetadata = this.metadataProvider.get();
|
||||
InitializrMetadata metadata = InitializrMetadataBuilder.create()
|
||||
.withInitializrMetadata(new UrlResource(createUrl("/metadata/config")))
|
||||
.build();
|
||||
|
||||
@@ -60,25 +60,26 @@ public class ProjectGenerationSmokeTests
|
||||
public void setup() throws IOException {
|
||||
Assume.assumeTrue("Smoke tests disabled (set System property 'smoke.test')",
|
||||
Boolean.getBoolean("smoke.test"));
|
||||
downloadDir = folder.newFolder();
|
||||
this.downloadDir = this.folder.newFolder();
|
||||
FirefoxProfile fxProfile = new FirefoxProfile();
|
||||
fxProfile.setPreference("browser.download.folderList", 2);
|
||||
fxProfile.setPreference("browser.download.manager.showWhenStarting", false);
|
||||
fxProfile.setPreference("browser.download.dir", downloadDir.getAbsolutePath());
|
||||
fxProfile.setPreference("browser.download.dir",
|
||||
this.downloadDir.getAbsolutePath());
|
||||
fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
|
||||
"application/zip,application/x-compress,application/octet-stream");
|
||||
FirefoxOptions options = new FirefoxOptions().setProfile(fxProfile);
|
||||
driver = new FirefoxDriver(options);
|
||||
((JavascriptExecutor) driver).executeScript("window.focus();");
|
||||
this.driver = new FirefoxDriver(options);
|
||||
((JavascriptExecutor) this.driver).executeScript("window.focus();");
|
||||
|
||||
Actions actions = new Actions(driver);
|
||||
enterAction = actions.sendKeys(Keys.ENTER).build();
|
||||
Actions actions = new Actions(this.driver);
|
||||
this.enterAction = actions.sendKeys(Keys.ENTER).build();
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
if (driver != null) {
|
||||
driver.close();
|
||||
if (this.driver != null) {
|
||||
this.driver.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,8 +356,8 @@ public class ProjectGenerationSmokeTests
|
||||
}
|
||||
|
||||
private HomePage toHome(String path) {
|
||||
driver.get("http://localhost:" + port + path);
|
||||
return new HomePage(driver);
|
||||
this.driver.get("http://localhost:" + this.port + path);
|
||||
return new HomePage(this.driver);
|
||||
}
|
||||
|
||||
private ProjectAssert assertSimpleProject() throws Exception {
|
||||
@@ -366,7 +367,7 @@ public class ProjectGenerationSmokeTests
|
||||
|
||||
private void selectDependency(HomePage page, String text) {
|
||||
page.autocomplete(text);
|
||||
enterAction.perform();
|
||||
this.enterAction.perform();
|
||||
}
|
||||
|
||||
private byte[] from(String fileName) throws Exception {
|
||||
@@ -374,7 +375,7 @@ public class ProjectGenerationSmokeTests
|
||||
}
|
||||
|
||||
private File getArchive(String fileName) {
|
||||
File archive = new File(downloadDir, fileName);
|
||||
File archive = new File(this.downloadDir, fileName);
|
||||
assertTrue("Expected content with name " + fileName, archive.exists());
|
||||
return archive;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
third.setVersionRange("1.1.8.RELEASE");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", first, second, third).build();
|
||||
DependencyMetadata dependencyMetadata = provider.get(metadata,
|
||||
DependencyMetadata dependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.1.5.RELEASE"));
|
||||
assertEquals(2, dependencyMetadata.getDependencies().size());
|
||||
assertEquals(0, dependencyMetadata.getRepositories().size());
|
||||
@@ -64,7 +64,7 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", first, second).build();
|
||||
|
||||
DependencyMetadata dependencyMetadata = provider.get(metadata,
|
||||
DependencyMetadata dependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.0.5.RELEASE"));
|
||||
assertEquals(2, dependencyMetadata.getDependencies().size());
|
||||
assertEquals("org.bar",
|
||||
@@ -74,7 +74,7 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
assertEquals("0.1.0.RELEASE",
|
||||
dependencyMetadata.getDependencies().get("first").getVersion());
|
||||
|
||||
DependencyMetadata anotherDependencyMetadata = provider.get(metadata,
|
||||
DependencyMetadata anotherDependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.1.0.RELEASE"));
|
||||
assertEquals(2, anotherDependencyMetadata.getDependencies().size());
|
||||
assertEquals("org.biz",
|
||||
@@ -95,7 +95,7 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addRepository("repo-foo", "my-repo", "http://localhost", false)
|
||||
.addDependencyGroup("test", first, second, third).build();
|
||||
DependencyMetadata dependencyMetadata = provider.get(metadata,
|
||||
DependencyMetadata dependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.1.5.RELEASE"));
|
||||
assertEquals(3, dependencyMetadata.getDependencies().size());
|
||||
assertEquals(1, dependencyMetadata.getRepositories().size());
|
||||
@@ -120,7 +120,7 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addBom("bom-foo", bom).addDependencyGroup("test", first, second, third)
|
||||
.build();
|
||||
DependencyMetadata dependencyMetadata = provider.get(metadata,
|
||||
DependencyMetadata dependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.1.5.RELEASE"));
|
||||
assertEquals(3, dependencyMetadata.getDependencies().size());
|
||||
assertEquals(0, dependencyMetadata.getRepositories().size());
|
||||
@@ -186,7 +186,7 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
.addRepository("repo-bar", "bar", "http://localhost", false)
|
||||
.addRepository("repo-biz", "biz", "http://localhost", false)
|
||||
.addDependencyGroup("test", first, second, third).build();
|
||||
return provider.get(metadata, Version.parse(bootVersion));
|
||||
return this.provider.get(metadata, Version.parse(bootVersion));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
restTemplate = new RestTemplate();
|
||||
mockServer = MockRestServiceServer.createServer(restTemplate);
|
||||
this.restTemplate = new RestTemplate();
|
||||
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,7 +63,7 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
.addBootVersion("0.0.8.RELEASE", false).build();
|
||||
assertEquals("0.0.9.RELEASE", metadata.getBootVersions().getDefault().getId());
|
||||
DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider(
|
||||
metadata, objectMapper, restTemplate);
|
||||
metadata, objectMapper, this.restTemplate);
|
||||
expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(),
|
||||
"metadata/sagan/spring-boot.json");
|
||||
|
||||
@@ -85,7 +85,7 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
.addBootVersion("0.0.8.RELEASE", false).build();
|
||||
assertEquals("0.0.9.RELEASE", metadata.getBootVersions().getDefault().getId());
|
||||
DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider(
|
||||
metadata, objectMapper, restTemplate);
|
||||
metadata, objectMapper, this.restTemplate);
|
||||
expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(),
|
||||
"metadata/sagan/spring-boot-no-default.json");
|
||||
|
||||
|
||||
@@ -50,17 +50,17 @@ public class SpringBootMetadataReaderTests {
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
private final MockRestServiceServer server = MockRestServiceServer
|
||||
.bindTo(restTemplate).build();
|
||||
.bindTo(this.restTemplate).build();
|
||||
|
||||
@Test
|
||||
public void readAvailableVersions() throws IOException {
|
||||
server.expect(requestTo("https://spring.io/project_metadata/spring-boot"))
|
||||
this.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(objectMapper,
|
||||
restTemplate,
|
||||
metadata.getConfiguration().getEnv().getSpringBootMetadataUrl())
|
||||
List<DefaultMetadataElement> versions = new SpringBootMetadataReader(
|
||||
this.objectMapper, this.restTemplate,
|
||||
this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl())
|
||||
.getBootVersions();
|
||||
assertNotNull("spring boot versions should not be null", versions);
|
||||
AtomicBoolean defaultFound = new AtomicBoolean(false);
|
||||
@@ -74,7 +74,7 @@ public class SpringBootMetadataReaderTests {
|
||||
defaultFound.set(true);
|
||||
}
|
||||
});
|
||||
server.verify();
|
||||
this.server.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class MockMvcClientHttpRequestFactory implements ClientHttpRequestFactory
|
||||
for (String field : this.fields) {
|
||||
snippets.add(new ResponseFieldSnippet(field));
|
||||
}
|
||||
actions.andDo(document(label, preprocessResponse(prettyPrint()),
|
||||
actions.andDo(document(this.label, preprocessResponse(prettyPrint()),
|
||||
snippets.toArray(new Snippet[0])));
|
||||
this.fields = new ArrayList<>();
|
||||
return actions;
|
||||
|
||||
@@ -34,20 +34,20 @@ public final class MockMvcClientHttpRequestFactoryTestExecutionListener
|
||||
ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) testContext
|
||||
.getApplicationContext().getAutowireCapableBeanFactory();
|
||||
if (!beanFactory.containsBean("mockMvcClientHttpRequestFactory")) {
|
||||
factory = new MockMvcClientHttpRequestFactory(
|
||||
this.factory = new MockMvcClientHttpRequestFactory(
|
||||
beanFactory.getBean(MockMvc.class));
|
||||
beanFactory.registerSingleton("mockMvcClientHttpRequestFactory",
|
||||
this.factory);
|
||||
}
|
||||
else {
|
||||
factory = beanFactory.getBean("mockMvcClientHttpRequestFactory",
|
||||
this.factory = beanFactory.getBean("mockMvcClientHttpRequestFactory",
|
||||
MockMvcClientHttpRequestFactory.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTestMethod(TestContext testContext) throws Exception {
|
||||
if (factory != null) {
|
||||
if (this.factory != null) {
|
||||
this.factory.setTest(testContext.getTestClass(), testContext.getTestMethod());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ResponseFieldSnippet extends TemplatedSnippet {
|
||||
}
|
||||
this.file = file;
|
||||
this.path = path;
|
||||
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
|
||||
this.objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -84,8 +84,8 @@ public class ResponseFieldSnippet extends TemplatedSnippet {
|
||||
.getAttributes().get(RestDocumentationContext.class.getName());
|
||||
WriterResolver writerResolver = (WriterResolver) operation.getAttributes()
|
||||
.get(WriterResolver.class.getName());
|
||||
try (Writer writer = writerResolver
|
||||
.resolve(operation.getName() + "/" + getSnippetName(), file, context)) {
|
||||
try (Writer writer = writerResolver.resolve(
|
||||
operation.getName() + "/" + getSnippetName(), this.file, context)) {
|
||||
Map<String, Object> model = createModel(operation);
|
||||
model.putAll(getAttributes());
|
||||
TemplateEngine templateEngine = (TemplateEngine) operation.getAttributes()
|
||||
@@ -97,14 +97,15 @@ public class ResponseFieldSnippet extends TemplatedSnippet {
|
||||
@Override
|
||||
protected Map<String, Object> createModel(Operation operation) {
|
||||
try {
|
||||
Object object = objectMapper.readValue(
|
||||
Object object = this.objectMapper.readValue(
|
||||
operation.getResponse().getContentAsString(), Object.class);
|
||||
Object field = fieldProcessor.extract(JsonFieldPath.compile(path), object);
|
||||
if (field instanceof List && index != null) {
|
||||
field = ((List<?>) field).get(index);
|
||||
Object field = this.fieldProcessor.extract(JsonFieldPath.compile(this.path),
|
||||
object);
|
||||
if (field instanceof List && this.index != null) {
|
||||
field = ((List<?>) field).get(this.index);
|
||||
}
|
||||
return Collections.singletonMap("value",
|
||||
objectMapper.writeValueAsString(field));
|
||||
this.objectMapper.writeValueAsString(field));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
|
||||
Reference in New Issue
Block a user