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));
}
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());
}
Aggregations