Skip to content

Commit

Permalink
Add spring-mvc-server feature so springdoc-mvc-openapi can depend on it
Browse files Browse the repository at this point in the history
Fixes #4153
  • Loading branch information
murdos committed Jan 4, 2023
1 parent dcbabf0 commit 38a7644
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum JHLiteFeatureSlug implements JHipsterFeatureSlugFactory {
OAUTH_PROVIDER_SPRINGDOC("oauth-provider-springdoc"),
SERVICE_DISCOVERY("service-discovery"),
SPRING_SERVER("spring-server"),
SPRING_MVC_SERVER("spring-mvc-server"),
SPRINGDOC("springdoc");

private final String slug;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
SPRING_BOOT_OAUTH_2_AUTH_0("spring-boot-oauth2-auth0"),
SPRING_BOOT_OAUTH_2_OKTA("spring-boot-oauth2-okta"),
SPRING_BOOT_PULSAR("spring-boot-pulsar"),
SPRING_BOOT_MVC("spring-boot-mvc"),
SPRING_BOOT_TOMCAT("spring-boot-tomcat"),
SPRING_BOOT_UNDERTOW("spring-boot-undertow"),
SPRING_BOOT_WEBFLUX("spring-boot-webflux"),
SPRING_BOOT_WEBFLUX_NETTY("spring-boot-webflux-netty"),
SPRING_CLOUD("spring-cloud"),
SPRINGDOC_JWT("springdoc-jwt"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ JHipsterModuleResource springdocMvcModule(SpringdocApplicationService springdocA
.slug(SPRINGDOC_MVC_OPENAPI)
.propertiesDefinition(buildPropertiesDefinition())
.apiDoc(API_GROUP, "Add springdoc-openapi for spring MVC")
.organization(JHipsterModuleOrganization.builder().feature(SPRINGDOC).addDependency(SPRING_BOOT_TOMCAT).build())
.organization(JHipsterModuleOrganization.builder().feature(SPRINGDOC).addDependency(SPRING_MVC_SERVER).build())
.tags(SERVER_TAG, SPRING_TAG, SPRING_BOOT_TAG, DOCUMENTATION_TAG, SWAGGER_TAG)
.factory(springdocApplicationService::buildSpringdocMvcModule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public JHipsterModule buildTomcatModule(JHipsterModuleProperties properties) {
public JHipsterModule buildUndertowModule(JHipsterModuleProperties properties) {
return factory.buildUndertowModule(properties);
}

public JHipsterModule buildEmptyModule(JHipsterModuleProperties properties) {
return factory.buildEmptyModule(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class SpringBootMvcsModulesFactory {

private static final String CORS_PRIMARY = "security/infrastructure/primary";

public JHipsterModule buildEmptyModule(JHipsterModuleProperties properties) {
return moduleBuilder(properties).build();
}

public JHipsterModule buildTomcatModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@
@Configuration
class SpringBootMvcModulesConfiguration {

private static final String SERVER_TAG = "server";
private static final String SPRING_BOOT_TAG = "spring-boot";
private static final String SPRING_TAG = "spring";
private static final String MVC_TAG = "mvc";
private static final String WEB_TAG = "web";

@Bean
JHipsterModuleResource springBootMvcModule(SpringBootMvcApplicationService springBootMvc) {
return JHipsterModuleResource
.builder()
.slug(SPRING_BOOT_MVC)
.propertiesDefinition(properties())
.apiDoc("Spring Boot MVC", "Add Spring Boot MVC")
.organization(JHipsterModuleOrganization.builder().feature(SPRING_SERVER).addDependency(SPRING_BOOT).build())
.tags(SERVER_TAG, SPRING_TAG, SPRING_BOOT_TAG, MVC_TAG, WEB_TAG)
.factory(springBootMvc::buildEmptyModule);
}

@Bean
JHipsterModuleResource springBootTomcatMvcModule(SpringBootMvcApplicationService springBootMvc) {
Expand All @@ -22,8 +38,8 @@ JHipsterModuleResource springBootTomcatMvcModule(SpringBootMvcApplicationService
.slug(SPRING_BOOT_TOMCAT)
.propertiesDefinition(properties())
.apiDoc("Spring Boot - MVC", "Add Spring Boot MVC with Tomcat")
.organization(organization())
.tags("server", "spring", SPRING_BOOT_TAG, "mvc", "web", "tomcat")
.organization(mvcServerOrganization())
.tags(SERVER_TAG, SPRING_TAG, SPRING_BOOT_TAG, MVC_TAG, WEB_TAG, "tomcat")
.factory(springBootMvc::buildTomcatModule);
}

Expand All @@ -34,16 +50,16 @@ JHipsterModuleResource springBootUndertowMvcModule(SpringBootMvcApplicationServi
.slug(SPRING_BOOT_UNDERTOW)
.propertiesDefinition(properties())
.apiDoc("Spring Boot - MVC", "Add Spring Boot MVC with Undertow")
.organization(organization())
.tags("server", "spring", SPRING_BOOT_TAG, "mvc", "web", "undertow")
.organization(mvcServerOrganization())
.tags(SERVER_TAG, SPRING_TAG, SPRING_BOOT_TAG, MVC_TAG, WEB_TAG, "undertow")
.factory(springBootMvc::buildUndertowModule);
}

private JHipsterModulePropertiesDefinition properties() {
return JHipsterModulePropertiesDefinition.builder().addBasePackage().addIndentation().addServerPort().build();
}

private JHipsterModuleOrganization organization() {
return JHipsterModuleOrganization.builder().feature(SPRING_SERVER).addDependency(SPRING_BOOT).build();
private JHipsterModuleOrganization mvcServerOrganization() {
return JHipsterModuleOrganization.builder().feature(SPRING_MVC_SERVER).addDependency(SPRING_BOOT_MVC).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public SpringBootWebfluxApplicationService() {
factory = new SpringBootWebfluxModuleFactory();
}

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return factory.buildModule(properties);
public JHipsterModule buildNettyModule(JHipsterModuleProperties properties) {
return factory.buildNettyModule(properties);
}

public JHipsterModule buildEmptyModule(JHipsterModuleProperties properties) {
return factory.buildEmptyModule(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public class SpringBootWebfluxModuleFactory {

private static final String EXCEPTION_PRIMARY = "technical/infrastructure/primary/exception";

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
public JHipsterModule buildEmptyModule(JHipsterModuleProperties properties) {
return moduleBuilder(properties).build();
}

public JHipsterModule buildNettyModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

String packagePath = properties.packagePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,29 @@ class SpringBootWebfluxModuleConfiguration {

@Bean
JHipsterModuleResource springBootWebfluxModule(SpringBootWebfluxApplicationService webflux) {
return JHipsterModuleResource
.builder()
.slug(SPRING_BOOT_WEBFLUX)
.propertiesDefinition(properties())
.apiDoc("Spring Boot - Webflux", "Add Spring Boot Webflux")
.organization(JHipsterModuleOrganization.builder().feature(SPRING_SERVER).addDependency(SPRING_BOOT).build())
.tags("server", "webflux")
.factory(webflux::buildEmptyModule);
}

@Bean
JHipsterModuleResource springBootWebfluxNettyModule(SpringBootWebfluxApplicationService webflux) {
return JHipsterModuleResource
.builder()
.slug(SPRING_BOOT_WEBFLUX_NETTY)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addIndentation().addServerPort().build())
.propertiesDefinition(properties())
.apiDoc("Spring Boot - Webflux", "Add Spring Boot Webflux with Netty")
.organization(JHipsterModuleOrganization.builder().feature(SPRING_SERVER).addDependency(SPRING_BOOT).build())
.organization(JHipsterModuleOrganization.builder().addDependency(SPRING_BOOT_WEBFLUX).build())
.tags("server", "webflux")
.factory(webflux::buildModule);
.factory(webflux::buildNettyModule);
}

private static JHipsterModulePropertiesDefinition properties() {
return JHipsterModulePropertiesDefinition.builder().addBasePackage().addIndentation().addServerPort().build();
}
}
14 changes: 10 additions & 4 deletions src/test/features/spring-mvc.feature
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
Feature: Spring MVC

Scenario: Should apply spring mvc tomcat module
When I apply "spring-boot-tomcat" module to default project with maven file
| packageName | tech.jhipster.chips |
When I apply modules to default project
| maven-java |
| spring-boot |
| spring-boot-mvc |
| spring-boot-tomcat |
Then I should have "<artifactId>spring-boot-starter-web</artifactId>" in "pom.xml"

Scenario: Should apply spring mvc undertow module
When I apply "spring-boot-undertow" module to default project with maven file
| packageName | tech.jhipster.chips |
When I apply modules to default project
| maven-java |
| spring-boot |
| spring-boot-mvc |
| spring-boot-undertow |
Then I should have "<artifactId>spring-boot-starter-undertow</artifactId>" in "pom.xml"
9 changes: 6 additions & 3 deletions src/test/features/webflux.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
Feature: Webflux module

Scenario: Should apply webflux module
When I apply "spring-boot-webflux-netty" module to default project with maven file
| packageName | tech.jhipster.chips |
| serverPort | 9000 |
When I apply modules to default project
| maven-java |
| spring-boot |
| spring-boot-webflux |
| spring-boot-webflux-netty |
Then I should have "<artifactId>spring-boot-starter-webflux</artifactId>" in "pom.xml"
Then I should have files in "src/main/java/tech/jhipster/chips/technical/infrastructure/primary/exception/"
| FieldErrorDTO.java |
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class SpringBootWebfluxModuleFactoryTest {
private static final SpringBootWebfluxModuleFactory factory = new SpringBootWebfluxModuleFactory();

@Test
void shouldBuildModule() {
void shouldBuildWebfluxNettyModule() {
JHipsterModuleProperties properties = JHipsterModulesFixture
.propertiesBuilder(TestFileUtils.tmpDirForTest())
.basePackage("com.jhipster.test")
.put("serverPort", 9000)
.build();

JHipsterModule module = factory.buildModule(properties);
JHipsterModule module = factory.buildNettyModule(properties);

assertThatModuleWithFiles(module, pomFile())
.hasFile("pom.xml")
Expand Down

0 comments on commit 38a7644

Please sign in to comment.