Search in sources :

Example 71 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class SqlGeneratorChainTest method validate_oneGenerators_noErrors.

@Test
public void validate_oneGenerators_noErrors() {
    SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator());
    generators.add(new MockSqlGenerator(1, "A1", "A2"));
    SqlGeneratorChain chain = new SqlGeneratorChain(generators);
    ValidationErrors validationErrors = chain.validate(new MockSqlStatement(), new MockDatabase());
    assertFalse(validationErrors.hasErrors());
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors) TreeSet(java.util.TreeSet) MockSqlStatement(liquibase.statement.core.MockSqlStatement) MockDatabase(liquibase.sdk.database.MockDatabase) Test(org.junit.Test)

Example 72 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class ChangeParameterMetaData method analyzeRequiredDatabases.

protected Set<String> analyzeRequiredDatabases(String[] requiredDatabases) {
    if (requiredDatabases == null) {
        requiredDatabases = new String[] { ChangeParameterMetaData.COMPUTE };
    }
    Set<String> computedDatabases = new HashSet<String>();
    if (requiredDatabases.length == 1 && StringUtils.join(requiredDatabases, ",").equals(ChangeParameterMetaData.COMPUTE)) {
        int validDatabases = 0;
        for (Database database : DatabaseFactory.getInstance().getImplementedDatabases()) {
            try {
                if (!change.generateStatementsVolatile(database)) {
                    Change testChange = change.getClass().newInstance();
                    ValidationErrors originalErrors = getStatementErrors(testChange, database);
                    this.setValue(testChange, this.getExampleValue(database));
                    ValidationErrors finalErrors = getStatementErrors(testChange, database);
                    if (originalErrors.getRequiredErrorMessages().size() > 0 && finalErrors.getRequiredErrorMessages().size() < originalErrors.getRequiredErrorMessages().size()) {
                        computedDatabases.add(database.getShortName());
                    }
                    validDatabases++;
                }
            } catch (Exception ignore) {
            }
        }
        if (validDatabases == 0) {
            return new HashSet<String>();
        } else if (computedDatabases.size() == validDatabases) {
            computedDatabases = new HashSet<String>(Arrays.asList("all"));
        }
        computedDatabases.remove("none");
    } else {
        computedDatabases = new HashSet<String>(Arrays.asList(requiredDatabases));
    }
    computedDatabases.remove("none");
    return computedDatabases;
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors) Database(liquibase.database.Database) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 73 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class UpdateDataChange method validate.

@Override
public ValidationErrors validate(Database database) {
    ValidationErrors validate = super.validate(database);
    validate.checkRequiredField("columns", getColumns());
    return validate;
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors)

Example 74 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class ChangeParameterMetaData method analyzeSupportedDatabases.

protected Set<String> analyzeSupportedDatabases(String[] supportedDatabases) {
    if (supportedDatabases == null) {
        supportedDatabases = new String[] { ChangeParameterMetaData.COMPUTE };
    }
    Set<String> computedDatabases = new HashSet<String>();
    if (supportedDatabases.length == 1 && StringUtils.join(supportedDatabases, ",").equals(ChangeParameterMetaData.COMPUTE)) {
        int validDatabases = 0;
        for (Database database : DatabaseFactory.getInstance().getImplementedDatabases()) {
            if (database.getShortName() == null || database.getShortName().equals("unsupported")) {
                continue;
            }
            if (!change.supports(database)) {
                continue;
            }
            try {
                if (!change.generateStatementsVolatile(database)) {
                    Change testChange = change.getClass().newInstance();
                    ValidationErrors originalErrors = getStatementErrors(testChange, database);
                    this.setValue(testChange, this.getExampleValue(database));
                    ValidationErrors finalErrors = getStatementErrors(testChange, database);
                    if (finalErrors.getUnsupportedErrorMessages().size() == 0 || finalErrors.getUnsupportedErrorMessages().size() == originalErrors.getUnsupportedErrorMessages().size()) {
                        computedDatabases.add(database.getShortName());
                    }
                    validDatabases++;
                }
            } catch (Exception ignore) {
            }
        }
        if (validDatabases == 0) {
            return new HashSet<String>(Arrays.asList("all"));
        } else if (computedDatabases.size() == validDatabases) {
            computedDatabases = new HashSet<String>(Arrays.asList("all"));
        }
        computedDatabases.remove("none");
        return computedDatabases;
    } else {
        return new HashSet<String>(Arrays.asList(supportedDatabases));
    }
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors) Database(liquibase.database.Database) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 75 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class ChangeParameterMetaData method getStatementErrors.

private ValidationErrors getStatementErrors(Change testChange, Database database) {
    ValidationErrors errors = new ValidationErrors();
    SqlStatement[] statements = testChange.generateStatements(database);
    for (SqlStatement statement : statements) {
        errors.addAll(SqlGeneratorFactory.getInstance().validate(statement, database));
    }
    return errors;
}
Also used : SqlStatement(liquibase.statement.SqlStatement) ValidationErrors(liquibase.exception.ValidationErrors)

Aggregations

ValidationErrors (liquibase.exception.ValidationErrors)89 Test (org.junit.Test)11 MockDatabase (liquibase.sdk.database.MockDatabase)9 Database (liquibase.database.Database)6 MockSqlStatement (liquibase.statement.core.MockSqlStatement)6 TreeSet (java.util.TreeSet)5 ArrayList (java.util.ArrayList)2 Change (liquibase.change.Change)2 ChangeFactory (liquibase.change.ChangeFactory)2 ChangeMetaData (liquibase.change.ChangeMetaData)2 ChangeParameterMetaData (liquibase.change.ChangeParameterMetaData)2 CreateTableChange (liquibase.change.core.CreateTableChange)2 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)2 RanChangeSet (liquibase.changelog.RanChangeSet)2 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)2 SqlStatement (liquibase.statement.SqlStatement)2 AddColumnStatement (liquibase.statement.core.AddColumnStatement)2 JUnitResourceAccessor (liquibase.test.JUnitResourceAccessor)2 AbstractVerifyTest (liquibase.verify.AbstractVerifyTest)2 Ignore (org.junit.Ignore)2