From e11bdfd26ac8e961300d014c288bc433207b2d13 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Fri, 3 Nov 2023 18:45:17 +0100 Subject: [PATCH] [test] Add tests for EReference name change mono and multi valued --- .../ExtendedMetaDataAttributesLoadTests.java | 77 +++++++++++++++++++ ... ExtendedMetaDataReferencesLoadTests.java} | 2 +- .../TestChangeReferenceNameMono.json | 27 +++++++ .../TestChangeReferenceNameMono.xmi | 12 +++ .../TestChangeReferenceNameMulti.json | 36 +++++++++ .../TestChangeReferenceNameMulti.xmi | 14 ++++ 6 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataAttributesLoadTests.java rename tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/{ExtendedMetaDataLoadTests.java => ExtendedMetaDataReferencesLoadTests.java} (97%) create mode 100644 tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMono.json create mode 100644 tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMono.xmi create mode 100644 tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMulti.json create mode 100644 tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMulti.xmi diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataAttributesLoadTests.java b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataAttributesLoadTests.java new file mode 100644 index 0000000..3273e0e --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataAttributesLoadTests.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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 ExtendedMetaDataAttributesLoadTests extends AbstractEMFJsonTests { + + /** + * {@inheritDoc} + * + * @see org.eclipse.sirius.emfjson.tests.internal.AbstractEMFJsonTests#getRootPath() + */ + @Override + protected String getRootPath() { + return "/unit/references/extendedmetadata/"; //$NON-NLS-1$ + } + + /** + * Change the name of a monovalued EReference. + */ + @Test + public void testChangeReferenceNameMono() { + ExtendedMetaData metaData = new BasicExtendedMetaData() { + @Override + public EStructuralFeature getElement(EClass eClass, String namespace, String name) { + if ("NodeSingleValueReference".equals(eClass.getName()) && "singleValuedReferenceOld".equals(name)) { + // $NON-NLS-1$ //$NON-NLS-2$ + return eClass.getEStructuralFeature("singleValuedReference"); //$NON-NLS-1$ + } + // return super.getElement(eClass, namespace, name); // Doesn't work + return eClass.getEStructuralFeature(name); + } + }; + + this.options.put(JsonResource.OPTION_EXTENDED_META_DATA, metaData); + this.testLoad("TestChangeReferenceNameMono.xmi"); //$NON-NLS-1$ + } + + /** + * Change the name of a multivalued EReference. + */ + @Test + public void testChangeReferenceNameMulti() { + ExtendedMetaData metaData = new BasicExtendedMetaData() { + @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); // Doesn't work + return eClass.getEStructuralFeature(name); + } + }; + + this.options.put(JsonResource.OPTION_EXTENDED_META_DATA, metaData); + this.testLoad("TestChangeReferenceNameMulti.xmi"); //$NON-NLS-1$ + } + +} diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataLoadTests.java b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataReferencesLoadTests.java similarity index 97% rename from tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataLoadTests.java rename to tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataReferencesLoadTests.java index 720730d..8372ea5 100644 --- a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataLoadTests.java +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataReferencesLoadTests.java @@ -21,7 +21,7 @@ /** * Tests loading with ExtendedMetaData. */ -public class ExtendedMetaDataLoadTests extends AbstractEMFJsonTests { +public class ExtendedMetaDataReferencesLoadTests extends AbstractEMFJsonTests { /** * {@inheritDoc} diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMono.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMono.json new file mode 100644 index 0000000..8c1b129 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMono.json @@ -0,0 +1,27 @@ +{ + "json": { + "version": "1.0", + "encoding": "utf-8" + }, + "ns": { + "nodes": "http://www.obeo.fr/EMFJson" + }, + "schemaLocation": { + "http://www.obeo.fr/EMFJson": "../../../nodes.ecore" + }, + "content": [ + { + "eClass": "nodes:NodeSingleValueReference", + "data": { + "name": "Node1", + "singleValuedReferenceOld": "Node2" + } + }, + { + "eClass": "nodes:NodeSingleValueReference", + "data": { + "name": "Node2" + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMono.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMono.xmi new file mode 100644 index 0000000..e31affa --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMono.xmi @@ -0,0 +1,12 @@ + + + + + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMulti.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMulti.json new file mode 100644 index 0000000..9579c94 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMulti.json @@ -0,0 +1,36 @@ +{ + "json": { + "version": "1.0", + "encoding": "utf-8" + }, + "ns": { + "nodes": "http://www.obeo.fr/EMFJson" + }, + "schemaLocation": { + "http://www.obeo.fr/EMFJson": "../../../nodes.ecore" + }, + "content": [ + { + "eClass": "nodes:NodeMultiValuedReference", + "data": { + "name": "Node1", + "multiValuedReference": [ + "Node2", + "Node3" + ] + } + }, + { + "eClass": "nodes:NodeMultiValuedReference", + "data": { + "name": "Node2" + } + }, + { + "eClass": "nodes:NodeMultiValuedReference", + "data": { + "name": "Node3" + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMulti.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMulti.xmi new file mode 100644 index 0000000..54c458f --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/references/extendedmetadata/TestChangeReferenceNameMulti.xmi @@ -0,0 +1,14 @@ + + + + + +