mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 17:48:14 +08:00
Polish "Remove support for style"
Closes gh-959
This commit is contained in:
@@ -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<R extends ProjectRequest> {
|
||||
this.projectGenerationInvoker = projectGenerationInvoker;
|
||||
}
|
||||
|
||||
@ModelAttribute
|
||||
R projectRequest(@RequestHeader Map<String, String> 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<String, String> headers);
|
||||
|
||||
protected InitializrMetadata getMetadata() {
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user