Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)

51903 to 54309 


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Samuel Langlois
2013-08-20 17:17:31 +00:00
parent 0a36e2af67
commit ab4ca7177f
1576 changed files with 36419 additions and 8603 deletions

View File

@@ -1,192 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
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.inOrder;
import java.util.Arrays;
import java.util.List;
import org.alfresco.util.schemacomp.DbObjectVisitor;
import org.alfresco.util.schemacomp.DbProperty;
import org.alfresco.util.schemacomp.DiffContext;
import org.alfresco.util.schemacomp.Difference.Where;
import org.alfresco.util.schemacomp.Results;
import org.alfresco.util.schemacomp.validator.AbstractDbValidator;
import org.alfresco.util.schemacomp.validator.DbValidator;
import org.hibernate.dialect.Dialect;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
/**
* Tests for the AbstractDbObject base class.
*
* @author Matt Ward
*/
@RunWith(MockitoJUnitRunner.class)
public class AbstractDbObjectTest
{
private ConcreteDbObject dbObject;
private @Mock Results differences;
private DiffContext ctx;
private @Mock Dialect dialect;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception
{
dbObject = new ConcreteDbObject("the_object");
ctx = new DiffContext(dialect, differences, null, null);
}
@Test
public void sameAs()
{
dbObject.setName(null);
assertFalse("Not the same.", dbObject.sameAs(null));
assertFalse("Not the same.", dbObject.sameAs(new ConcreteDbObject("other_obj_name")));
assertTrue("The very same", dbObject.sameAs(dbObject));
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 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));
}
@Test
public void diff()
{
ConcreteDbObject otherObject = new ConcreteDbObject("the_other_object");
dbObject.diff(otherObject, ctx);
InOrder inOrder = inOrder(differences);
// The name of the object should be diffed
inOrder.verify(differences).add(
Where.IN_BOTH_BUT_DIFFERENCE,
new DbProperty(dbObject, "name"),
new DbProperty(otherObject, "name"));
// Then the doDiff() method should be processed
inOrder.verify(differences).add(
Where.IN_BOTH_BUT_DIFFERENCE,
new DbProperty(dbObject, "someProp"),
new DbProperty(otherObject, "someProp"));
}
@Test
public void canGetValidators()
{
List<DbValidator> validators = dbObject.getValidators();
assertEquals(0, validators.size());
dbObject.setValidators(null);
validators = dbObject.getValidators();
assertEquals(0, validators.size());
dbObject.setValidators(validatorList(new TestValidator1(), new TestValidator2()));
validators = dbObject.getValidators();
assertEquals(2, validators.size());
assertEquals(TestValidator1.class, validators.get(0).getClass());
assertEquals(TestValidator2.class, validators.get(1).getClass());
}
/**
* Concrete DbObject for testing the AbstractDbObject base class.
*/
public static class ConcreteDbObject extends AbstractDbObject
{
private String someProp = "property value";
public ConcreteDbObject(String name)
{
super(null, name);
}
@Override
protected void doDiff(DbObject right, DiffContext ctx)
{
Results differences = ctx.getComparisonResults();
differences.add(
Where.IN_BOTH_BUT_DIFFERENCE,
new DbProperty(this, "someProp"),
new DbProperty(right, "someProp"));
}
@Override
public void accept(DbObjectVisitor visitor)
{
}
public String getSomeProp()
{
return this.someProp;
}
}
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)
{
return Arrays.asList(validators);
}
private static class TestValidator extends AbstractDbValidator
{
@Override
public void validate(DbObject reference, DbObject target, DiffContext ctx)
{
}
}
private static class TestValidator1 extends TestValidator
{
}
private static class TestValidator2 extends TestValidator
{
}
}

View File

