Code Monkey home page Code Monkey logo

flyway-junit5-extensions's People

Contributors

bjoernpetersen avatar dependabot-preview[bot] avatar dependabot[bot] avatar gastaldi avatar radcortez avatar vinche59 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

vinche59

flyway-junit5-extensions's Issues

[Quarkus] How to use with postgres Docker devservices?

How to use this extension with Quarkus postgres devservices?
Attempting a simple test with no application.properties (so it uses devservices to launch a postgres database), doesn't seem to work as the extension is apparently not sending credentials.

2023-01-17 17:27:23,623 INFO  [org.tes.doc.DockerClientProviderStrategy] (build-28) Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
2023-01-17 17:27:24,190 INFO  [org.tes.doc.DockerClientProviderStrategy] (build-28) Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
2023-01-17 17:27:24,193 INFO  [org.tes.DockerClientFactory] (build-28) Docker host IP address is localhost
2023-01-17 17:27:24,213 INFO  [org.tes.DockerClientFactory] (build-28) Connected to docker: 
  Server Version: 20.10.22
  API Version: 1.41
  Operating System: Manjaro Linux
  Total Memory: 15658 MB
2023-01-17 17:27:24,224 INFO  [org.tes.uti.ImageNameSubstitutor] (build-28) Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
2023-01-17 17:27:24,228 INFO  [org.tes.DockerClientFactory] (build-28) Checking the system...
2023-01-17 17:27:24,229 INFO  [org.tes.DockerClientFactory] (build-28) โœ”๏ธŽ Docker server version should be at least 1.6.0
2023-01-17 17:27:24,349 INFO  [๐Ÿณ .io/postgres:14]] (build-28) Creating container for image: docker.io/postgres:14
2023-01-17 17:27:24,599 INFO  [๐Ÿณ .io/postgres:14]] (build-28) Container docker.io/postgres:14 is starting: a7c92549c92d12eaf66e089667732c64dfb110b0ecb54c5c439385b86e4b0f4b
2023-01-17 17:27:26,257 INFO  [๐Ÿณ .io/postgres:14]] (build-28) Container docker.io/postgres:14 started in PT2.018415746S
2023-01-17 17:27:26,257 INFO  [io.qua.dev.pos.dep.PostgresqlDevServicesProcessor] (build-28) Dev Services for PostgreSQL started.
2023-01-17 17:27:26,258 INFO  [io.qua.dat.dep.dev.DevServicesDatasourceProcessor] (build-28) Dev Services for the default datasource (postgresql) started - container ID is a7c92549c92d
2023-01-17 17:27:28,812 INFO  [io.quarkus] (main) telpark-campaigns-core 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.15.3.Final) started in 6.259s. Listening on: http://localhost:8081
2023-01-17 17:27:28,815 INFO  [io.quarkus] (main) Profile test activated. 
2023-01-17 17:27:28,815 INFO  [io.quarkus] (main) Installed features: [agroal, cdi, config-yaml, flyway, hibernate-orm, hibernate-orm-panache, hibernate-validator, jdbc-postgresql, logging-gelf, micrometer, narayana-jta, smallrye-context-propagation, smallrye-fault-tolerance, vertx]
2023-01-17 17:27:28,910 INFO  [org.fly.cor.int.lic.VersionPrinter] (main) Flyway Community Edition 9.8.3 by Redgate
2023-01-17 17:27:28,911 INFO  [org.fly.cor.int.lic.VersionPrinter] (main) See what's new here: https://flywaydb.org/documentation/learnmore/releaseNotes#9.8.3
2023-01-17 17:27:28,911 INFO  [org.fly.cor.int.lic.VersionPrinter] (main) 
2023-01-17 17:27:28,928 WARN  [org.fly.cor.int.jdb.JdbcUtils] (main) Connection error: The server requested SCRAM-based authentication, but no password was provided.
Retrying in 1 sec...
2023-01-17 17:27:29,931 WARN  [org.fly.cor.int.jdb.JdbcUtils] (main) Connection error: The server requested SCRAM-based authentication, but no password was provided.
Retrying in 2 sec...
2023-01-17 17:27:31,933 WARN  [org.fly.cor.int.jdb.JdbcUtils] (main) Connection error: The server requested SCRAM-based authentication, but no password was provided.
Retrying in 4 sec...

Tried filling the "username" and "password", with no luck.

@QuarkusTest
@FlywayTest(@DataSource(value = QuarkusDataSourceProvider.class, username = "quarkus", password = "quarkus"))
class TestRepositoryABC {
   // ...
}

EDIT:

Solved! Needed to fetch the values from the configuration into the auxiliary method.

@QuarkusTest
@FlywayTest(@DataSource(value = QuarkusDataSourceProvider.class))
class TestRepositoryABC {
    public static class QuarkusDataSourceProvider implements DataSourceProvider {
		@Override
		public DataSourceInfo getDatasourceInfo(final ExtensionContext extensionContext) {
			final Config config = ConfigProvider.getConfig();
			return DataSourceInfo.config(config.getValue("quarkus.datasource.jdbc.url", String.class),
										 config.getValue("quarkus.datasource.username", String.class),
										 config.getValue("quarkus.datasource.password", String.class));
		}
	}
}

