forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...ay/deployment/src/test/java/io/quarkus/flyway/test/FlywayMultiDataSourcesDevModeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.DefaultValue; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.flywaydb.core.api.Location; | ||
import org.flywaydb.core.api.configuration.Configuration; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.flyway.FlywayDataSource; | ||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
// see https://github.com/quarkusio/quarkus/issues/9415 | ||
public class FlywayMultiDataSourcesDevModeTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Endpoint.class) | ||
.addAsResource("config-for-multiple-datasources.properties", "application.properties")); | ||
|
||
@Test | ||
public void testProperConfigApplied() { | ||
RestAssured.get("/fly").then() | ||
.statusCode(200) | ||
.body(containsString("db/location1,db/location2")); | ||
|
||
RestAssured.get("/fly?name=users").then() | ||
.statusCode(200) | ||
.body(containsString("db/users/location1,db/users/location2")); | ||
|
||
RestAssured.get("/fly?name=inventory").then() | ||
.statusCode(200) | ||
.body(containsString("db/inventory/location1,db/inventory/location")); | ||
} | ||
|
||
@Path("/fly") | ||
public static class Endpoint { | ||
|
||
@Inject | ||
Flyway flywayDefault; | ||
|
||
@Inject | ||
@FlywayDataSource("users") | ||
Flyway flywayUsers; | ||
|
||
@Inject | ||
@FlywayDataSource("inventory") | ||
Flyway flywayInventory; | ||
|
||
@GET | ||
@Produces("text/plain") | ||
public String locations(@QueryParam("name") @DefaultValue("default") String name) { | ||
Configuration configuration; | ||
if ("default".equals(name)) { | ||
configuration = flywayDefault.getConfiguration(); | ||
} else if ("users".equals(name)) { | ||
configuration = flywayUsers.getConfiguration(); | ||
} else if ("inventory".equals(name)) { | ||
configuration = flywayInventory.getConfiguration(); | ||
} else { | ||
throw new RuntimeException("Flyway " + name + " not found"); | ||
} | ||
|
||
return Arrays.stream(configuration.getLocations()).map(Location::getPath).collect(Collectors.joining(",")); | ||
} | ||
|
||
} | ||
} |