Repository: jhipster/jhipster-lite
Pull request #9607 (2024-04-22 19:20:53)

Module: Approval testing using ApprovalTests


Patch:
diff --git a/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java b/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java
index 471bbdb58..bcef8b0d0 100644
--- a/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java
+++ b/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java
@@ -13,6 +13,7 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
   ANGULAR_JWT("angular-jwt"),
   ANGULAR_OAUTH_2("angular-oauth2"),
   APPLICATION_SERVICE_HEXAGONAL_ARCHITECTURE_DOCUMENTATION("application-service-hexagonal-architecture-documentation"),
+  APPROVAL_TESTS("approval-tests"),
   BANNER_JHIPSTER_V2("banner-jhipster-v2"),
   BANNER_JHIPSTER_V3("banner-jhipster-v3"),
   BANNER_JHIPSTER_V7("banner-jhipster-v7"),
diff --git a/src/main/resources/generator/dependencies/pom.xml b/src/main/resources/generator/dependencies/pom.xml
index 398b81655..430aa9890 100644
--- a/src/main/resources/generator/dependencies/pom.xml
+++ b/src/main/resources/generator/dependencies/pom.xml
@@ -44,6 +44,7 @@
     <testcontainers.version>1.19.7</testcontainers.version>
     <archunit-junit5.version>1.3.0</archunit-junit5.version>
     <cucumber.version>7.17.0</cucumber.version>
+    <approvaltests.version>22.3.3</approvaltests.version>
     <jqwik.version>1.8.3</jqwik.version>
     <!-- Maven Plugins -->
     <os-maven-plugin.version>1.7.1</os-maven-plugin.version>
@@ -337,6 +338,12 @@
         <artifactId>pulsar-client</artifactId>
         <version>${pulsar.version}</version>
       </dependency>
+      <dependency>
+        <groupId>com.approvaltests</groupId>
+        <artifactId>approvaltests</artifactId>
+        <version>${approvaltests.version}</version>
+        <scope>test</scope>
+      </dependency>
       <dependency>
         <groupId>net.jqwik</groupId>
         <artifactId>jqwik</artifactId>


