use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class DefaultComparisonUtilsTest method propertyIsNotComparedWhenValidatorTakesResponsibility.
@Test
public void propertyIsNotComparedWhenValidatorTakesResponsibility() {
DbObject db1 = new DatabaseObject("db1");
DbProperty db1NameProp = new DbProperty(db1, "name");
DbObject db2 = new DatabaseObject("db2");
DbProperty db2NameProp = new DbProperty(db2, "name");
// Using mock to decouple unit test from actual NameValidator.
DbValidator nameValidator = mock(DbValidator.class);
when(nameValidator.validates("name")).thenReturn(true);
db1.getValidators().add(nameValidator);
comparisonUtils.compareSimple(db1NameProp, db2NameProp, ctx);
verify(differences, never()).add(Where.IN_BOTH_BUT_DIFFERENCE, db1NameProp, db2NameProp);
}
use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class DefaultComparisonUtilsTest method orderingFaultsWhenCollectionsSameSize.
// Check that two 'simple' collections (i.e. composed of non DbObject objects)
// must have the same items at the same indexes for those items to qualify as being in both
// collections with no difference. This is important for, e.g. column orderings in
// indexes or primary keys.
@Test
public void orderingFaultsWhenCollectionsSameSize() {
Collection<Object> left = new ArrayList<Object>();
Collections.<Object>addAll(left, 0, "one", 2, "3", "4_this", 5, "6_this", "seven");
DbObject leftDbObj = new DbObjectWithCollection("left", left);
DbProperty leftCollProp = new DbProperty(leftDbObj, "collection");
Collection<Object> right = new ArrayList<Object>();
Collections.<Object>addAll(right, 0, "one", 2, "3", "4_that", 5, "6_that", "seven");
DbObject rightDbObj = new DbObjectWithCollection("right", right);
DbProperty rightCollProp = new DbProperty(rightDbObj, "collection");
comparisonUtils.compareSimpleOrderedLists(leftCollProp, rightCollProp, ctx);
verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(leftDbObj, "collection[0]", 0), dbPropForValue(rightDbObj, "collection[0]", 0));
verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(leftDbObj, "collection[1]", "one"), dbPropForValue(rightDbObj, "collection[1]", "one"));
verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(leftDbObj, "collection[2]", 2), dbPropForValue(rightDbObj, "collection[2]", 2));
verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(leftDbObj, "collection[3]", "3"), dbPropForValue(rightDbObj, "collection[3]", "3"));
verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, dbPropForValue(leftDbObj, "collection[4]", "4_this"), dbPropForValue(rightDbObj, "collection[4]", "4_that"));
verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(leftDbObj, "collection[5]", 5), dbPropForValue(rightDbObj, "collection[5]", 5));
verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, dbPropForValue(leftDbObj, "collection[6]", "6_this"), dbPropForValue(rightDbObj, "collection[6]", "6_that"));
verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(leftDbObj, "collection[7]", "seven"), dbPropForValue(rightDbObj, "collection[7]", "seven"));
}
use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class DefaultComparisonUtilsTest method createMockDbObjects.
private List<DbObject> createMockDbObjects(int size) {
ArrayList<DbObject> dbObjects = new ArrayList<DbObject>(size);
for (int i = 0; i < size; i++) {
DbObject dbo = mock(DbObject.class);
when(dbo.toString()).thenReturn("Mock DbObject " + i);
dbObjects.add(dbo);
}
return dbObjects;
}
use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class DefaultComparisonUtilsTest method compareCollections.
@Test
public void compareCollections() {
DbObject db1 = new DatabaseObject("db1");
// only in left
DbObject db2 = new DatabaseObject("db2");
// only in right
DbObject db3 = new DatabaseObject("db3");
DbObject db4 = new DatabaseObject("db4");
Collection<DbObject> left = new ArrayList<DbObject>();
Collections.addAll(left, db1, db2, db4);
Collection<DbObject> right = new ArrayList<DbObject>();
Collections.addAll(right, db1, db3, db4);
comparisonUtils.compareCollections(left, right, ctx);
// Differences and ommissions are noticed...
verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, new DbProperty(db1), new DbProperty(db1));
verify(differences).add(Where.ONLY_IN_REFERENCE, new DbProperty(db2), null);
verify(differences).add(Where.ONLY_IN_TARGET, null, new DbProperty(db3));
verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, new DbProperty(db4), new DbProperty(db4));
}
use of org.alfresco.util.schemacomp.model.DbObject in project alfresco-repository by Alfresco.
the class DefaultComparisonUtilsTest method objectIsNotComparedWhenValidatorTakesResponsibility.
@Test
public void objectIsNotComparedWhenValidatorTakesResponsibility() {
DbObject db1 = new DatabaseObject("db1");
DbObject db2 = new DatabaseObject("db2");
DbObject db3 = new DatabaseObject("db3");
DbObject db4 = new DatabaseObject("db4");
Collection<DbObject> reference = new ArrayList<DbObject>();
Collections.addAll(reference, db1, db3);
Collection<DbObject> target = new ArrayList<DbObject>();
Collections.addAll(target, db2, db4);
DbValidator validator = mock(DbValidator.class);
when(validator.validatesFullObject()).thenReturn(true);
db1.getValidators().add(validator);
db2.getValidators().add(validator);
comparisonUtils.compareCollections(reference, target, ctx);
verify(differences, never()).add(Where.ONLY_IN_REFERENCE, new DbProperty(db1), null);
verify(differences, never()).add(Where.ONLY_IN_TARGET, null, new DbProperty(db2));
verify(differences).add(Where.ONLY_IN_REFERENCE, new DbProperty(db3), null);
verify(differences).add(Where.ONLY_IN_TARGET, null, new DbProperty(db4));
}
Aggregations