@@ -1,104 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
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.
* @author Matt Ward
*/
public class ColumnTest extends DbObjectTestBase<Column>
{
private Column thisColumn;
private Column thatColumn;
@Before
public void setUp() throws Exception
{
thisColumn = new Column(null, "this_column", "VARCHAR2(100)", false);
thatColumn = new Column(null, "that_column", "NUMBER(10)", true);
}
@Override
protected Column getThisObject()
{
return thisColumn;
}
@Override
protected Column getThatObject()
{
return thatColumn;
}
@Override
protected void doDiffTests()
{
DbProperty thisTypeProp = new DbProperty(thisColumn, "type");
DbProperty thatTypeProp = new DbProperty(thatColumn, "type");
inOrder.verify(comparisonUtils).compareSimple(thisTypeProp, thatTypeProp, ctx);
DbProperty thisNullableProp = new DbProperty(thisColumn, "nullable");
DbProperty thatNullableProp = new DbProperty(thatColumn, "nullable");
inOrder.verify(comparisonUtils).compareSimple(thisNullableProp, thatNullableProp, ctx);
DbProperty thisOrderProp = new DbProperty(thisColumn, "order");
DbProperty thatOrderProp = new DbProperty(thatColumn, "order");
inOrder.verify(comparisonUtils).compareSimple(thisOrderProp, thatOrderProp, ctx);
DbProperty thisAutoIncProp = new DbProperty(thisColumn, "autoIncrement");
DbProperty thatAutoIncProp = new DbProperty(thatColumn, "autoIncrement");
inOrder.verify(comparisonUtils).compareSimple(thisAutoIncProp, thatAutoIncProp, ctx);
}
@Test
public void acceptVisitor()
{
thisColumn.accept(visitor);
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));
}
}

View File

@@ -1,102 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
import static org.mockito.Mockito.inOrder;
import java.util.ArrayList;
import java.util.List;
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.hibernate.dialect.Dialect;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
/**
* Abstract base class for tests for AbstractDbObject subclasses.
*
* @author Matt Ward
*/
@RunWith(MockitoJUnitRunner.class)
public abstract class DbObjectTestBase<T extends AbstractDbObject>
{
protected @Mock Dialect dialect;
protected @Mock Results differences;
protected DiffContext ctx;
protected @Mock ComparisonUtils comparisonUtils;
protected InOrder inOrder;
protected abstract T getThisObject();
protected abstract T getThatObject();
protected @Mock DbObjectVisitor visitor;
@Before
public final void baseSetUp()
{
// Check that the correct calls happened in the correct order.
List<Object> mocks = getMocksUsedInDiff();
inOrder = inOrder(mocks.toArray());
ctx = new DiffContext(dialect, differences, null, null);
}
/**
* Override to add additional mocks to the InOrder call verification.
*
* @return List<Object>
*/
protected List<Object> getMocksUsedInDiff()
{
List<Object> objects = new ArrayList<Object>();
objects.add(differences);
objects.add(comparisonUtils);
return objects;
}
@Test
public void canDiffObjects()
{
AbstractDbObject thisObject = getThisObject();
thisObject.setComparisonUtils(comparisonUtils);
AbstractDbObject thatObject = getThatObject();
thatObject.setComparisonUtils(comparisonUtils);
// Invoke the method under test
thisObject.diff(thatObject, ctx);
// The name of the object should be diffed
inOrder.verify(comparisonUtils).compareSimple(
new DbProperty(thisObject, "name"),
new DbProperty(thatObject, "name"),
ctx);
// Then the doDiff() method should be processed...
doDiffTests();
}
protected abstract void doDiffTests();
}

View File

