[test] Add check on "red cross" decorator for deleted element

During an analysis of another issue, we discover that test
org.eclipse.sirius.tests.swtbot.DeleteSemanticElementToCheckDecorator is
no longer useful. Indeed, the core of the test do nothing. What it
should test has been added in another test
org.eclipse.sirius.tests.unit.diagram.synchronization.UnsynchronizedMappingAndDeleteFromOutsideEditorTests.
2 API classes have been moved from swtbot test framework to junit test
framework.

Change-Id: I2eaae8ffa25f775c34b2870063e168ac93ae2c3c
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
diff --git a/plugins/org.eclipse.sirius.tests.junit.support/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.junit.support/META-INF/MANIFEST.MF
index 2d99a1e..2d1a350 100644
--- a/plugins/org.eclipse.sirius.tests.junit.support/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.tests.junit.support/META-INF/MANIFEST.MF
@@ -22,6 +22,7 @@
 Bundle-Localization: plugin
 Bundle-ActivationPolicy: lazy
 Export-Package: org.eclipse.sirius.tests.support.api;version="1.2.0",
+ org.eclipse.sirius.tests.support.api.matcher;version="4.1.7",
  org.eclipse.sirius.tests.support.command;version="3.0.0",
  org.eclipse.sirius.tests.support.internal;x-internal:=true;version="3.0.0",
  org.eclipse.sirius.tests.support.internal.helper;x-friends:=org.eclipse.sirius.tree.tests;version="0.1.0"
diff --git a/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/matcher/AbstractDecoratorMatcher.java b/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/matcher/AbstractDecoratorMatcher.java
similarity index 60%
rename from plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/matcher/AbstractDecoratorMatcher.java
rename to plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/matcher/AbstractDecoratorMatcher.java
index c93aef8..765b08f 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/matcher/AbstractDecoratorMatcher.java
+++ b/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/matcher/AbstractDecoratorMatcher.java
@@ -8,18 +8,21 @@
  * Contributors:
  *      Obeo - Initial API and implementation
  */
-package org.eclipse.sirius.tests.swtbot.support.api.matcher;
+package org.eclipse.sirius.tests.support.api.matcher;
 
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.eclipse.draw2d.Figure;
 import org.eclipse.draw2d.IFigure;
 import org.eclipse.gef.EditPart;
 import org.eclipse.gef.EditPartViewer;
 import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration;
 import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.ImageFigureEx;
+import org.eclipse.sirius.tests.support.api.ImageEquality;
 import org.eclipse.swt.graphics.Image;
-import org.eclipse.swtbot.swt.finder.matchers.AbstractMatcher;
+import org.hamcrest.BaseMatcher;
 
 /**
  * 
@@ -27,7 +30,7 @@
  * 
  * @author amartin
  */
