-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[28] Add support for changing attributes type
Bug: #28
- Loading branch information
1 parent
25da059
commit cdbf855
Showing
8 changed files
with
179 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ain/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/JsonHelperDataLoadTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* 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: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.emfjson.tests.internal.unit.load; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.EStructuralFeature; | ||
import org.eclipse.sirius.emfjson.resource.JsonResource; | ||
import org.eclipse.sirius.emfjson.tests.internal.AbstractEMFJsonTests; | ||
import org.eclipse.sirius.emfjson.utils.JsonHelper; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests loading with ExtendedMetaData. | ||
*/ | ||
public class JsonHelperDataLoadTests extends AbstractEMFJsonTests { | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.eclipse.sirius.emfjson.tests.internal.AbstractEMFJsonTests#getRootPath() | ||
*/ | ||
@Override | ||
protected String getRootPath() { | ||
return "/unit/attributes/extendedmetadata/"; //$NON-NLS-1$ | ||
} | ||
|
||
/** | ||
* Change the type of a monovalued EAttribute. | ||
*/ | ||
@Test | ||
public void testChangeAttributeTypeMono() { | ||
JsonHelper jsonHelper = new JsonHelper() { | ||
@Override | ||
public void setValue(EObject object, EStructuralFeature feature, Object value) { | ||
Object newValue = value; | ||
if ("NodeSingleValueAttribute".equals(feature.getEContainingClass().getName()) && "singleIntAttribute".equals(feature.getName())) { //$NON-NLS-1$ //$NON-NLS-2$ | ||
newValue = new Integer(((String) value).length()); | ||
} | ||
super.setValue(object, feature, newValue); | ||
} | ||
}; | ||
|
||
this.options.put(JsonResource.OPTION_CUSTOM_HELPER, jsonHelper); | ||
this.testLoad("TestChangeAttributeTypeMono.xmi"); //$NON-NLS-1$ | ||
} | ||
|
||
/** | ||
* Change the type of a monovalued EAttribute. | ||
*/ | ||
@Test | ||
public void testChangeAttributeTypeMulti() { | ||
JsonHelper jsonHelper = new JsonHelper() { | ||
@Override | ||
public void setValue(EObject object, EStructuralFeature feature, Object value) { | ||
Object newValue = value; | ||
if ("NodeMultiValuedAttribute".equals(feature.getEContainingClass().getName()) && "multiIntAttribute".equals(feature.getName())) { //$NON-NLS-1$ //$NON-NLS-2$ | ||
newValue = new Integer(((String) value).length()); | ||
} | ||
super.setValue(object, feature, newValue); | ||
} | ||
}; | ||
|
||
this.options.put(JsonResource.OPTION_CUSTOM_HELPER, jsonHelper); | ||
this.testLoad("TestChangeAttributeTypeMulti.xmi"); //$NON-NLS-1$ | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...ests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMono.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
"singleIntAttribute": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
} | ||
} | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
...tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMono.xmi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
singleIntAttribute="26"/> |
25 changes: 25 additions & 0 deletions
25
...sts/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMulti.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
"multiIntAttribute": [ | ||
"ABC", | ||
"ABCDEF", | ||
"ABCDEFGHI" | ||
] | ||
} | ||
} | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
...ests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMulti.xmi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> | ||
<multiIntAttribute>3</multiIntAttribute> | ||
<multiIntAttribute>6</multiIntAttribute> | ||
<multiIntAttribute>9</multiIntAttribute> | ||
</nodes:NodeMultiValuedAttribute> |