From 54df23b95fd17b40a4c31c5d9da5140488f72853 Mon Sep 17 00:00:00 2001 From: Jan Wittler Date: Fri, 25 Nov 2022 17:13:02 +0100 Subject: [PATCH] adapt test cases to UUID changes --- .../views/impl/ChangeDerivingView.xtend | 2 +- .../views/impl/IdentityMappingViewType.java | 2 +- .../framework/views/util/ResourceCopier.xtend | 54 +++++++++--- .../BasicStateChangePropagationTest.xtend | 82 +++++++++---------- .../StateChangePropagationTest.xtend | 8 +- .../views/util/XmiIdEdgeCaseTest.java | 4 +- 6 files changed, 91 insertions(+), 61 deletions(-) diff --git a/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/impl/ChangeDerivingView.xtend b/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/impl/ChangeDerivingView.xtend index cad27c6ce2..0f6e0d8b4c 100644 --- a/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/impl/ChangeDerivingView.xtend +++ b/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/impl/ChangeDerivingView.xtend @@ -49,7 +49,7 @@ class ChangeDerivingView implements ModifiableView, CommittableView { private def setupReferenceState() { originalStateViewResourceSet = new ResourceSetImpl - ResourceCopier.copyViewResources(view.viewResourceSet.resources, originalStateViewResourceSet) + new ResourceCopier().copyViewResources(view.viewResourceSet.resources, originalStateViewResourceSet) originalStateResourceMapping = new HashMap view.viewResourceSet.resources.forEach[resource | originalStateResourceMapping.put(resource, originalStateViewResourceSet.resources.findFirst[URI === resource.URI])] } diff --git a/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/impl/IdentityMappingViewType.java b/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/impl/IdentityMappingViewType.java index 77aa89515e..14fd88e584 100644 --- a/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/impl/IdentityMappingViewType.java +++ b/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/impl/IdentityMappingViewType.java @@ -55,7 +55,7 @@ public void updateView(ModifiableView view) { List resourcesWithSelectedElements = viewSources.stream() .filter(resource -> resource.getContents().stream().anyMatch(selection::isViewObjectSelected)) .collect(Collectors.toList()); - Map mapping = ResourceCopier.copyViewSourceResources(resourcesWithSelectedElements, + Map mapping = new ResourceCopier().copyViewSourceResources(resourcesWithSelectedElements, viewResourceSet, selection::isViewObjectSelected); view.getViewSource().getUuidResolver().resolveResources(mapping, viewUuidResolver); }); diff --git a/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/util/ResourceCopier.xtend b/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/util/ResourceCopier.xtend index 67fd5aa12a..66fb0b7473 100644 --- a/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/util/ResourceCopier.xtend +++ b/bundles/tools.vitruv.framework.views/src/tools/vitruv/framework/views/util/ResourceCopier.xtend @@ -1,6 +1,5 @@ package tools.vitruv.framework.views.util -import edu.kit.ipd.sdq.activextendannotations.Utility import java.nio.file.Files import java.util.HashMap import java.util.Map @@ -19,8 +18,9 @@ import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.common.util /** * A utility class to create copies of resources. */ -@Utility class ResourceCopier { + var Map copyToOriginalMapping = new HashMap(); + /** * Indicates whether the given resource requires a full copy. * If false is returned, the resource supports a partial copy, @@ -39,7 +39,7 @@ class ResourceCopier { * @param rootElementPredicate A predicate to include only a subset of the root elements of the originalResources * @returns A mapping from each original resource to its copy */ - static def Map copyViewSourceResources(Iterable originalResources, + def Map copyViewSourceResources(Iterable originalResources, ResourceSet newResourceSet, (EObject)=>Boolean rootElementPredicate) { // do not copy xmi:id for view source resources as the change recorder does not record them // and thus the information will be lost when propagating changes back to the view source @@ -53,7 +53,7 @@ class ResourceCopier { * @param newResourceSet The resource set to which the copies are attached * @returns A mapping from each original resource to its copy */ - static def Map copyViewResources(Iterable originalResources, + def Map copyViewResources(Iterable originalResources, ResourceSet newResourceSet) { // copy xmi:id for view resources such that an exact copy is created // this is e.g. necessary for change deriving strategies that rely on identifiers @@ -67,12 +67,22 @@ class ResourceCopier { * @param newResourceSet The resource set to which the copy is attached * @returns The newly created copy of the resource */ - static def Resource copyViewResource(Resource originalResource, ResourceSet newResourceSet) { + def Resource copyViewResource(Resource originalResource, ResourceSet newResourceSet) { val mapping = copyViewResources(#[originalResource], newResourceSet) return mapping.get(originalResource) } - private static def Map copyResources(Iterable originalResources, + /** + * Returns the element to which the given element is its copy, + * or {@code null} if no such element exists. + * + * @param copy is the copied {@link EObject}. + */ + def EObject getOriginalForCopy(EObject copy) { + copyToOriginalMapping.get(copy) + } + + private def Map copyResources(Iterable originalResources, ResourceSet newResourceSet, Boolean copyXmlIds, (EObject)=>Boolean rootElementPredicate) { val resourceMapping = new HashMap() for (umlResource : originalResources.filter[isWritableUmlResource].toList) { @@ -104,7 +114,7 @@ class ResourceCopier { * To circumvent the issue, we store the UML model to a temporary resource and reload it, * because save/load properly handles the situation not covered by the copier. */ - private static def Resource copyUmlResource(Resource originalResource, ResourceSet newResourceSet) { + private def Resource copyUmlResource(Resource originalResource, ResourceSet newResourceSet) { val originalURI = originalResource.URI val tempFilePath = Files.createTempFile(null, "." + originalURI.fileExtension) val tempURI = URI.createFileURI(tempFilePath.toString) @@ -115,6 +125,7 @@ class ResourceCopier { copiedResource.URI = originalURI Files.delete(tempFilePath) EcoreUtil.resolveAll(copiedResource) + registerInMappingForUmlResources(originalResource, copiedResource) return copiedResource } @@ -126,7 +137,7 @@ class ResourceCopier { * We must NOT copy these elements but only copy the containing element and then resolve it to avoid * element duplication. */ - private static def Map copyResourcesInternal(Iterable originalResources, + private def Map copyResourcesInternal(Iterable originalResources, ResourceSet newResourceSet, Boolean copyXmlIds, (EObject)=>Boolean rootElementPredicate) { val copier = new Copier(true) var resourceMapping = new HashMap() @@ -143,7 +154,9 @@ class ResourceCopier { originalResource.URI) val selectedRootElements = originalResource.contents.filter[rootElementPredicate.apply(it)] val mappedRootElements = selectedRootElements.map [ - checkNotNull(copier.get(it), "corresponding object for %s is null", it) + val result = checkNotNull(copier.get(it), "corresponding object for %s is null", it) + registerInMapping(it, copier) + return result ] copiedResource.contents.addAll(mappedRootElements) newResourceSet.resources += copiedResource @@ -163,7 +176,7 @@ class ResourceCopier { return resourceMapping } - private static def boolean isContainedInOtherThanOwnResource(EObject eObject, Iterable resources) { + private def boolean isContainedInOtherThanOwnResource(EObject eObject, Iterable resources) { val rootContainerResource = EcoreUtil.getRootContainer(eObject).eResource return rootContainerResource !== eObject.eResource && resources.contains(rootContainerResource) } @@ -176,7 +189,7 @@ class ResourceCopier { * Copies the IDs of the source's elements to the target. * It is expected that both resources are in an identical state. */ - private static def void copyUmlIds(XMLResource source, XMLResource target) { + private def void copyUmlIds(XMLResource source, XMLResource target) { val sourceIterator = source.allContents val targetIterator = target.allContents while (sourceIterator.hasNext && targetIterator.hasNext) { @@ -189,4 +202,23 @@ class ResourceCopier { checkState(!sourceIterator.hasNext, "source uml resource has too many elements") checkState(!targetIterator.hasNext, "target uml resource has too many elements") } + + private def void registerInMapping(EObject original, EcoreUtil.Copier copier) { + copyToOriginalMapping.put(copier.get(original), original) + original.eContents.forEach [ registerInMapping(it, copier) ] + } + + private def void registerInMappingForUmlResources(Resource originalResource, Resource copiedResource) { + val originalIterator = originalResource.allContents + val copyIterator = copiedResource.allContents + while (originalIterator.hasNext && copyIterator.hasNext) { + val original = originalIterator.next + val copy = copyIterator.next + checkState(original.eClass === copy.eClass, "non matching elements %s and %s", original, + copy) + copyToOriginalMapping.put(copy, original) + } + checkState(!originalIterator.hasNext, "original uml resource has too many elements") + checkState(!copyIterator.hasNext, "copied uml resource has too many elements") + } } diff --git a/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/changederivation/BasicStateChangePropagationTest.xtend b/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/changederivation/BasicStateChangePropagationTest.xtend index 26a1040669..d39d19a1f6 100644 --- a/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/changederivation/BasicStateChangePropagationTest.xtend +++ b/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/changederivation/BasicStateChangePropagationTest.xtend @@ -6,15 +6,17 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl import org.junit.jupiter.api.DisplayName import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource +import tools.vitruv.change.atomic.EChangeIdManager import tools.vitruv.change.atomic.eobject.CreateEObject import tools.vitruv.change.atomic.eobject.DeleteEObject import tools.vitruv.change.atomic.feature.attribute.ReplaceSingleValuedEAttribute import tools.vitruv.change.atomic.root.InsertRootEObject import tools.vitruv.change.atomic.root.RemoveRootEObject +import tools.vitruv.change.atomic.uuid.UuidResolver import tools.vitruv.testutils.Capture -import static org.hamcrest.MatcherAssert.assertThat import static org.hamcrest.CoreMatchers.instanceOf +import static org.hamcrest.MatcherAssert.assertThat import static org.junit.jupiter.api.Assertions.assertEquals import static org.junit.jupiter.api.Assertions.assertTrue import static tools.vitruv.testutils.matchers.ModelMatchers.containsModelOf @@ -22,7 +24,6 @@ import static tools.vitruv.testutils.metamodels.AllElementTypesCreators.aet import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceSetUtil.withGlobalFactories import static extension tools.vitruv.testutils.Capture.operator_doubleGreaterThan -import tools.vitruv.change.atomic.uuid.UuidResolver class BasicStateChangePropagationTest extends StateChangePropagationTest { private def getTestUri() { @@ -39,17 +40,19 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { ] ] + // Create empty resource to apply generated changes to + val validationResourceSet = new ResourceSetImpl() + val validationUuidResolver = UuidResolver.create(validationResourceSet) + val changes = strategyToTest.getChangeSequenceForCreated(modelResource) + EChangeIdManager.setOrGenerateIds(changes.EChanges, uuidResolver) + changes.unresolve().resolveAndApply(validationUuidResolver) + assertEquals(3, changes.EChanges.size) assertEquals(1, changes.EChanges.filter(InsertRootEObject).size) assertEquals(1, changes.EChanges.filter(CreateEObject).size) assertEquals(1, changes.EChanges.filter(ReplaceSingleValuedEAttribute).size) - // Create empty resource to apply generated changes to - val validationResourceSet = new ResourceSetImpl() - val validationUuidResolver = UuidResolver.create(validationResourceSet) - changes.unresolve().resolveAndApply(validationUuidResolver) - modelResource.save(null) assertEquals(1, validationResourceSet.resources.size) assertThat(validationResourceSet.resources.get(0), containsModelOf(modelResource)) @@ -60,7 +63,7 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { @MethodSource("strategiesToTest") def void deleteResource(StateBasedChangeResolutionStrategy strategyToTest) { val modelResource = new Capture - resourceSet.record [ + resourceSet.record(uuidResolver) [ createResource(testUri) => [ contents += aet.Root => [ id = "Root" @@ -74,13 +77,14 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { val validationUuidResolver = UuidResolver.create(validationResourceSet) uuidResolver.resolveResource(-modelResource, oldResource, validationUuidResolver) - val changes = strategyToTest.getChangeSequenceForDeleted(-modelResource, uuidResolver) + val changes = strategyToTest.getChangeSequenceForDeleted(-modelResource) + EChangeIdManager.setOrGenerateIds(changes.EChanges, uuidResolver) + changes.unresolve().resolveAndApply(validationUuidResolver) + assertEquals(2, changes.EChanges.size) assertEquals(1, changes.EChanges.filter(RemoveRootEObject).size) assertEquals(1, changes.EChanges.filter(DeleteEObject).size) - changes.unresolve().resolveAndApply(validationUuidResolver) - assertEquals(1, validationResourceSet.resources.size) assertTrue(validationResourceSet.resources.get(0).contents.empty) } @@ -90,7 +94,7 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { @MethodSource("strategiesToTest") def void replaceRootElement(StateBasedChangeResolutionStrategy strategyToTest) { val modelResource = new Capture - resourceSet.record [ + resourceSet.record(uuidResolver) [ createResource(testUri) => [ contents += aet.Root => [ id = "Root" @@ -104,15 +108,14 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { val validationUuidResolver = UuidResolver.create(validationResourceSet) uuidResolver.resolveResource(-modelResource, oldState, validationUuidResolver) - (-modelResource).record [ + (-modelResource).record(uuidResolver) [ contents.clear() contents += aet.Root => [ id = "Root2" ] ] - val changes = strategyToTest.getChangeSequenceBetween(-modelResource, oldState, validationUuidResolver) - changes.unresolve().resolveAndApply(validationUuidResolver) + strategyToTest.getChangeSequenceBetweenAndApply(-modelResource, oldState, validationUuidResolver) assertEquals(1, validationResourceSet.resources.size) assertThat(validationResourceSet.resources.get(0), containsModelOf(-modelResource)) @@ -124,7 +127,7 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { def void changeRootElementFeature(StateBasedChangeResolutionStrategy strategyToTest) { val modelResource = new Capture val root = aet.Root - resourceSet.record [ + resourceSet.record(uuidResolver) [ createResource(testUri) => [ contents += root => [ id = "Root" @@ -138,16 +141,15 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { val validationUuidResolver = UuidResolver.create(validationResourceSet) uuidResolver.resolveResource(-modelResource, oldState, validationUuidResolver) - resourceSet.record [ + resourceSet.record(uuidResolver) [ root.singleValuedEAttribute = 2 ] - val changes = strategyToTest.getChangeSequenceBetween(-modelResource, oldState, validationUuidResolver) + val changes = strategyToTest.getChangeSequenceBetweenAndApply(-modelResource, oldState, validationUuidResolver) + EChangeIdManager.setOrGenerateIds(changes.EChanges, validationUuidResolver) assertEquals(1, changes.EChanges.size) assertEquals(1, changes.EChanges.filter(ReplaceSingleValuedEAttribute).size) - changes.unresolve().resolveAndApply(validationUuidResolver) - assertEquals(1, validationResourceSet.resources.size) assertThat(validationResourceSet.resources.get(0), containsModelOf(-modelResource)) } @@ -158,7 +160,7 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { def void changeRootElementId(DefaultStateBasedChangeResolutionStrategy strategyToTest) { val modelResource = new Capture val root = aet.Root - resourceSet.record [ + resourceSet.record(uuidResolver) [ createResource(testUri) => [ contents += root => [ id = "Root" @@ -172,11 +174,11 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { val validationUuidResolver = UuidResolver.create(validationResourceSet) uuidResolver.resolveResource(-modelResource, oldState, validationUuidResolver) - resourceSet.record [ + resourceSet.record(uuidResolver) [ root.id = "Root2" ] - val changes = strategyToTest.getChangeSequenceBetween(-modelResource, oldState, validationUuidResolver) + var changes = strategyToTest.getChangeSequenceBetweenAndApply(-modelResource, oldState, validationUuidResolver) switch (strategyToTest.useIdentifiers) { case ONLY, case WHEN_AVAILABLE: { @@ -196,8 +198,6 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { } } - changes.unresolve().resolveAndApply(validationUuidResolver) - assertEquals(1, validationResourceSet.resources.size) assertThat(validationResourceSet.resources.get(0), containsModelOf(-modelResource)) } @@ -209,7 +209,7 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { val modelResource = new Capture val root = aet.Root val containedRoot = aet.Root - resourceSet.record [ + resourceSet.record(uuidResolver) [ createResource(testUri) => [ contents += root => [ id = "Root" @@ -227,16 +227,14 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { val validationUuidResolver = UuidResolver.create(validationResourceSet) uuidResolver.resolveResource(-modelResource, oldState, validationUuidResolver) - resourceSet.record [ + resourceSet.record(uuidResolver) [ containedRoot.singleValuedEAttribute = 1 ] - val changes = strategyToTest.getChangeSequenceBetween(-modelResource, oldState, validationUuidResolver) + val changes = strategyToTest.getChangeSequenceBetweenAndApply(-modelResource, oldState, validationUuidResolver) assertEquals(1, changes.EChanges.size) assertEquals(1, changes.EChanges.filter(ReplaceSingleValuedEAttribute).size) - changes.unresolve().resolveAndApply(validationUuidResolver) - assertEquals(1, validationResourceSet.resources.size) assertThat(validationResourceSet.resources.get(0), containsModelOf(-modelResource)) } @@ -248,7 +246,7 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { val modelResource = new Capture val root = aet.Root val containedRoot = aet.Root - resourceSet.record [ + resourceSet.record(uuidResolver) [ createResource(testUri) => [ contents += root => [ id = "Root" @@ -266,11 +264,11 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { val validationUuidResolver = UuidResolver.create(validationResourceSet) uuidResolver.resolveResource(-modelResource, oldState, validationUuidResolver) - resourceSet.record [ + resourceSet.record(uuidResolver) [ containedRoot.id = "ContainedRoot2" ] - val changes = strategyToTest.getChangeSequenceBetween(-modelResource, oldState, validationUuidResolver) + val changes = strategyToTest.getChangeSequenceBetweenAndApply(-modelResource, oldState, validationUuidResolver) switch (strategyToTest.useIdentifiers) { case ONLY, case WHEN_AVAILABLE: { @@ -290,8 +288,6 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { } } - changes.unresolve().resolveAndApply(validationUuidResolver) - assertEquals(1, validationResourceSet.resources.size) assertThat(validationResourceSet.resources.get(0), containsModelOf(-modelResource)) } @@ -302,7 +298,7 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { def void moveResource(StateBasedChangeResolutionStrategy strategyToTest) { val modelResource = new Capture val root = aet.Root - resourceSet.record [ + resourceSet.record(uuidResolver) [ createResource(testUri) => [ contents += root => [ id = "Root" @@ -317,19 +313,17 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { uuidResolver.resolveResource(-modelResource, oldState, validationUuidResolver) val movedResourceUri = getModelURI("moved.allElementTypes") - resourceSet.record [ + resourceSet.record(uuidResolver) [ createResource(movedResourceUri) => [ contents += root ] >> modelResource ] - val changes = strategyToTest.getChangeSequenceBetween(-modelResource, oldState, validationUuidResolver) + val changes = strategyToTest.getChangeSequenceBetweenAndApply(-modelResource, oldState, validationUuidResolver) assertEquals(2, changes.EChanges.size) assertEquals(1, changes.EChanges.filter(RemoveRootEObject).size) assertEquals(1, changes.EChanges.filter(InsertRootEObject).size) - changes.unresolve().resolveAndApply(validationUuidResolver) - (-modelResource).save(null) assertEquals(2, validationResourceSet.resources.size) assertThat(validationResourceSet.getResource(movedResourceUri, false), containsModelOf(-modelResource)) @@ -341,7 +335,7 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { def void moveResourceAndChangeRootFeature(StateBasedChangeResolutionStrategy strategyToTest) { val modelResource = new Capture val root = aet.Root - resourceSet.record [ + resourceSet.record(uuidResolver) [ createResource(testUri) => [ contents += root => [ id = "Root" @@ -356,7 +350,7 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { uuidResolver.resolveResource(-modelResource, oldState, validationUuidResolver) val movedResourceUri = getModelURI("moved.allElementTypes") - resourceSet.record [ + resourceSet.record(uuidResolver) [ (-modelResource).contents -= root root.singleValuedEAttribute = 2 createResource(movedResourceUri) => [ @@ -364,14 +358,12 @@ class BasicStateChangePropagationTest extends StateChangePropagationTest { ] >> modelResource ] - val changes = strategyToTest.getChangeSequenceBetween(-modelResource, oldState, validationUuidResolver) + val changes = strategyToTest.getChangeSequenceBetweenAndApply(-modelResource, oldState, validationUuidResolver) assertEquals(3, changes.EChanges.size) assertEquals(1, changes.EChanges.filter(RemoveRootEObject).size) assertEquals(1, changes.EChanges.filter(InsertRootEObject).size) assertEquals(1, changes.EChanges.filter(ReplaceSingleValuedEAttribute).size) - changes.unresolve().resolveAndApply(validationUuidResolver) - (-modelResource).save(null) assertEquals(2, validationResourceSet.resources.size) assertThat(validationResourceSet.getResource(movedResourceUri, false), containsModelOf(-modelResource)) diff --git a/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/changederivation/StateChangePropagationTest.xtend b/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/changederivation/StateChangePropagationTest.xtend index 70fc24f1d4..2638463c17 100644 --- a/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/changederivation/StateChangePropagationTest.xtend +++ b/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/changederivation/StateChangePropagationTest.xtend @@ -104,7 +104,7 @@ abstract class StateChangePropagationTest { protected def compareChanges(Resource model, Resource checkpoint, StateBasedChangeResolutionStrategy strategyToTest) { model.save(null) val deltaBasedChange = resourceSet.endRecording - val stateBasedChange = strategyToTest.getChangeSequenceBetween(model, checkpoint, checkpointUuidResolver) + val stateBasedChange = strategyToTest.getChangeSequenceBetweenAndApply(model, checkpoint, checkpointUuidResolver) assertNotNull(stateBasedChange) val message = getTextualRepresentation(stateBasedChange, deltaBasedChange) val stateBasedChangedObjects = stateBasedChange.affectedAndReferencedEObjects @@ -180,4 +180,10 @@ abstract class StateChangePropagationTest { protected def URI getModelURI(String modelFileName) { return testProjectFolder.resolve("model").resolve(modelFileName).toFile().createFileURI() } + + protected def getChangeSequenceBetweenAndApply(StateBasedChangeResolutionStrategy strategy, Resource newState, Resource oldState, UuidResolver oldStateUuidResolver) { + val changes = strategy.getChangeSequenceBetween(newState, oldState) + EChangeIdManager.setOrGenerateIds(changes.EChanges, oldStateUuidResolver) + return changes.unresolve.resolveAndApply(oldStateUuidResolver) + } } diff --git a/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/util/XmiIdEdgeCaseTest.java b/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/util/XmiIdEdgeCaseTest.java index ce2cf79b28..aa87fc1c44 100644 --- a/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/util/XmiIdEdgeCaseTest.java +++ b/tests/tools.vitruv.framework.views.tests/src/tools/vitruv/framework/views/util/XmiIdEdgeCaseTest.java @@ -45,7 +45,7 @@ void setup(@TestProject Path testProjectFolder) { public void testSingleResourceCopy() { Pair> umlResourcePair = createPopulatedUmlResourceAndIdMapping("my"); ResourceSet copyResourceSet = new ResourceSetImpl(); - XMLResource copiedModel = (XMLResource) ResourceCopier.copyViewResource(umlResourcePair.get0(), + XMLResource copiedModel = (XMLResource) new ResourceCopier().copyViewResource(umlResourcePair.get0(), copyResourceSet); validateIds(copiedModel, umlResourcePair.get1()); } @@ -57,7 +57,7 @@ public void testMultiResourceCopy() { Pair> umlResourcePair3 = createPopulatedUmlResourceAndIdMapping("my3"); ResourceSet copyResourceSet = new ResourceSetImpl(); - Map copiedModels = ResourceCopier.copyViewResources( + Map copiedModels = new ResourceCopier().copyViewResources( List.of(umlResourcePair.get0(), umlResourcePair2.get0(), umlResourcePair3.get0()), copyResourceSet); XMLResource copiedModel = (XMLResource) copiedModels.get(umlResourcePair.get0()); XMLResource copiedModel2 = (XMLResource) copiedModels.get(umlResourcePair2.get0());