diff options
author | Arnaud Dieumegard | 2020-08-27 17:52:28 +0000 |
---|---|---|
committer | Florian Barbin | 2020-10-30 14:55:07 +0000 |
commit | 58225c715f3684bdcabdb0147d304b48a226d556 (patch) | |
tree | cd79d4bef0ac9c8ae15b8e49fed99b55f70566d5 | |
parent | fee05cc66ee3f95054b0380917dc03ca786a9aa6 (diff) | |
download | org.eclipse.sirius-58225c715f3684bdcabdb0147d304b48a226d556.tar.gz org.eclipse.sirius-58225c715f3684bdcabdb0147d304b48a226d556.tar.xz org.eclipse.sirius-58225c715f3684bdcabdb0147d304b48a226d556.zip |
[563117] Add API call arguments checks
Add checks for call arguments: diagrams, sessions, map, target diagram
name. Add related tests. Add documentation.
Bug: 563117
Change-Id: I162cc5f6d2245cd7c164ff3488c17232b75c4c98
Signed-off-by: Arnaud Dieumegard <arnaud.dieumegard@obeo.fr>
7 files changed, 792 insertions, 34 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties index 80068d68e2..35810099f4 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties @@ -1362,4 +1362,14 @@ _UI_LayoutOption_targets_feature = Targets MappingBasedDiagramContentDumplicationSwitch_ImpossibleToFindBestMapping=Impossible to find a suitable Mapping from BestMappingGetter for element {0} MappingBasedSiriusFormatManagerFactory_ImpossibleToCopyNoteInNonExistingOrUnreachableTarget=Impossible to link note to non existing or unreachable target diagram element created from {0} MappingBasedSiriusFormatManagerFactory_ImpossibleToResolveOtherBoundTargetNote=Impossible to resolve edge's other bound target diagram note created from {0} -MappingBasedSiriusFormatManagerFactory_ImpossibleToFindTargetTextNoteContainer=Impossible to find target diagram parent node for {0}
\ No newline at end of file +MappingBasedSiriusFormatManagerFactory_ImpossibleToFindTargetTextNoteContainer=Impossible to find target diagram parent node for {0} +MappingBasedDiagramContentDumplicationSwitch_ErrorImpossibleToCreateNodeFromNodeCandidate=Cannot create a new node based on node candidate {0} computed from source diagram element {1} +MappingBasedDiagramContentDumplicationSwitch_ErrorImpossibleToCreateEdgeFromEdgeCandidate=Cannot create a new edge based on edge candidate {0} computed from source diagram element {1} +MappingBasedSiriusFormatManagerFactory_ErrorMappingfunctionIncompleteOnSequenceDiagram=Source to target semantic mapping must provide a mapping for each semantic elements of the source sequence diagram {0} +MappingBasedSiriusFormatManagerFactory_ErrorMappingfunctionIsEmpty=Source to target semantic mapping must not be empty +MappingBasedSiriusFormatManagerFactory_ErrorDiagramIsNull=Diagram parameters must not be null +MappingBasedSiriusFormatManagerFactory_ErrorTargetDiagramNameIsEmpty=Created target diagram name must not be empty +MappingBasedSiriusFormatManagerFactory_ErrorSourceAndTargetDiagramDecriptionsDoesNotMatch= Source diagram description {0} does not match with target diagram description {1} +MappingBasedSiriusFormatManagerFactory_ErrorSourceAndTargetDiagramsAreTheSame=Source and target diagrams must be different +MappingBasedSiriusFormatManagerFactory_ErrorSourceAndOrTargetSessionsNull=Source and/or target session must not be null +MappingBasedSiriusFormatManagerFactory_ErrorTargetDiagramRootIsNull=Target diagram root element must not be null
\ No newline at end of file diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/MappingBasedSiriusFormatManagerFactory.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/MappingBasedSiriusFormatManagerFactory.java index eabf5540b8..3320bf5ab1 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/MappingBasedSiriusFormatManagerFactory.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/MappingBasedSiriusFormatManagerFactory.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.emf.common.command.Command; @@ -108,25 +109,29 @@ public class MappingBasedSiriusFormatManagerFactory { * Apply format on {@code targetDiagram} based on the {@code sourceDiagram}. Format data are applied only for * diagram elements whose semantic object is provided in the {@code correspondenceMap}. * + * Calls to this API shall be embedded in a command. + * * @param sourceSession - * The {@link Session} for the source diagram + * The {@link Session} for the source diagram. Must not be null. * @param sourceDiagram - * The source diagram + * The source diagram. Must not be null. * @param correspondenceMap - * The mapping function between source diagram elements and target diagram elements + * The mapping function between source diagram elements and target diagram elements Must not be null. In + * the case where {@code sourceDiagram} is a Sequence diagram, must provide a mapping for each semantic + * element of {@code sourceDiagram}. * @param targetSession - * The {@link Session} for the target diagram + * The {@link Session} for the target diagram. Must not be null. * @param targetDiagram - * The target diagram + * The target diagram. Must not be null. * @param copyNotes - * Whether or not to copy source diagram notes to target diagram + * Whether or not to copy source diagram notes to target diagram. * @return The target diagram. */ public DDiagram applyFormatOnDiagram(Session sourceSession, DDiagram sourceDiagram, final Map<EObject, EObject> correspondenceMap, Session targetSession, DDiagram targetDiagram, boolean copyNotes) { // Check application correction - checkApplyFormatOnDiagramCallCorrection(sourceDiagram, correspondenceMap, targetDiagram); + checkApplyFormatOnDiagramCallCorrection(sourceDiagram, correspondenceMap, targetDiagram, sourceSession, targetSession); // Apply format according to map applyFormatAccordingToMap(sourceSession, sourceDiagram, correspondenceMap, targetSession, targetDiagram, copyNotes); @@ -135,30 +140,35 @@ public class MappingBasedSiriusFormatManagerFactory { } /** - * Apply format on a new {@link DDiagram} for name @code {@code targetDiagramName} based on the - * {@code sourceDiagram}. Format data are applied only for diagram elements whose semantic object is provided in the + * Apply format on a new {@link DDiagram} for name {@code targetDiagramName} based on the {@code sourceDiagram}. + * Format data are applied only for diagram elements whose semantic object is provided in the * {@code correspondenceMap}. * + * Calls to this API shall be embedded in a command. + * * @param sourceSession - * The {@link Session} for the source diagram + * The {@link Session} for the source diagram. Must not be null. * @param sourceDiagram - * The source diagram + * The source diagram. Must not be null. * @param correspondenceMap - * The mapping function between source diagram elements and target diagram elements + * The mapping function between source diagram elements and target diagram elements. Must not be null. In + * the case where {@code sourceDiagram} is a Sequence diagram, must provide a mapping for each semantic + * element of {@code sourceDiagram}. * @param targetSession - * The {@link Session} for the target diagram + * The {@link Session} for the target diagram. Must not be null. * @param targetDiagramName - * The target diagram name + * The target diagram name. Must not be null or equal to "". * @param targetDiagramRoot - * The root EObject for the new diagram + * The root EObject for the new diagram. Must not be null. * @param copyNotes - * Whether or not to copy source diagram notes to target diagram + * Whether or not to copy source diagram notes to target diagram. * @return The created target diagram. */ public DDiagram applyFormatOnNewDiagram(Session sourceSession, DDiagram sourceDiagram, final Map<EObject, EObject> correspondenceMap, Session targetSession, String targetDiagramName, EObject targetDiagramRoot, boolean copyNotes) { + // Check application correction - checkApplyFormatOnNewDiagramCallCorrection(sourceDiagram, correspondenceMap, targetDiagramName); + checkApplyFormatOnNewDiagramCallCorrection(sourceDiagram, correspondenceMap, targetDiagramName, sourceSession, targetSession, targetDiagramRoot); DSemanticDiagram targetDiagram = createRepresentation(sourceDiagram, targetSession, targetDiagramName, targetDiagramRoot); @@ -177,8 +187,6 @@ public class MappingBasedSiriusFormatManagerFactory { diagramContentDuplicationSwitch = new MappingBasedDiagramContentDuplicationSwitch((DSemanticDiagram) targetDiagram, correspondenceMap, targetSession); diagramContentDuplicationSwitch.doSwitch(sourceDiagram); - isAppliedOnSequenceDiagram = computeIsSequenceDiagram(sourceDiagram); - DiagramEditPart sourceDiagramEditPart = null; DiagramEditPart targetDiagramEditPart = null; try { @@ -220,12 +228,40 @@ public class MappingBasedSiriusFormatManagerFactory { * The correspondence map. * @param targetDiagram * The target diagram. + * @param targetSession + * The source diagram session. + * @param sourceSession + * The target diagram session. */ - private void checkApplyFormatOnDiagramCallCorrection(DDiagram sourceDiagram, final Map<EObject, EObject> correspondenceMap, DDiagram targetDiagram) { + private void checkApplyFormatOnDiagramCallCorrection(DDiagram sourceDiagram, final Map<EObject, EObject> correspondenceMap, DDiagram targetDiagram, Session sourceSession, Session targetSession) { + checkDiagram(sourceDiagram); + checkDiagram(targetDiagram); + checkSourceDiagramVSTargetDiagram(sourceDiagram, targetDiagram); + checkSourceAndTargetSessions(sourceSession, targetSession); + isAppliedOnSequenceDiagram = computeIsSequenceDiagram(sourceDiagram); + checkMapSourceCorrection(sourceDiagram, correspondenceMap); + } + + private void checkDiagram(DDiagram diagram) { + if (diagram == null) { + throw new IllegalArgumentException(Messages.MappingBasedSiriusFormatManagerFactory_ErrorDiagramIsNull); + } + } + + private void checkSourceDiagramVSTargetDiagram(DDiagram sourceDiagram, DDiagram targetDiagram) { + if (sourceDiagram.equals(targetDiagram)) { + throw new IllegalArgumentException(Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndTargetDiagramsAreTheSame); + } if (!sourceDiagram.getDescription().equals(targetDiagram.getDescription())) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException(MessageFormat.format(Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndTargetDiagramDecriptionsDoesNotMatch, sourceDiagram.getDescription(), + targetDiagram.getDescription())); + } + } + + private void checkSourceAndTargetSessions(Session sourceSession, Session targetSession) { + if (sourceSession == null || targetSession == null) { + throw new IllegalArgumentException(Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndOrTargetSessionsNull); } - checkMapCorrection(sourceDiagram, correspondenceMap, targetDiagram); } /** @@ -239,12 +275,24 @@ public class MappingBasedSiriusFormatManagerFactory { * The correspondence map. * @param targetDiagramName * The new target diagram name. + * @param targetSession + * The source diagram session. + * @param sourceSession + * The target diagram session. + * @param targetDiagramRoot */ - private void checkApplyFormatOnNewDiagramCallCorrection(DDiagram sourceDiagram, final Map<EObject, EObject> correspondenceMap, String targetDiagramName) { - if (sourceDiagram == null || targetDiagramName.isEmpty()) { - throw new IllegalArgumentException(); + private void checkApplyFormatOnNewDiagramCallCorrection(DDiagram sourceDiagram, final Map<EObject, EObject> correspondenceMap, String targetDiagramName, Session sourceSession, + Session targetSession, EObject targetDiagramRoot) { + checkDiagram(sourceDiagram); + if (targetDiagramName == null || targetDiagramName.isEmpty()) { + throw new IllegalArgumentException(Messages.MappingBasedSiriusFormatManagerFactory_ErrorTargetDiagramNameIsEmpty); + } + if (targetDiagramRoot == null) { + throw new IllegalArgumentException(Messages.MappingBasedSiriusFormatManagerFactory_ErrorTargetDiagramRootIsNull); } - checkMapCorrection(sourceDiagram, correspondenceMap, sourceDiagram); + checkSourceAndTargetSessions(sourceSession, targetSession); + isAppliedOnSequenceDiagram = computeIsSequenceDiagram(sourceDiagram); + checkMapSourceCorrection(sourceDiagram, correspondenceMap); } /** @@ -256,16 +304,18 @@ public class MappingBasedSiriusFormatManagerFactory { * The source diagram. * @param correspondenceMap * The correspondence map to check. - * @param targetDiagram - * The target diagram. */ - private void checkMapCorrection(DDiagram sourceDiagram, final Map<EObject, EObject> correspondenceMap, DDiagram targetDiagram) { + private void checkMapSourceCorrection(DDiagram sourceDiagram, final Map<EObject, EObject> correspondenceMap) { if (correspondenceMap.isEmpty()) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException(Messages.MappingBasedSiriusFormatManagerFactory_ErrorMappingfunctionIsEmpty); + } + if (isAppliedOnSequenceDiagram) { + List<EObject> allSourceDiagramSemanticElements = sourceDiagram.getDiagramElements().stream().map(DDiagramElement::getTarget).collect(Collectors.toList()); + boolean contains = correspondenceMap.keySet().containsAll(allSourceDiagramSemanticElements); + if (!contains) { + throw new IllegalArgumentException(MessageFormat.format(Messages.MappingBasedSiriusFormatManagerFactory_ErrorMappingfunctionIncompleteOnSequenceDiagram, sourceDiagram)); + } } - // TODO check map - // sourceObject to targetObject correction = sourceDiagram[sourceObject].mapping compatible with - // targetDiagram[targetObject] ? } /** diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/semantic/MappingBasedDiagramContentDuplicationSwitch.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/semantic/MappingBasedDiagramContentDuplicationSwitch.java index 164cd53909..65a52784ac 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/semantic/MappingBasedDiagramContentDuplicationSwitch.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/semantic/MappingBasedDiagramContentDuplicationSwitch.java @@ -343,6 +343,9 @@ public class MappingBasedDiagramContentDuplicationSwitch extends DiagramSwitch<V // createdTargetElement.getGraphicalFilters() // find hide filter and copy from getSourceDDiagramElementToTargetDDiagramElementMap().put(sourceDElement, createdTargetElement); + } else { + throw new IllegalArgumentException( + MessageFormat.format(Messages.MappingBasedDiagramContentDumplicationSwitch_ErrorImpossibleToCreateNodeFromNodeCandidate, abstractDNodeCandidate, sourceDElement)); } } @@ -446,6 +449,9 @@ public class MappingBasedDiagramContentDuplicationSwitch extends DiagramSwitch<V createdNewEdge.setVisible(toHandleEdge.isVisible()); handledEdges.add(toHandleEdge); getSourceDDiagramElementToTargetDDiagramElementMap().put(toHandleEdge, createdNewEdge); + } else { + throw new IllegalArgumentException( + MessageFormat.format(Messages.MappingBasedDiagramContentDumplicationSwitch_ErrorImpossibleToCreateEdgeFromEdgeCandidate, abstractDEdgeCandidate, toHandleEdge)); } } else { edgesToEdge.add(toHandleEdge); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java index c33a42648d..8762dae178 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java @@ -1627,6 +1627,36 @@ public final class Messages { @TranslatableMessage public static String MappingBasedSiriusFormatManagerFactory_ImpossibleToFindTargetTextNoteContainer; + @TranslatableMessage + public static String MappingBasedDiagramContentDumplicationSwitch_ErrorImpossibleToCreateNodeFromNodeCandidate; + + @TranslatableMessage + public static String MappingBasedDiagramContentDumplicationSwitch_ErrorImpossibleToCreateEdgeFromEdgeCandidate; + + @TranslatableMessage + public static String MappingBasedSiriusFormatManagerFactory_ErrorMappingfunctionIncompleteOnSequenceDiagram; + + @TranslatableMessage + public static String MappingBasedSiriusFormatManagerFactory_ErrorMappingfunctionIsEmpty; + + @TranslatableMessage + public static String MappingBasedSiriusFormatManagerFactory_ErrorDiagramIsNull; + + @TranslatableMessage + public static String MappingBasedSiriusFormatManagerFactory_ErrorTargetDiagramNameIsEmpty; + + @TranslatableMessage + public static String MappingBasedSiriusFormatManagerFactory_ErrorSourceAndTargetDiagramDecriptionsDoesNotMatch; + + @TranslatableMessage + public static String MappingBasedSiriusFormatManagerFactory_ErrorSourceAndTargetDiagramsAreTheSame; + + @TranslatableMessage + public static String MappingBasedSiriusFormatManagerFactory_ErrorSourceAndOrTargetSessionsNull; + + @TranslatableMessage + public static String MappingBasedSiriusFormatManagerFactory_ErrorTargetDiagramRootIsNull; + // CHECKSTYLE:ON private Messages() { // Prevents instanciation. diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java index b8b82daed3..cd7d713671 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java @@ -134,6 +134,8 @@ import org.eclipse.sirius.tests.unit.diagram.format.data.FormatHelperImplEdgeFor import org.eclipse.sirius.tests.unit.diagram.format.data.FormatHelperImplNodeFormatData1Test; import org.eclipse.sirius.tests.unit.diagram.format.data.FormatHelperImplNodeFormatData2Test; import org.eclipse.sirius.tests.unit.diagram.format.data.LabelPositionOnContainerAndListTest; +import org.eclipse.sirius.tests.unit.diagram.format.data.MappingBasedSiriusFormatDataManagerCallCheckSequenceTest; +import org.eclipse.sirius.tests.unit.diagram.format.data.MappingBasedSiriusFormatDataManagerCallCheckTest; import org.eclipse.sirius.tests.unit.diagram.format.data.MappingBasedSiriusFormatDataManagerCreateTargetDiagramTest; import org.eclipse.sirius.tests.unit.diagram.format.data.MappingBasedSiriusFormatDataManagerCreateTargetSequenceDiagramTest; import org.eclipse.sirius.tests.unit.diagram.format.data.MappingBasedSiriusFormatDataManagerExistingTargetDiagramTest; @@ -450,6 +452,8 @@ public class AllDiagramPluginsTests { suite.addTest(new JUnit4TestAdapter(MappingBasedSiriusFormatDataManagerExistingTargetDiagramTest.class)); suite.addTest(new JUnit4TestAdapter(MappingBasedSiriusFormatDataManagerCreateTargetSequenceDiagramTest.class)); suite.addTest(new JUnit4TestAdapter(MappingBasedSiriusFormatDataManagerExistingTargetSequenceDiagramTest.class)); + suite.addTest(new JUnit4TestAdapter(MappingBasedSiriusFormatDataManagerCallCheckTest.class)); + suite.addTest(new JUnit4TestAdapter(MappingBasedSiriusFormatDataManagerCallCheckSequenceTest.class)); suite.addTestSuite(LabelPositionOnContainerAndListTest.class); suite.addTestSuite(LabelVisibilityOnDragAndDropTests.class); suite.addTestSuite(LabelVisibilityOnCreationTest.class); diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/format/data/MappingBasedSiriusFormatDataManagerCallCheckSequenceTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/format/data/MappingBasedSiriusFormatDataManagerCallCheckSequenceTest.java new file mode 100644 index 0000000000..40ea8c2d09 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/format/data/MappingBasedSiriusFormatDataManagerCallCheckSequenceTest.java @@ -0,0 +1,293 @@ +/******************************************************************************* + * Copyright (c) 2020 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.unit.diagram.format.data; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.DDiagramElement; +import org.eclipse.sirius.diagram.DSemanticDiagram; +import org.eclipse.sirius.diagram.ui.provider.Messages; +import org.eclipse.sirius.diagram.ui.tools.api.format.MappingBasedSiriusFormatManagerFactory; +import org.eclipse.sirius.diagram.ui.tools.api.format.semantic.MappingBasedSiriusFormatDataManager; +import org.eclipse.sirius.tests.SiriusTestsPlugin; +import org.eclipse.sirius.tests.support.api.TestsUtil; +import org.eclipse.sirius.tests.unit.diagram.format.data.manager.mappingbased.MappingBasedTestConfiguration; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.sirius.viewpoint.ViewpointFactory; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test class for {@link MappingBasedSiriusFormatDataManager}. Inspired from + * {@link SiriusFormatDataManagerForSemanticElementsApplyWithPredefinedDataTest}. + * + * @author adieumegard + */ +@RunWith(value = Parameterized.class) +public class MappingBasedSiriusFormatDataManagerCallCheckSequenceTest extends AbstractMappingBasedSiriusFormatDataManagerTest { + + @SuppressWarnings("hiding") + protected static final String DATA_PATH = "data/sequence/unit/layout/mappingbased/"; + + @SuppressWarnings("hiding") + protected static final String SEMANTIC_MODEL_NAME = "fixture.interactions"; + + @SuppressWarnings("hiding") + protected static final String SEMANTIC_TARGET_MODEL_NAME = "targetfixture.interactions"; + + protected static final String TYPES_MODEL_NAME = "types.ecore"; + + @SuppressWarnings("hiding") + protected static final String SESSION_MODEL_NAME = "fixture.aird"; + + @SuppressWarnings("hiding") + protected static final String MODELER_NAME = "../../variablesAccess/variablesAccess.odesign"; + + @Override + protected String getSessionModelName() { + return SESSION_MODEL_NAME; + } + + @Override + protected String getSemanticModelName() { + return SEMANTIC_MODEL_NAME; + } + + @Override + protected String getSemanticTargetModelName() { + return SEMANTIC_TARGET_MODEL_NAME; + } + + @Override + protected String getModelerName() { + return MODELER_NAME; + } + + @Override + protected String getDataPath() { + return DATA_PATH; + } + + protected static final Predicate<Diagram> ONLY_RAW_DIAGRAM = new Predicate<Diagram>() { + + @Override + public boolean test(final Diagram input) { + return input.raw; + } + }; + + protected static final Diagram MB_SEQ_BASIC_COMBINED = new Diagram("Basic Combined Fragment Diagram", 0, 0); + + protected static final Diagram MB_SEQ_BASIC_COMBINED_RAW = new Diagram("Basic Combined Fragment Diagram Raw", 0, 0, true); + + protected static final Representation MB_SEQ_REPRES_BASIC_COMBINED = new Representation("Sequence Diagram on Interaction", MB_SEQ_BASIC_COMBINED, MB_SEQ_BASIC_COMBINED_RAW); + + @Parameters + public static Collection<Object[]> data() { + // We could use @Theories and @Datapoints but the theory stops as soon + // as there is a failure. With parameters, we have feedback for all + // scenarii. + Collection<Object[]> data = new ArrayList<>(); + data.add(new Object[] { MB_SEQ_REPRES_BASIC_COMBINED }); + return data; + } + + /** + * Compute configuration for source to target EObjects mapping. Uses all the source model elements and removes one + * of them + * + * @return + */ + protected MappingBasedTestConfiguration getFaultyTestConfiguration(EObject root) { + Map<String, String> full_map = new HashMap<String, String>(); + String sourceRootID = MappingBasedTestConfiguration.getID(root); + String targetRootID = MappingBasedTestConfiguration.getID(root, "target"); + full_map.put(sourceRootID, targetRootID); + + root.eAllContents().forEachRemaining(element -> { + String sourceID = MappingBasedTestConfiguration.getID(element); + String targetID = MappingBasedTestConfiguration.getID(element, "target"); + full_map.put(sourceID, targetID); + }); + + String toRemove = full_map.keySet().stream().filter(key -> !key.equals(sourceRootID)).findFirst().get(); + full_map.remove(toRemove); + + return new MappingBasedTestConfiguration(semanticModel, semanticTargetModel, full_map, "", "fullFaulty"); + } + + /** + * Constructor for parameterized test. + * + * @param representationToCopyFormat + * a representation description + * @param representationToPasteFormat + * a representation description + * @param diagramToCopyFormatZoomData + * the zoom data to set for format copy in the current scenario + * @param diagramToPasteFormatZoomData + * the zoom data to set for format application in the current scenario + * @throws Exception + */ + public MappingBasedSiriusFormatDataManagerCallCheckSequenceTest(Representation representationToCopyFormat) throws Exception { + super(representationToCopyFormat); + } + + @Override + @Before + public void setUp() throws Exception { + copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, getDataPath(), TYPES_MODEL_NAME); + super.setUp(); + } + + /** + * Test method. + * + * @throws Exception + * Test error. + */ + @Test + public void testCallCheckMapCompleteness() throws Exception { + if (TestsUtil.shouldSkipLongTests()) { + return; + } + + final DDiagram diagramToCopyFormat = getDiagram(MB_SEQ_REPRES_BASIC_COMBINED, MB_SEQ_BASIC_COMBINED); + final DDiagram diagramToPasteFormat = getDiagram(MB_SEQ_REPRES_BASIC_COMBINED, MB_SEQ_BASIC_COMBINED_RAW); + + Collection<DiagramEditPart> diagramToCopyEditParts = getDiagramEditPart(session, diagramToCopyFormat); + assertTrue(!diagramToCopyEditParts.isEmpty()); + final DiagramEditPart diagramToCopyEditPart = diagramToCopyEditParts.stream().findFirst().get(); + final EObject semanticElement = diagramToCopyEditPart.resolveSemanticElement(); + EObject rootDiagramElement = null; + if (semanticElement instanceof DSemanticDiagram) { + rootDiagramElement = ((DSemanticDiagram) semanticElement).getTarget(); + } else if (semanticElement instanceof DDiagramElement) { + rootDiagramElement = ((DDiagramElement) semanticElement).getTarget(); + } + try { + applyPredefinedFormatDataOnRawDiagrams(diagramToCopyFormat, diagramToPasteFormat, getFaultyTestConfiguration(rootDiagramElement)); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), MessageFormat.format(Messages.MappingBasedSiriusFormatManagerFactory_ErrorMappingfunctionIncompleteOnSequenceDiagram, diagramToCopyFormat)); + } + } + + private DDiagram getDiagram(Representation rep, Diagram diag) { + + List<DRepresentationDescriptor> allDDiagramDescriptors = getRepresentationDescriptors(rep.name, session).stream().collect(Collectors.toList()); + Collections.sort(allDDiagramDescriptors, USING_NAME); + DRepresentationDescriptor dRepresentationDescriptorToFind = ViewpointFactory.eINSTANCE.createDRepresentationDescriptor(); + dRepresentationDescriptorToFind.setName(diag.name); + final int search = Collections.binarySearch(allDDiagramDescriptors, dRepresentationDescriptorToFind, USING_NAME); + + assertTrue("Source Diagram " + dRepresentationDescriptorToFind.getName() + " is not found in representation", search > -1); + + return (DDiagram) allDDiagramDescriptors.get(search).getRepresentation(); + } + + protected void applyPredefinedFormatDataOnRawDiagrams(DDiagram diagramToCopyFormat, DDiagram diagramToPasteFormat, MappingBasedTestConfiguration mapTestConfiguration) throws Exception { + + Map<EObject, EObject> map = mapTestConfiguration.getObjectsMap(); + + try { + final RecordingCommand command = new RecordingCommand(session.getTransactionalEditingDomain()) { + @Override + protected void doExecute() { + // Update diagram, but transaction will be rollbacked + DDiagram newDiagram = MappingBasedSiriusFormatManagerFactory.getInstance().applyFormatOnDiagram(session, diagramToCopyFormat, map, session, diagramToPasteFormat, false); + } + }; + + try { + // Force rollback of transaction to let raw diagram + // unchanged + session.getTransactionalEditingDomain().addResourceSetListener(ROLLBACK_LISTENER); + session.getTransactionalEditingDomain().getCommandStack().execute(command); + } finally { + session.getTransactionalEditingDomain().removeResourceSetListener(ROLLBACK_LISTENER); + } + TestsUtil.synchronizationWithUIThread(); + + } finally { + + } + } + + protected void applyPredefinedFormatDataOnNewDiagram(DDiagram diagramToCopyFormat, MappingBasedTestConfiguration mapTestConfiguration, String diagramName, EObject targetDiagramRoot) + throws Exception { + + Map<EObject, EObject> map = mapTestConfiguration.getObjectsMap(); + + try { + final RecordingCommand command = new RecordingCommand(session.getTransactionalEditingDomain()) { + @Override + protected void doExecute() { + // Update diagram, but transaction will be rollbacked + DDiagram newDiagram = MappingBasedSiriusFormatManagerFactory.getInstance().applyFormatOnNewDiagram(session, diagramToCopyFormat, map, session, diagramName, targetDiagramRoot, + false); + } + }; + + try { + // Force rollback of transaction to let raw diagram + // unchanged + session.getTransactionalEditingDomain().addResourceSetListener(ROLLBACK_LISTENER); + session.getTransactionalEditingDomain().getCommandStack().execute(command); + } finally { + session.getTransactionalEditingDomain().removeResourceSetListener(ROLLBACK_LISTENER); + } + TestsUtil.synchronizationWithUIThread(); + + } finally { + + } + } + + @Override + protected String getPlatformRelatedFullXmiDataPath() { + return PLUGIN_PATH + getPlatformRelatedXmiDataPath(); + } + + @Override + protected String getPlatformRelatedXmiDataPath() { + return getPlatformRelatedDataPath() + XMI_FOLDER; + } + + @Override + protected String getPlatformRelatedDataPath() { + String path = getDataPath(); + String platformVersion = Platform.getBundle("org.eclipse.core.runtime").getHeaders().get("Bundle-Version"); + if (platformVersion.startsWith("3.3") || platformVersion.startsWith("3.4") || platformVersion.startsWith("3.5")) { + path = getDataPath() + "3.5/"; + } else if (platformVersion.startsWith("3.6")) { + path = getDataPath() + "3.6/"; + } + return path; + } +} diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/format/data/MappingBasedSiriusFormatDataManagerCallCheckTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/format/data/MappingBasedSiriusFormatDataManagerCallCheckTest.java new file mode 100644 index 0000000000..280bc24054 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/format/data/MappingBasedSiriusFormatDataManagerCallCheckTest.java @@ -0,0 +1,365 @@ +/******************************************************************************* + * Copyright (c) 2020 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.unit.diagram.format.data; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.ui.provider.Messages; +import org.eclipse.sirius.diagram.ui.tools.api.format.MappingBasedSiriusFormatManagerFactory; +import org.eclipse.sirius.tests.support.api.TestsUtil; +import org.eclipse.sirius.tests.unit.diagram.format.data.manager.mappingbased.MappingBasedTestConfiguration; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.sirius.viewpoint.ViewpointFactory; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameters; + +public class MappingBasedSiriusFormatDataManagerCallCheckTest extends AbstractMappingBasedSiriusFormatDataManagerTest { + + protected static final Diagram MB_DIAG_TYPE8_MYPACKAGE = new Diagram("DiagType8 of MyPackage", 16, 0); + + protected static final Diagram MB_DIAG_TYPE8_RAW = new Diagram("DiagType8 Raw of targetMyPackage", 16, 0, true); + + protected static final Representation MB_REPRES_TYPE8 = new Representation("DiagType8", MB_DIAG_TYPE8_MYPACKAGE, MB_DIAG_TYPE8_RAW); + + protected static final Diagram MB_DIAG_TYPE10_MYPACKAGE = new Diagram("DiagType10 of MyPackage", 16, 2); + + protected static final Diagram MB_DIAG_TYPE10_RAW = new Diagram("DiagType10 Raw of targetMyPackage", 16, 2, true); + + protected static final Representation MB_REPRES_TYPE10 = new Representation("DiagType10", MB_DIAG_TYPE10_MYPACKAGE, MB_DIAG_TYPE10_RAW); + + protected static final Predicate<Diagram> ONLY_RAW_DIAGRAM = new Predicate<Diagram>() { + + @Override + public boolean test(final Diagram input) { + return input.raw; + } + }; + + @Parameters + public static Collection<Object[]> data() { + // We could use @Theories and @Datapoints but the theory stops as soon + // as there is a failure. With parameters, we have feedback for all + // scenarii. + Collection<Object[]> data = new ArrayList<>(); + data.add(new Object[] { MB_REPRES_TYPE8 }); + return data; + } + + public MappingBasedSiriusFormatDataManagerCallCheckTest(Representation representationToCopyFormat) throws Exception { + super(representationToCopyFormat); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + } + + /** + * Test method. + * + * @throws Exception + * Test error. + */ + @Test + public void testCallCheckEmptyMapping() throws Exception { + if (TestsUtil.shouldSkipLongTests()) { + return; + } + + final DDiagram diagramToCopyFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_MYPACKAGE); + final DDiagram diagramToPasteFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_RAW); + + try { + applyPredefinedFormatDataOnRawDiagrams(diagramToCopyFormat, diagramToPasteFormat, getEmptyTestConfiguration(), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorMappingfunctionIsEmpty); + } + + try { + applyPredefinedFormatDataOnNewDiagram(diagramToCopyFormat, getEmptyTestConfiguration(), diagramToPasteFormat.getName(), diagramToPasteFormat.getDiagramElements().get(0), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorMappingfunctionIsEmpty); + } + } + + /** + * Test method. + * + * @throws Exception + * Test error. + */ + @Test + public void testCallCheckSameDiagrams() throws Exception { + if (TestsUtil.shouldSkipLongTests()) { + return; + } + + final DDiagram diagramToCopyFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_MYPACKAGE); + final DDiagram diagramToPasteFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_MYPACKAGE); + + try { + applyPredefinedFormatDataOnRawDiagrams(diagramToCopyFormat, diagramToPasteFormat, getFullTestConfiguration(), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndTargetDiagramsAreTheSame); + } + + try { + applyPredefinedFormatDataOnNewDiagram(diagramToCopyFormat, getFullTestConfiguration(), diagramToPasteFormat.getName(), diagramToPasteFormat.getDiagramElements().get(0), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndTargetDiagramsAreTheSame); + } + } + + /** + * Test method. + * + * @throws Exception + * Test error. + */ + @Test + public void testCallCheckNullDiagrams() throws Exception { + if (TestsUtil.shouldSkipLongTests()) { + return; + } + + final DDiagram diagramToCopyFormat = null; + final DDiagram diagramToPasteFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_MYPACKAGE); + + try { + applyPredefinedFormatDataOnRawDiagrams(diagramToCopyFormat, diagramToPasteFormat, getFullTestConfiguration(), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorDiagramIsNull); + } + + try { + applyPredefinedFormatDataOnRawDiagrams(diagramToPasteFormat, diagramToCopyFormat, getFullTestConfiguration(), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorDiagramIsNull); + } + + try { + applyPredefinedFormatDataOnNewDiagram(diagramToCopyFormat, getFullTestConfiguration(), diagramToPasteFormat.getName(), diagramToPasteFormat.getDiagramElements().get(0), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorDiagramIsNull); + } + } + + /** + * Test method. + * + * @throws Exception + * Test error. + */ + @Test + public void testCallCheckNullOrEmptyDiagramName() throws Exception { + if (TestsUtil.shouldSkipLongTests()) { + return; + } + + final DDiagram diagramToCopyFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_MYPACKAGE); + final DDiagram diagramToPasteFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_MYPACKAGE); + + try { + applyPredefinedFormatDataOnNewDiagram(diagramToCopyFormat, getFullTestConfiguration(), "", diagramToPasteFormat.getDiagramElements().get(0), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorTargetDiagramNameIsEmpty); + } + + try { + applyPredefinedFormatDataOnNewDiagram(diagramToCopyFormat, getFullTestConfiguration(), null, diagramToPasteFormat.getDiagramElements().get(0), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorTargetDiagramNameIsEmpty); + } + } + + /** + * Test method. + * + * @throws Exception + * Test error. + */ + @Test + public void testCallCheckDescriptionMatch() throws Exception { + if (TestsUtil.shouldSkipLongTests()) { + return; + } + + final DDiagram diagramToCopyFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_MYPACKAGE); + final DDiagram diagramToPasteFormat = getDiagram(MB_REPRES_TYPE10, MB_DIAG_TYPE10_MYPACKAGE); + + try { + applyPredefinedFormatDataOnRawDiagrams(diagramToCopyFormat, diagramToPasteFormat, getFullTestConfiguration(), session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), MessageFormat.format(Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndTargetDiagramDecriptionsDoesNotMatch, diagramToCopyFormat.getDescription(), + diagramToPasteFormat.getDescription())); + } + } + + /** + * Test method. + * + * @throws Exception + * Test error. + */ + @Test + public void testCallCheckSessions() throws Exception { + if (TestsUtil.shouldSkipLongTests()) { + return; + } + + final DDiagram diagramToCopyFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_MYPACKAGE); + final DDiagram diagramToPasteFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_RAW); + + try { + applyPredefinedFormatDataOnRawDiagrams(diagramToCopyFormat, diagramToPasteFormat, getFullTestConfiguration(), session, null); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndOrTargetSessionsNull); + } + + try { + applyPredefinedFormatDataOnRawDiagrams(diagramToCopyFormat, diagramToPasteFormat, getFullTestConfiguration(), null, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndOrTargetSessionsNull); + } + + try { + applyPredefinedFormatDataOnNewDiagram(diagramToCopyFormat, getFullTestConfiguration(), diagramToPasteFormat.getName(), diagramToPasteFormat.getDiagramElements().get(0), session, null); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndOrTargetSessionsNull); + } + + try { + applyPredefinedFormatDataOnNewDiagram(diagramToCopyFormat, getFullTestConfiguration(), diagramToPasteFormat.getName(), diagramToPasteFormat.getDiagramElements().get(0), null, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorSourceAndOrTargetSessionsNull); + } + } + + /** + * Test method. + * + * @throws Exception + * Test error. + */ + @Test + public void testCallCheckNullTargetDiagramRoot() throws Exception { + if (TestsUtil.shouldSkipLongTests()) { + return; + } + + final DDiagram diagramToCopyFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_MYPACKAGE); + final DDiagram diagramToPasteFormat = getDiagram(MB_REPRES_TYPE8, MB_DIAG_TYPE8_RAW); + + try { + applyPredefinedFormatDataOnNewDiagram(diagramToCopyFormat, getFullTestConfiguration(), diagramToPasteFormat.getName(), null, session, session); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), Messages.MappingBasedSiriusFormatManagerFactory_ErrorTargetDiagramRootIsNull); + } + } + + private DDiagram getDiagram(Representation rep, Diagram diag) { + + List<DRepresentationDescriptor> allDDiagramDescriptors = getRepresentationDescriptors(rep.name, session).stream().collect(Collectors.toList()); + Collections.sort(allDDiagramDescriptors, USING_NAME); + DRepresentationDescriptor dRepresentationDescriptorToFind = ViewpointFactory.eINSTANCE.createDRepresentationDescriptor(); + dRepresentationDescriptorToFind.setName(diag.name); + final int search = Collections.binarySearch(allDDiagramDescriptors, dRepresentationDescriptorToFind, USING_NAME); + + assertTrue("Source Diagram " + dRepresentationDescriptorToFind.getName() + " is not found in representation", search > -1); + + return (DDiagram) allDDiagramDescriptors.get(search).getRepresentation(); + } + + protected void applyPredefinedFormatDataOnRawDiagrams(DDiagram diagramToCopyFormat, DDiagram diagramToPasteFormat, MappingBasedTestConfiguration mapTestConfiguration, Session sourceSession, + Session targetSession) throws Exception { + + Map<EObject, EObject> map = mapTestConfiguration.getObjectsMap(); + + try { + final RecordingCommand command = new RecordingCommand(session.getTransactionalEditingDomain()) { + @Override + protected void doExecute() { + // Update diagram, but transaction will be rollbacked + DDiagram newDiagram = MappingBasedSiriusFormatManagerFactory.getInstance().applyFormatOnDiagram(sourceSession, diagramToCopyFormat, map, targetSession, diagramToPasteFormat, + false); + } + }; + + try { + // Force rollback of transaction to let raw diagram + // unchanged + session.getTransactionalEditingDomain().addResourceSetListener(ROLLBACK_LISTENER); + session.getTransactionalEditingDomain().getCommandStack().execute(command); + } finally { + session.getTransactionalEditingDomain().removeResourceSetListener(ROLLBACK_LISTENER); + } + TestsUtil.synchronizationWithUIThread(); + + } finally { + + } + } + + protected void applyPredefinedFormatDataOnNewDiagram(DDiagram diagramToCopyFormat, MappingBasedTestConfiguration mapTestConfiguration, String diagramName, EObject targetDiagramRoot, + Session sourceSession, Session targetSession) throws Exception { + + Map<EObject, EObject> map = mapTestConfiguration.getObjectsMap(); + + try { + final RecordingCommand command = new RecordingCommand(session.getTransactionalEditingDomain()) { + @Override + protected void doExecute() { + // Update diagram, but transaction will be rollbacked + DDiagram newDiagram = MappingBasedSiriusFormatManagerFactory.getInstance().applyFormatOnNewDiagram(sourceSession, diagramToCopyFormat, map, targetSession, diagramName, + targetDiagramRoot, false); + } + }; + + try { + // Force rollback of transaction to let raw diagram + // unchanged + session.getTransactionalEditingDomain().addResourceSetListener(ROLLBACK_LISTENER); + session.getTransactionalEditingDomain().getCommandStack().execute(command); + } finally { + session.getTransactionalEditingDomain().removeResourceSetListener(ROLLBACK_LISTENER); + } + TestsUtil.synchronizationWithUIThread(); + + } finally { + + } + } + + /** + * Compute configuration for source to target EObjects mapping. Uses none of the model elements. + * + * @return + */ + protected MappingBasedTestConfiguration getEmptyTestConfiguration() { + Map<String, String> full_map = new HashMap<String, String>(); + return new MappingBasedTestConfiguration(semanticModel, semanticTargetModel, full_map, null, "empty"); + } + +} |