/** * Runs the specified liquibase change log. * <p> * Liquibase uses a JDBC datasource to get a connection to the database and has its own transaction handling. * Therefore, it won't participate in the current transaction. * <p> * We'll still require a transaction to be present for the current EntityManager. We'll commit that transaction * in order to execute the Liquibase changes and begin a new transaction before returning. * That means that the EntityManager's transaction will be open at the end of this method and can be used * to perform further queries / updates. * @param changeLogResourceName Name of the change log resource. The resource will be loaded using the * default class loader. */ public void runLiquibaseChangeLog(final String changeLogResourceName) { this.runLiquibaseChangeLog(changeLogResourceName, null); }
/** * Check if we can use the replaceOrExists tag. Liquibase doesn't support it with Derby, throwing an Exception. * Therefore we filter the change logs before submitting them to Liquibase. */ @Test public void liquibase_canUseReplaceOrExists() { DbSchemaUtil su = new DbSchemaUtil(this.em); su.clearSchema(); su.runLiquibaseChangeLog("ch/inftec/ju/dbutil/test/DbSchemaUtilTest_liquibase_canUseReplaceOrExists.xml"); } }
@Test public void tableStructure_canBeCreatedUsingLiquibase() { DbSchemaUtil su = new DbSchemaUtil(this.em); su.clearSchema(); su.runLiquibaseChangeLog("ju-testing/data/default-changeLog.xml"); }
@Test public void canListSequences() { JuAssumeUtils.dbIsNot(this.emUtil, DbType.MYSQL); // Sequences are not supported by MqSQL new DbSchemaUtil(this.emUtil).runLiquibaseChangeLog("ch/inftec/ju/dbutil/test/JuEmUtilTest_canListSequences.xml"); List<String> sequenceNames = this.emUtil.getSequenceNames(); Assert.assertTrue(sequenceNames.contains("TESTSEQUENCE")); }
@Test public void canResetIdentityGeneration_forSequences() { JuAssumeUtils.dbIsNot(this.emUtil, DbType.MYSQL); DbSchemaUtil su = new DbSchemaUtil(this.emUtil); su.prepareDefaultSchemaAndTestData(); su.runLiquibaseChangeLog("ch/inftec/ju/dbutil/test/JuEmUtilTest_canListSequences.xml"); this.emUtil.resetIdentityGenerationOrSequences(1); // Is done by prepareDefaultSchemaAndTestData, but the testSequence might just have been created //CREATE SEQUENCE PUBLIC.testSequence Assert.assertEquals(new Long(1L), this.emUtil.getNextValueFromSequence("testSequence")); this.emUtil.resetIdentityGenerationOrSequences(10); Assert.assertEquals(new Long(10L), this.emUtil.getNextValueFromSequence("testSequence")); }
@JuDbTest(profile="derby-lb-create", persistenceUnit="ju-testing-pu-liquibase") @Test public void canGenerateSchema_usingLiquibase() { Assert.assertEquals(0, this.emUtil.getTableNames().size()); new DbSchemaUtil(this.em).runLiquibaseChangeLog("ch/inftec/ju/testing/db/LiquibaseTest_testingEntityChangeLog.xml"); assertThat(this.emUtil.getTableNames(), hasItem("TESTINGENTITY")); }
this.runLiquibaseChangeLog("ju-testing/data/default-changeLog.xml"); this.runLiquibaseChangeLog("ju-testing/data/default-changeLog-hibernateSequence.xml"); this.runLiquibaseChangeLog("ju-testing/data/default-changeLog-mySqlEngine.xml");
/** * This tests data loading from an external file, as well as locating that file in a relative * sub folder. */ @JuDbTest(profile="derby-lb-import", persistenceUnit="ju-testing-pu-liquibase") @Test public void canImportData_fromExternalFile_inRelativeSubFolder() { Assert.assertEquals(0, this.emUtil.getTableNames().size()); new DbSchemaUtil(this.em).runLiquibaseChangeLog("ch/inftec/ju/testing/db/LiquibaseTest_loadFromExternalFile.xml"); TestingEntity te = this.em.find(TestingEntity.class, 1L); Assert.assertEquals("Loaded from File", te.getName()); } }
@Test public void tablesAreCreated_usingLiquibaseExplicitly() { DbSchemaUtil su = new DbSchemaUtil(this.em); su.clearSchema(); Assert.assertFalse(JuCollectionUtils.collectionContainsIgnoreCase(this.emUtil.getTableNames(), "TestingEntity_LB")); su.runLiquibaseChangeLog("ch/inftec/ju/dbutil/test/LiquibaseTestDataTest_testingEntity.xml"); Assert.assertTrue(JuCollectionUtils.collectionContainsIgnoreCase(this.emUtil.getTableNames(), "TestingEntity_LB")); }
@JuDbTest(profile="derby-lb-change", persistenceUnit="ju-testing-pu-liquibase") @Test public void canExecute_dbUnitDataSet_asLiquibaseChangeSet() { Assert.assertEquals(0, this.emUtil.getTableNames().size()); new DbSchemaUtil(this.em).runLiquibaseChangeLog("ch/inftec/ju/testing/db/LiquibaseTest_dbUnitChangeLog.xml"); TestingEntity te = this.em.find(TestingEntity.class, 1L); Assert.assertEquals("LiquibaseDbUnitChangeSet", te.getName()); }