@@ -1,127 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
import static org.junit.Assert.*;
import static org.mockito.Mockito.verify;
import org.alfresco.util.schemacomp.DbProperty;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for the ForeignKey class.
*
* @author Matt Ward
*/
public class ForeignKeyTest extends DbObjectTestBase<ForeignKey>
{
private ForeignKey thisFK, thatFK;
private Table parent;
@Before
public void setUp() throws Exception
{
parent = new Table("parent");
thisFK = new ForeignKey(null, "this_fk", "local_col", "target_table", "target_col");
thatFK = new ForeignKey(null, "that_fk", "local_col", "target_table", "target_col");
}
@Override
protected ForeignKey getThisObject()
{
return thisFK;
}
@Override
protected ForeignKey getThatObject()
{
return thatFK;
}
@Override
protected void doDiffTests()
{
inOrder.verify(comparisonUtils).compareSimple(
new DbProperty(thisFK, "localColumn"),
new DbProperty(thatFK, "localColumn"),
ctx);
inOrder.verify(comparisonUtils).compareSimple(
new DbProperty(thisFK, "targetTable"),
new DbProperty(thatFK, "targetTable"),
ctx);
inOrder.verify(comparisonUtils).compareSimple(
new DbProperty(thisFK, "targetColumn"),
new DbProperty(thatFK, "targetColumn"),
ctx);
}
@Test
public void acceptVisitor()
{
thisFK.accept(visitor);
verify(visitor).visit(thisFK);
}
@Test
public void sameAs()
{
// FKs are the same if they have all the same properties
thisFK = new ForeignKey(parent, "the_fk", "local_col", "target_table", "target_col");
thatFK = new ForeignKey(parent, "the_fk", "local_col", "target_table", "target_col");
assertTrue("FKs should be considered the same", thisFK.sameAs(thatFK));
// FKs are the same even if they have different names (but all other properties are the same)
thisFK = new ForeignKey(parent, "the_fk", "local_col", "target_table", "target_col");
thatFK = new ForeignKey(parent, "different_name", "local_col", "target_table", "target_col");
assertTrue("FKs should be considered the same", thisFK.sameAs(thatFK));
// Two references to the same FK are the same of course
assertTrue("FKs should be considered the same", thisFK.sameAs(thisFK));
// A null is never the same
assertFalse("FKs should be considered the different", thisFK.sameAs(null));
thisFK = new ForeignKey(parent, "the_fk", "local_col", "target_table", "target_col");
thatFK = new ForeignKey(new Table("different_parent"), "the_fk", "local_col", "target_table", "target_col");
assertFalse("FKs should be different: parents are different.", thisFK.sameAs(thatFK));
thisFK = new ForeignKey(parent, "the_fk", "local_col", "target_table", "target_col");
thatFK = new ForeignKey(parent, "the_fk", "local_col2", "target_table", "target_col");
assertFalse("FKs have different local columns.", thisFK.sameAs(thatFK));
thisFK = new ForeignKey(parent, "the_fk", "local_col", "target_table", "target_col");
thatFK = new ForeignKey(parent, "the_fk", "local_col", "target_table2", "target_col");
assertFalse("FKs have different target table.", thisFK.sameAs(thatFK));
thisFK = new ForeignKey(parent, "the_fk", "local_col", "target_table", "target_col");
thatFK = new ForeignKey(parent, "the_fk", "local_col", "target_table", "target_col2");
assertFalse("FKs have different target column.", thisFK.sameAs(thatFK));
// ALF-14129 fix test
thisFK = new ForeignKey(parent, "the_fk", "local_col", "target_table", "target_col");
thatFK = new ForeignKey(parent, "the_fk", "local_col", "TARGET_TABLE", "target_col");
assertTrue("FKs are case sensitive to targetTable's name.", thisFK.sameAs(thatFK));
}
}

View File

