From 6049ee6f1c9a702b9073b45ae9201d21b9a26278 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Fri, 1 Nov 2019 21:40:24 -0400 Subject: [PATCH] init schema test --- .../jpa/migrate/taskdef/AddTableTest.java | 1 - .../taskdef/InitializeSchemaTaskTest.java | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableTest.java index 359a0698dfc..ccf66a63b8d 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableTest.java @@ -33,7 +33,6 @@ public class AddTableTest extends BaseTest { task.setTableName("SOMETABLE"); task.addSql(DriverTypeEnum.H2_EMBEDDED, "create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); getMigrator().addTask(task); - getMigrator().migrate(); assertThat(JdbcUtils.getTableNames(getConnectionProperties()), containsInAnyOrder("SOMETABLE")); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java new file mode 100644 index 00000000000..6dc16a4bf4f --- /dev/null +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java @@ -0,0 +1,30 @@ +package ca.uhn.fhir.jpa.migrate.taskdef; + +import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; +import ca.uhn.fhir.jpa.migrate.JdbcUtils; +import org.junit.Test; + +import java.sql.SQLException; +import java.util.Collections; +import java.util.List; + +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.Assert.*; + +public class InitializeSchemaTaskTest extends BaseTest { + + @Test + public void testInitializeTwice() throws SQLException { + InitializeSchemaTask task = new InitializeSchemaTask("1", "1", t -> getSql()); + getMigrator().addTask(task); + getMigrator().migrate(); + assertThat(JdbcUtils.getTableNames(getConnectionProperties()), containsInAnyOrder("SOMETABLE")); + + // Second migrate runs without issue + getMigrator().migrate(); + } + + private List getSql() { + return Collections.singletonList("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); + } +}