mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
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:
@@ -0,0 +1,85 @@
|
||||
package org.alfresco.util.schemacomp.validator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.alfresco.util.schemacomp.DbProperty;
|
||||
import org.alfresco.util.schemacomp.DiffContext;
|
||||
import org.alfresco.util.schemacomp.ValidationResult;
|
||||
import org.alfresco.util.schemacomp.model.DbObject;
|
||||
import org.alfresco.util.schemacomp.model.Index;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Validates columns names in a Index using a regular expression pattern.
|
||||
*
|
||||
* @author pavel.yurkevich
|
||||
*/
|
||||
public class IndexColumnsValidator extends NameValidator
|
||||
{
|
||||
private final static Log log = LogFactory.getLog(IndexColumnsValidator.class);
|
||||
|
||||
@Override
|
||||
public void validate(DbObject reference, DbObject target, DiffContext ctx)
|
||||
{
|
||||
if (!(target instanceof Index))
|
||||
{
|
||||
throw new AlfrescoRuntimeException("IndexColumnsValidator could be used only in context of index object but was: " + target.toString());
|
||||
}
|
||||
|
||||
List<String> referenceColumnNames = ((Index)reference).getColumnNames();
|
||||
List<String> targetColumnNames = ((Index)target).getColumnNames();
|
||||
|
||||
for (int i = 0; i < targetColumnNames.size(); i++)
|
||||
{
|
||||
String columnName = targetColumnNames.get(i);
|
||||
|
||||
if (getPattern() != null && !getPattern().matcher(columnName).matches())
|
||||
{
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Pattern [" + getPattern() + "] not matched.");
|
||||
}
|
||||
String message = I18NUtil.getMessage("system.schema_comp.name_validator", getPattern());
|
||||
ValidationResult result = new ValidationResult(new DbProperty(target, "columnNames", i), message);
|
||||
ctx.getComparisonResults().add(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Pattern [" + getPattern() + "] matched OK.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (targetColumnNames.size() != referenceColumnNames.size())
|
||||
{
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Number of columns in index " + target.getName() + "doesn't match expected result");
|
||||
}
|
||||
String message = I18NUtil.getMessage("system.schema_comp.index_columns_validator", targetColumnNames.size(), referenceColumnNames.size());
|
||||
ValidationResult result = new ValidationResult(new DbProperty(target, "columnNames"), message);
|
||||
ctx.getComparisonResults().add(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Number of columns is equivalent.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validates(String fieldName)
|
||||
{
|
||||
ParameterCheck.mandatoryString("fieldName", fieldName);
|
||||
return (fieldName.equals("columnNames"));
|
||||
}
|
||||
}
|
@@ -1,94 +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.validator;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.alfresco.util.schemacomp.DiffContext;
|
||||
import org.alfresco.util.schemacomp.Results;
|
||||
import org.alfresco.util.schemacomp.ValidationResult;
|
||||
import org.alfresco.util.schemacomp.model.DbObject;
|
||||
import org.alfresco.util.schemacomp.model.Index;
|
||||
import org.hibernate.dialect.Oracle10gDialect;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for the NameValidator class.
|
||||
*
|
||||
* @author Matt Ward
|
||||
*/
|
||||
public class NameValidatorTest
|
||||
{
|
||||
private NameValidator validator;
|
||||
private DiffContext ctx;
|
||||
private Results validationResults;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
validator = new NameValidator();
|
||||
validationResults = new Results();
|
||||
ctx = new DiffContext(new Oracle10gDialect(), validationResults, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSpecifyDefaultRequiredPattern()
|
||||
{
|
||||
validator.setPattern(Pattern.compile("SYS_[A-Z_]+"));
|
||||
validator.validate(null, indexForName("SYS_MYINDEX"), ctx);
|
||||
validator.validate(null, indexForName("SYS_"), ctx);
|
||||
validator.validate(null, indexForName("SYS_MY_INDEX"), ctx);
|
||||
validator.validate(null, indexForName("MY_INDEX"), ctx);
|
||||
|
||||
assertEquals(2, validationResults.size());
|
||||
assertEquals("SYS_", ((ValidationResult) validationResults.get(0)).getValue());
|
||||
assertEquals("MY_INDEX", ((ValidationResult) validationResults.get(1)).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canValidateAgainstPatternForDialect()
|
||||
{
|
||||
validator.setPattern(Pattern.compile("ORA_[A-Z_]+"));
|
||||
|
||||
validator.validate(null, indexForName("ORA_MYINDEX"), ctx);
|
||||
validator.validate(null, indexForName("SYS_MYINDEX"), ctx);
|
||||
|
||||
assertEquals(1, validationResults.size());
|
||||
assertEquals("SYS_MYINDEX", ((ValidationResult) validationResults.get(0)).getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void canSetPatternUsingProperties()
|
||||
{
|
||||
validator.setProperty("pattern", "ORA_[A-Z_]+");
|
||||
assertEquals("ORA_[A-Z_]+", validator.getPattern().toString());
|
||||
}
|
||||
|
||||
|
||||
private DbObject indexForName(String name)
|
||||
{
|
||||
return new Index(null, name, new ArrayList<String>());
|
||||
}
|
||||
}
|
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 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.validator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.alfresco.util.schemacomp.DiffContext;
|
||||
import org.alfresco.util.schemacomp.Results;
|
||||
import org.alfresco.util.schemacomp.ValidationResult;
|
||||
import org.alfresco.util.schemacomp.model.DbObject;
|
||||
import org.alfresco.util.schemacomp.model.Schema;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for the SchemaVersionValidator class.
|
||||
*
|
||||
* @author Matt Ward
|
||||
*/
|
||||
public class SchemaVersionValidatorTest
|
||||
{
|
||||
private SchemaVersionValidator validator;
|
||||
private DbObject reference;
|
||||
private DbObject target;
|
||||
private DiffContext ctx;
|
||||
private Results results;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
validator = new SchemaVersionValidator();
|
||||
results = new Results();
|
||||
ctx = new DiffContext(null, results, null, null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void validateWhenTargetVersionPredatesReference()
|
||||
{
|
||||
reference = schemaWithVersion(501);
|
||||
target = schemaWithVersion(500);
|
||||
|
||||
validator.validate(reference, target, ctx);
|
||||
|
||||
assertEquals(1, results.size());
|
||||
ValidationResult result = (ValidationResult) results.get(0);
|
||||
assertEquals(500, result.getValue());
|
||||
assertEquals("version", result.getDbProperty().getPropertyName());
|
||||
assertSame(target, result.getDbProperty().getDbObject());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void validateWhenTargetVersionSameAsReference()
|
||||
{
|
||||
reference = schemaWithVersion(501);
|
||||
target = schemaWithVersion(501);
|
||||
|
||||
validator.validate(reference, target, ctx);
|
||||
|
||||
assertEquals(0, results.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void validateWhenTargetVersionAfterReference()
|
||||
{
|
||||
reference = schemaWithVersion(501);
|
||||
target = schemaWithVersion(502);
|
||||
|
||||
validator.validate(reference, target, ctx);
|
||||
|
||||
assertEquals(0, results.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValidates()
|
||||
{
|
||||
assertEquals(true, validator.validates("version"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValidatesFullObject()
|
||||
{
|
||||
assertEquals(false, validator.validatesFullObject());
|
||||
}
|
||||
|
||||
|
||||
private DbObject schemaWithVersion(int version)
|
||||
{
|
||||
return new Schema("", "", version, true);
|
||||
}
|
||||
}
|
@@ -1,31 +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.validator;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses(
|
||||
{
|
||||
NameValidatorTest.class
|
||||
})
|
||||
public class ValidatorTestSuite
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user