From 6bdb9c4c28be466154fc4bab0aa41b94dbd3179b Mon Sep 17 00:00:00 2001 From: Colin DAMON Date: Wed, 31 Aug 2022 18:13:24 +0200 Subject: [PATCH] Merge bean validation test in spring boot --- .../BeanValidationTestApplicationService.java | 20 --------- .../BeanValidationTestModuleFactory.java | 42 ------------------- ...BeanValidationTestModuleConfiguration.java | 25 ----------- .../domain/SpringBootCoreModuleFactory.java | 14 +++++++ .../DummyFeatureModuleConfiguration.java | 1 - .../BeanValidationAssertions.java.mustache | 0 .../BeanValidationTest.java.mustache | 0 .../features/bean-validation-test.feature | 7 ---- .../BeanValidationTestModuleFactoryTest.java | 40 ------------------ .../SpringBootCoreModuleFactoryTest.java | 11 +++++ tests-ci/generate.sh | 6 --- 11 files changed, 25 insertions(+), 141 deletions(-) delete mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/application/BeanValidationTestApplicationService.java delete mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/domain/BeanValidationTestModuleFactory.java delete mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/infrastructure/primary/BeanValidationTestModuleConfiguration.java rename src/main/resources/generator/server/springboot/{beanvalidationtest => core}/BeanValidationAssertions.java.mustache (100%) rename src/main/resources/generator/server/springboot/{beanvalidationtest => core}/BeanValidationTest.java.mustache (100%) delete mode 100644 src/test/features/bean-validation-test.feature delete mode 100644 src/test/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/domain/BeanValidationTestModuleFactoryTest.java diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/application/BeanValidationTestApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/application/BeanValidationTestApplicationService.java deleted file mode 100644 index 55527e4d9af..00000000000 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/application/BeanValidationTestApplicationService.java +++ /dev/null @@ -1,20 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.beanvalidationtest.application; - -import org.springframework.stereotype.Service; -import tech.jhipster.lite.generator.server.springboot.beanvalidationtest.domain.BeanValidationTestModuleFactory; -import tech.jhipster.lite.module.domain.JHipsterModule; -import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; - -@Service -public class BeanValidationTestApplicationService { - - private final BeanValidationTestModuleFactory factory; - - public BeanValidationTestApplicationService() { - factory = new BeanValidationTestModuleFactory(); - } - - public JHipsterModule buildModule(JHipsterModuleProperties properties) { - return factory.buildModule(properties); - } -} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/domain/BeanValidationTestModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/domain/BeanValidationTestModuleFactory.java deleted file mode 100644 index 4054471d615..00000000000 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/domain/BeanValidationTestModuleFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.beanvalidationtest.domain; - -import static tech.jhipster.lite.module.domain.JHipsterModule.*; - -import tech.jhipster.lite.error.domain.Assert; -import tech.jhipster.lite.module.domain.JHipsterModule; -import tech.jhipster.lite.module.domain.file.JHipsterSource; -import tech.jhipster.lite.module.domain.javadependency.JavaDependency; -import tech.jhipster.lite.module.domain.javadependency.JavaDependencyScope; -import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; - -public class BeanValidationTestModuleFactory { - - private static final JHipsterSource SOURCE = from("server/springboot/beanvalidationtest"); - - public JHipsterModule buildModule(JHipsterModuleProperties properties) { - Assert.notNull("properties", properties); - - //@formatter:off - return moduleBuilder(properties) - .javaDependencies() - .addDependency(reflectionsDependency()) - .and() - .files() - .batch(SOURCE, toSrcTestJava().append(properties.packagePath())) - .addTemplate("BeanValidationAssertions.java") - .addTemplate("BeanValidationTest.java") - .and() - .and() - .build(); - //@formatter:on - } - - private JavaDependency reflectionsDependency() { - return javaDependency() - .groupId("org.reflections") - .artifactId("reflections") - .versionSlug("reflections") - .scope(JavaDependencyScope.TEST) - .build(); - } -} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/infrastructure/primary/BeanValidationTestModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/infrastructure/primary/BeanValidationTestModuleConfiguration.java deleted file mode 100644 index 04bde843a71..00000000000 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/infrastructure/primary/BeanValidationTestModuleConfiguration.java +++ /dev/null @@ -1,25 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.beanvalidationtest.infrastructure.primary; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import tech.jhipster.lite.generator.server.springboot.beanvalidationtest.application.BeanValidationTestApplicationService; -import tech.jhipster.lite.module.domain.resource.JHipsterModuleApiDoc; -import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization; -import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition; -import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource; - -@Configuration -class BeanValidationTestModuleConfiguration { - - @Bean - JHipsterModuleResource beanValidationtTestModule(BeanValidationTestApplicationService beanValidationTest) { - return JHipsterModuleResource - .builder() - .slug("bean-validation-test") - .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addIndentation().build()) - .apiDoc(new JHipsterModuleApiDoc("Spring Boot - MVC", "Add test tools for bean validation")) - .organization(JHipsterModuleOrganization.SPRINGBOOT_DEPENDENCY) - .tags("server", "spring", "spring-boot", "validation") - .factory(beanValidationTest::buildModule); - } -} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactory.java index 914db5ca8f6..5dce3e7fbac 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactory.java @@ -57,6 +57,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) { .addDependency(springBootConfigurationProcessor()) .addDependency(groupId("org.apache.commons"), artifactId("commons-lang3")) .addDependency(springBootTest()) + .addDependency(reflectionsDependency()) .and() .javaBuildPlugins() .pluginManagement(springBootPluginManagement()) @@ -73,6 +74,10 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) { .add(SOURCE.template("logback.xml"), TEST_RESOURCES_DESTINATION.append("logback.xml")) .add(SOURCE.template("LogsSpy.java"), toSrcTestJava().append(properties.packagePath()).append("LogsSpy.java")) .add(SOURCE.template("ApplicationStartupTracesTest.java"), toSrcTestJava().append(packagePath).append("ApplicationStartupTracesTest.java")) + .batch(SOURCE, toSrcTestJava().append(properties.packagePath())) + .addTemplate("BeanValidationAssertions.java") + .addTemplate("BeanValidationTest.java") + .and() .and() .optionalReplacements() .in("pom.xml") @@ -107,6 +112,15 @@ private JavaDependency springBootTest() { .build(); } + private JavaDependency reflectionsDependency() { + return javaDependency() + .groupId("org.reflections") + .artifactId("reflections") + .versionSlug("reflections") + .scope(JavaDependencyScope.TEST) + .build(); + } + private JavaBuildPlugin springBootPluginManagement() { return JavaBuildPlugin .builder() diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/feature/infrastructure/primary/DummyFeatureModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/feature/infrastructure/primary/DummyFeatureModuleConfiguration.java index 92bb1c3df1f..0ba21d923d9 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/feature/infrastructure/primary/DummyFeatureModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/feature/infrastructure/primary/DummyFeatureModuleConfiguration.java @@ -25,7 +25,6 @@ JHipsterModuleResource dummyFeatureModule(DummyApplicationService dummy) { .addFeatureDependency("web-error-management") .addFeatureDependency("springdoc") .addModuleDependency("java-base") - .addModuleDependency("bean-validation-test") .build() ) .tags("server") diff --git a/src/main/resources/generator/server/springboot/beanvalidationtest/BeanValidationAssertions.java.mustache b/src/main/resources/generator/server/springboot/core/BeanValidationAssertions.java.mustache similarity index 100% rename from src/main/resources/generator/server/springboot/beanvalidationtest/BeanValidationAssertions.java.mustache rename to src/main/resources/generator/server/springboot/core/BeanValidationAssertions.java.mustache diff --git a/src/main/resources/generator/server/springboot/beanvalidationtest/BeanValidationTest.java.mustache b/src/main/resources/generator/server/springboot/core/BeanValidationTest.java.mustache similarity index 100% rename from src/main/resources/generator/server/springboot/beanvalidationtest/BeanValidationTest.java.mustache rename to src/main/resources/generator/server/springboot/core/BeanValidationTest.java.mustache diff --git a/src/test/features/bean-validation-test.feature b/src/test/features/bean-validation-test.feature deleted file mode 100644 index 6d3caf381d4..00000000000 --- a/src/test/features/bean-validation-test.feature +++ /dev/null @@ -1,7 +0,0 @@ -Feature: Bean validation test - - Scenario: Should apply bean validation test module - When I apply "bean-validation-test" module to default project with maven file - | packageName | tech.jhipster.chips | - Then I should have files in "src/test/java/tech/jhipster/chips" - | BeanValidationAssertions.java | diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/domain/BeanValidationTestModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/domain/BeanValidationTestModuleFactoryTest.java deleted file mode 100644 index 6ed7e40377a..00000000000 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/beanvalidationtest/domain/BeanValidationTestModuleFactoryTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.beanvalidationtest.domain; - -import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*; - -import org.junit.jupiter.api.Test; -import tech.jhipster.lite.TestFileUtils; -import tech.jhipster.lite.UnitTest; -import tech.jhipster.lite.module.domain.JHipsterModule; -import tech.jhipster.lite.module.domain.JHipsterModulesFixture; -import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; - -@UnitTest -class BeanValidationTestModuleFactoryTest { - - private static final BeanValidationTestModuleFactory factory = new BeanValidationTestModuleFactory(); - - @Test - void shouldBuildModule() { - JHipsterModuleProperties properties = JHipsterModulesFixture - .propertiesBuilder(TestFileUtils.tmpDirForTest()) - .basePackage("com.jhipster.test") - .build(); - - JHipsterModule module = factory.buildModule(properties); - - assertThatModuleWithFiles(module, pomFile()) - .createPrefixedFiles("src/test/java/com/jhipster/test", "BeanValidationAssertions.java", "BeanValidationTest.java") - .createFile("pom.xml") - .containing( - """ - - org.reflections - reflections - ${reflections.version} - test - - """ - ); - } -} diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactoryTest.java index 3128ee1e16d..facf718fc38 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactoryTest.java @@ -67,6 +67,16 @@ void shouldBuildModuleOnProjectWithoutDefaultGoal() { """ ) + .containing( + """ + + org.reflections + reflections + ${reflections.version} + test + + """ + ) .containing( """ @@ -146,6 +156,7 @@ void shouldBuildModuleOnProjectWithoutDefaultGoal() { "src/main/resources/config/application-local.properties", "src/test/resources/config/application.properties" ) + .createPrefixedFiles("src/test/java/com/jhipster/test", "BeanValidationAssertions.java", "BeanValidationTest.java") .createFiles("src/test/resources/logback.xml", "src/main/resources/logback-spring.xml") .createFiles("documentation/logs-spy.md") .createJavaTests("com/jhipster/test/LogsSpy.java"); diff --git a/tests-ci/generate.sh b/tests-ci/generate.sh index ca76e09520d..d34d1307caf 100755 --- a/tests-ci/generate.sh +++ b/tests-ci/generate.sh @@ -120,7 +120,6 @@ elif [[ $application == 'fullapp' ]]; then applyModules "postgresql" "liquibase" applyModules \ - "bean-validation-test" \ "dummy-feature" \ "dummy-jpa-persistence" \ "dummy-liquibase-changelog" \ @@ -142,7 +141,6 @@ elif [[ $application == 'oauth2app' ]]; then applyModules \ "spring-boot-cucumber" \ "spring-boot-cucumber-oauth2-authentication" \ - "bean-validation-test" \ "dummy-feature" elif [[ $application == 'mysqlapp' ]]; then @@ -156,7 +154,6 @@ elif [[ $application == 'mysqlapp' ]]; then applyModules "spring-boot-cucumber-jpa-reset" applyModules \ - "bean-validation-test" \ "dummy-feature" \ "dummy-jpa-persistence" \ "dummy-liquibase-changelog" \ @@ -189,7 +186,6 @@ elif [[ $application == 'flywayapp' ]]; then applyModules "spring-boot-cucumber-jpa-reset" applyModules \ - "bean-validation-test" \ "dummy-feature" \ "dummy-jpa-persistence" \ "dummy-postgresql-flyway-changelog" \ @@ -207,7 +203,6 @@ elif [[ $application == 'undertowapp' ]]; then applyModules "spring-boot-cucumber-jpa-reset" applyModules \ - "bean-validation-test" \ "dummy-feature" \ "dummy-jpa-persistence" \ "dummy-not-postgresql-flyway-changelog" \ @@ -247,7 +242,6 @@ elif [[ $application == 'mongodbapp' ]]; then cucumber_with_jwt applyModules \ - "bean-validation-test" \ "dummy-feature" \ "dummy-mongodb-persistence"