mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-11518 and ALF-11519: unify separate validation/differences lists and move text generation to Result classes.
ALF-11518: Unify differences and validation results lists ALF-11519: Move validation/diff result text generation from SchemaBootstrap to result classes. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32110 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -96,16 +96,35 @@ public abstract class AbstractDbObject implements DbObject
|
||||
@Override
|
||||
public boolean sameAs(DbObject other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this == other)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!this.getClass().equals(other.getClass()))
|
||||
{
|
||||
// Objects are not the same type, even if they have the same name and parent
|
||||
return false;
|
||||
}
|
||||
if (getName() != null && other != null && other.getName() != null)
|
||||
{
|
||||
return getName().equals(other.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only other way we can know if they are the same is if they are
|
||||
// the exact same object reference.
|
||||
return this == other;
|
||||
boolean sameParent = false;
|
||||
|
||||
if (getParent() == null && other.getParent() == null)
|
||||
{
|
||||
sameParent = true;
|
||||
}
|
||||
else if (getParent() != null && getParent().sameAs(other.getParent()))
|
||||
{
|
||||
sameParent = true;
|
||||
}
|
||||
return sameParent && getName().equals(other.getName());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -23,7 +23,6 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -33,7 +32,6 @@ import org.alfresco.util.schemacomp.DiffContext;
|
||||
import org.alfresco.util.schemacomp.Difference.Where;
|
||||
import org.alfresco.util.schemacomp.Result.Strength;
|
||||
import org.alfresco.util.schemacomp.Results;
|
||||
import org.alfresco.util.schemacomp.ValidationResult;
|
||||
import org.alfresco.util.schemacomp.validator.AbstractDbValidator;
|
||||
import org.alfresco.util.schemacomp.validator.DbValidator;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
@@ -64,7 +62,7 @@ public class AbstractDbObjectTest
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
dbObject = new ConcreteDbObject("the_object");
|
||||
ctx = new DiffContext(dialect, differences, new ArrayList<ValidationResult>(), null, null);
|
||||
ctx = new DiffContext(dialect, differences, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +81,8 @@ public class AbstractDbObjectTest
|
||||
|
||||
dbObject.setName("the_name");
|
||||
assertFalse("Not the same.", dbObject.sameAs(null));
|
||||
assertFalse("Not the same.", dbObject.sameAs(new ConcreteDbObject("different_name")));
|
||||
assertFalse("Not the same.", dbObject.sameAs(new ConcreteDbObject("different_name")));
|
||||
assertFalse("Not the same type", dbObject.sameAs(new AnotherConcreteDbObject("the_name")));
|
||||
assertTrue("Logically the same object.", dbObject.sameAs(new ConcreteDbObject("the_name")));
|
||||
assertTrue("The very same object with non-null name", dbObject.sameAs(dbObject));
|
||||
}
|
||||
@@ -146,7 +145,7 @@ public class AbstractDbObjectTest
|
||||
@Override
|
||||
protected void doDiff(DbObject right, DiffContext ctx, Strength strength)
|
||||
{
|
||||
Results differences = ctx.getDifferences();
|
||||
Results differences = ctx.getComparisonResults();
|
||||
differences.add(
|
||||
Where.IN_BOTH_BUT_DIFFERENCE,
|
||||
new DbProperty(this, "someProp"),
|
||||
@@ -164,6 +163,19 @@ public class AbstractDbObjectTest
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnotherConcreteDbObject extends AbstractDbObject
|
||||
{
|
||||
public AnotherConcreteDbObject(String name)
|
||||
{
|
||||
super(null, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(DbObjectVisitor visitor)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<DbValidator> validatorList(DbValidator... validators)
|
||||
{
|
||||
|
@@ -131,4 +131,28 @@ public class Column extends AbstractDbObject
|
||||
{
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameAs(DbObject other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this == other)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (getClass().equals(other.getClass()))
|
||||
{
|
||||
if (getName() != null && other.getName() != null)
|
||||
{
|
||||
if (getParent() != null && other.getParent() != null && getParent().sameAs(other.getParent()))
|
||||
{
|
||||
return getName().equals(other.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import org.alfresco.util.schemacomp.DbProperty;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests for the Column class.
|
||||
@@ -73,5 +74,24 @@ public class ColumnTest extends DbObjectTestBase<Column>
|
||||
|
||||
verify(visitor).visit(thisColumn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameAs()
|
||||
{
|
||||
Table thisTable = new Table("the_table");
|
||||
thisColumn = new Column(thisTable, "this_column", "VARCHAR2(100)", false);
|
||||
|
||||
Table thatTable = new Table("the_table");
|
||||
thatColumn = new Column(thatTable, "this_column", "VARCHAR2(100)", false);
|
||||
|
||||
// This column, whilst having the same name as thisColumn, has a different
|
||||
// parent table - and so is not considered 'the same'.
|
||||
Table anotherTable = new Table("another_table");
|
||||
Column anotherColumn = new Column(anotherTable, "this_column", "VARCHAR2(100)", false);
|
||||
|
||||
assertTrue("Column should always be the same as itself", thisColumn.sameAs(thisColumn));
|
||||
assertTrue("Columns should be the same due to same parent table names", thisColumn.sameAs(thatColumn));
|
||||
assertFalse("Should NOT be the same due to different parent table names", thisColumn.sameAs(anotherColumn));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.util.schemacomp.model;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -27,9 +27,8 @@ import org.alfresco.util.schemacomp.ComparisonUtils;
|
||||
import org.alfresco.util.schemacomp.DbObjectVisitor;
|
||||
import org.alfresco.util.schemacomp.DbProperty;
|
||||
import org.alfresco.util.schemacomp.DiffContext;
|
||||
import org.alfresco.util.schemacomp.Results;
|
||||
import org.alfresco.util.schemacomp.Result.Strength;
|
||||
import org.alfresco.util.schemacomp.ValidationResult;
|
||||
import org.alfresco.util.schemacomp.Results;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -61,7 +60,7 @@ public abstract class DbObjectTestBase<T extends AbstractDbObject>
|
||||
// Check that the correct calls happened in the correct order.
|
||||
List<Object> mocks = getMocksUsedInDiff();
|
||||
inOrder = inOrder(mocks.toArray());
|
||||
ctx = new DiffContext(dialect, differences, new ArrayList<ValidationResult>(), null, null);
|
||||
ctx = new DiffContext(dialect, differences, null, null);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user