TEST_SCHEMA_REFERENCE_URLS = Arrays.asList(
- "classpath:alfresco/dbscripts/create/${db.script.dialect}/Test-Schema-Reference-ALF.xml",
- "classpath:alfresco/dbscripts/create/${db.script.dialect}/Schema-Reference-ACT.xml");
+ TEST_SCHEMA_REFERENCE_FILE,
+ "classpath:alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Schema-Reference-ACT.xml");
private static ApplicationContextInit APP_CONTEXT_INIT = ApplicationContextInit.createStandardContextWithOverrides(BOOTSTRAP_TEST_CONTEXT);
@@ -59,6 +80,17 @@ public class SchemaBootstrapTest
private SchemaBootstrap schemaBootstrap;
private SchemaUpgradeScriptPatch optionalPatch;
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver(SchemaBootstrapTest.class.getClassLoader());
+ Document schemaRefXML = loadXML(rpr.getResource(MAIN_SCHEMA_REFERENCE_FILE));
+ Node indexes = getIndexesNode(schemaRefXML);
+ indexes.appendChild(createTestIndex(schemaRefXML));
+ Resource testSchemaRef = rpr.getResource(TEST_SCHEMA_REFERENCE_FILE);
+ updateTestSchemaReferenceFile(testSchemaRef, schemaRefXML);
+ }
+
@Before
public void setUp() throws Exception
{
@@ -83,4 +115,47 @@ public class SchemaBootstrapTest
+ optionalPatch.getId() + " has been run"));
}
+ private static void updateTestSchemaReferenceFile(Resource testSchemaRef, Document newDoc) throws Exception
+ {
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ StreamResult result = new StreamResult(testSchemaRef.getFile());
+ DOMSource source = new DOMSource(newDoc);
+ transformer.transform(source, result);
+ }
+
+ private static Element createTestIndex(Document document)
+ {
+ Element testIndex = document.createElement("index");
+ testIndex.setAttribute("name", "idx_alf_node_test");
+ testIndex.setAttribute("unique", "false");
+
+ Element columnNames = document.createElement("columnnames");
+ for (String colName: Arrays.asList("acl_id", "audit_creator"))
+ {
+ Element columnName = document.createElement("columnname");
+ columnName.setNodeValue(colName);
+ columnNames.appendChild(columnName);
+ }
+ testIndex.appendChild(columnNames);
+
+ return testIndex;
+ }
+
+ private static Node getIndexesNode(Document document) throws XPathExpressionException
+ {
+ XPathFactory xPathfactory = XPathFactory.newInstance();
+ XPath xpath = xPathfactory.newXPath();
+ XPathExpression expr = xpath.compile("/schema/objects/table[@name='alf_node']/indexes");
+ Node indexes = (Node)expr.evaluate(document, XPathConstants.NODE);
+ return indexes;
+ }
+
+ private static Document loadXML(Resource resource) throws Exception
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder;
+ builder = factory.newDocumentBuilder();
+ return builder.parse(resource.getInputStream());
+ }
}
diff --git a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaDifferenceHelperUnitTest.java b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaDifferenceHelperUnitTest.java
index 2592e45600..ec5fd4e2cf 100644
--- a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaDifferenceHelperUnitTest.java
+++ b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaDifferenceHelperUnitTest.java
@@ -43,6 +43,7 @@ import org.alfresco.repo.admin.patch.AppliedPatch;
import org.alfresco.repo.admin.patch.PatchService;
import org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch;
import org.alfresco.repo.domain.dialect.Dialect;
+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;
@@ -125,8 +126,7 @@ public class SchemaDifferenceHelperUnitTest
private Difference createDifference()
{
- Difference difference = new Difference(Where.IN_BOTH_BUT_DIFFERENCE, mock(DbProperty.class), mock(DbProperty.class));
- return difference;
+ return new Difference(Where.IN_BOTH_BUT_DIFFERENCE, new DbProperty(mock(DbObject.class)), new DbProperty(mock(DbObject.class)));
}
private Index createTableIndex(String tableName)
diff --git a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaReferenceFileTest.java b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaReferenceFileTest.java
index 5c620c075d..2488f8be5e 100644
--- a/repository/src/test/java/org/alfresco/util/schemacomp/SchemaReferenceFileTest.java
+++ b/repository/src/test/java/org/alfresco/util/schemacomp/SchemaReferenceFileTest.java
@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * Copyright (C) 2005 - 2021 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -25,47 +25,47 @@
*/
package org.alfresco.util.schemacomp;
-
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
import org.alfresco.repo.domain.schema.SchemaBootstrap;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.testing.category.DBTests;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
- * Test intended for use in the continuous integration system that checks whether the
- * schema reference file (for whichever database the tests are being run against)
- * is in sync with the actual schema. If the test fails (and the schema comparator is
- * in working order) then the most likely cause is that a new up-to-date schema reference file
- * needs to be created.
+ * Test intended for use in the continuous integration system that checks
+ * whether the schema reference file (for whichever database the tests are being
+ * run against) is in sync with the actual schema. If the test fails (and the
+ * schema comparator is in working order) then the most likely cause is that a
+ * new up-to-date schema reference file needs to be created.
*
* Schema reference files are created using the {@link DbToXML} tool.
*
- * Note: if no reference file exists then the test will pass, this is to allow piece meal
- * introduction of schmea reference files.
+ * Note: if no reference file exists then the test will pass, this is to allow
+ * piece meal introduction of schmea reference files.
*
* @see DbToXML
* @author Matt Ward
*/
-@Category({OwnJVMTestsCategory.class, DBTests.class})
+@Category({ OwnJVMTestsCategory.class, DBTests.class })
public class SchemaReferenceFileTest
{
private ClassPathXmlApplicationContext ctx;
private SchemaBootstrap schemaBootstrap;
-
+
@Before
public void setUp() throws Exception
{
- ctx = (ClassPathXmlApplicationContext) ApplicationContextHelper.getApplicationContext();
+ ctx = (ClassPathXmlApplicationContext) ApplicationContextHelper.getApplicationContext();
schemaBootstrap = (SchemaBootstrap) ctx.getBean("schemaBootstrap");
}
@@ -74,12 +74,28 @@ public class SchemaReferenceFileTest
{
ByteArrayOutputStream buff = new ByteArrayOutputStream();
PrintWriter out = new PrintWriter(buff);
- int numProblems = schemaBootstrap.validateSchema(null, out);
+ int maybeProblems = schemaBootstrap.validateSchema(null, out);
out.flush();
-
- if (numProblems > 0)
+
+ if (maybeProblems > 0)
{
- fail(buff.toString());
+ List errors = computeRealErrors(buff);
+ assertTrue("\n"+buff, errors.isEmpty());
}
}
+
+ private List computeRealErrors(ByteArrayOutputStream buff)
+ {
+ String[] lines = buff.toString().split("\\n");
+
+ List errors = new ArrayList<>();
+ for (int i = 0; i < lines.length; i++)
+ {
+ String line = lines[i].trim();
+ if (line.isEmpty())
+ break;
+ errors.add(line);
+ }
+ return errors;
+ }
}
diff --git a/repository/src/test/resources/alfresco/dbscripts/test-bootstrap-context.xml b/repository/src/test/resources/alfresco/dbscripts/bootstrap-context-test.xml
similarity index 100%
rename from repository/src/test/resources/alfresco/dbscripts/test-bootstrap-context.xml
rename to repository/src/test/resources/alfresco/dbscripts/bootstrap-context-test.xml
diff --git a/repository/src/test/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Test-Schema-Reference-ALF.xml b/repository/src/test/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Test-Schema-Reference-ALF.xml
index 927a2fc2a2..0089785445 100644
--- a/repository/src/test/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Test-Schema-Reference-ALF.xml
+++ b/repository/src/test/resources/alfresco/dbscripts/create/org.alfresco.repo.domain.dialect.PostgreSQLDialect/Test-Schema-Reference-ALF.xml
@@ -44,7 +44,6 @@
-
@@ -2551,38 +2550,6 @@