diff --git a/bundles/org.eclipse.sirius.emfjson/META-INF/MANIFEST.MF b/bundles/org.eclipse.sirius.emfjson/META-INF/MANIFEST.MF index e3e768b..ddc22de 100644 --- a/bundles/org.eclipse.sirius.emfjson/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.sirius.emfjson/META-INF/MANIFEST.MF @@ -20,4 +20,3 @@ Import-Package: javax.xml.bind;version="0.0.0", org.eclipse.emf.ecore.resource.impl;version="0.0.0", org.eclipse.emf.ecore.util;version="0.0.0" Automatic-Module-Name: org.eclipse.sirius.emfjson -Require-Bundle: javax.xml.bind;bundle-version="2.2.0" diff --git a/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/resource/JsonResource.java b/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/resource/JsonResource.java index 440b071..89057c1 100644 --- a/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/resource/JsonResource.java +++ b/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/resource/JsonResource.java @@ -16,6 +16,7 @@ import java.io.InputStream; import java.io.OutputStream; +import java.util.Comparator; import java.util.Map; import org.eclipse.emf.common.util.URI; @@ -418,6 +419,12 @@ interface IEObjectHandler { */ String OPTION_ID_MANAGER = "OPTION_ID_MANAGER"; //$NON-NLS-1$ + /** + * An option to provide a {@link Comparator} of {@link EStructuralFeature} to determine the order of the attributes + * in the serialized Json. + */ + Object OPTION_SAVE_FEATURES_ORDER_COMPARATOR = "OPTION_SAVE_FEATURES_ORDER_COMPARATOR"; //$NON-NLS-1$ + /** * Associate an ID to the {@link EObject}. * diff --git a/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/GsonEObjectDeserializer.java b/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/GsonEObjectDeserializer.java index f702431..a7fc860 100644 --- a/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/GsonEObjectDeserializer.java +++ b/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/GsonEObjectDeserializer.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.sirius.emfjson.utils; +import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; @@ -22,6 +23,7 @@ import java.io.IOException; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -38,6 +40,7 @@ import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EEnum; import org.eclipse.emf.ecore.EFactory; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; @@ -422,7 +425,9 @@ private void deserializeData(JsonObject properties, EClass eClass, EObject eObje if (properties != null) { Set> entrySet = properties.entrySet(); for (Entry entry : entrySet) { - EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(entry.getKey()); + EStructuralFeature eStructuralFeature = (this.extendedMetaData != null) ? // + this.extendedMetaData.getElement(eClass, eClass.getEPackage().getNsURI(), entry.getKey()) : // + eClass.getEStructuralFeature(entry.getKey()); if (eStructuralFeature instanceof EAttribute) { this.deserializeEAttribute((EAttribute) eStructuralFeature, entry.getValue(), eObject); @@ -884,23 +889,76 @@ private EObject loadEGenericType(JsonObject jsonObject) { private void deserializeEAttribute(EAttribute eAttribute, JsonElement jsonElement, EObject eObject) { EDataType dataType = eAttribute.getEAttributeType(); if (!eAttribute.isMany()) { - String newValue = this.getAsFlexibleString(jsonElement); - Object value = EcoreUtil.createFromString(dataType, newValue); + Object value = null; + if (this.isPojo(dataType)) { + value = new Gson().fromJson(jsonElement, eAttribute.getEType().getInstanceClass()); + } else { + String newValue = this.getAsFlexibleString(jsonElement); + value = this.tryCreateDataTypeFromString(dataType, newValue); + } this.helper.setValue(eObject, eAttribute, value); } else { JsonArray asJsonArray = this.getAsFlexibleArray(jsonElement); Object eGet = this.helper.getValue(eObject, eAttribute); if (eGet instanceof Collection) { for (JsonElement jElement : asJsonArray) { - Object value = EcoreUtil.createFromString(dataType, jElement.getAsString()); - @SuppressWarnings("unchecked") - Collection collection = (Collection) eGet; - collection.add(value); + Object value = null; + if (this.isPojo(dataType)) { + value = new Gson().fromJson(jElement, eAttribute.getEType().getInstanceClass()); + } else { + value = this.tryCreateDataTypeFromString(dataType, jElement.getAsString()); + } + this.helper.setValue(eObject, eAttribute, value); } } } } + /** + * List of the datatypes defined by the {@link EcorePackage}. + */ + private static final List ECORE_PACKAGE_DATA_TYPES = Arrays.asList(EcorePackage.eINSTANCE.getEString(), EcorePackage.eINSTANCE.getEBoolean(), EcorePackage.eINSTANCE.getEBooleanObject(), + EcorePackage.eINSTANCE.getEInt(), EcorePackage.eINSTANCE.getEIntegerObject(), EcorePackage.eINSTANCE.getEBigDecimal(), EcorePackage.eINSTANCE.getEBigInteger(), + EcorePackage.eINSTANCE.getEByte(), EcorePackage.eINSTANCE.getEByteArray(), EcorePackage.eINSTANCE.getEByteObject(), EcorePackage.eINSTANCE.getEChar(), + EcorePackage.eINSTANCE.getECharacterObject(), EcorePackage.eINSTANCE.getEDate(), EcorePackage.eINSTANCE.getEDouble(), EcorePackage.eINSTANCE.getEDoubleObject(), + EcorePackage.eINSTANCE.getEFloat(), EcorePackage.eINSTANCE.getEFloatObject(), EcorePackage.eINSTANCE.getELong(), EcorePackage.eINSTANCE.getELongObject(), + EcorePackage.eINSTANCE.getEShort(), EcorePackage.eINSTANCE.getEShortObject()); + + /** + * Tests if the given {@link EDataType} is a POJO. + * + * @param dataType + * A {@link EDataType} to test + * @return true if the given {@link EDataType} is not one of the {@link EcorePackage} DataTypes nor an + * {@link EEnum}. + */ + private boolean isPojo(EDataType dataType) { + return !ECORE_PACKAGE_DATA_TYPES.contains(dataType) && // + dataType.eClass() != EcorePackage.eINSTANCE.getEEnum() && // + dataType.getInstanceClass() != null; + } + + /** + * Try to create a {@link EDataType} instance from a serialized form of the value. If the serialization is not + * compatible with the given EDataType, returns the serialized form of the value unchanged. + * + * @param dataType + * The {@link EDataType} to instantiate + * @param serializedValue + * The serialized form of the value + * @return A new EDataType instance or the given serializedValue if the EDataType could not be instantiated from the + * serializedValue. + */ + private Object tryCreateDataTypeFromString(EDataType dataType, String serializedValue) { + Object value; + try { + value = EcoreUtil.createFromString(dataType, serializedValue); + } catch (IllegalArgumentException e) { + value = serializedValue; + } + return value; + } + /** * Read a JSON element as a string. If the element is a non-empty array, unwrap it and consider the first element * inside instead of trying to convert the array into a string. diff --git a/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/GsonEObjectSerializer.java b/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/GsonEObjectSerializer.java index 278a325..379040b 100644 --- a/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/GsonEObjectSerializer.java +++ b/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/GsonEObjectSerializer.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.sirius.emfjson.utils; +import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -24,12 +25,14 @@ import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.stream.Collectors; import javax.xml.bind.DatatypeConverter; @@ -863,10 +866,18 @@ private JsonElement createJsonHeader() { * The EObject to serialize * @return A JsonObject containing all the properties of the given object */ + @SuppressWarnings("unchecked") private JsonObject serializeEAllStructuralFeatures(EObject eObject) { JsonObject properties = new JsonObject(); EClass eClass = eObject.eClass(); - EList eAllStructuralFeatures = eClass.getEAllStructuralFeatures(); + List eAllStructuralFeatures = eClass.getEAllStructuralFeatures(); + + Object orderFeatures = this.options.get(JsonResource.OPTION_SAVE_FEATURES_ORDER_COMPARATOR); + if (orderFeatures instanceof Comparator) { + eAllStructuralFeatures = eAllStructuralFeatures.stream() // + .sorted((Comparator) orderFeatures) // + .collect(Collectors.toList()); + } for (EStructuralFeature eStructuralFeature : eAllStructuralFeatures) { if (this.shouldSerialize(eObject, eStructuralFeature)) { @@ -1017,22 +1028,31 @@ private JsonElement serializeEDataType(EObject eObject, EAttribute eAttribute) { Object value = this.helper.getValue(eObject, eAttribute); EFactory eFactoryInstance = eAttribute.getEType().getEPackage().getEFactoryInstance(); + boolean isPojo = eAttribute.getEAttributeType().getInstanceClass() != null; if (eAttribute.isMany()) { JsonArray jsonArray = new JsonArray(); if (value instanceof Collection) { Collection collection = (Collection) value; for (Object object : collection) { - jsonArray.add(new JsonPrimitive(eFactoryInstance.convertToString(eAttribute.getEAttributeType(), object))); + if (isPojo) { + jsonArray.add(new Gson().toJsonTree(object)); + } else { + jsonArray.add(new JsonPrimitive(eFactoryInstance.convertToString(eAttribute.getEAttributeType(), object))); + } } } jsonElement = jsonArray; } else { - String stringValue = eFactoryInstance.convertToString(eAttribute.getEAttributeType(), value); - - if (stringValue == null) { - stringValue = ""; //$NON-NLS-1$ + if (isPojo) { + jsonElement = new Gson().toJsonTree(value); + } else { + String stringValue = eFactoryInstance.convertToString(eAttribute.getEAttributeType(), value); + if (stringValue == null) { + stringValue = ""; //$NON-NLS-1$ + } + jsonElement = new JsonPrimitive(stringValue); } - jsonElement = new JsonPrimitive(stringValue); + } return jsonElement; diff --git a/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/JsonHelper.java b/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/JsonHelper.java index 27c5125..2b5751d 100644 --- a/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/JsonHelper.java +++ b/bundles/org.eclipse.sirius.emfjson/src/main/java/org/eclipse/sirius/emfjson/utils/JsonHelper.java @@ -14,6 +14,7 @@ package org.eclipse.sirius.emfjson.utils; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -581,7 +582,8 @@ public EClassifier getType(EFactory eFactory, String typeName) { } /** - * Sets the value of the feature for the given object. + * Sets the value of the feature for the given object. If the feature is multivalued, add the value to the + * collection of values already set. * * @param object * the given object @@ -591,7 +593,13 @@ public EClassifier getType(EFactory eFactory, String typeName) { * the value to set */ public void setValue(EObject object, EStructuralFeature feature, Object value) { - object.eSet(feature, value); + if (feature.isMany()) { + @SuppressWarnings("unchecked") + Collection collection = (Collection) object.eGet(feature); + collection.add(value); + } else { + object.eSet(feature, value); + } } /** diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/AbstractEMFJsonTests.java b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/AbstractEMFJsonTests.java index 955b19c..5ff1c6a 100644 --- a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/AbstractEMFJsonTests.java +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/AbstractEMFJsonTests.java @@ -43,6 +43,7 @@ import org.eclipse.sirius.emfjson.resource.JsonResource; import org.eclipse.sirius.emfjson.resource.JsonResourceFactoryImpl; import org.eclipse.sirius.emfjson.resource.JsonResourceImpl; +import org.eclipse.sirius.emfjson.utils.JsonHelper; import org.junit.Assert; /** @@ -276,6 +277,10 @@ public Resource createResource(URI uriValue) { resource = resourceSet.createResource(uri); String extension = resource.getURI().fileExtension(); if (extension.equals(JsonResourceFactoryImpl.EXTENSION)) { + if (this.options.get(JsonResource.OPTION_CUSTOM_HELPER) instanceof JsonHelper) { + JsonHelper jsonHelper = (JsonHelper) this.options.get(JsonResource.OPTION_CUSTOM_HELPER); + jsonHelper.setResource(resource); + } resource.load(inputStream, this.options); } else { resource.load(inputStream, Collections.EMPTY_MAP); diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/DataTypeLoadTests.java b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/DataTypeLoadTests.java index ad7837c..92f6203 100644 --- a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/DataTypeLoadTests.java +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/DataTypeLoadTests.java @@ -49,4 +49,20 @@ public void testMultipleSerialiationDataType() { this.testLoad("NodeMultipleCustomDataType.xmi"); //$NON-NLS-1$ } + /** + * Test deserialization of POJO EDataType EAttribute monovalued. + */ + @Test + public void testLoadSingleValueAttributePojoDataType() { + this.testLoad("NodeSingleValueAttributePojoDataType.xmi"); //$NON-NLS-1$ + } + + /** + * Test deserialization of POJO EDataType EAttribute multivalued. + */ + @Test + public void testLoadMultiValuedAttributePojoDataType() { + this.testLoad("NodeMultiValuedAttributePojoDataType.xmi"); //$NON-NLS-1$ + } + } 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..2999ccf --- /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,95 @@ +/******************************************************************************* + * 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() { + // 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 ("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); + } + + }; + // CHECKSTYLE:ON + 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() { + // 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); // Doesn't work + return eClass.getEStructuralFeature(name); + } + + }; + // CHECKSTYLE:ON + 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/ExtendedMetaDataReferencesLoadTests.java b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataReferencesLoadTests.java new file mode 100644 index 0000000..ead839b --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/ExtendedMetaDataReferencesLoadTests.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * 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 ExtendedMetaDataReferencesLoadTests 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() { + // 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 ("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); + } + + }; + // CHECKSTYLE:ON + 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$ + } + +} diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/JsonHelperDataLoadTests.java b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/JsonHelperDataLoadTests.java new file mode 100644 index 0000000..11fc40d --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/load/JsonHelperDataLoadTests.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * 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() { + // CHECKSTYLE:OFF + JsonHelper jsonHelper = new JsonHelper() { + + /** + * {@inheritDoc} + * + * @see org.eclipse.sirius.emfjson.utils.JsonHelper#setValue(org.eclipse.emf.ecore.EObject, + * org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object) + */ + @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); + } + + }; + + // CHECKSTYLE:ON + 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() { + // CHECKSTYLE:OFF + JsonHelper jsonHelper = new JsonHelper() { + + /** + * {@inheritDoc} + * + * @see org.eclipse.sirius.emfjson.utils.JsonHelper#setValue(org.eclipse.emf.ecore.EObject, + * org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object) + */ + @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); + } + + }; + + // CHECKSTYLE:ON + this.options.put(JsonResource.OPTION_CUSTOM_HELPER, jsonHelper); + this.testLoad("TestChangeAttributeTypeMulti.xmi"); //$NON-NLS-1$ + } + + /** + * Change the value of a monovalued EAttribute. + */ + @Test + public void testChangeAttributeValueMono() { + // CHECKSTYLE:OFF + JsonHelper jsonHelper = new JsonHelper() { + + /** + * {@inheritDoc} + * + * @see org.eclipse.sirius.emfjson.utils.JsonHelper#setValue(org.eclipse.emf.ecore.EObject, + * org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object) + */ + @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); + } + + }; + + // CHECKSTYLE:ON + 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() { + // CHECKSTYLE:OFF + JsonHelper jsonHelper = new JsonHelper() { + + /** + * {@inheritDoc} + * + * @see org.eclipse.sirius.emfjson.utils.JsonHelper#setValue(org.eclipse.emf.ecore.EObject, + * org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object) + */ + @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); + } + + }; + + // CHECKSTYLE:ON + this.options.put(JsonResource.OPTION_CUSTOM_HELPER, jsonHelper); + this.testLoad("TestChangeAttributeValueMulti.xmi"); //$NON-NLS-1$ + } + +} diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/save/DataTypeSaveTests.java b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/save/DataTypeSaveTests.java index 68e05d5..46af566 100644 --- a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/save/DataTypeSaveTests.java +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/save/DataTypeSaveTests.java @@ -49,4 +49,20 @@ public void testMultipleSerialiationDataType() { this.testSave("NodeMultipleCustomDataType.xmi"); //$NON-NLS-1$ } + /** + * Test serialization of POJO EDataType EAttribute monovalued. + */ + @Test + public void testSaveSingleValueAttributePojoDataType() { + this.testSave("NodeSingleValueAttributePojoDataType.xmi"); //$NON-NLS-1$ + } + + /** + * Test serialization of POJO EDataType EAttribute multivalued. + */ + @Test + public void testSaveMultiValuedAttributePojoDataType() { + this.testSave("NodeMultiValuedAttributePojoDataType.xmi"); //$NON-NLS-1$ + } + } diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/save/SerializeOptionsTests.java b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/save/SerializeOptionsTests.java index 176869e..f593fa8 100644 --- a/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/save/SerializeOptionsTests.java +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/java/org/eclipse/sirius/emfjson/tests/internal/unit/save/SerializeOptionsTests.java @@ -25,6 +25,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.Map; import org.eclipse.emf.common.util.BasicEList; @@ -450,4 +451,24 @@ public void postLoad(JsonResource resource, InputStream inputStream, Map l this.testSave("SimpleModelWithOnlyDefaultValueForResourceHandlerPreSavingTest.xmi"); //$NON-NLS-1$ } + + /** + * Test the serialization with feature order comparator. + */ + @Test + public void testSerializationWithFeatureOrderComparator() { + + // A comparator to sort the feature on their name length. + Comparator featuresComparator = new Comparator() { + @Override + public int compare(EStructuralFeature o1, EStructuralFeature o2) { + return o1.getName().length() - o2.getName().length(); + } + }; + + this.options.put(JsonResource.OPTION_SAVE_FEATURES_ORDER_COMPARATOR, featuresComparator); + this.testSave("TestSerializationWithFeatureOrderComparator.xmi"); //$NON-NLS-1$ + + } + } diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/model/TestPojoDataTypeImpl.java b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/model/TestPojoDataTypeImpl.java new file mode 100644 index 0000000..0a3f0fb --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/model/TestPojoDataTypeImpl.java @@ -0,0 +1,166 @@ +package model; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/******************************************************************************* + * 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 + *******************************************************************************/ + +public class TestPojoDataTypeImpl { + + /** + * A String value. + */ + private String stringValue = null; + + /** + * An integer value. + */ + private int intValue = 0; + + /** + * Not serialized. + */ + private transient int transientIntValue = 0; + + /** + * Empty constructor for Json serialization. + * + */ + public TestPojoDataTypeImpl() { + + } + + /** + * Returns the stringValue. + * + * @return The stringValue + */ + public String getStringValue() { + return this.stringValue; + } + + /** + * Sets the stringValue. + * + * @param stringValue + * The stringValue to set + */ + public void setStringValue(String stringValue) { + this.stringValue = stringValue; + } + + /** + * Returns the intValue. + * + * @return The intValue + */ + public int getIntValue() { + return this.intValue; + } + + /** + * Sets the intValue. + * + * @param intValue + * The intValue to set + */ + public void setIntValue(int intValue) { + this.intValue = intValue; + } + + /** + * Returns the transientIntValue. + * + * @return The transientIntValue + */ + public int getTransientIntValue() { + return this.transientIntValue; + } + + /** + * Sets the transientIntValue. + * + * @param transientIntValue + * The transientIntValue to set + */ + public void setTransientIntValue(int transientIntValue) { + this.transientIntValue = transientIntValue; + } + + /** + * Used by the XMI serialization. This doesn't produce as a Json string on purpose, not to interfere with the Json + * serialization.
+ * + * @return A string representing this {@link TestPojoDataTypeImpl} instance. + */ + @Override + public String toString() { + return String.format("TestPojoDataTypeImpl('%s', %d)", this.stringValue.replaceAll("'", "'"), Integer.valueOf(this.intValue)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + /** + * Used by the XMI deserialization. This doesn't take a Json string on purpose, not to interfere with the Json + * deserialization. + * + * @param serialized + * The serialized form of a {@link TestPojoDataTypeImpl} as produced by + * {@link TestPojoDataTypeImpl#toString()}. + * @return A new instance of {@link TestPojoDataTypeImpl} if the given serialized form is consistent, null + * otherwise. + */ + public static TestPojoDataTypeImpl valueOf(String serialized) { + TestPojoDataTypeImpl value = null; + Matcher matcher = Pattern.compile("TestPojoDataTypeImpl\\('([^']*)', ([0-9]+)\\)").matcher(serialized); //$NON-NLS-1$ + if (matcher.matches()) { + value = new TestPojoDataTypeImpl(); + value.setStringValue(matcher.group(1).replaceAll("'", "'")); //$NON-NLS-1$ //$NON-NLS-2$ + value.setIntValue(Integer.parseInt(matcher.group(2))); + } + return value; + } + + /** + * {@inheritDoc} + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.intValue; + result = prime * result + ((this.stringValue == null) ? 0 : this.stringValue.hashCode()); + return result; + } + + /** + * {@inheritDoc} + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + TestPojoDataTypeImpl other = (TestPojoDataTypeImpl) obj; + if (this.intValue != other.intValue) + return false; + if (this.stringValue == null) { + if (other.stringValue != null) + return false; + } else if (!this.stringValue.equals(other.stringValue)) + return false; + return true; + } + +} diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/nodes.ecore b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/nodes.ecore index 0747385..9391e96 100644 --- a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/nodes.ecore +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/nodes.ecore @@ -61,6 +61,8 @@ + + + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeMultiValuedAttributePojoDataType.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeMultiValuedAttributePojoDataType.json new file mode 100644 index 0000000..125177c --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeMultiValuedAttributePojoDataType.json @@ -0,0 +1,33 @@ +{ + "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:NodeMultiValuedAttribute", + "data": { + "multiPojoDataTypeAttribute": [ + { + "stringValue": "Eleven", + "intValue": 11 + }, + { + "stringValue": "Twelve", + "intValue": 12 + }, + { + "stringValue": "Forty two", + "intValue": 42 + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeMultiValuedAttributePojoDataType.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeMultiValuedAttributePojoDataType.xmi new file mode 100644 index 0000000..3730971 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeMultiValuedAttributePojoDataType.xmi @@ -0,0 +1,11 @@ + + + TestPojoDataTypeImpl('Eleven', 11) + TestPojoDataTypeImpl('Twelve', 12) + TestPojoDataTypeImpl('Forty two', 42) + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeSingleValueAttributePojoDataType.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeSingleValueAttributePojoDataType.json new file mode 100644 index 0000000..e6c48a7 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeSingleValueAttributePojoDataType.json @@ -0,0 +1,23 @@ +{ + "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:NodeSingleValueAttribute", + "data": { + "singleTestPojoDataTypeAttribute": { + "stringValue": "Twelve", + "intValue": 12 + } + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeSingleValueAttributePojoDataType.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeSingleValueAttributePojoDataType.xmi new file mode 100644 index 0000000..1aaf797 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/datatypes/NodeSingleValueAttributePojoDataType.xmi @@ -0,0 +1,8 @@ + + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMono.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMono.json new file mode 100644 index 0000000..fc4c951 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMono.json @@ -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" + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMono.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMono.xmi new file mode 100644 index 0000000..a89f2d3 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMono.xmi @@ -0,0 +1,8 @@ + + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMulti.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMulti.json new file mode 100644 index 0000000..f5b5520 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMulti.json @@ -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" + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMulti.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMulti.xmi new file mode 100644 index 0000000..8de839a --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeNameMulti.xmi @@ -0,0 +1,11 @@ + + + multiStringAttribute value 1 + multiStringAttribute value 2 + multiStringAttribute value 3 + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMono.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMono.json new file mode 100644 index 0000000..888b286 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMono.json @@ -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" + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMono.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMono.xmi new file mode 100644 index 0000000..1f500ef --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMono.xmi @@ -0,0 +1,8 @@ + + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMulti.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMulti.json new file mode 100644 index 0000000..3c949f6 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMulti.json @@ -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" + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMulti.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMulti.xmi new file mode 100644 index 0000000..c2e01d4 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeTypeMulti.xmi @@ -0,0 +1,11 @@ + + + 3 + 6 + 9 + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMono.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMono.json new file mode 100644 index 0000000..6945ff9 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMono.json @@ -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" + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMono.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMono.xmi new file mode 100644 index 0000000..6e891d4 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMono.xmi @@ -0,0 +1,8 @@ + + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMulti.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMulti.json new file mode 100644 index 0000000..3f87845 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMulti.json @@ -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" + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMulti.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMulti.xmi new file mode 100644 index 0000000..b609f77 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/extendedmetadata/TestChangeAttributeValueMulti.xmi @@ -0,0 +1,11 @@ + + + ABC + ABCDEF + ABCDEFGHI + diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/serializeoptions/TestSerializationWithFeatureOrderComparator.json b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/serializeoptions/TestSerializationWithFeatureOrderComparator.json new file mode 100644 index 0000000..63e7c46 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/serializeoptions/TestSerializationWithFeatureOrderComparator.json @@ -0,0 +1,22 @@ +{ + "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:NodeSingleValueAttribute", + "data": { + "singleIntAttribute": 12, + "singleStringAttribute": "String value", + "singleBooleanAttribute": true + } + } + ] +} \ No newline at end of file diff --git a/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/serializeoptions/TestSerializationWithFeatureOrderComparator.xmi b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/serializeoptions/TestSerializationWithFeatureOrderComparator.xmi new file mode 100644 index 0000000..19bde55 --- /dev/null +++ b/tests/org.eclipse.sirius.emfjson.tests/src/main/resources/unit/attributes/serializeoptions/TestSerializationWithFeatureOrderComparator.xmi @@ -0,0 +1,10 @@ + + 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 @@ + + + + + +