Search in sources :

Example 76 with ValidationErrors

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

the class AddDefaultValueChange method validate.

@Override
public ValidationErrors validate(Database database) {
    ValidationErrors validate = new ValidationErrors();
    int nonNullValues = 0;
    if (defaultValue != null) {
        nonNullValues++;
    }
    if (defaultValueNumeric != null) {
        nonNullValues++;
    }
    if (defaultValueBoolean != null) {
        nonNullValues++;
    }
    if (defaultValueDate != null) {
        nonNullValues++;
    }
    if (defaultValueComputed != null) {
        nonNullValues++;
    }
    if (defaultValueSequenceNext != null) {
        nonNullValues++;
    }
    if (nonNullValues > 1) {
        validate.addError("Only one defaultValue* value can be specified");
    } else {
        validate.addAll(super.validate(database));
    }
    return validate;
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors)

Example 77 with ValidationErrors

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

the class DropColumnChange method validate.

@Override
public ValidationErrors validate(Database database) {
    if (database instanceof SQLiteDatabase) {
        ValidationErrors validationErrors = new ValidationErrors();
        validationErrors.checkRequiredField("tableName", tableName);
        validationErrors.checkRequiredField("columnName", columnName);
        return validationErrors;
    }
    return super.validate(database);
}
Also used : SQLiteDatabase(liquibase.database.core.SQLiteDatabase) ValidationErrors(liquibase.exception.ValidationErrors)

Example 78 with ValidationErrors

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

the class OutputChange method validate.

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

Example 79 with ValidationErrors

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

the class ValidatingVisitorTest method visit_validateError.

@Test
public void visit_validateError() throws Exception {
    changeSet1.addChange(new CreateTableChange() {

        @Override
        public ValidationErrors validate(Database database) {
            ValidationErrors changeValidationErrors = new ValidationErrors();
            changeValidationErrors.addError("Test message");
            return changeValidationErrors;
        }
    });
    List<RanChangeSet> ran = new ArrayList<RanChangeSet>();
    ValidatingVisitor handler = new ValidatingVisitor(ran);
    handler.visit(changeSet1, new DatabaseChangeLog(), null, null);
    assertEquals(1, handler.getValidationErrors().getErrorMessages().size());
    assertTrue(handler.getValidationErrors().getErrorMessages().get(0).startsWith("Test message"));
    assertFalse(handler.validationPassed());
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors) CreateTableChange(liquibase.change.core.CreateTableChange) MockDatabase(liquibase.sdk.database.MockDatabase) Database(liquibase.database.Database) ArrayList(java.util.ArrayList) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 80 with ValidationErrors

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

the class AddForeignKeyConstraintGenerator method validate.

@Override
public ValidationErrors validate(AddForeignKeyConstraintStatement addForeignKeyConstraintStatement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    ValidationErrors validationErrors = new ValidationErrors();
    if ((addForeignKeyConstraintStatement.isInitiallyDeferred() || addForeignKeyConstraintStatement.isDeferrable()) && !database.supportsInitiallyDeferrableColumns()) {
        validationErrors.checkDisallowedField("initiallyDeferred", addForeignKeyConstraintStatement.isInitiallyDeferred(), database);
        validationErrors.checkDisallowedField("deferrable", addForeignKeyConstraintStatement.isDeferrable(), database);
    }
    validationErrors.checkRequiredField("baseColumnNames", addForeignKeyConstraintStatement.getBaseColumnNames());
    validationErrors.checkRequiredField("baseTableNames", addForeignKeyConstraintStatement.getBaseTableName());
    validationErrors.checkRequiredField("referencedColumnNames", addForeignKeyConstraintStatement.getReferencedColumnNames());
    validationErrors.checkRequiredField("referencedTableName", addForeignKeyConstraintStatement.getReferencedTableName());
    validationErrors.checkRequiredField("constraintName", addForeignKeyConstraintStatement.getConstraintName());
    validationErrors.checkDisallowedField("onDelete", addForeignKeyConstraintStatement.getOnDelete(), database, SybaseDatabase.class);
    return validationErrors;
}
Also used : 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