/* * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program 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 General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * As a special exception to the terms and conditions of version 2.0 of * the GPL, you may redistribute this Program in connection with Free/Libre * and Open Source Software ("FLOSS") applications as described in Alfresco's * FLOSS exception. You should have recieved a copy of the text describing * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ package org.alfresco.repo.dictionary; import java.io.ByteArrayInputStream; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.cache.EhCacheAdapter; import org.alfresco.repo.dictionary.DictionaryDAOImpl.DictionaryRegistry; import org.alfresco.repo.dictionary.NamespaceDAOImpl.NamespaceRegistry; import org.alfresco.repo.tenant.SingleTServiceImpl; import org.alfresco.repo.tenant.TenantService; import org.alfresco.service.namespace.QName; public class DiffModelTest extends TestCase { public static final String MODEL1_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " Base" + " The Base Type 2" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " Base" + " The Base Type 3" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " Base" + " The Base Aspect 2" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " Base" + " The Base Aspect 3" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + ""; public static final String MODEL1_UPDATE1_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " Base" + " The Base Type 3" + " " + " " + " d:text" + " " + " " + " " + " " + " Base" + " The Base Type 4" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " Base" + " The Base Aspect 3" + " " + " " + " d:int" + " " + " " + " d:int" + " " + " " + " " + " " + " Base" + " The Base Aspect 4" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + ""; public static final String MODEL2_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + ""; public static final String MODEL2_EXTRA_PROPERTIES_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " d:date" + " " + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:boolean" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + ""; public static final String MODEL3_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + ""; public static final String MODEL3_EXTRA_TYPES_AND_ASPECTS_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " Base" + " The Base Type 2" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " Base" + " The Base Aspect 2" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + ""; public static final String MODEL4_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:text" + " " + " " + " " + " " + ""; public static final String MODEL4_EXTRA_DEFAULT_ASPECT_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " " + " test1:aspect1" + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:text" + " " + " " + " " + " " + ""; public static final String MODEL5_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " " + " " + " Base" + " The Base Type 2" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:text" + " " + " " + " " + " " + " Base" + " The Base Aspect 2" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + ""; public static final String MODEL5_EXTRA_ASSOCIATIONS_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Base" + " The Base Type 1" + " " + " " + " d:text" + " " + " " + " " + " " + " " + " false" + " false" + " " + " " + " test1:type2" + " false" + " false" + " " + " " + " " + " " + " " + " Base" + " The Base Type 2" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 1" + " " + " " + " d:text" + " " + " " + " " + " " + " " + " test1:role1" + " false" + " true" + " " + " " + " test1:aspect2" + " test1:role2" + " false" + " true" + " " + " " + " " + " " + " " + " Base" + " The Base Aspect 2" + " " + " " + " d:text" + " " + " " + " d:int" + " " + " " + " " + " " + ""; public static final String MODEL6_XML = "" + " Another description" + " Alfresco" + " 2007-08-01" + " 1.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Type1 Title" + " Type1 Description" + " " + " " + " Prop1 Title" + " Prop1 Description" + " d:text" + " " + " " + " " + " " + " " + " " + " Aspect1 Title" + " Aspect1 Description" + " " + " " + " Prop9 Title" + " Prop9 Description" + " d:text" + " " + " " + " " + " " + ""; public static final String MODEL6_UPDATE1_XML = "" + " Another description - UPDATE1" + " Alfresco - UPDATE1" + " 2009-08-01" + " 2.0" + " " + " " + " " + " " + " " + " " + " " + " " + " Type1 Title - UPDATE1" + " Type1 Description - UPDATE1" + " " + " " + " Prop1 Title - UPDATE1" + " Prop1 Description - UPDATE1" + " d:text" + " " + " " + " " + " " + " " + " " + " Aspect1 Title" + " Aspect1 Description" + " " + " " + " Prop9 Title - UPDATE1" + " Prop9 Description - UPDATE1" + " d:text" + " " + " " + " " + " " + ""; private DictionaryDAOImpl dictionaryDAO; /** * Setup */ protected void setUp() throws Exception { // Initialise the Dictionary TenantService tenantService = new SingleTServiceImpl(); NamespaceDAOImpl namespaceDAO = new NamespaceDAOImpl(); namespaceDAO.setTenantService(tenantService); initNamespaceCaches(namespaceDAO); dictionaryDAO = new DictionaryDAOImpl(namespaceDAO); dictionaryDAO.setTenantService(tenantService); initDictionaryCaches(dictionaryDAO); // include Alfresco dictionary model List bootstrapModels = new ArrayList(); bootstrapModels.add("alfresco/model/dictionaryModel.xml"); DictionaryBootstrap bootstrap = new DictionaryBootstrap(); bootstrap.setModels(bootstrapModels); bootstrap.setDictionaryDAO(dictionaryDAO); bootstrap.bootstrap(); } private void initDictionaryCaches(DictionaryDAOImpl dictionaryDAO) { CacheManager cacheManager = new CacheManager(); Cache dictionaryEhCache = new Cache("dictionaryCache", 50, false, true, 0L, 0L); cacheManager.addCache(dictionaryEhCache); EhCacheAdapter dictionaryCache = new EhCacheAdapter(); dictionaryCache.setCache(dictionaryEhCache); dictionaryDAO.setDictionaryRegistryCache(dictionaryCache); } private void initNamespaceCaches(NamespaceDAOImpl namespaceDAO) { CacheManager cacheManager = new CacheManager(); Cache namespaceEhCache = new Cache("namespaceCache", 50, false, true, 0L, 0L); cacheManager.addCache(namespaceEhCache); EhCacheAdapter namespaceCache = new EhCacheAdapter(); namespaceCache.setCache(namespaceEhCache); namespaceDAO.setNamespaceRegistryCache(namespaceCache); } public void testDeleteModel() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL1_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); List 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)); } @SuppressWarnings("unused") public void testNoExistingModelToDelete() { try { List modelDiffs = dictionaryDAO.diffModel(null, null); assertTrue("Should throw exeception that there is no previous version of the model to delete", true); } catch (AlfrescoRuntimeException e) { assertTrue("Wrong error message", e.getMessage().equals("Invalid arguments - no previous version of model to delete")); } ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL1_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel compiledModel = dictionaryDAO.getCompiledModel(modelName); try { List modelDiffs = dictionaryDAO.diffModel(null, compiledModel); assertTrue("Should throw exeception that there is no previous version of the model to delete", true); } catch (AlfrescoRuntimeException e) { assertTrue("Wrong error message", e.getMessage().equals("Invalid arguments - no previous version of model to delete")); } } public void testNewModel() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL1_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List 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)); } public void testNonIncUpdateModel() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL1_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); byteArrayInputStream = new ByteArrayInputStream(MODEL1_UPDATE1_XML.getBytes()); model = M2Model.createModel(byteArrayInputStream); modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion); for (M2ModelDiff M2ModelDiff : modelDiffs) { System.out.println(M2ModelDiff.toString()); } assertEquals(8, modelDiffs.size()); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_CREATED)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED)); assertEquals(1, 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(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UPDATED)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_DELETED)); } public void testIncUpdatePropertiesAdded() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL2_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); byteArrayInputStream = new ByteArrayInputStream(MODEL2_EXTRA_PROPERTIES_XML.getBytes()); model = M2Model.createModel(byteArrayInputStream); modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion); for (M2ModelDiff modelDiff : modelDiffs) { System.out.println(modelDiff.toString()); } assertEquals(2, modelDiffs.size()); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED_INC)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UPDATED_INC)); } public void testIncUpdateTypesAndAspectsAdded() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL3_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); byteArrayInputStream = new ByteArrayInputStream(MODEL3_EXTRA_TYPES_AND_ASPECTS_XML.getBytes()); model = M2Model.createModel(byteArrayInputStream); modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List 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_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)); } public void testIncUpdateAssociationsAdded() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL5_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); byteArrayInputStream = new ByteArrayInputStream(MODEL5_EXTRA_ASSOCIATIONS_XML.getBytes()); model = M2Model.createModel(byteArrayInputStream); modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List 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_UPDATED_INC)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED)); } public void testIncUpdateTitleDescription() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL6_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); byteArrayInputStream = new ByteArrayInputStream(MODEL6_UPDATE1_XML.getBytes()); model = M2Model.createModel(byteArrayInputStream); modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion); for (M2ModelDiff modelDiff : modelDiffs) { System.out.println(modelDiff.toString()); } assertEquals(2, modelDiffs.size()); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED_INC)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UPDATED_INC)); } public void testNonIncUpdatePropertiesRemoved() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL2_EXTRA_PROPERTIES_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); byteArrayInputStream = new ByteArrayInputStream(MODEL2_XML.getBytes()); model = M2Model.createModel(byteArrayInputStream); modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion); for (M2ModelDiff modelDiff : modelDiffs) { System.out.println(modelDiff.toString()); } assertEquals(2, modelDiffs.size()); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UPDATED)); } public void testNonIncUpdateTypesAndAspectsRemoved() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL3_EXTRA_TYPES_AND_ASPECTS_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); byteArrayInputStream = new ByteArrayInputStream(MODEL3_XML.getBytes()); model = M2Model.createModel(byteArrayInputStream); modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List 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_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)); } public void testNonIncUpdateDefaultAspectAdded() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL4_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); byteArrayInputStream = new ByteArrayInputStream(MODEL4_EXTRA_DEFAULT_ASPECT_XML.getBytes()); model = M2Model.createModel(byteArrayInputStream); modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List modelDiffs = dictionaryDAO.diffModel(previousVersion, newVersion); for (M2ModelDiff modelDiff : modelDiffs) { System.out.println(modelDiff.toString()); } assertEquals(2, modelDiffs.size()); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UPDATED)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED)); } public void testNonIncUpdateAssociationsRemoved() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(MODEL5_EXTRA_ASSOCIATIONS_XML.getBytes()); M2Model model = M2Model.createModel(byteArrayInputStream); QName modelName = dictionaryDAO.putModel(model); CompiledModel previousVersion = dictionaryDAO.getCompiledModel(modelName); byteArrayInputStream = new ByteArrayInputStream(MODEL5_XML.getBytes()); model = M2Model.createModel(byteArrayInputStream); modelName = dictionaryDAO.putModel(model); CompiledModel newVersion = dictionaryDAO.getCompiledModel(modelName); List 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_UPDATED)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_TYPE, M2ModelDiff.DIFF_UNCHANGED)); assertEquals(1, countDiffs(modelDiffs, M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_UNCHANGED)); } private int countDiffs(List M2ModelDiffs, String elementType, String diffType) { int count = 0; for (M2ModelDiff modelDiff : M2ModelDiffs) { if (modelDiff.getDiffType().equals(diffType) && modelDiff.getElementType().equals(elementType)) { count++; } } return count; } }