Skip to content

Commit

Permalink
[27] Add tests to validate that the attribute value can be changed
Browse files Browse the repository at this point in the history
Bug: #27
  • Loading branch information
vrichard12 authored and sbegaudeau committed Jan 10, 2024
1 parent 628cf0e commit fb873b6
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,45 @@ public void setValue(EObject object, EStructuralFeature feature, Object value) {
this.testLoad("TestChangeAttributeTypeMulti.xmi"); //$NON-NLS-1$
}

/**
* Change the value of a monovalued EAttribute.
*/
@Test
public void testChangeAttributeValueMono() {
JsonHelper jsonHelper = new JsonHelper() {
@Override
public void setValue(EObject object, EStructuralFeature feature, Object value) {
Object newValue = value;
if ("NodeSingleValueAttribute".equals(feature.getEContainingClass().getName()) && "singleStringAttribute".equals(feature.getName())) { //$NON-NLS-1$ //$NON-NLS-2$
newValue = ((String) value).toUpperCase();
}
super.setValue(object, feature, newValue);
}

};

this.options.put(JsonResource.OPTION_CUSTOM_HELPER, jsonHelper);
this.testLoad("TestChangeAttributeValueMono.xmi"); //$NON-NLS-1$
}

/**
* Change the value of a multivalued EAttribute.
*/
@Test
public void testChangeAttributeValueMulti() {
JsonHelper jsonHelper = new JsonHelper() {
@Override
public void setValue(EObject object, EStructuralFeature feature, Object value) {
Object newValue = value;
if ("NodeMultiValuedAttribute".equals(feature.getEContainingClass().getName()) && "multiStringAttribute".equals(feature.getName())) { //$NON-NLS-1$ //$NON-NLS-2$
newValue = ((String) value).toUpperCase();
}
super.setValue(object, feature, newValue);
}
};

this.options.put(JsonResource.OPTION_CUSTOM_HELPER, jsonHelper);
this.testLoad("TestChangeAttributeValueMulti.xmi"); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"json": {
"version": "1.0",
"encoding": "utf-8"
},
"ns": {
"emfjson": "http://obeo.fr/emfjson",
"nodes": "http://www.obeo.fr/EMFJson"
},
"schemaLocation": {
"http://www.obeo.fr/EMFJson": "../../../nodes.ecore"
},
"content": [
{
"eClass": "nodes:NodeSingleValueAttribute",
"data": {
"singleStringAttribute": "singleStringAttribute value"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ASCII"?>
<nodes:NodeSingleValueAttribute
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:nodes="http://www.obeo.fr/EMFJson"
xsi:schemaLocation="http://www.obeo.fr/EMFJson ../../../nodes.ecore"
singleStringAttribute="SINGLESTRINGATTRIBUTE VALUE"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"json": {
"version": "1.0",
"encoding": "utf-8"
},
"ns": {
"emfjson": "http://obeo.fr/emfjson",
"nodes": "http://www.obeo.fr/EMFJson"
},
"schemaLocation": {
"http://www.obeo.fr/EMFJson": "../../../nodes.ecore"
},
"content": [
{
"eClass": "nodes:NodeMultiValuedAttribute",
"data": {
"multiStringAttribute": [
"abc",
"abcdef",
"abcdefghi"
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="ASCII"?>
<nodes:NodeMultiValuedAttribute
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:nodes="http://www.obeo.fr/EMFJson"
xsi:schemaLocation="http://www.obeo.fr/EMFJson ../../../nodes.ecore">
<multiStringAttribute>ABC</multiStringAttribute>
<multiStringAttribute>ABCDEF</multiStringAttribute>
<multiStringAttribute>ABCDEFGHI</multiStringAttribute>
</nodes:NodeMultiValuedAttribute>

0 comments on commit fb873b6

Please sign in to comment.