@@ -1,109 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
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.junit.Before;
import org.junit.Test;
/**
* Tests for the Index class.
* @author Matt Ward
*/
public class IndexTest extends DbObjectTestBase<Index>
{
private Table thisTable;
private Index thisIndex;
private Table thatTable;
private Index thatIndex;
@Before
public void setUp()
{
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
protected Index getThisObject()
{
return thisIndex;
}
@Override
protected Index getThatObject()
{
return thatIndex;
}
@Override
protected void doDiffTests()
{
inOrder.verify(comparisonUtils).compareSimpleOrderedLists(
new DbProperty(thisIndex, "columnNames"),
new DbProperty(thatIndex, "columnNames"),
ctx);
inOrder.verify(comparisonUtils).compareSimple(
new DbProperty(thisIndex, "unique"),
new DbProperty(thatIndex, "unique"),
ctx);
}
@Test
public void sameAs()
{
assertTrue("Indexes should be logically the same.",
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(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(thisTable, "this_index", Arrays.asList("name", "id", "age"))));
assertFalse("Indexes should be identified different (different name and column order)",
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(thisTable, "different_name", Arrays.asList("node_ref", "url"))));
}
@Test
public void acceptVisitor()
{
thisIndex.accept(visitor);
verify(visitor).visit(thisIndex);
}
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* Test suite for all the model tests.
*
* @author Matt Ward
*/
@RunWith(Suite.class)
@Suite.SuiteClasses(
{
AbstractDbObjectTest.class,
ColumnTest.class,
ForeignKeyTest.class,
IndexTest.class,
PrimaryKeyTest.class,
SchemaTest.class,
SequenceTest.class,
TableTest.class
})
public class ModelTestSuite
{
// Suite defined by annotation above.
}

View File

@@ -1,149 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import java.util.Arrays;
import java.util.List;
import org.alfresco.util.schemacomp.DbProperty;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for the PrimaryKey class.
*
* @author Matt Ward
*/
public class PrimaryKeyTest extends DbObjectTestBase<PrimaryKey>
{
private PrimaryKey thisPK;
private PrimaryKey thatPK;
private Table parent;
@Before
public void setUp()
{
parent = new Table("parent_table");
thisPK = new PrimaryKey(
parent,
"this_pk",
columns("id", "name", "age"),
columnOrders(2, 1, 3));
thatPK = new PrimaryKey(
parent,
"that_pk",
columns("a", "b"),
columnOrders(1, 2));
}
@Override
protected PrimaryKey getThisObject()
{
return thisPK;
}
@Override
protected PrimaryKey getThatObject()
{
return thatPK;
}
@Override
protected void doDiffTests()
{
inOrder.verify(comparisonUtils).compareSimpleOrderedLists(
new DbProperty(thisPK, "columnNames"),
new DbProperty(thatPK, "columnNames"),
ctx);
inOrder.verify(comparisonUtils).compareSimpleOrderedLists(
new DbProperty(thisPK, "columnOrders"),
new DbProperty(thatPK, "columnOrders"),
ctx);
}
@Test
public void acceptVisitor()
{
thisPK.accept(visitor);
verify(visitor).visit(thisPK);
}
@Test
public void sameAs()
{
// Same parent, same name, same columns and ordering - must be same (intended) PK
assertTrue("Primary keys should be logically equivalent",
thisPK.sameAs(
new PrimaryKey(
parent,
"this_pk",
columns("id", "name", "age"),
columnOrders(2, 1, 3))));
// Different names - still the same PK
assertTrue("Primary keys should be logically equivalent",
thisPK.sameAs(
new PrimaryKey(parent, "different_name",
columns("id", "name", "age"),
columnOrders(2, 1, 3))));
// Same object reference ("physically" same object)
assertTrue("PKs should be the same", thisPK.sameAs(thisPK));
// Same parent, same type, but different everything else!
assertTrue("Primary keys should be logically equivalent",
thisPK.sameAs(
new PrimaryKey(parent, "different_name",
columns("di", "eman", "ega"),
columnOrders(1, 2, 3))));
// Same parent, but different type
assertFalse("PKs are never the same as a non-PK",
thisPK.sameAs(new Index(parent, "wrong_type", columns())));
// Different parents
Table otherParent = new Table("other_parent");
assertFalse("PKs should be considered different (different parents)",
thisPK.sameAs(
new PrimaryKey(otherParent, "this_pk",
columns("id", "name", "age"),
columnOrders(2, 1, 3))));
// Other PK is null
assertFalse("PKs should not be considered the same (other PK is null)",
thisPK.sameAs(null));
}
private List<String> columns(String... columns)
{
return Arrays.asList(columns);
}
private List<Integer> columnOrders(Integer... columnOrders)
{
return Arrays.asList(columnOrders);
}
}

View File

@@ -1,109 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
import static org.junit.Assert.*;
import static org.mockito.Mockito.verify;
import org.alfresco.util.schemacomp.DbProperty;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
/**
* Tests for the Schema class.
*
* @author Matt Ward
*/
@RunWith(MockitoJUnitRunner.class)
public class SchemaTest extends DbObjectTestBase<Schema>
{
private Schema left;
private Schema right;
@Before
public void setUp()
{
left = new Schema("left_schema");
right = new Schema("right_schema");
}
@Override
protected Schema getThisObject()
{
return left;
}
@Override
protected Schema getThatObject()
{
return right;
}
@Override
protected void doDiffTests()
{
// We need to be warned if comparing, for example a version 500 schema with a
// version 501 schema.
inOrder.verify(comparisonUtils).compareSimple(
new DbProperty(left, "version"),
new DbProperty(right, "version"),
ctx);
// In addition to the base class functionality, Schema.diff() compares
// the DbObjects held in the other schema with its own DbObjects.
inOrder.verify(comparisonUtils).compareCollections(left.objects, right.objects, ctx);
}
@Test
public void acceptVisitor()
{
DbObject dbo1 = Mockito.mock(DbObject.class);
left.add(dbo1);
DbObject dbo2 = Mockito.mock(DbObject.class);
left.add(dbo2);
DbObject dbo3 = Mockito.mock(DbObject.class);
left.add(dbo3);
left.accept(visitor);
verify(dbo1).accept(visitor);
verify(dbo2).accept(visitor);
verify(dbo3).accept(visitor);
verify(visitor).visit(left);
}
@Test
public void sameAs()
{
// We have to assume that two schemas are always the same, regardless of name,
// otherwise unless the reference schema has the same name as the target database
// all the comparisons will fail - and users can choose to install databases with any schema
// name they choose.
assertTrue("Schemas should be considered the same", left.sameAs(right));
// Things are always the same as themselves.
assertTrue("Schemas are the same physical object", left.sameAs(left));
assertFalse("A table is not the same as a schema", left.sameAs(new Table("left_schema")));
assertFalse("null is not the same as a schema", left.sameAs(null));
}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
import static org.mockito.Mockito.verify;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for the Sequence class.
* @author Matt Ward
*/
public class SequenceTest extends DbObjectTestBase<Sequence>
{
private Sequence thisSequence;
private Sequence thatSequence;
@Before
public void setUp()
{
thisSequence = new Sequence(null, "this_sequence");
thatSequence = new Sequence(null, "that_sequence");
}
@Test
public void acceptVisitor()
{
thisSequence.accept(visitor);
verify(visitor).visit(thisSequence);
}
@Override
protected Sequence getThisObject()
{
return thisSequence;
}
@Override
protected Sequence getThatObject()
{
return thatSequence;
}
@Override
protected void doDiffTests()
{
// Nothing extra to diff.
}
}

View File

@@ -1,135 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
import static org.mockito.Mockito.verify;
import java.util.ArrayList;
import java.util.List;
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;
/**
* Tests for the Table class.
*
* @author Matt Ward
*/
@RunWith(MockitoJUnitRunner.class)
public class TableTest extends DbObjectTestBase<Table>
{
private Table table;
private Table otherTable;
private List<Column> columns;
private @Mock PrimaryKey primaryKey;
private List<ForeignKey> foreignKeys;
private List<Index> indexes;
@Before
public void setUp() throws Exception
{
columns = listOfMocks(Column.class, 3);
foreignKeys = listOfMocks(ForeignKey.class, 1);
indexes = listOfMocks(Index.class, 1);
table = new Table(null, "the_table", columns, primaryKey, foreignKeys, indexes);
otherTable = new Table(null, "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()
{
List<Object> mocks = super.getMocksUsedInDiff();
mocks.add(primaryKey);
return mocks;
}
public void doDiffTests()
{
// Check columns
inOrder.verify(comparisonUtils).compareCollections(table.getColumns(), otherTable.getColumns(), ctx);
// Check primary key
inOrder.verify(primaryKey).diff(otherTable.getPrimaryKey(), ctx);
// Check foreign keys
inOrder.verify(comparisonUtils).compareCollections(
table.getForeignKeys(), otherTable.getForeignKeys(), ctx);
// Check indexes
inOrder.verify(comparisonUtils).compareCollections(
table.getIndexes(), otherTable.getIndexes(), ctx);
}
@Override
protected Table getThisObject()
{
return table;
}
@Override
protected Table getThatObject()
{
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);
}
}