mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-10771: adding validation to schema compare tool
Added support to DbObjects to accept visitors Added ValidatingVisitor to invoke suitable validator on each DbObject Added NameValidator and NullValidator to operate on DbObject types Added test suites git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31494 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -20,14 +20,21 @@ package org.alfresco.util.schemacomp.model;
|
||||
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.util.schemacomp.Result.Strength;
|
||||
import org.apache.poi.ss.formula.functions.Columns;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
@@ -40,16 +47,16 @@ public class TableTest extends DbObjectTestBase<Table>
|
||||
{
|
||||
private Table table;
|
||||
private Table otherTable;
|
||||
private Collection<Column> columns;
|
||||
private List<Column> columns;
|
||||
private @Mock PrimaryKey primaryKey;
|
||||
private Collection<ForeignKey> foreignKeys;
|
||||
private Collection<Index> indexes;
|
||||
private List<ForeignKey> foreignKeys;
|
||||
private List<Index> indexes;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
columns = asList(
|
||||
/*columns = asList(
|
||||
new Column("columnA", "VARCHAR2(50)", false),
|
||||
new Column("columnB", "VARCHAR2(100)", false),
|
||||
new Column("columnC", "VARCHAR2(200)", true));
|
||||
@@ -58,11 +65,31 @@ public class TableTest extends DbObjectTestBase<Table>
|
||||
|
||||
indexes = asList(new Index("an_index", asList("columnA", "columnC")));
|
||||
|
||||
table = new Table("the_table", columns, primaryKey, foreignKeys, indexes);
|
||||
otherTable = new Table("the_other_table", columns, primaryKey, foreignKeys, indexes);*/
|
||||
|
||||
columns = listOfMocks(Column.class, 3);
|
||||
|
||||
foreignKeys = listOfMocks(ForeignKey.class, 1);
|
||||
|
||||
indexes = listOfMocks(Index.class, 1);
|
||||
|
||||
table = new Table("the_table", columns, primaryKey, foreignKeys, indexes);
|
||||
otherTable = new Table("the_other_table", columns, primaryKey, foreignKeys, indexes);
|
||||
}
|
||||
|
||||
|
||||
private <T> List<T> listOfMocks(Class<T> c, int size)
|
||||
{
|
||||
List<T> list = new ArrayList<T>(size);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
list.add((T) Mockito.mock(c));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<Object> getMocksUsedInDiff()
|
||||
{
|
||||
@@ -99,4 +126,31 @@ public class TableTest extends DbObjectTestBase<Table>
|
||||
{
|
||||
return otherTable;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void acceptVisitor()
|
||||
{
|
||||
table.setColumns(columns);
|
||||
table.setForeignKeys(foreignKeys);
|
||||
table.setIndexes(indexes);
|
||||
table.setPrimaryKey(primaryKey);
|
||||
|
||||
table.accept(visitor);
|
||||
|
||||
// All the children should be visited
|
||||
List<DbObject> children = new ArrayList<DbObject>();
|
||||
children.addAll(columns);
|
||||
children.addAll(foreignKeys);
|
||||
children.addAll(indexes);
|
||||
children.add(primaryKey);
|
||||
|
||||
for (DbObject child : children)
|
||||
{
|
||||
verify(child).accept(visitor);
|
||||
}
|
||||
|
||||
// The parent itself should be visited
|
||||
verify(visitor).visit(table);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user