Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-10-23 14:52:14 +0000
committerCamille Letavernier2014-10-23 15:04:44 +0000
commitfb77eb1a047622852720c386c33400b27ad35aca (patch)
tree27a3d8f3c4fb7a9ea6892910edca9bf7529dae54
parentf7c3d9f2a2ed45c584dee56e17ba0dd558fdeba9 (diff)
downloadorg.eclipse.papyrus-fb77eb1a047622852720c386c33400b27ad35aca.tar.gz
org.eclipse.papyrus-fb77eb1a047622852720c386c33400b27ad35aca.tar.xz
org.eclipse.papyrus-fb77eb1a047622852720c386c33400b27ad35aca.zip
448385: [XText Editors] Embedded editors must be tested
https://bugs.eclipse.org/bugs/show_bug.cgi?id=448385 - Add default value test for Ports and Properties
-rw-r--r--plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.xtext.ui/src/org/eclipse/papyrus/uml/textedit/port/xtext/ui/contribution/UMLPortEditorPropertyUtil.java10
-rw-r--r--plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.xtext.ui/src/org/eclipse/papyrus/uml/textedit/property/xtext/ui/contributions/UMLPropertyEditorPropertyUtil.java10
-rw-r--r--tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.tests/src/org/eclipse/papyrus/uml/textedit/port/tests/suites/PortGrammarTests.java16
-rw-r--r--tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.tests/src/org/eclipse/papyrus/uml/textedit/property/tests/suites/PropertyGrammarTests.java16
4 files changed, 46 insertions, 6 deletions
diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.xtext.ui/src/org/eclipse/papyrus/uml/textedit/port/xtext/ui/contribution/UMLPortEditorPropertyUtil.java b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.xtext.ui/src/org/eclipse/papyrus/uml/textedit/port/xtext/ui/contribution/UMLPortEditorPropertyUtil.java
index c2c8ec22991..a21274d1c91 100644
--- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.xtext.ui/src/org/eclipse/papyrus/uml/textedit/port/xtext/ui/contribution/UMLPortEditorPropertyUtil.java
+++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.xtext.ui/src/org/eclipse/papyrus/uml/textedit/port/xtext/ui/contribution/UMLPortEditorPropertyUtil.java
@@ -57,10 +57,14 @@ public class UMLPortEditorPropertyUtil extends PortUtil {
if (!multiplicity.trim().equals("[1]")) {
buffer.append(multiplicity);
}
+ buffer.append(" ");
// property modifiers
- buffer.append(" ");
- buffer.append(PropertyUtil.getModifiersAsString(port, false));
+ String modifiers = PropertyUtil.getModifiersAsString(port, false);
+ if (!"".equals(modifiers)) {
+ buffer.append(modifiers);
+ buffer.append(" ");
+ }
// default value
if (port.getDefaultValue() != null) {
@@ -98,7 +102,7 @@ public class UMLPortEditorPropertyUtil extends PortUtil {
}.doSwitch(port.getDefaultValue());
if (defaultValue != null) {
- buffer.append(" = ");
+ buffer.append("= ");
buffer.append(defaultValue);
}
}
diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.xtext.ui/src/org/eclipse/papyrus/uml/textedit/property/xtext/ui/contributions/UMLPropertyEditorPropertyUtil.java b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.xtext.ui/src/org/eclipse/papyrus/uml/textedit/property/xtext/ui/contributions/UMLPropertyEditorPropertyUtil.java
index 427c2b953c1..313c7b1689f 100644
--- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.xtext.ui/src/org/eclipse/papyrus/uml/textedit/property/xtext/ui/contributions/UMLPropertyEditorPropertyUtil.java
+++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.xtext.ui/src/org/eclipse/papyrus/uml/textedit/property/xtext/ui/contributions/UMLPropertyEditorPropertyUtil.java
@@ -51,14 +51,18 @@ public class UMLPropertyEditorPropertyUtil extends PropertyUtil {
if (!multiplicity.trim().equals("[1]")) {
buffer.append(multiplicity);
}
+ buffer.append(" ");
// property modifiers
- buffer.append(" ");
- buffer.append(PropertyUtil.getModifiersAsString(property, false));
+ String modifiers = PropertyUtil.getModifiersAsString(property, false);
+ if (!"".equals(modifiers)) {
+ buffer.append(modifiers);
+ buffer.append(" ");
+ }
// default value
if (property.getDefault() != null) {
- buffer.append(" = ");
+ buffer.append("= ");
String defaultValue = new UMLSwitch<String>() {
@Override
public String caseLiteralBoolean(org.eclipse.uml2.uml.LiteralBoolean object) {
diff --git a/tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.tests/src/org/eclipse/papyrus/uml/textedit/port/tests/suites/PortGrammarTests.java b/tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.tests/src/org/eclipse/papyrus/uml/textedit/port/tests/suites/PortGrammarTests.java
index 254b27caf46..e0a45488452 100644
--- a/tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.tests/src/org/eclipse/papyrus/uml/textedit/port/tests/suites/PortGrammarTests.java
+++ b/tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.port.tests/src/org/eclipse/papyrus/uml/textedit/port/tests/suites/PortGrammarTests.java
@@ -18,9 +18,11 @@ import org.eclipse.papyrus.uml.textedit.tests.AbstractGrammarTest;
import org.eclipse.papyrus.uml.xtext.integration.DefaultXtextDirectEditorConfiguration;
import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.LiteralReal;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.PrimitiveType;
+import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.VisibilityKind;
import org.junit.Assert;
@@ -79,6 +81,20 @@ public class PortGrammarTests extends AbstractGrammarTest<Port> {
Assert.assertEquals("# /p1 : ~model::type1", tester.getInitialText(testedPort));
}
+ @Test
+ public void testDefaultValues() throws Exception {
+ testedPort.setIsUnique(false);
+
+ LiteralReal defaultRealValue = UMLFactory.eINSTANCE.createLiteralReal();
+ defaultRealValue.setValue(123.54);
+ testedPort.setDefaultValue(defaultRealValue);
+
+ Assert.assertEquals("+ p1 : <Undefined> = 123.54", tester.getInitialText(testedPort));
+ tester.parseText(testedPort, "p1 = .2");
+ Assert.assertEquals("The instance of ValueSpecification should not change when compatible types are used", defaultRealValue, testedPort.getDefaultValue());
+ Assert.assertEquals(.2, defaultRealValue.getValue(), 0.001);
+ }
+
@Override
public DefaultXtextDirectEditorConfiguration getEditor() {
return new PortXtextDirectEditorConfiguration();
diff --git a/tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.tests/src/org/eclipse/papyrus/uml/textedit/property/tests/suites/PropertyGrammarTests.java b/tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.tests/src/org/eclipse/papyrus/uml/textedit/property/tests/suites/PropertyGrammarTests.java
index ea72e9664d1..7d4138b980d 100644
--- a/tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.tests/src/org/eclipse/papyrus/uml/textedit/property/tests/suites/PropertyGrammarTests.java
+++ b/tests/junit/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.property.tests/src/org/eclipse/papyrus/uml/textedit/property/tests/suites/PropertyGrammarTests.java
@@ -17,9 +17,11 @@ import org.eclipse.papyrus.uml.textedit.tests.AbstractGrammarTest;
import org.eclipse.papyrus.uml.xtext.integration.DefaultXtextDirectEditorConfiguration;
import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.LiteralReal;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.PrimitiveType;
import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.VisibilityKind;
import org.junit.Assert;
@@ -72,6 +74,20 @@ public class PropertyGrammarTests extends AbstractGrammarTest<Property> {
Assert.assertEquals("# /p1 : model::type1", tester.getInitialText(testedProperty));
}
+ @Test
+ public void testDefaultValues() throws Exception {
+ testedProperty.setIsUnique(false);
+
+ LiteralReal defaultRealValue = UMLFactory.eINSTANCE.createLiteralReal();
+ defaultRealValue.setValue(123.54);
+ testedProperty.setDefaultValue(defaultRealValue);
+
+ Assert.assertEquals("+ p1 : <Undefined> = 123.54", tester.getInitialText(testedProperty));
+ tester.parseText(testedProperty, "p1 = .2");
+ Assert.assertEquals("The instance of ValueSpecification should not change when compatible types are used", defaultRealValue, testedProperty.getDefaultValue());
+ Assert.assertEquals(.2, defaultRealValue.getValue(), 0.001);
+ }
+
@Override
public DefaultXtextDirectEditorConfiguration getEditor() {
return new PropertyXtextDirectEditorConfiguration();

Back to the top