Search in sources :

Example 41 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class H2IntegrationTest method runYamlChangelog.

@Test
public void runYamlChangelog() throws Exception {
    if (getDatabase() == null) {
        return;
    }
    Liquibase liquibase = createLiquibase(completeChangeLog);
    clearDatabase();
    // run again to test changelog testing logic
    liquibase = createLiquibase("changelogs/yaml/common.tests.changelog.yaml");
    liquibase.setChangeLogParameter("loginuser", testSystem.getUsername());
    try {
        liquibase.update(this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Example 42 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class H2IntegrationTest method runJsonChangelog.

@Test
public void runJsonChangelog() throws Exception {
    if (getDatabase() == null) {
        return;
    }
    Liquibase liquibase = createLiquibase(completeChangeLog);
    clearDatabase();
    // run again to test changelog testing logic
    liquibase = createLiquibase("changelogs/json/common.tests.changelog.json");
    liquibase.setChangeLogParameter("loginuser", testSystem.getUsername());
    try {
        liquibase.update(this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Example 43 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class MssqlIntegrationTest method dataTypesTest.

@Test
public void dataTypesTest() throws Exception {
    assumeNotNull(this.getDatabase());
    clearDatabase();
    Liquibase liquibase = createLiquibase("changelogs/mssql/issues/data.types.xml");
    liquibase.update((String) null);
    DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(CatalogAndSchema.DEFAULT, this.getDatabase(), new SnapshotControl(getDatabase()));
    for (Table table : snapshot.get(Table.class)) {
        if (getDatabase().isLiquibaseObject(table)) {
            continue;
        }
        for (Column column : table.getColumns()) {
            String expectedType = column.getName().split("_")[0];
            switch(expectedType.toUpperCase()) {
                // varchar(max), nvarchar(max) and varbinary(max).
                case "TEXT":
                    expectedType = "varchar";
                    break;
                case "NTEXT":
                    expectedType = "nvarchar";
                    break;
                case "IMAGE":
                    expectedType = "varbinary";
                    break;
                default:
            }
            String foundTypeDefinition = DataTypeFactory.getInstance().from(column.getType(), new MSSQLDatabase()).toDatabaseDataType(getDatabase()).toString();
            // [varbinary] -> varbinary
            foundTypeDefinition = foundTypeDefinition.replaceFirst("^\\[(.*?)\\]", "$1");
            String foundType = foundTypeDefinition.replaceFirst("\\(.*", "").trim();
            assertEquals("Wrong data type for " + table.getName() + "." + column.getName(), expectedType.toLowerCase(), foundType.toLowerCase());
            if ("varbinary".equalsIgnoreCase(expectedType)) {
                if (column.getName().endsWith("_MAX")) {
                    assertEquals("VARBINARY(MAX)", foundTypeDefinition.toUpperCase());
                } else {
                    assertEquals("VARBINARY(1)", foundTypeDefinition.toUpperCase());
                }
            }
        }
    }
}
Also used : Liquibase(liquibase.Liquibase) Table(liquibase.structure.core.Table) Column(liquibase.structure.core.Column) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot) SnapshotControl(liquibase.snapshot.SnapshotControl) Test(org.junit.Test)

Example 44 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class OracleIntegrationTest method smartDataLoad.

@Test
public void smartDataLoad() throws Exception {
    assumeNotNull(this.getDatabase());
    Liquibase liquibase = createLiquibase("changelogs/common/smartDataLoad.changelog.xml");
    clearDatabase();
    try {
        liquibase.update(this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
    // check that the automatically rollback now works too
    try {
        liquibase.rollback(new Date(0), this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Date(java.util.Date) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Example 45 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class OracleIntegrationTest method viewCreatedOnCorrectSchema.

@Test
public void viewCreatedOnCorrectSchema() throws Exception {
    assumeNotNull(this.getDatabase());
    Liquibase liquibase = createLiquibase(this.viewOnSchemaChangeLog);
    clearDatabase();
    try {
        liquibase.update(this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
    Statement queryIndex = ((JdbcConnection) this.getDatabase().getConnection()).getUnderlyingConnection().createStatement();
    ResultSet indexOwner = queryIndex.executeQuery("SELECT owner FROM ALL_VIEWS WHERE view_name = 'V_BOOK2'");
    assertTrue(indexOwner.next());
    String owner = indexOwner.getString("owner");
    assertEquals("LBCAT2", owner);
    // check that the automatically rollback now works too
    try {
        liquibase.rollback(new Date(0), this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Date(java.util.Date) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Aggregations

Liquibase (liquibase.Liquibase)97 Test (org.junit.Test)29 LiquibaseException (liquibase.exception.LiquibaseException)25 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)25 JdbcConnection (liquibase.database.jvm.JdbcConnection)24 IOException (java.io.IOException)22 Database (liquibase.database.Database)22 SQLException (java.sql.SQLException)17 Contexts (liquibase.Contexts)17 ValidationFailedException (liquibase.exception.ValidationFailedException)11 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)10 DatabaseException (liquibase.exception.DatabaseException)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 BuildException (org.apache.tools.ant.BuildException)10 ChangeSet (liquibase.changelog.ChangeSet)9 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)9 Connection (java.sql.Connection)8 ResourceAccessor (liquibase.resource.ResourceAccessor)8 FileNotFoundException (java.io.FileNotFoundException)6 Date (java.util.Date)6