diff --git a/Jenkinsfile b/Jenkinsfile index fd7af70d8..cb02f3551 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,25 +71,25 @@ pipeline { } } - stage('Run RCPTT Tests') { + stage('Run JUnit Tests') { steps { wrap([$class: 'Xvnc', takeScreenshot: false, useXauthority: true]) { script { - sh 'mvn -Dmaven.test.failure.ignore=true verify -P rcptt -e' - + sh "mvn -Dmaven.test.failure.ignore=true verify -P test -e" } } - } + } } - stage('Run JUnit Tests') { + stage('Run RCPTT Tests') { steps { wrap([$class: 'Xvnc', takeScreenshot: false, useXauthority: true]) { script { - sh "mvn -Dmaven.test.failure.ignore=true verify -P test -e" + sh 'mvn -Dmaven.test.failure.ignore=true verify -P rcptt -e' + } } - } + } } stage('Publish tests results') { diff --git a/releng/plugins/org.polarsys.kitalpha.releng.targets/kitalpha.targetplatform b/releng/plugins/org.polarsys.kitalpha.releng.targets/kitalpha.targetplatform index a70f3e589..8bd946af1 100644 --- a/releng/plugins/org.polarsys.kitalpha.releng.targets/kitalpha.targetplatform +++ b/releng/plugins/org.polarsys.kitalpha.releng.targets/kitalpha.targetplatform @@ -115,6 +115,7 @@ location sirius "https://download.eclipse.org/sirius/updates/stable/7.4.1-S20240 org.eclipse.sirius.specifier.ide.ui.source.feature.group lazy org.eclipse.sirius.specifier.ide.ui.acceleo.feature.group lazy org.eclipse.sirius.specifier.ide.ui.acceleo.source.feature.group lazy + org.eclipse.acceleo.query.source.feature.group org.eclipse.sirius.interpreter.feature.feature.group lazy org.eclipse.sirius.properties.feature.feature.group lazy diff --git a/sirius/plugins/org.polarsys.kitalpha.sirius.rotativeimage/META-INF/MANIFEST.MF b/sirius/plugins/org.polarsys.kitalpha.sirius.rotativeimage/META-INF/MANIFEST.MF index 7e8286bfc..eebca220b 100644 --- a/sirius/plugins/org.polarsys.kitalpha.sirius.rotativeimage/META-INF/MANIFEST.MF +++ b/sirius/plugins/org.polarsys.kitalpha.sirius.rotativeimage/META-INF/MANIFEST.MF @@ -14,7 +14,10 @@ Require-Bundle: org.eclipse.ui, org.eclipse.sirius.common.ui, org.eclipse.sirius.diagram, org.eclipse.sirius.diagram.ui, - org.eclipse.osgi + org.eclipse.osgi, + org.apache.batik.dom, + org.apache.batik.bridge, + org.apache.batik.transcoder Bundle-RequiredExecutionEnvironment: JavaSE-17 Eclipse-LazyStart: true Export-Package: org.polarsys.kitalpha.sirius.rotativeimage, diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/META-INF/MANIFEST.MF b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/META-INF/MANIFEST.MF index 2b94cde86..605917cd2 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/META-INF/MANIFEST.MF +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/META-INF/MANIFEST.MF @@ -24,7 +24,8 @@ Require-Bundle: org.junit, org.eclipse.gmf.runtime.draw2d.ui, org.eclipse.gmf.runtime.diagram.ui, org.eclipse.sirius.common, - org.apache.batik.transcoder;bundle-version="1.14.0" + org.apache.batik.transcoder, + org.eclipse.emf.common.ui Bundle-Vendor: %providerName Import-Package: org.eclipse.core.runtime, org.eclipse.gmf.runtime.diagram.ui.editparts diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/description/test.odesign b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/description/test.odesign index 12e41bf3b..00407bb88 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/description/test.odesign +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/description/test.odesign @@ -1,125 +1,134 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon.svg b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon.svg index 01e175515..0c65e7810 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon.svg +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon.svg @@ -1,64 +1,64 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_bottom.svg b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_bottom.svg index b4f6365cf..226b0523a 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_bottom.svg +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_bottom.svg @@ -1,68 +1,68 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_left.svg b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_left.svg index e4a914076..924b2232b 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_left.svg +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_left.svg @@ -1,68 +1,68 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_right.svg b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_right.svg index 6ffc0dc8d..bbf145a44 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_right.svg +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_right.svg @@ -1,68 +1,68 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_top.svg b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_top.svg index 062c6d0ec..f7a2a561a 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_top.svg +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon_top.svg @@ -1,64 +1,64 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/rotationIcon.svg b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/rotationIcon.svg index 891e9b427..90ca804e1 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/rotationIcon.svg +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/rotationIcon.svg @@ -1,64 +1,64 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/models/Test1.aird b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/models/Test1.aird index 1ac4be92f..343bf7cf0 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/models/Test1.aird +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/models/Test1.aird @@ -1,1220 +1,1220 @@ - - - - Test1.xmi - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - + + + + Test1.xmi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/models/test.ecore b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/models/test.ecore index 1a6042c81..99ecb82ee 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/models/test.ecore +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/models/test.ecore @@ -15,6 +15,7 @@ + diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/LoadSessionWithExtensionTest.java b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/LoadSessionWithExtensionTest.java index a2751481b..da6a04b30 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/LoadSessionWithExtensionTest.java +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/LoadSessionWithExtensionTest.java @@ -1,128 +1,132 @@ -/******************************************************************************* - * Copyright (c) 2021 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 - * http://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.polarsys.kitalpha.sirius.rotativeimage.junit.tests.testcases; - -import java.util.Collection; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.sirius.business.api.dialect.DialectManager; -import org.eclipse.sirius.business.api.session.Session; -import org.eclipse.sirius.business.api.session.SessionManager; -import org.eclipse.sirius.diagram.DDiagram; -import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; -import org.eclipse.sirius.tests.support.api.TestsUtil; -import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; -import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; -import org.eclipse.sirius.ui.business.api.session.IEditingSession; -import org.eclipse.sirius.ui.business.api.session.SessionUIManager; -import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; -import org.junit.Assert; - -/** - * Checks the loading of the RotativeImage extension point - * - * @author Arnaud Dieumegard - */ -public class LoadSessionWithExtensionTest extends SiriusDiagramTestCase { - - protected static final String PLATFORM_PLUGIN_PATH = "platform:/plugin/"; - protected static final String ROTATIVEIMAGE_TEST_PLUGIN_NAME = "/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests"; - - private static final String TEST_XMI_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.xmi"; - private static final String TEST_AIRD_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.aird"; - private static final String TEST_ODESIGN_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/description/test.odesign"; - - private static final String ID_REPRESENTATION_DESCRIPTOR = "_idds4E1NEeySgagIY4HK9g"; - private static final String ID_REPRESENTATION_DESCRIPTOR_PNG = "_h9U1ME4GEeyTxN2ah5Tp3g"; - private static final String ID_REPRESENTATION_DESCRIPTOR_FAULTY_ROTATIVE_PNG = "_4gkTAE6SEeyXs6TJVt2feA"; - private static final String ID_REPRESENTATION_DESCRIPTOR_FAULTY_ROTATIVE_SVG = "_BTwm8E6TEeyXs6TJVt2feA"; - - private static final String[] ALL_REPRESENTATION_ID = {ID_REPRESENTATION_DESCRIPTOR, ID_REPRESENTATION_DESCRIPTOR_PNG, ID_REPRESENTATION_DESCRIPTOR_FAULTY_ROTATIVE_PNG, ID_REPRESENTATION_DESCRIPTOR_FAULTY_ROTATIVE_SVG}; - - @Override - protected void setUp() throws Exception { - super.setUp(); - genericSetUp(TEST_XMI_PATH, TEST_ODESIGN_PATH, TEST_AIRD_PATH); - } - - /** - * Open selected diagrams in session. - */ - public void testDiagramsOpening() { - for (String repId : ALL_REPRESENTATION_ID) { - DRepresentationDescriptor desc = getRepresentationDescriptor(session, repId); - assertNotNull(desc); - - DDiagram ddiagram = (DDiagram) desc.getRepresentation(); - assertNotNull(ddiagram); - - DialectEditor editor = (DialectEditor) DialectUIManager.INSTANCE.openEditor(session, ddiagram, new NullProgressMonitor()); - TestsUtil.synchronizationWithUIThread(); - DialectUIManager.INSTANCE.refreshEditor(editor, new NullProgressMonitor()); - TestsUtil.synchronizationWithUIThread(); - } - } - - public DRepresentationDescriptor getRepresentationDescriptor(Session session, String id) { - Collection representationDescriptors = DialectManager.INSTANCE.getAllRepresentationDescriptors(session); - for (DRepresentationDescriptor representationDescriptor : representationDescriptors) { - - String descriptorFragment; - try { - descriptorFragment = representationDescriptor.getRepPath().getResourceURI().fragment(); - } catch (NullPointerException e) { - descriptorFragment = ""; - } - - String descriptorUid = representationDescriptor.getUid(); - - if (id.equals(descriptorFragment) || id.equals(descriptorUid)) { - return representationDescriptor; - } - } - return null; - } - - @Override - protected void tearDown() throws Exception { - doCleanup(); - super.tearDown(); - } - - private void doCleanup() { - final IEditingSession sessionUI = SessionUIManager.INSTANCE.getUISession(session); - if (sessionUI != null) { - SessionUIManager.INSTANCE.remove(sessionUI); - sessionUI.close(); - TestsUtil.emptyEventsFromUIThread(); - } - if (session != null) { - doRemoveSession(); - doCloseSession(); - session = null; - } - viewpoints.clear(); - } - - private void doCloseSession() { - session.close(new NullProgressMonitor()); - Assert.assertFalse("Can't close the session", session.isOpen()); - } - - private void doRemoveSession() { - SessionManager.INSTANCE.remove(session); - for (final Session session2 : SessionManager.INSTANCE.getSessions()) { - Assert.assertFalse("Remove failed", session2.equals(session)); - } - } - -} +/******************************************************************************* + * Copyright (c) 2021 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 + * http://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.polarsys.kitalpha.sirius.rotativeimage.junit.tests.testcases; + +import java.util.Collection; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.sirius.business.api.dialect.DialectManager; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.business.api.session.SessionManager; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; +import org.eclipse.sirius.tests.support.api.TestsUtil; +import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; +import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.eclipse.sirius.ui.business.api.session.IEditingSession; +import org.eclipse.sirius.ui.business.api.session.SessionUIManager; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.swt.graphics.Resource; +import org.junit.Assert; + +/** + * Checks the loading of the RotativeImage extension point + * + * @author Arnaud Dieumegard + */ +public class LoadSessionWithExtensionTest extends SiriusDiagramTestCase { + + protected static final String PLATFORM_PLUGIN_PATH = "platform:/plugin/"; + protected static final String ROTATIVEIMAGE_TEST_PLUGIN_NAME = "/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests"; + + private static final String TEST_XMI_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.xmi"; + private static final String TEST_AIRD_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.aird"; + private static final String TEST_ODESIGN_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/description/test.odesign"; + + private static final String ID_REPRESENTATION_DESCRIPTOR = "_idds4E1NEeySgagIY4HK9g"; + private static final String ID_REPRESENTATION_DESCRIPTOR_PNG = "_h9U1ME4GEeyTxN2ah5Tp3g"; + private static final String ID_REPRESENTATION_DESCRIPTOR_FAULTY_ROTATIVE_PNG = "_4gkTAE6SEeyXs6TJVt2feA"; + private static final String ID_REPRESENTATION_DESCRIPTOR_FAULTY_ROTATIVE_SVG = "_BTwm8E6TEeyXs6TJVt2feA"; + + private static final String[] ALL_REPRESENTATION_ID = {ID_REPRESENTATION_DESCRIPTOR, ID_REPRESENTATION_DESCRIPTOR_PNG, ID_REPRESENTATION_DESCRIPTOR_FAULTY_ROTATIVE_PNG, ID_REPRESENTATION_DESCRIPTOR_FAULTY_ROTATIVE_SVG}; + + @Override + protected void setUp() throws Exception { + super.setUp(); + Resource.setNonDisposeHandler(null); + genericSetUp(TEST_XMI_PATH, TEST_ODESIGN_PATH, TEST_AIRD_PATH); + } + + /** + * Open selected diagrams in session. + */ + public void testDiagramsOpening() { + for (String repId : ALL_REPRESENTATION_ID) { + DRepresentationDescriptor desc = getRepresentationDescriptor(session, repId); + assertNotNull(desc); + + DDiagram ddiagram = (DDiagram) desc.getRepresentation(); + assertNotNull(ddiagram); + + DialectEditor editor = (DialectEditor) DialectUIManager.INSTANCE.openEditor(session, ddiagram, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + DialectUIManager.INSTANCE.refreshEditor(editor, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + DialectUIManager.INSTANCE.closeEditor(editor, false); + TestsUtil.synchronizationWithUIThread(); + } + } + + public DRepresentationDescriptor getRepresentationDescriptor(Session session, String id) { + Collection representationDescriptors = DialectManager.INSTANCE.getAllRepresentationDescriptors(session); + for (DRepresentationDescriptor representationDescriptor : representationDescriptors) { + + String descriptorFragment; + try { + descriptorFragment = representationDescriptor.getRepPath().getResourceURI().fragment(); + } catch (NullPointerException e) { + descriptorFragment = ""; + } + + String descriptorUid = representationDescriptor.getUid(); + + if (id.equals(descriptorFragment) || id.equals(descriptorUid)) { + return representationDescriptor; + } + } + return null; + } + + @Override + protected void tearDown() throws Exception { + doCleanup(); + super.tearDown(); + } + + private void doCleanup() { + final IEditingSession sessionUI = SessionUIManager.INSTANCE.getUISession(session); + if (sessionUI != null) { + SessionUIManager.INSTANCE.remove(sessionUI); + sessionUI.close(); + TestsUtil.emptyEventsFromUIThread(); + } + if (session != null) { + doRemoveSession(); + doCloseSession(); + session = null; + } + viewpoints.clear(); + } + + private void doCloseSession() { + session.close(new NullProgressMonitor()); + Assert.assertFalse("Can't close the session", session.isOpen()); + } + + private void doRemoveSession() { + SessionManager.INSTANCE.remove(session); + for (final Session session2 : SessionManager.INSTANCE.getSessions()) { + Assert.assertFalse("Remove failed", session2.equals(session)); + } + } + +} diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeImageDisplayTest.java b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeImageDisplayTest.java index afea4694a..5311a05c5 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeImageDisplayTest.java +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeImageDisplayTest.java @@ -1,465 +1,284 @@ -/******************************************************************************* - * Copyright (c) 2021 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 - * http://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.polarsys.kitalpha.sirius.rotativeimage.junit.tests.testcases; - -import java.io.File; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.PositionConstants; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.sirius.business.api.dialect.DialectManager; -import org.eclipse.sirius.business.api.session.Session; -import org.eclipse.sirius.business.api.session.SessionManager; -import org.eclipse.sirius.diagram.DDiagram; -import org.eclipse.sirius.diagram.DDiagramElement; -import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNode2EditPart; -import org.eclipse.sirius.diagram.ui.internal.edit.parts.WorkspaceImageEditPart; -import org.eclipse.sirius.diagram.ui.internal.refresh.listeners.WorkspaceFileResourceChangeListener; -import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; -import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; -import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; -import org.eclipse.sirius.tests.support.api.TestsUtil; -import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; -import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; -import org.eclipse.sirius.ui.business.api.session.IEditingSession; -import org.eclipse.sirius.ui.business.api.session.SessionUIManager; -import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.junit.Assert; -import org.polarsys.kitalpha.sirius.rotativeimage.figures.Rotative4ImagesSVGWorkspaceImageFigure; -import org.polarsys.kitalpha.sirius.rotativeimage.figures.RotativeSVGWorkspaceImageFigure; -import org.polarsys.kitalpha.sirius.rotativeimage.figures.RotativeWorkspaceImageFigure; - -/** - * Checks the displayed images in rotative ports. Compares displayed images with Image registers content. PNG images are - * stored in the static {@link org.polarsys.kitalpha.sirius.rotativeimage.Activator ImageRegistry} SVG images are stored - * in the static {@link org.eclipse.sirius.diagram.ui.tools.api.figure.SVGFigure.ImageCache} - * - * @author Arnaud Dieumegard - */ -public class RotativeImageDisplayTest extends SiriusDiagramTestCase { - - protected static final String PLATFORM_PLUGIN_PATH = "platform:/plugin/"; - - protected static final String ROTATIVEIMAGE_TEST_PLUGIN_NAME = "/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests"; - - private static final String TEST_XMI_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.xmi"; - - private static final String TEST_AIRD_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.aird"; - - private static final String TEST_ODESIGN_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/description/test.odesign"; - - private static final String ID_REPRESENTATION_DESCRIPTOR_SVG = "_idds4E1NEeySgagIY4HK9g"; - - private static final String ID_REPRESENTATION_DESCRIPTOR_PNG = "_h9U1ME4GEeyTxN2ah5Tp3g"; - - private static final String ID_REPRESENTATION_DESCRIPTOR_FAULTY_4IMAGES = "_xkHCoFKBEeytGcI8gHYSmQ"; - - private Map dDiagramElementToPositionConstantRotationSVG; - - private Map dDiagramElementToPositionConstantFourImagesSVG; - - private Map dDiagramElementToPositionConstantRotationPNG; - - private Map dDiagramElementToPositionConstantFourImagesPNG; - - private Map dDiagramElementsToFileExtensionForFauly4Images; - - private static final String SVG = ".svg"; - - private static final String PNG = ".png"; - - private static final String ROTATIONICON = "org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/rotationIcon"; - - private static final String ROTATIONICON_SVG = ROTATIONICON + SVG; - - private static final String ROTATIONICON_PNG = ROTATIONICON + PNG; - - private static final String FOURIMAGESICON_PREFIX = "/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon"; - - private static final String FOURIMAGESICON_ERROR = FOURIMAGESICON_PREFIX + "_error"; - - private static final String TOP = "top"; - - private static final String BOTTOM = "bottom"; - - private static final String RIGHT = "right"; - - private static final String LEFT = "left"; - - @Override - protected void setUp() throws Exception { - super.setUp(); - genericSetUp(TEST_XMI_PATH, TEST_ODESIGN_PATH, TEST_AIRD_PATH); - - // Set test data - dDiagramElementToPositionConstantFourImagesSVG = new HashMap<>(); - dDiagramElementToPositionConstantFourImagesSVG.put("_ieoKgE1NEeySgagIY4HK9g", PositionConstants.NORTH); - dDiagramElementToPositionConstantFourImagesSVG.put("_ie8TkE1NEeySgagIY4HK9g", PositionConstants.EAST); - dDiagramElementToPositionConstantFourImagesSVG.put("_ie-v0E1NEeySgagIY4HK9g", PositionConstants.WEST); - dDiagramElementToPositionConstantFourImagesSVG.put("_ifBMEE1NEeySgagIY4HK9g", PositionConstants.SOUTH); - - dDiagramElementToPositionConstantRotationSVG = new HashMap<>(); - dDiagramElementToPositionConstantRotationSVG.put("_ZRjK4U6VEey8JIaoK8ucAw", PositionConstants.NORTH); - dDiagramElementToPositionConstantRotationSVG.put("_ZRoqcU6VEey8JIaoK8ucAw", PositionConstants.EAST); - dDiagramElementToPositionConstantRotationSVG.put("_ZRrtwU6VEey8JIaoK8ucAw", PositionConstants.WEST); - dDiagramElementToPositionConstantRotationSVG.put("_ZRuxEk6VEey8JIaoK8ucAw", PositionConstants.SOUTH); - - dDiagramElementToPositionConstantFourImagesPNG = new HashMap<>(); - dDiagramElementToPositionConstantFourImagesPNG.put("_iB9dkU4GEeyTxN2ah5Tp3g", PositionConstants.NORTH); - dDiagramElementToPositionConstantFourImagesPNG.put("_iCBvAU4GEeyTxN2ah5Tp3g", PositionConstants.EAST); - dDiagramElementToPositionConstantFourImagesPNG.put("_iCC9IU4GEeyTxN2ah5Tp3g", PositionConstants.WEST); - dDiagramElementToPositionConstantFourImagesPNG.put("_iCDkMU4GEeyTxN2ah5Tp3g", PositionConstants.SOUTH); - - dDiagramElementToPositionConstantRotationPNG = new HashMap<>(); - dDiagramElementToPositionConstantRotationPNG.put("_bfZigE6VEey8JIaoK8ucAw", PositionConstants.NORTH); - dDiagramElementToPositionConstantRotationPNG.put("_bfb-wk6VEey8JIaoK8ucAw", PositionConstants.EAST); - dDiagramElementToPositionConstantRotationPNG.put("_bffCEU6VEey8JIaoK8ucAw", PositionConstants.WEST); - dDiagramElementToPositionConstantRotationPNG.put("_bfheU06VEey8JIaoK8ucAw", PositionConstants.SOUTH); - - dDiagramElementsToFileExtensionForFauly4Images = new HashMap<>(); - dDiagramElementsToFileExtensionForFauly4Images.put("_xkVsIFKBEeytGcI8gHYSmQ", PNG); - dDiagramElementsToFileExtensionForFauly4Images.put("_xkWTMlKBEeytGcI8gHYSmQ", PNG); - dDiagramElementsToFileExtensionForFauly4Images.put("_xkWTNlKBEeytGcI8gHYSmQ", PNG); - dDiagramElementsToFileExtensionForFauly4Images.put("_xkW6Q1KBEeytGcI8gHYSmQ", PNG); - dDiagramElementsToFileExtensionForFauly4Images.put("_xkW6R1KBEeytGcI8gHYSmQ", SVG); - dDiagramElementsToFileExtensionForFauly4Images.put("_xkXhUlKBEeytGcI8gHYSmQ", SVG); - dDiagramElementsToFileExtensionForFauly4Images.put("_xkXhVlKBEeytGcI8gHYSmQ", SVG); - dDiagramElementsToFileExtensionForFauly4Images.put("_xkYIYVKBEeytGcI8gHYSmQ", SVG); - } - - /** - * Ensure Rotative and 4Images WorkspaceImages reference expected SVG images - */ - @SuppressWarnings("restriction") - public void testSVGDiagramImages() { - String repId = ID_REPRESENTATION_DESCRIPTOR_SVG; - DDiagram ddiagram = getDDiagramFromId(repId); - - for (Entry entry : dDiagramElementToPositionConstantRotationSVG.entrySet()) { - String elementId = entry.getKey(); - int position = entry.getValue(); - - WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); - assertNotNull(editPart); - RotativeSVGWorkspaceImageFigure figure = (RotativeSVGWorkspaceImageFigure) editPart.getContentPane(); - assertNotNull(figure); - - // Check for SVGImage DocumentKey - String figureDocumentKey = figure.getDocumentKey(); - assertTrue("Figure " + entry.getKey() + " should reference uri " + ROTATIONICON_SVG + position + " instead uri is " + figureDocumentKey, - figureDocumentKey.endsWith(ROTATIONICON_SVG + position)); - } - - for (Entry entry : dDiagramElementToPositionConstantFourImagesSVG.entrySet()) { - String elementId = entry.getKey(); - int position = entry.getValue(); - - WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); - assertNotNull(editPart); - Rotative4ImagesSVGWorkspaceImageFigure figure = (Rotative4ImagesSVGWorkspaceImageFigure) editPart.getContentPane(); - assertNotNull(figure); - - // Check for SVGImage DocumentKey - String figureDocumentKey = figure.getDocumentKey(); - String postfix = buildExpectedImagePostfix(position, SVG); - assertTrue("Figure " + entry.getKey() + " should reference uri containing " + FOURIMAGESICON_PREFIX + postfix + " instead uri is " + figureDocumentKey, - figureDocumentKey.endsWith(FOURIMAGESICON_PREFIX + postfix)); - } - } - - /** - * Ensure Rotative and 4Images WorkspaceImages reference expected PNG images - */ - @SuppressWarnings("restriction") - public void testPNGDiagramImages() { - String repId = ID_REPRESENTATION_DESCRIPTOR_PNG; - DDiagram ddiagram = getDDiagramFromId(repId); - - // Ensure displayed images rely on the correct rotated image - for (Entry entry : dDiagramElementToPositionConstantRotationPNG.entrySet()) { - String elementId = entry.getKey(); - int position = entry.getValue(); - - // Get the EditPart and the Figure - WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); - assertNotNull(editPart); - RotativeWorkspaceImageFigure figure = (RotativeWorkspaceImageFigure) editPart.getContentPane(); - assertNotNull(figure); - - Image nonRotatedImage = getImageFromPath(ROTATIONICON_PNG, PNG); - assertNotNull(nonRotatedImage); - compareImages(figure, nonRotatedImage, position); - } - - // Ensure displayed images rely on the correct 4Images - for (Entry entry : dDiagramElementToPositionConstantFourImagesPNG.entrySet()) { - String elementId = entry.getKey(); - int position = entry.getValue(); - - // Get the EditPart and the Figure - WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); - assertNotNull(editPart); - RotativeWorkspaceImageFigure figure = (RotativeWorkspaceImageFigure) editPart.getContentPane(); - assertNotNull(figure); - - // Get expected image - Image expectedImage = getImageFromPath(FOURIMAGESICON_PREFIX + buildExpectedImagePostfix(position, PNG), PNG); - assertNotNull(expectedImage); - compareImages(figure, expectedImage, PositionConstants.NORTH); - } - } - - /** - * Ensure 4Images WorkspaceImages reference default WorkspaceImage (the one defined in the odesign) when no - * postfixed 4image exists (_top, ...) - */ - public void testFaultyRotativeDiagramImages() { - String repId = ID_REPRESENTATION_DESCRIPTOR_FAULTY_4IMAGES; - DDiagram ddiagram = getDDiagramFromId(repId); - - for (Entry entry : dDiagramElementsToFileExtensionForFauly4Images.entrySet()) { - String elementId = entry.getKey(); - String extension = entry.getValue(); - - IFigure figure = getFigure(ddiagram, elementId); - - if (figure instanceof RotativeWorkspaceImageFigure) { - // Get expected image - Image expectedImage = getImageNotFoundImage(); - assertNotNull(expectedImage); - compareImages((RotativeWorkspaceImageFigure) figure, expectedImage, PositionConstants.NORTH); - } else { - String figureDocumentKey = ((Rotative4ImagesSVGWorkspaceImageFigure) figure).getDocumentKey(); - assertTrue("Figure " + entry.getKey() + " should reference uri " + FOURIMAGESICON_ERROR + extension + " instead uri is " + figureDocumentKey, - figureDocumentKey.endsWith(FOURIMAGESICON_ERROR + extension)); - } - } - } - - private Image getImageFromPath(String path, String extension) { - if (extension.equals(SVG)) { - return DiagramUIPlugin.getPlugin().getBundledImage(path); - } else { - final File imageFile = WorkspaceFileResourceChangeListener.getInstance().getFileFromURI(path); - ImageDescriptor desc = null; - if (imageFile != null && WorkspaceFileResourceChangeListener.getInstance().getReadStatusOfFile(imageFile)) { - try { - desc = WorkspaceFileResourceChangeListener.getInstance().findImageDescriptor(imageFile); - } catch (MalformedURLException e) { - // do nothing - } - } - if (desc != null) { - return DiagramUIPlugin.getPlugin().getImage(desc); - } else { - return getImageNotFoundImage(); - } - } - } - - private Image getImageNotFoundImage() { - return DiagramUIPlugin.getPlugin().getImage(DiagramUIPlugin.Implementation.findImageWithDimensionDescriptor(DiagramImagesPath.IMAGE_NOT_FOUND)); - } - - private IFigure getFigure(DDiagram ddiagram, String elementId) { - WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId); - assertNotNull(editPart); - IFigure figure = editPart.getContentPane(); - assertNotNull(figure); - return figure; - } - - private DDiagram getDDiagramFromId(String repId) { - DRepresentationDescriptor desc = getRepresentationDescriptor(session, repId); - DDiagram ddiagram = (DDiagram) desc.getRepresentation(); - - DialectEditor editor = (DialectEditor) DialectUIManager.INSTANCE.openEditor(session, ddiagram, new NullProgressMonitor()); - TestsUtil.synchronizationWithUIThread(); - DialectUIManager.INSTANCE.refreshEditor(editor, new NullProgressMonitor()); - TestsUtil.synchronizationWithUIThread(); - return ddiagram; - } - - private String buildExpectedImagePostfix(int position, String extension) { - String postfix = "_"; - switch (position) { - case PositionConstants.NORTH: - postfix += TOP; - break; - case PositionConstants.EAST: - postfix += RIGHT; - break; - case PositionConstants.WEST: - postfix += LEFT; - break; - case PositionConstants.SOUTH: - postfix += BOTTOM; - break; - } - postfix += extension; - return postfix; - } - - /** - * Compare images through ImageData comparison. expectedImage may be rotated according to the rotation parameter - * whose values should be among: - *
    - *
  • PositionConstants.NORTH: No rotation
  • - *
  • PositionConstants.EAST: 90° rotation to the right
  • - *
  • PositionConstants.WEST: 90° rotation to the left
  • - *
  • PositionConstants.SOUTH: 180° rotation
  • - *
- * - * @param figure - * @param nonRotatedOriginalImage - * @param rotation - * The rotation to apply to expectedImage - */ - private void compareImages(RotativeWorkspaceImageFigure figure, Image nonRotatedOriginalImage, int rotation) { - ImageData expectedImageData = nonRotatedOriginalImage.getImageData(); - ImageData actualImageData = figure.getImage().getImageData(); - compareImageData(rotation, expectedImageData, actualImageData); - } - - private void compareImageData(int rotation, ImageData expectedImageData, ImageData actualImageData) { - for (int x = 0; x < expectedImageData.width; x++) { - for (int y = 0; y < expectedImageData.height; y++) { - int expectedX = x; - int expectedY = y; - - switch (rotation) { - case PositionConstants.WEST: // left 90 degrees - expectedX = y; - expectedY = actualImageData.width - x - 1; - break; - case PositionConstants.EAST: // right 90 degrees - expectedX = actualImageData.height - y - 1; - expectedY = x; - break; - case PositionConstants.SOUTH: // 180 degrees - expectedX = actualImageData.width - x - 1; - expectedY = actualImageData.height - y - 1; - break; - } - // The tested image pixel at position rotated matches the original non rotated image - assertEquals(expectedImageData.getPixel(x, y), actualImageData.getPixel(expectedX, expectedY)); - assertEquals(expectedImageData.getAlpha(x, y), actualImageData.getAlpha(expectedX, expectedY)); - } - } - } - - @SuppressWarnings({ "unchecked", "restriction" }) - private WorkspaceImageEditPart getImageEditPart(DDiagram ddiagram, String elementId) { - List diagramElementsFromLabel = getDiagramElementsFromUid(ddiagram, elementId, DDiagramElement.class); - for (DDiagramElement dDiagramElement : diagramElementsFromLabel) { - IGraphicalEditPart editPart = getEditPart(dDiagramElement); - if (editPart instanceof DNode2EditPart) { - List childrens = (List) editPart.getChildren().stream().filter(WorkspaceImageEditPart.class::isInstance).collect(Collectors.toList()); - assertNotNull(childrens); - assertEquals(1, childrens.size()); - return childrens.get(0); - } - - } - return null; - } - - private List getDiagramElementsFromUid(final DDiagram diagram, final String uid, final Class searchedClass) { - final List found = new ArrayList<>(); - final Iterator it = diagram.eAllContents(); - while (it.hasNext()) { - final EObject cur = it.next(); - if (searchedClass.isInstance(cur) && (uidFeature(cur.eClass()) != null) && uid.equals(getUidValue(cur))) { - found.add(searchedClass.cast(cur)); - } - } - return found; - } - - private String getUidValue(final EObject cur) { - return (String) cur.eGet(uidFeature(cur.eClass())); - } - - private EStructuralFeature uidFeature(final EClass class1) { - return class1.getEStructuralFeature("uid"); - } - - public DRepresentationDescriptor getRepresentationDescriptor(Session session, String id) { - Collection representationDescriptors = DialectManager.INSTANCE.getAllRepresentationDescriptors(session); - for (DRepresentationDescriptor representationDescriptor : representationDescriptors) { - - String descriptorFragment; - try { - descriptorFragment = representationDescriptor.getRepPath().getResourceURI().fragment(); - } catch (NullPointerException e) { - descriptorFragment = ""; - } - - String descriptorUid = representationDescriptor.getUid(); - - if (id.equals(descriptorFragment) || id.equals(descriptorUid)) { - return representationDescriptor; - } - } - return null; - } - - @Override - protected void tearDown() throws Exception { - doCleanup(); - super.tearDown(); - } - - private void doCleanup() { - final IEditingSession sessionUI = SessionUIManager.INSTANCE.getUISession(session); - if (sessionUI != null) { - SessionUIManager.INSTANCE.remove(sessionUI); - sessionUI.close(); - TestsUtil.emptyEventsFromUIThread(); - } - if (session != null) { - doRemoveSession(); - doCloseSession(); - session = null; - } - viewpoints.clear(); - } - - private void doCloseSession() { - session.close(new NullProgressMonitor()); - Assert.assertFalse("Can't close the session", session.isOpen()); - } - - private void doRemoveSession() { - SessionManager.INSTANCE.remove(session); - for (final Session session2 : SessionManager.INSTANCE.getSessions()) { - Assert.assertFalse("Remove failed", session2.equals(session)); - } - } - -} +/******************************************************************************* + * Copyright (c) 2021 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 + * http://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.polarsys.kitalpha.sirius.rotativeimage.junit.tests.testcases; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.ui.internal.refresh.listeners.WorkspaceFileResourceChangeListener; +import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; +import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Resource; +import org.polarsys.kitalpha.sirius.rotativeimage.figures.Rotative4ImagesSVGWorkspaceImageFigure; +import org.polarsys.kitalpha.sirius.rotativeimage.figures.RotativeSVGWorkspaceImageFigure; +import org.polarsys.kitalpha.sirius.rotativeimage.figures.RotativeWorkspaceImageFigure; + +/** + * Checks the displayed images in rotative ports. Compares displayed images with Image registers content. PNG images are + * stored in the static {@link org.polarsys.kitalpha.sirius.rotativeimage.Activator ImageRegistry} SVG images are stored + * in the static {@link org.eclipse.sirius.diagram.ui.tools.api.figure.SVGFigure.ImageCache} + * + * @author Arnaud Dieumegard + */ +public class RotativeImageDisplayTest extends RotativeSiriusTest { + + private static final String ID_REPRESENTATION_DESCRIPTOR_SVG = "_idds4E1NEeySgagIY4HK9g"; + + private static final String ID_REPRESENTATION_DESCRIPTOR_PNG = "_h9U1ME4GEeyTxN2ah5Tp3g"; + + private static final String ID_REPRESENTATION_DESCRIPTOR_FAULTY_4IMAGES = "_xkHCoFKBEeytGcI8gHYSmQ"; + + private Map dDiagramElementToPositionConstantRotationSVG; + + private Map dDiagramElementToPositionConstantFourImagesSVG; + + private Map dDiagramElementToPositionConstantRotationPNG; + + private Map dDiagramElementToPositionConstantFourImagesPNG; + + private Map dDiagramElementsToFileExtensionForFauly4Images; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setPreferenceAutoRefresh(true); + setPreferenceRefreshOnOpening(true); + Resource.setNonDisposeHandler(null); + genericSetUp(TEST_XMI_PATH, TEST_ODESIGN_PATH, TEST_AIRD_PATH); + + // Set test data + dDiagramElementToPositionConstantFourImagesSVG = new HashMap<>(); + dDiagramElementToPositionConstantFourImagesSVG.put("_ieoKgE1NEeySgagIY4HK9g", PositionConstants.NORTH); + dDiagramElementToPositionConstantFourImagesSVG.put("_ie8TkE1NEeySgagIY4HK9g", PositionConstants.EAST); + dDiagramElementToPositionConstantFourImagesSVG.put("_ie-v0E1NEeySgagIY4HK9g", PositionConstants.WEST); + dDiagramElementToPositionConstantFourImagesSVG.put("_ifBMEE1NEeySgagIY4HK9g", PositionConstants.SOUTH); + + dDiagramElementToPositionConstantRotationSVG = new HashMap<>(); + dDiagramElementToPositionConstantRotationSVG.put("_ZRjK4U6VEey8JIaoK8ucAw", PositionConstants.NORTH); + dDiagramElementToPositionConstantRotationSVG.put("_ZRoqcU6VEey8JIaoK8ucAw", PositionConstants.EAST); + dDiagramElementToPositionConstantRotationSVG.put("_ZRrtwU6VEey8JIaoK8ucAw", PositionConstants.WEST); + dDiagramElementToPositionConstantRotationSVG.put("_ZRuxEk6VEey8JIaoK8ucAw", PositionConstants.SOUTH); + + dDiagramElementToPositionConstantFourImagesPNG = new HashMap<>(); + dDiagramElementToPositionConstantFourImagesPNG.put("_iB9dkU4GEeyTxN2ah5Tp3g", PositionConstants.NORTH); + dDiagramElementToPositionConstantFourImagesPNG.put("_iCBvAU4GEeyTxN2ah5Tp3g", PositionConstants.EAST); + dDiagramElementToPositionConstantFourImagesPNG.put("_iCC9IU4GEeyTxN2ah5Tp3g", PositionConstants.WEST); + dDiagramElementToPositionConstantFourImagesPNG.put("_iCDkMU4GEeyTxN2ah5Tp3g", PositionConstants.SOUTH); + + dDiagramElementToPositionConstantRotationPNG = new HashMap<>(); + dDiagramElementToPositionConstantRotationPNG.put("_bfZigE6VEey8JIaoK8ucAw", PositionConstants.NORTH); + dDiagramElementToPositionConstantRotationPNG.put("_bfb-wk6VEey8JIaoK8ucAw", PositionConstants.EAST); + dDiagramElementToPositionConstantRotationPNG.put("_bffCEU6VEey8JIaoK8ucAw", PositionConstants.WEST); + dDiagramElementToPositionConstantRotationPNG.put("_bfheU06VEey8JIaoK8ucAw", PositionConstants.SOUTH); + + dDiagramElementsToFileExtensionForFauly4Images = new HashMap<>(); + dDiagramElementsToFileExtensionForFauly4Images.put("_xkVsIFKBEeytGcI8gHYSmQ", PNG); + dDiagramElementsToFileExtensionForFauly4Images.put("_xkWTMlKBEeytGcI8gHYSmQ", PNG); + dDiagramElementsToFileExtensionForFauly4Images.put("_xkWTNlKBEeytGcI8gHYSmQ", PNG); + dDiagramElementsToFileExtensionForFauly4Images.put("_xkW6Q1KBEeytGcI8gHYSmQ", PNG); + dDiagramElementsToFileExtensionForFauly4Images.put("_xkW6R1KBEeytGcI8gHYSmQ", SVG); + dDiagramElementsToFileExtensionForFauly4Images.put("_xkXhUlKBEeytGcI8gHYSmQ", SVG); + dDiagramElementsToFileExtensionForFauly4Images.put("_xkXhVlKBEeytGcI8gHYSmQ", SVG); + dDiagramElementsToFileExtensionForFauly4Images.put("_xkYIYVKBEeytGcI8gHYSmQ", SVG); + } + + /** + * Ensure Rotative and 4Images WorkspaceImages reference expected SVG images + */ + public void testSVGDiagramImages() { + String repId = ID_REPRESENTATION_DESCRIPTOR_SVG; + DDiagram ddiagram = getDDiagramFromId(repId); + DiagramEditor editor = openEditor(ddiagram); + + for (Entry entry : dDiagramElementToPositionConstantRotationSVG.entrySet()) { + String elementId = entry.getKey(); + int position = entry.getValue(); + + IFigure figure = getFigure(ddiagram, elementId, editor); + shallBeRotativeOn(figure, position); + } + + for (Entry entry : dDiagramElementToPositionConstantFourImagesSVG.entrySet()) { + String elementId = entry.getKey(); + int position = entry.getValue(); + + IFigure figure = getFigure(ddiagram, elementId, editor); + shallBe4ImagesOn(figure, position); + } + } + + private void shallBeRotativeOn(IFigure figure, int position) { + assertTrue(figure instanceof RotativeSVGWorkspaceImageFigure); + + // Check for SVGImage DocumentKey + String figureDocumentKey = ((RotativeSVGWorkspaceImageFigure) figure).getDocumentKey(); + assertTrue("Figure should reference uri " + ROTATIONICON_SVG + position + " instead uri is " + figureDocumentKey, + figureDocumentKey.endsWith(ROTATIONICON_SVG + position)); + } + + /** + * Ensure Rotative and 4Images WorkspaceImages reference expected PNG images + */ + public void testPNGDiagramImages() { + String repId = ID_REPRESENTATION_DESCRIPTOR_PNG; + DDiagram ddiagram = getDDiagramFromId(repId); + DiagramEditor editor = openEditor(ddiagram); + + // Ensure displayed images rely on the correct rotated image + for (Entry entry : dDiagramElementToPositionConstantRotationPNG.entrySet()) { + String elementId = entry.getKey(); + int position = entry.getValue(); + + // Get the EditPart and the Figure + IFigure figure = getFigure(ddiagram, elementId, editor); + assertTrue(figure instanceof RotativeWorkspaceImageFigure); + + Image nonRotatedImage = getImageFromPath(ROTATIONICON_PNG, PNG); + assertNotNull(nonRotatedImage); + compareImages((RotativeWorkspaceImageFigure) figure, nonRotatedImage, position); + } + + // Ensure displayed images rely on the correct 4Images + for (Entry entry : dDiagramElementToPositionConstantFourImagesPNG.entrySet()) { + String elementId = entry.getKey(); + int position = entry.getValue(); + + // Get the EditPart and the Figure + IFigure figure = getFigure(ddiagram, elementId, editor); + assertTrue(figure instanceof RotativeWorkspaceImageFigure); + + // Get expected image + Image expectedImage = getImageFromPath(FOURIMAGESICON_PREFIX + buildExpectedImagePostfix(position, PNG), PNG); + assertNotNull(expectedImage); + compareImages((RotativeWorkspaceImageFigure) figure, expectedImage, PositionConstants.NORTH); + } + } + + /** + * Ensure 4Images WorkspaceImages reference default WorkspaceImage (the one defined in the odesign) when no postfixed + * 4image exists (_top, ...) + */ + public void testFaultyRotativeDiagramImages() { + String repId = ID_REPRESENTATION_DESCRIPTOR_FAULTY_4IMAGES; + DDiagram ddiagram = getDDiagramFromId(repId); + DiagramEditor editor = openEditor(ddiagram); + for (Entry entry : dDiagramElementsToFileExtensionForFauly4Images.entrySet()) { + String elementId = entry.getKey(); + String extension = entry.getValue(); + + IFigure figure = getFigure(ddiagram, elementId, editor); + + if (figure instanceof RotativeWorkspaceImageFigure) { + // Get expected image + Image expectedImage = getImageNotFoundImage(); + assertNotNull(expectedImage); + compareImages((RotativeWorkspaceImageFigure) figure, expectedImage, PositionConstants.NORTH); + } else { + String figureDocumentKey = ((Rotative4ImagesSVGWorkspaceImageFigure) figure).getDocumentKey(); + assertTrue("Figure " + entry.getKey() + " should reference uri " + FOURIMAGESICON_ERROR + extension + + " instead uri is " + figureDocumentKey, figureDocumentKey.endsWith(FOURIMAGESICON_ERROR + extension)); + } + } + } + + private Image getImageFromPath(String path, String extension) { + if (extension.equals(SVG)) { + return DiagramUIPlugin.getPlugin().getBundledImage(path); + } else { + final File imageFile = WorkspaceFileResourceChangeListener.getInstance().getFileFromURI(path); + ImageDescriptor desc = null; + if (imageFile != null && WorkspaceFileResourceChangeListener.getInstance().getReadStatusOfFile(imageFile)) { + try { + desc = WorkspaceFileResourceChangeListener.getInstance().findImageDescriptor(imageFile); + } catch (MalformedURLException e) { + // do nothing + } + } + if (desc != null) { + return DiagramUIPlugin.getPlugin().getImage(desc); + } else { + return getImageNotFoundImage(); + } + } + } + + private Image getImageNotFoundImage() { + return DiagramUIPlugin.getPlugin() + .getImage(DiagramUIPlugin.Implementation.findImageWithDimensionDescriptor(DiagramImagesPath.IMAGE_NOT_FOUND)); + } + + private DDiagram getDDiagramFromId(String repId) { + DRepresentationDescriptor desc = getRepresentationDescriptor(session, repId); + DDiagram ddiagram = (DDiagram) desc.getRepresentation(); + return ddiagram; + } + + /** + * Compare images through ImageData comparison. expectedImage may be rotated according to the rotation parameter whose + * values should be among: + *
    + *
  • PositionConstants.NORTH: No rotation
  • + *
  • PositionConstants.EAST: 90°rotation to the right
  • + *
  • PositionConstants.WEST: 90° rotation to the left
  • + *
  • PositionConstants.SOUTH: 180° rotation
  • + *
+ * + * @param figure + * @param nonRotatedOriginalImage + * @param rotation + * The rotation to apply to expectedImage + */ + private void compareImages(RotativeWorkspaceImageFigure figure, Image nonRotatedOriginalImage, int rotation) { + ImageData expectedImageData = nonRotatedOriginalImage.getImageData(); + ImageData actualImageData = figure.getImage().getImageData(); + compareImageData(rotation, expectedImageData, actualImageData); + } + + private void compareImageData(int rotation, ImageData expectedImageData, ImageData actualImageData) { + for (int x = 0; x < expectedImageData.width; x++) { + for (int y = 0; y < expectedImageData.height; y++) { + int expectedX = x; + int expectedY = y; + + switch (rotation) { + case PositionConstants.WEST: // left 90 degrees + expectedX = y; + expectedY = actualImageData.width - x - 1; + break; + case PositionConstants.EAST: // right 90 degrees + expectedX = actualImageData.height - y - 1; + expectedY = x; + break; + case PositionConstants.SOUTH: // 180 degrees + expectedX = actualImageData.width - x - 1; + expectedY = actualImageData.height - y - 1; + break; + } + // The tested image pixel at position rotated matches the original non rotated image + assertEquals(expectedImageData.getPixel(x, y), actualImageData.getPixel(expectedX, expectedY)); + assertEquals(expectedImageData.getAlpha(x, y), actualImageData.getAlpha(expectedX, expectedY)); + } + } + } + +} diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeImageMovementTest.java b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeImageMovementTest.java index d99e943cc..22462bb8b 100644 --- a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeImageMovementTest.java +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeImageMovementTest.java @@ -1,212 +1,100 @@ -/******************************************************************************* - * Copyright (c) 2021 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 - * http://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.polarsys.kitalpha.sirius.rotativeimage.junit.tests.testcases; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; -import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest; -import org.eclipse.sirius.business.api.dialect.DialectManager; -import org.eclipse.sirius.business.api.session.Session; -import org.eclipse.sirius.business.api.session.SessionManager; -import org.eclipse.sirius.common.tools.api.util.CommandStackUtil; -import org.eclipse.sirius.diagram.DDiagram; -import org.eclipse.sirius.diagram.DDiagramElement; -import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNode2EditPart; -import org.eclipse.sirius.diagram.ui.internal.edit.parts.WorkspaceImageEditPart; -import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; -import org.eclipse.sirius.tests.support.api.TestsUtil; -import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; -import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; -import org.eclipse.sirius.ui.business.api.session.IEditingSession; -import org.eclipse.sirius.ui.business.api.session.SessionUIManager; -import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; -import org.junit.Assert; -import org.polarsys.kitalpha.sirius.rotativeimage.figures.Rotative4ImagesSVGWorkspaceImageFigure; - -/** - * Checks that displayed images in rotative bordered node move when node changes side of parent - * - * @author Arnaud Dieumegard - */ -public class RotativeImageMovementTest extends SiriusDiagramTestCase { - - protected static final String PLATFORM_PLUGIN_PATH = "platform:/plugin/"; - - protected static final String ROTATIVEIMAGE_TEST_PLUGIN_NAME = "/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests"; - - private static final String TEST_XMI_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.xmi"; - - private static final String TEST_AIRD_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.aird"; - - private static final String TEST_ODESIGN_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/description/test.odesign"; - - private static final String ID_REPRESENTATION_DESCRIPTOR_SVG = "_idds4E1NEeySgagIY4HK9g"; - - private static final String SVG = ".svg"; - - private static final String FOURIMAGESICON_PREFIX = "/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon"; - - private static final String BOTTOM = "bottom"; - - private static final String LEFT = "left"; - - private static final String BOTTOM_E1_BORDERNODE_ID = "_ifBMEE1NEeySgagIY4HK9g"; - - @Override - protected void setUp() throws Exception { - super.setUp(); - genericSetUp(TEST_XMI_PATH, TEST_ODESIGN_PATH, TEST_AIRD_PATH); - } - - /** - * Ensure Rotative and 4Images WorkspaceImages reference expected SVG images - */ - @SuppressWarnings("restriction") - public void testMoveImages() { - String repId = ID_REPRESENTATION_DESCRIPTOR_SVG; - DRepresentationDescriptor desc = getRepresentationDescriptor(session, repId); - DDiagram ddiagram = (DDiagram) desc.getRepresentation(); - - DialectEditor editor = (DialectEditor) DialectUIManager.INSTANCE.openEditor(session, ddiagram, new NullProgressMonitor()); - TestsUtil.synchronizationWithUIThread(); - DialectUIManager.INSTANCE.refreshEditor(editor, new NullProgressMonitor()); - TestsUtil.synchronizationWithUIThread(); - - List diagramElementsFromLabel = getDiagramElementsFromUid(ddiagram, BOTTOM_E1_BORDERNODE_ID, DDiagramElement.class); - for (DDiagramElement dDiagramElement : diagramElementsFromLabel) { - IGraphicalEditPart editPart = getEditPart(dDiagramElement); - if (editPart instanceof DNode2EditPart) { - List childrens = (List) editPart.getChildren().stream().filter(WorkspaceImageEditPart.class::isInstance).collect(Collectors.toList()); - assertNotNull(childrens); - assertEquals(1, childrens.size()); - - WorkspaceImageEditPart bottomEditPart = childrens.get(0); - assertNotNull(bottomEditPart); - Rotative4ImagesSVGWorkspaceImageFigure bottomFigure = (Rotative4ImagesSVGWorkspaceImageFigure) bottomEditPart.getContentPane(); - assertNotNull(bottomFigure); - - // Check for SVGImage DocumentKey - String figureDocumentKey = bottomFigure.getDocumentKey(); - assertTrue("Figure should reference uri " + FOURIMAGESICON_PREFIX + "_" + BOTTOM + SVG + " instead uri is " + figureDocumentKey, - figureDocumentKey.endsWith(FOURIMAGESICON_PREFIX + "_" + BOTTOM + SVG)); - - // Arrange all in diagram - performArrangeAll(ddiagram, (DiagramEditor) editor); - - // Check new position - figureDocumentKey = bottomFigure.getDocumentKey(); - assertTrue("Figure should reference uri " + FOURIMAGESICON_PREFIX + "_" + LEFT + SVG + " instead uri is " + figureDocumentKey, - figureDocumentKey.endsWith(FOURIMAGESICON_PREFIX + "_" + LEFT + SVG)); - - } - } - - } - - private void performArrangeAll(DDiagram ddiagram, DiagramEditor editor) { - final ArrangeRequest request = new ArrangeRequest(ActionIds.ACTION_ARRANGE_ALL); - request.setPartsToArrange(Arrays.asList(editor.getDiagramEditPart())); - editor.getDiagramEditPart().refresh(); - editor.getDiagramEditPart().performRequest(request); - CommandStackUtil.flushOperations(editor.getEditingDomain().getCommandStack()); - editor.getDiagramEditPart().getRoot().getViewer().flush(); - TestsUtil.synchronizationWithUIThread(); - } - - private List getDiagramElementsFromUid(final DDiagram diagram, final String uid, final Class searchedClass) { - final List found = new ArrayList<>(); - final Iterator it = diagram.eAllContents(); - while (it.hasNext()) { - final EObject cur = it.next(); - if (searchedClass.isInstance(cur) && uidFeature(cur.eClass()) != null) { - if (uid.equals(getUidValue(cur))) { - found.add(searchedClass.cast(cur)); - } - } - } - return found; - } - - private String getUidValue(final EObject cur) { - return (String) cur.eGet(uidFeature(cur.eClass())); - } - - private EStructuralFeature uidFeature(final EClass class1) { - return class1.getEStructuralFeature("uid"); - } - - public DRepresentationDescriptor getRepresentationDescriptor(Session session, String id) { - Collection representationDescriptors = DialectManager.INSTANCE.getAllRepresentationDescriptors(session); - for (DRepresentationDescriptor representationDescriptor : representationDescriptors) { - - String descriptorFragment; - try { - descriptorFragment = representationDescriptor.getRepPath().getResourceURI().fragment(); - } catch (NullPointerException e) { - descriptorFragment = ""; - } - - String descriptorUid = representationDescriptor.getUid(); - - if (id.equals(descriptorFragment) || id.equals(descriptorUid)) { - return representationDescriptor; - } - } - return null; - } - - @Override - protected void tearDown() throws Exception { - doCleanup(); - super.tearDown(); - } - - private void doCleanup() { - final IEditingSession sessionUI = SessionUIManager.INSTANCE.getUISession(session); - if (sessionUI != null) { - SessionUIManager.INSTANCE.remove(sessionUI); - sessionUI.close(); - TestsUtil.emptyEventsFromUIThread(); - } - if (session != null) { - doRemoveSession(); - doCloseSession(); - session = null; - } - viewpoints.clear(); - } - - private void doCloseSession() { - session.close(new NullProgressMonitor()); - Assert.assertFalse("Can't close the session", session.isOpen()); - } - - private void doRemoveSession() { - SessionManager.INSTANCE.remove(session); - for (final Session session2 : SessionManager.INSTANCE.getSessions()) { - Assert.assertFalse("Remove failed", session2.equals(session)); - } - } - -} +/******************************************************************************* + * Copyright (c) 2021 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 + * http://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.polarsys.kitalpha.sirius.rotativeimage.junit.tests.testcases; + +import java.util.List; +import java.util.stream.Collectors; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.DDiagramElement; +import org.eclipse.sirius.diagram.ui.internal.edit.parts.WorkspaceImageEditPart; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.swt.graphics.Resource; +import org.polarsys.kitalpha.sirius.rotativeimage.figures.Rotative4ImagesSVGWorkspaceImageFigure; + +/** + * Checks that displayed images in rotative bordered node move when node changes side of parent + * + * @author Arnaud Dieumegard + */ +public class RotativeImageMovementTest extends RotativeSiriusTest { + + private static final String ID_REPRESENTATION_DESCRIPTOR_SVG = "_idds4E1NEeySgagIY4HK9g"; + + private static final String BOTTOM_E1_BORDERNODE_ID = "_ifBMEE1NEeySgagIY4HK9g"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setPreferenceAutoRefresh(true); + setPreferenceRefreshOnOpening(true); + Resource.setNonDisposeHandler(null); + genericSetUp(TEST_XMI_PATH, TEST_ODESIGN_PATH, TEST_AIRD_PATH); + } + + /** + * Ensure that image is changed if the port is moved + */ + public void testMoveImages() { + DRepresentationDescriptor desc = getRepresentationDescriptor(session, ID_REPRESENTATION_DESCRIPTOR_SVG); + DDiagram ddiagram = (DDiagram) desc.getRepresentation(); + DiagramEditor editor = openEditor(ddiagram); + + IFigure figure = getFigure(ddiagram, BOTTOM_E1_BORDERNODE_ID, editor); + shallBe4ImagesOn(figure, PositionConstants.SOUTH); + + // We put the port on the left. After reopening the diagram, it will be moved to west according to conditional + // style. + DDiagramElement port = getDiagramElementFromUid(ddiagram, BOTTOM_E1_BORDERNODE_ID, DDiagramElement.class); + setLeft(port, Boolean.TRUE); + + closeEditor(editor); + editor = openEditor(ddiagram); + + figure = getFigure(ddiagram, BOTTOM_E1_BORDERNODE_ID, editor); + shallBe4ImagesOn(figure, PositionConstants.WEST); + } + + private Rotative4ImagesSVGWorkspaceImageFigure getFigure(IGraphicalEditPart editPart) { + List childrens = (List) editPart.getChildren().stream() + .filter(WorkspaceImageEditPart.class::isInstance).collect(Collectors.toList()); + assertNotNull(childrens); + assertEquals(1, childrens.size()); + + WorkspaceImageEditPart bottomEditPart = childrens.get(0); + assertNotNull(bottomEditPart); + Rotative4ImagesSVGWorkspaceImageFigure bottomFigure = (Rotative4ImagesSVGWorkspaceImageFigure) bottomEditPart + .getContentPane(); + assertNotNull(bottomFigure); + return bottomFigure; + } + + private void setLeft(EObject target, Boolean isLeft) { + TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(target); + domain.getCommandStack().execute(new RecordingCommand(domain) { + @Override + protected void doExecute() { + ((DDiagramElement) target).getTarget() + .eSet(((DDiagramElement) target).getTarget().eClass().getEStructuralFeature("left"), isLeft); + } + }); + } + +} diff --git a/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeSiriusTest.java b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeSiriusTest.java new file mode 100644 index 000000000..9d42ab4c7 --- /dev/null +++ b/sirius/tests/plugins/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/src/org/polarsys/kitalpha/sirius/rotativeimage/junit/tests/testcases/RotativeSiriusTest.java @@ -0,0 +1,253 @@ +/******************************************************************************* + * Copyright (c) 2024 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 + * http://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.polarsys.kitalpha.sirius.rotativeimage.junit.tests.testcases; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.sirius.business.api.dialect.DialectManager; +import org.eclipse.sirius.business.api.preferences.SiriusPreferencesKeys; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.business.api.session.SessionManager; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.DDiagramElement; +import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNode2EditPart; +import org.eclipse.sirius.diagram.ui.internal.edit.parts.WorkspaceImageEditPart; +import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; +import org.eclipse.sirius.tests.support.api.TestsUtil; +import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.eclipse.sirius.ui.business.api.preferences.SiriusUIPreferencesKeys; +import org.eclipse.sirius.ui.business.api.session.IEditingSession; +import org.eclipse.sirius.ui.business.api.session.SessionUIManager; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; +import org.eclipse.ui.PlatformUI; +import org.junit.Assert; +import org.polarsys.kitalpha.sirius.rotativeimage.figures.Rotative4ImagesSVGWorkspaceImageFigure; + +public class RotativeSiriusTest extends SiriusDiagramTestCase { + + protected static final String PNG = ".png"; + + protected static final String SVG = ".svg"; + + protected static final String ROTATIONICON = "org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/rotationIcon"; + + protected static final String ROTATIONICON_SVG = ROTATIONICON + SVG; + + protected static final String ROTATIONICON_PNG = ROTATIONICON + PNG; + + protected static final String FOURIMAGESICON_PREFIX = "/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests/icons/4imagesIcon"; + + protected static final String FOURIMAGESICON_ERROR = FOURIMAGESICON_PREFIX + "_error"; + + protected static final String TOP = "top"; + + protected static final String BOTTOM = "bottom"; + + protected static final String RIGHT = "right"; + + protected static final String LEFT = "left"; + + protected static final String PLATFORM_PLUGIN_PATH = "platform:/plugin/"; + + protected static final String ROTATIVEIMAGE_TEST_PLUGIN_NAME = "/org.polarsys.kitalpha.sirius.rotativeimage.junit.tests"; + + protected static final String TEST_XMI_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.xmi"; + + protected static final String TEST_AIRD_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/models/Test1.aird"; + + protected static final String TEST_ODESIGN_PATH = ROTATIVEIMAGE_TEST_PLUGIN_NAME + "/description/test.odesign"; + + private String getUidValue(final EObject cur) { + return (String) cur.eGet(uidFeature(cur.eClass())); + } + + private EStructuralFeature uidFeature(final EClass class1) { + return class1.getEStructuralFeature("uid"); + } + + /** + * Set the auto refresh preference for diagram + * + * @apiNote that this method will affect the running instance (not specific to a given project) + * @see org.eclipse.sirius.business.api.session.Session.getSiriusPreferences + * @param value + */ + public static void setPreferenceAutoRefresh(final boolean value) { + IPreferenceStore preferenceStore = SiriusEditPlugin.getPlugin().getCorePreferenceStore(); + preferenceStore.setValue(SiriusPreferencesKeys.PREF_AUTO_REFRESH.name(), value); + } + + /** + * Set the refresh on opening preference for diagram + * + * @apiNote that this method will affect the running instance (not specific to a given project) + * @see org.eclipse.sirius.business.api.session.Session.getSiriusPreferences + * @param value + */ + public static void setPreferenceRefreshOnOpening(final boolean value) { + IPreferenceStore preferenceStore = SiriusEditPlugin.getPlugin().getPreferenceStore(); + preferenceStore.setValue(SiriusUIPreferencesKeys.PREF_REFRESH_ON_REPRESENTATION_OPENING.name(), value); + } + + public DRepresentationDescriptor getRepresentationDescriptor(Session session, String id) { + Collection representationDescriptors = DialectManager.INSTANCE + .getAllRepresentationDescriptors(session); + for (DRepresentationDescriptor representationDescriptor : representationDescriptors) { + + String descriptorFragment; + try { + descriptorFragment = representationDescriptor.getRepPath().getResourceURI().fragment(); + } catch (NullPointerException e) { + descriptorFragment = ""; + } + + String descriptorUid = representationDescriptor.getUid(); + + if (id.equals(descriptorFragment) || id.equals(descriptorUid)) { + return representationDescriptor; + } + } + return null; + } + + @Override + protected void tearDown() throws Exception { + doCleanup(); + super.tearDown(); + } + + private void doCleanup() { + final IEditingSession sessionUI = SessionUIManager.INSTANCE.getUISession(session); + if (sessionUI != null) { + SessionUIManager.INSTANCE.remove(sessionUI); + sessionUI.close(); + TestsUtil.emptyEventsFromUIThread(); + } + if (session != null) { + doRemoveSession(); + doCloseSession(); + session = null; + } + viewpoints.clear(); + Collection editors = Stream + .of(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()) + .map(x -> x.getEditor(false)).filter(Objects::nonNull).filter(DiagramEditor.class::isInstance) + .map(DiagramEditor.class::cast).collect(Collectors.toSet()); + editors.forEach(e -> closeEditor(e)); + TestsUtil.emptyEventsFromUIThread(); + } + + private void doCloseSession() { + session.close(new NullProgressMonitor()); + Assert.assertFalse("Can't close the session", session.isOpen()); + } + + private void doRemoveSession() { + SessionManager.INSTANCE.remove(session); + for (final Session session2 : SessionManager.INSTANCE.getSessions()) { + Assert.assertFalse("Remove failed", session2.equals(session)); + } + } + + protected T getDiagramElementFromUid(final DDiagram diagram, final String uid, + final Class searchedClass) { + final List found = new ArrayList<>(); + final Iterator it = diagram.eAllContents(); + while (it.hasNext()) { + final EObject cur = it.next(); + if (searchedClass.isInstance(cur) && (uidFeature(cur.eClass()) != null) && uid.equals(getUidValue(cur))) { + return searchedClass.cast(cur); + } + } + return null; + } + + @SuppressWarnings({ "unchecked", "restriction" }) + private WorkspaceImageEditPart getImageEditPart(DDiagram ddiagram, String elementId, DiagramEditor editor) { + DDiagramElement dDiagramElement = getDiagramElementFromUid(ddiagram, elementId, DDiagramElement.class); + IGraphicalEditPart editPart = getEditPart(dDiagramElement, editor); + if (editPart instanceof DNode2EditPart) { + List childrens = (List) editPart.getChildren().stream() + .filter(WorkspaceImageEditPart.class::isInstance).collect(Collectors.toList()); + assertNotNull(childrens); + assertEquals(1, childrens.size()); + return childrens.get(0); + } + return null; + } + + protected IFigure getFigure(DDiagram ddiagram, String elementId, DiagramEditor editor) { + WorkspaceImageEditPart editPart = getImageEditPart(ddiagram, elementId, editor); + assertNotNull(editPart); + IFigure figure = editPart.getContentPane(); + assertNotNull(figure); + return figure; + } + + protected DiagramEditor openEditor(DDiagram ddiagram) { + DiagramEditor editor = (DiagramEditor) DialectUIManager.INSTANCE.openEditor(session, ddiagram, + new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + return editor; + } + + protected void closeEditor(DiagramEditor editor) { + DialectUIManager.INSTANCE.closeEditor(editor, false); + TestsUtil.synchronizationWithUIThread(); + } + + protected String buildExpectedImagePostfix(int position, String extension) { + String postfix = "_"; + switch (position) { + case PositionConstants.NORTH: + postfix += TOP; + break; + case PositionConstants.EAST: + postfix += RIGHT; + break; + case PositionConstants.WEST: + postfix += LEFT; + break; + case PositionConstants.SOUTH: + postfix += BOTTOM; + break; + } + postfix += extension; + return postfix; + } + + protected void shallBe4ImagesOn(IFigure figure, int position) { + assertTrue(figure instanceof Rotative4ImagesSVGWorkspaceImageFigure); + String figureDocumentKey = ((Rotative4ImagesSVGWorkspaceImageFigure) figure).getDocumentKey(); + String postfix = buildExpectedImagePostfix(position, SVG); + assertTrue( + "Figure should reference uri " + FOURIMAGESICON_PREFIX + postfix + " instead uri is " + figureDocumentKey, + figureDocumentKey.endsWith(FOURIMAGESICON_PREFIX + postfix)); + } + +}