From af9d54331711bc0fc6285c011801ff610d30ec5e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 17 Sep 2019 11:05:51 +0200 Subject: [PATCH] Polish "Remove support for style" Closes gh-959 --- .../ProjectGenerationController.java | 11 +++++- ...tGenerationControllerIntegrationTests.java | 34 +++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java b/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java index 8a7d81e8..9ddc0515 100644 --- a/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java +++ b/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java @@ -58,6 +58,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; /** @@ -81,13 +82,21 @@ public abstract class ProjectGenerationController { this.projectGenerationInvoker = projectGenerationInvoker; } + @ModelAttribute + R projectRequest(@RequestHeader Map headers, + @RequestParam(name = "style", required = false) String style) { + if (style != null) { + throw new InvalidProjectRequestException("Dependencies must be specified using 'dependencies'"); + } + return projectRequest(headers); + } + /** * Create an initialized {@link ProjectRequest} instance to use to bind the parameters * of a project generation request. * @param headers the headers of the request * @return a new {@link ProjectRequest} instance */ - @ModelAttribute public abstract R projectRequest(@RequestHeader Map headers); protected InitializrMetadata getMetadata() { diff --git a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java index cab52866..0988304e 100755 --- a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java +++ b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java @@ -30,6 +30,7 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.web.client.HttpClientErrorException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.fail; /** @@ -102,7 +103,7 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont } @Test - void dependenciesIsAnAliasOfStyle() { + void dependencies() { ProjectStructure project = downloadZip("/starter.zip?dependencies=web&dependencies=jpa"); assertDefaultProject(project); assertHasWebResources(project); @@ -113,7 +114,7 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont } @Test - void dependenciesIsAnAliasOfStyleCommaSeparated() { + void dependenciesCommaSeparated() { ProjectStructure project = downloadZip("/starter.zip?dependencies=web,jpa"); assertDefaultProject(project); assertHasWebResources(project); @@ -170,6 +171,35 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont } } + @Test + void styleWithProjectZip() { + assertUsingStyleIsFailingForUrl("/starter.zip?dependencies=web&style=should-not-use"); + } + + @Test + void styleWithProjectTgz() { + assertUsingStyleIsFailingForUrl("/starter.tgz?dependencies=web&style=should-not-use"); + } + + @Test + void styleWithMavenBuild() { + assertUsingStyleIsFailingForUrl("/pom.xml?dependencies=web&style=should-not-use"); + } + + @Test + void styleWithGradleBuild() { + assertUsingStyleIsFailingForUrl("/build.gradle?dependencies=web&style=should-not-use"); + } + + private void assertUsingStyleIsFailingForUrl(String url) { + assertThatExceptionOfType(HttpClientErrorException.class) + .isThrownBy(() -> getRestTemplate().getForEntity(createUrl(url), byte[].class)).satisfies((ex) -> { + assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + assertStandardErrorBody(ex.getResponseBodyAsString(), + "Dependencies must be specified using 'dependencies'"); + }); + } + @Test void webIsAddedPom() { String body = getRestTemplate().getForObject(createUrl("/pom.xml?packaging=war"), String.class);