From 46c70c648d754b6b768acaed9e5a53bee4d19e88 Mon Sep 17 00:00:00 2001 From: Gabriel Pascual Date: Wed, 21 May 2014 15:17:36 +0200 Subject: 435394: [CSS] Unit tests shall be created for project stylesheets feature. https://bugs.eclipse.org/bugs/show_bug.cgi?id=435394 - Add unit tests for project stylesheets preference - Fix managing of exceptions for that JUnit does it Change-Id: I8b35c91179d676d7a3437b0b407ae33864d613c9 Signed-off-by: Gabriel Pascual --- .../model/projectStylesheetsTest/model.di | 17 ++ .../model/projectStylesheetsTest/model.notation | 287 +++++++++++++++++++++ .../model/projectStylesheetsTest/model.uml | 18 ++ .../stylesheets/projectStylesheetsTest.css | 19 ++ .../infra/gmfdiag/css/tests/tests/AllTests.java | 46 ++-- .../css/tests/tests/CSSProjectStylesheetsTest.java | 174 +++++++++++++ 6 files changed, 538 insertions(+), 23 deletions(-) create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.di create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.notation create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.uml create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/projectStylesheetsTest.css create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSProjectStylesheetsTest.java diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.di b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.di new file mode 100644 index 00000000000..a8838c28bdd --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.di @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.notation b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.notation new file mode 100644 index 00000000000..933eb6ad99b --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.notation @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + myInterface + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + myClass + myOtherClass + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + myClass + + + + + + + + + + + + + + + + + + + + + + + + + + myClass + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.uml b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.uml new file mode 100644 index 00000000000..e8fa769a5e1 --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/projectStylesheetsTest/model.uml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/projectStylesheetsTest.css b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/projectStylesheetsTest.css new file mode 100644 index 00000000000..f387124dfeb --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/projectStylesheetsTest.css @@ -0,0 +1,19 @@ +/***************************************************************************** + * Copyright (c) 2014 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: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net + *****************************************************************************/ + +ClassDiagram Package { + lineColor:yellow; + lineWidth:4; + +} + + 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 index 38d5847383e..c92f3ef628f 100644 --- 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 @@ -1,23 +1,23 @@ -/***************************************************************************** - * 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, CSSModelStylesheetTest.class, CSSCompartmentsTests.class, CSSSupportTest.class }) -public class AllTests { - //Test suite -} +/***************************************************************************** + * 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, CSSModelStylesheetTest.class, CSSCompartmentsTests.class, CSSSupportTest.class, CSSProjectStylesheetsTest.class }) +public class AllTests { + //Test suite +} diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSProjectStylesheetsTest.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSProjectStylesheetsTest.java new file mode 100644 index 00000000000..370765ed60d --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSProjectStylesheetsTest.java @@ -0,0 +1,174 @@ +/***************************************************************************** + * Copyright (c) 2014 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: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.gmfdiag.css.tests.tests; + +import java.net.URL; +import java.util.Collections; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +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.Shape; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.gmfdiag.css.engine.ProjectCSSEngine; +import org.eclipse.papyrus.infra.gmfdiag.css.engine.WorkspaceCSSEngine; +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.preferences.ThemePreferences; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference; +import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsFactory; +import org.eclipse.papyrus.infra.gmfdiag.css.tests.Activator; +import org.eclipse.papyrus.junit.utils.FilesUtils; +import org.eclipse.papyrus.junit.utils.ProjectUtils; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * Test class for Stylesheets project. + * + * @author Gabriel Pascual + * + */ +public class CSSProjectStylesheetsTest extends AbstractCSSStylesheetTest { + + /** Used project to get project CSS engine. */ + private static IProject project = null; + + @BeforeClass + public static void initCSSTheme() throws Exception { + + IPreferenceStore cssThemePreferences = org.eclipse.papyrus.infra.gmfdiag.css.Activator.getDefault().getPreferenceStore(); + cssThemePreferences.setValue(ThemePreferences.CURRENT_THEME, "org.eclipse.papyrus.css.papyrus_theme"); + WorkspaceCSSEngine.instance.reset(); + + testEnvironmentInitialisation(); + + + } + + + + /** + * To test style sheets preference of a project, it is necessary to create environment in runtime workspace. + */ + private static void testEnvironmentInitialisation() throws Exception { + + //Create URI of Papyrus project elements + URI notationFileURI = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/model/projectStylesheetsTest/model.notation", true); + URI diFileURI = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/model/projectStylesheetsTest/model.di", true); + URI umlFileURI = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/model/projectStylesheetsTest/model.uml", true); + + // Create URI of CSS files + URI classProviderCSSFileURI = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/stylesheets/classProviderTest.css", true); + URI comparmentCSSFileURI = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/stylesheets/compartments.css", true); + URI labelCSSFileURI = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/stylesheets/labels.css", true); + URI modelStylesheetsCSSFileURI = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/stylesheets/ModelStylesheetTest.css", true); + URI projectStylesheetsCSSFileURI = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/stylesheets/projectStylesheetsTest.css", true); + URI stylsheetFileURI = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/stylesheets/stylesheetTest.css", true); + + + + // Create first project which contains Papyrus elements + project = ProjectUtils.createProject("projectStylesheetsTest"); + FilesUtils.copyFiles(project, "model.notation", new URL(notationFileURI.toString())); + FilesUtils.copyFiles(project, "model.di", new URL(diFileURI.toString())); + FilesUtils.copyFiles(project, "model.uml", new URL(umlFileURI.toString())); + + // Create second project that contains CSS files + IProject cssProject = ProjectUtils.createProject("stylesheets"); + FilesUtils.copyFiles(cssProject, "classProviderTest.css", new URL(classProviderCSSFileURI.toString())); + FilesUtils.copyFiles(cssProject, "compartments.css", new URL(comparmentCSSFileURI.toString())); + FilesUtils.copyFiles(cssProject, "labels.css", new URL(labelCSSFileURI.toString())); + FilesUtils.copyFiles(cssProject, "ModelStylesheetTest.css", new URL(modelStylesheetsCSSFileURI.toString())); + FilesUtils.copyFiles(cssProject, "projectStylesheetsTest.css", new URL(projectStylesheetsCSSFileURI.toString())); + FilesUtils.copyFiles(cssProject, "stylesheetTest.css", new URL(stylsheetFileURI.toString())); + + + + createStylesheetsProjectPreference(); + } + + + + /** + * Add a Stylesheets project preference. + */ + private static void createStylesheetsProjectPreference() throws Exception { + IPath preferencePath = new ProjectScope(project).getLocation().append(ProjectCSSEngine.PROJECT_STYLESHEETS); + + // Verify presence of file in project + IPath projectRelativePath = preferencePath.makeRelativeTo(project.getLocation()); + IFile preferenceFile = project.getFile(projectRelativePath); + //Create default preference file + ResourceSet resourceSet = new ResourceSetImpl(); + Resource preferenceResource = resourceSet.createResource(URI.createPlatformResourceURI(preferenceFile.getFullPath().toOSString(), true)); + + StyleSheetReference stylesheetReference = StylesheetsFactory.eINSTANCE.createStyleSheetReference(); + stylesheetReference.setPath("/stylesheets/projectStylesheetsTest.css"); + preferenceResource.getContents().add(stylesheetReference); + + + preferenceResource.save(Collections.EMPTY_MAP); + + } + + + @AfterClass + public static void cleanWorkspace() throws Exception { + if(project != null) { + project.refreshLocal(IProject.DEPTH_INFINITE, new NullProgressMonitor()); + project.delete(true, true, new NullProgressMonitor()); + } + } + + @Before + public void init() throws Exception { + + ResourceSet resourceSet = houseKeeper.createResourceSet(); + CSSHelper.installCSSSupport(resourceSet); + + + IFile file = project.getFile("model.notation"); + Diagram diagram = (Diagram)EMFHelper.loadEMFModel(resourceSet, URI.createPlatformResourceURI(file.getFullPath().toOSString(), true)); + Assert.assertNotNull("Cannot find the model", diagram); + Assert.assertTrue("CSS are not activated on this resource", diagram instanceof CSSDiagram); + this.diagram = (CSSDiagram)diagram; + + + + } + + /** + * Test of style sheets project preference on model with no priority conflict. + */ + @Test + public void testProjectStylesheets() { + + Shape componentView = findShape("Package1"); + + //Stylesheets project preference apply yellow line color and line width of 4 + Assert.assertEquals("Invalid line color", rgb(255, 255, 0), componentView.getLineColor()); + Assert.assertEquals("Invalid color", 4, componentView.getLineWidth()); + } +} -- cgit v1.2.3