Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support for Environment to flyway service #245

Merged
merged 1 commit into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/src/asciidoc/module_dbflyway.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The migrate command accepts an optional --out-of-order parameter.

In addition to CLI support, there's also a `FlywayService` that can be
configured as a QBean. We recommend to use a low filename (such as
`01_flyway.xml` so that the service starts before other services that may
`01_flyway.xml`) so that the service starts before other services that may
require the schema to be impacted in the database.

The QBean descriptor looks like this:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.internal.info.MigrationInfoDumper;
import org.jdom2.Element;
import org.jpos.core.ConfigurationException;
import org.jpos.core.Environment;
import org.jpos.core.XmlConfigurable;
import org.jpos.q2.QBeanSupport;

Expand Down Expand Up @@ -77,9 +77,7 @@ protected void initService() {
}

@Override
public void setConfiguration(Element e) throws ConfigurationException {
commands = e.getChildText("commands");
if (commands == null)
commands = "info";
public void setConfiguration(Element e) {
commands = Environment.get(e.getChildText("commands"), "info");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.jpos.flyway;

import org.jdom2.Element;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Arturo Volpe
* @since 2022-05-12
*/
class FlywayServiceTest {

@Test
void test_empty_config() throws Exception {

FlywayService flywayService = new FlywayService();
flywayService.setConfiguration(new Element("flyway"));

assertEquals("info", flywayService.commands);
}

@Test
void test_static_config() throws Exception {

FlywayService flywayService = new FlywayService();
flywayService.setConfiguration(new Element("flyway")
.addContent(new Element("commands").addContent("info"))
);

assertEquals("info", flywayService.commands);
}

@Test
void test_env_config() throws Exception {

System.setProperty("flyway_commands", "info migrate");
FlywayService flywayService = new FlywayService();
flywayService.setConfiguration(new Element("flyway")
.addContent(new Element("commands").addContent("${flyway_commands}"))
);

assertEquals("info migrate", flywayService.commands);
}
}