Test patch:
diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/application/ApprovalTestingApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/application/ApprovalTestingApplicationService.java
new file mode 100644
index 000000000..ecb1bd8ad
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/application/ApprovalTestingApplicationService.java
@@ -0,0 +1,20 @@
+package tech.jhipster.lite.generator.server.javatool.approvaltesting.application;
+
+import org.springframework.stereotype.Service;
+import tech.jhipster.lite.generator.server.javatool.approvaltesting.domain.ApprovalTestingModuleFactory;
+import tech.jhipster.lite.module.domain.JHipsterModule;
+import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
+
+@Service
+public class ApprovalTestingApplicationService {
+
+  private final ApprovalTestingModuleFactory approvalTesting;
+
+  public ApprovalTestingApplicationService() {
+    approvalTesting = new ApprovalTestingModuleFactory();
+  }
+
+  public JHipsterModule build(JHipsterModuleProperties properties) {
+    return approvalTesting.build(properties);
+  }
+}
diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/domain/ApprovalTestingModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/domain/ApprovalTestingModuleFactory.java
new file mode 100644
index 000000000..46d6f0b65
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/domain/ApprovalTestingModuleFactory.java
@@ -0,0 +1,22 @@
+package tech.jhipster.lite.generator.server.javatool.approvaltesting.domain;
+
+import static tech.jhipster.lite.module.domain.JHipsterModule.*;
+
+import tech.jhipster.lite.module.domain.JHipsterModule;
+import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
+import tech.jhipster.lite.shared.error.domain.Assert;
+
+public class ApprovalTestingModuleFactory {
+
+  public JHipsterModule build(JHipsterModuleProperties properties) {
+    Assert.notNull("properties", properties);
+
+    //@formatter:off
+    return moduleBuilder(properties)
+      .javaDependencies()
+        .addTestDependency(groupId("com.approvaltests"), artifactId("approvaltests"), versionSlug("approvaltests"))
+        .and()
+      .build();
+    //@formatter:on
+  }
+}
diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/infrastructure/primary/AdvancedTestingModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/infrastructure/primary/AdvancedTestingModuleConfiguration.java
new file mode 100644
index 000000000..95f677326
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/infrastructure/primary/AdvancedTestingModuleConfiguration.java
@@ -0,0 +1,25 @@
+package tech.jhipster.lite.generator.server.javatool.approvaltesting.infrastructure.primary;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import tech.jhipster.lite.generator.server.javatool.approvaltesting.application.ApprovalTestingApplicationService;
+import tech.jhipster.lite.generator.slug.domain.JHLiteFeatureSlug;
+import tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug;
+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 AdvancedTestingModuleConfiguration {
+
+  @Bean
+  JHipsterModuleResource approvalTestsModule(ApprovalTestingApplicationService approvalTesting) {
+    return JHipsterModuleResource.builder()
+      .slug(JHLiteModuleSlug.APPROVAL_TESTS)
+      .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().build())
+      .apiDoc("Advanced testing", "Add ApprovalTests library for Approval testing")
+      .organization(JHipsterModuleOrganization.builder().addDependency(JHLiteFeatureSlug.JAVA_BUILD_TOOL).build())
+      .tags("server", "testing")
+      .factory(approvalTesting::build);
+  }
+}
diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/package-info.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/package-info.java
new file mode 100644
index 000000000..d8a7325a8
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/package-info.java
@@ -0,0 +1,2 @@
+@tech.jhipster.lite.BusinessContext
+package tech.jhipster.lite.generator.server.javatool.approvaltesting;
diff --git a/src/test/features/server/javatool/approval-testing.feature b/src/test/features/server/javatool/approval-testing.feature
new file mode 100644
index 000000000..f4433893c
--- /dev/null
+++ b/src/test/features/server/javatool/approval-testing.feature
@@ -0,0 +1,6 @@
+Feature: Approval testing module
+
+  Scenario: Should apply approval-tests module in maven project
+    When I apply "approval-tests" module to default project with maven file
+      | packageName | tech.jhipster.chips |
+    Then I should have "<artifactId>approvaltests</artifactId>" in "pom.xml"
diff --git a/src/test/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/domain/ApprovalTestingModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/domain/ApprovalTestingModuleFactoryTest.java
new file mode 100644
index 000000000..6d0018ce2
--- /dev/null
+++ b/src/test/java/tech/jhipster/lite/generator/server/javatool/approvaltesting/domain/ApprovalTestingModuleFactoryTest.java
@@ -0,0 +1,36 @@
+package tech.jhipster.lite.generator.server.javatool.approvaltesting.domain;
+
+import static tech.jhipster.lite.TestFileUtils.*;
+import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*;
+
+import org.junit.jupiter.api.Test;
+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 ApprovalTestingModuleFactoryTest {
+
+  private final ApprovalTestingModuleFactory factory = new ApprovalTestingModuleFactory();
+
+  @Test
+  void shouldBuildApprovalTestsModule() {
+    JHipsterModuleProperties properties = JHipsterModulesFixture.propertiesBuilder(tmpDirForTest()).build();
+
+    JHipsterModule module = factory.build(properties);
+
+    assertThatModuleWithFiles(module, pomFile())
+      .hasFile("pom.xml")
+      .containing(
+        """
+            <dependency>
+              <groupId>com.approvaltests</groupId>
+              <artifactId>approvaltests</artifactId>
+              <version>${approvaltests.version}</version>
+              <scope>test</scope>
+            </dependency>
+        """
+      );
+  }
+}
diff --git a/tests-ci/generate.sh b/tests-ci/generate.sh
index 83e32140e..8cbfb8b41 100755
--- a/tests-ci/generate.sh
+++ b/tests-ci/generate.sh
@@ -58,6 +58,7 @@ spring_boot() {
   "github-actions-${java_build_tool}" \
   "java-base" \
   "checkstyle" \
+  "approval-tests" \
   "jqwik" \
   "protobuf" \
   "protobuf-backwards-compatibility-check" \