From 3d98d0203b66ab05bda7c24d2c032c83391023fd Mon Sep 17 00:00:00 2001 From: Camille Letavernier Date: Thu, 30 Jan 2014 14:30:51 +0100 Subject: 417178: [CSS] The CSS Engine shall support compartments (Show/Hide, collapse, show title...) https://bugs.eclipse.org/bugs/show_bug.cgi?id=417178 Add tests--- .../.project | 6 + .../META-INF/MANIFEST.MF | 3 +- ....eclipse.papyrus.infra.gmfdiag.css.tests.launch | 3 +- .../resources/model/compartmentsTest/model.di | 23 ++ .../model/compartmentsTest/model.notation | 254 +++++++++++++++++++++ .../resources/model/compartmentsTest/model.uml | 44 ++++ .../resources/stylesheets/compartments.css | 39 ++++ .../resources/stylesheets/labels.css | 0 .../infra/gmfdiag/css/tests/tests/AllTests.java | 4 +- .../css/tests/tests/CSSCompartmentsTests.java | 233 +++++++++++++++++++ 10 files changed, 605 insertions(+), 4 deletions(-) create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.di create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.notation create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.uml create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/compartments.css create mode 100644 tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/labels.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/CSSCompartmentsTests.java (limited to 'tests/junit') diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/.project b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/.project index ddbc718c56e..ff2463a3162 100644 --- a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/.project +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/.project @@ -5,6 +5,11 @@ + + org.eclipse.xtext.ui.shared.xtextBuilder + + + org.eclipse.jdt.core.javabuilder @@ -24,5 +29,6 @@ org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature + org.eclipse.xtext.ui.shared.xtextNature diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/META-INF/MANIFEST.MF index eb2be6b5fd3..481cbb8fc50 100644 --- a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/META-INF/MANIFEST.MF @@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.resources;bundle-version="3.8.0", org.eclipse.uml2.uml;bundle-version="4.0.0", org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.0.0", - org.junit;bundle-version="4.10.0" + org.junit;bundle-version="4.10.0", + org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0" Export-Package: org.eclipse.papyrus.infra.gmfdiag.css.tests, org.eclipse.papyrus.infra.gmfdiag.css.tests.tests Bundle-Vendor: Eclipse Modeling Project diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/org.eclipse.papyrus.infra.gmfdiag.css.tests.launch b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/org.eclipse.papyrus.infra.gmfdiag.css.tests.launch index 934fbbe559c..eb1de64a68e 100644 --- a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/org.eclipse.papyrus.infra.gmfdiag.css.tests.launch +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/org.eclipse.papyrus.infra.gmfdiag.css.tests.launch @@ -23,11 +23,12 @@ + - + diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.di b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.di new file mode 100644 index 00000000000..b38a75b62ee --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.di @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.notation b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.notation new file mode 100644 index 00000000000..6fa635f903c --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.notation @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.uml b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.uml new file mode 100644 index 00000000000..b356eaf5ce0 --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/model/compartmentsTest/model.uml @@ -0,0 +1,44 @@ + + + + Test model for CSS in Luna >= M5 (Compartments, Labels) + + + Expected: Attribute collapsed, Nested classifier hidden + + + Expected: Compartments hidden + + + Expected: Collapsed = false + + + Expected: Attribute and Operation visible + + + Expected: Compartment Attribute and Operation visible + + + Expected: Only operation compartment is visible + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/compartments.css b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/compartments.css new file mode 100644 index 00000000000..a07ea565036 --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/compartments.css @@ -0,0 +1,39 @@ +* { + showTitle: false; +} + +/* Check showTitle, to avoid priority conflicts with more specific rules */ +.showTitleForAllCompartments Compartment { + showTitle: true; +} + +Interface > Compartment[kind=attribute], +Interface > Compartment[kind=nestedClassifier] { + visible:false; +} + +Interface[ownedAttribute] > Compartment[kind=attribute]{ + visible:true; +} + +Compartment[kind=nestedClassifier] { + visible: false; +} + + +/* Collapse the Attribute compartment if the Class contains a P1 attribute (Displayed) */ +Class[ownedAttribute~="P1"] > Compartment[kind=attribute]{ + collapsed: true; +} + +Enumeration > Compartment { + collapsed: true; +} + +Enumeration > Compartment[kind=EnUmerAtionLiteRal]{ /* Case insensitive */ + collapsed: false; +} + +Compartment { + showTitle: true; +} diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/labels.css b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/resources/stylesheets/labels.css new file mode 100644 index 00000000000..e69de29bb2d 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 54ee115ce9a..185aab5136d 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,6 +1,6 @@ /***************************************************************************** * 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 @@ -17,7 +17,7 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ CSSClassProviderTest.class, CSSStylesheetTest.class +@SuiteClasses({ CSSClassProviderTest.class, CSSStylesheetTest.class, CSSCompartmentsTests.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/CSSCompartmentsTests.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSCompartmentsTests.java new file mode 100644 index 00000000000..c311a50ca4e --- /dev/null +++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.css.tests/src/org/eclipse/papyrus/infra/gmfdiag/css/tests/tests/CSSCompartmentsTests.java @@ -0,0 +1,233 @@ +/***************************************************************************** + * 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: + * 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.Collections; +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.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl; +import org.eclipse.gmf.runtime.notation.BasicCompartment; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.Shape; +import org.eclipse.gmf.runtime.notation.TitleStyle; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStringStyleObservableList; +import org.eclipse.papyrus.infra.gmfdiag.css.helper.CSSHelper; +import org.eclipse.papyrus.infra.gmfdiag.css.helper.ResetStyleHelper; +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; + +/** + * Test case for Compartment-related styles and properties + * See resources/model/compartmentsTest/model.di for details + * + * @author Camille Letavernier + * + */ +public class CSSCompartmentsTests { + + public static final String CLASS_ATTRIBUTE_COMPARTMENT_TYPE = "7017"; //$NON-NLS-1$ + + public static final String CLASS_OPERATION_COMPARTMENT_TYPE = "7018"; //$NON-NLS-1$ + + public static final String CLASS_CLASSIFIER_COMPARTMENT_TYPE = "7019"; //$NON-NLS-1$ + + public static final String INTERFACE_ATTRIBUTE_COMPARTMENT_TYPE = "7006"; //$NON-NLS-1$ + + public static final String INTERFACE_OPERATION_COMPARTMENT_TYPE = "7007"; //$NON-NLS-1$ + + public static final String INTERFACE_INTERFACEIFIER_COMPARTMENT_TYPE = "7008"; //$NON-NLS-1$ + + public static final String ENUMERATION_LITERAL_COMPARTMENT_TYPE = "7015"; //$NON-NLS-1$ + + private CSSDiagram diagram; + + @Before + public void init() { + ResourceSet resourceSet = new ResourceSetImpl(); + CSSHelper.installCSSSupport(resourceSet); + + URI uri = URI.createPlatformPluginURI(Activator.PLUGIN_ID + "/resources/model/compartmentsTest/model.notation", true); //$NON-NLS-1$ + 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 Class1 and Class2 */ + @Test + public void testAttributeCompartment() { + Shape class1 = findShape("Class1"); + Shape class2 = findShape("Class2"); + + BasicCompartment attributes1 = findCompartment(class1, CLASS_ATTRIBUTE_COMPARTMENT_TYPE); + Assert.assertTrue("Attribute compartment should be collapsed, as it contains a P1 property", attributes1.isCollapsed()); + Assert.assertTrue("Attribute compartment should be visible", attributes1.isVisible()); + BasicCompartment operations1 = findCompartment(class1, CLASS_OPERATION_COMPARTMENT_TYPE); + Assert.assertTrue("Operation compartment should be visible", operations1.isVisible()); + BasicCompartment classifiers1 = findCompartment(class1, CLASS_CLASSIFIER_COMPARTMENT_TYPE); + Assert.assertFalse("Classifiers compartment should be hidden", classifiers1.isVisible()); + + BasicCompartment attributes2 = findCompartment(class2, CLASS_ATTRIBUTE_COMPARTMENT_TYPE); + Assert.assertFalse("Attribute compartment should not be collapsed, as it doesn't contain a P1 property", attributes2.isCollapsed()); + Assert.assertTrue("Attribute compartment should be visible", attributes2.isVisible()); + BasicCompartment operations2 = findCompartment(class2, CLASS_OPERATION_COMPARTMENT_TYPE); + Assert.assertTrue("Operation compartment should be visible", operations2.isVisible()); + BasicCompartment classifiers2 = findCompartment(class2, CLASS_CLASSIFIER_COMPARTMENT_TYPE); + Assert.assertFalse("Classifiers compartment should be hidden", classifiers2.isVisible()); + + + } + + /* Test Enumeration1 */ + @Test + //Currently fails. The EnumerationLiteral compartment is not defined in the NotationTypesMap + public void testCaseInsensitiveForEnumeration() { + Shape enumeration = findShape("Enumeration1"); + BasicCompartment compartment = findCompartment(enumeration, ENUMERATION_LITERAL_COMPARTMENT_TYPE); + + Assert.assertFalse("EnumerationLiteral Compartment should not be collapsed", compartment.isCollapsed()); + } + + /* Test Interface 1 and Interface 2 */ + //Currently fails. The interface compartments are not defined in the NotationTypesMap + @Test + public void testAttributeCompartmentForInterface() { + Shape interface1 = findShape("Interface1"); + Shape interface2 = findShape("Interface2"); + + BasicCompartment attributes1 = findCompartment(interface1, INTERFACE_ATTRIBUTE_COMPARTMENT_TYPE); + Assert.assertTrue("Attribute compartment should be visible, as it contains a Property", attributes1.isVisible()); + BasicCompartment operations1 = findCompartment(interface1, INTERFACE_OPERATION_COMPARTMENT_TYPE); + Assert.assertTrue("Operation compartment should be visible", operations1.isVisible()); + BasicCompartment classifiers1 = findCompartment(interface1, INTERFACE_INTERFACEIFIER_COMPARTMENT_TYPE); + Assert.assertFalse("Classifiers compartment should be hidden", classifiers1.isVisible()); + + BasicCompartment attributes2 = findCompartment(interface2, INTERFACE_ATTRIBUTE_COMPARTMENT_TYPE); + Assert.assertFalse("Attribute compartment should not be visible, as it doesn't contain any property", attributes2.isVisible()); + BasicCompartment operations2 = findCompartment(interface2, INTERFACE_OPERATION_COMPARTMENT_TYPE); + Assert.assertTrue("Operation compartment should be visible", operations2.isVisible()); + BasicCompartment classifiers2 = findCompartment(interface2, INTERFACE_INTERFACEIFIER_COMPARTMENT_TYPE); + Assert.assertFalse("Classifiers compartment should be hidden", classifiers2.isVisible()); + } + + /* Test Class 3 */ + @Test + public void testCompartmentForceValue() { + //Test initial situation + Shape class3 = findShape("Class3"); + + //Check all compartments + for(View childNode : (List)class3.getChildren()) { + if(childNode instanceof BasicCompartment) { + Assert.assertFalse("All compartments from Class3 should be hidden", childNode.isVisible()); + } + } + + //We need an editingDomain for the ResetStyle operation + new TransactionalEditingDomainImpl(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE), diagram.eResource().getResourceSet()); + + //Test resetStyle + ResetStyleHelper.resetStyle(Collections.singleton(class3)); + //Check only some specific compartments. Some style rules still hide the nestedClassifier compartment. The visibility of e.g. the ShapeCompartment is undetermined. + BasicCompartment attributesCompartment = findCompartment(class3, CLASS_ATTRIBUTE_COMPARTMENT_TYPE); + BasicCompartment operationsCompartment = findCompartment(class3, CLASS_OPERATION_COMPARTMENT_TYPE); + + Assert.assertTrue("Attributes compartment should be visible after the reset style", attributesCompartment.isVisible()); + Assert.assertTrue("Operations compartment should be visible after the reset style", operationsCompartment.isVisible()); + } + + /* Test apply style */ + @Test + //Currently fails. showTitle is not properly supported for BasicCompartments + //Unlike Compartment, BasicCompartment doesn't implement TitleStyle. Instead, + //it owns a specific instance of TitleStyle, which is not supported by the CSS Engine (?) + public void testShowAllCompartmentsTitles() { + //Initial state: title should be hidden + for(View childNode : (List)diagram.getChildren()) { + for(View compartment : (List)childNode.getChildren()) { + if(compartment instanceof BasicCompartment) { + TitleStyle titleStyle = (TitleStyle)compartment.getStyle(NotationPackage.eINSTANCE.getTitleStyle()); + Assert.assertFalse("Title should be hidden", titleStyle.isShowTitle()); + } + } + } + + //Apply style + CustomStringStyleObservableList stylesList = new CustomStringStyleObservableList(diagram, null, "cssClass"); + stylesList.add("showTitleForAllCompartments"); + + //Check that all titles are visible + for(View childNode : (List)diagram.getChildren()) { + for(View compartment : (List)childNode.getChildren()) { + if(compartment instanceof BasicCompartment) { + TitleStyle titleStyle = (TitleStyle)compartment.getStyle(NotationPackage.eINSTANCE.getTitleStyle()); + Assert.assertTrue("Title should be visible", titleStyle.isShowTitle()); + } + } + } + } + + + @After + public void dispose() { + Iterator iterator = diagram.eResource().getResourceSet().getResources().iterator(); + while(iterator.hasNext()) { + iterator.next().unload(); + iterator.remove(); + } + } + + private BasicCompartment findCompartment(Shape element, String type) { + for(View childNode : (List)element.getChildren()) { + if(type.equals(childNode.getType())) { + return (BasicCompartment)childNode; + } + } + + return null; + } + + 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; + } + +} -- cgit v1.2.3