from alfresco-data-model

SEARCH-2362: Consider changing properties from mandatory/enforced/pro… (#313)

* SEARCH-2362: Consider changing properties from mandatory/enforced/protected to NON mandatory/enforced/protected as incremental changes

* SEARCH-2362 Update tests to check whole set of returned diffs at once.

Co-authored-by: Tom Page <thomas.page@alfresco.com>

(cherry picked from commit 576601564251038311627f230f286b96ea950383)
Bump dependency.cxf.version from 3.3.7 to 3.4.0 (#309)

(cherry picked from commit dc689a911d83b608d49572cada5c2d16441c1eea)
Bump chemistry-opencmis-commons-impl from 1.0.0 to 1.1.0 (#305)

(cherry picked from commit 98fa7b66851aeada1bb6ea05bd6e747e3c55b342)
Bump commons-compress from 1.19 to 1.20 (#303)

(cherry picked from commit f6a950d4a36f05083536638cc5ff7866436f191d)
Bump pdfbox from 2.0.17 to 2.0.20 (#304)

(cherry picked from commit 435b786817ee18c28b84d093c6fbfbc330434e4c)
This commit is contained in:
Alan Davis
2020-10-05 23:47:58 +01:00
parent c58d8f1be7
commit 8491e891d9
4 changed files with 260 additions and 194 deletions

View File

@@ -551,21 +551,45 @@ import org.springframework.util.StringUtils;
// check mandatory
if (isMandatory() != propDef.isMandatory())
{
// Change from mandatory to NON mandatory is an incremental change
if (isMandatory() && !propDef.isMandatory())
{
isUpdatedIncrementally = true;
}
else
{
isUpdated = true;
}
}
// check mandatory enforced
if (isMandatoryEnforced() != propDef.isMandatoryEnforced())
{
// Change from mandatory enforced to NON mandatory enforced is an incremental change
if (isMandatoryEnforced() && ! propDef.isMandatoryEnforced())
{
isUpdatedIncrementally = true;
}
else
{
isUpdated = true;
}
}
// check protected
if (isProtected() != propDef.isProtected())
{
// Change from protected to NON protected is an incremental change
if (isProtected() && !propDef.isProtected())
{
isUpdatedIncrementally = true;
}
else
{
isUpdated = true;
}
}
//
// property indexing - is index enabled -> stored, atomic, tokenized (true, false, both)

View File

@@ -896,6 +896,58 @@ public class AbstractModelTest extends TestCase
" </aspects>" +
"</model>";
public static final String MODEL8_XML =
"<model name=\"test8:model8\" xmlns=\"http://www.alfresco.org/model/dictionary/1.0\">" +
" <imports>" +
" <import uri=\"http://www.alfresco.org/model/dictionary/1.0\" prefix=\"d\"/>" +
" </imports>" +
" <namespaces>" +
" <namespace uri=\"http://www.alfresco.org/model/test8/1.0\" prefix=\"test8\"/>" +
" </namespaces>" +
" <aspects>" +
" <aspect name=\"test8:aspectA\">" +
" <properties> " +
" <property name=\"test8:propA1\"> " +
" <title>Prop A1</title> " +
" <type>d:text</type> " +
" <mandatory enforced=\"true\" protected =\"true\">true</mandatory> " +
" </property> " +
" </properties> " +
" </aspect>" +
" </aspects>" +
"</model>";
public static final String MODEL8_CHANGE_MANDATORY_PROPERTIES_ASPECTS_XML =
"<model name=\"test8:model8\" xmlns=\"http://www.alfresco.org/model/dictionary/1.0\">" +
" <imports>" +
" <import uri=\"http://www.alfresco.org/model/dictionary/1.0\" prefix=\"d\"/>" +
" </imports>" +
" <namespaces>" +
" <namespace uri=\"http://www.alfresco.org/model/test8/1.0\" prefix=\"test8\"/>" +
" </namespaces>" +
" <aspects>" +
" <aspect name=\"test8:aspectA\">" +
" <properties> " +
" <property name=\"test8:propA1\"> " +
" <title>Prop A1</title> " +
" <type>d:text</type> " +
" <mandatory>false</mandatory> " +
" </property> " +
" </properties> " +
" </aspect>" +
" </aspects>" +
"</model>";
public AbstractModelTest()

View File

@@ -25,12 +25,32 @@
*/
package org.alfresco.repo.dictionary;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.averagingDouble;
import static java.util.stream.Collectors.toMap;
import static org.alfresco.repo.dictionary.M2ModelDiff.DIFF_CREATED;
import static org.alfresco.repo.dictionary.M2ModelDiff.DIFF_DELETED;
import static org.alfresco.repo.dictionary.M2ModelDiff.DIFF_UNCHANGED;
import static org.alfresco.repo.dictionary.M2ModelDiff.DIFF_UPDATED;
import static org.alfresco.repo.dictionary.M2ModelDiff.DIFF_UPDATED_INC;
import static org.alfresco.repo.dictionary.M2ModelDiff.TYPE_ASPECT;
import static org.alfresco.repo.dictionary.M2ModelDiff.TYPE_ASSOCIATION;
import static org.alfresco.repo.dictionary.M2ModelDiff.TYPE_PROPERTY;
import static org.alfresco.repo.dictionary.M2ModelDiff.TYPE_TYPE;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.google.common.collect.Maps;
import junit.framework.TestCase;
@@ -40,8 +60,10 @@ import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.DynamicallySizedThreadPoolExecutor;
import org.alfresco.util.Pair;
import org.alfresco.util.TraceableThreadFactory;
import org.alfresco.util.cache.DefaultAsynchronouslyRefreshedCacheRegistry;
import org.apache.commons.collections4.map.UnmodifiableMap;
public class DiffModelTest extends AbstractModelTest
{
@@ -91,15 +113,10 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, null);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(6, modelDiffs.size());
assertEquals(3, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_DELETED));
assertEquals(3, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_DELETED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_DELETED), 3,
new Pair(TYPE_ASPECT, DIFF_DELETED), 3);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
@SuppressWarnings("unused")
@@ -144,15 +161,10 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(null, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(6, modelDiffs.size());
assertEquals(3, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_CREATED));
assertEquals(3, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_CREATED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_CREATED), 3,
new Pair(TYPE_ASPECT, DIFF_CREATED), 3);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testDuplicateModels()
@@ -190,27 +202,19 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff M2ModelDiff : modelDiffs)
{
System.out.println(M2ModelDiff.toString());
}
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_CREATED), 1,
new Pair(TYPE_TYPE, DIFF_UNCHANGED), 2,
new Pair(TYPE_TYPE, DIFF_DELETED), 1,
assertEquals(16, modelDiffs.size());
new Pair(TYPE_ASPECT, DIFF_CREATED), 1,
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 2,
new Pair(TYPE_ASPECT, DIFF_DELETED), 1,
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_CREATED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(0, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_DELETED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_CREATED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(0, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UPDATED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_DELETED));
assertEquals(0, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_CREATED));
assertEquals(6, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UPDATED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_DELETED));
new Pair(TYPE_PROPERTY, DIFF_UNCHANGED), 6,
new Pair(TYPE_PROPERTY, DIFF_UPDATED), 1,
new Pair(TYPE_PROPERTY, DIFF_DELETED), 1);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testIncUpdatePropertiesAdded()
@@ -227,17 +231,12 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(8, modelDiffs.size());
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(4, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_CREATED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_UNCHANGED), 1,
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 1,
new Pair(TYPE_PROPERTY, DIFF_UNCHANGED), 4,
new Pair(TYPE_PROPERTY, DIFF_CREATED), 2);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testIncUpdateTypesAndAspectsAdded()
@@ -254,20 +253,13 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(8, modelDiffs.size());
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_CREATED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_CREATED));
assertEquals(4, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_UNCHANGED), 1,
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 1,
new Pair(TYPE_TYPE, DIFF_CREATED), 1,
new Pair(TYPE_ASPECT, DIFF_CREATED), 1,
new Pair(TYPE_PROPERTY, DIFF_UNCHANGED), 4);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testIncUpdateAssociationsAdded()
@@ -284,21 +276,13 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(12, modelDiffs.size());
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED_INC));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(6, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_CREATED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_UPDATED_INC), 1,
new Pair(TYPE_TYPE, DIFF_UNCHANGED), 1,
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 2,
new Pair(TYPE_PROPERTY, DIFF_UNCHANGED), 6,
new Pair(TYPE_ASSOCIATION, DIFF_CREATED), 2);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testIncUpdateTitleDescription()
@@ -315,16 +299,11 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(4, modelDiffs.size());
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED_INC));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UPDATED_INC));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_UPDATED_INC), 1,
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 1,
new Pair(TYPE_PROPERTY, DIFF_UPDATED_INC), 2);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testNonIncUpdatePropertiesRemoved()
@@ -341,17 +320,12 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(8, modelDiffs.size());
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(4, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_DELETED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_UNCHANGED), 1,
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 1,
new Pair(TYPE_PROPERTY, DIFF_UNCHANGED), 4,
new Pair(TYPE_PROPERTY, DIFF_DELETED), 2);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testNonIncUpdateTypesAndAspectsRemoved()
@@ -368,20 +342,13 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(8, modelDiffs.size());
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_DELETED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_DELETED));
assertEquals(4, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_UNCHANGED), 1,
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 1,
new Pair(TYPE_TYPE, DIFF_DELETED), 1,
new Pair(TYPE_ASPECT, DIFF_DELETED), 1,
new Pair(TYPE_PROPERTY, DIFF_UNCHANGED), 4);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testNonIncUpdateDefaultAspectAdded()
@@ -398,16 +365,11 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(4, modelDiffs.size());
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_UPDATED), 1,
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 1,
new Pair(TYPE_PROPERTY, DIFF_UNCHANGED), 2);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testNonIncUpdateAssociationsRemoved()
@@ -424,21 +386,13 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(12, modelDiffs.size());
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(6, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASSOCIATION, M2ModelDiff.DIFF_DELETED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_TYPE, DIFF_UPDATED), 1,
new Pair(TYPE_TYPE, DIFF_UNCHANGED), 1,
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 2,
new Pair(TYPE_PROPERTY, DIFF_UNCHANGED), 6,
new Pair(TYPE_ASSOCIATION, DIFF_DELETED), 2);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testIncUpdatePropertiesAddedToMandatoryAspect()
@@ -455,15 +409,10 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
}
assertEquals(3, modelDiffs.size());
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_CREATED));
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 2,
new Pair(TYPE_PROPERTY, DIFF_CREATED), 1);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
public void testNonIncUpdatePropertiesRemovedFromMandatoryAspect()
@@ -480,29 +429,70 @@ public class DiffModelTest extends AbstractModelTest
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
for (M2ModelDiff modelDiff : modelDiffs)
{
System.out.println(modelDiff.toString());
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 2,
new Pair(TYPE_PROPERTY, DIFF_DELETED), 1);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
assertEquals(3, modelDiffs.size());
/**
* Changing a property from mandatory/enforced/protected to NON mandatory/enforced/protected
* is an incremental change and it should be allowed.
*/
public void testIncChangeMandatoryProperties()
{
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(AbstractModelTest.MODEL8_XML.getBytes());
M2Model model = M2Model.createModel(byteArrayInputStream);
QName modelName = dictionaryDAO.putModel(model);
CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName);
assertEquals(2, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED));
assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_PROPERTY, M2ModelDiff.DIFF_DELETED));
byteArrayInputStream = new ByteArrayInputStream(AbstractModelTest.MODEL8_CHANGE_MANDATORY_PROPERTIES_ASPECTS_XML.getBytes());
model = M2Model.createModel(byteArrayInputStream);
modelName = dictionaryDAO.putModel(model);
CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName);
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 1,
new Pair(TYPE_PROPERTY, DIFF_UPDATED_INC), 1);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
private int countDiffs(List<M2ModelDiff> M2ModelDiffs, String elementType, String diffType)
/**
* Changing a property from NOT mandatory/enforced/protected to mandatory/enforced/protected
* is considered to be a non incremental change.
*/
public void testNonIncChangeMandatoryProperties()
{
int count = 0;
for (M2ModelDiff modelDiff : M2ModelDiffs)
{
if (modelDiff.getDiffType().equals(diffType) && modelDiff.getElementType().equals(elementType))
{
count++;
}
}
return count;
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(AbstractModelTest.MODEL8_CHANGE_MANDATORY_PROPERTIES_ASPECTS_XML.getBytes());
M2Model model = M2Model.createModel(byteArrayInputStream);
QName modelName = dictionaryDAO.putModel(model);
CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName);
byteArrayInputStream = new ByteArrayInputStream(AbstractModelTest.MODEL8_XML.getBytes());
model = M2Model.createModel(byteArrayInputStream);
modelName = dictionaryDAO.putModel(model);
CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName);
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion);
Map<Pair<String, String>, Integer> expected = Map.of(
new Pair(TYPE_ASPECT, DIFF_UNCHANGED), 1,
new Pair(TYPE_PROPERTY, DIFF_UPDATED), 1);
assertEquals("Unexpected set of diffs found.", expected, getAllDiffCounts(modelDiffs));
}
/**
* Count the diffs grouping by element type and diff type.
*
* @param m2ModelDiffs The list of diffs returned from the dictionaryDAO.
* @return A map from (elementType, diffType) to the number of occurrences of matching diffs in the list.
*/
private Map<Pair<String, String>, Integer> getAllDiffCounts(List<M2ModelDiff> m2ModelDiffs)
{
return m2ModelDiffs.stream()
.map(modelDiff -> new Pair<>(modelDiff.getElementType(), modelDiff.getDiffType()))
.collect(toMap(identity(), pair -> 1, Integer::sum));
}
}

View File

@@ -60,8 +60,8 @@
<dependency.antlr.version>3.5.2</dependency.antlr.version>
<dependency.jackson.version>2.11.2</dependency.jackson.version>
<dependency.jackson-databind.version>2.11.2</dependency.jackson-databind.version>
<dependency.cxf.version>3.3.7</dependency.cxf.version>
<dependency.opencmis.version>1.0.0</dependency.opencmis.version>
<dependency.cxf.version>3.4.0</dependency.cxf.version>
<dependency.opencmis.version>1.1.0</dependency.opencmis.version>
<dependency.pdfbox.version>2.0.20</dependency.pdfbox.version>
<dependency.webscripts.version>8.8</dependency.webscripts.version>
<dependency.bouncycastle.version>1.66</dependency.bouncycastle.version>
@@ -525,7 +525,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.19</version>
<version>1.20</version>
</dependency>
<!-- upgrade dependency from TIKA -->
<dependency>