From d29e6b4656522bfdb77a3a719003f01e40484efe Mon Sep 17 00:00:00 2001 From: Roman Oborin <36501652+romchellis@users.noreply.github.com> Date: Mon, 5 Jun 2023 10:23:37 +0400 Subject: [PATCH] Jooq into separate tag (#13) * Jooq into separate tag * Return harness alpha v --- README.md | 25 +++--- examples/mariadb-flyway-example/pom.xml | 24 +++--- examples/mysql-flyway-example/pom.xml | 24 +++--- examples/postgres-flyway-example/pom.xml | 29 ++++--- examples/postgres-liquibase-example/pom.xml | 25 +++--- pom.xml | 5 ++ .../testcontainers/jooq/codegen/Plugin.java | 80 ++++--------------- .../jooq/codegen/database/DatabaseProps.java | 27 ++++++- .../codegen/datasource/TargetDatasource.java | 14 ++-- .../jooq/codegen/jooq/JooqGenerator.java | 78 ++++++++++++++++++ .../jooq/codegen/jooq/JooqProps.java | 55 +++++++++++++ .../java/assertions/MavenProjectAssert.java | 50 ++++++++++++ src/test/java/assertions/SchemaAssert.java | 47 ----------- src/test/java/common/Common.java | 7 +- .../jooq/codegen/PluginTest.java | 79 +++++++++--------- .../pom.xml} | 28 +++---- .../pom.xml} | 28 +++---- .../pom.xml} | 27 +++---- .../pom.xml} | 44 +++++----- 19 files changed, 412 insertions(+), 284 deletions(-) create mode 100644 src/main/java/org/testcontainers/jooq/codegen/jooq/JooqGenerator.java create mode 100644 src/main/java/org/testcontainers/jooq/codegen/jooq/JooqProps.java create mode 100644 src/test/java/assertions/MavenProjectAssert.java delete mode 100644 src/test/java/assertions/SchemaAssert.java rename src/test/resources/pom/{mariadb-liquibase-pom.xml => mariadb-liquibase/pom.xml} (79%) rename src/test/resources/pom/{mysql-flyway-pom.xml => mysql-flyway/pom.xml} (78%) rename src/test/resources/pom/{postgres-flyway-pom.xml => postgres-flyway/pom.xml} (80%) rename src/test/resources/pom/{postgres-liquibase-pom.xml => postgres-liquibase/pom.xml} (74%) diff --git a/README.md b/README.md index 5c36ccb..bf19d9d 100644 --- a/README.md +++ b/README.md @@ -104,17 +104,20 @@ by using [Testcontainers](https://www.testcontainers.org/) and applying database You can configure any supporting jooq config here. see https://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration/ --> - - - .* - flyway_schema_history - public - - - org.jooq.codegen.maven.example - target/generated-sources/jooq - - + + false + + + .* + flyway_schema_history + public + + + org.jooq.codegen.maven.example + target/generated-sources/jooq + + + diff --git a/examples/mariadb-flyway-example/pom.xml b/examples/mariadb-flyway-example/pom.xml index 792d44f..c9d56ad 100644 --- a/examples/mariadb-flyway-example/pom.xml +++ b/examples/mariadb-flyway-example/pom.xml @@ -65,17 +65,19 @@ - - - .* - flyway_schema_history - test - - - org.jooq.codegen.maven.example - target/generated-sources/jooq - - + + + + .* + flyway_schema_history + test + + + org.jooq.codegen.maven.example + target/generated-sources/jooq + + + diff --git a/examples/mysql-flyway-example/pom.xml b/examples/mysql-flyway-example/pom.xml index f6ba059..4ae9087 100644 --- a/examples/mysql-flyway-example/pom.xml +++ b/examples/mysql-flyway-example/pom.xml @@ -65,17 +65,19 @@ - - - .* - flyway_schema_history - test - - - org.jooq.codegen.maven.example - target/generated-sources/jooq - - + + + + .* + flyway_schema_history + test + + + org.jooq.codegen.maven.example + target/generated-sources/jooq + + + diff --git a/examples/postgres-flyway-example/pom.xml b/examples/postgres-flyway-example/pom.xml index 6cf9bf7..cba715d 100644 --- a/examples/postgres-flyway-example/pom.xml +++ b/examples/postgres-flyway-example/pom.xml @@ -14,7 +14,8 @@ 17 UTF-8 1.18.1 - 0.0.2 + 0.0.2 + 3.18.3 42.6.0 @@ -65,18 +66,20 @@ filesystem:src/main/resources/db/migration/postgresql - - - - .* - flyway_schema_history - public - - - org.jooq.codegen.maven.example - target/generated-sources/jooq - - + + + + + .* + flyway_schema_history + public + + + org.jooq.codegen.maven.example + target/generated-sources/jooq + + + diff --git a/examples/postgres-liquibase-example/pom.xml b/examples/postgres-liquibase-example/pom.xml index 79fc78d..d015e23 100644 --- a/examples/postgres-liquibase-example/pom.xml +++ b/examples/postgres-liquibase-example/pom.xml @@ -70,17 +70,20 @@ - - - .* - DATABASECHANGELOG - custom - - - org.jooq.codegen.maven.example - target/generated-sources/jooq - - + + + + .* + DATABASECHANGELOG + custom + + + org.jooq.codegen.maven.example + target/generated-sources/jooq + + + + diff --git a/pom.xml b/pom.xml index 858f34d..21845f7 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,11 @@ K Siva Prasad Reddy sivaprasadreddy.k@gmail.com + + contributor + Roman Oborin + deadok68@gmail.com + diff --git a/src/main/java/org/testcontainers/jooq/codegen/Plugin.java b/src/main/java/org/testcontainers/jooq/codegen/Plugin.java index aebe9a5..7b85bd0 100644 --- a/src/main/java/org/testcontainers/jooq/codegen/Plugin.java +++ b/src/main/java/org/testcontainers/jooq/codegen/Plugin.java @@ -2,8 +2,6 @@ import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; import static org.apache.maven.plugins.annotations.ResolutionScope.TEST; -import static org.jooq.Constants.XSD_CODEGEN; -import static org.jooq.codegen.GenerationTool.DEFAULT_TARGET_DIRECTORY; import static org.testcontainers.jooq.codegen.util.OptionalUtils.bothPresent; import java.io.File; @@ -11,17 +9,16 @@ import java.net.URLClassLoader; import java.util.List; import java.util.Optional; +import javax.inject.Inject; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.jooq.codegen.GenerationTool; -import org.jooq.meta.jaxb.Configuration; -import org.jooq.meta.jaxb.Jdbc; -import org.jooq.meta.jaxb.Target; import org.testcontainers.jooq.codegen.database.DatabaseProps; import org.testcontainers.jooq.codegen.datasource.TargetDatasource; +import org.testcontainers.jooq.codegen.jooq.JooqGenerator; +import org.testcontainers.jooq.codegen.jooq.JooqProps; import org.testcontainers.jooq.codegen.migration.runner.FlywayRunner; import org.testcontainers.jooq.codegen.migration.runner.LiquibaseRunner; import org.testcontainers.jooq.codegen.migration.runner.MigrationRunner; @@ -32,33 +29,28 @@ */ @Mojo(name = "generate", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = TEST, threadSafe = true) public class Plugin extends AbstractMojo { + @Parameter(property = "project", required = true, readonly = true) private MavenProject project; - @Parameter(property = "jooq.codegen.skip") - private boolean skip; - - @Parameter(property = "jooq.codegen.basedir") - private String basedir; - - @Parameter - private org.jooq.meta.jaxb.Jdbc jdbc; - - @Parameter - private org.jooq.meta.jaxb.Generator generator; - @Parameter(required = true) private DatabaseProps database; + @Parameter(required = true) + private JooqProps jooq; + @Parameter private FlywayRunner flyway; @Parameter private LiquibaseRunner liquibase; + @Inject + private JooqGenerator jooqGenerator; + @Override public void execute() throws MojoExecutionException { - if (skip) { + if (jooq.skip()) { getLog().info("Skipping jOOQ code generation"); return; } @@ -66,18 +58,17 @@ public void execute() throws MojoExecutionException { if (database.getType() == null) { throw new MojoExecutionException("Property 'type' should be specified inside 'database' block"); } - checkGeneratorArguments(); + final var oldCL = Thread.currentThread().getContextClassLoader(); final var mavenClassloader = getMavenClassloader(); - try (var targetDatasource = TargetDatasource.createOrJoinExisting(jdbc, database)) { + try (var targetDatasource = TargetDatasource.createOrJoinExisting(jooq, database)) { doExecute(mavenClassloader, targetDatasource); } catch (Exception ex) { throw new MojoExecutionException("Error running jOOQ code generation tool", ex); } finally { closeClassloader(oldCL, mavenClassloader); } - project.addCompileSourceRoot(generator.getTarget().getDirectory()); } private void doExecute(URLClassLoader mavenClassloader, TargetDatasource targetDatasource) throws Exception { @@ -89,16 +80,6 @@ private void doExecute(URLClassLoader mavenClassloader, TargetDatasource targetD mavenClassloader, project); Thread.currentThread().setContextClassLoader(mavenClassloader); - String actualBasedir = basedir == null ? project.getBasedir().getAbsolutePath() : basedir; - - setGeneratorTargets(); - - if (jdbc == null) { - jdbc = new Jdbc(); - } - jdbc.setUrl(targetDatasource.getUrl()); - jdbc.setUser(targetDatasource.getUsername()); - jdbc.setPassword(targetDatasource.getPassword()); final var oFlyway = Optional.ofNullable(flyway); final var oLiquibase = Optional.ofNullable(liquibase); @@ -118,15 +99,7 @@ private void doExecute(URLClassLoader mavenClassloader, TargetDatasource targetD getLog().info("Migrations applied successfully"); - final var configuration = new Configuration(); - configuration.setJdbc(jdbc); - configuration.setGenerator(generator); - configuration.setBasedir(actualBasedir); - - if (getLog().isDebugEnabled()) { - getLog().debug("Using this configuration:\n" + configuration); - } - GenerationTool.generate(configuration); + jooqGenerator.generateSources(targetDatasource, jooq, getLog()); } private void closeClassloader(ClassLoader oldCL, URLClassLoader mavenClassloader) { @@ -138,31 +111,6 @@ private void closeClassloader(ClassLoader oldCL, URLClassLoader mavenClassloader } } - private void setGeneratorTargets() { - if (generator.getTarget() == null) { - generator.setTarget(new Target()); - } - if (generator.getTarget().getDirectory() == null) { - generator.getTarget().setDirectory(DEFAULT_TARGET_DIRECTORY); - } - } - - private void checkGeneratorArguments() throws MojoExecutionException { - if (generator == null) { - getLog().error("Incorrect configuration of jOOQ code generation tool"); - getLog().error( - """ - The jOOQ-codegen-maven module's generator configuration is not set up correctly. - This can have a variety of reasons, among which: - - Your pom.xml's contains invalid XML according to %s - - There is a version or artifact mismatch between your pom.xml and your commandline""" - .formatted(XSD_CODEGEN)); - - throw new MojoExecutionException( - "Incorrect configuration of jOOQ code generation tool. See error above for details."); - } - } - private URLClassLoader getMavenClassloader() throws MojoExecutionException { try { List classpathElements = project.getRuntimeClasspathElements(); diff --git a/src/main/java/org/testcontainers/jooq/codegen/database/DatabaseProps.java b/src/main/java/org/testcontainers/jooq/codegen/database/DatabaseProps.java index 1e9bc8a..07ea243 100644 --- a/src/main/java/org/testcontainers/jooq/codegen/database/DatabaseProps.java +++ b/src/main/java/org/testcontainers/jooq/codegen/database/DatabaseProps.java @@ -1,11 +1,36 @@ package org.testcontainers.jooq.codegen.database; -/** Database configuration properties. */ +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Database configuration properties. + */ public class DatabaseProps { + /** + * Required + */ + @Parameter(required = true) private DatabaseType type; + + /** + * Optional + */ + @Parameter private String containerImage; + /** + * Optional + */ + @Parameter private String username; + /** + * Optional + */ + @Parameter private String password; + /** + * Optional + */ + @Parameter private String databaseName; public DatabaseType getType() { diff --git a/src/main/java/org/testcontainers/jooq/codegen/datasource/TargetDatasource.java b/src/main/java/org/testcontainers/jooq/codegen/datasource/TargetDatasource.java index f64713b..d38acc0 100644 --- a/src/main/java/org/testcontainers/jooq/codegen/datasource/TargetDatasource.java +++ b/src/main/java/org/testcontainers/jooq/codegen/datasource/TargetDatasource.java @@ -7,20 +7,24 @@ import org.jooq.meta.jaxb.Jdbc; import org.testcontainers.jooq.codegen.database.DatabaseProps; import org.testcontainers.jooq.codegen.database.DatabaseProvider; +import org.testcontainers.jooq.codegen.jooq.JooqProps; -/** Datasource to migrate and generate sources on */ +/** + * Datasource to migrate and generate sources on + */ public interface TargetDatasource extends AutoCloseable { - public static TargetDatasource createOrJoinExisting(Jdbc jdbc, DatabaseProps database) { - if (needSpinContainer(jdbc)) { + static TargetDatasource createOrJoinExisting(JooqProps jooq, DatabaseProps database) { + if (needSpinContainer(jooq)) { var databaseContainer = DatabaseProvider.getDatabaseContainer(database); return new ContainerTargetDatasource(databaseContainer); } - return new ExistingTargetDatasource(jdbc); + return new ExistingTargetDatasource(jooq.getJdbc()); } - private static boolean needSpinContainer(Jdbc jdbc) { + private static boolean needSpinContainer(JooqProps jooq) { + final var jdbc = jooq.getJdbc(); return ((Predicate) Objects::isNull) .or(props -> props.getUrl() == null) .or(props -> props.getUser() == null) diff --git a/src/main/java/org/testcontainers/jooq/codegen/jooq/JooqGenerator.java b/src/main/java/org/testcontainers/jooq/codegen/jooq/JooqGenerator.java new file mode 100644 index 0000000..0506844 --- /dev/null +++ b/src/main/java/org/testcontainers/jooq/codegen/jooq/JooqGenerator.java @@ -0,0 +1,78 @@ +package org.testcontainers.jooq.codegen.jooq; + +import static org.jooq.Constants.XSD_CODEGEN; +import static org.jooq.codegen.GenerationTool.DEFAULT_TARGET_DIRECTORY; + +import java.util.Optional; +import javax.inject.Inject; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.jooq.codegen.GenerationTool; +import org.jooq.meta.jaxb.Configuration; +import org.jooq.meta.jaxb.Jdbc; +import org.jooq.meta.jaxb.Target; +import org.testcontainers.jooq.codegen.datasource.TargetDatasource; + +/** + * Jooq sources generator + */ +public class JooqGenerator { + + @Inject + private MavenProject project; + + public void generateSources(TargetDatasource targetDatasource, JooqProps jooq, Log log) throws Exception { + checkGeneratorArguments(jooq, log); + setGeneratorTargets(jooq); + + var jdbc = jooq.getJdbc(); + var basedir = Optional.ofNullable(jooq.getBaseDir()) + .orElse(project.getBasedir().getAbsolutePath()); + if (jdbc == null) { + jdbc = new Jdbc(); + } + jdbc.setUrl(targetDatasource.getUrl()); + jdbc.setUser(targetDatasource.getUsername()); + jdbc.setPassword(targetDatasource.getPassword()); + + final var configuration = new Configuration(); + configuration.setJdbc(jdbc); + configuration.setGenerator(jooq.getGenerator()); + configuration.setBasedir(basedir); + + if (log.isDebugEnabled()) { + log.debug("Using this configuration:\n" + configuration); + } + GenerationTool.generate(configuration); + project.addCompileSourceRoot(jooq.getGenerator().getTarget().getDirectory()); + } + + private void setGeneratorTargets(JooqProps jooq) { + var generator = jooq.getGenerator(); + if (generator.getTarget() == null) { + generator.setTarget(new Target()); + } + if (generator.getTarget().getDirectory() == null) { + generator.getTarget().setDirectory(DEFAULT_TARGET_DIRECTORY); + } + } + + private void checkGeneratorArguments(JooqProps jooq, Log log) throws MojoExecutionException { + if (jooq.getGenerator() != null) { + return; + } + + log.error("Incorrect configuration of jOOQ code generation tool"); + log.error( + """ + The jOOQ-codegen-maven module's generator configuration is not set up correctly. + This can have a variety of reasons, among which: + - Your pom.xml's contains invalid XML according to %s + - There is a version or artifact mismatch between your pom.xml and your commandline""" + .formatted(XSD_CODEGEN)); + + throw new MojoExecutionException( + "Incorrect configuration of jOOQ code generation tool. See error above for details."); + } +} diff --git a/src/main/java/org/testcontainers/jooq/codegen/jooq/JooqProps.java b/src/main/java/org/testcontainers/jooq/codegen/jooq/JooqProps.java new file mode 100644 index 0000000..f039e66 --- /dev/null +++ b/src/main/java/org/testcontainers/jooq/codegen/jooq/JooqProps.java @@ -0,0 +1,55 @@ +package org.testcontainers.jooq.codegen.jooq; + +import org.apache.maven.plugins.annotations.Parameter; +import org.jooq.meta.jaxb.Generator; +import org.jooq.meta.jaxb.Jdbc; + +/** + * Jooq specific properties + */ +public class JooqProps { + + /** + * Jdbc specific properties
+ * Optional + */ + @Parameter + private Jdbc jdbc; + + /** + * Sources generator specific properties
+ * Optional + */ + @Parameter + private Generator generator; + + /** + * Skip jooq sources generation
+ * Optional, default - false + */ + @Parameter + private boolean skip; + + /** + * Basedir relative which generation happens
+ * Optional + */ + @Parameter + private String baseDir; + + public Jdbc getJdbc() { + return jdbc; + } + + public Generator getGenerator() { + return generator; + } + + public boolean skip() { + return skip; + } + + public String getBaseDir() { + return baseDir; + } +} diff --git a/src/test/java/assertions/MavenProjectAssert.java b/src/test/java/assertions/MavenProjectAssert.java new file mode 100644 index 0000000..8c43e2f --- /dev/null +++ b/src/test/java/assertions/MavenProjectAssert.java @@ -0,0 +1,50 @@ +package assertions; + +import static common.Common.DEFAULT_GENERATED_BASEDIR; +import static common.Common.DEFAULT_GENERATED_PACKAGE; +import static org.assertj.core.api.Assertions.assertThat; + +import java.nio.file.Path; +import org.apache.maven.project.MavenProject; +import org.assertj.core.api.AbstractAssert; + +/** + * Maven project assert, used for testing generated sources or rest project specific thongs + */ +public class MavenProjectAssert extends AbstractAssert { + + private final Path generatedSourcesPackage; + + protected MavenProjectAssert(MavenProject mavenProject, Path generatedBasedir, Path generatedPackage) { + super(mavenProject, MavenProjectAssert.class); + generatedSourcesPackage = + mavenProject.getBasedir().toPath().resolve(generatedBasedir).resolve(generatedPackage); + } + + public static MavenProjectAssert assertThatProject(MavenProject project) { + return new MavenProjectAssert(project, DEFAULT_GENERATED_BASEDIR, DEFAULT_GENERATED_PACKAGE); + } + + public static MavenProjectAssert assertThatProject(MavenProject project, Path baseDir, Path pkg) { + return new MavenProjectAssert(project, baseDir, pkg); + } + + public MavenProjectAssert hasGeneratedJooqTable(String schema, String tableFile) { + var schemaDir = generatedSourcesPackage.resolve(schema); + var tablesDir = schemaDir.resolve("tables"); + var table = tablesDir.resolve(tableFile); + assertThat(table) + .withFailMessage("Maven project generated sources %s does not contain file: %s", tablesDir, tableFile) + .isNotEmptyFile(); + return this; + } + + public MavenProjectAssert hasGeneratedJooqTable(String tableFile) { + var tableDir = generatedSourcesPackage.resolve("tables"); + var file = tableDir.resolve(tableFile); + assertThat(file) + .withFailMessage("Maven project generated sources does not contain file: %s", file) + .isNotEmptyFile(); + return this; + } +} diff --git a/src/test/java/assertions/SchemaAssert.java b/src/test/java/assertions/SchemaAssert.java deleted file mode 100644 index 055eb45..0000000 --- a/src/test/java/assertions/SchemaAssert.java +++ /dev/null @@ -1,47 +0,0 @@ -package assertions; - -import static common.Common.GENERATED_SOURCES_PATH; -import static org.assertj.core.api.Assertions.assertThat; - -import java.nio.file.Path; -import org.assertj.core.api.AbstractAssert; - -/** - * Generated sources schema assert, it picks generated sources root and makes assertions based on existence generated files - * - * @see common.Common Common constants - */ -public class SchemaAssert extends AbstractAssert { - - private SchemaAssert(String s) { - super(GENERATED_SOURCES_PATH.resolve(s), SchemaAssert.class); - } - - private SchemaAssert() { - super(GENERATED_SOURCES_PATH, SchemaAssert.class); - } - - /** - * Returns assert under generated sources with provided schema name directory - * - * @param name Schema name - */ - public static SchemaAssert assertThatSchema(String name) { - return new SchemaAssert(name); - } - - /** - * Returns assert under generated sources without schema name directory - */ - public static SchemaAssert assertThatDefaultSchema() { - return new SchemaAssert(); - } - - public SchemaAssert containsTable(String tableName) { - var table = actual.resolve("tables").resolve(tableName); - assertThat(table) - .withFailMessage("%s directory does not contain file %s", actual, tableName) - .isNotEmptyFile(); - return this; - } -} diff --git a/src/test/java/common/Common.java b/src/test/java/common/Common.java index e6dfc08..372cd67 100644 --- a/src/test/java/common/Common.java +++ b/src/test/java/common/Common.java @@ -1,13 +1,12 @@ package common; -import java.io.File; import java.nio.file.Path; /** * Common constants for tests */ public class Common { - public static final Path GENERATED_SOURCES_ROOT = Path.of("target/generated-sources/jooq"); - public static final Path GENERATED_SOURCES_PATH = GENERATED_SOURCES_ROOT.resolve("org/jooq/codegen/maven/test"); - public static final File GENERATED_ROOT_DIR = GENERATED_SOURCES_ROOT.toFile(); + + public static final Path DEFAULT_GENERATED_BASEDIR = Path.of("target/generated-sources/jooq"); + public static final Path DEFAULT_GENERATED_PACKAGE = Path.of("org/jooq/codegen/maven/test"); } diff --git a/src/test/java/org/testcontainers/jooq/codegen/PluginTest.java b/src/test/java/org/testcontainers/jooq/codegen/PluginTest.java index 2e48634..a392b67 100644 --- a/src/test/java/org/testcontainers/jooq/codegen/PluginTest.java +++ b/src/test/java/org/testcontainers/jooq/codegen/PluginTest.java @@ -1,77 +1,84 @@ package org.testcontainers.jooq.codegen; -import static assertions.SchemaAssert.assertThatDefaultSchema; -import static assertions.SchemaAssert.assertThatSchema; -import static common.Common.GENERATED_ROOT_DIR; +import static assertions.MavenProjectAssert.assertThatProject; +import static org.codehaus.plexus.PlexusTestCase.getTestFile; -import java.io.File; -import org.apache.commons.io.FileUtils; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.MojoRule; +import org.apache.maven.project.MavenProject; +import org.junit.Rule; +import org.junit.Test; /** - * Integration test plugin under real pom files + * Integration test plugin under real pom files
+ * Sources by default are generated under the same test pom directory
+ * You can check them after test runs, nothing gets into final jar */ -public class PluginTest extends AbstractMojoTestCase { - - /** - * Cleanup generated sources - */ - @Override - public void tearDown() throws Exception { - super.tearDown(); - FileUtils.deleteDirectory(GENERATED_ROOT_DIR); - } +public class PluginTest { + + @Rule + public MojoRule mojoRule = new MojoRule(); + @Test public void testPostgresFlyway() throws Exception { // given - File pom = getTestPom("postgres-flyway-pom.xml"); + MavenProject mavenProject = getMavenProject("postgres-flyway"); // when - lookupMojo("generate", pom).execute(); + mojoRule.lookupConfiguredMojo(mavenProject, "generate").execute(); // then - assertThatDefaultSchema().containsTable("Users.java"); - assertThatDefaultSchema().containsTable("FlywaySchemaHistory.java"); + assertThatProject(mavenProject) + .hasGeneratedJooqTable("Users.java") + .hasGeneratedJooqTable("FlywaySchemaHistory.java"); } + @Test public void testPostgresLiquibase() throws Exception { // given - File pom = getTestPom("postgres-liquibase-pom.xml"); + MavenProject mavenProject = getMavenProject("postgres-liquibase"); // when - lookupMojo("generate", pom).execute(); + mojoRule.lookupConfiguredMojo(mavenProject, "generate").execute(); // then - assertThatSchema("custom").containsTable("Person.java"); - assertThatSchema("custom").containsTable("Users.java"); - assertThatSchema("public_").containsTable("Databasechangelog.java"); + assertThatProject(mavenProject) + .hasGeneratedJooqTable("custom", "Person.java") + .hasGeneratedJooqTable("custom", "Users.java") + .hasGeneratedJooqTable("public_", "Databasechangelog.java"); } + @Test public void testMysqlFlyway() throws Exception { // given - File pom = getTestPom("mysql-flyway-pom.xml"); + MavenProject mavenProject = getMavenProject("mysql-flyway"); // when - lookupMojo("generate", pom).execute(); + mojoRule.lookupConfiguredMojo(mavenProject, "generate").execute(); // then - assertThatSchema("test").containsTable("Users.java"); - assertThatSchema("test").containsTable("FlywaySchemaHistory.java"); + assertThatProject(mavenProject) + .hasGeneratedJooqTable("test", "FlywaySchemaHistory.java") + .hasGeneratedJooqTable("test", "Users.java"); } + @Test public void testMariadbLiquibase() throws Exception { // given - File pom = getTestPom("mariadb-liquibase-pom.xml"); + MavenProject mavenProject = getMavenProject("mariadb-liquibase"); // when - lookupMojo("generate", pom).execute(); + mojoRule.lookupConfiguredMojo(mavenProject, "generate").execute(); // then - assertThatSchema("test").containsTable("Users.java"); - assertThatSchema("test").containsTable("Databasechangelog.java"); + assertThatProject(mavenProject) + .hasGeneratedJooqTable("test", "Users.java") + .hasGeneratedJooqTable("test", "Databasechangelog.java"); } - private File getTestPom(String filename) { - return getTestFile("src/test/resources/pom/%s".formatted(filename)); + private MavenProject getMavenProject(String dirName) throws Exception { + var baseDir = getTestFile("src/test/resources/pom/%s".formatted(dirName)); + var mavenProject = mojoRule.readMavenProject(baseDir); + mojoRule.getContainer().addComponent(mavenProject, MavenProject.class, ""); + return mavenProject; } } diff --git a/src/test/resources/pom/mariadb-liquibase-pom.xml b/src/test/resources/pom/mariadb-liquibase/pom.xml similarity index 79% rename from src/test/resources/pom/mariadb-liquibase-pom.xml rename to src/test/resources/pom/mariadb-liquibase/pom.xml index 372403b..599405e 100644 --- a/src/test/resources/pom/mariadb-liquibase-pom.xml +++ b/src/test/resources/pom/mariadb-liquibase/pom.xml @@ -11,7 +11,8 @@ 17 1.18.1 - 0.0.2 + 0.0.2 + 3.18.3 42.6.0 @@ -76,11 +77,6 @@ - - test-group-id - test-artifact-id - 1.0.0-SNAPSHOT - MARIADB test @@ -95,15 +91,17 @@ db.changelog-root.xml - - - .* - - - org.jooq.codegen.maven.test - target/generated-sources/jooq - - + + + + .* + + + org.jooq.codegen.maven.test + target/generated-sources/jooq + + + diff --git a/src/test/resources/pom/mysql-flyway-pom.xml b/src/test/resources/pom/mysql-flyway/pom.xml similarity index 78% rename from src/test/resources/pom/mysql-flyway-pom.xml rename to src/test/resources/pom/mysql-flyway/pom.xml index aabf940..66223a0 100644 --- a/src/test/resources/pom/mysql-flyway-pom.xml +++ b/src/test/resources/pom/mysql-flyway/pom.xml @@ -11,7 +11,8 @@ 17 1.18.1 - 0.0.2 + 0.0.2 + 3.18.3 42.6.0 @@ -76,11 +77,6 @@ - - test-group-id - test-artifact-id - 1.0.0-SNAPSHOT - MYSQL @@ -89,15 +85,17 @@ filesystem:src/test/resources/db/migration/mysql - - - .* - - - org.jooq.codegen.maven.test - target/generated-sources/jooq - - + + + + .* + + + org.jooq.codegen.maven.test + target/generated-sources/jooq + + + diff --git a/src/test/resources/pom/postgres-flyway-pom.xml b/src/test/resources/pom/postgres-flyway/pom.xml similarity index 80% rename from src/test/resources/pom/postgres-flyway-pom.xml rename to src/test/resources/pom/postgres-flyway/pom.xml index 62cc444..7315902 100644 --- a/src/test/resources/pom/postgres-flyway-pom.xml +++ b/src/test/resources/pom/postgres-flyway/pom.xml @@ -76,11 +76,6 @@ - - test-group-id - test-artifact-id - 1.0.0-SNAPSHOT - POSTGRES postgres:15-alpine @@ -93,16 +88,18 @@ filesystem:src/test/resources/db/migration/postgres - - - .* - public - - - org.jooq.codegen.maven.test - target/generated-sources/jooq - - + + + + .* + public + + + org.jooq.codegen.maven.test + target/generated-sources/jooq + + + diff --git a/src/test/resources/pom/postgres-liquibase-pom.xml b/src/test/resources/pom/postgres-liquibase/pom.xml similarity index 74% rename from src/test/resources/pom/postgres-liquibase-pom.xml rename to src/test/resources/pom/postgres-liquibase/pom.xml index 76fac25..bc67020 100644 --- a/src/test/resources/pom/postgres-liquibase-pom.xml +++ b/src/test/resources/pom/postgres-liquibase/pom.xml @@ -11,7 +11,8 @@ 17 1.18.1 - 0.0.2 + 0.0.2 + 3.18.3 42.6.0 @@ -76,11 +77,6 @@ - - test-group-id - test-artifact-id - 1.0.0-SNAPSHOT - POSTGRES postgres:15-alpine @@ -96,23 +92,25 @@ db.changelog-root.xml - - - .* - - - custom - - - public - - - - - org.jooq.codegen.maven.test - target/generated-sources/jooq - - + + + + .* + + + custom + + + public + + + + + org.jooq.codegen.maven.test + target/generated-sources/jooq + + +