From 762879faed5472a6e4b9971d772bf1c9381308d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Nov 2025 23:07:11 +0000 Subject: [PATCH 1/2] chore: [DevOps] bump the production-minor-patch group with 10 updates Bumps the production-minor-patch group with 10 updates: | Package | From | To | | --- | --- | --- | | [org.openapitools:openapi-generator](https://github.com/openapitools/openapi-generator) | `7.16.0` | `7.17.0` | | [com.fasterxml.jackson.core:jackson-core](https://github.com/FasterXML/jackson-core) | `2.20.0` | `2.20.1` | | [com.fasterxml.jackson.core:jackson-databind](https://github.com/FasterXML/jackson) | `2.20.0` | `2.20.1` | | [com.fasterxml.jackson.dataformat:jackson-dataformat-xml](https://github.com/FasterXML/jackson-dataformat-xml) | `2.20.0` | `2.20.1` | | [com.fasterxml.jackson.dataformat:jackson-dataformat-yaml](https://github.com/FasterXML/jackson-dataformats-text) | `2.20.0` | `2.20.1` | | [com.fasterxml.jackson.datatype:jackson-datatype-guava](https://github.com/FasterXML/jackson-datatypes-collections) | `2.20.0` | `2.20.1` | | [com.fasterxml.jackson.datatype:jackson-datatype-joda](https://github.com/FasterXML/jackson-datatype-joda) | `2.20.0` | `2.20.1` | | [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit-framework) | `6.0.0` | `6.0.1` | | [org.junit.jupiter:junit-jupiter-params](https://github.com/junit-team/junit-framework) | `6.0.0` | `6.0.1` | | org.apache.maven.plugin-testing:maven-plugin-testing-harness | `3.3.0` | `3.4.0` | Updates `org.openapitools:openapi-generator` from 7.16.0 to 7.17.0 - [Release notes](https://github.com/openapitools/openapi-generator/releases) - [Changelog](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/3.0.0-release-note.md) - [Commits](https://github.com/openapitools/openapi-generator/compare/v7.16.0...v7.17.0) Updates `com.fasterxml.jackson.core:jackson-core` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson-core/compare/jackson-core-2.20.0...jackson-core-2.20.1) Updates `com.fasterxml.jackson.core:jackson-databind` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson/commits) Updates `com.fasterxml.jackson.dataformat:jackson-dataformat-xml` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson-dataformat-xml/compare/jackson-dataformat-xml-2.20.0...jackson-dataformat-xml-2.20.1) Updates `com.fasterxml.jackson.dataformat:jackson-dataformat-yaml` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson-dataformats-text/compare/jackson-dataformats-text-2.20.0...jackson-dataformats-text-2.20.1) Updates `com.fasterxml.jackson.datatype:jackson-datatype-guava` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson-datatypes-collections/compare/jackson-datatypes-collections-2.20.0...jackson-datatypes-collections-2.20.1) Updates `com.fasterxml.jackson.datatype:jackson-datatype-joda` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson-datatype-joda/compare/jackson-datatype-joda-2.20.0...jackson-datatype-joda-2.20.1) Updates `com.fasterxml.jackson.core:jackson-databind` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson/commits) Updates `com.fasterxml.jackson.dataformat:jackson-dataformat-xml` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson-dataformat-xml/compare/jackson-dataformat-xml-2.20.0...jackson-dataformat-xml-2.20.1) Updates `com.fasterxml.jackson.dataformat:jackson-dataformat-yaml` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson-dataformats-text/compare/jackson-dataformats-text-2.20.0...jackson-dataformats-text-2.20.1) Updates `com.fasterxml.jackson.datatype:jackson-datatype-guava` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson-datatypes-collections/compare/jackson-datatypes-collections-2.20.0...jackson-datatypes-collections-2.20.1) Updates `com.fasterxml.jackson.datatype:jackson-datatype-joda` from 2.20.0 to 2.20.1 - [Commits](https://github.com/FasterXML/jackson-datatype-joda/compare/jackson-datatype-joda-2.20.0...jackson-datatype-joda-2.20.1) Updates `org.junit.jupiter:junit-jupiter-api` from 6.0.0 to 6.0.1 - [Release notes](https://github.com/junit-team/junit-framework/releases) - [Commits](https://github.com/junit-team/junit-framework/compare/r6.0.0...r6.0.1) Updates `org.junit.jupiter:junit-jupiter-params` from 6.0.0 to 6.0.1 - [Release notes](https://github.com/junit-team/junit-framework/releases) - [Commits](https://github.com/junit-team/junit-framework/compare/r6.0.0...r6.0.1) Updates `org.junit.jupiter:junit-jupiter-params` from 6.0.0 to 6.0.1 - [Release notes](https://github.com/junit-team/junit-framework/releases) - [Commits](https://github.com/junit-team/junit-framework/compare/r6.0.0...r6.0.1) Updates `org.apache.maven.plugin-testing:maven-plugin-testing-harness` from 3.3.0 to 3.4.0 --- updated-dependencies: - dependency-name: org.openapitools:openapi-generator dependency-version: 7.17.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.core:jackson-core dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.dataformat:jackson-dataformat-xml dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.datatype:jackson-datatype-guava dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.datatype:jackson-datatype-joda dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.dataformat:jackson-dataformat-xml dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.datatype:jackson-datatype-guava dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: com.fasterxml.jackson.datatype:jackson-datatype-joda dependency-version: 2.20.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-version: 6.0.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: org.junit.jupiter:junit-jupiter-params dependency-version: 6.0.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: org.junit.jupiter:junit-jupiter-params dependency-version: 6.0.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch - dependency-name: org.apache.maven.plugin-testing:maven-plugin-testing-harness dependency-version: 3.4.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: production-minor-patch ... Signed-off-by: dependabot[bot] --- dependency-bundles/bom/pom.xml | 2 +- pom.xml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dependency-bundles/bom/pom.xml b/dependency-bundles/bom/pom.xml index 1dc57e4bd..902614d67 100644 --- a/dependency-bundles/bom/pom.xml +++ b/dependency-bundles/bom/pom.xml @@ -77,7 +77,7 @@ 2.3.0 2.13.2 - 2.20.0 + 2.20.1 2.20 1.2.3 diff --git a/pom.xml b/pom.xml index 382ccb2d4..14b7dd6ec 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ **/testclasses/** 4.87.9 - 2.20.0 + 2.20.1 2.20 20250517 @@ -105,15 +105,15 @@ 0.4.3 5.20.0 1.5.3 - 6.0.0 + 6.0.1 2.6 5.0.0 2.0.13 3.9.11 3.15.2 - 3.3.0 + 3.4.0 3.2.3 - 7.16.0 + 7.17.0 2.2.40 2.1.35 1.6.11 From e712a46ce73cd205f7791d91e319a5e27d451f05 Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Thu, 6 Nov 2025 14:32:01 +0100 Subject: [PATCH 2/2] Replace workaround pom parsed mojo loading with latest @MojoTest. --- .../odata-v4-generator-maven-plugin/pom.xml | 6 -- .../generator/DataModelGeneratorMojoTest.java | 40 ++------ .../odata-generator-maven-plugin/pom.xml | 6 -- .../generator/DataModelGeneratorMojoTest.java | 41 ++------ .../openapi-generator-maven-plugin/pom.xml | 7 -- ...DataModelGeneratorMojoIntegrationTest.java | 53 +++------- .../DataModelGeneratorMojoUnitTest.java | 96 +++++++------------ 7 files changed, 66 insertions(+), 183 deletions(-) diff --git a/datamodel/odata-v4/odata-v4-generator-maven-plugin/pom.xml b/datamodel/odata-v4/odata-v4-generator-maven-plugin/pom.xml index c02f3ef16..fd969cb4f 100644 --- a/datamodel/odata-v4/odata-v4-generator-maven-plugin/pom.xml +++ b/datamodel/odata-v4/odata-v4-generator-maven-plugin/pom.xml @@ -68,12 +68,6 @@ junit-jupiter-api test - - junit - junit - 4.13.2 - test - org.assertj assertj-core diff --git a/datamodel/odata-v4/odata-v4-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/odatav4/generator/DataModelGeneratorMojoTest.java b/datamodel/odata-v4/odata-v4-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/odatav4/generator/DataModelGeneratorMojoTest.java index 0bb355589..f15be6ab9 100644 --- a/datamodel/odata-v4/odata-v4-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/odatav4/generator/DataModelGeneratorMojoTest.java +++ b/datamodel/odata-v4/odata-v4-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/odatav4/generator/DataModelGeneratorMojoTest.java @@ -1,27 +1,25 @@ package com.sap.cloud.sdk.datamodel.odatav4.generator; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import java.io.File; -import java.net.URL; - -import org.apache.maven.plugin.testing.MojoRule; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; import org.junit.jupiter.api.Test; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; import com.sap.cloud.sdk.datamodel.odata.utility.NameSource; import com.sap.cloud.sdk.datamodel.odata.utility.S4HanaNamingStrategy; import com.sap.cloud.sdk.datamodel.odatav4.generator.annotation.DefaultAnnotationStrategy; +@MojoTest class DataModelGeneratorMojoTest { + private static final String TEST_POM = "src/test/resources/DataModelGeneratorMojoTest/pom.xml"; + @Test - void test() + @InjectMojo( goal = "generate", pom = TEST_POM ) + void test( DataModelGeneratorMojo mojo ) throws Throwable { - final DataModelGeneratorMojo mojo = loadTestProject(); final DataModelGenerator generator = mojo.getDataModelGenerator(); assertSoftly(softly -> { @@ -51,28 +49,4 @@ void test() softly.assertThat(generator.isServiceMethodsPerEntitySet()).isTrue(); }); } - - private DataModelGeneratorMojo loadTestProject() - throws Throwable - { - final URL resource = getClass().getClassLoader().getResource(getClass().getSimpleName()); - assertThat(resource).isNotNull(); - - final File pomFile = new File(resource.getFile()); - - final MojoRule rule = new MojoRule(); - // hacky workaround to invoke the internal call to "testCase.setUp()" inside MojoRule - // exploiting the fact that the setup is not teared down after "evaluate" returns - // this workaround is applied because "lookupConfiguredMojo" is not available on AbstractMojoTestCase - // and this way we can skip the effort to re-implement what is already available in MojoRule - rule.apply(new Statement() - { - @Override - public void evaluate() - { - - } - }, Description.createSuiteDescription("dummy")).evaluate(); - return (DataModelGeneratorMojo) rule.lookupConfiguredMojo(pomFile, "generate"); - } } diff --git a/datamodel/odata/odata-generator-maven-plugin/pom.xml b/datamodel/odata/odata-generator-maven-plugin/pom.xml index 92946d733..a1bb85de1 100644 --- a/datamodel/odata/odata-generator-maven-plugin/pom.xml +++ b/datamodel/odata/odata-generator-maven-plugin/pom.xml @@ -69,12 +69,6 @@ test - - junit - junit - 4.13.2 - test - org.assertj assertj-core diff --git a/datamodel/odata/odata-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/odata/generator/DataModelGeneratorMojoTest.java b/datamodel/odata/odata-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/odata/generator/DataModelGeneratorMojoTest.java index 354275c52..8811244b0 100644 --- a/datamodel/odata/odata-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/odata/generator/DataModelGeneratorMojoTest.java +++ b/datamodel/odata/odata-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/odata/generator/DataModelGeneratorMojoTest.java @@ -1,27 +1,24 @@ package com.sap.cloud.sdk.datamodel.odata.generator; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import java.io.File; -import java.net.URL; - -import org.apache.maven.plugin.testing.MojoRule; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; import org.junit.jupiter.api.Test; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; import com.sap.cloud.sdk.datamodel.odata.generator.annotation.DefaultAnnotationStrategy; import com.sap.cloud.sdk.datamodel.odata.utility.NameSource; import com.sap.cloud.sdk.datamodel.odata.utility.S4HanaNamingStrategy; +@MojoTest class DataModelGeneratorMojoTest { + private static final String TEST_POM = "src/test/resources/DataModelGeneratorMojoTest/pom.xml"; + @Test - void test() - throws Throwable + @InjectMojo( goal = "generate", pom = TEST_POM ) + void test( DataModelGeneratorMojo mojo ) { - final DataModelGeneratorMojo mojo = loadTestProject(); final DataModelGenerator generator = mojo.getDataModelGenerator(); assertSoftly(softly -> { @@ -51,28 +48,4 @@ void test() softly.assertThat(generator.isServiceMethodsPerEntitySet()).isTrue(); }); } - - private DataModelGeneratorMojo loadTestProject() - throws Throwable - { - final URL resource = getClass().getClassLoader().getResource(getClass().getSimpleName()); - assertThat(resource).isNotNull(); - - final File pomFile = new File(resource.getFile()); - - final MojoRule rule = new MojoRule(); - // hacky workaround to invoke the internal call to "testCase.setUp()" inside MojoRule - // exploiting the fact that the setup is not teared down after "evaluate" returns - // this workaround is applied because "lookupConfiguredMojo" is not available on AbstractMojoTestCase - // and this way we can skip the effort to re-implement what is already available in MojoRule - rule.apply(new Statement() - { - @Override - public void evaluate() - { - - } - }, Description.createSuiteDescription("dummy")).evaluate(); - return (DataModelGeneratorMojo) rule.lookupConfiguredMojo(pomFile, "generate"); - } } diff --git a/datamodel/openapi/openapi-generator-maven-plugin/pom.xml b/datamodel/openapi/openapi-generator-maven-plugin/pom.xml index 1d9d21759..44dae3e82 100644 --- a/datamodel/openapi/openapi-generator-maven-plugin/pom.xml +++ b/datamodel/openapi/openapi-generator-maven-plugin/pom.xml @@ -68,13 +68,6 @@ junit-jupiter-api test - - - junit - junit - 4.13.2 - test - org.assertj assertj-core diff --git a/datamodel/openapi/openapi-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorMojoIntegrationTest.java b/datamodel/openapi/openapi-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorMojoIntegrationTest.java index 82dea91ec..113ebfe24 100644 --- a/datamodel/openapi/openapi-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorMojoIntegrationTest.java +++ b/datamodel/openapi/openapi-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorMojoIntegrationTest.java @@ -3,17 +3,15 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.File; -import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.function.Predicate; -import org.apache.maven.plugin.testing.MojoRule; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; import com.sap.cloud.sdk.datamodel.openapi.generator.model.ApiMaturity; import com.sap.cloud.sdk.datamodel.openapi.generator.model.GenerationConfiguration; @@ -25,22 +23,26 @@ * module. However, it was found that the OpenAPI generator behaves strange when it comes to accessing the templates as * resources on the classpath. This issue was not caught in the {@code DataModelGeneratorIntegrationTest}. */ +@MojoTest class DataModelGeneratorMojoIntegrationTest { - @TempDir - File outputDirectory; - + private static final String TEST_POM = + "src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/input/pom.xml"; private static final String FOLDER_WITH_EXPECTED_CONTENT = "src/test/resources/" + DataModelGeneratorMojoIntegrationTest.class.getSimpleName() + "/sodastore/output"; + @TempDir + File outputDirectory; + @Test - void generateAndCompareSodastoreLibrary() + @InjectMojo( goal = "generate", pom = TEST_POM ) + void generateAndCompareSodastoreLibrary( DataModelGeneratorMojo mojo ) throws Throwable { final String outputFolderWithActualContent = Paths.get(outputDirectory.getAbsolutePath()).resolve("output").toString(); - generateSodastoreLibrary(outputFolderWithActualContent); + generateSodastoreLibrary(mojo, outputFolderWithActualContent); assertThatDirectoriesHaveSameContent( Paths.get(FOLDER_WITH_EXPECTED_CONTENT), @@ -49,17 +51,16 @@ void generateAndCompareSodastoreLibrary() // Run this test method manually to overwrite the folder containing the expected content with the latest generator state // @Test - void regenerateExpectedSodastoreLibrary() + @InjectMojo( goal = "generate", pom = TEST_POM ) + void regenerateExpectedSodastoreLibrary( DataModelGeneratorMojo mojo ) throws Throwable { - generateSodastoreLibrary(FOLDER_WITH_EXPECTED_CONTENT); + generateSodastoreLibrary(mojo, FOLDER_WITH_EXPECTED_CONTENT); } - private void generateSodastoreLibrary( final String outputDirectory ) + private void generateSodastoreLibrary( DataModelGeneratorMojo mojo, final String outputDirectory ) throws Throwable { - final DataModelGeneratorMojo mojo = loadTestProject(); - final GenerationConfiguration configuration = mojo.retrieveGenerationConfiguration().get(); assertThat(configuration.getApiMaturity()).isEqualTo(ApiMaturity.RELEASED); @@ -84,28 +85,4 @@ private static void assertThatDirectoriesHaveSameContent( final Path a, final Pa Files.walk(a).filter(isFile).forEach(p -> assertThat(p).hasSameTextualContentAs(b.resolve(a.relativize(p)))); Files.walk(b).filter(isFile).forEach(p -> assertThat(p).hasSameTextualContentAs(a.resolve(b.relativize(p)))); } - - private DataModelGeneratorMojo loadTestProject() - throws Throwable - { - final URL resource = getClass().getClassLoader().getResource(getClass().getSimpleName() + "/sodastore/input"); - assertThat(resource).isNotNull(); - - final File pomFile = new File(resource.getFile()); - - final MojoRule rule = new MojoRule(); - // hacky workaround to invoke the internal call to "testCase.setUp()" inside MojoRule - // exploiting the fact that the setup is not teared down after "evaluate" returns - // this workaround is applied because "lookupConfiguredMojo" is not available on AbstractMojoTestCase - // and this way we can skip the effort to re-implement what is already available in MojoRule - rule.apply(new Statement() - { - @Override - public void evaluate() - { - - } - }, Description.createSuiteDescription("dummy")).evaluate(); - return (DataModelGeneratorMojo) rule.lookupConfiguredMojo(pomFile, "generate"); - } } diff --git a/datamodel/openapi/openapi-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorMojoUnitTest.java b/datamodel/openapi/openapi-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorMojoUnitTest.java index 7e66ca37c..aa632f7a6 100644 --- a/datamodel/openapi/openapi-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorMojoUnitTest.java +++ b/datamodel/openapi/openapi-generator-maven-plugin/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorMojoUnitTest.java @@ -4,14 +4,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.io.File; -import java.net.URL; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.testing.MojoRule; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; import com.sap.cloud.sdk.datamodel.openapi.generator.exception.OpenApiGeneratorException; import com.sap.cloud.sdk.datamodel.openapi.generator.model.ApiMaturity; @@ -19,20 +17,29 @@ import io.vavr.control.Try; +@MojoTest class DataModelGeneratorMojoUnitTest { + private static final String RESOURCE_PATH = "src/test/resources/DataModelGeneratorMojoUnitTest"; + private static final String ALL_PARAMETERS_POM = RESOURCE_PATH + "/testInvocationWithAllParameters/pom.xml"; + private static final String MANDATORY_PARAMETERS_POM = + RESOURCE_PATH + "/testInvocationWithMandatoryParameters/pom.xml"; + private static final String EMPTY_REQUIRED_PARAMETER_POM = RESOURCE_PATH + "/testEmptyRequiredParameter/pom.xml"; + private static final String SKIP_EXECUTION_POM = RESOURCE_PATH + "/testSkipExecution/pom.xml"; + private static final String UNEXPECTED_API_MATURITY_POM = + RESOURCE_PATH + "/testInvocationWithUnexpectedApiMaturity/pom.xml"; + private static final String ADDITIONAL_PROPERTIES_POM = + RESOURCE_PATH + "/testAdditionalPropertiesAndEnablingAnyOfOneOf/pom.xml"; + @TempDir File outputDirectory; - private DataModelGeneratorMojo sut; - @Test - void testInvocationWithAllParameters() + @InjectMojo( goal = "generate", pom = ALL_PARAMETERS_POM ) + void testInvocationWithAllParameters( DataModelGeneratorMojo mojo ) throws Throwable { - sut = loadTestProject("/testInvocationWithAllParameters"); - - final GenerationConfiguration configuration = sut.retrieveGenerationConfiguration().get(); + final GenerationConfiguration configuration = mojo.retrieveGenerationConfiguration().get(); assertThat(configuration.getApiMaturity()).isEqualTo(ApiMaturity.RELEASED); assertThat(configuration.isVerbose()).isTrue(); @@ -44,18 +51,17 @@ void testInvocationWithAllParameters() assertThat(configuration.deleteOutputDirectory()).isTrue(); assertThat(configuration.isOneOfAnyOfGenerationEnabled()).isFalse(); - sut.setOutputDirectory(outputDirectory.getAbsolutePath()); + mojo.setOutputDirectory(outputDirectory.getAbsolutePath()); - sut.execute(); + mojo.execute(); } @Test - void testInvocationWithMandatoryParameters() + @InjectMojo( goal = "generate", pom = MANDATORY_PARAMETERS_POM ) + void testInvocationWithMandatoryParameters( DataModelGeneratorMojo mojo ) throws Throwable { - sut = loadTestProject("/testInvocationWithMandatoryParameters"); - - final GenerationConfiguration configuration = sut.retrieveGenerationConfiguration().get(); + final GenerationConfiguration configuration = mojo.retrieveGenerationConfiguration().get(); assertThat(configuration.getApiMaturity()).isEqualTo(ApiMaturity.RELEASED); assertThat(configuration.isVerbose()).isFalse(); @@ -66,18 +72,17 @@ void testInvocationWithMandatoryParameters() assertThat(configuration.getApiPackage()).isEqualTo("com.sap.cloud.sdk.datamodel.rest.test.api"); assertThat(configuration.deleteOutputDirectory()).isFalse(); - sut.setOutputDirectory(outputDirectory.getAbsolutePath()); + mojo.setOutputDirectory(outputDirectory.getAbsolutePath()); - sut.execute(); + mojo.execute(); } @Test - void testEmptyRequiredParameter() + @InjectMojo( goal = "generate", pom = EMPTY_REQUIRED_PARAMETER_POM ) + void testEmptyRequiredParameter( DataModelGeneratorMojo mojo ) throws Throwable { - sut = loadTestProject("/testEmptyRequiredParameter"); - - final Try mojoExecutionTry = Try.run(sut::execute); + final Try mojoExecutionTry = Try.run(mojo::execute); assertThat(mojoExecutionTry.isFailure()).isTrue(); @@ -91,61 +96,34 @@ void testEmptyRequiredParameter() } @Test - void testSkipExecution() + @InjectMojo( goal = "generate", pom = SKIP_EXECUTION_POM ) + void testSkipExecution( DataModelGeneratorMojo mojo ) throws Throwable { - sut = loadTestProject("/testSkipExecution"); - - sut.execute(); + mojo.execute(); //no reasonable assertion possible } @Test - void testInvocationWithUnexpectedApiMaturity() + @InjectMojo( goal = "generate", pom = UNEXPECTED_API_MATURITY_POM ) + void testInvocationWithUnexpectedApiMaturity( DataModelGeneratorMojo mojo ) throws Throwable { - sut = loadTestProject("/testInvocationWithUnexpectedApiMaturity"); - assertThatExceptionOfType(MojoExecutionException.class) - .isThrownBy(sut::execute) + .isThrownBy(mojo::execute) .withCauseInstanceOf(IllegalArgumentException.class); } @Test - void testAdditionalPropertiesAndEnablingAnyOfOneOf() + @InjectMojo( goal = "generate", pom = ADDITIONAL_PROPERTIES_POM ) + void testAdditionalPropertiesAndEnablingAnyOfOneOf( DataModelGeneratorMojo mojo ) throws Throwable { - sut = loadTestProject("/testAdditionalPropertiesAndEnablingAnyOfOneOf"); - - assertThat(sut.retrieveGenerationConfiguration().get().getAdditionalProperties()) + assertThat(mojo.retrieveGenerationConfiguration().get().getAdditionalProperties()) .containsEntry("param1", "val1") .containsEntry("param2", "val2") .containsEntry("useAbstractionForFiles", "true"); - assertThat(sut.retrieveGenerationConfiguration().get().isOneOfAnyOfGenerationEnabled()).isTrue(); - } - - private DataModelGeneratorMojo loadTestProject( String testDir ) - throws Throwable - { - final URL resource = getClass().getClassLoader().getResource(getClass().getSimpleName() + testDir); - assertThat(resource).isNotNull(); - - final File pomFile = new File(resource.getFile()); - - final MojoRule rule = new MojoRule(); - // hacky workaround to invoke the internal call to "testCase.setUp()" inside MojoRule - // exploiting the fact that the setup is not teared down after "evaluate" returns - // this workaround is applied because "lookupConfiguredMojo" is not available on AbstractMojoTestCase - // and this way we can skip the effort to re-implement what is already available in MojoRule - rule.apply(new Statement() - { - @Override - public void evaluate() - { - - } - }, Description.createSuiteDescription("dummy")).evaluate(); - return (DataModelGeneratorMojo) rule.lookupConfiguredMojo(pomFile, "generate"); + assertThat(mojo.retrieveGenerationConfiguration().get().isOneOfAnyOfGenerationEnabled()).isTrue(); } }