Quarkus native test

First of all, thanks for creating this extension it is very useful when creating tests.

Rather than asking for a solution, I'd like to understand if you have ever tried to use your extension in native mode

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTestpublic
class NativeFruitsEndpointIT extends FruitsEndpointTest {
    // Runs the same tests as the parent class
}

Just like all the examples in Quarkus-quickstart e.g. https://github.com/quarkusio/quarkus-quickstarts/blob/main/hibernate-orm-panache-quickstart/src/test/java/org/acme/hibernate/orm/panache/NativeFruitsEndpointIT.java

  • I've tried to execute a native test using Quarkus with no success, it seems that in native mode the extension is not executed. However, all tests in no native mode work perfectly fine. Is this an expected behavior or perhaps the extension requires enhancement for Quarkus Native tests?

A way to pass arbitrary flyway config to @FlywayTest

I have seen other issues regarding using a file or environment variables to pass configurations to flyway. this might work in some scenarios but in specific cases they are not practical or need much additional effort. like when one has many tests which each need to be configured differently.

A very effective solution (which can also be potentially done very easily) is that one can set an arbitrary map on the @FlywayTest to just pass configurations to the instance that is created later. What do you think?

Define schema

Hi, is it possible to specify a default schema that will be used to clean and migrate the database? I'm writing unit tests in a Quarkus project using a H2 database. All of the entities are configured to use a certain database schema.

However, in the test logs I can see that all the clean and migrate scripts are executed using the default schema of the database (which is called PUBLIC and not my database schema).

A possible workaround for the migration scripts is to add the line SET SCHEMA MYSCHEMA at the beginning of the SQL script, but the clean method after each test will not work because it tries to clean the wrong schema.

Is there a way to specify the used database schema?

How to use this extension with a database managed by Quarks Dev Services

In the Quarkus example implementation of the DataSourceProvider you make it clear that it's not possible to interact with Quarkus at that point in order to get the connection string directly from ConfigProvider.getConfig(), so you rely on reading the application.properties file with the help of SmallRyeConfigBuilder.

My question is: since the value of quarkus.datasource.jdbc.url is purposely omitted from the file in order to have the DB launched by Dev Service during test, how would you be able to get the connection details in order to implement a DataSourceProvider ?

There's probably a way of doing so, but I'm quite new to the Quarkus world so I'm not aware. Really need this for my integration tests, or else I will have to rely on dropping and populating everything manually for each test, which is quite tedious and error-prone

README.md outdated

The examples seem to be outdated.

E.g. in the meta annotations section

@FlywayTest(datasource = @Datasource(url = "jdbc:h2:mem:test"))

does not longer work, but

@FlywayTest(@DataSource(url = "jdbc:h2:mem:test"))

(big S in DataSource and omitted datasource = )

flywaydb JdbcUtils can't connect to H2

schema is created but can't connect to execute SQL.

"%test":
  quarkus:
    datasource:
      credentials-provider: custom
      db-kind: h2
      jdbc:
        driver: org.h2.Driver
        url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS
      username: sa
    hibernate-orm:
      dialect: org.hibernate.dialect.H2Dialect
      database:
        generation: create

PROVIDER:

import com.radcortez.flyway.test.junit.DataSourceProvider;
import com.radcortez.flyway.test.junit.DataSourceInfo;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.extension.ExtensionContext;

@Slf4j
public class H2DatasourceProvider implements DataSourceProvider {

    @Override
    public DataSourceInfo getDatasourceInfo(final ExtensionContext extensionContext) {
        // Quarkus Dev Services rewrite the Dev Service datasource in the configuration
        Config config = ConfigProvider.getConfig();
        String url = config.getValue("quarkus.datasource.jdbc.url", String.class);
        String username = config.getValue("quarkus.datasource.username", String.class);
        String password = ""; //NOT REQUIRED BY H2 config.getValue("quarkus.datasource.password", String.class);
        log.info("TEST Datasource at URL [{}], user [{}], pw [{}]", url, username, password);
        return DataSourceInfo.config(url, username, password);
    }
}

TEST CLASS:
@QuarkusTest @Tag("integration") @TestProfile(TestConfigProfile.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) @FlywayTest(@DataSource(H2DatasourceProvider.class))

RESULTS
`
"2022-07-15 12:38:19,341 INFO (main) [io.quarkus.printStartupTime()] Installed features: [agroal, cdi, config-yaml, hibernate-orm, jdbc-h2, jdbc-postgresql, narayana-jta, rest-client, resteasy, resteasy-jackson, resteasy-multipart, scheduler, security, security-jdbc, security-properties-file, smallrye-context-propagation, smallrye-fault-tolerance, vertx]

"2022-07-15 12:38:19,406 INFO (main) [com.bar.config.H2DatasourceProvider.getDatasourceInfo()] TEST Datasource at URL [jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS market], user [sa], pw []

2022-07-15 12:38:19,739 WARN (main) [org.flywaydb.core.internal.jdbc.JdbcUtils.warn()] Connection error: Wrong user name or password [28000-197] Retrying in 1 sec...
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.