-public abstract class AbstractDecoratorMatcher extends AbstractMatcher<EditPart> {
+public abstract class AbstractDecoratorMatcher extends BaseMatcher<EditPart> {
 
     /**
      * return the image of the targeted decorator.
@@ -36,11 +39,8 @@
      */
     protected abstract Image getImage();
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    protected boolean doMatch(final Object item) {
+    public boolean matches(final Object item) {
         if (item instanceof EditPart) {
             EditPart part = (EditPart) item;
             EditPartViewer viewer = part.getViewer();
@@ -50,7 +50,7 @@
                 final EditPart currentPart = entry.getValue();
                 final IFigure visual = entry.getKey();
                 if (currentPart.equals(part) && visual instanceof IDecoration) {
-                    return isTheRightDecoration(visual);
+                    return findFigureWithImage(visual, getImage());
                 }
 
             }
@@ -59,12 +59,21 @@
         return false;
     }
 
-    private boolean isTheRightDecoration(final IFigure item) {
-        final IFigure decoration = item;
-        if (!decoration.getChildren().isEmpty() && decoration.getChildren().get(0) instanceof ImageFigureEx) {
-            return ((ImageFigureEx) decoration.getChildren().get(0)).getImage().equals(getImage());
+    @SuppressWarnings("restriction")
+    private boolean findFigureWithImage(IFigure figure, Image image) {
+        if (figure instanceof ImageFigureEx) {
+            if (ImageEquality.areEqualImages(((ImageFigureEx) figure).getImage(), image)) {
+                return true;
+            }
         }
-        return false;
-    }
 
+        boolean imageFigureExFound = false;
+        Iterator<Figure> it = figure.getChildren().iterator();
+        while (it.hasNext() && !imageFigureExFound) {
+            Figure innerFigure = it.next();
+            imageFigureExFound = findFigureWithImage(innerFigure, image);
+        }
+
+        return imageFigureExFound;
+    }
 }
diff --git a/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/matcher/DeletedDecoratorMatcher.java b/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/matcher/DeletedDecoratorMatcher.java
similarity index 90%
rename from plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/matcher/DeletedDecoratorMatcher.java
rename to plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/matcher/DeletedDecoratorMatcher.java
index d8552ad..753a898 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/matcher/DeletedDecoratorMatcher.java
+++ b/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/matcher/DeletedDecoratorMatcher.java
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES
+ * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES
  * All rights reserved.   This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -8,7 +8,7 @@
  * Contributors:
  *      Obeo - Initial API and implementation
  */
-package org.eclipse.sirius.tests.swtbot.support.api.matcher;
+package org.eclipse.sirius.tests.support.api.matcher;
 
 import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin;
 import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath;
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/synchronization/UnsynchronizedMappingAndDeleteFromOutsideEditorTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/synchronization/UnsynchronizedMappingAndDeleteFromOutsideEditorTests.java
index 68dc047..c58fb8c 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/synchronization/UnsynchronizedMappingAndDeleteFromOutsideEditorTests.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/synchronization/UnsynchronizedMappingAndDeleteFromOutsideEditorTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -42,6 +42,7 @@
 import org.eclipse.sirius.tests.support.api.EclipseTestsSupportHelper;
 import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase;
 import org.eclipse.sirius.tests.support.api.TestsUtil;
+import org.eclipse.sirius.tests.support.api.matcher.DeletedDecoratorMatcher;
 import org.eclipse.sirius.tools.api.command.DCommand;
 import org.eclipse.sirius.ui.business.api.dialect.DialectEditor;
 import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
@@ -146,10 +147,15 @@
         // Check the number of diagram elements
         assertEquals("The diagram should not be modify because we are in manual refresh mode.", 5, diagram.getOwnedDiagramElements().size());
         // Check edit part for a DNode
-        assertFalse("The editMode of editPart which target the class C1InSubRoot must be disabled.", getEditPart(testedClass).isEditModeEnabled());
+        IGraphicalEditPart testedClassEditPart = getEditPart(testedClass);
+        assertFalse("The editMode of editPart which target the class C1InSubRoot must be disabled.", testedClassEditPart.isEditModeEnabled());
+        // Check edit part for a DNode is decorated with a red cross
+        assertTrue("No deleted decorator found on editPart which target the class C1InSubRoot", new DeletedDecoratorMatcher().matches(testedClassEditPart));
+        IGraphicalEditPart testedPackageEditPart = getEditPart(testedPackage);
         // Check edit part for a DContainer
-        assertFalse("The editMode of editPart which target the package p1InSubRoot must be disabled.", getEditPart(testedPackage).isEditModeEnabled());
-
+        assertFalse("The editMode of editPart which target the package p1InSubRoot must be disabled.", testedPackageEditPart.isEditModeEnabled());
+        // Check edit part for a DNode is decorated with a red cross
+        assertTrue("No deleted decorator found on editPart which target the package p1InSubRoot", new DeletedDecoratorMatcher().matches(testedPackageEditPart));
         // Launch a manual refresh and check again the number of diagram
         // elements
         refresh(diagram);
@@ -295,6 +301,7 @@
         // reloaded.
         if (Display.getCurrent() != null) {
             PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
+                @Override
                 public void run(IProgressMonitor monitor) throws InterruptedException {
                     Job.getJobManager().join(ResourceSyncClientNotifier.FAMILY, monitor);
                 }
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DeleteSemanticElementToCheckDecorator.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DeleteSemanticElementToCheckDecorator.java
deleted file mode 100644
index 820fb01..0000000
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DeleteSemanticElementToCheckDecorator.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *    Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.sirius.tests.swtbot;
-
-import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramNameEditPart;
-import org.eclipse.sirius.tests.swtbot.support.api.business.UIDiagramRepresentation;
-import org.eclipse.sirius.tests.swtbot.support.api.business.UILocalSession;
-import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource;
-import org.eclipse.sirius.tests.swtbot.support.api.condition.OpenedSessionCondition;
-import org.eclipse.sirius.tests.swtbot.support.api.matcher.AbstractDecoratorMatcher;
-import org.eclipse.sirius.tests.swtbot.support.api.matcher.DeletedDecoratorMatcher;
-import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
-
-/**
- * 
- * @author amartin
- */
-public class DeleteSemanticElementToCheckDecorator extends AbstractScenarioTestCase {
-
-    private static final String DATA_UNIT_DIR = "data/unit/deleteSemanticElement/";
-
-    private static final String FILE_DIR = "/";
-
-    private static AbstractDecoratorMatcher matcher = new DeletedDecoratorMatcher();
-
-    private static final String VIEWPOINT_NAME = "Design";
-
-    private static final String SESSION_FILE = "DeleteSemanticElement.aird";
-
-    private static final String MODEL = "DeleteSemanticElement.ecore";
-
-    private static final String REPRESENTATION_NAME_DIAGRAM = "Entities";
-
-    private static final String REPRESENTATION_INSTANCE_NAME_DIAGRAM = "RootPackage package entities";
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onSetUpBeforeClosingWelcomePage() throws Exception {
-        copyFileToTestProject(Activator.PLUGIN_ID, DATA_UNIT_DIR, MODEL, SESSION_FILE);
-    }
-
-    public void testDeleteSemanticElement() throws Exception {
-
-        final UIResource sessionAirdResource = new UIResource(designerProject, FILE_DIR, SESSION_FILE);
-
-        final UILocalSession localSession = designerPerspective.openSessionFromFile(sessionAirdResource);
-        bot.waitUntil(new OpenedSessionCondition(1));
-        final UIDiagramRepresentation diagram = localSession.getLocalSessionBrowser().perCategory().selectViewpoint(VIEWPOINT_NAME).selectRepresentation(REPRESENTATION_NAME_DIAGRAM)
-                .selectRepresentationInstance(REPRESENTATION_INSTANCE_NAME_DIAGRAM, UIDiagramRepresentation.class).open();
-
-        assertTrue("The element which are not deleted are decorated !", checkUntouchedElementAreNotDecorated(diagram));
-
-        assertNotNull("[Delete Semantic Element TestCase]:Error the diagram couldn't be opened!", diagram);
-
-        diagram.close();
-    }
-
-    private boolean CheckIfNodeIsDecoratedWithDeleted(UIDiagramRepresentation diagram, String nodeName) {
-        SWTBotGefEditPart checkedNodeEditPart = getRightEPForDecoration(diagram.getEditor().getEditPart(nodeName));
-        assertNotNull(checkedNodeEditPart);
-        assertFalse("no decorator found", matcher.matches(checkedNodeEditPart));
-        return true;
-    }
-
-    private boolean checkUntouchedElementAreNotDecorated(UIDiagramRepresentation diagram) {
-        CheckIfNodeIsDecoratedWithDeleted(diagram, "NOT_TOERASE_CONTAINER");
-        CheckIfNodeIsDecoratedWithDeleted(diagram, "NOT_TOERASE_CONTAINED");
-        CheckIfNodeIsDecoratedWithDeleted(diagram, "NOT_TOERASE");
-        return true;
-    }
-
-    private SWTBotGefEditPart getRightEPForDecoration(SWTBotGefEditPart editPart) {
-        SWTBotGefEditPart part = editPart;
-        if (part.part() instanceof IDiagramNameEditPart)
-            part = part.parent();
-        return part;
-    }
-
-}
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/ValidationTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/ValidationTest.java
index d764d8b..3d49b83 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/ValidationTest.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/ValidationTest.java
@@ -13,12 +13,12 @@
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.sirius.business.api.session.SessionManager;
 import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart;
+import org.eclipse.sirius.tests.support.api.matcher.AbstractDecoratorMatcher;
 import org.eclipse.sirius.tests.swtbot.support.api.business.UIDiagramRepresentation;
 import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource;
 import org.eclipse.sirius.tests.swtbot.support.api.business.UISessionCreationWizardFlow.SessionChoice;
 import org.eclipse.sirius.tests.swtbot.support.api.condition.CheckSelectedCondition;
 import org.eclipse.sirius.tests.swtbot.support.api.condition.OpenedSessionCondition;
-import org.eclipse.sirius.tests.swtbot.support.api.matcher.AbstractDecoratorMatcher;
 import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotCommonHelper;
 import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils;
 import org.eclipse.sirius.ui.business.api.preferences.SiriusUIPreferencesKeys;
@@ -118,8 +118,8 @@
         assertEquals(activeEditor.getReference(), editor.getReference());
         assertEquals("The wrong editor was opened", "ecore package entities", editor.getTitle());
         assertEquals("There should not be more than one open session.", 1, SessionManager.INSTANCE.getSessions().size());
-        assertEquals("The selection should be the element concerned by the marker", NEW_ECLASS_1, ((IDiagramElementEditPart) ((IStructuredSelection) editor.getSelection()).iterator().next())
-                .resolveDiagramElement().getName());
+        assertEquals("The selection should be the element concerned by the marker", NEW_ECLASS_1,
+                ((IDiagramElementEditPart) ((IStructuredSelection) editor.getSelection()).iterator().next()).resolveDiagramElement().getName());
 
         // Close the session and save it
         editor.close();
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
index 712cc57..58b42a3 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
@@ -191,7 +191,6 @@
         suite.addTestSuite(ExportDiagramAsImageWhenManyRepresentationsHaveSameNameTest.class);
         suite.addTestSuite(EdgeCreationTest.class);
         suite.addTestSuite(DragAndDropFromTableAndTreeToDiagramTest.class);
-        suite.addTestSuite(DeleteSemanticElementToCheckDecorator.class);
         suite.addTestSuite(DeleteFromDiagramTest.class);
         suite.addTestSuite(DeleteDiagramWithListeningPaletteToolTest.class);
         suite.addTestSuite(BoldItalicFontSynchronizationTest.class);