Search in sources :

Example 21 with DbObject

use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.

the class DefaultComparisonUtilsTest method compareCollectionsWithMultipleMatches.

@Test
public void compareCollectionsWithMultipleMatches() {
    DbObject db2 = new DatabaseObject("db2");
    DbObject db3 = new DatabaseObject("db3");
    DbObject db4 = new DatabaseObject("db4");
    DbObject db1 = new DatabaseObject("db1", db2, db3);
    Collection<DbObject> left = new ArrayList<DbObject>();
    Collections.addAll(left, db1, db4);
    Collection<DbObject> right = new ArrayList<DbObject>();
    Collections.addAll(right, db1, db2, db3);
    comparisonUtils.compareCollections(left, right, ctx);
    // Differences and ommissions are noticed...
    verify(differences).add(Where.ONLY_IN_REFERENCE, new DbProperty(db4), null);
    verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, new DbProperty(db1), new DbProperty(db1));
    verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, new DbProperty(db1), new DbProperty(db2));
    verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, new DbProperty(db1), new DbProperty(db3));
}
Also used : DbObject(org.alfresco.util.schemacomp.model.DbObject) AbstractDbObject(org.alfresco.util.schemacomp.model.AbstractDbObject) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 22 with DbObject

use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.

the class SchemaComparatorTest method systemGeneratedPrimaryKeyAndIndex.

/**
 * Tests index of primary key validation, problem found when comparing DB2 schemas (now EOLed) which has
 * system generated indexes for primary keys, but might still be useful as a test.
 */
@Test
public void systemGeneratedPrimaryKeyAndIndex() {
    reference = new Schema("schema", "alf_", 9012, false);
    target = new Schema("schema", "alf_", 9012, false);
    NameValidator validator = new NameValidator();
    validator.setProperty("pattern", "SQL[0-9]+");
    final List<DbValidator> validators = new ArrayList<DbValidator>();
    validators.add(new NameValidator());
    reference.add(new Table(reference, "ALF_ACL_CHANGE_SET", columns(false, "id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), new PrimaryKey(null, "SQL120116153559440", Arrays.asList("id", "nodeRef"), Arrays.asList(1, 2)), fkeys(), indexes("SQL120116153559441 [unique] ID_", "fooX ID_")));
    // Target schema's database objects
    target.add(new Table(target, "ALF_ACL_CHANGE_SET", columns(false, "id NUMBER(10)", "name VARCHAR2(150)", "nodeRef VARCHAR2(200)"), new PrimaryKey(null, "SQL120116153559442", Arrays.asList("id", "nodeRef"), Arrays.asList(1, 2)), fkeys(), indexes("SQL120116153559443 [unique] ID_", "fooX ID_")));
    reference.add(new Table(reference, "ALF_LOCK_RESOURCE", columns(false, "id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), new PrimaryKey(null, "SQL120116153554310", Arrays.asList("ID", "int"), Arrays.asList(1, 2)), fkeys(), indexes("SQL120116153616440 [unique] ID_")));
    target.add(new Table(reference, "ALF_LOCK_RESOURCE", columns(false, "id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), new PrimaryKey(null, "SQL120116153554313", Arrays.asList("ID", "int"), Arrays.asList(1, 2)), fkeys(), indexes("SQL120116153616444 [unique] ID_")));
    /**
     * Now plug in the pattern validator
     */
    DbObjectVisitor visitor = new DbObjectVisitor() {

        @Override
        public void visit(DbObject dbObject) {
            if (dbObject instanceof Index) {
                dbObject.setValidators(validators);
            }
            if (dbObject instanceof PrimaryKey) {
                dbObject.setValidators(validators);
            }
        }
    };
    reference.accept(visitor);
    target.accept(visitor);
    comparator = new SchemaComparator(reference, target, dialect);
    comparator.validateAndCompare();
    // See stdout for diagnostics dump...
    dumpDiffs(comparator.getComparisonResults(), false);
    dumpValidation(comparator.getComparisonResults());
    Results results = comparator.getComparisonResults();
    // There are no logical differences
    assertEquals(0, results.size());
}
Also used : Table(org.alfresco.util.schemacomp.model.Table) DbObject(org.alfresco.util.schemacomp.model.DbObject) NameValidator(org.alfresco.util.schemacomp.validator.NameValidator) Schema(org.alfresco.util.schemacomp.model.Schema) ArrayList(java.util.ArrayList) PrimaryKey(org.alfresco.util.schemacomp.model.PrimaryKey) Index(org.alfresco.util.schemacomp.model.Index) DbValidator(org.alfresco.util.schemacomp.validator.DbValidator) Test(org.junit.Test)

Aggregations

DbObject (org.alfresco.util.schemacomp.model.DbObject)22 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 AbstractDbObject (org.alfresco.util.schemacomp.model.AbstractDbObject)12 DbValidator (org.alfresco.util.schemacomp.validator.DbValidator)9 Table (org.alfresco.util.schemacomp.model.Table)5 Schema (org.alfresco.util.schemacomp.model.Schema)4 Index (org.alfresco.util.schemacomp.model.Index)3 Sequence (org.alfresco.util.schemacomp.model.Sequence)3 PrimaryKey (org.alfresco.util.schemacomp.model.PrimaryKey)2 Collection (java.util.Collection)1 Where (org.alfresco.util.schemacomp.Difference.Where)1 Column (org.alfresco.util.schemacomp.model.Column)1 ForeignKey (org.alfresco.util.schemacomp.model.ForeignKey)1 NameValidator (org.alfresco.util.schemacomp.validator.NameValidator)1