-
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.
[26] Add support for renaming attributes
Bug: #26
- Loading branch information
1 parent
c11d1e9
commit 59af680
Showing
6 changed files
with
151 additions
and
1 deletion.
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
83 changes: 83 additions & 0 deletions
83
...n/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataLoadTests.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,83 @@ | ||
/******************************************************************************* | ||
* 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.EClass; | ||
import org.eclipse.emf.ecore.EStructuralFeature; | ||
import org.eclipse.emf.ecore.util.BasicExtendedMetaData; | ||
import org.eclipse.emf.ecore.util.ExtendedMetaData; | ||
import org.eclipse.sirius.emfjson.resource.JsonResource; | ||
import org.eclipse.sirius.emfjson.tests.internal.AbstractEMFJsonTests; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests loading with ExtendedMetaData. | ||
*/ | ||
public class ExtendedMetaDataLoadTests 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 name of a monovalued EAttribute. | ||
*/ | ||
@Test | ||
public void testChangeAttributeNameMono() { | ||
ExtendedMetaData metaData = new BasicExtendedMetaData() { | ||
@Override | ||
public EStructuralFeature getElement(EClass eClass, String namespace, String name) { | ||
if ("NodeSingleValueAttribute".equals(eClass.getName()) && "singleStringAttributeOld".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$ | ||
return eClass.getEStructuralFeature("singleStringAttribute"); //$NON-NLS-1$ | ||
} | ||
return super.getElement(eClass, namespace, name); | ||
} | ||
|
||
}; | ||
this.options.put(JsonResource.OPTION_EXTENDED_META_DATA, metaData); | ||
this.testLoad("TestChangeAttributeNameMono.xmi"); //$NON-NLS-1$ | ||
} | ||
|
||
/** | ||
* Change the name of a multivalued EAttribute. | ||
*/ | ||
@Test | ||
public void testChangeAttributeNameMulti() { | ||
// CHECKSTYLE:OFF | ||
ExtendedMetaData metaData = new BasicExtendedMetaData() { | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.eclipse.emf.ecore.util.BasicExtendedMetaData#getElement(org.eclipse.emf.ecore.EClass, | ||
* java.lang.String, java.lang.String) | ||
*/ | ||
@Override | ||
public EStructuralFeature getElement(EClass eClass, String namespace, String name) { | ||
if ("NodeMultiValuedAttribute".equals(eClass.getName()) && "multiStringAttributeOld".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$ | ||
return eClass.getEStructuralFeature("multiStringAttribute"); //$NON-NLS-1$ | ||
} | ||
return super.getElement(eClass, namespace, name); | ||
} | ||
|
||
}; | ||
// CHECKSTYLE:ON | ||
this.options.put(JsonResource.OPTION_EXTENDED_META_DATA, metaData); | ||
this.testLoad("TestChangeAttributeNameMulti.xmi"); //$NON-NLS-1$ | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...ests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMono.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": { | ||
"singleStringAttributeOld": "singleStringAttribute value" | ||
} | ||
} | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
...tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMono.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" | ||
singleStringAttribute="singleStringAttribute value"/> |
25 changes: 25 additions & 0 deletions
25
...sts/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMulti.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": { | ||
"multiStringAttributeOld": [ | ||
"multiStringAttribute value 1", | ||
"multiStringAttribute value 2", | ||
"multiStringAttribute value 3" | ||
] | ||
} | ||
} | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
...ests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMulti.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"> | ||
<multiStringAttribute>multiStringAttribute value 1</multiStringAttribute> | ||
<multiStringAttribute>multiStringAttribute value 2</multiStringAttribute> | ||
<multiStringAttribute>multiStringAttribute value 3</multiStringAttribute> | ||
</nodes:NodeMultiValuedAttribute> |