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

@@ -0,0 +1,103 @@
/*
* Copyright (C) 2005-2013 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.fail;
import java.util.Arrays;
import java.util.regex.Pattern;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.util.schemacomp.DiffContext;
import org.alfresco.util.schemacomp.Results;
import org.alfresco.util.schemacomp.ValidationResult;
import org.alfresco.util.schemacomp.model.Index;
import org.alfresco.util.schemacomp.model.Table;
import org.hibernate.dialect.Oracle10gDialect;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for the IndexColumnsValidator class.
*
* @author pavel.yurkevich
*/
public class IndexColumnsValidatorTest
{
private IndexColumnsValidator validator;
private DiffContext ctx;
private Results validationResults;
@Before
public void setUp() throws Exception
{
validator = new IndexColumnsValidator();
validationResults = new Results();
ctx = new DiffContext(new Oracle10gDialect(), validationResults, null, null);
}
@Test
public void testNonIndex()
{
validator.setPattern(Pattern.compile("SYS_NC.+"));
assertEquals("SYS_NC.+", validator.getPattern().toString());
try
{
validator.validate(null, new Table("SYS_NC234234"), ctx);
fail("Validator should faile for non-index object");
}
catch (AlfrescoRuntimeException e)
{
// expected to fail for table object
}
}
@Test
public void testAllOk()
{
validator.setPattern(Pattern.compile("SYS_NC.+"));
assertEquals("SYS_NC.+", validator.getPattern().toString());
validator.validate(indexForColumns("SYS_NC234234", "SYS_NC654123"), indexForColumns("SYS_NC123123", "SYS_NC225588"), ctx);
assertEquals(0, validationResults.size());
}
@Test
public void testNotValid()
{
validator.setPattern(Pattern.compile("SYS_NC.+"));
assertEquals("SYS_NC.+", validator.getPattern().toString());
Index target = indexForColumns("TEST_INDEX1", "SYS_NC892345", "MY_INDEX");
validator.validate(indexForColumns("SYS_NC234234", "SYS_NC654123"), target, ctx);
assertEquals(3, validationResults.size());
assertEquals("TEST_INDEX1", ((ValidationResult) validationResults.get(0)).getValue());
assertEquals("MY_INDEX", ((ValidationResult) validationResults.get(1)).getValue());
assertEquals(target.getColumnNames(), ((ValidationResult) validationResults.get(2)).getValue());
}
private Index indexForColumns(String ... names)
{
return new Index(null, null, Arrays.asList(names));
}
}

View File

@@ -0,0 +1,94 @@
/*
* 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>());
}
}

View File

@@ -0,0 +1,112 @@
/*
* 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);
}
}

View File

@@ -0,0 +1,31 @@
/*
* 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
{
}