diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionEnum.java
index 04568303f89..7669fa4e8e1 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionEnum.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/VersionEnum.java
@@ -31,6 +31,10 @@ public enum VersionEnum {
V3_6_0,
V3_7_0,
V3_8_0,
- V4_0_0
+ V4_0_0;
+ public static VersionEnum latestVersion() {
+ VersionEnum[] values = VersionEnum.values();
+ return values[values.length - 1];
+ }
}
diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/pom.xml b/hapi-fhir-cli/hapi-fhir-cli-api/pom.xml
index ce4a55202c4..c1169e57e21 100644
--- a/hapi-fhir-cli/hapi-fhir-cli-api/pom.xml
+++ b/hapi-fhir-cli/hapi-fhir-cli-api/pom.xml
@@ -97,6 +97,11 @@
org.apache.derby
derby
+
+ com.h2database
+ h2
+ test
+
org.mariadb.jdbc
mariadb-java-client
diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/HapiMigrateDatabaseCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/HapiMigrateDatabaseCommandTest.java
index 0f0a207744f..ba184732e21 100644
--- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/HapiMigrateDatabaseCommandTest.java
+++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/HapiMigrateDatabaseCommandTest.java
@@ -1,6 +1,7 @@
package ca.uhn.fhir.cli;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
+import ca.uhn.fhir.util.VersionEnum;
import com.google.common.base.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
@@ -12,6 +13,7 @@ import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatemen
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobCreator;
+import javax.validation.constraints.NotNull;
import java.io.File;
import java.io.IOException;
import java.sql.PreparedStatement;
@@ -31,23 +33,21 @@ import static org.junit.Assert.assertTrue;
public class HapiMigrateDatabaseCommandTest {
private static final Logger ourLog = LoggerFactory.getLogger(HapiMigrateDatabaseCommandTest.class);
+ public static final String DB_DIRECTORY = "target/h2_test";
static {
System.setProperty("test", "true");
}
@Test
- public void testMigrate_340_370() throws IOException {
+ public void testMigrate_340_current() throws IOException {
- File directory = new File("target/migrator_derby_test_340_360");
- if (directory.exists()) {
- FileUtils.deleteDirectory(directory);
- }
+ File location = getLocation("migrator_h2_test_340_current");
- String url = "jdbc:derby:directory:" + directory.getAbsolutePath() + ";create=true";
- DriverTypeEnum.ConnectionProperties connectionProperties = DriverTypeEnum.DERBY_EMBEDDED.newConnectionProperties(url, "", "");
+ String url = "jdbc:h2:" + location.getAbsolutePath() + ";create=true";
+ DriverTypeEnum.ConnectionProperties connectionProperties = DriverTypeEnum.H2_EMBEDDED.newConnectionProperties(url, "", "");
- String initSql = "/persistence_create_derby107_340.sql";
+ String initSql = "/persistence_create_h2_340.sql";
executeSqlStatements(connectionProperties, initSql);
seedDatabase340(connectionProperties);
@@ -58,7 +58,57 @@ public class HapiMigrateDatabaseCommandTest {
String[] args = new String[]{
"migrate-database",
- "-d", "DERBY_EMBEDDED",
+ "-d", "H2_EMBEDDED",
+ "-u", url,
+ "-n", "",
+ "-p", "",
+ "-f", "V3_4_0",
+ "-t", VersionEnum.latestVersion().toString()
+ };
+ App.main(args);
+
+ connectionProperties.getTxTemplate().execute(t -> {
+ JdbcTemplate jdbcTemplate = connectionProperties.newJdbcTemplate();
+ List