Skip to content

Commit

Permalink
Merge pull request #9607 from murdos/feature/approvals-testing
Browse files Browse the repository at this point in the history
Module: Approval testing using ApprovalTests
  • Loading branch information
murdos authored Apr 26, 2024
2 parents 162806d + b06679d commit 3266169
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@tech.jhipster.lite.BusinessContext
package tech.jhipster.lite.generator.server.javatool.approvaltesting;
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/generator/dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions src/test/features/server/javatool/approval-testing.feature
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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>
"""
);
}
}
1 change: 1 addition & 0 deletions tests-ci/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ spring_boot() {
"github-actions-${java_build_tool}" \
"java-base" \
"checkstyle" \
"approval-tests" \
"jqwik" \
"protobuf" \
"protobuf-backwards-compatibility-check" \
Expand Down

0 comments on commit 3266169

Please sign in to comment.