mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
125781 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1) 125603 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127808 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
108 lines
3.9 KiB
Java
108 lines
3.9 KiB
Java
package org.alfresco.util.schemacomp;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
import org.alfresco.util.schemacomp.model.DbObject;
|
|
import org.alfresco.util.schemacomp.model.Index;
|
|
import org.alfresco.util.schemacomp.model.Schema;
|
|
import org.alfresco.util.schemacomp.model.Table;
|
|
import org.alfresco.util.schemacomp.validator.DbValidator;
|
|
import org.hibernate.dialect.MySQL5InnoDBDialect;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import static org.junit.Assert.*;
|
|
import org.mockito.Mockito;
|
|
|
|
/**
|
|
* Tests for the ValidatingVisitor class.
|
|
*
|
|
* @author Matt Ward
|
|
*/
|
|
public class ValidatingVisitorTest
|
|
{
|
|
private DiffContext ctx;
|
|
private ValidatingVisitor visitor;
|
|
private Table refTable;
|
|
private Table targetTable;
|
|
private Schema refSchema;
|
|
private Schema targetSchema;
|
|
private Index refIndex;
|
|
private Index targetIndex1;
|
|
private Index targetIndex2;
|
|
private Index targetIndex3;
|
|
private List<DbValidator> validators;
|
|
private ComparisonUtils comparisonUtils;
|
|
|
|
|
|
@Before
|
|
public void setUp() throws Exception
|
|
{
|
|
refTable = new Table("reference_table");
|
|
refIndex = new Index(refTable, "index_name", Arrays.asList("a", "b", "c"));
|
|
ctx = new DiffContext(new MySQL5InnoDBDialect(), refSchema, targetSchema);
|
|
visitor = new ValidatingVisitor(ctx);
|
|
|
|
validators = new ArrayList<DbValidator>();
|
|
validators.add(Mockito.mock(DbValidator.class));
|
|
validators.add(Mockito.mock(DbValidator.class));
|
|
refIndex.setValidators(validators);
|
|
|
|
targetTable = new Table("target_table");
|
|
targetIndex1 = new Index(targetTable, "index_name", Arrays.asList("a", "b", "c"));
|
|
targetIndex2 = new Index(targetTable, "another_index", Arrays.asList("a", "b", "c"));
|
|
targetIndex3 = new Index(targetTable, "index_name", Arrays.asList("e", "f"));
|
|
|
|
comparisonUtils = Mockito.mock(ComparisonUtils.class);
|
|
visitor.setComparisonUtils(comparisonUtils);
|
|
}
|
|
|
|
|
|
@Test
|
|
public void canValidate()
|
|
{
|
|
Mockito.when(comparisonUtils.findEquivalentObjects(refSchema, refIndex)).
|
|
thenReturn(Arrays.asList((DbObject) targetIndex1, targetIndex2, targetIndex3));
|
|
|
|
// Validate all instances of the target schema's indexes that are equivalent to this index
|
|
visitor.visit(refIndex);
|
|
|
|
Mockito.verify(validators.get(0)).validate(refIndex, targetIndex1, ctx);
|
|
Mockito.verify(validators.get(0)).validate(refIndex, targetIndex2, ctx);
|
|
Mockito.verify(validators.get(0)).validate(refIndex, targetIndex3, ctx);
|
|
|
|
Mockito.verify(validators.get(1)).validate(refIndex, targetIndex1, ctx);
|
|
Mockito.verify(validators.get(1)).validate(refIndex, targetIndex2, ctx);
|
|
Mockito.verify(validators.get(1)).validate(refIndex, targetIndex3, ctx);
|
|
}
|
|
|
|
|
|
@Test
|
|
public void redundantDbObjectsAreNoticed()
|
|
{
|
|
Mockito.when(comparisonUtils.findEquivalentObjects(refSchema, refIndex)).
|
|
thenReturn(Arrays.asList((DbObject) targetIndex1, targetIndex2, targetIndex3));
|
|
|
|
// Validate all instances of the target schema's indexes that are equivalent to this index
|
|
visitor.visit(refIndex);
|
|
|
|
assertEquals(1, ctx.getComparisonResults().size());
|
|
assertEquals(RedundantDbObject.class, ctx.getComparisonResults().get(0).getClass());
|
|
}
|
|
|
|
|
|
@Test
|
|
public void nonRedundantDbObjectsAreNoticed()
|
|
{
|
|
Mockito.when(comparisonUtils.findEquivalentObjects(refSchema, refIndex)).
|
|
thenReturn(Arrays.asList((DbObject) targetIndex1));
|
|
|
|
// Validate all instances of the target schema's indexes that are equivalent to this index
|
|
visitor.visit(refIndex);
|
|
|
|
assertEquals(0, ctx.getComparisonResults().size());
|
|
}
|
|
}
|