-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#265 Add junit to test additional image dependency merge
scenarios Change-Id: Idcfe511aba1a2719640c3ac2b05d8443f09fef8e Signed-off-by: Anita Matei Gabriel <matei.anita@thalesgroup.com>
- Loading branch information
1 parent
fa2bce9
commit b6493d8
Showing
6 changed files
with
364 additions
and
27 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...sts.ju/src/org/eclipse/emf/diffmerge/tests/ju/ImageDependencyAnnotationDiffMergeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2023 Thales Global Services S.A.S. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Thales Global Services S.A.S. - initial API and implementation | ||
**********************************************************************/ | ||
package org.eclipse.emf.diffmerge.tests.ju; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.eclipse.emf.diffmerge.diffdata.impl.EElementPresenceImpl; | ||
import org.eclipse.emf.diffmerge.generic.api.diff.IDifference; | ||
import org.eclipse.emf.diffmerge.tests.elements.Elements.ElementsFactory; | ||
import org.eclipse.emf.diffmerge.tests.elements.Elements.Root; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.sirius.business.internal.image.ImageDependenciesAnnotationHelper; | ||
import org.eclipse.sirius.viewpoint.description.DAnnotationEntry; | ||
import org.eclipse.sirius.viewpoint.description.DescriptionFactory; | ||
|
||
public class ImageDependencyAnnotationDiffMergeTest extends ImageDependencyDiffMergeTest { | ||
|
||
@Override | ||
protected int getRequiredDifferences() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
protected void assertDifferences(IDifference diff) { | ||
assertNotImageDepsAnnotation(diff); | ||
|
||
} | ||
|
||
@Override | ||
protected EObject getSourceRoot() { | ||
DAnnotationEntry annotation = DescriptionFactory.eINSTANCE.createDAnnotationEntry(); | ||
annotation.setSource(ImageDependenciesAnnotationHelper.IMAGES_DEPENDENCIES_ANNOTATION_SOURCE_NAME); | ||
|
||
return annotation; | ||
} | ||
|
||
@Override | ||
protected EObject getTargetRoot() { | ||
Root root = ElementsFactory.eINSTANCE.createRoot(); | ||
|
||
return root; | ||
} | ||
|
||
private void assertNotImageDepsAnnotation(IDifference diff) { | ||
if (diff instanceof EElementPresenceImpl) { | ||
EElementPresenceImpl castDiff = (EElementPresenceImpl) diff; | ||
if (castDiff.getElementMatch().getReference() instanceof DAnnotationEntry) { | ||
assertEquals("Image dependency annotations should not be proposed for merging.", false, | ||
((DAnnotationEntry) castDiff.getElementMatch().getReference()).getSource() | ||
.equals(ImageDependenciesAnnotationHelper.IMAGES_DEPENDENCIES_ANNOTATION_SOURCE_NAME)); | ||
} | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...ffmerge.tests.ju/src/org/eclipse/emf/diffmerge/tests/ju/ImageDependencyDiffMergeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2023 Thales Global Services S.A.S. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Thales Global Services S.A.S. - initial API and implementation | ||
**********************************************************************/ | ||
package org.eclipse.emf.diffmerge.tests.ju; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Collection; | ||
|
||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.diffmerge.diffdata.EComparison; | ||
import org.eclipse.emf.diffmerge.diffdata.impl.EComparisonImpl; | ||
import org.eclipse.emf.diffmerge.generic.api.Role; | ||
import org.eclipse.emf.diffmerge.generic.api.diff.IDifference; | ||
import org.eclipse.emf.diffmerge.sirius.SiriusDiffPolicy; | ||
import org.eclipse.emf.diffmerge.sirius.SiriusMatchPolicy; | ||
import org.eclipse.emf.diffmerge.sirius.SiriusMergePolicy; | ||
import org.eclipse.emf.diffmerge.sirius.SiriusScope; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.transaction.RecordingCommand; | ||
import org.eclipse.emf.transaction.TransactionalEditingDomain; | ||
import org.eclipse.sirius.business.api.session.Session; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public abstract class ImageDependencyDiffMergeTest { | ||
private SiriusScope sourceScope; | ||
private SiriusScope destinationScope; | ||
private EComparison comparison; | ||
|
||
private int passedAsserts = 0; | ||
|
||
@Before | ||
public void setupProjects() { | ||
URI semanticDestination = URI.createPlatformResourceURI("target project/target project.elements", false); | ||
ProjectHelper.saveSemanticResource(semanticDestination, getTargetRoot()); | ||
Session destinationSession = ProjectHelper.createSessionOn(semanticDestination); | ||
destinationScope = new SiriusScope(destinationSession.getSessionResource().getURI(), | ||
destinationSession.getTransactionalEditingDomain(), true); | ||
|
||
URI semanticSource = URI.createPlatformResourceURI("source project/source project.elements", false); | ||
ProjectHelper.saveSemanticResource(semanticSource, getSourceRoot()); | ||
Session sourceSession = ProjectHelper.createSessionOn(semanticSource); | ||
sourceScope = new SiriusScope(sourceSession.getSessionResource().getURI(), | ||
sourceSession.getTransactionalEditingDomain(), true); | ||
|
||
comparison = new EComparisonImpl(destinationScope, sourceScope); | ||
destinationScope.setComparison(comparison); | ||
sourceScope.setComparison(comparison); | ||
} | ||
|
||
@Test | ||
public void runTest() { | ||
TransactionalEditingDomain domain = (TransactionalEditingDomain) destinationScope.getEditingDomain(); | ||
domain.getCommandStack().execute(new RecordingCommand(domain) { | ||
|
||
@Override | ||
protected void doExecute() { | ||
comparison.compute(new SiriusMatchPolicy(), new SiriusDiffPolicy(), new SiriusMergePolicy(), | ||
new NullProgressMonitor()); | ||
Collection<IDifference<EObject>> diffs = comparison.getDifferences(Role.REFERENCE); | ||
|
||
comparison.merge(Role.TARGET, true, new NullProgressMonitor()); | ||
|
||
diffs.stream().forEach(diff -> { | ||
assertDifferences(diff); | ||
}); | ||
|
||
assertEquals("More or less differences have been found than required.", getRequiredDifferences(), | ||
passedAsserts); | ||
} | ||
|
||
}); | ||
} | ||
|
||
protected void increasePassedAsserts() { | ||
passedAsserts++; | ||
} | ||
|
||
protected abstract int getRequiredDifferences(); | ||
|
||
protected abstract void assertDifferences(IDifference diff); | ||
|
||
protected abstract EObject getSourceRoot(); | ||
|
||
protected abstract EObject getTargetRoot(); | ||
} |
112 changes: 112 additions & 0 deletions
112
...tests.ju/src/org/eclipse/emf/diffmerge/tests/ju/ImageDependencyRichTextDiffMergeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2023 Thales Global Services S.A.S. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Thales Global Services S.A.S. - initial API and implementation | ||
**********************************************************************/ | ||
package org.eclipse.emf.diffmerge.tests.ju; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.eclipse.emf.diffmerge.diffdata.impl.EAttributeValuePresenceImpl; | ||
import org.eclipse.emf.diffmerge.generic.api.diff.IDifference; | ||
import org.eclipse.emf.diffmerge.generic.gdiffdata.impl.GElementRelativePresenceImpl; | ||
import org.eclipse.emf.diffmerge.tests.elements.Elements.Element; | ||
import org.eclipse.emf.diffmerge.tests.elements.Elements.ElementsFactory; | ||
import org.eclipse.emf.diffmerge.tests.elements.Elements.ElementsPackage; | ||
import org.eclipse.emf.diffmerge.tests.elements.Elements.Root; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.sirius.business.api.image.RichTextAttributeRegistry; | ||
import org.junit.Before; | ||
|
||
public class ImageDependencyRichTextDiffMergeTest extends ImageDependencyDiffMergeTest { | ||
|
||
private final String ROOT_ID = "root"; | ||
private final String EXISTING_ELEMENT_ID = "existingElement"; | ||
private final String NEW_ELEMENT_ID = "newElement"; | ||
private final String NEW_ELEMENT_CHILD_ID = "newElementChild"; | ||
|
||
@Override | ||
protected int getRequiredDifferences() { | ||
return 4; | ||
} | ||
|
||
@Override | ||
protected void assertDifferences(IDifference diff) { | ||
assertHardcodedPathElement(diff, EXISTING_ELEMENT_ID); | ||
assertHardcodedPathElement(diff, NEW_ELEMENT_ID); | ||
assertHardcodedPathElement(diff, NEW_ELEMENT_CHILD_ID); | ||
assertRelativePathElement(diff, EXISTING_ELEMENT_ID); | ||
} | ||
|
||
@Override | ||
protected EObject getSourceRoot() { | ||
Root root = ElementsFactory.eINSTANCE.createRoot(); | ||
Element existingElement = ElementsFactory.eINSTANCE.createElement(); | ||
Element newElement = ElementsFactory.eINSTANCE.createElement(); | ||
Element newElementChild = ElementsFactory.eINSTANCE.createElement(); | ||
|
||
root.setId(ROOT_ID); | ||
existingElement.setId(EXISTING_ELEMENT_ID); | ||
newElement.setId(NEW_ELEMENT_ID); | ||
newElementChild.setId(NEW_ELEMENT_CHILD_ID); | ||
|
||
existingElement.setName("<p><img src=\"source project/image.png\" /></p>\n"); | ||
newElement.setName("<p><img src=\"source project/image.png\" /></p>\n"); | ||
newElementChild.setName("<p><img src=\"source project/image.png\" /></p>\n"); | ||
|
||
root.getContent().add(existingElement); | ||
newElement.getManyContent().add(newElementChild); | ||
root.getContent().add(newElement); | ||
|
||
return root; | ||
|
||
} | ||
|
||
@Override | ||
protected EObject getTargetRoot() { | ||
Root root = ElementsFactory.eINSTANCE.createRoot(); | ||
Element existingElement = ElementsFactory.eINSTANCE.createElement(); | ||
root.setId(ROOT_ID); | ||
existingElement.setId(EXISTING_ELEMENT_ID); | ||
|
||
root.getContent().add(existingElement); | ||
return root; | ||
} | ||
|
||
@Before | ||
public void initializeElements() { | ||
RichTextAttributeRegistry.INSTANCE.add(ElementsPackage.Literals.NAMED_ELEMENT__NAME); | ||
} | ||
|
||
private void assertHardcodedPathElement(IDifference diff, String name) { | ||
if (diff instanceof GElementRelativePresenceImpl) { | ||
GElementRelativePresenceImpl castDiff = (GElementRelativePresenceImpl) diff; | ||
if (castDiff.getElementMatch().getTarget() instanceof Element | ||
&& ((Element) castDiff.getElementMatch().getTarget()).getId().equals(name)) { | ||
Element element = ((Element) castDiff.getElementMatch().getTarget()); | ||
assertEquals(String.format("Image path for %s should be hardcoded to target project.", name), | ||
"<p><img src=\"target project/image.png\" /></p>\n", element.getName()); | ||
increasePassedAsserts(); | ||
} | ||
} | ||
} | ||
|
||
private void assertRelativePathElement(IDifference diff, String name) { | ||
if (diff instanceof EAttributeValuePresenceImpl) { | ||
EAttributeValuePresenceImpl castDiff = (EAttributeValuePresenceImpl) diff; | ||
if (castDiff.getElementMatch().getTarget() instanceof Element | ||
&& ((Element) castDiff.getElementMatch().getTarget()).getId().equals(name)) { | ||
assertEquals("Image path of modified element should be made relative.", | ||
"<p><img src=\"./image.png\" /></p>\n", castDiff.getValue()); | ||
increasePassedAsserts(); | ||
} | ||
} | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...ju/src/org/eclipse/emf/diffmerge/tests/ju/ImageDependencyWorkspaceImageDiffMergeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2023 Thales Global Services S.A.S. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Thales Global Services S.A.S. - initial API and implementation | ||
**********************************************************************/ | ||
package org.eclipse.emf.diffmerge.tests.ju; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.eclipse.emf.diffmerge.generic.api.diff.IDifference; | ||
import org.eclipse.emf.diffmerge.generic.gdiffdata.impl.GElementRelativePresenceImpl; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.sirius.diagram.DNodeContainer; | ||
import org.eclipse.sirius.diagram.DiagramFactory; | ||
import org.eclipse.sirius.diagram.WorkspaceImage; | ||
|
||
public class ImageDependencyWorkspaceImageDiffMergeTest extends ImageDependencyDiffMergeTest { | ||
private final String NODE_ID = "node"; | ||
|
||
@Override | ||
protected int getRequiredDifferences() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
protected void assertDifferences(IDifference diff) { | ||
assertPathWorkspaceImage(diff); | ||
|
||
} | ||
|
||
@Override | ||
protected EObject getSourceRoot() { | ||
DNodeContainer node = DiagramFactory.eINSTANCE.createDNodeContainer(); | ||
node.setUid(NODE_ID); | ||
WorkspaceImage workspaceImage = DiagramFactory.eINSTANCE.createWorkspaceImage(); | ||
workspaceImage.setWorkspacePath("source project/test.PNG"); | ||
node.setOwnedStyle(workspaceImage); | ||
|
||
return node; | ||
} | ||
|
||
@Override | ||
protected EObject getTargetRoot() { | ||
DNodeContainer node = DiagramFactory.eINSTANCE.createDNodeContainer(); | ||
node.setUid(NODE_ID); | ||
return node; | ||
} | ||
|
||
private void assertPathWorkspaceImage(IDifference diff) { | ||
if (diff instanceof GElementRelativePresenceImpl) { | ||
GElementRelativePresenceImpl castDiff = (GElementRelativePresenceImpl) diff; | ||
if (castDiff.getElementMatch().getTarget() instanceof WorkspaceImage) { | ||
WorkspaceImage workspaceImage = ((WorkspaceImage) castDiff.getElementMatch().getTarget()); | ||
assertEquals("Image path should be hardcoded to target project.", "target project/test.PNG", | ||
workspaceImage.getWorkspacePath()); | ||
increasePassedAsserts(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.