Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-01-30 10:02:54 +0000
committerCamille Letavernier2014-01-30 10:02:54 +0000
commitbe67bc8bcf1bf5fb870e17af7506dbf405b62885 (patch)
tree5e513555949ca453be8014748bbb95bfb07836c2 /tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag
parenta4609aa0fd9800739c5111f15e33d6fe034ff8de (diff)
downloadorg.eclipse.papyrus-be67bc8bcf1bf5fb870e17af7506dbf405b62885.tar.gz
org.eclipse.papyrus-be67bc8bcf1bf5fb870e17af7506dbf405b62885.tar.xz
org.eclipse.papyrus-be67bc8bcf1bf5fb870e17af7506dbf405b62885.zip
424315: [Releng - CSS] The Papyrus CSS Feature should be included as a
main component in Papyrus https://bugs.eclipse.org/bugs/show_bug.cgi?id=424315 Add the CSS Tests to Papyrus/Main tests
Diffstat (limited to 'tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag')
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/Activator.java69
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/AllTests.java25
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSClassProviderTest.java98
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSStylesheetTest.java177
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSSupportTest.java77
5 files changed, 446 insertions, 0 deletions
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/Activator.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/Activator.java
new file mode 100644
index 00000000000..5994b38d491
--- /dev/null
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/Activator.java
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.tests;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.gmfdiag.css.tests"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/AllTests.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/AllTests.java
new file mode 100644
index 00000000000..54ee115ce9a
--- /dev/null
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/AllTests.java
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.tests.tests;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+
+@RunWith(Suite.class)
+@SuiteClasses({ CSSClassProviderTest.class, CSSStylesheetTest.class
+
+})
+public class AllTests {
+
+}
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSClassProviderTest.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSClassProviderTest.java
new file mode 100644
index 00000000000..a6946632989
--- /dev/null
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSClassProviderTest.java
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.tests.tests;
+
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.engine.ExtendedCSSEngine;
+import org.eclipse.papyrus.infra.gmfdiag.css.helper.CSSHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSDiagram;
+import org.eclipse.papyrus.infra.gmfdiag.css.provider.CSSClassContentProvider;
+import org.eclipse.papyrus.infra.gmfdiag.css.tests.Activator;
+import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class CSSClassProviderTest {
+
+ private CSSDiagram diagram;
+
+ private static int expectedNumberOfClasses = 17;
+
+ @Before
+ public void init() {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ CSSHelper.installCSSSupport(resourceSet);
+
+ URI uri = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/model/classProviderTest/model.notation", true);
+ try {
+ Diagram diagram = (Diagram)EMFHelper.loadEMFModel(resourceSet, uri);
+ Assert.assertNotNull("Cannot find the model", diagram);
+ Assert.assertTrue("CSS are not activated on this resource", diagram instanceof CSSDiagram);
+ this.diagram = (CSSDiagram)diagram;
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ }
+ }
+
+ @Test
+ public void testCSSClassContentProvider() {
+ ExtendedCSSEngine engine = diagram.getEngine();
+ IStaticContentProvider provider = new CSSClassContentProvider("Interface", engine);
+ Object[] result = provider.getElements();
+ List<Object> resultList = Arrays.asList(result);
+
+ //Result is expected to contain c01 to c17
+ //Result should not contain x01 to x13
+ //Result may contain anything else (Depending on the current Workspace Theme).
+
+ //Check that all expected classes are returned
+ for(int i = 1; i <= expectedNumberOfClasses; i++) {
+ String expectedClassName = "c";
+ if(i < 10) {
+ expectedClassName += "0";
+ }
+ expectedClassName += i;
+ Assert.assertTrue("An expected CSS Class has not been found: " + expectedClassName, resultList.contains(expectedClassName));
+ }
+
+ //Check that no invalid class is returned
+ for(Object object : resultList) {
+ Assert.assertTrue("The CSSClassContentProvider must return Strings", object instanceof String);
+ String cssClass = (String)object;
+
+ Assert.assertFalse("Invalid CSS Class has been returned: " + cssClass, cssClass.matches("x[0-9]+"));
+ }
+ }
+
+ @After
+ public void dispose() {
+ Iterator<Resource> iterator = diagram.eResource().getResourceSet().getResources().iterator();
+ while(iterator.hasNext()) {
+ iterator.next().unload();
+ iterator.remove();
+ }
+ }
+}
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSStylesheetTest.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSStylesheetTest.java
new file mode 100644
index 00000000000..0c1efe15355
--- /dev/null
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSStylesheetTest.java
@@ -0,0 +1,177 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.tests.tests;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.GradientStyle;
+import org.eclipse.gmf.runtime.notation.Shape;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.appearance.helper.AppearanceHelper;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.helper.CSSHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSDiagram;
+import org.eclipse.papyrus.infra.gmfdiag.css.tests.Activator;
+import org.eclipse.uml2.uml.NamedElement;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class CSSStylesheetTest {
+
+ private CSSDiagram diagram;
+
+ @Before
+ public void init() {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ CSSHelper.installCSSSupport(resourceSet);
+
+ URI uri = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/model/stylesheetTest/model.notation", true);
+ try {
+ Diagram diagram = (Diagram)EMFHelper.loadEMFModel(resourceSet, uri);
+ Assert.assertNotNull("Cannot find the model", diagram);
+ Assert.assertTrue("CSS are not activated on this resource", diagram instanceof CSSDiagram);
+ this.diagram = (CSSDiagram)diagram;
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ }
+ }
+
+ @Test
+ public void testClassStyle() {
+ Shape classView = findShape("Class1");
+ if(classView == null) {
+ return;
+ }
+
+ Assert.assertEquals("Invalid color", rgb(255, 0, 0), classView.getFillColor()); //Red = #FF0000
+ Assert.assertNull("Invalid gradient", classView.getGradient());
+ Assert.assertTrue(AppearanceHelper.showElementIcon(classView));
+ }
+
+ @Test
+ public void testInterfaceStyle() {
+ Shape interfaceView = findShape("Interface1");
+
+ Assert.assertNotNull(interfaceView.getGradient());
+ Assert.assertEquals(rgb(255, 255, 0), interfaceView.getFillColor()); //Yellow = #FFFF00
+ Assert.assertEquals(rgb(255, 0, 0), interfaceView.getGradient().getGradientColor1()); //Red = #FF0000
+ Assert.assertEquals(GradientStyle.VERTICAL, interfaceView.getGradient().getGradientStyle());
+ Assert.assertTrue(AppearanceHelper.showElementIcon(interfaceView));
+ }
+
+ @Test
+ public void testCSSClassStyle() {
+ Shape interfaceView = findShape("Interface2");
+ Assert.assertNotNull(interfaceView.getGradient());
+ Assert.assertEquals(rgb(144, 238, 144), interfaceView.getFillColor()); //Lightgreen = #90EE90
+
+ //Case insensitive color name
+ Assert.assertEquals(rgb(0, 191, 255), interfaceView.getGradient().getGradientColor1()); //DeepSkyBlue = #00BFFF
+
+ Assert.assertEquals(GradientStyle.HORIZONTAL, interfaceView.getGradient().getGradientStyle());
+ Assert.assertFalse(AppearanceHelper.showElementIcon(interfaceView));
+
+ //TODO: Font names should be case-insensitive
+ Assert.assertEquals("KaiTi", interfaceView.getFontName());
+ }
+
+ @Test
+ public void testPackage() {
+ Shape packageView = findShape("Package1");
+ Assert.assertNotNull(packageView.getGradient());
+
+ //Inherited style (From *)
+ Assert.assertEquals(rgb(255, 0, 0), packageView.getGradient().getGradientColor1()); //Red = #FF0000
+ }
+
+ @Test
+ public void testPriorities() {
+ //Tests the priorities between styles:
+ //.myClass : Low priority
+ //.myClass.myOtherClass : Highest priority
+ //[isAbstract=true] : Medium priority
+ //Styles should also be merged when they aren't conflicting (ie. [isAbstract] + .myClass -> fontName = Tunga)
+ Shape class3 = findShape("Class3");
+ Shape class5 = findShape("Class5");
+
+ testBlueStyle(class3); //isAbstract
+ testBlueStyle(class5); //isAbstract
+
+ Shape class4 = findShape("Class4");
+
+ testWhiteStyle(class4); //.myClass.myOtherClass (Overrides isAbstract)
+ testFontName(class4); //.myClass (Doesn't conflict with isAbstract)
+
+ Shape class6 = findShape("Class6");
+
+ testWhiteStyle(class6); //.myClass
+ testFontName(class6); //.myClass
+
+ Shape class7 = findShape("Class7");
+
+ testBlueStyle(class7); //isAbstract
+ testFontName(class7); //.myClass (Doesn't conflict with isAbstract)
+ }
+
+ private void testBlueStyle(Shape shape) {
+ Assert.assertEquals(rgb(195, 205, 255), shape.getFillColor()); //rgb syntax
+ Assert.assertTrue(shape.isBold());
+ Assert.assertNotNull(shape.getGradient());
+ }
+
+ private void testWhiteStyle(Shape shape) {
+ Assert.assertEquals(rgb(255, 255, 255), shape.getFillColor()); //White = #FFFFFF (Hexa syntax)
+ Assert.assertFalse(shape.isBold());
+ Assert.assertNull(shape.getGradient());
+ }
+
+ private void testFontName(Shape shape) {
+ Assert.assertEquals("Tunga", shape.getFontName());
+ }
+
+ @After
+ public void dispose() {
+ Iterator<Resource> iterator = diagram.eResource().getResourceSet().getResources().iterator();
+ while(iterator.hasNext()) {
+ iterator.next().unload();
+ iterator.remove();
+ }
+ }
+
+ private int rgb(int red, int green, int blue) {
+ return red | green << 8 | blue << 16;
+ }
+
+ private Shape findShape(String elementName) {
+ for(Object viewObject : diagram.getChildren()) {
+ View view = (View)viewObject;
+ if(view instanceof Shape && view.getElement() instanceof NamedElement) {
+ NamedElement element = (NamedElement)view.getElement();
+ if(elementName.equals(element.getName())) {
+ return (Shape)view;
+ }
+ }
+ }
+
+ Assert.fail("Cannot find the view associated to " + elementName);
+ return null;
+ }
+}
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSSupportTest.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSSupportTest.java
new file mode 100644
index 00000000000..c0fb3f6647a
--- /dev/null
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSSupportTest.java
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.tests.tests;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.helper.CSSHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSDiagram;
+import org.eclipse.papyrus.infra.gmfdiag.css.tests.Activator;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test the installation of CSS Support on a standard ResourceSet
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class CSSSupportTest {
+
+ /**
+ * Installs the CSS support on a resource set and check the results
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCSSSupport() throws Exception {
+ //Resource set with CSS Support installed
+ ResourceSet resourceSetWithCSSSupport = new ResourceSetImpl();
+ CSSHelper.installCSSSupport(resourceSetWithCSSSupport);
+
+ URI uri = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/model/stylesheetTest/model.notation", true);
+
+ Diagram diagram = (Diagram)EMFHelper.loadEMFModel(resourceSetWithCSSSupport, uri);
+
+ //The diagram should be a CSSDiagram
+ Assert.assertTrue(diagram instanceof CSSDiagram);
+
+ CSSDiagram cssDiagram = (CSSDiagram)diagram;
+
+ //The CSSDiagram should have a CSSEngine
+ Assert.assertNotNull(cssDiagram.getEngine());
+
+ //Dispose the CSS Engine
+ resourceSetWithCSSSupport.getResources().remove(diagram.eResource());
+ }
+
+ /**
+ * Tests a standard resource set (without CSS support) and check the results.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testWithoutCSSSupport() throws Exception {
+ //Standard resource set (Without CSS Support installed)
+ ResourceSet resourceSetWithoutCSSSupport = new ResourceSetImpl();
+
+ URI uri = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/model/stylesheetTest/model.notation", true);
+
+ Diagram diagram = (Diagram)EMFHelper.loadEMFModel(resourceSetWithoutCSSSupport, uri);
+
+ //The diagram should be a standard GMF Diagram (i.e. not a CSSDiagram)
+ Assert.assertFalse(diagram instanceof CSSDiagram);
+ }
+}

Back to the top