moar integration tests

This commit is contained in:
Ken Stevens 2019-11-03 13:46:09 -05:00
parent de4f909eda
commit 5890059362
2 changed files with 35 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.cli;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
import ca.uhn.fhir.jpa.migrate.JdbcUtils;
import com.google.common.base.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
@ -25,8 +26,7 @@ import java.util.List;
import java.util.Map;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
public class HapiFlywayMigrateDatabaseCommandTest {
@ -38,7 +38,7 @@ public class HapiFlywayMigrateDatabaseCommandTest {
}
@Test
public void testMigrate() throws IOException {
public void testMigrateFrom340() throws IOException, SQLException {
File location = getLocation("migrator_h2_test_340_current");
@ -61,7 +61,9 @@ public class HapiFlywayMigrateDatabaseCommandTest {
"-n", "",
"-p", ""
};
assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_RES_REINDEX_JOB"));
App.main(args);
assertTrue(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_RES_REINDEX_JOB"));
connectionProperties.getTxTemplate().execute(t -> {
JdbcTemplate jdbcTemplate = connectionProperties.newJdbcTemplate();
@ -75,6 +77,33 @@ public class HapiFlywayMigrateDatabaseCommandTest {
});
}
@Test
public void testMigrateFromEmptySchema() throws IOException, SQLException {
File location = getLocation("migrator_h2_test_empty_current");
String url = "jdbc:h2:" + location.getAbsolutePath() + ";create=true";
DriverTypeEnum.ConnectionProperties connectionProperties = DriverTypeEnum.H2_EMBEDDED.newConnectionProperties(url, "", "");
ourLog.info("**********************************************");
ourLog.info("Starting Migration...");
ourLog.info("**********************************************");
String[] args = new String[]{
BaseFlywayMigrateDatabaseCommand.MIGRATE_DATABASE,
"-d", "H2_EMBEDDED",
"-u", url,
"-n", "",
"-p", ""
};
assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_RESOURCE"));
assertFalse(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_BLK_EXPORT_JOB"));
App.main(args);
assertTrue(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_RESOURCE")); // Early table
assertTrue(JdbcUtils.getTableNames(connectionProperties).contains("HFJ_BLK_EXPORT_JOB")); // Late table
}
@NotNull
private File getLocation(String theDatabaseName) throws IOException {
File directory = new File(DB_DIRECTORY);

View File

@ -63,10 +63,10 @@ public class CalculateHashesTask extends BaseTableColumnTask<CalculateHashesTask
}
Set<String> tableNames = JdbcUtils.getTableNames(getConnectionProperties());
// This table was added a few days after hash indexes were added, so it is a reasonable indicator for whether this
// This table was added shortly after hash indexes were added, so it is a reasonable indicator for whether this
// migration has already been run
if (tableNames.contains("TRM_CONCEPT_DESIG")) {
logInfo(ourLog, "The table TRM_CONCEPT_DESIG already exists. Skipping calculate hashes task.");
if (tableNames.contains("HFJ_RES_REINDEX_JOB")) {
logInfo(ourLog, "The table HFJ_RES_REINDEX_JOB already exists. Skipping calculate hashes task.");
return;
}