Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-11-24 12:49:41 +0000
committervincent lorenzo2016-11-29 11:01:26 +0000
commit3ed639ecef256da3eeff86d3b428720561f362df (patch)
treeea5d0d552c2e0b62cd9ee3cafd907ee69c0ad2e8 /tests/junit
parentb3141df23ca644573f8b2813ad8859722d418bd9 (diff)
downloadorg.eclipse.papyrus-3ed639ecef256da3eeff86d3b428720561f362df.tar.gz
org.eclipse.papyrus-3ed639ecef256da3eeff86d3b428720561f362df.tar.xz
org.eclipse.papyrus-3ed639ecef256da3eeff86d3b428720561f362df.zip
Bug 496905: [Diagram][ModelExplorer][Table][Dialog] Papyrus must integrate
the internationalization feature provided by UML. https://bugs.eclipse.org/bugs/show_bug.cgi?id=496905 Commit of UML for internationalization. Change-Id: Ia61e5ef4d537f9e9b192bcfe073f921542fe4876 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'tests/junit')
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/GMFUnsafeTest.java441
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/canonical/TestStaticFeatureRepresentation.java238
2 files changed, 341 insertions, 338 deletions
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/GMFUnsafeTest.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/GMFUnsafeTest.java
index c6516300371..917eddc6a80 100644
--- a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/GMFUnsafeTest.java
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/GMFUnsafeTest.java
@@ -1,220 +1,221 @@
-/*
- * Copyright (c) 2014 CEA and others.
- *
- * 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:
- * Christian W. Damus (CEA) - Initial API and implementation
- *
- */
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Collections;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.command.AbstractCommand;
-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.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.papyrus.infra.core.resource.TransactionalEditingDomainManager;
-import org.eclipse.papyrus.infra.emf.gmf.util.GMFUnsafe;
-import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.Model;
-import org.eclipse.uml2.uml.Property;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestName;
-
-import junit.framework.AssertionFailedError;
-
-
-/**
- * Test suite for the {@link GMFUnsafe} class.
- */
-public class GMFUnsafeTest extends AbstractPapyrusTest {
-
- @Rule
- public final TestName testName = new TestName();
-
- private TransactionalEditingDomain domain;
-
- private Model model;
-
- private Class classA;
-
- private boolean doIt;
-
- @Test
- public void testWrite_runnable() throws Exception {
- if (doIt()) {
- GMFUnsafe.write(domain, new Runnable() {
-
- public void run() {
- createAttribute();
- }
- });
- }
- }
-
- @Test
- public void testWrite_command() throws Exception {
- if (doIt()) {
- GMFUnsafe.write(domain, new AbstractCommand() {
-
- public void redo() {
- createAttribute();
- }
-
- public void execute() {
- createAttribute();
- }
- });
- }
- }
-
- @Test
- public void testWrite_gmfCommand() throws Exception {
- if (doIt()) {
- GMFUnsafe.write(domain, new AbstractTransactionalCommand(domain, "Test", Collections.emptyList()) {
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- createAttribute();
- return CommandResult.newOKCommandResult();
- }
- });
- }
- }
-
- @Test
- public void testWrap() throws Exception {
- if (doIt()) {
- GMFUnsafe.wrap(domain, new AbstractCommand() {
-
- public void redo() {
- createAttribute();
- }
-
- public void execute() {
- createAttribute();
- }
- }).execute();
- }
- }
-
- //
- // Test framework
- //
-
- @Before
- public void createFixture() throws Exception {
- ResourceSet rset = new ResourceSetImpl();
- domain = TransactionalEditingDomainManager.createTransactionalEditingDomain(rset);
-
- // This will be treated by the editing domain as a read-only resource (except that we run unprotected transactions)
- Resource res = rset.createResource(URI.createURI("bogus://test/model.uml"));
-
- InputStream input = getClass().getResourceAsStream("model.uml");
- try {
- res.load(input, null);
- } finally {
- input.close();
- }
-
- model = (Model) res.getContents().get(0);
- classA = (Class) model.getOwnedType("A");
- }
-
- @After
- public void destroyFixture() {
- ResourceSet rset = domain.getResourceSet();
-
- for (Resource next : rset.getResources()) {
- next.unload();
- next.eAdapters().clear();
- }
- rset.getResources().clear();
- rset.eAdapters().clear();
-
- domain.dispose();
-
- model = null;
- classA = null;
- }
-
- Property createAttribute() {
- return classA.createOwnedAttribute("related", classA);
- }
-
- void assertProperty() {
- Property related = classA.getOwnedAttribute("related", classA);
- assertThat(related, notNullValue());
- }
-
- boolean doIt() {
- if (!doIt) {
- try {
- domain.runExclusive(new Runnable() {
-
- public void run() {
- try {
- GMFUnsafe.write(domain, new Runnable() {
-
- public void run() {
- doIt = true;
-
- try {
- // Reflectively re-invoke the test method. This will result in it execution of its body because
- // the re-entrant call to doIt() will return true this time
- try {
- Object test = GMFUnsafeTest.this;
- Method method = test.getClass().getDeclaredMethod(testName.getMethodName());
- method.invoke(test);
- } catch (Exception e) {
- if ((e instanceof InvocationTargetException) && (((InvocationTargetException) e).getTargetException() instanceof AssertionFailedError)) {
- throw (AssertionFailedError) ((InvocationTargetException) e).getTargetException();
- }
- e.printStackTrace();
- fail("Reflective invocation of test failed: " + e.getLocalizedMessage());
- }
- } finally {
- doIt = false;
- }
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- fail("Unsafe write failed: " + e.getLocalizedMessage());
- }
-
- assertProperty();
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- fail("Read transaction failed: " + e.getLocalizedMessage());
- }
- }
-
- return doIt;
- }
-}
+/*
+ * Copyright (c) 2014 CEA and others.
+ *
+ * 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:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905
+ *
+ */
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.AbstractCommand;
+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.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.infra.core.resource.TransactionalEditingDomainManager;
+import org.eclipse.papyrus.infra.emf.gmf.util.GMFUnsafe;
+import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Property;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+import junit.framework.AssertionFailedError;
+
+
+/**
+ * Test suite for the {@link GMFUnsafe} class.
+ */
+public class GMFUnsafeTest extends AbstractPapyrusTest {
+
+ @Rule
+ public final TestName testName = new TestName();
+
+ private TransactionalEditingDomain domain;
+
+ private Model model;
+
+ private Class classA;
+
+ private boolean doIt;
+
+ @Test
+ public void testWrite_runnable() throws Exception {
+ if (doIt()) {
+ GMFUnsafe.write(domain, new Runnable() {
+
+ public void run() {
+ createAttribute();
+ }
+ });
+ }
+ }
+
+ @Test
+ public void testWrite_command() throws Exception {
+ if (doIt()) {
+ GMFUnsafe.write(domain, new AbstractCommand() {
+
+ public void redo() {
+ createAttribute();
+ }
+
+ public void execute() {
+ createAttribute();
+ }
+ });
+ }
+ }
+
+ @Test
+ public void testWrite_gmfCommand() throws Exception {
+ if (doIt()) {
+ GMFUnsafe.write(domain, new AbstractTransactionalCommand(domain, "Test", Collections.emptyList()) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ createAttribute();
+ return CommandResult.newOKCommandResult();
+ }
+ });
+ }
+ }
+
+ @Test
+ public void testWrap() throws Exception {
+ if (doIt()) {
+ GMFUnsafe.wrap(domain, new AbstractCommand() {
+
+ public void redo() {
+ createAttribute();
+ }
+
+ public void execute() {
+ createAttribute();
+ }
+ }).execute();
+ }
+ }
+
+ //
+ // Test framework
+ //
+
+ @Before
+ public void createFixture() throws Exception {
+ ResourceSet rset = new ResourceSetImpl();
+ domain = TransactionalEditingDomainManager.createTransactionalEditingDomain(rset);
+
+ // This will be treated by the editing domain as a read-only resource (except that we run unprotected transactions)
+ Resource res = rset.createResource(URI.createURI("bogus://test/model.uml"));
+
+ InputStream input = getClass().getResourceAsStream("model.uml");
+ try {
+ res.load(input, null);
+ } finally {
+ input.close();
+ }
+
+ model = (Model) res.getContents().get(0);
+ classA = (Class) model.getOwnedType("A");
+ }
+
+ @After
+ public void destroyFixture() {
+ ResourceSet rset = domain.getResourceSet();
+
+ for (Resource next : rset.getResources()) {
+ next.unload();
+ next.eAdapters().clear();
+ }
+ rset.getResources().clear();
+ rset.eAdapters().clear();
+
+ domain.dispose();
+
+ model = null;
+ classA = null;
+ }
+
+ Property createAttribute() {
+ return classA.createOwnedAttribute("related", classA);
+ }
+
+ void assertProperty() {
+ Property related = classA.getOwnedAttribute("related", classA);
+ assertThat(related, notNullValue());
+ }
+
+ boolean doIt() {
+ if (!doIt) {
+ try {
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+ try {
+ GMFUnsafe.write(domain, new Runnable() {
+
+ public void run() {
+ doIt = true;
+
+ try {
+ // Reflectively re-invoke the test method. This will result in it execution of its body because
+ // the re-entrant call to doIt() will return true this time
+ try {
+ Object test = GMFUnsafeTest.this;
+ Method method = test.getClass().getDeclaredMethod(testName.getMethodName());
+ method.invoke(test);
+ } catch (Exception e) {
+ if ((e instanceof InvocationTargetException) && (((InvocationTargetException) e).getTargetException() instanceof AssertionFailedError)) {
+ throw (AssertionFailedError) ((InvocationTargetException) e).getTargetException();
+ }
+ e.printStackTrace();
+ fail("Reflective invocation of test failed: " + e.getLocalizedMessage());
+ }
+ } finally {
+ doIt = false;
+ }
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Unsafe write failed: " + e.getLocalizedMessage());
+ }
+
+ assertProperty();
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Read transaction failed: " + e.getLocalizedMessage());
+ }
+ }
+
+ return doIt;
+ }
+} \ No newline at end of file
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/canonical/TestStaticFeatureRepresentation.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/canonical/TestStaticFeatureRepresentation.java
index 588101b9801..6cd665a07f7 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/canonical/TestStaticFeatureRepresentation.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/canonical/TestStaticFeatureRepresentation.java
@@ -1,118 +1,120 @@
-/*****************************************************************************
- * Copyright (c) 2013, 2015 CEA LIST, Christian W. Damus, and others.
- *
- *
- * 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:
- * Nizar GUEDIDI (CEA LIST) - Initial API and implementation
- * Christian W. Damus - bug 473183
- /*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.clazz.test.canonical;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.eclipse.draw2d.text.FlowPage;
-import org.eclipse.emf.edit.command.SetCommand;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
-import org.eclipse.gmf.runtime.draw2d.ui.text.TextFlowEx;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.updater.DiagramUpdater;
-import org.eclipse.papyrus.commands.ICreationCommand;
-import org.eclipse.papyrus.infra.emf.gmf.command.EMFtoGMFCommandWrapper;
-import org.eclipse.papyrus.uml.diagram.clazz.CreateClassDiagramCommand;
-import org.eclipse.papyrus.uml.diagram.clazz.custom.edit.part.CustomUMLDiagramUpdater;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassAttributeCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassOperationCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes;
-import org.eclipse.papyrus.uml.diagram.clazz.test.IClassDiagramTestsConstants;
-import org.eclipse.papyrus.uml.diagram.common.editparts.UMLCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.tests.canonical.StateNotShareable;
-import org.eclipse.papyrus.uml.diagram.tests.canonical.TestChildLabel;
-import org.eclipse.uml2.uml.Feature;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.junit.Test;
-
-/**
- * this class is used to test if feature are a representation for static
- *
- */
-@StateNotShareable
-public class TestStaticFeatureRepresentation extends TestChildLabel {
-
- @Override
- public DiagramUpdater getDiagramUpdater() {
- return CustomUMLDiagramUpdater.INSTANCE;
- }
-
- @Override
- protected ICreationCommand getDiagramCommandCreation() {
- return new CreateClassDiagramCommand();
- }
-
- @Override
- protected String getProjectName() {
- return IClassDiagramTestsConstants.PROJECT_NAME;
- }
-
- @Override
- protected String getFileName() {
- return IClassDiagramTestsConstants.FILE_NAME;
- }
-
- @Test
- public void testStaticOperation() {
- testToCreateATopNode(UMLElementTypes.Class_Shape);
- testToTestStaticoperation(UMLElementTypes.Operation_ClassOperationLabel, ClassOperationCompartmentEditPart.VISUAL_ID);
- }
-
- @Test
- public void testStaticProperty() {
- testToCreateATopNode(UMLElementTypes.Class_Shape);
- testToTestStaticoperation(UMLElementTypes.Property_ClassAttributeLabel, ClassAttributeCompartmentEditPart.VISUAL_ID);
- }
-
- protected void testToTestStaticoperation(IElementType type, String containerType) {
- ListCompartmentEditPart compartment = null;
- int index = 0;
- while (compartment == null && index < getTopEditPart().getChildren().size()) {
- if ((getTopEditPart().getChildren().get(index)) instanceof ListCompartmentEditPart && (((View) ((ListCompartmentEditPart) (getTopEditPart().getChildren().get(index))).getModel()).getType().equals(containerType))) {
- compartment = (ListCompartmentEditPart) (getTopEditPart().getChildren().get(index));
- }
- index++;
- }
- assertTrue("Container not found", compartment != null);
- // CREATION
- assertTrue(CREATION + INITIALIZATION_TEST, compartment.getChildren().size() == 0);
- assertTrue(CREATION + INITIALIZATION_TEST, getRootSemanticModel().getOwnedElements().size() == 0);
- CreateViewRequest requestcreation = CreateViewRequestFactory.getCreateShapeRequest(type, getDiagramEditPart().getDiagramPreferencesHint());
- Command command = compartment.getCommand(requestcreation);
- assertNotNull(CREATION + COMMAND_NULL, command);
- assertTrue(CREATION + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
- assertTrue("CREATION: " + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true);
- // creation of label
- diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
- assertTrue(CREATION + TEST_THE_EXECUTION, compartment.getChildren().size() == 1);
- assertTrue("ceated editpart is a feature editpart", ((compartment.getChildren().get(0)) instanceof UMLCompartmentEditPart));
- UMLCompartmentEditPart featureEditPart = (UMLCompartmentEditPart) compartment.getChildren().get(0);
- // make it static
- SetCommand setStaticOperation = new SetCommand(diagramEditor.getEditingDomain(), featureEditPart.resolveSemanticElement(), UMLPackage.eINSTANCE.getFeature_IsStatic(), true);
- diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(new EMFtoGMFCommandWrapper(setStaticOperation)));
- TextFlowEx label = (TextFlowEx) ((FlowPage) featureEditPart.getFigure().getChildren().get(0)).getChildren().get(0);
- featureEditPart.refresh();
- // the semantic element is static
- assertTrue("the feature is static", ((Feature) featureEditPart.resolveSemanticElement()).isStatic());
- // the graphical element is underlined
- assertTrue("the figigure is drawn as static", label.isTextUnderlined());
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013, 2015 CEA LIST, Christian W. Damus, and others.
+ *
+ *
+ * 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:
+ * Nizar GUEDIDI (CEA LIST) - Initial API and implementation
+ * Christian W. Damus - bug 473183
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905
+ /*****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.clazz.test.canonical;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.draw2d.text.FlowPage;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
+import org.eclipse.gmf.runtime.draw2d.ui.text.TextFlowEx;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.gmf.command.EMFtoGMFCommandWrapper;
+import org.eclipse.papyrus.infra.gmfdiag.common.updater.DiagramUpdater;
+import org.eclipse.papyrus.commands.ICreationCommand;
+import org.eclipse.papyrus.infra.emf.gmf.command.EMFtoGMFCommandWrapper;
+import org.eclipse.papyrus.uml.diagram.clazz.CreateClassDiagramCommand;
+import org.eclipse.papyrus.uml.diagram.clazz.custom.edit.part.CustomUMLDiagramUpdater;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassAttributeCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassOperationCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.clazz.test.IClassDiagramTestsConstants;
+import org.eclipse.papyrus.uml.diagram.common.editparts.UMLCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.tests.canonical.StateNotShareable;
+import org.eclipse.papyrus.uml.diagram.tests.canonical.TestChildLabel;
+import org.eclipse.uml2.uml.Feature;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.Test;
+
+/**
+ * this class is used to test if feature are a representation for static
+ *
+ */
+@StateNotShareable
+public class TestStaticFeatureRepresentation extends TestChildLabel {
+
+ @Override
+ public DiagramUpdater getDiagramUpdater() {
+ return CustomUMLDiagramUpdater.INSTANCE;
+ }
+
+ @Override
+ protected ICreationCommand getDiagramCommandCreation() {
+ return new CreateClassDiagramCommand();
+ }
+
+ @Override
+ protected String getProjectName() {
+ return IClassDiagramTestsConstants.PROJECT_NAME;
+ }
+
+ @Override
+ protected String getFileName() {
+ return IClassDiagramTestsConstants.FILE_NAME;
+ }
+
+ @Test
+ public void testStaticOperation() {
+ testToCreateATopNode(UMLElementTypes.Class_Shape);
+ testToTestStaticoperation(UMLElementTypes.Operation_ClassOperationLabel, ClassOperationCompartmentEditPart.VISUAL_ID);
+ }
+
+ @Test
+ public void testStaticProperty() {
+ testToCreateATopNode(UMLElementTypes.Class_Shape);
+ testToTestStaticoperation(UMLElementTypes.Property_ClassAttributeLabel, ClassAttributeCompartmentEditPart.VISUAL_ID);
+ }
+
+ protected void testToTestStaticoperation(IElementType type, String containerType) {
+ ListCompartmentEditPart compartment = null;
+ int index = 0;
+ while (compartment == null && index < getTopEditPart().getChildren().size()) {
+ if ((getTopEditPart().getChildren().get(index)) instanceof ListCompartmentEditPart && (((View) ((ListCompartmentEditPart) (getTopEditPart().getChildren().get(index))).getModel()).getType().equals(containerType))) {
+ compartment = (ListCompartmentEditPart) (getTopEditPart().getChildren().get(index));
+ }
+ index++;
+ }
+ assertTrue("Container not found", compartment != null);
+ // CREATION
+ assertTrue(CREATION + INITIALIZATION_TEST, compartment.getChildren().size() == 0);
+ assertTrue(CREATION + INITIALIZATION_TEST, getRootSemanticModel().getOwnedElements().size() == 0);
+ CreateViewRequest requestcreation = CreateViewRequestFactory.getCreateShapeRequest(type, getDiagramEditPart().getDiagramPreferencesHint());
+ Command command = compartment.getCommand(requestcreation);
+ assertNotNull(CREATION + COMMAND_NULL, command);
+ assertTrue(CREATION + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
+ assertTrue("CREATION: " + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true);
+ // creation of label
+ diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
+ assertTrue(CREATION + TEST_THE_EXECUTION, compartment.getChildren().size() == 1);
+ assertTrue("ceated editpart is a feature editpart", ((compartment.getChildren().get(0)) instanceof UMLCompartmentEditPart));
+ UMLCompartmentEditPart featureEditPart = (UMLCompartmentEditPart) compartment.getChildren().get(0);
+ // make it static
+ SetCommand setStaticOperation = new SetCommand(diagramEditor.getEditingDomain(), featureEditPart.resolveSemanticElement(), UMLPackage.eINSTANCE.getFeature_IsStatic(), true);
+ diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(new EMFtoGMFCommandWrapper(setStaticOperation)));
+ TextFlowEx label = (TextFlowEx) ((FlowPage) featureEditPart.getFigure().getChildren().get(0)).getChildren().get(0);
+ featureEditPart.refresh();
+ // the semantic element is static
+ assertTrue("the feature is static", ((Feature) featureEditPart.resolveSemanticElement()).isStatic());
+ // the graphical element is underlined
+ assertTrue("the figigure is drawn as static", label.isTextUnderlined());
+ }
+}

Back to the top