mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-10771: schema validation and differences rules
Validation serialized and deserialized in XML. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31942 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,12 +18,17 @@
|
||||
*/
|
||||
package org.alfresco.util.schemacomp.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.util.schemacomp.ComparisonUtils;
|
||||
import org.alfresco.util.schemacomp.DbProperty;
|
||||
import org.alfresco.util.schemacomp.DefaultComparisonUtils;
|
||||
import org.alfresco.util.schemacomp.DiffContext;
|
||||
import org.alfresco.util.schemacomp.Result.Strength;
|
||||
import org.alfresco.util.schemacomp.Results;
|
||||
import org.alfresco.util.schemacomp.validator.DbValidator;
|
||||
|
||||
/**
|
||||
* Useful base class for many, if not all the {@link DbObject} implementations.
|
||||
@@ -37,6 +42,7 @@ public abstract class AbstractDbObject implements DbObject
|
||||
/** How differences in the name field should be reported */
|
||||
private Strength nameStrength = Strength.ERROR;
|
||||
protected ComparisonUtils comparisonUtils = new DefaultComparisonUtils();
|
||||
private List<DbValidator<?>> validators = new ArrayList<DbValidator<?>>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -203,4 +209,28 @@ public abstract class AbstractDbObject implements DbObject
|
||||
{
|
||||
this.comparisonUtils = comparisonUtils;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<DbValidator<? extends DbObject>> getValidators()
|
||||
{
|
||||
return validators;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param validators the validators to set
|
||||
*/
|
||||
@Override
|
||||
public void setValidators(List<DbValidator<? extends DbObject>> validators)
|
||||
{
|
||||
if (validators == null)
|
||||
{
|
||||
this.validators = Collections.emptyList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.validators = validators;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.util.schemacomp.DbObjectVisitor;
|
||||
import org.alfresco.util.schemacomp.DbProperty;
|
||||
@@ -32,6 +34,8 @@ 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;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -83,8 +87,7 @@ public class AbstractDbObjectTest
|
||||
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()
|
||||
{
|
||||
@@ -110,6 +113,25 @@ public class AbstractDbObjectTest
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void canGetValidators()
|
||||
{
|
||||
List<DbValidator<? extends DbObject>> 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.
|
||||
*/
|
||||
@@ -142,4 +164,27 @@ public class AbstractDbObjectTest
|
||||
return this.someProp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<DbValidator<? extends DbObject>> validatorList(DbValidator<? extends DbObject>... validators)
|
||||
{
|
||||
return Arrays.asList(validators);
|
||||
}
|
||||
|
||||
|
||||
private static class TestValidator extends AbstractDbValidator<DbObject>
|
||||
{
|
||||
@Override
|
||||
public void validate(DbObject reference, DbObject target, DiffContext ctx)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestValidator1 extends TestValidator
|
||||
{
|
||||
}
|
||||
|
||||
private static class TestValidator2 extends TestValidator
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@ package org.alfresco.util.schemacomp.model;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -116,7 +115,6 @@ public class Column extends AbstractDbObject
|
||||
@Override
|
||||
protected void doDiff(DbObject right, DiffContext ctx, Strength strength)
|
||||
{
|
||||
Results differences = ctx.getDifferences();
|
||||
DbProperty thisTypeProp = new DbProperty(this, "type");
|
||||
DbProperty thisNullableProp = new DbProperty(this, "nullable");
|
||||
|
||||
|
@@ -18,10 +18,14 @@
|
||||
*/
|
||||
package org.alfresco.util.schemacomp.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.util.schemacomp.DbObjectVisitor;
|
||||
import org.alfresco.util.schemacomp.DiffContext;
|
||||
import org.alfresco.util.schemacomp.Results;
|
||||
import org.alfresco.util.schemacomp.Result.Strength;
|
||||
import org.alfresco.util.schemacomp.validator.DbValidator;
|
||||
|
||||
/**
|
||||
* All database objects to be modelled for schema comparisons must implement this interface, examples
|
||||
@@ -86,4 +90,20 @@ public interface DbObject
|
||||
* @param parent
|
||||
*/
|
||||
void setParent(DbObject parent);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the list of validators associated with this database object.
|
||||
*
|
||||
* @see DbValidator
|
||||
* @return DbValidator List
|
||||
*/
|
||||
List<DbValidator<? extends DbObject>> getValidators();
|
||||
|
||||
/**
|
||||
* Set/override the validators associated with this database object.
|
||||
*
|
||||
* @param validators
|
||||
*/
|
||||
void setValidators(List<DbValidator<? extends DbObject>> validators);
|
||||
}
|
||||
|
Reference in New Issue
Block a user