ALF-10771: schema validation and differences rules

Laying some groundwork for the main code.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31921 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2011-11-14 10:16:59 +00:00
parent 60688d34b9
commit 4c863f5e0a
16 changed files with 165 additions and 84 deletions

View File

@@ -60,7 +60,7 @@ public class AbstractDbObjectTest
public void setUp() throws Exception
{
dbObject = new ConcreteDbObject("the_object");
ctx = new DiffContext(dialect, differences, new ArrayList<ValidationResult>());
ctx = new DiffContext(dialect, differences, new ArrayList<ValidationResult>(), null, null);
}
@Test

View File

@@ -61,7 +61,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>());
ctx = new DiffContext(dialect, differences, new ArrayList<ValidationResult>(), null, null);
}

View File

@@ -122,17 +122,24 @@ public class Index extends AbstractDbObject
{
Index other = (Index) o;
if (getName() != null)
// An index can only be 'the same' if it belongs to the correct table.
if (!getParent().sameAs(other.getParent()))
{
if (getName().equals(other.getName()))
{
return true;
}
else
{
return columnNames.equals(other.getColumnNames());
}
return false;
}
// If it has the same name, then it is intended to be the same index
if (getName() != null && getName().equals(other.getName()))
{
return true;
}
else
{
// The name may be different, but if it has the same parent table (see above)
// and indexes the same columns, then it is the same index.
return columnNames.equals(other.getColumnNames());
}
}
return false;

View File

@@ -18,14 +18,17 @@
*/
package org.alfresco.util.schemacomp.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import java.util.Arrays;
import org.alfresco.util.schemacomp.DbProperty;
import org.alfresco.util.schemacomp.Result.Strength;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.verify;
/**
@@ -34,14 +37,18 @@ import static org.mockito.Mockito.verify;
*/
public class IndexTest extends DbObjectTestBase<Index>
{
private Table thisTable;
private Index thisIndex;
private Table thatTable;
private Index thatIndex;
@Before
public void setUp()
{
thisIndex = new Index(null, "this_index", Arrays.asList("id", "name", "age"));
thatIndex = new Index(null, "that_index", Arrays.asList("a", "b"));
thisTable = new Table("this_table");
thisIndex = new Index(thisTable, "this_index", Arrays.asList("id", "name", "age"));
thatTable = new Table("that_table");
thatIndex = new Index(thatTable, "that_index", Arrays.asList("a", "b"));
}
@Override
@@ -82,19 +89,23 @@ public class IndexTest extends DbObjectTestBase<Index>
public void sameAs()
{
assertTrue("Indexes should be logically the same.",
thisIndex.sameAs(new Index(null, "this_index", Arrays.asList("id", "name", "age"))));
thisIndex.sameAs(new Index(thisTable, "this_index", Arrays.asList("id", "name", "age"))));
assertFalse("Indexes have logically different parents",
thisIndex.sameAs(new Index(thatTable, "this_index", Arrays.asList("id", "name", "age"))));
assertTrue("Indexes should be logically the same, despite different names (as same column order)",
thisIndex.sameAs(new Index(null, "different_name", Arrays.asList("id", "name", "age"))));
thisIndex.sameAs(new Index(thisTable, "different_name", Arrays.asList("id", "name", "age"))));
assertTrue("Indexes should be identified as the same despite different column order (as same name).",
thisIndex.sameAs(new Index(null, "this_index", Arrays.asList("name", "id", "age"))));
thisIndex.sameAs(new Index(thisTable, "this_index", Arrays.asList("name", "id", "age"))));
assertFalse("Indexes should be identified different (different name and column order)",
thisIndex.sameAs(new Index(null, "different_name", Arrays.asList("name", "id", "age"))));
thisIndex.sameAs(new Index(thisTable, "different_name", Arrays.asList("name", "id", "age"))));
assertFalse("Indexes should be identified different (different name & different columns)",
thisIndex.sameAs(new Index(null, "different_name", Arrays.asList("node_ref", "url"))));
thisIndex.sameAs(new Index(thisTable, "different_name", Arrays.asList("node_ref", "url"))));
}

View File

@@ -220,8 +220,11 @@ public class Table extends AbstractDbObject
private List<DbObject> getChildren()
{
List<DbObject> children = new ArrayList<DbObject>();
children.addAll(columns);
children.add(primaryKey);
children.addAll(columns);
if (primaryKey != null)
{
children.add(primaryKey);
}
children.addAll(foreignKeys);
children.addAll(indexes);
return children;