From 0bfbbcf996cf64a93bb70c2457d4930a517ac4b9 Mon Sep 17 00:00:00 2001 From: DaikiKaminari Date: Wed, 6 Oct 2021 10:04:49 +0200 Subject: [PATCH 01/21] Added emf-jackson dependency for json testing --- neoemf-io/pom.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/neoemf-io/pom.xml b/neoemf-io/pom.xml index a2a7dd41ad..bd0cc002a9 100644 --- a/neoemf-io/pom.xml +++ b/neoemf-io/pom.xml @@ -25,6 +25,15 @@ + + + oss.sonatype.org-snapshot + http://oss.sonatype.org/content/repositories/snapshots + false + true + + + @@ -111,6 +120,13 @@ assertj-core + + org.emfjson + emfjson-jackson + 1.3.0 + bundle + + From 02afb86003b4964273a1c74ef2fe6cff20a94adb Mon Sep 17 00:00:00 2001 From: DaikiKaminari <52349037+DaikiKaminari@users.noreply.github.com> Date: Thu, 28 Oct 2021 22:50:54 +0200 Subject: [PATCH 02/21] Prepare for json writer --- .../fr/inria/atlanmod/neoemf/io/Migrator.java | 4 +- .../inria/atlanmod/neoemf/io/reader/Test.java | 13 +++ .../reader/json/AbstractJsonStreamReader.java | 20 ++++ .../io/reader/json/JsonStreamReader.java | 5 + .../inria/atlanmod/neoemf/io/reader/store.xml | 91 +++++++++++++++++++ .../{ => xmi}/AbstractXmiStreamReader.java | 3 +- .../io/reader/{ => xmi}/XmiStreamReader.java | 2 +- .../writer/json/AbstractJsonStreamWriter.java | 41 +++++++++ .../writer/json/IdentingJsonStreamWriter.java | 14 +++ .../io/writer/json/JsonStreamWriter.java | 14 +++ .../neoemf/io/writer/json/JsonWriter.java | 4 + .../{ => xmi}/AbstractXmiStreamWriter.java | 3 +- .../{ => xmi}/IndentingXmiStreamWriter.java | 2 +- .../io/writer/{ => xmi}/XmiStreamWriter.java | 2 +- .../atlanmod/neoemf/io/XmiReaderTest.java | 2 +- 15 files changed, 212 insertions(+), 8 deletions(-) create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/Test.java create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/JsonStreamReader.java create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/store.xml rename neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/{ => xmi}/AbstractXmiStreamReader.java (96%) rename neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/{ => xmi}/XmiStreamReader.java (99%) create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/IdentingJsonStreamWriter.java create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonWriter.java rename neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/{ => xmi}/AbstractXmiStreamWriter.java (98%) rename neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/{ => xmi}/IndentingXmiStreamWriter.java (98%) rename neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/{ => xmi}/XmiStreamWriter.java (98%) diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java index fe10c443f4..553cfc1d25 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java @@ -19,10 +19,10 @@ import fr.inria.atlanmod.neoemf.io.reader.AbstractReader; import fr.inria.atlanmod.neoemf.io.reader.DefaultMapperReader; import fr.inria.atlanmod.neoemf.io.reader.Reader; -import fr.inria.atlanmod.neoemf.io.reader.XmiStreamReader; +import fr.inria.atlanmod.neoemf.io.reader.xmi.XmiStreamReader; import fr.inria.atlanmod.neoemf.io.writer.DefaultMapperWriter; import fr.inria.atlanmod.neoemf.io.writer.Writer; -import fr.inria.atlanmod.neoemf.io.writer.XmiStreamWriter; +import fr.inria.atlanmod.neoemf.io.writer.xmi.XmiStreamWriter; import org.atlanmod.commons.annotation.VisibleForTesting; import org.atlanmod.commons.log.Level; diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/Test.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/Test.java new file mode 100644 index 0000000000..b356b2692a --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/Test.java @@ -0,0 +1,13 @@ +package fr.inria.atlanmod.neoemf.io.reader; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class Test { + public static void main(String[] args) throws IOException { + Path fileName = Path.of("demo.txt"); + String store_xml = Files.readString(fileName); + System.out.println(store_xml); + } +} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java new file mode 100644 index 0000000000..b7b46707b5 --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java @@ -0,0 +1,20 @@ +package fr.inria.atlanmod.neoemf.io.reader.json; + +import fr.inria.atlanmod.neoemf.io.reader.AbstractStreamReader; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.io.InputStream; + +public class AbstractJsonStreamReader extends AbstractStreamReader { + + @Override + public void parse(InputStream stream) throws IOException { + + } + + @Override + protected boolean isSpecialAttribute(@Nullable String prefix, String name, String value) throws IOException { + return false; + } +} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/JsonStreamReader.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/JsonStreamReader.java new file mode 100644 index 0000000000..3d5da5bb4a --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/JsonStreamReader.java @@ -0,0 +1,5 @@ +package fr.inria.atlanmod.neoemf.io.reader.json; + +public class JsonStreamReader extends AbstractJsonStreamReader { + +} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/store.xml b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/store.xml new file mode 100644 index 0000000000..2b42d41917 --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/store.xml @@ -0,0 +1,91 @@ + + + +]> + + +
+
+ + + + +
+ + + + + + +
+ + + + + +
+ + + +
+ + + + +
+ + + + + + +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/AbstractXmiStreamReader.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/xmi/AbstractXmiStreamReader.java similarity index 96% rename from neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/AbstractXmiStreamReader.java rename to neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/xmi/AbstractXmiStreamReader.java index b2cd73a387..61eaf5293e 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/AbstractXmiStreamReader.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/xmi/AbstractXmiStreamReader.java @@ -6,13 +6,14 @@ * this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/ */ -package fr.inria.atlanmod.neoemf.io.reader; +package fr.inria.atlanmod.neoemf.io.reader.xmi; import fr.inria.atlanmod.neoemf.io.processor.AbstractProcessor; import fr.inria.atlanmod.neoemf.io.processor.EcoreMapper; import fr.inria.atlanmod.neoemf.io.processor.XPathResolver; import fr.inria.atlanmod.neoemf.io.proxy.ProxyReference; import fr.inria.atlanmod.neoemf.io.proxy.ProxyValue; +import fr.inria.atlanmod.neoemf.io.reader.AbstractStreamReader; import fr.inria.atlanmod.neoemf.io.util.XmiConstants; import org.atlanmod.commons.log.Log; diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/XmiStreamReader.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/xmi/XmiStreamReader.java similarity index 99% rename from neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/XmiStreamReader.java rename to neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/xmi/XmiStreamReader.java index 49b21654f6..612b524189 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/XmiStreamReader.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/xmi/XmiStreamReader.java @@ -6,7 +6,7 @@ * this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/ */ -package fr.inria.atlanmod.neoemf.io.reader; +package fr.inria.atlanmod.neoemf.io.reader.xmi; import com.ctc.wstx.api.WstxInputProperties; diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java new file mode 100644 index 0000000000..f481421f45 --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java @@ -0,0 +1,41 @@ +package fr.inria.atlanmod.neoemf.io.writer.json; + +import fr.inria.atlanmod.neoemf.core.Id; +import fr.inria.atlanmod.neoemf.io.proxy.ProxyAttribute; +import fr.inria.atlanmod.neoemf.io.proxy.ProxyReference; +import fr.inria.atlanmod.neoemf.io.writer.AbstractStreamWriter; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; + +public class AbstractJsonStreamWriter extends AbstractStreamWriter { + /** + * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. + * + * @param stream the stream where to write data + */ + protected AbstractJsonStreamWriter(OutputStream stream) { + super(stream); + } + + @Override + public void onAttribute(ProxyAttribute attribute, List values) throws IOException { + + } + + @Override + public void onReference(ProxyReference reference, List values) throws IOException { + + } + + @Override + public void onInitialize() throws IOException { + + } + + @Override + public void onComplete() throws IOException { + + } +} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/IdentingJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/IdentingJsonStreamWriter.java new file mode 100644 index 0000000000..e3b40e3555 --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/IdentingJsonStreamWriter.java @@ -0,0 +1,14 @@ +package fr.inria.atlanmod.neoemf.io.writer.json; + +import java.io.OutputStream; + +public class IdentingJsonStreamWriter extends JsonStreamWriter { + /** + * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. + * + * @param stream the stream where to write data + */ + protected IdentingJsonStreamWriter(OutputStream stream) { + super(stream); + } +} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java new file mode 100644 index 0000000000..d603e0a5b4 --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -0,0 +1,14 @@ +package fr.inria.atlanmod.neoemf.io.writer.json; + +import java.io.OutputStream; + +public class JsonStreamWriter extends AbstractJsonStreamWriter { + /** + * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. + * + * @param stream the stream where to write data + */ + protected JsonStreamWriter(OutputStream stream) { + super(stream); + } +} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonWriter.java new file mode 100644 index 0000000000..013a15425e --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonWriter.java @@ -0,0 +1,4 @@ +package fr.inria.atlanmod.neoemf.io.writer.json; + +public class JsonWriter { +} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/AbstractXmiStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/xmi/AbstractXmiStreamWriter.java similarity index 98% rename from neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/AbstractXmiStreamWriter.java rename to neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/xmi/AbstractXmiStreamWriter.java index 057a91cff3..15410017d9 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/AbstractXmiStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/xmi/AbstractXmiStreamWriter.java @@ -6,7 +6,7 @@ * this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/ */ -package fr.inria.atlanmod.neoemf.io.writer; +package fr.inria.atlanmod.neoemf.io.writer.xmi; import fr.inria.atlanmod.neoemf.core.Id; import fr.inria.atlanmod.neoemf.io.processor.ValueConverter; @@ -17,6 +17,7 @@ import fr.inria.atlanmod.neoemf.io.proxy.ProxyReference; import fr.inria.atlanmod.neoemf.io.util.XmiConstants; +import fr.inria.atlanmod.neoemf.io.writer.AbstractStreamWriter; import org.atlanmod.commons.annotation.Beta; import org.atlanmod.commons.primitive.Strings; import org.eclipse.emf.ecore.EAttribute; diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/IndentingXmiStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/xmi/IndentingXmiStreamWriter.java similarity index 98% rename from neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/IndentingXmiStreamWriter.java rename to neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/xmi/IndentingXmiStreamWriter.java index ff2b6bd46d..9e8a7414cc 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/IndentingXmiStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/xmi/IndentingXmiStreamWriter.java @@ -6,7 +6,7 @@ * this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/ */ -package fr.inria.atlanmod.neoemf.io.writer; +package fr.inria.atlanmod.neoemf.io.writer.xmi; import org.atlanmod.commons.primitive.Strings; diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/XmiStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/xmi/XmiStreamWriter.java similarity index 98% rename from neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/XmiStreamWriter.java rename to neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/xmi/XmiStreamWriter.java index ba7d1078ab..9fa638f391 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/XmiStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/xmi/XmiStreamWriter.java @@ -6,7 +6,7 @@ * this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/ */ -package fr.inria.atlanmod.neoemf.io.writer; +package fr.inria.atlanmod.neoemf.io.writer.xmi; import fr.inria.atlanmod.neoemf.io.util.XmiConstants; diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/XmiReaderTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/XmiReaderTest.java index 1a23bbd79e..d4da0767a1 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/XmiReaderTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/XmiReaderTest.java @@ -13,7 +13,7 @@ import fr.inria.atlanmod.neoemf.io.proxy.ProxyClass; import fr.inria.atlanmod.neoemf.io.proxy.ProxyReference; import fr.inria.atlanmod.neoemf.io.provider.UriProvider; -import fr.inria.atlanmod.neoemf.io.reader.XmiStreamReader; +import fr.inria.atlanmod.neoemf.io.reader.xmi.XmiStreamReader; import fr.inria.atlanmod.neoemf.io.util.InMemoryElement; import fr.inria.atlanmod.neoemf.io.util.InMemoryWriter; import fr.inria.atlanmod.neoemf.io.util.ResourceManager; From e20c369a020af8dc1e2ffa8d09a0ec3f446261ba Mon Sep 17 00:00:00 2001 From: DaikiKaminari <52349037+DaikiKaminari@users.noreply.github.com> Date: Fri, 29 Oct 2021 09:22:09 +0200 Subject: [PATCH 03/21] Add json jackson dependency to pom --- neoemf-io/pom.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/neoemf-io/pom.xml b/neoemf-io/pom.xml index bd0cc002a9..226acdf509 100644 --- a/neoemf-io/pom.xml +++ b/neoemf-io/pom.xml @@ -22,6 +22,7 @@ 1.0-2 4.2.1 4.4.1 + 2.12.5 @@ -91,6 +92,19 @@ org.eclipse.emf.ecore.xcore.lib + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + From 5b482a19f2f9ca1c0a8a0243fb15d98aa77f3db9 Mon Sep 17 00:00:00 2001 From: DaikiKaminari <52349037+DaikiKaminari@users.noreply.github.com> Date: Fri, 29 Oct 2021 11:51:10 +0200 Subject: [PATCH 04/21] Method skeleton for json writer --- .../fr/inria/atlanmod/neoemf/io/Migrator.java | 15 + .../writer/json/AbstractJsonStreamWriter.java | 62 +- .../writer/json/IdentingJsonStreamWriter.java | 14 - .../io/writer/json/JsonStreamWriter.java | 41 +- .../neoemf/io/writer/json/JsonWriter.java | 4 - .../src/test/resources/model/Sample.aird | 1509 +++++++++++++++++ .../resources/model/subSampleModel/.gitkeep | 0 7 files changed, 1620 insertions(+), 25 deletions(-) delete mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/IdentingJsonStreamWriter.java delete mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonWriter.java create mode 100644 neoemf-io/src/test/resources/model/Sample.aird create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/.gitkeep diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java index 553cfc1d25..cd2ab49885 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java @@ -22,6 +22,7 @@ import fr.inria.atlanmod.neoemf.io.reader.xmi.XmiStreamReader; import fr.inria.atlanmod.neoemf.io.writer.DefaultMapperWriter; import fr.inria.atlanmod.neoemf.io.writer.Writer; +import fr.inria.atlanmod.neoemf.io.writer.json.JsonStreamWriter; import fr.inria.atlanmod.neoemf.io.writer.xmi.XmiStreamWriter; import org.atlanmod.commons.annotation.VisibleForTesting; @@ -285,6 +286,20 @@ public Migrator toXmi(@WillNotClose OutputStream stream) throws IOException { return to(new XmiStreamWriter(stream)); } + /** + * Specifies the {@code stream} where to write the data. + * + * @param stream the file where to write + * + * @return this migrator (for chaining) + * + * @throws IOException if an I/O error occurs when writing + */ + @Nonnull + public Migrator toJson(@WillNotClose OutputStream stream) throws IOException { + return to(new JsonStreamWriter(stream)); + } + //endregion //region Listeners diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java index f481421f45..aef0dfecd2 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java @@ -9,28 +9,29 @@ import java.io.OutputStream; import java.util.List; -public class AbstractJsonStreamWriter extends AbstractStreamWriter { +public abstract class AbstractJsonStreamWriter extends AbstractStreamWriter { /** * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. * * @param stream the stream where to write data */ - protected AbstractJsonStreamWriter(OutputStream stream) { + public AbstractJsonStreamWriter(OutputStream stream) { super(stream); } @Override - public void onAttribute(ProxyAttribute attribute, List values) throws IOException { - + public void onInitialize() throws IOException { + // on créé l'URI, on stocke le minimum dans le fichier json (soit "[]") + writeStartDocument(); } @Override - public void onReference(ProxyReference reference, List values) throws IOException { + public void onAttribute(ProxyAttribute attribute, List values) throws IOException { } @Override - public void onInitialize() throws IOException { + public void onReference(ProxyReference reference, List values) throws IOException { } @@ -38,4 +39,53 @@ public void onInitialize() throws IOException { public void onComplete() throws IOException { } + + /** + * Writes the start of a document, including the general header. + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeStartDocument() throws IOException; + + /** + * Writes the start of an element {@code name} + * + * @param name the name of the element + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeStartElement(String name) throws IOException; + + /** + * Writes an attribute of the current element. + * + * @param name the name of the attribute + * @param value the value of the attribute + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeAttribute(String name, String value) throws IOException; + + /** + * Writes characters. + * + * @param characters the characters + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeCharacters(String characters) throws IOException; + + /** + * Writes the end of the current element. + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeEndElement() throws IOException; + + /** + * Writes the end of the document and finalizes the migration. + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeEndDocument() throws IOException; } diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/IdentingJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/IdentingJsonStreamWriter.java deleted file mode 100644 index e3b40e3555..0000000000 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/IdentingJsonStreamWriter.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.inria.atlanmod.neoemf.io.writer.json; - -import java.io.OutputStream; - -public class IdentingJsonStreamWriter extends JsonStreamWriter { - /** - * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. - * - * @param stream the stream where to write data - */ - protected IdentingJsonStreamWriter(OutputStream stream) { - super(stream); - } -} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java index d603e0a5b4..d1ac20ea34 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -1,14 +1,53 @@ package fr.inria.atlanmod.neoemf.io.writer.json; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; import java.io.OutputStream; +import javax.annotation.Nonnull; + public class JsonStreamWriter extends AbstractJsonStreamWriter { + @Nonnull + protected final ObjectMapper mapper; + /** * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. * * @param stream the stream where to write data */ - protected JsonStreamWriter(OutputStream stream) { + public JsonStreamWriter(OutputStream stream) { super(stream); + mapper = new ObjectMapper(); + } + + @Override + protected void writeStartDocument() throws IOException { + + } + + @Override + protected void writeStartElement(String name) throws IOException { + + } + + @Override + protected void writeAttribute(String name, String value) throws IOException { + + } + + @Override + protected void writeCharacters(String characters) throws IOException { + + } + + @Override + protected void writeEndElement() throws IOException { + + } + + @Override + protected void writeEndDocument() throws IOException { + } } diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonWriter.java deleted file mode 100644 index 013a15425e..0000000000 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonWriter.java +++ /dev/null @@ -1,4 +0,0 @@ -package fr.inria.atlanmod.neoemf.io.writer.json; - -public class JsonWriter { -} diff --git a/neoemf-io/src/test/resources/model/Sample.aird b/neoemf-io/src/test/resources/model/Sample.aird new file mode 100644 index 0000000000..46676ded7a --- /dev/null +++ b/neoemf-io/src/test/resources/model/Sample.aird @@ -0,0 +1,1509 @@ + + + + Sample.ecore + Sample.genmodel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + italic + + + + + + + + + + + + + + + + + + + + italic + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + italic + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + labelSize + + + labelSize + + + + + + + + + + + italic + + + + + + + + + + + + italic + + + + + + + + + + + + italic + + + + + + + + + + + + italic + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/neoemf-io/src/test/resources/model/subSampleModel/.gitkeep b/neoemf-io/src/test/resources/model/subSampleModel/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 From 614d9eb573913b8179a2ef7864f0a7cb5d2b075e Mon Sep 17 00:00:00 2001 From: DaikiKaminari <52349037+DaikiKaminari@users.noreply.github.com> Date: Sat, 30 Oct 2021 17:17:45 +0200 Subject: [PATCH 05/21] Add JsonWriterTest to test writing json and a tiny ecore model for testing --- .../fr/inria/atlanmod/neoemf/io/Migrator.java | 16 + .../writer/json/AbstractJsonStreamWriter.java | 1 - .../io/writer/json/JsonStreamWriter.java | 10 +- .../test/java/writer/json/JsonWriterTest.java | 59 ++++ .../subSampleModel/simplestClass/Sample.aird | 315 ++++++++++++++++++ .../subSampleModel/simplestClass/Sample.ecore | 17 + .../resources/test-output/test-write.json | 1 + 7 files changed, 415 insertions(+), 4 deletions(-) create mode 100644 neoemf-io/src/test/java/writer/json/JsonWriterTest.java create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore create mode 100644 neoemf-io/src/test/resources/test-output/test-write.json diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java index cd2ab49885..55f2010a2f 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java @@ -286,6 +286,22 @@ public Migrator toXmi(@WillNotClose OutputStream stream) throws IOException { return to(new XmiStreamWriter(stream)); } + /** + * Specifies the JSON {@code file} where to write the data. + * + * @param file the file where to write + * + * @return this migrator (for chaining) + * + * @throws IOException if an I/O error occurs during the creation + * @see #toXmi(File, boolean) + */ + @Nonnull + public Migrator toJson(File file) throws IOException { + OutputStream outputStream = new FileOutputStream(file); + return toJson(outputStream); + } + /** * Specifies the {@code stream} where to write the data. * diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java index aef0dfecd2..856bf635bb 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java @@ -21,7 +21,6 @@ public AbstractJsonStreamWriter(OutputStream stream) { @Override public void onInitialize() throws IOException { - // on créé l'URI, on stocke le minimum dans le fichier json (soit "[]") writeStartDocument(); } diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java index d1ac20ea34..e91b5da10c 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -1,5 +1,6 @@ package fr.inria.atlanmod.neoemf.io.writer.json; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; @@ -10,20 +11,23 @@ public class JsonStreamWriter extends AbstractJsonStreamWriter { @Nonnull protected final ObjectMapper mapper; + @Nonnull + protected final JsonGenerator jGenerator; /** * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. * * @param stream the stream where to write data */ - public JsonStreamWriter(OutputStream stream) { + public JsonStreamWriter(OutputStream stream) throws IOException { super(stream); mapper = new ObjectMapper(); + jGenerator = mapper.getFactory().createGenerator(target); } @Override protected void writeStartDocument() throws IOException { - + jGenerator.writeStartArray(); } @Override @@ -48,6 +52,6 @@ protected void writeEndElement() throws IOException { @Override protected void writeEndDocument() throws IOException { - + jGenerator.writeEndArray(); } } diff --git a/neoemf-io/src/test/java/writer/json/JsonWriterTest.java b/neoemf-io/src/test/java/writer/json/JsonWriterTest.java new file mode 100644 index 0000000000..19d2f8b9f4 --- /dev/null +++ b/neoemf-io/src/test/java/writer/json/JsonWriterTest.java @@ -0,0 +1,59 @@ +package writer.json; + +import fr.inria.atlanmod.neoemf.data.Backend; +import fr.inria.atlanmod.neoemf.data.im.DefaultInMemoryBackend; +import fr.inria.atlanmod.neoemf.data.mapping.DataMapper; +import fr.inria.atlanmod.neoemf.io.Migrator; +import fr.inria.atlanmod.neoemf.io.provider.UriProvider; +import fr.inria.atlanmod.neoemf.io.util.ResourceManager; +import fr.inria.atlanmod.neoemf.util.ModelComparisonUtils; +import org.atlanmod.commons.AbstractFileBasedTest; +import org.atlanmod.commons.log.Log; +import org.atlanmod.commons.primitive.Strings; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; +import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.ValueSource; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +class JsonWriterTest { + static void testWrite(String sourcePath, String targetPath) throws IOException { + Log.info("Exporting to file... [{0}]", targetPath); + File targetFile = new File(targetPath); + + try (DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new FileInputStream(sourcePath)) { + Migrator.fromXmi(in).toMapper(mapper).migrate(); + + Migrator.fromMapper(mapper) + .toJson(targetFile) + .migrate(); + } + + // Comparing with EMF + /* + EObject actual = ResourceManager.load(URI.createFileURI(targetFile.toString())); + EObject expected = ResourceManager.load(uri); + + ModelComparisonUtils.assertEObjectAreEqual(actual, expected); + + actual.eResource().unload(); + expected.eResource().unload(); + */ + } + + public static void main(String[] args) throws IOException { + String sourcePath = "D:/Users/Daiki/Documents/Ecole/Universite/Master/M2/Capstone/NeoEMF/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore"; + String targePath = "D:/Users/Daiki/Documents/Ecole/Universite/Master/M2/Capstone/NeoEMF/neoemf-io/src/test/resources/test-output/test-write.json"; + testWrite(sourcePath, targePath); + } +} diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird new file mode 100644 index 0000000000..4c88823b55 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird @@ -0,0 +1,315 @@ + + + + Sample.ecore + Sample.genmodel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + italic + + + + + + + + + + + + + + + + italic + + + + + + + + + + italic + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + italic + + + + + + + + + + + + + + + + + + + + + diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore new file mode 100644 index 0000000000..8a34d24eb3 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore @@ -0,0 +1,17 @@ + + + +
+
+
+
+
+
+
+
+ + + + + diff --git a/neoemf-io/src/test/resources/test-output/test-write.json b/neoemf-io/src/test/resources/test-output/test-write.json new file mode 100644 index 0000000000..adb55ec3f1 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/test-write.json @@ -0,0 +1 @@ +
\ No newline at end of file From ad1d51f9bcb61d55469cca3af43c6900e18af5c1 Mon Sep 17 00:00:00 2001 From: DaikiKaminari Date: Sat, 13 Nov 2021 14:18:59 +0100 Subject: [PATCH 06/21] Fix json-jackson save --- .../writer/json/AbstractJsonStreamWriter.java | 1 + .../io/writer/json/JsonStreamWriter.java | 3 +- .../neoemf/io/reader/XmiReaderTest.java | 435 ++++++++++++++++++ .../test/java/writer/json/JsonWriterTest.java | 4 +- .../resources/test-output/test-write.json | 2 +- 5 files changed, 441 insertions(+), 4 deletions(-) create mode 100644 neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/reader/XmiReaderTest.java diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java index 856bf635bb..de7e489e2a 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java @@ -22,6 +22,7 @@ public AbstractJsonStreamWriter(OutputStream stream) { @Override public void onInitialize() throws IOException { writeStartDocument(); + writeEndDocument(); } @Override diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java index e91b5da10c..7b8b5f3117 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -32,7 +32,7 @@ protected void writeStartDocument() throws IOException { @Override protected void writeStartElement(String name) throws IOException { - + jGenerator.writeStartObject(); } @Override @@ -53,5 +53,6 @@ protected void writeEndElement() throws IOException { @Override protected void writeEndDocument() throws IOException { jGenerator.writeEndArray(); + jGenerator.close(); } } diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/reader/XmiReaderTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/reader/XmiReaderTest.java new file mode 100644 index 0000000000..c25bcc2256 --- /dev/null +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/reader/XmiReaderTest.java @@ -0,0 +1,435 @@ +/* + * Copyright (c) 2013 Atlanmod. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v2.0 which accompanies + * this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/ + */ + +package fr.inria.atlanmod.neoemf.io.reader; + +import fr.inria.atlanmod.neoemf.core.Id; +import fr.inria.atlanmod.neoemf.io.Migrator; +import fr.inria.atlanmod.neoemf.io.proxy.ProxyAttribute; +import fr.inria.atlanmod.neoemf.io.proxy.ProxyClass; +import fr.inria.atlanmod.neoemf.io.proxy.ProxyReference; +import fr.inria.atlanmod.neoemf.io.provider.UriProvider; +import fr.inria.atlanmod.neoemf.io.reader.xmi.XmiStreamReader; +import fr.inria.atlanmod.neoemf.io.util.InMemoryElement; +import fr.inria.atlanmod.neoemf.io.util.InMemoryWriter; +import fr.inria.atlanmod.neoemf.io.util.ResourceManager; + +import org.atlanmod.commons.AbstractTest; +import org.eclipse.emf.common.util.URI; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.atlanmod.commons.Preconditions.checkGreaterThan; +import static org.atlanmod.commons.Preconditions.checkNotNull; + +/** + * A test-case about the reading of a model. + */ +@ParametersAreNonnullByDefault +@SuppressWarnings("ConstantConditions") // Test with `@Nonnull` +class XmiReaderTest extends AbstractTest { + + /** + * A map that holds the mapping between an XPath and its {@code xmi:id} value. + */ + private static final Map MAPPING = new HashMap<>(); + + static { + MAPPING.put("/@Model.0", "_PYE3oE0VEeeM143ZRH6p9g"); + + MAPPING.put("/@Model.0/@orphanTypes.5", "_PZgbAk0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@orphanTypes.9", "_PZgbBk0VEeeM143ZRH6p9g"); + + MAPPING.put("/@Model.0/@ownedElements.0", "_PYNagE0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0", "_PYOooU0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0", "_PYOook0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@modifier.0", "_PYUIME0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.1/@returnType.0", "_PYWkdU0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2", "_PYXLgE0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@modifier.0", "_PYXLg00VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.3", "_PYXLh00VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.5/@returnType.0", "_PZAExk0VEeeM143ZRH6p9g"); + + MAPPING.put("/@Model.0/@ownedElements.1", "_PZKcwE0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@ownedElements.1/@ownedPackages.1", "_PZOuME0VEeeM143ZRH6p9g"); + + MAPPING.put("/@Model.0/@ownedElements.2/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0", "_PZbijE0VEeeM143ZRH6p9g"); + + MAPPING.put("/@Model.0/@compilationUnits.0", "_PZhpIE0VEeeM143ZRH6p9g"); + + MAPPING.put("/@Model.0/@compilationUnits.1", "_PZhpOE0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@compilationUnits.1/@imports.1", "_PZhpOk0VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@compilationUnits.1/@imports.2", "_PZhpO00VEeeM143ZRH6p9g"); + MAPPING.put("/@Model.0/@compilationUnits.1/@imports.10", "_PZiQNE0VEeeM143ZRH6p9g"); + } + + /** + * Retrieves an element from the {@code root} element with the successive {@code indices}. + * + * @param root the element from which to start the search + * @param indices the index of the element, recursively in the children from the {@code root} + * + * @return the element + */ + @Nonnull + private static InMemoryElement childFrom(InMemoryElement root, int... indices) { + checkGreaterThan(indices.length, 0, "You must define at least one index"); + + InMemoryElement child = root; + + for (int index : indices) { + child = child.children().get(index); + } + + return checkNotNull(child, "child"); + } + + @BeforeAll + static void registerPackages() { + ResourceManager.registerAllPackages(); + } + + /** + * Check that the elements and their children are properly processed. + */ + @ParameterizedTest(name = "[{index}] source = {0}") + @ArgumentsSource(UriProvider.AllWithTypes.class) + void testElementsAndChildren(URI uri, Boolean withId) throws IOException { + InMemoryElement root = readResource(uri); + + InMemoryElement o; + InMemoryElement child; + + assertValidElement(root, resolve("/@Model.0", withId), "Model", 19); + { + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0 + o = childFrom(root, 0, 0, 0, 0, 0, 0); + assertValidElement(o, resolve("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0", withId), "ownedElements", 7); + { + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0/@modifier + child = childFrom(o, 0); + assertValidElement(child, resolve("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@modifier.0", withId), "modifier", 0); + + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0/@bodyDeclarations.2 + child = childFrom(o, 3); + assertValidElement(child, resolve("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2", withId), "bodyDeclarations", 5); + } + + //@Model/@ownedElements.1 + o = childFrom(root, 1); + assertValidElement(o, resolve("/@Model.0/@ownedElements.1", withId), "ownedElements", 5); + + //@Model/@orphanTypes.5 + o = childFrom(root, 8); + assertValidElement(o, resolve("/@Model.0/@orphanTypes.5", withId), "orphanTypes", 0); + + //@Model/@compilationUnits.1 + o = childFrom(root, 17); + assertValidElement(o, resolve("/@Model.0/@compilationUnits.1", withId), "compilationUnits", 16); + { + //@Model/@compilationUnits.1/@imports.2 + child = childFrom(o, 2); + assertValidElement(child, resolve("/@Model.0/@compilationUnits.1/@imports.2", withId), "imports", 0); + } + } + } + + /** + * Check that the XPath references are properly processed. + */ + @ParameterizedTest(name = "[{index}] source = {0}") + @ArgumentsSource(UriProvider.AllWithTypes.class) + void testReferences(URI uri, Boolean withId) throws IOException { + InMemoryElement root = readResource(uri); + + InMemoryElement o; + InMemoryElement child; + + List references; + + references = root.references(); + assertThat(references).hasSize(19); + assertValidReference(references.get(0), "ownedElements", resolve("/@Model.0/@ownedElements.0", withId), true, true); + assertValidReference(references.get(12), "orphanTypes", resolve("/@Model.0/@orphanTypes.9", withId), true, true); + { + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0 + o = childFrom(root, 0, 0, 0, 0, 0, 0); + references = o.references(); + assertThat(references).hasSize(8); + assertValidReference(references.get(0), "originalCompilationUnit", resolve("/@Model.0/@compilationUnits.0", withId), false, false); + assertValidReference(references.get(5), "bodyDeclarations", resolve("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.3", withId), true, true); + { + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0/@modifier + child = childFrom(o, 0); + assertThat(child.references()).isEmpty(); + + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0/@bodyDeclarations.2 + child = childFrom(o, 3); + references = child.references(); + assertThat(references).hasSize(6); + assertValidReference(references.get(0), "originalCompilationUnit", resolve("/@Model.0/@compilationUnits.0", withId), false, false); + assertValidReference(references.get(2), "modifier", resolve("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@modifier.0", withId), false, true); + } + + //@Model/@ownedElements.1 + o = childFrom(root, 1); + references = o.references(); + assertThat(references).hasSize(5); + assertValidReference(references.get(1), "ownedPackages", resolve("/@Model.0/@ownedElements.1/@ownedPackages.1", withId), true, true); + + //@Model/@orphanTypes.5 + o = childFrom(root, 8); + references = o.references(); + + assertThat(references).hasSize(12); + assertValidReference(references.get(0), "usagesInTypeAccess", resolve("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.1/@returnType.0", withId), true, false); + assertValidReference(references.get(9), "usagesInTypeAccess", resolve("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.5/@returnType.0", withId), true, false); + + //@Model/@compilationUnits.1 + o = childFrom(root, 17); + references = o.references(); + assertThat(references).hasSize(18); + assertValidReference(references.get(0), "package", resolve("/@Model.0/@ownedElements.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0", withId), false, false); + assertValidReference(references.get(3), "imports", resolve("/@Model.0/@compilationUnits.1/@imports.1", withId), true, true); + assertValidReference(references.get(12), "imports", resolve("/@Model.0/@compilationUnits.1/@imports.10", withId), true, true); + { + //@Model/@compilationUnits.1/@imports.2 + child = childFrom(o, 2); + references = child.references(); + assertThat(references).hasSize(2); + assertValidReference(references.get(0), "originalCompilationUnit", resolve("/@Model.0/@compilationUnits.1", withId), false, false); + assertValidReference(references.get(1), "importedElement", resolve("/@Model.0/@ownedElements.2/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedPackages.0/@ownedElements.0", withId), false, false); + } + } + } + + /** + * Check that the attributes are properly processed. + */ + @ParameterizedTest(name = "[{index}] source = {0}") + @ArgumentsSource(UriProvider.AllWithTypes.class) + void testAttributes(URI uri) throws IOException { + InMemoryElement root = readResource(uri); + + InMemoryElement o; + InMemoryElement child; + + List attributes; + + attributes = root.attributes(); + assertThat(attributes).hasSize(1); // Assert that 'xmi:version' and 'xmlns' don't exist + assertValidAttribute(attributes.get(0), "name", "fr.inria.atlanmod.kyanos.tests"); + { + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0 + o = childFrom(root, 0, 0, 0, 0, 0, 0); + attributes = o.attributes(); + assertThat(attributes).hasSize(1); + assertValidAttribute(attributes.get(0), "name", "TestCreateResource"); + { + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0/@modifier + child = childFrom(o, 0); + attributes = child.attributes(); + assertThat(attributes).hasSize(1); + assertValidAttribute(attributes.get(0), "visibility", "public"); + + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0/@bodyDeclarations.2 + child = childFrom(o, 3); + attributes = child.attributes(); + assertThat(attributes).hasSize(1); + assertValidAttribute(attributes.get(0), "name", "tearDownAfterClass"); + } + + //@Model/@ownedElements.1 + o = childFrom(root, 1); + attributes = o.attributes(); + assertThat(attributes).hasSize(2); + assertValidAttribute(attributes.get(0), "name", "java"); + assertValidAttribute(attributes.get(1), "proxy", true); + + //@Model/@orphanTypes.5 + o = childFrom(root, 8); + attributes = o.attributes(); + assertThat(attributes).hasSize(1); + assertValidAttribute(attributes.get(0), "name", "void"); + + //@Model/@compilationUnits.1 + o = childFrom(root, 17); + attributes = o.attributes(); + assertThat(attributes).hasSize(2); + assertValidAttribute(attributes.get(0), "name", "TestXmi.java"); + assertValidAttribute(attributes.get(1), "originalFilePath", "C:\\Eclipse\\eclipse-SDK-4.3.1-win32-x86_64-Blue\\eclipse\\workspace\\fr.inria.atlanmod.kyanos.tests\\src\\fr\\inria\\atlanmod\\kyanos\\tests\\TestXmi.java"); + { + //@Model/@compilationUnits.1/@imports.2 + child = childFrom(o, 2); + assertThat(child.attributes()).isEmpty(); + } + } + } + + /** + * Check that the meta-classes ('xsi:type' or 'xmi:type') are properly processed. + */ + @ParameterizedTest(name = "[{index}] source = {0}") + @ArgumentsSource(UriProvider.AllWithTypes.class) + void testMetaClasses(URI uri) throws IOException { + InMemoryElement root = readResource(uri); + + InMemoryElement o; + InMemoryElement child; + + assertValidMetaClass(root.metaClass(), "java", "Model"); + { + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0 + o = childFrom(root, 0, 0, 0, 0, 0, 0); + assertValidMetaClass(o.metaClass(), "java", "ClassDeclaration"); + { + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0/@modifier + child = childFrom(o, 0); + assertValidMetaClass(child.metaClass(), "java", "Modifier"); + + //@Model/@ownedElements.0/@ownedPackages[4]/@ownedElements.0/@bodyDeclarations.2 + child = childFrom(o, 3); + assertValidMetaClass(child.metaClass(), "java", "MethodDeclaration"); + } + + //@Model/@ownedElements.1 + o = childFrom(root, 1); + assertValidMetaClass(o.metaClass(), "java", "Package"); + + //@Model/@orphanTypes.5 + o = childFrom(root, 8); + assertValidMetaClass(o.metaClass(), "java", "PrimitiveTypeVoid"); + + //@Model/@compilationUnits.1 + o = childFrom(root, 17); + assertValidMetaClass(o.metaClass(), "java", "CompilationUnit"); + { + //@Model/@compilationUnits.1/@imports.2 + child = childFrom(o, 2); + assertValidMetaClass(child.metaClass(), "java", "ImportDeclaration"); + } + } + } + + /** + * Check if the reader stop its execution if it hasn't any handler. + */ + @Test + void testReaderWithoutHandler() { + assertThat( + catchThrowable(() -> new XmiStreamReader().read(null)) + ).isInstanceOf(NullPointerException.class); + } + + /** + * Reads a resource file from the given {@code uri}. + * + * @param uri the URI of the resource + * + * @return the root of the read resource + */ + @Nonnull + private InMemoryElement readResource(URI uri) throws IOException { + InMemoryWriter writer = new InMemoryWriter(); + + try (InputStream in = new URL(uri.toString()).openStream()) { + Migrator.fromXmi(in) + //.to(writer) TODO + .withCounter() + .withTimer() +// .withLogger() + .migrate(); + } + + return checkNotNull(writer.getRoot(), "writer.root"); + } + + /** + * Retrieves the identifier of the given {@code path} if {@code useIds() == true}. + * + * @param path the path to retrieve + * + * @return the identifier + */ + @Nonnull + private Id resolve(String path, boolean withId) { + Id id = withId + ? Id.getProvider().generate(MAPPING.get(path)) + : Id.getProvider().generate(path); + + return checkNotNull(id, "Undefined path: %s", path); + } + + /** + * Checks that the {@code element} has the given arguments. + * + * @param element the element to test + * @param id the expected identifier + * @param name the expected name + * @param size the expected size + */ + private void assertValidElement(InMemoryElement element, Id id, String name, int size) { + assertThat(element.id()).isEqualTo(id); + assertThat(element.name()).isEqualTo(name); + assertThat(element.children()).hasSize(size); + } + + /** + * Checks that the {@code metaClass} has the given arguments. + * + * @param metaClass the meta-class to test + * @param nsPrefix the expected namespace prefix + * @param name the expected name + */ + private void assertValidMetaClass(ProxyClass metaClass, String nsPrefix, String name) { + assertThat(metaClass.getNamespace().getPrefix()).isEqualTo(nsPrefix); + assertThat(metaClass.getName()).isEqualTo(name); + } + + /** + * Checks that the {@code reference} has the given arguments. + * + * @param reference the reference to test + * @param name the expected name + * @param idReference the expected reference + * @param isMany {@code true} if the {@code reference} is multi-valued + * @param isContainment {@code true} if the {@code reference} is a containment + */ + private void assertValidReference(ProxyReference reference, String name, Id idReference, boolean isMany, boolean isContainment) { + assertThat(reference.getName()).isEqualTo(name); + assertThat(reference.getValue().getResolved()).isEqualTo(idReference); + assertThat(reference.isContainment()).isEqualTo(isContainment); + assertThat(reference.isMany()).isEqualTo(isMany); + } + + /** + * Checks that the {@code attribute} has the given arguments. + * + * @param attribute the attribute to test + * @param name the expected name + * @param value the expected value + */ + private void assertValidAttribute(ProxyAttribute attribute, String name, Object value) { + assertThat(attribute.getName()).isEqualTo(name); + assertThat(attribute.getValue().getResolved()).isEqualTo(value); + } +} diff --git a/neoemf-io/src/test/java/writer/json/JsonWriterTest.java b/neoemf-io/src/test/java/writer/json/JsonWriterTest.java index 19d2f8b9f4..cdb577448b 100644 --- a/neoemf-io/src/test/java/writer/json/JsonWriterTest.java +++ b/neoemf-io/src/test/java/writer/json/JsonWriterTest.java @@ -52,8 +52,8 @@ static void testWrite(String sourcePath, String targetPath) throws IOException { } public static void main(String[] args) throws IOException { - String sourcePath = "D:/Users/Daiki/Documents/Ecole/Universite/Master/M2/Capstone/NeoEMF/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore"; - String targePath = "D:/Users/Daiki/Documents/Ecole/Universite/Master/M2/Capstone/NeoEMF/neoemf-io/src/test/resources/test-output/test-write.json"; + String sourcePath = "neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore"; + String targePath = "neoemf-io/src/test/resources/test-output/test-write.json"; testWrite(sourcePath, targePath); } } diff --git a/neoemf-io/src/test/resources/test-output/test-write.json b/neoemf-io/src/test/resources/test-output/test-write.json index adb55ec3f1..0637a088a0 100644 --- a/neoemf-io/src/test/resources/test-output/test-write.json +++ b/neoemf-io/src/test/resources/test-output/test-write.json @@ -1 +1 @@ -
\ No newline at end of file +[] \ No newline at end of file From 23718045fa5beeb93d08961df0aab36940d27c95 Mon Sep 17 00:00:00 2001 From: DaikiKaminari <52349037+DaikiKaminari@users.noreply.github.com> Date: Mon, 22 Nov 2021 21:10:29 +0100 Subject: [PATCH 07/21] Not a commit, just the current state in the middle of testing.. --- neoemf-core/pom.xml | 6 ++ neoemf-io/pom.xml | 4 + .../io/writer/json/JsonStreamWriter.java | 9 +++ .../neoemf/io/json/JsonWriterTest.java | 81 +++++++++++++++++++ .../neoemf/io/reader/XmiReaderTest.java | 2 +- .../test/java/writer/json/JsonWriterTest.java | 59 -------------- .../subSampleModel/simplestClass/Sample.aird | 7 +- .../subSampleModel/simplestClass/Sample.ecore | 2 +- .../simplestClass/Sample.genmodel | 16 ++++ .../simplestClass/build.properties | 9 +++ .../simplestClass/plugin.properties | 4 + .../subSampleModel/simplestClass/plugin.xml | 32 ++++++++ .../simplestClass/test-jackson-write.json | 0 .../resources/test-output/test-write.json | 1 - 14 files changed, 166 insertions(+), 66 deletions(-) create mode 100644 neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java delete mode 100644 neoemf-io/src/test/java/writer/json/JsonWriterTest.java create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml create mode 100644 neoemf-io/src/test/resources/test-output/simplestClass/test-jackson-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/test-write.json diff --git a/neoemf-core/pom.xml b/neoemf-core/pom.xml index 508461ea67..12abdd0852 100644 --- a/neoemf-core/pom.xml +++ b/neoemf-core/pom.xml @@ -143,6 +143,12 @@ true pom + + com.google.code.findbugs + jsr305 + 3.0.2 + compile + diff --git a/neoemf-io/pom.xml b/neoemf-io/pom.xml index 226acdf509..5efd22eaba 100644 --- a/neoemf-io/pom.xml +++ b/neoemf-io/pom.xml @@ -186,6 +186,10 @@ pom test + + org.eclipse.emf + org.eclipse.emf.ecore.xmi + diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java index 7b8b5f3117..b7e2db891d 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -13,6 +13,7 @@ public class JsonStreamWriter extends AbstractJsonStreamWriter { protected final ObjectMapper mapper; @Nonnull protected final JsonGenerator jGenerator; + protected int id; /** * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. @@ -23,6 +24,13 @@ public JsonStreamWriter(OutputStream stream) throws IOException { super(stream); mapper = new ObjectMapper(); jGenerator = mapper.getFactory().createGenerator(target); + id = 0; + } + + private int nextId() { + int temp = id; + id++; + return temp; } @Override @@ -33,6 +41,7 @@ protected void writeStartDocument() throws IOException { @Override protected void writeStartElement(String name) throws IOException { jGenerator.writeStartObject(); + // jGenerator.writeFieldName(); } @Override diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java new file mode 100644 index 0000000000..8ffea42acb --- /dev/null +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java @@ -0,0 +1,81 @@ +package fr.inria.atlanmod.neoemf.io.json; + +import fr.inria.atlanmod.neoemf.data.im.DefaultInMemoryBackend; +import fr.inria.atlanmod.neoemf.data.mapping.DataMapper; +import fr.inria.atlanmod.neoemf.io.Migrator; +import fr.inria.atlanmod.neoemf.tests.sample.Node; +import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; +import fr.inria.atlanmod.neoemf.tests.sample.Value; +import fr.inria.atlanmod.neoemf.tests.sample.impl.ValueImpl; +import org.atlanmod.commons.log.Log; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.emfjson.jackson.resource.JsonResourceFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; + +class JsonWriterTest { + // Get the factory + private static final SampleFactory factory = SampleFactory.eINSTANCE; + + static void populateResource(Resource resource) { + Value val = factory.createValue(); + val.setValue(10); + + resource.getContents().addAll(Arrays.asList( + val + )); + } + + static void testWrite(String targetPath) throws IOException { + // java to emfjson-jackson (for testing/comparison purpose) + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry() + .getExtensionToFactoryMap() + .put("json", new JsonResourceFactory()); + Resource resource = resourceSet.createResource(URI.createFileURI(targetPath + "test-jackson-write.json")); + populateResource(resource); + resource.save(null); + + try (DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new FileInputStream(targetPath + "test-jackson-write.json")) { + // java to xmi + Migrator.fromXmi(in) + .toMapper(mapper) + .migrate(); + Log.info("Exporting to file... [{0}]", targetPath + "test-write.xmi"); + File targetFileXMI = new File(targetPath + "test-write.xmi"); + Migrator.fromMapper(mapper). + toXmi(targetFileXMI, false) + .migrate(); + + // java to json + Log.info("Exporting to file... [{0}]", targetPath + "test-write.json"); + File targetFileJSON = new File(targetPath + "test-write.json"); + Migrator.fromMapper(mapper) + .toJson(targetFileJSON) + .migrate(); + } + + // Comparing models loaded from XMI (EMF/NeoEMF reader) and JSON (emfjson-jackson reader) + /* + EObject actual = ResourceManager.load(URI.createFileURI(targetFile.toString())); + EObject expected = ResourceManager.load(uri); + + ModelComparisonUtils.assertEObjectAreEqual(actual, expected); + + actual.eResource().unload(); + expected.eResource().unload(); + */ + } + + public static void main(String[] args) throws IOException { + String targePath = "neoemf-io/src/test/resources/test-output/simplestClass/"; + testWrite(targePath); + } +} diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/reader/XmiReaderTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/reader/XmiReaderTest.java index c25bcc2256..2dbf9648e7 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/reader/XmiReaderTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/reader/XmiReaderTest.java @@ -353,7 +353,7 @@ private InMemoryElement readResource(URI uri) throws IOException { try (InputStream in = new URL(uri.toString()).openStream()) { Migrator.fromXmi(in) - //.to(writer) TODO + // .to(writer) // TODO .withCounter() .withTimer() // .withLogger() diff --git a/neoemf-io/src/test/java/writer/json/JsonWriterTest.java b/neoemf-io/src/test/java/writer/json/JsonWriterTest.java deleted file mode 100644 index cdb577448b..0000000000 --- a/neoemf-io/src/test/java/writer/json/JsonWriterTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package writer.json; - -import fr.inria.atlanmod.neoemf.data.Backend; -import fr.inria.atlanmod.neoemf.data.im.DefaultInMemoryBackend; -import fr.inria.atlanmod.neoemf.data.mapping.DataMapper; -import fr.inria.atlanmod.neoemf.io.Migrator; -import fr.inria.atlanmod.neoemf.io.provider.UriProvider; -import fr.inria.atlanmod.neoemf.io.util.ResourceManager; -import fr.inria.atlanmod.neoemf.util.ModelComparisonUtils; -import org.atlanmod.commons.AbstractFileBasedTest; -import org.atlanmod.commons.log.Log; -import org.atlanmod.commons.primitive.Strings; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ArgumentsSource; -import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.ValueSource; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; - -class JsonWriterTest { - static void testWrite(String sourcePath, String targetPath) throws IOException { - Log.info("Exporting to file... [{0}]", targetPath); - File targetFile = new File(targetPath); - - try (DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new FileInputStream(sourcePath)) { - Migrator.fromXmi(in).toMapper(mapper).migrate(); - - Migrator.fromMapper(mapper) - .toJson(targetFile) - .migrate(); - } - - // Comparing with EMF - /* - EObject actual = ResourceManager.load(URI.createFileURI(targetFile.toString())); - EObject expected = ResourceManager.load(uri); - - ModelComparisonUtils.assertEObjectAreEqual(actual, expected); - - actual.eResource().unload(); - expected.eResource().unload(); - */ - } - - public static void main(String[] args) throws IOException { - String sourcePath = "neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore"; - String targePath = "neoemf-io/src/test/resources/test-output/test-write.json"; - testWrite(sourcePath, targePath); - } -} diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird index 4c88823b55..e961760752 100644 --- a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird @@ -9,7 +9,7 @@ - + @@ -290,9 +290,8 @@ KEEP_LOCATION KEEP_SIZE KEEP_RATIO - - italic - + + diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore index 8a34d24eb3..d88b74a8f0 100644 --- a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore @@ -11,7 +11,7 @@
- + diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel new file mode 100644 index 0000000000..e33ac6c493 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel @@ -0,0 +1,16 @@ + + + Sample.ecore + + + + + + diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties new file mode 100644 index 0000000000..d54d9dc3ad --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties @@ -0,0 +1,9 @@ +# + +bin.includes = .,\ + model/,\ + plugin.xml,\ + plugin.properties +jars.compile.order = . +source.. = src-gen/ +output.. = bin/ diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties new file mode 100644 index 0000000000..e27e39b957 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties @@ -0,0 +1,4 @@ +# + +pluginName = Sample Model +providerName = www.example.org diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml new file mode 100644 index 0000000000..bab04ba4f5 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/neoemf-io/src/test/resources/test-output/simplestClass/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/simplestClass/test-jackson-write.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/neoemf-io/src/test/resources/test-output/test-write.json b/neoemf-io/src/test/resources/test-output/test-write.json deleted file mode 100644 index 0637a088a0..0000000000 --- a/neoemf-io/src/test/resources/test-output/test-write.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file From 4110f1dae895ac9c56a3c8b075fafaf8ab6290cf Mon Sep 17 00:00:00 2001 From: DaikiKaminari <52349037+DaikiKaminari@users.noreply.github.com> Date: Tue, 23 Nov 2021 17:49:11 +0100 Subject: [PATCH 08/21] Latest tests --- neoemf-io/pom.xml | 1 + .../io/writer/json/JsonStreamWriter.java | 7 +++-- .../neoemf/io/json/JsonWriterTest.java | 26 +++++++++++-------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/neoemf-io/pom.xml b/neoemf-io/pom.xml index 5efd22eaba..5c5a7ec7ae 100644 --- a/neoemf-io/pom.xml +++ b/neoemf-io/pom.xml @@ -139,6 +139,7 @@ emfjson-jackson 1.3.0 bundle + test diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java index b7e2db891d..212eaf3fe9 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -41,22 +41,21 @@ protected void writeStartDocument() throws IOException { @Override protected void writeStartElement(String name) throws IOException { jGenerator.writeStartObject(); - // jGenerator.writeFieldName(); } @Override protected void writeAttribute(String name, String value) throws IOException { - + jGenerator.writeStringField(name, value); } @Override protected void writeCharacters(String characters) throws IOException { - + jGenerator.writeString(characters); } @Override protected void writeEndElement() throws IOException { - + jGenerator.writeEndObject(); } @Override diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java index 8ffea42acb..b98644d2d6 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java @@ -33,6 +33,14 @@ static void populateResource(Resource resource) { )); } + static void populateResource2(Resource resource) { + Node node = factory.createLocalNode(); + node.setLabel("Test"); + resource.getContents().addAll(Arrays.asList( + node + )); + } + static void testWrite(String targetPath) throws IOException { // java to emfjson-jackson (for testing/comparison purpose) ResourceSet resourceSet = new ResourceSetImpl(); @@ -40,20 +48,14 @@ static void testWrite(String targetPath) throws IOException { .getExtensionToFactoryMap() .put("json", new JsonResourceFactory()); Resource resource = resourceSet.createResource(URI.createFileURI(targetPath + "test-jackson-write.json")); - populateResource(resource); + populateResource(resource); // FIXME not working : error resource.save(null); - try (DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new FileInputStream(targetPath + "test-jackson-write.json")) { - // java to xmi - Migrator.fromXmi(in) - .toMapper(mapper) - .migrate(); - Log.info("Exporting to file... [{0}]", targetPath + "test-write.xmi"); - File targetFileXMI = new File(targetPath + "test-write.xmi"); - Migrator.fromMapper(mapper). - toXmi(targetFileXMI, false) - .migrate(); + // java to xmi + // TODO save + /* + try (DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new FileInputStream(targetPath + "input-test-file.xmi")) { // java to json Log.info("Exporting to file... [{0}]", targetPath + "test-write.json"); File targetFileJSON = new File(targetPath + "test-write.json"); @@ -62,6 +64,8 @@ static void testWrite(String targetPath) throws IOException { .migrate(); } + */ + // Comparing models loaded from XMI (EMF/NeoEMF reader) and JSON (emfjson-jackson reader) /* EObject actual = ResourceManager.load(URI.createFileURI(targetFile.toString())); From 51face7822103c4f4385c808d783851b607dc76a Mon Sep 17 00:00:00 2001 From: DaikiKaminari <52349037+DaikiKaminari@users.noreply.github.com> Date: Thu, 25 Nov 2021 22:21:05 +0100 Subject: [PATCH 09/21] Fix bug with jackson --- neoemf-io/pom.xml | 2 +- .../neoemf/io/json/JsonWriterTest.java | 22 ++++++++++++++----- .../simplestClass/test-jackson-write.json | 4 ++++ .../test-output/simplestClass/test-write.xmi | 2 ++ 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 neoemf-io/src/test/resources/test-output/simplestClass/test-write.xmi diff --git a/neoemf-io/pom.xml b/neoemf-io/pom.xml index 5c5a7ec7ae..f94e315317 100644 --- a/neoemf-io/pom.xml +++ b/neoemf-io/pom.xml @@ -22,7 +22,7 @@ 1.0-2 4.2.1 4.4.1 - 2.12.5 + 2.13.0 diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java index b98644d2d6..00856bd10d 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java @@ -12,6 +12,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; import org.emfjson.jackson.resource.JsonResourceFactory; import java.io.File; @@ -47,16 +48,27 @@ static void testWrite(String targetPath) throws IOException { resourceSet.getResourceFactoryRegistry() .getExtensionToFactoryMap() .put("json", new JsonResourceFactory()); + Log.info("Exporting to file... [{0}]", targetPath + "test-jackson-write.json"); Resource resource = resourceSet.createResource(URI.createFileURI(targetPath + "test-jackson-write.json")); - populateResource(resource); // FIXME not working : error + populateResource(resource); resource.save(null); // java to xmi - // TODO save + ResourceSet resourceSet2 = new ResourceSetImpl(); + resourceSet2.getResourceFactoryRegistry() + .getExtensionToFactoryMap() + .put("xmi", new XMIResourceFactoryImpl()); + Log.info("Exporting to file... [{0}]", targetPath + "test-write.xmi"); + Resource resource2 = resourceSet2.createResource(URI.createFileURI(targetPath + "test-write.xmi")); + populateResource(resource2); + resource2.save(null); - /* - try (DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new FileInputStream(targetPath + "input-test-file.xmi")) { + try (DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new FileInputStream(targetPath + "test-write.xmi")) { // java to json + Migrator.fromXmi(in) + .toMapper(mapper) + .migrate(); + Log.info("Exporting to file... [{0}]", targetPath + "test-write.json"); File targetFileJSON = new File(targetPath + "test-write.json"); Migrator.fromMapper(mapper) @@ -64,8 +76,6 @@ static void testWrite(String targetPath) throws IOException { .migrate(); } - */ - // Comparing models loaded from XMI (EMF/NeoEMF reader) and JSON (emfjson-jackson reader) /* EObject actual = ResourceManager.load(URI.createFileURI(targetFile.toString())); diff --git a/neoemf-io/src/test/resources/test-output/simplestClass/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/simplestClass/test-jackson-write.json index e69de29bb2..662a6da128 100644 --- a/neoemf-io/src/test/resources/test-output/simplestClass/test-jackson-write.json +++ b/neoemf-io/src/test/resources/test-output/simplestClass/test-jackson-write.json @@ -0,0 +1,4 @@ +{ + "eClass" : "http://www.neoemf.com/tests/sample#//Value", + "value" : 10 +} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/simplestClass/test-write.xmi b/neoemf-io/src/test/resources/test-output/simplestClass/test-write.xmi new file mode 100644 index 0000000000..91c32c8f86 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/simplestClass/test-write.xmi @@ -0,0 +1,2 @@ + + From a9235e99ba378eb75f52901f8fd88cf8c46b2909 Mon Sep 17 00:00:00 2001 From: DaikiKaminari <52349037+DaikiKaminari@users.noreply.github.com> Date: Mon, 29 Nov 2021 20:17:54 +0100 Subject: [PATCH 10/21] Implementation of attribute serialization in json --- .../writer/json/AbstractJsonStreamWriter.java | 25 ++++++++++++--- .../io/writer/json/JsonStreamWriter.java | 8 +++-- .../neoemf/io/json/JsonWriterTest.java | 32 +++++-------------- .../test-output/simplestClass/test-write.json | 4 +++ 4 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 neoemf-io/src/test/resources/test-output/simplestClass/test-write.json diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java index de7e489e2a..e09a820deb 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java @@ -2,6 +2,7 @@ import fr.inria.atlanmod.neoemf.core.Id; import fr.inria.atlanmod.neoemf.io.proxy.ProxyAttribute; +import fr.inria.atlanmod.neoemf.io.proxy.ProxyElement; import fr.inria.atlanmod.neoemf.io.proxy.ProxyReference; import fr.inria.atlanmod.neoemf.io.writer.AbstractStreamWriter; @@ -22,22 +23,36 @@ public AbstractJsonStreamWriter(OutputStream stream) { @Override public void onInitialize() throws IOException { writeStartDocument(); - writeEndDocument(); } @Override - public void onAttribute(ProxyAttribute attribute, List values) throws IOException { + public final void onStartElement(ProxyElement element) throws IOException { + super.onStartElement(element); + writeStartElement(element.getMetaClass().getNamespace().getUri(), element.getName()); + } + @Override + public void onAttribute(ProxyAttribute attribute, List values) throws IOException { + System.out.println(attribute.getOrigin().getEAttributeType()); + if (!attribute.isMany()) { + writeAttribute(attribute.getName(), values.get(0)); + } else { + writeAttribute(attribute.getName(), values); + } } @Override public void onReference(ProxyReference reference, List values) throws IOException { + } + @Override + public void onEndElement() throws IOException { + writeEndElement(); } @Override public void onComplete() throws IOException { - + writeEndDocument(); } /** @@ -54,7 +69,7 @@ public void onComplete() throws IOException { * * @throws IOException if an I/O error occurs when writing */ - protected abstract void writeStartElement(String name) throws IOException; + protected abstract void writeStartElement(String namespace, String name) throws IOException; /** * Writes an attribute of the current element. @@ -64,7 +79,7 @@ public void onComplete() throws IOException { * * @throws IOException if an I/O error occurs when writing */ - protected abstract void writeAttribute(String name, String value) throws IOException; + protected abstract void writeAttribute(String name, Object value) throws IOException; /** * Writes characters. diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java index 212eaf3fe9..0540bf7fa8 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -24,6 +24,7 @@ public JsonStreamWriter(OutputStream stream) throws IOException { super(stream); mapper = new ObjectMapper(); jGenerator = mapper.getFactory().createGenerator(target); + jGenerator.useDefaultPrettyPrinter(); id = 0; } @@ -39,13 +40,14 @@ protected void writeStartDocument() throws IOException { } @Override - protected void writeStartElement(String name) throws IOException { + protected void writeStartElement(String namespace, String name) throws IOException { jGenerator.writeStartObject(); + jGenerator.writeStringField("eClass", namespace + "#//" + name); } @Override - protected void writeAttribute(String name, String value) throws IOException { - jGenerator.writeStringField(name, value); + protected void writeAttribute(String name, Object value) throws IOException { + jGenerator.writeObjectField(name, value); } @Override diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java index 00856bd10d..44396866a6 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java @@ -3,15 +3,16 @@ import fr.inria.atlanmod.neoemf.data.im.DefaultInMemoryBackend; import fr.inria.atlanmod.neoemf.data.mapping.DataMapper; import fr.inria.atlanmod.neoemf.io.Migrator; -import fr.inria.atlanmod.neoemf.tests.sample.Node; -import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; -import fr.inria.atlanmod.neoemf.tests.sample.Value; +import fr.inria.atlanmod.neoemf.tests.sample.*; +import fr.inria.atlanmod.neoemf.tests.sample.impl.TypeMapImpl; import fr.inria.atlanmod.neoemf.tests.sample.impl.ValueImpl; import org.atlanmod.commons.log.Log; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.util.EObjectEList; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; import org.emfjson.jackson.resource.JsonResourceFactory; @@ -28,20 +29,14 @@ class JsonWriterTest { static void populateResource(Resource resource) { Value val = factory.createValue(); val.setValue(10); + Value val2 = factory.createValue(); + val.setValue(12); resource.getContents().addAll(Arrays.asList( val )); } - static void populateResource2(Resource resource) { - Node node = factory.createLocalNode(); - node.setLabel("Test"); - resource.getContents().addAll(Arrays.asList( - node - )); - } - static void testWrite(String targetPath) throws IOException { // java to emfjson-jackson (for testing/comparison purpose) ResourceSet resourceSet = new ResourceSetImpl(); @@ -75,21 +70,10 @@ static void testWrite(String targetPath) throws IOException { .toJson(targetFileJSON) .migrate(); } - - // Comparing models loaded from XMI (EMF/NeoEMF reader) and JSON (emfjson-jackson reader) - /* - EObject actual = ResourceManager.load(URI.createFileURI(targetFile.toString())); - EObject expected = ResourceManager.load(uri); - - ModelComparisonUtils.assertEObjectAreEqual(actual, expected); - - actual.eResource().unload(); - expected.eResource().unload(); - */ } public static void main(String[] args) throws IOException { - String targePath = "neoemf-io/src/test/resources/test-output/simplestClass/"; - testWrite(targePath); + testWrite("neoemf-io/src/test/resources/test-output/simplestClass/"); + } } diff --git a/neoemf-io/src/test/resources/test-output/simplestClass/test-write.json b/neoemf-io/src/test/resources/test-output/simplestClass/test-write.json new file mode 100644 index 0000000000..48deeadd77 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/simplestClass/test-write.json @@ -0,0 +1,4 @@ +[ { + "eClass" : "http://www.neoemf.com/tests/sample#//Value", + "value" : 10 +} ] \ No newline at end of file From 8f2d113777d6f536972eddcea160169fcb7febcf Mon Sep 17 00:00:00 2001 From: DaikiKaminari Date: Tue, 28 Dec 2021 16:53:27 +0100 Subject: [PATCH 11/21] Added automated testing with JUnit for JsonWriter --- .../neoemf/io/json/JsonWriterTest.java | 79 ----- .../neoemf/io/writer/json/AttributeTest.java | 42 +++ .../neoemf/io/writer/json/Helper.java | 80 +++++ .../resources/model/subSampleModel/.gitkeep | 0 .../subSampleModel/simplestClass/Sample.aird | 314 ------------------ .../subSampleModel/simplestClass/Sample.ecore | 17 - .../simplestClass/Sample.genmodel | 16 - .../simplestClass/build.properties | 9 - .../simplestClass/plugin.properties | 4 - .../subSampleModel/simplestClass/plugin.xml | 32 -- .../multipleAttribute/test-jackson-write.json | 7 + .../multipleAttribute/test-write.xmi | 5 + .../singleAttribute}/test-jackson-write.json | 0 .../singleAttribute}/test-write.json | 0 .../singleAttribute}/test-write.xmi | 0 15 files changed, 134 insertions(+), 471 deletions(-) delete mode 100644 neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java create mode 100644 neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java create mode 100644 neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java delete mode 100644 neoemf-io/src/test/resources/model/subSampleModel/.gitkeep delete mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird delete mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore delete mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel delete mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties delete mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties delete mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml create mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-jackson-write.json create mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-write.xmi rename neoemf-io/src/test/resources/test-output/{simplestClass => AttributeTest/singleAttribute}/test-jackson-write.json (100%) rename neoemf-io/src/test/resources/test-output/{simplestClass => AttributeTest/singleAttribute}/test-write.json (100%) rename neoemf-io/src/test/resources/test-output/{simplestClass => AttributeTest/singleAttribute}/test-write.xmi (100%) diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java deleted file mode 100644 index 44396866a6..0000000000 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonWriterTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package fr.inria.atlanmod.neoemf.io.json; - -import fr.inria.atlanmod.neoemf.data.im.DefaultInMemoryBackend; -import fr.inria.atlanmod.neoemf.data.mapping.DataMapper; -import fr.inria.atlanmod.neoemf.io.Migrator; -import fr.inria.atlanmod.neoemf.tests.sample.*; -import fr.inria.atlanmod.neoemf.tests.sample.impl.TypeMapImpl; -import fr.inria.atlanmod.neoemf.tests.sample.impl.ValueImpl; -import org.atlanmod.commons.log.Log; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.emf.ecore.util.EObjectEList; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; -import org.emfjson.jackson.resource.JsonResourceFactory; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; - -class JsonWriterTest { - // Get the factory - private static final SampleFactory factory = SampleFactory.eINSTANCE; - - static void populateResource(Resource resource) { - Value val = factory.createValue(); - val.setValue(10); - Value val2 = factory.createValue(); - val.setValue(12); - - resource.getContents().addAll(Arrays.asList( - val - )); - } - - static void testWrite(String targetPath) throws IOException { - // java to emfjson-jackson (for testing/comparison purpose) - ResourceSet resourceSet = new ResourceSetImpl(); - resourceSet.getResourceFactoryRegistry() - .getExtensionToFactoryMap() - .put("json", new JsonResourceFactory()); - Log.info("Exporting to file... [{0}]", targetPath + "test-jackson-write.json"); - Resource resource = resourceSet.createResource(URI.createFileURI(targetPath + "test-jackson-write.json")); - populateResource(resource); - resource.save(null); - - // java to xmi - ResourceSet resourceSet2 = new ResourceSetImpl(); - resourceSet2.getResourceFactoryRegistry() - .getExtensionToFactoryMap() - .put("xmi", new XMIResourceFactoryImpl()); - Log.info("Exporting to file... [{0}]", targetPath + "test-write.xmi"); - Resource resource2 = resourceSet2.createResource(URI.createFileURI(targetPath + "test-write.xmi")); - populateResource(resource2); - resource2.save(null); - - try (DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new FileInputStream(targetPath + "test-write.xmi")) { - // java to json - Migrator.fromXmi(in) - .toMapper(mapper) - .migrate(); - - Log.info("Exporting to file... [{0}]", targetPath + "test-write.json"); - File targetFileJSON = new File(targetPath + "test-write.json"); - Migrator.fromMapper(mapper) - .toJson(targetFileJSON) - .migrate(); - } - } - - public static void main(String[] args) throws IOException { - testWrite("neoemf-io/src/test/resources/test-output/simplestClass/"); - - } -} diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java new file mode 100644 index 0000000000..191a778896 --- /dev/null +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java @@ -0,0 +1,42 @@ +package fr.inria.atlanmod.neoemf.io.writer.json; + +import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; +import fr.inria.atlanmod.neoemf.tests.sample.Value; +import org.eclipse.emf.ecore.resource.Resource; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.function.Consumer; + +public class AttributeTest { + // Get the factory + private static final SampleFactory factory = SampleFactory.eINSTANCE; + + @Test + void testSingleAttribute() { + Consumer populator = resource -> { + Value val = factory.createValue(); + val.setValue(10); + + resource.getContents().addAll(Arrays.asList( + val + )); + }; + Helper.testMigration(populator, "AttributeTest/singleAttribute/"); + } + + @Test + void testMultipleAttributes() { + Consumer populator = resource -> { + Value val = factory.createValue(); + val.setValue(10); + Value val2 = factory.createValue(); + val2.setValue(12); + + resource.getContents().addAll(Arrays.asList( + val, val2 + )); + }; + Helper.testMigration(populator, "AttributeTest/multipleAttribute/"); + } +} diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java new file mode 100644 index 0000000000..7dadacbabd --- /dev/null +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java @@ -0,0 +1,80 @@ +package fr.inria.atlanmod.neoemf.io.writer.json; + +import fr.inria.atlanmod.neoemf.data.im.DefaultInMemoryBackend; +import fr.inria.atlanmod.neoemf.data.mapping.DataMapper; +import fr.inria.atlanmod.neoemf.io.Migrator; +import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; +import org.atlanmod.commons.log.Log; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; +import org.emfjson.jackson.resource.JsonResourceFactory; +import org.jetbrains.annotations.NotNull; + +import java.io.*; +import java.util.function.Consumer; + +public class Helper { + private static final String testOutputPath = "src/test/resources/test-output/"; + + private static Resource resourceEmfJsonJackson; + private static Resource resourceXmi; + private static String currentTargetPath; + + static boolean deleteDirectory(String path) { + File directoryToBeDeleted = new File(path); + File[] allContents = directoryToBeDeleted.listFiles(); + if (allContents != null) { + for (File file : allContents) { + deleteDirectory(file.getPath()); + } + } + return directoryToBeDeleted.delete(); + } + + static void testMigration(Consumer populator, @NotNull String targetPath) { + try { + currentTargetPath = testOutputPath + targetPath; + deleteDirectory(currentTargetPath); + + // java to emfjson-jackson (for testing/comparison purpose) + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry() + .getExtensionToFactoryMap() + .put("json", new JsonResourceFactory()); + Log.info("Exporting to file... [{0}]", currentTargetPath + "test-jackson-write.json"); + resourceEmfJsonJackson = resourceSet.createResource(URI.createFileURI(currentTargetPath + "test-jackson-write.json")); + populator.accept(resourceEmfJsonJackson); + resourceEmfJsonJackson.save(null); + + // java to xmi (to use in the Migrator input) + ResourceSet resourceSet2 = new ResourceSetImpl(); + resourceSet2.getResourceFactoryRegistry() + .getExtensionToFactoryMap() + .put("xmi", new XMIResourceFactoryImpl()); + Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.xmi"); + resourceXmi = resourceSet2.createResource(URI.createFileURI(currentTargetPath + "test-write.xmi")); + populator.accept(resourceXmi); + resourceXmi.save(null); + + DataMapper mapper = new DefaultInMemoryBackend(); + InputStream in = new FileInputStream(currentTargetPath + "test-write.xmi"); + // xmi to mapper + Migrator.fromXmi(in) + .toMapper(mapper) + .migrate(); + + // mapper to json (our implementation) + Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.json"); + File targetFileJSON = new File(currentTargetPath + "test-write.json"); + Migrator.fromMapper(mapper) + .toJson(targetFileJSON) + .migrate(); + + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/neoemf-io/src/test/resources/model/subSampleModel/.gitkeep b/neoemf-io/src/test/resources/model/subSampleModel/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird deleted file mode 100644 index e961760752..0000000000 --- a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird +++ /dev/null @@ -1,314 +0,0 @@ - - - - Sample.ecore - Sample.genmodel - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - italic - - - - - - - - - - - - - - - - italic - - - - - - - - - - italic - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore deleted file mode 100644 index d88b74a8f0..0000000000 --- a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore +++ /dev/null @@ -1,17 +0,0 @@ - - - -
-
-
-
-
-
-
-
- - - - - diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel deleted file mode 100644 index e33ac6c493..0000000000 --- a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel +++ /dev/null @@ -1,16 +0,0 @@ - - - Sample.ecore - - - - - - diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties deleted file mode 100644 index d54d9dc3ad..0000000000 --- a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties +++ /dev/null @@ -1,9 +0,0 @@ -# - -bin.includes = .,\ - model/,\ - plugin.xml,\ - plugin.properties -jars.compile.order = . -source.. = src-gen/ -output.. = bin/ diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties deleted file mode 100644 index e27e39b957..0000000000 --- a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties +++ /dev/null @@ -1,4 +0,0 @@ -# - -pluginName = Sample Model -providerName = www.example.org diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml deleted file mode 100644 index bab04ba4f5..0000000000 --- a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-jackson-write.json new file mode 100644 index 0000000000..309b6d5ca1 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-jackson-write.json @@ -0,0 +1,7 @@ +[ { + "eClass" : "http://www.neoemf.com/tests/sample#//Value", + "value" : 10 +}, { + "eClass" : "http://www.neoemf.com/tests/sample#//Value", + "value" : 12 +} ] \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-write.xmi new file mode 100644 index 0000000000..3a124a1849 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-write.xmi @@ -0,0 +1,5 @@ + + + + + diff --git a/neoemf-io/src/test/resources/test-output/simplestClass/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json similarity index 100% rename from neoemf-io/src/test/resources/test-output/simplestClass/test-jackson-write.json rename to neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json diff --git a/neoemf-io/src/test/resources/test-output/simplestClass/test-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.json similarity index 100% rename from neoemf-io/src/test/resources/test-output/simplestClass/test-write.json rename to neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.json diff --git a/neoemf-io/src/test/resources/test-output/simplestClass/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi similarity index 100% rename from neoemf-io/src/test/resources/test-output/simplestClass/test-write.xmi rename to neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi From 3c4d4b282997abc1de2bc6b315bc67228b9c921f Mon Sep 17 00:00:00 2001 From: DaikiKaminari Date: Tue, 28 Dec 2021 17:00:30 +0100 Subject: [PATCH 12/21] Removed files generated during tests --- .gitignore | 3 ++- .../multipleAttribute/test-jackson-write.json | 7 ------- .../AttributeTest/multipleAttribute/test-write.xmi | 5 ----- .../AttributeTest/singleAttribute/test-jackson-write.json | 4 ---- .../AttributeTest/singleAttribute/test-write.json | 4 ---- .../AttributeTest/singleAttribute/test-write.xmi | 2 -- 6 files changed, 2 insertions(+), 23 deletions(-) delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-jackson-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-write.xmi delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi diff --git a/.gitignore b/.gitignore index 5d5cde8bc6..caf9fa0adf 100644 --- a/.gitignore +++ b/.gitignore @@ -133,5 +133,6 @@ **/java-gen **/src-gen/ - +### Tests +neoemf-io/src/test/resources/test-output/* diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-jackson-write.json deleted file mode 100644 index 309b6d5ca1..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-jackson-write.json +++ /dev/null @@ -1,7 +0,0 @@ -[ { - "eClass" : "http://www.neoemf.com/tests/sample#//Value", - "value" : 10 -}, { - "eClass" : "http://www.neoemf.com/tests/sample#//Value", - "value" : 12 -} ] \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-write.xmi deleted file mode 100644 index 3a124a1849..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttribute/test-write.xmi +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json deleted file mode 100644 index 662a6da128..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "eClass" : "http://www.neoemf.com/tests/sample#//Value", - "value" : 10 -} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.json deleted file mode 100644 index 48deeadd77..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.json +++ /dev/null @@ -1,4 +0,0 @@ -[ { - "eClass" : "http://www.neoemf.com/tests/sample#//Value", - "value" : 10 -} ] \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi deleted file mode 100644 index 91c32c8f86..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi +++ /dev/null @@ -1,2 +0,0 @@ - - From 2d5efb95ccaffa26a34929f59fa37d06acb38e9d Mon Sep 17 00:00:00 2001 From: DaikiKaminari Date: Fri, 31 Dec 2021 17:54:49 +0100 Subject: [PATCH 13/21] Added test for multi valued attributes --- .../neoemf/io/writer/json/AttributeTest.java | 25 ++ .../neoemf/io/writer/json/Helper.java | 84 +++--- .../src/test/resources/model/Sample.aird | 263 +++++++++++------- 3 files changed, 237 insertions(+), 135 deletions(-) diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java index 191a778896..8a67d96dfd 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java @@ -1,7 +1,10 @@ package fr.inria.atlanmod.neoemf.io.writer.json; +import fr.inria.atlanmod.neoemf.tests.sample.Node; import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; import fr.inria.atlanmod.neoemf.tests.sample.Value; +import fr.inria.atlanmod.neoemf.tests.sample.impl.LocalNodeImpl; +import fr.inria.atlanmod.neoemf.tests.sample.impl.PhysicalNodeImpl; import org.eclipse.emf.ecore.resource.Resource; import org.junit.jupiter.api.Test; @@ -39,4 +42,26 @@ void testMultipleAttributes() { }; Helper.testMigration(populator, "AttributeTest/multipleAttribute/"); } + + @Test + void testMultiValuedAttribute() { + Consumer populator = resource -> { + Node node = factory.createPhysicalNode(); + node.setLabel("parentNode"); + Node node1 = factory.createPhysicalNode(); + node1.setLabel("childrenNode1"); + node1.setParent(node); + Node node2 = factory.createPhysicalNode(); + node2.setLabel("childrenNode2"); + node2.setParent(node); + + node.getChildren().add(node1); + node.getChildren().add(node2); + + resource.getContents().addAll(Arrays.asList( + node, node1, node2 + )); + }; + Helper.testMigration(populator, "AttributeTest/multiValuedAttribute/"); + } } diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java index 7dadacbabd..785c266e53 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java @@ -34,44 +34,64 @@ static boolean deleteDirectory(String path) { return directoryToBeDeleted.delete(); } + static private void saveWithEmfJsonJackson(Consumer populator, @NotNull String targetPath) throws IOException { + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry() + .getExtensionToFactoryMap() + .put("json", new JsonResourceFactory()); + Log.info("Exporting to file... [{0}]", currentTargetPath + "test-jackson-write.json"); + resourceEmfJsonJackson = resourceSet.createResource(URI.createFileURI(currentTargetPath + "test-jackson-write.json")); + populator.accept(resourceEmfJsonJackson); + resourceEmfJsonJackson.save(null); + } + + static private void saveWithEmfXmi(Consumer populator, @NotNull String targetPath) throws IOException { + ResourceSet resourceSet2 = new ResourceSetImpl(); + resourceSet2.getResourceFactoryRegistry() + .getExtensionToFactoryMap() + .put("xmi", new XMIResourceFactoryImpl()); + Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.xmi"); + resourceXmi = resourceSet2.createResource(URI.createFileURI(currentTargetPath + "test-write.xmi")); + populator.accept(resourceXmi); + resourceXmi.save(null); + } + + static private DataMapper getMapperFromXmi() throws IOException { + DataMapper mapper = new DefaultInMemoryBackend(); + InputStream in = new FileInputStream(currentTargetPath + "test-write.xmi"); + // xmi to mapper + Migrator.fromXmi(in) + .toMapper(mapper) + .migrate(); + return mapper; + } + + static private void mapperToJson(DataMapper mapper) throws IOException { + // mapper to json (our implementation) + Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.json"); + File targetFileJSON = new File(currentTargetPath + "test-write.json"); + Migrator.fromMapper(mapper) + .toJson(targetFileJSON) + .migrate(); + } + + static void testMigration(Consumer populator, @NotNull String targetPath) { try { currentTargetPath = testOutputPath + targetPath; deleteDirectory(currentTargetPath); // java to emfjson-jackson (for testing/comparison purpose) - ResourceSet resourceSet = new ResourceSetImpl(); - resourceSet.getResourceFactoryRegistry() - .getExtensionToFactoryMap() - .put("json", new JsonResourceFactory()); - Log.info("Exporting to file... [{0}]", currentTargetPath + "test-jackson-write.json"); - resourceEmfJsonJackson = resourceSet.createResource(URI.createFileURI(currentTargetPath + "test-jackson-write.json")); - populator.accept(resourceEmfJsonJackson); - resourceEmfJsonJackson.save(null); - - // java to xmi (to use in the Migrator input) - ResourceSet resourceSet2 = new ResourceSetImpl(); - resourceSet2.getResourceFactoryRegistry() - .getExtensionToFactoryMap() - .put("xmi", new XMIResourceFactoryImpl()); - Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.xmi"); - resourceXmi = resourceSet2.createResource(URI.createFileURI(currentTargetPath + "test-write.xmi")); - populator.accept(resourceXmi); - resourceXmi.save(null); - - DataMapper mapper = new DefaultInMemoryBackend(); - InputStream in = new FileInputStream(currentTargetPath + "test-write.xmi"); - // xmi to mapper - Migrator.fromXmi(in) - .toMapper(mapper) - .migrate(); - - // mapper to json (our implementation) - Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.json"); - File targetFileJSON = new File(currentTargetPath + "test-write.json"); - Migrator.fromMapper(mapper) - .toJson(targetFileJSON) - .migrate(); + saveWithEmfJsonJackson(populator, targetPath); + + // java to xmi (used in the Migrator input) + saveWithEmfXmi(populator, targetPath); + + // migrate xmi to mapper + DataMapper mapper = getMapperFromXmi(); + + // migrate mapper to json + // mapperToJson(mapper); } catch (IOException e) { e.printStackTrace(); diff --git a/neoemf-io/src/test/resources/model/Sample.aird b/neoemf-io/src/test/resources/model/Sample.aird index 46676ded7a..325b8fa636 100644 --- a/neoemf-io/src/test/resources/model/Sample.aird +++ b/neoemf-io/src/test/resources/model/Sample.aird @@ -1,11 +1,11 @@ - + Sample.ecore Sample.genmodel - + @@ -42,7 +42,7 @@ - + @@ -55,7 +55,7 @@ - + @@ -68,7 +68,7 @@ - + @@ -81,7 +81,7 @@ - + @@ -98,7 +98,7 @@ - + @@ -107,7 +107,7 @@ - + @@ -116,7 +116,7 @@ - + @@ -133,7 +133,7 @@ - + @@ -146,7 +146,7 @@ - + @@ -159,7 +159,7 @@ - + @@ -204,7 +204,7 @@ - + @@ -225,7 +225,7 @@ - + @@ -238,7 +238,7 @@ - + @@ -251,7 +251,7 @@ - + @@ -260,7 +260,7 @@ - + @@ -269,7 +269,7 @@ - + @@ -278,7 +278,7 @@ - + @@ -287,7 +287,7 @@ - + @@ -300,7 +300,7 @@ - + @@ -321,71 +321,71 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -395,7 +395,7 @@ - + @@ -417,209 +417,209 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -657,33 +657,33 @@ - + - + - + - + - + - + - + - + @@ -692,10 +692,10 @@ - + - + @@ -721,17 +721,17 @@ - + - + - + - + @@ -785,6 +785,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -817,6 +820,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -837,6 +843,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -857,6 +866,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -873,6 +885,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -897,6 +912,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -905,6 +923,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -913,6 +934,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -937,6 +961,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -953,6 +980,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -969,6 +999,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -1045,6 +1078,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -1077,6 +1113,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -1093,6 +1132,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO italic @@ -1110,6 +1152,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -1118,6 +1163,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -1126,6 +1174,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -1134,6 +1185,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO @@ -1142,6 +1196,9 @@ + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO From 59912df684266eec59d63ed7bc78ffaf66300de7 Mon Sep 17 00:00:00 2001 From: Mamadou Diallo Date: Tue, 28 Dec 2021 14:59:49 +0100 Subject: [PATCH 14/21] reader start --- neoemf-core/pom.xml | 6 +++ neoemf-data/berkeleydb/pom.xml | 6 +++ neoemf-data/blueprints/core/pom.xml | 6 +++ neoemf-data/blueprints/neo4j/pom.xml | 6 +++ neoemf-data/blueprints/pom.xml | 8 ++++ neoemf-data/hbase/pom.xml | 6 +++ neoemf-data/mapdb/pom.xml | 6 +++ neoemf-data/mongodb/pom.xml | 6 +++ neoemf-data/pom.xml | 6 +++ neoemf-io/pom.xml | 21 ++++++++- .../reader/json/AbstractJsonStreamReader.java | 44 +++++++++++++++++-- .../io/reader/json/JsonReaderHelper.java | 17 +++++++ .../atlanmod/neoemf/io/reader/json/User.java | 39 ++++++++++++++++ .../neoemf/io/util/JsonConstants.java | 11 +++++ neoemf-io/src/main/resources/data.json | 5 +++ .../neoemf/io/json/JsonReaderTest.java | 44 +++++++++++++++++++ .../neoemf/io/util/ResourceManager.java | 6 ++- neoemf-tests/pom.xml | 6 +++ neoemf-utils/p2/pom.xml | 8 ++++ neoemf-utils/pom.xml | 6 +++ pom.xml | 6 +++ 21 files changed, 262 insertions(+), 7 deletions(-) create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/JsonReaderHelper.java create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/User.java create mode 100644 neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/util/JsonConstants.java create mode 100644 neoemf-io/src/main/resources/data.json create mode 100644 neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonReaderTest.java diff --git a/neoemf-core/pom.xml b/neoemf-core/pom.xml index 12abdd0852..172654c3aa 100644 --- a/neoemf-core/pom.xml +++ b/neoemf-core/pom.xml @@ -149,6 +149,12 @@ 3.0.2 compile + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/neoemf-data/berkeleydb/pom.xml b/neoemf-data/berkeleydb/pom.xml index b748ae7a20..52f14f76ce 100644 --- a/neoemf-data/berkeleydb/pom.xml +++ b/neoemf-data/berkeleydb/pom.xml @@ -27,6 +27,12 @@ com.sleepycat je + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/neoemf-data/blueprints/core/pom.xml b/neoemf-data/blueprints/core/pom.xml index 0aaecb6bf8..7029fcd377 100644 --- a/neoemf-data/blueprints/core/pom.xml +++ b/neoemf-data/blueprints/core/pom.xml @@ -39,6 +39,12 @@ org.eclipse.emf.ecore test + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/neoemf-data/blueprints/neo4j/pom.xml b/neoemf-data/blueprints/neo4j/pom.xml index ba214588c7..6403c03acb 100644 --- a/neoemf-data/blueprints/neo4j/pom.xml +++ b/neoemf-data/blueprints/neo4j/pom.xml @@ -72,6 +72,12 @@ test-jar test + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/neoemf-data/blueprints/pom.xml b/neoemf-data/blueprints/pom.xml index 02507fae72..c5d7b7a585 100644 --- a/neoemf-data/blueprints/pom.xml +++ b/neoemf-data/blueprints/pom.xml @@ -24,5 +24,13 @@ 2.6.0 1.10 + + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + + diff --git a/neoemf-data/hbase/pom.xml b/neoemf-data/hbase/pom.xml index c1f7e9ee97..ee21fda8a0 100644 --- a/neoemf-data/hbase/pom.xml +++ b/neoemf-data/hbase/pom.xml @@ -97,6 +97,12 @@ junit-vintage-engine ${junit.version} + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/neoemf-data/mapdb/pom.xml b/neoemf-data/mapdb/pom.xml index 3d15e0e12f..3835e016d0 100644 --- a/neoemf-data/mapdb/pom.xml +++ b/neoemf-data/mapdb/pom.xml @@ -36,6 +36,12 @@ --> + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/neoemf-data/mongodb/pom.xml b/neoemf-data/mongodb/pom.xml index e77efc173d..d2eaa92990 100644 --- a/neoemf-data/mongodb/pom.xml +++ b/neoemf-data/mongodb/pom.xml @@ -36,6 +36,12 @@ de.flapdoodle.embed.mongo compile + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/neoemf-data/pom.xml b/neoemf-data/pom.xml index d6b01fec7d..08db16082e 100644 --- a/neoemf-data/pom.xml +++ b/neoemf-data/pom.xml @@ -104,6 +104,12 @@ ${project.version} runtime + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/neoemf-io/pom.xml b/neoemf-io/pom.xml index f94e315317..9bcf3b66e6 100644 --- a/neoemf-io/pom.xml +++ b/neoemf-io/pom.xml @@ -101,7 +101,7 @@ com.fasterxml.jackson.core - jackson-annotations + jackson-core ${jackson.version} @@ -134,6 +134,20 @@ assertj-core + + + org.emfjson + emfjson-jackson + 1.3.0 + + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + org.emfjson emfjson-jackson @@ -144,12 +158,15 @@ + + @@ -160,7 +177,7 @@ org.eclipse.platform org.eclipse.core.runtime - [3.20.0,) + 3.23.0 test diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java index b7b46707b5..b7b736fe5f 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java @@ -1,15 +1,53 @@ package fr.inria.atlanmod.neoemf.io.reader.json; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.jsonldjava.utils.Obj; import fr.inria.atlanmod.neoemf.io.reader.AbstractStreamReader; +import org.apache.commons.io.IOUtils; +import org.emfjson.jackson.resource.JsonResourceFactory; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; -import java.io.InputStream; +import org.eclipse.emf.ecore.resource.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Map; + public class AbstractJsonStreamReader extends AbstractStreamReader { + private final Logger logger = LoggerFactory.getLogger(AbstractJsonStreamReader.class); + + public AbstractJsonStreamReader(){ + JsonReaderHelper.resourceSet.getResourceFactoryRegistry() + .getExtensionToFactoryMap() + .put("json", new JsonResourceFactory()); + + } + @Override - public void parse(InputStream stream) throws IOException { + public void parse(@NotNull InputStream stream) throws IOException { + + + /* + resource = JsonReaderHelper.mapper.reader() + .withAttribute(EMFContext.Attributes.RESOURCE_SET, JsonReaderHelper.resourceSet) + .withAttribute(EMFContext.Attributes.RESOURCE_URI, JsonReaderHelper.resourceData) + .forType(Resource.class) + .readValue(stream); + */ + + String theString = IOUtils.toString(stream, StandardCharsets.UTF_8); + ObjectMapper mapper = new ObjectMapper(); + Reader reader = new StringReader(theString); + } diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/JsonReaderHelper.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/JsonReaderHelper.java new file mode 100644 index 0000000000..33b67893ee --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/JsonReaderHelper.java @@ -0,0 +1,17 @@ +package fr.inria.atlanmod.neoemf.io.reader.json; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; + +import java.io.InputStream; + + +public class JsonReaderHelper { + + public static final ObjectMapper mapper = new ObjectMapper(); + public static final ResourceSet resourceSet = new ResourceSetImpl(); + public static final String resourceData = "/Users/macbook/eclipse-workspace/NeoEMF/neoemf-io/src/main/resources/data.json"; + + +} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/User.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/User.java new file mode 100644 index 0000000000..abea086daf --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/User.java @@ -0,0 +1,39 @@ +package fr.inria.atlanmod.neoemf.io.reader.json; + +public class User { + + private int id; + private String name; + + public User(int id, String name) { + this.id = id; + this.name = name; + } + + public User() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/util/JsonConstants.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/util/JsonConstants.java new file mode 100644 index 0000000000..e9213936a9 --- /dev/null +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/util/JsonConstants.java @@ -0,0 +1,11 @@ +package fr.inria.atlanmod.neoemf.io.util; + +import org.atlanmod.commons.annotation.Static; + +import javax.annotation.ParametersAreNonnullByDefault; + +@Static +@ParametersAreNonnullByDefault +public final class JsonConstants { + +} diff --git a/neoemf-io/src/main/resources/data.json b/neoemf-io/src/main/resources/data.json new file mode 100644 index 0000000000..994b398f49 --- /dev/null +++ b/neoemf-io/src/main/resources/data.json @@ -0,0 +1,5 @@ +{ + "eClass" : "http://emfjson.org/domain#//User", + "id": 1, + "name" : "Bob" +} diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonReaderTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonReaderTest.java new file mode 100644 index 0000000000..a8b4af00b1 --- /dev/null +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonReaderTest.java @@ -0,0 +1,44 @@ +package fr.inria.atlanmod.neoemf.io.json; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.jsonldjava.utils.Obj; +import fr.inria.atlanmod.neoemf.io.reader.json.AbstractJsonStreamReader; +import fr.inria.atlanmod.neoemf.io.reader.json.JsonReaderHelper; + +import java.io.*; +import java.nio.file.Paths; +import java.util.Map; +import java.util.Objects; + +import fr.inria.atlanmod.neoemf.io.reader.json.User; +import org.apache.log4j.Logger; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.emfjson.jackson.resource.JsonResourceFactory; +import org.osgi.framework.UnfilteredServiceListener; + +public class JsonReaderTest { + + public static void main(String [] args) throws IOException { + final Logger logger = Logger.getLogger(JsonReaderTest.class); + final ObjectMapper mapper = new ObjectMapper(); + AbstractJsonStreamReader reader = new AbstractJsonStreamReader(); + InputStream stream = new FileInputStream(JsonReaderHelper.resourceData); + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry() + .getExtensionToFactoryMap() + .put("json", new JsonResourceFactory()); + final String jsonData = "/Users/macbook/eclipse-workspace/NeoEMF/neoemf-io/src/main/resources/data.json"; + Resource resource = resourceSet.createResource(URI.createFileURI(jsonData)); + //reader.parse(stream); + File file = new File(jsonData); + + User user = mapper.readValue(file, User.class); + logger.info(user); + } + + +} diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/util/ResourceManager.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/util/ResourceManager.java index 84a45d63b1..2c9cf7553d 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/util/ResourceManager.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/util/ResourceManager.java @@ -8,7 +8,7 @@ package fr.inria.atlanmod.neoemf.io.util; -import fr.inria.atlanmod.neoemf.tests.sample.impl.SamplePackageImpl; +//import fr.inria.atlanmod.neoemf.tests.sample.impl.SamplePackageImpl; import org.atlanmod.commons.Throwables; import org.atlanmod.commons.annotation.Singleton; @@ -20,7 +20,7 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.xmi.XMIResource; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; -import org.eclipse.gmt.modisco.java.impl.JavaPackageImpl; +//import org.eclipse.gmt.modisco.java.impl.JavaPackageImpl; import java.io.IOException; import java.net.URL; @@ -92,8 +92,10 @@ public static URI zxmiWithId() { * Registers all {@link EPackage}s used in test-cases. */ public static void registerAllPackages() { + /* JavaPackageImpl.init(); SamplePackageImpl.init(); + */ } /** diff --git a/neoemf-tests/pom.xml b/neoemf-tests/pom.xml index 55f797a01d..13a06d65ee 100644 --- a/neoemf-tests/pom.xml +++ b/neoemf-tests/pom.xml @@ -220,6 +220,12 @@ test-jar test + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/neoemf-utils/p2/pom.xml b/neoemf-utils/p2/pom.xml index 23c20a674f..bc05b4d7a9 100644 --- a/neoemf-utils/p2/pom.xml +++ b/neoemf-utils/p2/pom.xml @@ -21,6 +21,14 @@ 2.3.0 + + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + + diff --git a/neoemf-utils/pom.xml b/neoemf-utils/pom.xml index 3e14249471..23f8f7c435 100644 --- a/neoemf-utils/pom.xml +++ b/neoemf-utils/pom.xml @@ -51,6 +51,12 @@ guava ${guava.version} + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + diff --git a/pom.xml b/pom.xml index fbaa0fefa7..b00e4d090e 100644 --- a/pom.xml +++ b/pom.xml @@ -183,6 +183,12 @@ jaxb-runtime 3.0.0 + + com.devialab + jackson-jsonld-maven + 0.0.4 + compile + From c87bf5c7a8c59560d9753855d364068ee8589a10 Mon Sep 17 00:00:00 2001 From: Mamadou Diallo Date: Sat, 1 Jan 2022 10:09:55 +0100 Subject: [PATCH 15/21] merge --- .../atlanmod/neoemf/io/AbstractNotifier.java | 2 +- .../neoemf/io/processor/EcoreMapper.java | 14 ++++++- .../neoemf/io/proxy/ProxyPackage.java | 25 +++++++++---- .../io/reader/AbstractStreamReader.java | 2 +- .../neoemf/io/writer/AbstractWriter.java | 1 - .../neoemf/io/writer/DefaultMapperWriter.java | 10 ++++- .../neoemf/io/writer/json/AttributeTest.java | 37 +++++++++++++------ 7 files changed, 68 insertions(+), 23 deletions(-) diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/AbstractNotifier.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/AbstractNotifier.java index 238622e274..a8fde81881 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/AbstractNotifier.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/AbstractNotifier.java @@ -79,7 +79,7 @@ public void notifyInitialize() throws IOException { @Override public void notifyStartElement(ProxyElement element) throws IOException { - checkNotNull(element, "element"); + checkNotNull(element, "element"); for (H h : handlers) { h.onStartElement(element); diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/processor/EcoreMapper.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/processor/EcoreMapper.java index 93cee521ac..1356772e8d 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/processor/EcoreMapper.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/processor/EcoreMapper.java @@ -24,6 +24,8 @@ import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.util.ExtendedMetaData; import org.eclipse.emf.ecore.util.FeatureMapUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.ArrayDeque; @@ -45,6 +47,8 @@ public class EcoreMapper extends AbstractProcessor { /** * A LIFO that holds the current {@link Id} chain. */ + + final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); @Nonnull private final Deque identifiers = new ArrayDeque<>(); @@ -112,7 +116,13 @@ private void processElementAsRoot(ProxyElement element) throws IOException { checkNotNull(element.getMetaClass(), "The root element must have a namespace"); // Retrieve the current EClass & define the meta-class of the current element if not present + // element is not null + // logger.info("ProxyElement is null:: {}", element == null); final ProxyClass metaClass = element.getMetaClass(); + // metaClass is not null + //logger.info("metaClass is null:: {}", metaClass == null); + // the following condition is true + //logger.info("metaClass name space getOrgin is null:: {}", metaClass.getNamespace().getOrigin() == null); final EClass eClass = getClass(element.getName(), metaClass.getNamespace().getOrigin()); metaClass.setOrigin(eClass); @@ -281,8 +291,10 @@ private EStructuralFeature getFeature(String name) { */ @Nonnull private EClass getClass(String name, EPackage ePackage) { + + logger.info("ePackage is null :: {}", ePackage == null); EClass eClass = (EClass) ePackage.getEClassifier(name); - checkNotNull(eClass, "Unable to find EClass '%s' from EPackage '%s'", name, ePackage.getNsURI()); + checkNotNull(eClass, "Unable to find EClass '%s' from EPackage '%s'", name, ePackage.getNsURI()); return eClass; } diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/proxy/ProxyPackage.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/proxy/ProxyPackage.java index 3ec7cae592..221922668c 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/proxy/ProxyPackage.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/proxy/ProxyPackage.java @@ -14,19 +14,19 @@ import org.atlanmod.commons.annotation.VisibleForTesting; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EcorePackage; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import org.eclipse.emf.ecore.impl.EPackageImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.*; + import static org.atlanmod.commons.Preconditions.checkNotNull; + /** * A simple representation of a {@link org.eclipse.emf.ecore.EPackage}. */ @@ -38,7 +38,6 @@ public class ProxyPackage implements Proxy { */ @Nonnull public static final ProxyPackage DEFAULT = Registry.getInstance().register(EcorePackage.eINSTANCE); - /** * The prefix of this namespace. */ @@ -56,7 +55,18 @@ public class ProxyPackage implements Proxy { */ @Nonnull private final LazyReference ePackage = LazyReference.soft(() -> { + final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + // Until here we don't have a null object + //EPackage p = EPackage.Registry.INSTANCE.getEPackage(getUri()); EPackage p = EPackage.Registry.INSTANCE.getEPackage(getUri()); + // EPackage p2 = new EPackageImpl("name", ); + logger.info("the ePackage :: {}", p); + if(p == null){ + // create an EPackage object + //p = EPackage.Registry.INSTANCE.getEPackage("http://www.omg.org/XMI"); + throw new NullPointerException("The ePackage is null"); + } + logger.info("Epackage name :::::: {}",getUri() ); checkNotNull(p, "EPackage %s is not registered.", getUri()); return p; }); @@ -75,6 +85,7 @@ private ProxyPackage(String prefix, String uri) { @Override public EPackage getOrigin() { return ePackage.get(); + //return (ePackage != null) ? ePackage.get(): new EPackageImpl("", ) } @Nonnull diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/AbstractStreamReader.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/AbstractStreamReader.java index db643202fc..6fa7f1496c 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/AbstractStreamReader.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/AbstractStreamReader.java @@ -77,7 +77,7 @@ public abstract class AbstractStreamReader extends AbstractReader { @Override public final void read(InputStream source) throws IOException { - checkNotNull(source, "source"); + checkNotNull(source, "source"); try (InputStream in = new BufferedInputStream(source)) { parse(in); diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/AbstractWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/AbstractWriter.java index f7e1eda687..3fb593ee2c 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/AbstractWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/AbstractWriter.java @@ -139,7 +139,6 @@ public void onEndElement() throws IOException { /** * Handles an attribute in the current element. - * * @param attribute the new attribute, without its value * @param values the ordered values of the attribute; when the {@code attribute} is single-valued, this parameter * is a {@link Collections#singletonList(Object)} diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/DefaultMapperWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/DefaultMapperWriter.java index 9ad8e82451..9a480872da 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/DefaultMapperWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/DefaultMapperWriter.java @@ -60,7 +60,6 @@ public void onComplete() { @Override public void onStartElement(ProxyElement element) throws IOException { super.onStartElement(element); - createElement(element, false); } @@ -72,10 +71,19 @@ public void onAttribute(ProxyAttribute attribute, List values) { target.valueFor(bean, values.get(0)); } else { + // Old code target.appendAllValues(bean, values); + // new code + /* + values.stream().map(v -> { + target.valueFor(bean, v); + return null; + });*/ + } } + @Override public void onReference(ProxyReference reference, List values) { SingleFeatureBean bean = SingleFeatureBean.of(reference.getOwner(), reference.getId()); diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java index 8a67d96dfd..08c8c76be2 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java @@ -1,6 +1,8 @@ package fr.inria.atlanmod.neoemf.io.writer.json; + import fr.inria.atlanmod.neoemf.tests.sample.Node; +import fr.inria.atlanmod.neoemf.tests.sample.Comment; import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; import fr.inria.atlanmod.neoemf.tests.sample.Value; import fr.inria.atlanmod.neoemf.tests.sample.impl.LocalNodeImpl; @@ -9,11 +11,12 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; public class AttributeTest { // Get the factory - private static final SampleFactory factory = SampleFactory.eINSTANCE; + private final SampleFactory factory = SampleFactory.eINSTANCE; @Test void testSingleAttribute() { @@ -21,7 +24,7 @@ void testSingleAttribute() { Value val = factory.createValue(); val.setValue(10); - resource.getContents().addAll(Arrays.asList( + resource.getContents().addAll(List.of( val )); }; @@ -30,17 +33,29 @@ void testSingleAttribute() { @Test void testMultipleAttributes() { + Value val = factory.createValue(); + val.setValue(10); + Value val2 = factory.createValue(); + val2.setValue(12); + // List values = List.of(val, val2); + + Comment comment = factory.createComment(); + comment.setContent("comment body"); + Consumer populator = resource -> { - Value val = factory.createValue(); - val.setValue(10); - Value val2 = factory.createValue(); - val2.setValue(12); + resource.getContents().addAll( + List.of(val2, comment)); + }; + /* + values.stream().map(v -> { + Consumer populator = resource -> { + resource.getContents().add(v); + }; + Helper.testMigration(populator, "AttributeTest/multipleAttribute/"); - resource.getContents().addAll(Arrays.asList( - val, val2 - )); - }; - Helper.testMigration(populator, "AttributeTest/multipleAttribute/"); + return null; + });*/ + Helper.testMigration(populator, "AttributeTest/multipleAttribute/"); } @Test From a3bc06d1577208a6052422fa128a208ebc6c1c67 Mon Sep 17 00:00:00 2001 From: DaikiKaminari Date: Sun, 2 Jan 2022 18:15:32 +0100 Subject: [PATCH 16/21] Try to fix loading from xmi to the mapper --- .../neoemf/io/writer/json/AttributeTest.java | 9 +++-- .../neoemf/io/writer/json/Helper.java | 35 ++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java index 8a67d96dfd..2b7183a680 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java @@ -2,10 +2,10 @@ import fr.inria.atlanmod.neoemf.tests.sample.Node; import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; +import fr.inria.atlanmod.neoemf.tests.sample.SamplePackage; import fr.inria.atlanmod.neoemf.tests.sample.Value; -import fr.inria.atlanmod.neoemf.tests.sample.impl.LocalNodeImpl; -import fr.inria.atlanmod.neoemf.tests.sample.impl.PhysicalNodeImpl; import org.eclipse.emf.ecore.resource.Resource; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -15,6 +15,11 @@ public class AttributeTest { // Get the factory private static final SampleFactory factory = SampleFactory.eINSTANCE; + @BeforeAll + static void initialize() { + SamplePackage.eINSTANCE.eClass(); + } + @Test void testSingleAttribute() { Consumer populator = resource -> { diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java index 785c266e53..abce3ce6ee 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java @@ -4,8 +4,10 @@ import fr.inria.atlanmod.neoemf.data.mapping.DataMapper; import fr.inria.atlanmod.neoemf.io.Migrator; import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; +import fr.inria.atlanmod.neoemf.tests.sample.SamplePackage; import org.atlanmod.commons.log.Log; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; @@ -14,6 +16,8 @@ import org.jetbrains.annotations.NotNull; import java.io.*; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; public class Helper { @@ -22,6 +26,7 @@ public class Helper { private static Resource resourceEmfJsonJackson; private static Resource resourceXmi; private static String currentTargetPath; + private static String packageName = SamplePackage.eNAME; static boolean deleteDirectory(String path) { File directoryToBeDeleted = new File(path); @@ -38,27 +43,31 @@ static private void saveWithEmfJsonJackson(Consumer populator, @NotNul ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry() .getExtensionToFactoryMap() - .put("json", new JsonResourceFactory()); - Log.info("Exporting to file... [{0}]", currentTargetPath + "test-jackson-write.json"); - resourceEmfJsonJackson = resourceSet.createResource(URI.createFileURI(currentTargetPath + "test-jackson-write.json")); + .put(packageName, new JsonResourceFactory()); + Log.info("Exporting to file... [{0}]", currentTargetPath + "test-jacksonjson-write." + packageName); + resourceEmfJsonJackson = resourceSet.createResource(URI.createFileURI(currentTargetPath + "test-jacksonjson-write." + packageName)); populator.accept(resourceEmfJsonJackson); - resourceEmfJsonJackson.save(null); + resourceEmfJsonJackson.save(Collections.EMPTY_MAP); } static private void saveWithEmfXmi(Consumer populator, @NotNull String targetPath) throws IOException { - ResourceSet resourceSet2 = new ResourceSetImpl(); - resourceSet2.getResourceFactoryRegistry() + final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; + final Map m = reg.getExtensionToFactoryMap(); + m.put(packageName, new XMIResourceFactoryImpl()); + + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry() .getExtensionToFactoryMap() - .put("xmi", new XMIResourceFactoryImpl()); - Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.xmi"); - resourceXmi = resourceSet2.createResource(URI.createFileURI(currentTargetPath + "test-write.xmi")); + .put(packageName, new XMIResourceFactoryImpl()); + Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write-xmi." + packageName); + resourceXmi = resourceSet.createResource(URI.createFileURI(currentTargetPath + "test-write-xmi." + packageName)); populator.accept(resourceXmi); - resourceXmi.save(null); + resourceXmi.save(Collections.EMPTY_MAP); } static private DataMapper getMapperFromXmi() throws IOException { DataMapper mapper = new DefaultInMemoryBackend(); - InputStream in = new FileInputStream(currentTargetPath + "test-write.xmi"); + InputStream in = new FileInputStream(currentTargetPath + "test-write-xmi." + packageName); // xmi to mapper Migrator.fromXmi(in) .toMapper(mapper) @@ -68,8 +77,8 @@ static private DataMapper getMapperFromXmi() throws IOException { static private void mapperToJson(DataMapper mapper) throws IOException { // mapper to json (our implementation) - Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.json"); - File targetFileJSON = new File(currentTargetPath + "test-write.json"); + Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write-json." + packageName); + File targetFileJSON = new File(currentTargetPath + "test-write-json." + packageName); Migrator.fromMapper(mapper) .toJson(targetFileJSON) .migrate(); From c6591d921148c92d59e5a051986d5d8d4765e12d Mon Sep 17 00:00:00 2001 From: Mamadou Diallo Date: Wed, 5 Jan 2022 20:43:56 +0100 Subject: [PATCH 17/21] local changes --- .../multiValuedAttribute/test-write.xmi | 6 +++++ .../multipleAttribute/test-write.xmi | 5 +++++ .../singleAttribute/test-write.xmi | 2 ++ .../fr/inria/atlanmod/neoemf/io/Migrator.java | 4 ++++ .../neoemf/io/proxy/ProxyPackage.java | 22 ++++++++++++------- .../neoemf/io/writer/json/AttributeTest.java | 6 ++--- .../neoemf/io/writer/json/Helper.java | 5 ++++- 7 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 neoemf-io/AttributeTest/multiValuedAttribute/test-write.xmi create mode 100644 neoemf-io/AttributeTest/multipleAttribute/test-write.xmi create mode 100644 neoemf-io/AttributeTest/singleAttribute/test-write.xmi diff --git a/neoemf-io/AttributeTest/multiValuedAttribute/test-write.xmi b/neoemf-io/AttributeTest/multiValuedAttribute/test-write.xmi new file mode 100644 index 0000000000..56ddd3dca2 --- /dev/null +++ b/neoemf-io/AttributeTest/multiValuedAttribute/test-write.xmi @@ -0,0 +1,6 @@ + + + + + + diff --git a/neoemf-io/AttributeTest/multipleAttribute/test-write.xmi b/neoemf-io/AttributeTest/multipleAttribute/test-write.xmi new file mode 100644 index 0000000000..7bf58e057b --- /dev/null +++ b/neoemf-io/AttributeTest/multipleAttribute/test-write.xmi @@ -0,0 +1,5 @@ + + + + + diff --git a/neoemf-io/AttributeTest/singleAttribute/test-write.xmi b/neoemf-io/AttributeTest/singleAttribute/test-write.xmi new file mode 100644 index 0000000000..91c32c8f86 --- /dev/null +++ b/neoemf-io/AttributeTest/singleAttribute/test-write.xmi @@ -0,0 +1,2 @@ + + diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java index 55f2010a2f..6801ce9439 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/Migrator.java @@ -28,6 +28,8 @@ import org.atlanmod.commons.annotation.VisibleForTesting; import org.atlanmod.commons.log.Level; import org.atlanmod.commons.log.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.Closeable; import java.io.File; @@ -401,6 +403,8 @@ public void migrate() throws IOException { try { // Bind handlers and notifiers Collection handlers = new ArrayList<>(listeners.size() + writers.size()); + final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + logger.info("writers :: {}", writers.toArray()); handlers.addAll(listeners); handlers.addAll(writers); reader.addNext(new NoopProcessor(handlers)); diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/proxy/ProxyPackage.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/proxy/ProxyPackage.java index 221922668c..8874a77cad 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/proxy/ProxyPackage.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/proxy/ProxyPackage.java @@ -31,7 +31,7 @@ * A simple representation of a {@link org.eclipse.emf.ecore.EPackage}. */ @ParametersAreNonnullByDefault -public class ProxyPackage implements Proxy { +public class ProxyPackage extends EPackageImpl implements Proxy { /** * The instance of the default namespace: {@code ecore @ http://www.eclipse.org/emf/2002/Ecore}. @@ -50,23 +50,27 @@ public class ProxyPackage implements Proxy { @Nonnull private final String uri; + final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + /** * The {@link EPackage} represented by this object. */ @Nonnull private final LazyReference ePackage = LazyReference.soft(() -> { - final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + // Until here we don't have a null object - //EPackage p = EPackage.Registry.INSTANCE.getEPackage(getUri()); EPackage p = EPackage.Registry.INSTANCE.getEPackage(getUri()); - // EPackage p2 = new EPackageImpl("name", ); + + logger.info("URI :: {}", getUri()); logger.info("the ePackage :: {}", p); - if(p == null){ + if(p == null && getUri().equals("http://www.neoemf.com/tests/sample")){ // create an EPackage object - //p = EPackage.Registry.INSTANCE.getEPackage("http://www.omg.org/XMI"); - throw new NullPointerException("The ePackage is null"); + p = EPackage.Registry.INSTANCE.getEPackage("http://www.neoemf.com/tests/sample"); + logger.info("The ePackage is null"); + + //p = new ProxyPackage("sample", "http://www.neoemf.com/tests/sample"); } - logger.info("Epackage name :::::: {}",getUri() ); + checkNotNull(p, "EPackage %s is not registered.", getUri()); return p; }); @@ -80,6 +84,8 @@ public class ProxyPackage implements Proxy { private ProxyPackage(String prefix, String uri) { this.prefix = prefix; this.uri = uri; + + // logger.info("prefix :: {}, namespace :: {}", prefix, uri); } @Override diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java index 08c8c76be2..2d23534280 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java @@ -55,7 +55,7 @@ void testMultipleAttributes() { return null; });*/ - Helper.testMigration(populator, "AttributeTest/multipleAttribute/"); + Helper.testMigration(populator, "AttributeTest/multipleAttribute/"); } @Test @@ -73,10 +73,10 @@ void testMultiValuedAttribute() { node.getChildren().add(node1); node.getChildren().add(node2); - resource.getContents().addAll(Arrays.asList( + resource.getContents().addAll(List.of( node, node1, node2 )); }; - Helper.testMigration(populator, "AttributeTest/multiValuedAttribute/"); + Helper.testMigration(populator, "AttributeTest/multiValuedAttribute/"); } } diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java index 785c266e53..b411c29cdb 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java @@ -51,7 +51,9 @@ static private void saveWithEmfXmi(Consumer populator, @NotNull String .getExtensionToFactoryMap() .put("xmi", new XMIResourceFactoryImpl()); Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.xmi"); - resourceXmi = resourceSet2.createResource(URI.createFileURI(currentTargetPath + "test-write.xmi")); + //resourceXmi = resourceSet2.createResource(URI.createFileURI(targetPath + "test-write.xmi")); + resourceXmi = resourceSet2.createResource(URI.createFileURI(currentTargetPath+ "test-write.xmi")); + Log.info("targetPath :: ", targetPath); populator.accept(resourceXmi); resourceXmi.save(null); } @@ -90,6 +92,7 @@ static void testMigration(Consumer populator, @NotNull String targetPa // migrate xmi to mapper DataMapper mapper = getMapperFromXmi(); + // mapper.save(); // migrate mapper to json // mapperToJson(mapper); From 324c47d8c570e9b834c9fbbd4990aaafc99afe0c Mon Sep 17 00:00:00 2001 From: DaikiKaminari Date: Fri, 7 Jan 2022 16:12:20 +0100 Subject: [PATCH 18/21] Fix error for xmi, need to fix error with emfjson-jackson --- neoemf-io/pom.xml | 7 +++++-- .../atlanmod/neoemf/io/writer/json/AttributeTest.java | 7 ++++--- .../fr/inria/atlanmod/neoemf/io/writer/json/Helper.java | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/neoemf-io/pom.xml b/neoemf-io/pom.xml index f94e315317..1e3b90064b 100644 --- a/neoemf-io/pom.xml +++ b/neoemf-io/pom.xml @@ -22,7 +22,7 @@ 1.0-2 4.2.1 4.4.1 - 2.13.0 + 2.13.1 @@ -99,12 +99,15 @@ ${jackson.version} + com.fasterxml.jackson.core - jackson-annotations + jackson-core ${jackson.version} + + diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java index 2b7183a680..1d07df2c75 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java @@ -4,6 +4,7 @@ import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; import fr.inria.atlanmod.neoemf.tests.sample.SamplePackage; import fr.inria.atlanmod.neoemf.tests.sample.Value; +import fr.inria.atlanmod.neoemf.tests.sample.impl.TypeMapImpl; import org.eclipse.emf.ecore.resource.Resource; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -33,7 +34,7 @@ void testSingleAttribute() { Helper.testMigration(populator, "AttributeTest/singleAttribute/"); } - @Test + /*@Test void testMultipleAttributes() { Consumer populator = resource -> { Value val = factory.createValue(); @@ -46,7 +47,7 @@ void testMultipleAttributes() { )); }; Helper.testMigration(populator, "AttributeTest/multipleAttribute/"); - } + }*/ @Test void testMultiValuedAttribute() { @@ -64,7 +65,7 @@ void testMultiValuedAttribute() { node.getChildren().add(node2); resource.getContents().addAll(Arrays.asList( - node, node1, node2 + node )); }; Helper.testMigration(populator, "AttributeTest/multiValuedAttribute/"); diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java index abce3ce6ee..101198fbd4 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java @@ -100,7 +100,7 @@ static void testMigration(Consumer populator, @NotNull String targetPa DataMapper mapper = getMapperFromXmi(); // migrate mapper to json - // mapperToJson(mapper); + mapperToJson(mapper); } catch (IOException e) { e.printStackTrace(); From 99b2429136970cfe3269392a0b9deba569dcef85 Mon Sep 17 00:00:00 2001 From: DaikiKaminari Date: Sat, 8 Jan 2022 19:00:27 +0100 Subject: [PATCH 19/21] [WIP] Fixing containment ref serialization --- neoemf-io/pom.xml | 17 +---- .../reader/json/AbstractJsonStreamReader.java | 5 +- .../writer/json/AbstractJsonStreamWriter.java | 24 ++++++- .../io/writer/json/JsonStreamWriter.java | 12 +++- .../neoemf/io/writer/json/AttributeTest.java | 63 ++++++------------- .../neoemf/io/writer/json/Helper.java | 50 ++++----------- neoemf-io/src/test/resources/model/Java.aird | 17 +++++ .../src/test/resources/model/Sample.aird | 18 +++--- .../src/test/resources/model/store.ecore | 40 ++++++++++++ 9 files changed, 132 insertions(+), 114 deletions(-) create mode 100644 neoemf-io/src/test/resources/model/Java.aird create mode 100644 neoemf-io/src/test/resources/model/store.ecore diff --git a/neoemf-io/pom.xml b/neoemf-io/pom.xml index 3680507e0e..bb8be17377 100644 --- a/neoemf-io/pom.xml +++ b/neoemf-io/pom.xml @@ -97,6 +97,7 @@ com.fasterxml.jackson.core jackson-databind ${jackson.version} + compile @@ -104,6 +105,7 @@ com.fasterxml.jackson.core jackson-core ${jackson.version} + compile @@ -137,26 +139,11 @@ assertj-core - - - org.emfjson - emfjson-jackson - 1.3.0 - - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - org.emfjson emfjson-jackson 1.3.0 bundle - test diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java index b7b736fe5f..b53bf42808 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java @@ -7,7 +7,6 @@ import com.github.jsonldjava.utils.Obj; import fr.inria.atlanmod.neoemf.io.reader.AbstractStreamReader; import org.apache.commons.io.IOUtils; -import org.emfjson.jackson.resource.JsonResourceFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -25,12 +24,12 @@ public class AbstractJsonStreamReader extends AbstractStreamReader { private final Logger logger = LoggerFactory.getLogger(AbstractJsonStreamReader.class); - public AbstractJsonStreamReader(){ + /*public AbstractJsonStreamReader(){ JsonReaderHelper.resourceSet.getResourceFactoryRegistry() .getExtensionToFactoryMap() .put("json", new JsonResourceFactory()); - } + }*/ @Override public void parse(@NotNull InputStream stream) throws IOException { diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java index e09a820deb..375d0a629e 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java @@ -5,10 +5,12 @@ import fr.inria.atlanmod.neoemf.io.proxy.ProxyElement; import fr.inria.atlanmod.neoemf.io.proxy.ProxyReference; import fr.inria.atlanmod.neoemf.io.writer.AbstractStreamWriter; +import org.atlanmod.commons.primitive.Strings; import java.io.IOException; import java.io.OutputStream; import java.util.List; +import java.util.stream.Collectors; public abstract class AbstractJsonStreamWriter extends AbstractStreamWriter { /** @@ -37,16 +39,26 @@ public void onAttribute(ProxyAttribute attribute, List values) throws IO if (!attribute.isMany()) { writeAttribute(attribute.getName(), values.get(0)); } else { - writeAttribute(attribute.getName(), values); + writeMultipleAttributes(attribute.getName(), values); } } @Override public void onReference(ProxyReference reference, List values) throws IOException { + if (!reference.isMany()) { + writeAttribute(reference.getName(), reference.getValue().getResolved()); + } + else { + System.out.println("__________________"); + System.out.println(reference.getValue().getResolved()); + System.out.println("__________________"); + writeAttribute(reference.getName(), reference.getValue().getResolved()); + } } @Override public void onEndElement() throws IOException { + super.onEndElement(); writeEndElement(); } @@ -81,6 +93,16 @@ public void onComplete() throws IOException { */ protected abstract void writeAttribute(String name, Object value) throws IOException; + /** + * Writes a multi valued attribute. + * + * @param name the name of the attribute + * @param values multiple values of the attribute + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeMultipleAttributes(String name, List values) throws IOException; + /** * Writes characters. * diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java index 0540bf7fa8..ec3fc71fe9 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.util.List; import javax.annotation.Nonnull; @@ -36,7 +37,6 @@ private int nextId() { @Override protected void writeStartDocument() throws IOException { - jGenerator.writeStartArray(); } @Override @@ -50,6 +50,15 @@ protected void writeAttribute(String name, Object value) throws IOException { jGenerator.writeObjectField(name, value); } + @Override + protected void writeMultipleAttributes(String name, List values) throws IOException { + jGenerator.writeArrayFieldStart(name); + for (Object v : values) { + jGenerator.writeObject(v); + } + jGenerator.writeEndArray(); + } + @Override protected void writeCharacters(String characters) throws IOException { jGenerator.writeString(characters); @@ -62,7 +71,6 @@ protected void writeEndElement() throws IOException { @Override protected void writeEndDocument() throws IOException { - jGenerator.writeEndArray(); jGenerator.close(); } } diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java index 1d07df2c75..18f722b6cd 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java @@ -4,70 +4,43 @@ import fr.inria.atlanmod.neoemf.tests.sample.SampleFactory; import fr.inria.atlanmod.neoemf.tests.sample.SamplePackage; import fr.inria.atlanmod.neoemf.tests.sample.Value; -import fr.inria.atlanmod.neoemf.tests.sample.impl.TypeMapImpl; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import store.StoreFactory; +import store.StorePackage; +import java.io.IOException; import java.util.Arrays; import java.util.function.Consumer; public class AttributeTest { // Get the factory - private static final SampleFactory factory = SampleFactory.eINSTANCE; + private static final SampleFactory sampleFactory = SampleFactory.eINSTANCE; + private static final StoreFactory storeFactory = StoreFactory.eINSTANCE; @BeforeAll static void initialize() { SamplePackage.eINSTANCE.eClass(); + StorePackage.eINSTANCE.eClass(); } @Test - void testSingleAttribute() { - Consumer populator = resource -> { - Value val = factory.createValue(); - val.setValue(10); - - resource.getContents().addAll(Arrays.asList( - val - )); - }; - Helper.testMigration(populator, "AttributeTest/singleAttribute/"); + void testSingleAttribute() throws IOException { + Helper.testMigration("AttributeTest/singleAttribute/"); } - /*@Test - void testMultipleAttributes() { - Consumer populator = resource -> { - Value val = factory.createValue(); - val.setValue(10); - Value val2 = factory.createValue(); - val2.setValue(12); - - resource.getContents().addAll(Arrays.asList( - val, val2 - )); - }; - Helper.testMigration(populator, "AttributeTest/multipleAttribute/"); - }*/ - @Test - void testMultiValuedAttribute() { - Consumer populator = resource -> { - Node node = factory.createPhysicalNode(); - node.setLabel("parentNode"); - Node node1 = factory.createPhysicalNode(); - node1.setLabel("childrenNode1"); - node1.setParent(node); - Node node2 = factory.createPhysicalNode(); - node2.setLabel("childrenNode2"); - node2.setParent(node); - - node.getChildren().add(node1); - node.getChildren().add(node2); + void testMultipleAttributes() throws IOException { + Helper.testMigration("AttributeTest/multipleAttributes/"); + } - resource.getContents().addAll(Arrays.asList( - node - )); - }; - Helper.testMigration(populator, "AttributeTest/multiValuedAttribute/"); + @Test + void testMultiValuedAttribute() throws IOException { + Helper.testMigration("AttributeTest/multiValuedAttribute/"); } } diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java index ed01488b4e..880b368d7b 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/Helper.java @@ -34,28 +34,6 @@ static boolean deleteDirectory(String path) { return directoryToBeDeleted.delete(); } - static private void saveWithEmfJsonJackson(Consumer populator, @NotNull String targetPath) throws IOException { - ResourceSet resourceSet = new ResourceSetImpl(); - resourceSet.getResourceFactoryRegistry() - .getExtensionToFactoryMap() - .put("json", new JsonResourceFactory()); - Log.info("Exporting to file... [{0}]", currentTargetPath + "test-jackson-write.json"); - resourceEmfJsonJackson = resourceSet.createResource(URI.createFileURI(currentTargetPath + "test-jackson-write.json")); - populator.accept(resourceEmfJsonJackson); - resourceEmfJsonJackson.save(null); - } - - static private void saveWithEmfXmi(Consumer populator, @NotNull String targetPath) throws IOException { - ResourceSet resourceSet2 = new ResourceSetImpl(); - resourceSet2.getResourceFactoryRegistry() - .getExtensionToFactoryMap() - .put("xmi", new XMIResourceFactoryImpl()); - Log.info("Exporting to file... [{0}]", currentTargetPath + "test-write.xmi"); - resourceXmi = resourceSet2.createResource(URI.createFileURI(currentTargetPath + "test-write.xmi")); - populator.accept(resourceXmi); - resourceXmi.save(null); - } - static private DataMapper getMapperFromXmi() throws IOException { DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new FileInputStream(currentTargetPath + "test-write.xmi"); @@ -75,26 +53,20 @@ static private void mapperToJson(DataMapper mapper) throws IOException { .migrate(); } + static void testMigration(@NotNull String targetPath) throws IOException { + currentTargetPath = testOutputPath + targetPath; + // deleteDirectory(currentTargetPath); - static void testMigration(Consumer populator, @NotNull String targetPath) { - try { - currentTargetPath = testOutputPath + targetPath; - deleteDirectory(currentTargetPath); + // java to emfjson-jackson (for testing/comparison purpose) + // saveWithEmfJsonJackson(populator, targetPath); - // java to emfjson-jackson (for testing/comparison purpose) - saveWithEmfJsonJackson(populator, targetPath); + // java to xmi (used in the Migrator input) + // saveWithEmfXmi(populator, targetPath); - // java to xmi (used in the Migrator input) - saveWithEmfXmi(populator, targetPath); + // migrate xmi to mapper + DataMapper mapper = getMapperFromXmi(); - // migrate xmi to mapper - DataMapper mapper = getMapperFromXmi(); - - // migrate mapper to json - mapperToJson(mapper); - - } catch (IOException e) { - e.printStackTrace(); - } + // migrate mapper to json + mapperToJson(mapper); } } diff --git a/neoemf-io/src/test/resources/model/Java.aird b/neoemf-io/src/test/resources/model/Java.aird new file mode 100644 index 0000000000..78f2a6a9af --- /dev/null +++ b/neoemf-io/src/test/resources/model/Java.aird @@ -0,0 +1,17 @@ + + + Java.ecore + Java.genmodel + + + + + + + + + + + + + diff --git a/neoemf-io/src/test/resources/model/Sample.aird b/neoemf-io/src/test/resources/model/Sample.aird index 325b8fa636..21c478e4b8 100644 --- a/neoemf-io/src/test/resources/model/Sample.aird +++ b/neoemf-io/src/test/resources/model/Sample.aird @@ -5,7 +5,7 @@ Sample.genmodel - + @@ -609,17 +609,17 @@ - + - + - + - + @@ -657,17 +657,17 @@ - + - + - + - + diff --git a/neoemf-io/src/test/resources/model/store.ecore b/neoemf-io/src/test/resources/model/store.ecore new file mode 100644 index 0000000000..87499d6348 --- /dev/null +++ b/neoemf-io/src/test/resources/model/store.ecore @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From a0748a50d34f223f0f4524af851b7e179b1cffb4 Mon Sep 17 00:00:00 2001 From: DaikiKaminari <52349037+DaikiKaminari@users.noreply.github.com> Date: Wed, 12 Jan 2022 21:25:09 +0100 Subject: [PATCH 20/21] Added tests sample, need to fix error when running tests --- .gitignore | 3 - neoemf-core/pom.xml | 4 +- .../multiValuedAttribute/test-write.xmi | 6 - .../multipleAttribute/test-write.xmi | 5 - .../writer/json/AbstractJsonStreamWriter.java | 41 ++- .../io/writer/json/JsonStreamWriter.java | 19 +- .../neoemf/io/util/ResourceManager.java | 4 +- .../neoemf/io/writer/json/AttributeTest.java | 4 - .../neoemf/io/writer/json/ReferenceTest.java | 26 ++ .../resources/model/subSampleModel/.gitkeep | 0 .../subSampleModel/simplestClass/Sample.aird | 314 ++++++++++++++++++ .../subSampleModel/simplestClass/Sample.ecore | 17 + .../simplestClass/Sample.genmodel | 16 + .../simplestClass/build.properties | 9 + .../simplestClass/plugin.properties | 4 + .../subSampleModel/simplestClass/plugin.xml | 32 ++ .../test-jackson-write.json | 11 + .../multiValuedAttribute/test-write.json | 11 + .../multiValuedAttribute/test-write.xmi | 5 + .../test-jackson-write.json | 4 + .../multipleAttributes/test-write.json | 4 + .../multipleAttributes/test-write.xmi | 2 + .../singleAttribute/test-jackson-write.json | 4 + .../singleAttribute/test-write.xmi | 0 .../complexReferences/test-jackson-write.json | 61 ++++ .../complexReferences/test-write.xmi | 12 + .../test-jackson-write.json | 42 +++ .../multipleReferences/test-write.xmi | 9 + .../singleReference/test-jackson-write.json | 17 + .../singleReference/test-write.xmi | 5 + 30 files changed, 662 insertions(+), 29 deletions(-) delete mode 100644 neoemf-io/AttributeTest/multiValuedAttribute/test-write.xmi delete mode 100644 neoemf-io/AttributeTest/multipleAttribute/test-write.xmi create mode 100644 neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/ReferenceTest.java create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/.gitkeep create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties create mode 100644 neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml create mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-jackson-write.json create mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.json create mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.xmi create mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-jackson-write.json create mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.json create mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.xmi create mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json rename neoemf-io/{ => src/test/resources/test-output}/AttributeTest/singleAttribute/test-write.xmi (100%) create mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-jackson-write.json create mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-write.xmi create mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-jackson-write.json create mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-write.xmi create mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-jackson-write.json create mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-write.xmi diff --git a/.gitignore b/.gitignore index caf9fa0adf..a98508e0fa 100644 --- a/.gitignore +++ b/.gitignore @@ -133,6 +133,3 @@ **/java-gen **/src-gen/ -### Tests -neoemf-io/src/test/resources/test-output/* - diff --git a/neoemf-core/pom.xml b/neoemf-core/pom.xml index 172654c3aa..5bbfc48470 100644 --- a/neoemf-core/pom.xml +++ b/neoemf-core/pom.xml @@ -19,8 +19,8 @@ - 3.21ea41 - 2.21ea43 + 3.22ea5 + 2.22ea17 2.14.1 3.3.0 diff --git a/neoemf-io/AttributeTest/multiValuedAttribute/test-write.xmi b/neoemf-io/AttributeTest/multiValuedAttribute/test-write.xmi deleted file mode 100644 index 56ddd3dca2..0000000000 --- a/neoemf-io/AttributeTest/multiValuedAttribute/test-write.xmi +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/neoemf-io/AttributeTest/multipleAttribute/test-write.xmi b/neoemf-io/AttributeTest/multipleAttribute/test-write.xmi deleted file mode 100644 index 7bf58e057b..0000000000 --- a/neoemf-io/AttributeTest/multipleAttribute/test-write.xmi +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java index 375d0a629e..458d182108 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java @@ -29,37 +29,50 @@ public void onInitialize() throws IOException { @Override public final void onStartElement(ProxyElement element) throws IOException { + System.out.println("__________________"); super.onStartElement(element); + System.out.println("ON START ELEM"); writeStartElement(element.getMetaClass().getNamespace().getUri(), element.getName()); + System.out.println("__________________"); } @Override public void onAttribute(ProxyAttribute attribute, List values) throws IOException { - System.out.println(attribute.getOrigin().getEAttributeType()); + System.out.println("__________________"); + System.out.println(attribute.getName()); if (!attribute.isMany()) { + System.out.println("SINGLE ATTR"); writeAttribute(attribute.getName(), values.get(0)); } else { + System.out.println("MULTIPLE ATTR"); writeMultipleAttributes(attribute.getName(), values); } + System.out.println("__________________"); } @Override public void onReference(ProxyReference reference, List values) throws IOException { + System.out.println("REF"); + if (reference.isContainment()) { + System.out.println("CONTAINMENT"); + writeStartContainmentReference(reference.getName()); + return; + } if (!reference.isMany()) { - writeAttribute(reference.getName(), reference.getValue().getResolved()); + writeAttribute(reference.getName(), values.get(0).toHexString()); } else { - System.out.println("__________________"); - System.out.println(reference.getValue().getResolved()); - System.out.println("__________________"); - writeAttribute(reference.getName(), reference.getValue().getResolved()); + writeAttribute(reference.getName(), values.stream().map(Id::toHexString).collect(Collectors.joining(Strings.SPACE))); } } @Override public void onEndElement() throws IOException { super.onEndElement(); + System.out.println("__________________"); + System.out.println("ON END ELEM"); writeEndElement(); + System.out.println("__________________"); } @Override @@ -112,6 +125,22 @@ public void onComplete() throws IOException { */ protected abstract void writeCharacters(String characters) throws IOException; + /** + * Writes the start of a containment reference + * + * @param name the name fo the reference + * + * @throws IOException + */ + protected abstract void writeStartContainmentReference(String name) throws IOException; + + /** + * Writes the end of a containment reference + * + * @throws IOException + */ + protected abstract void writeEndContainmentReference() throws IOException; + /** * Writes the end of the current element. * diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java index ec3fc71fe9..6df9cf4459 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -1,5 +1,6 @@ package fr.inria.atlanmod.neoemf.io.writer.json; +import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; @@ -59,6 +60,17 @@ protected void writeMultipleAttributes(String name, List values) throws jGenerator.writeEndArray(); } + @Override + protected void writeStartContainmentReference(String name) throws IOException { + jGenerator.writeFieldName(name); + jGenerator.writeStartArray(); + } + + @Override + protected void writeEndContainmentReference() throws IOException { + jGenerator.writeEndArray(); + } + @Override protected void writeCharacters(String characters) throws IOException { jGenerator.writeString(characters); @@ -66,7 +78,12 @@ protected void writeCharacters(String characters) throws IOException { @Override protected void writeEndElement() throws IOException { - jGenerator.writeEndObject(); + try { + jGenerator.writeEndObject(); + } catch (JsonGenerationException e) { + jGenerator.writeEndArray(); + jGenerator.writeEndObject(); + } } @Override diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/util/ResourceManager.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/util/ResourceManager.java index 2c9cf7553d..d9a7218188 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/util/ResourceManager.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/util/ResourceManager.java @@ -10,6 +10,7 @@ //import fr.inria.atlanmod.neoemf.tests.sample.impl.SamplePackageImpl; +import fr.inria.atlanmod.neoemf.tests.sample.impl.SamplePackageImpl; import org.atlanmod.commons.Throwables; import org.atlanmod.commons.annotation.Singleton; import org.atlanmod.commons.annotation.Static; @@ -20,6 +21,7 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.xmi.XMIResource; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; +import org.eclipse.gmt.modisco.java.impl.JavaPackageImpl; //import org.eclipse.gmt.modisco.java.impl.JavaPackageImpl; import java.io.IOException; @@ -92,10 +94,8 @@ public static URI zxmiWithId() { * Registers all {@link EPackage}s used in test-cases. */ public static void registerAllPackages() { - /* JavaPackageImpl.init(); SamplePackageImpl.init(); - */ } /** diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java index 18f722b6cd..48055e26bd 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java @@ -19,10 +19,6 @@ import java.util.function.Consumer; public class AttributeTest { - // Get the factory - private static final SampleFactory sampleFactory = SampleFactory.eINSTANCE; - private static final StoreFactory storeFactory = StoreFactory.eINSTANCE; - @BeforeAll static void initialize() { SamplePackage.eINSTANCE.eClass(); diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/ReferenceTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/ReferenceTest.java new file mode 100644 index 0000000000..d80b4be018 --- /dev/null +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/ReferenceTest.java @@ -0,0 +1,26 @@ +package fr.inria.atlanmod.neoemf.io.writer.json; + +import fr.inria.atlanmod.neoemf.tests.sample.SamplePackage; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import store.StorePackage; + +import java.io.IOException; + +public class ReferenceTest { + @BeforeAll + static void initialize() { + SamplePackage.eINSTANCE.eClass(); + StorePackage.eINSTANCE.eClass(); + } + + @Test + void testSingleReference() throws IOException { + Helper.testMigration("ReferenceTest/singleReference/"); + } + + @Test + void testSingleReference2() throws IOException { + Helper.testMigration("ReferenceTest/complexReferences/"); + } +} diff --git a/neoemf-io/src/test/resources/model/subSampleModel/.gitkeep b/neoemf-io/src/test/resources/model/subSampleModel/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird new file mode 100644 index 0000000000..e961760752 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.aird @@ -0,0 +1,314 @@ + + + + Sample.ecore + Sample.genmodel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + italic + + + + + + + + + + + + + + + + italic + + + + + + + + + + italic + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore new file mode 100644 index 0000000000..d88b74a8f0 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.ecore @@ -0,0 +1,17 @@ + + + +
+
+
+
+
+
+
+
+ + + + + diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel new file mode 100644 index 0000000000..e33ac6c493 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/Sample.genmodel @@ -0,0 +1,16 @@ + + + Sample.ecore + + + + + + diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties new file mode 100644 index 0000000000..d54d9dc3ad --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/build.properties @@ -0,0 +1,9 @@ +# + +bin.includes = .,\ + model/,\ + plugin.xml,\ + plugin.properties +jars.compile.order = . +source.. = src-gen/ +output.. = bin/ diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties new file mode 100644 index 0000000000..e27e39b957 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.properties @@ -0,0 +1,4 @@ +# + +pluginName = Sample Model +providerName = www.example.org diff --git a/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml new file mode 100644 index 0000000000..bab04ba4f5 --- /dev/null +++ b/neoemf-io/src/test/resources/model/subSampleModel/simplestClass/plugin.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-jackson-write.json new file mode 100644 index 0000000000..e50d992954 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-jackson-write.json @@ -0,0 +1,11 @@ +{ + "eClass" : "http://www.neoemf.com/tests/sample#//PhysicalNode", + "label" : "parentNode", + "children" : [ { + "eClass" : "http://www.neoemf.com/tests/sample#//PhysicalNode", + "label" : "childrenNode1" + }, { + "eClass" : "http://www.neoemf.com/tests/sample#//PhysicalNode", + "label" : "childrenNode2" + } ] +} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.json new file mode 100644 index 0000000000..1f08f3f7a9 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.json @@ -0,0 +1,11 @@ +{ + "eClass" : "http://www.neoemf.com/tests/sample#//PhysicalNode", + "label" : "parentNode", + "children" : [ { + "eClass" : "http://www.neoemf.com/tests/sample#//children", + "label" : "childrenNode1" + }, { + "eClass" : "http://www.neoemf.com/tests/sample#//children", + "label" : "childrenNode2" + } ] +} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.xmi new file mode 100644 index 0000000000..5da88b3c68 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.xmi @@ -0,0 +1,5 @@ + + + + + diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-jackson-write.json new file mode 100644 index 0000000000..c4ccf92078 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-jackson-write.json @@ -0,0 +1,4 @@ +{ + "eClass" : "http://com/univ-nantes/store#//Category", + "name" : "fruit" +} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.json new file mode 100644 index 0000000000..c4ccf92078 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.json @@ -0,0 +1,4 @@ +{ + "eClass" : "http://com/univ-nantes/store#//Category", + "name" : "fruit" +} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.xmi new file mode 100644 index 0000000000..f1e66cd3fc --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.xmi @@ -0,0 +1,2 @@ + + diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json new file mode 100644 index 0000000000..662a6da128 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json @@ -0,0 +1,4 @@ +{ + "eClass" : "http://www.neoemf.com/tests/sample#//Value", + "value" : 10 +} \ No newline at end of file diff --git a/neoemf-io/AttributeTest/singleAttribute/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi similarity index 100% rename from neoemf-io/AttributeTest/singleAttribute/test-write.xmi rename to neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-jackson-write.json new file mode 100644 index 0000000000..20f91d7a78 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-jackson-write.json @@ -0,0 +1,61 @@ +[ { + "eClass" : "http://com/univ-nantes/store#//Category", + "name" : "Fruit", + "product" : [ { + "eClass" : "http://com/univ-nantes/store#//Product", + "$ref" : "/99" + }, { + "eClass" : "http://com/univ-nantes/store#//Product", + "$ref" : "/99" + } ] +}, { + "eClass" : "http://com/univ-nantes/store#//Customer", + "id" : 100, + "name" : "François", + "order" : [ { + "eClass" : "http://com/univ-nantes/store#//Order", + "$ref" : "1000" + } ] +}, { + "eClass" : "http://com/univ-nantes/store#//OrderItem", + "quantity" : 5.0, + "product" : { + "id" : "/99", + "name" : "Peach", + "quantity" : 5.0, + "category" : { + "eClass" : "http://com/univ-nantes/store#//Category", + "$ref" : "/0" + } + }, + "id" : "1" +}, { + "eClass" : "http://com/univ-nantes/store#//OrderItem", + "quantity" : 10.0, + "product" : { + "id" : "/99", + "name" : "Apple", + "quantity" : 20.0, + "category" : { + "eClass" : "http://com/univ-nantes/store#//Category", + "$ref" : "/0" + } + }, + "id" : "2" +}, { + "eClass" : "http://com/univ-nantes/store#//Order", + "id" : 1000, + "createdAt" : "2022-01-11T20:03:40", + "state" : "SHIPPED", + "customer" : { + "eClass" : "http://com/univ-nantes/store#//Customer", + "$ref" : "100" + }, + "orderitem" : [ { + "eClass" : "http://com/univ-nantes/store#//OrderItem", + "$ref" : "/2" + }, { + "eClass" : "http://com/univ-nantes/store#//OrderItem", + "$ref" : "/3" + } ] +} ] \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-write.xmi b/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-write.xmi new file mode 100644 index 0000000000..c1269509e6 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-write.xmi @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-jackson-write.json new file mode 100644 index 0000000000..086beb32d4 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-jackson-write.json @@ -0,0 +1,42 @@ +[ { + "eClass" : "http://com/univ-nantes/store#//Category", + "name" : "Fruit", + "product" : [ { + "eClass" : "http://com/univ-nantes/store#//Product", + "$ref" : "99" + } ] +}, { + "eClass" : "http://com/univ-nantes/store#//Customer", + "id" : 100, + "name" : "François", + "order" : [ { + "eClass" : "http://com/univ-nantes/store#//Order", + "$ref" : "1000" + } ] +}, { + "eClass" : "http://com/univ-nantes/store#//OrderItem", + "quantity" : 5.0, + "product" : { + "id" : "99", + "name" : "Peach", + "quantity" : 5.0, + "category" : { + "eClass" : "http://com/univ-nantes/store#//Category", + "$ref" : "/0" + } + }, + "id" : "1" +}, { + "eClass" : "http://com/univ-nantes/store#//Order", + "id" : 1000, + "createdAt" : "2022-01-12T16:48:04", + "state" : "SHIPPED", + "customer" : { + "eClass" : "http://com/univ-nantes/store#//Customer", + "$ref" : "100" + }, + "orderitem" : [ { + "eClass" : "http://com/univ-nantes/store#//OrderItem", + "$ref" : "/2" + } ] +} ] \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-write.xmi b/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-write.xmi new file mode 100644 index 0000000000..69e353fac5 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-write.xmi @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-jackson-write.json new file mode 100644 index 0000000000..22b1c53f11 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-jackson-write.json @@ -0,0 +1,17 @@ +[ { + "eClass" : "http://com/univ-nantes/store#//Category", + "name" : "fruit", + "product" : [ { + "eClass" : "http://com/univ-nantes/store#//Product", + "$ref" : "1" + } ] +}, { + "eClass" : "http://com/univ-nantes/store#//Product", + "id" : "1", + "name" : "banana", + "quantity" : 5.2, + "category" : { + "eClass" : "http://com/univ-nantes/store#//Category", + "$ref" : "/0" + } +} ] \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-write.xmi b/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-write.xmi new file mode 100644 index 0000000000..1940c469c5 --- /dev/null +++ b/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-write.xmi @@ -0,0 +1,5 @@ + + + + + From 89171baa08073056db055df2c47da1a5950a26cf Mon Sep 17 00:00:00 2001 From: DaikiKaminari Date: Fri, 14 Jan 2022 16:09:34 +0100 Subject: [PATCH 21/21] Refactor --- .../reader/json/AbstractJsonStreamReader.java | 9 +- .../writer/json/AbstractJsonStreamWriter.java | 269 +++++++++--------- .../io/writer/json/JsonStreamWriter.java | 136 +++++---- .../neoemf/io/json/JsonReaderTest.java | 44 --- .../neoemf/io/writer/json/ReferenceTest.java | 26 -- .../{AttributeTest.java => WriterTest.java} | 10 +- .../test-jackson-write.json | 11 - .../multiValuedAttribute/test-write.json | 11 - .../multiValuedAttribute/test-write.xmi | 5 - .../test-jackson-write.json | 4 - .../multipleAttributes/test-write.json | 4 - .../multipleAttributes/test-write.xmi | 2 - .../singleAttribute/test-jackson-write.json | 4 - .../singleAttribute/test-write.xmi | 2 - .../complexReferences/test-jackson-write.json | 61 ---- .../complexReferences/test-write.xmi | 12 - .../test-jackson-write.json | 42 --- .../multipleReferences/test-write.xmi | 9 - .../singleReference/test-jackson-write.json | 17 -- .../singleReference/test-write.xmi | 5 - 20 files changed, 200 insertions(+), 483 deletions(-) delete mode 100644 neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonReaderTest.java delete mode 100644 neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/ReferenceTest.java rename neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/{AttributeTest.java => WriterTest.java} (77%) delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-jackson-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.xmi delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-jackson-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.xmi delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi delete mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-jackson-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-write.xmi delete mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-jackson-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-write.xmi delete mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-jackson-write.json delete mode 100644 neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-write.xmi diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java index b53bf42808..87b5553a8d 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/reader/json/AbstractJsonStreamReader.java @@ -4,9 +4,7 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.jsonldjava.utils.Obj; import fr.inria.atlanmod.neoemf.io.reader.AbstractStreamReader; -import org.apache.commons.io.IOUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,23 +31,22 @@ public class AbstractJsonStreamReader extends AbstractStreamReader { @Override public void parse(@NotNull InputStream stream) throws IOException { - - /* resource = JsonReaderHelper.mapper.reader() .withAttribute(EMFContext.Attributes.RESOURCE_SET, JsonReaderHelper.resourceSet) .withAttribute(EMFContext.Attributes.RESOURCE_URI, JsonReaderHelper.resourceData) .forType(Resource.class) .readValue(stream); - */ + String theString = IOUtils.toString(stream, StandardCharsets.UTF_8); ObjectMapper mapper = new ObjectMapper(); Reader reader = new StringReader(theString); - + */ } + @Override protected boolean isSpecialAttribute(@Nullable String prefix, String name, String value) throws IOException { return false; diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java index 458d182108..3a4b9611ad 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/AbstractJsonStreamWriter.java @@ -12,146 +12,131 @@ import java.util.List; import java.util.stream.Collectors; -public abstract class AbstractJsonStreamWriter extends AbstractStreamWriter { - /** - * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. - * - * @param stream the stream where to write data - */ - public AbstractJsonStreamWriter(OutputStream stream) { - super(stream); - } - - @Override - public void onInitialize() throws IOException { - writeStartDocument(); - } - - @Override - public final void onStartElement(ProxyElement element) throws IOException { - System.out.println("__________________"); - super.onStartElement(element); - System.out.println("ON START ELEM"); - writeStartElement(element.getMetaClass().getNamespace().getUri(), element.getName()); - System.out.println("__________________"); - } - - @Override - public void onAttribute(ProxyAttribute attribute, List values) throws IOException { - System.out.println("__________________"); - System.out.println(attribute.getName()); - if (!attribute.isMany()) { - System.out.println("SINGLE ATTR"); - writeAttribute(attribute.getName(), values.get(0)); - } else { - System.out.println("MULTIPLE ATTR"); - writeMultipleAttributes(attribute.getName(), values); - } - System.out.println("__________________"); - } - - @Override - public void onReference(ProxyReference reference, List values) throws IOException { - System.out.println("REF"); - if (reference.isContainment()) { - System.out.println("CONTAINMENT"); - writeStartContainmentReference(reference.getName()); - return; - } - if (!reference.isMany()) { - writeAttribute(reference.getName(), values.get(0).toHexString()); - } - else { - writeAttribute(reference.getName(), values.stream().map(Id::toHexString).collect(Collectors.joining(Strings.SPACE))); - } - } - - @Override - public void onEndElement() throws IOException { - super.onEndElement(); - System.out.println("__________________"); - System.out.println("ON END ELEM"); - writeEndElement(); - System.out.println("__________________"); - } - - @Override - public void onComplete() throws IOException { - writeEndDocument(); - } - - /** - * Writes the start of a document, including the general header. - * - * @throws IOException if an I/O error occurs when writing - */ - protected abstract void writeStartDocument() throws IOException; - - /** - * Writes the start of an element {@code name} - * - * @param name the name of the element - * - * @throws IOException if an I/O error occurs when writing - */ - protected abstract void writeStartElement(String namespace, String name) throws IOException; - - /** - * Writes an attribute of the current element. - * - * @param name the name of the attribute - * @param value the value of the attribute - * - * @throws IOException if an I/O error occurs when writing - */ - protected abstract void writeAttribute(String name, Object value) throws IOException; - - /** - * Writes a multi valued attribute. - * - * @param name the name of the attribute - * @param values multiple values of the attribute - * - * @throws IOException if an I/O error occurs when writing - */ - protected abstract void writeMultipleAttributes(String name, List values) throws IOException; - - /** - * Writes characters. - * - * @param characters the characters - * - * @throws IOException if an I/O error occurs when writing - */ - protected abstract void writeCharacters(String characters) throws IOException; - - /** - * Writes the start of a containment reference - * - * @param name the name fo the reference - * - * @throws IOException - */ - protected abstract void writeStartContainmentReference(String name) throws IOException; - - /** - * Writes the end of a containment reference - * - * @throws IOException - */ - protected abstract void writeEndContainmentReference() throws IOException; - - /** - * Writes the end of the current element. - * - * @throws IOException if an I/O error occurs when writing - */ - protected abstract void writeEndElement() throws IOException; - - /** - * Writes the end of the document and finalizes the migration. - * - * @throws IOException if an I/O error occurs when writing - */ - protected abstract void writeEndDocument() throws IOException; +public abstract class AbstractJsonStreamWriter extends AbstractStreamWriter { + /** + * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. + * + * @param stream the stream where to write data + */ + public AbstractJsonStreamWriter(OutputStream stream) { + super(stream); + } + + @Override + public void onInitialize() throws IOException { + writeStartDocument(); + } + + @Override + public final void onStartElement(ProxyElement element) throws IOException { + super.onStartElement(element); + writeStartElement(element.getMetaClass().getNamespace().getUri(), element.getMetaClass().getName()); + } + + @Override + public void onAttribute(ProxyAttribute attribute, List values) throws IOException { + if (!attribute.isMany()) { + writeAttribute(attribute.getName(), values.get(0)); + } else { + writeMultipleAttributes(attribute.getName(), values); + } + } + + @Override + public void onReference(ProxyReference reference, List values) throws IOException { + if (reference.isContainment()) { + if (reference.isMany()) { + writeStartMultiValuedContainmentReference(reference.getName()); + } else { + writeStartContainmentReference(reference.getName()); + } + return; + } + if (reference.isMany()) { + writeAttribute(reference.getName(), values.stream().map(Id::toHexString).collect(Collectors.joining(Strings.SPACE))); + } else { + writeAttribute(reference.getName(), values.get(0).toHexString()); + } + } + + @Override + public void onEndElement() throws IOException { + super.onEndElement(); + writeEndElement(); + } + + @Override + public void onComplete() throws IOException { + writeEndDocument(); + } + + /** + * Writes the start of a document, including the general header. + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeStartDocument() throws IOException; + + /** + * Writes the start of an element {@code name} + * + * @param name the name of the element + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeStartElement(String namespace, String name) throws IOException; + + /** + * Writes an attribute of the current element. + * + * @param name the name of the attribute + * @param value the value of the attribute + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeAttribute(String name, Object value) throws IOException; + + /** + * Writes a multi valued attribute. + * + * @param name the name of the attribute + * @param values multiple values of the attribute + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeMultipleAttributes(String name, List values) throws IOException; + + /** + * Writes characters. + * + * @param characters the characters + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeCharacters(String characters) throws IOException; + + /** + * Writes the start of a containment reference + * + * @param name the name fo the reference + * @throws IOException + */ + protected abstract void writeStartContainmentReference(String name) throws IOException; + + /** + * Write the start of a multi-valued containment reference + * + * @param name the name of the reference + */ + protected abstract void writeStartMultiValuedContainmentReference(String name) throws IOException; + + /** + * Writes the end of the current element. + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeEndElement() throws IOException; + + /** + * Writes the end of the document and finalizes the migration. + * + * @throws IOException if an I/O error occurs when writing + */ + protected abstract void writeEndDocument() throws IOException; } diff --git a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java index 6df9cf4459..adc76a686b 100644 --- a/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java +++ b/neoemf-io/src/main/java/fr/inria/atlanmod/neoemf/io/writer/json/JsonStreamWriter.java @@ -4,90 +4,84 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; +import javax.annotation.Nonnull; import java.io.IOException; import java.io.OutputStream; import java.util.List; -import javax.annotation.Nonnull; - public class JsonStreamWriter extends AbstractJsonStreamWriter { - @Nonnull - protected final ObjectMapper mapper; - @Nonnull - protected final JsonGenerator jGenerator; - protected int id; - - /** - * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. - * - * @param stream the stream where to write data - */ - public JsonStreamWriter(OutputStream stream) throws IOException { - super(stream); - mapper = new ObjectMapper(); - jGenerator = mapper.getFactory().createGenerator(target); - jGenerator.useDefaultPrettyPrinter(); - id = 0; - } + @Nonnull + protected final ObjectMapper mapper; + @Nonnull + protected final JsonGenerator jGenerator; + protected int id; - private int nextId() { - int temp = id; - id++; - return temp; - } + /** + * Constructs a new {@code AbstractStreamWriter} with the given {@code stream}. + * + * @param stream the stream where to write data + */ + public JsonStreamWriter(OutputStream stream) throws IOException { + super(stream); + mapper = new ObjectMapper(); + jGenerator = mapper.getFactory().createGenerator(target); + jGenerator.useDefaultPrettyPrinter(); + id = 0; + } - @Override - protected void writeStartDocument() throws IOException { - } + @Override + protected void writeStartDocument() throws IOException { + } - @Override - protected void writeStartElement(String namespace, String name) throws IOException { - jGenerator.writeStartObject(); - jGenerator.writeStringField("eClass", namespace + "#//" + name); - } + @Override + protected void writeStartElement(String namespace, String name) throws IOException { + jGenerator.writeStartObject(); + jGenerator.writeStringField("eClass", namespace + "#//" + name); + } - @Override - protected void writeAttribute(String name, Object value) throws IOException { - jGenerator.writeObjectField(name, value); - } + @Override + protected void writeAttribute(String name, Object value) throws IOException { + jGenerator.writeObjectField(name, value); + } - @Override - protected void writeMultipleAttributes(String name, List values) throws IOException { - jGenerator.writeArrayFieldStart(name); - for (Object v : values) { - jGenerator.writeObject(v); - } - jGenerator.writeEndArray(); - } + @Override + protected void writeMultipleAttributes(String name, List values) throws IOException { + jGenerator.writeArrayFieldStart(name); + for (Object v : values) { + jGenerator.writeObject(v); + } + jGenerator.writeEndArray(); + } - @Override - protected void writeStartContainmentReference(String name) throws IOException { - jGenerator.writeFieldName(name); - jGenerator.writeStartArray(); - } + @Override + protected void writeStartContainmentReference(String name) throws IOException { + jGenerator.writeFieldName(name); + jGenerator.writeStartObject(); + } - @Override - protected void writeEndContainmentReference() throws IOException { - jGenerator.writeEndArray(); - } + @Override + protected void writeStartMultiValuedContainmentReference(String name) throws IOException { + jGenerator.writeFieldName(name); + jGenerator.writeStartArray(); + } - @Override - protected void writeCharacters(String characters) throws IOException { - jGenerator.writeString(characters); - } + @Override + protected void writeCharacters(String characters) throws IOException { + jGenerator.writeString(characters); + } - @Override - protected void writeEndElement() throws IOException { - try { - jGenerator.writeEndObject(); - } catch (JsonGenerationException e) { - jGenerator.writeEndArray(); - jGenerator.writeEndObject(); - } - } + @Override + protected void writeEndElement() throws IOException { + try { + jGenerator.writeEndObject(); + } catch (JsonGenerationException e) { + jGenerator.writeEndArray(); + jGenerator.writeEndObject(); + } + } - @Override - protected void writeEndDocument() throws IOException { - jGenerator.close(); - } + @Override + protected void writeEndDocument() throws IOException { + jGenerator.close(); + } } diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonReaderTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonReaderTest.java deleted file mode 100644 index a8b4af00b1..0000000000 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/json/JsonReaderTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package fr.inria.atlanmod.neoemf.io.json; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.jsonldjava.utils.Obj; -import fr.inria.atlanmod.neoemf.io.reader.json.AbstractJsonStreamReader; -import fr.inria.atlanmod.neoemf.io.reader.json.JsonReaderHelper; - -import java.io.*; -import java.nio.file.Paths; -import java.util.Map; -import java.util.Objects; - -import fr.inria.atlanmod.neoemf.io.reader.json.User; -import org.apache.log4j.Logger; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.emfjson.jackson.resource.JsonResourceFactory; -import org.osgi.framework.UnfilteredServiceListener; - -public class JsonReaderTest { - - public static void main(String [] args) throws IOException { - final Logger logger = Logger.getLogger(JsonReaderTest.class); - final ObjectMapper mapper = new ObjectMapper(); - AbstractJsonStreamReader reader = new AbstractJsonStreamReader(); - InputStream stream = new FileInputStream(JsonReaderHelper.resourceData); - ResourceSet resourceSet = new ResourceSetImpl(); - resourceSet.getResourceFactoryRegistry() - .getExtensionToFactoryMap() - .put("json", new JsonResourceFactory()); - final String jsonData = "/Users/macbook/eclipse-workspace/NeoEMF/neoemf-io/src/main/resources/data.json"; - Resource resource = resourceSet.createResource(URI.createFileURI(jsonData)); - //reader.parse(stream); - File file = new File(jsonData); - - User user = mapper.readValue(file, User.class); - logger.info(user); - } - - -} diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/ReferenceTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/ReferenceTest.java deleted file mode 100644 index d80b4be018..0000000000 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/ReferenceTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package fr.inria.atlanmod.neoemf.io.writer.json; - -import fr.inria.atlanmod.neoemf.tests.sample.SamplePackage; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import store.StorePackage; - -import java.io.IOException; - -public class ReferenceTest { - @BeforeAll - static void initialize() { - SamplePackage.eINSTANCE.eClass(); - StorePackage.eINSTANCE.eClass(); - } - - @Test - void testSingleReference() throws IOException { - Helper.testMigration("ReferenceTest/singleReference/"); - } - - @Test - void testSingleReference2() throws IOException { - Helper.testMigration("ReferenceTest/complexReferences/"); - } -} diff --git a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/WriterTest.java similarity index 77% rename from neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java rename to neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/WriterTest.java index 48055e26bd..9e7c2550dc 100644 --- a/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/AttributeTest.java +++ b/neoemf-io/src/test/java/fr/inria/atlanmod/neoemf/io/writer/json/WriterTest.java @@ -18,7 +18,7 @@ import java.util.Arrays; import java.util.function.Consumer; -public class AttributeTest { +public class WriterTest { @BeforeAll static void initialize() { SamplePackage.eINSTANCE.eClass(); @@ -27,16 +27,16 @@ static void initialize() { @Test void testSingleAttribute() throws IOException { - Helper.testMigration("AttributeTest/singleAttribute/"); + Helper.testMigration("GeneratedInstances/singleAttribute/"); } @Test void testMultipleAttributes() throws IOException { - Helper.testMigration("AttributeTest/multipleAttributes/"); + Helper.testMigration("GeneratedInstances/multipleAttributes/"); } @Test - void testMultiValuedAttribute() throws IOException { - Helper.testMigration("AttributeTest/multiValuedAttribute/"); + void testMultiContainmentReference() throws IOException { + Helper.testMigration("GeneratedInstances/multiContainmentReference/"); } } diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-jackson-write.json deleted file mode 100644 index e50d992954..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-jackson-write.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "eClass" : "http://www.neoemf.com/tests/sample#//PhysicalNode", - "label" : "parentNode", - "children" : [ { - "eClass" : "http://www.neoemf.com/tests/sample#//PhysicalNode", - "label" : "childrenNode1" - }, { - "eClass" : "http://www.neoemf.com/tests/sample#//PhysicalNode", - "label" : "childrenNode2" - } ] -} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.json deleted file mode 100644 index 1f08f3f7a9..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "eClass" : "http://www.neoemf.com/tests/sample#//PhysicalNode", - "label" : "parentNode", - "children" : [ { - "eClass" : "http://www.neoemf.com/tests/sample#//children", - "label" : "childrenNode1" - }, { - "eClass" : "http://www.neoemf.com/tests/sample#//children", - "label" : "childrenNode2" - } ] -} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.xmi deleted file mode 100644 index 5da88b3c68..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/multiValuedAttribute/test-write.xmi +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-jackson-write.json deleted file mode 100644 index c4ccf92078..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-jackson-write.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "eClass" : "http://com/univ-nantes/store#//Category", - "name" : "fruit" -} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.json deleted file mode 100644 index c4ccf92078..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "eClass" : "http://com/univ-nantes/store#//Category", - "name" : "fruit" -} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.xmi deleted file mode 100644 index f1e66cd3fc..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/multipleAttributes/test-write.xmi +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json deleted file mode 100644 index 662a6da128..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-jackson-write.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "eClass" : "http://www.neoemf.com/tests/sample#//Value", - "value" : 10 -} \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi b/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi deleted file mode 100644 index 91c32c8f86..0000000000 --- a/neoemf-io/src/test/resources/test-output/AttributeTest/singleAttribute/test-write.xmi +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-jackson-write.json deleted file mode 100644 index 20f91d7a78..0000000000 --- a/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-jackson-write.json +++ /dev/null @@ -1,61 +0,0 @@ -[ { - "eClass" : "http://com/univ-nantes/store#//Category", - "name" : "Fruit", - "product" : [ { - "eClass" : "http://com/univ-nantes/store#//Product", - "$ref" : "/99" - }, { - "eClass" : "http://com/univ-nantes/store#//Product", - "$ref" : "/99" - } ] -}, { - "eClass" : "http://com/univ-nantes/store#//Customer", - "id" : 100, - "name" : "François", - "order" : [ { - "eClass" : "http://com/univ-nantes/store#//Order", - "$ref" : "1000" - } ] -}, { - "eClass" : "http://com/univ-nantes/store#//OrderItem", - "quantity" : 5.0, - "product" : { - "id" : "/99", - "name" : "Peach", - "quantity" : 5.0, - "category" : { - "eClass" : "http://com/univ-nantes/store#//Category", - "$ref" : "/0" - } - }, - "id" : "1" -}, { - "eClass" : "http://com/univ-nantes/store#//OrderItem", - "quantity" : 10.0, - "product" : { - "id" : "/99", - "name" : "Apple", - "quantity" : 20.0, - "category" : { - "eClass" : "http://com/univ-nantes/store#//Category", - "$ref" : "/0" - } - }, - "id" : "2" -}, { - "eClass" : "http://com/univ-nantes/store#//Order", - "id" : 1000, - "createdAt" : "2022-01-11T20:03:40", - "state" : "SHIPPED", - "customer" : { - "eClass" : "http://com/univ-nantes/store#//Customer", - "$ref" : "100" - }, - "orderitem" : [ { - "eClass" : "http://com/univ-nantes/store#//OrderItem", - "$ref" : "/2" - }, { - "eClass" : "http://com/univ-nantes/store#//OrderItem", - "$ref" : "/3" - } ] -} ] \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-write.xmi b/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-write.xmi deleted file mode 100644 index c1269509e6..0000000000 --- a/neoemf-io/src/test/resources/test-output/ReferenceTest/complexReferences/test-write.xmi +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-jackson-write.json deleted file mode 100644 index 086beb32d4..0000000000 --- a/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-jackson-write.json +++ /dev/null @@ -1,42 +0,0 @@ -[ { - "eClass" : "http://com/univ-nantes/store#//Category", - "name" : "Fruit", - "product" : [ { - "eClass" : "http://com/univ-nantes/store#//Product", - "$ref" : "99" - } ] -}, { - "eClass" : "http://com/univ-nantes/store#//Customer", - "id" : 100, - "name" : "François", - "order" : [ { - "eClass" : "http://com/univ-nantes/store#//Order", - "$ref" : "1000" - } ] -}, { - "eClass" : "http://com/univ-nantes/store#//OrderItem", - "quantity" : 5.0, - "product" : { - "id" : "99", - "name" : "Peach", - "quantity" : 5.0, - "category" : { - "eClass" : "http://com/univ-nantes/store#//Category", - "$ref" : "/0" - } - }, - "id" : "1" -}, { - "eClass" : "http://com/univ-nantes/store#//Order", - "id" : 1000, - "createdAt" : "2022-01-12T16:48:04", - "state" : "SHIPPED", - "customer" : { - "eClass" : "http://com/univ-nantes/store#//Customer", - "$ref" : "100" - }, - "orderitem" : [ { - "eClass" : "http://com/univ-nantes/store#//OrderItem", - "$ref" : "/2" - } ] -} ] \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-write.xmi b/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-write.xmi deleted file mode 100644 index 69e353fac5..0000000000 --- a/neoemf-io/src/test/resources/test-output/ReferenceTest/multipleReferences/test-write.xmi +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-jackson-write.json b/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-jackson-write.json deleted file mode 100644 index 22b1c53f11..0000000000 --- a/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-jackson-write.json +++ /dev/null @@ -1,17 +0,0 @@ -[ { - "eClass" : "http://com/univ-nantes/store#//Category", - "name" : "fruit", - "product" : [ { - "eClass" : "http://com/univ-nantes/store#//Product", - "$ref" : "1" - } ] -}, { - "eClass" : "http://com/univ-nantes/store#//Product", - "id" : "1", - "name" : "banana", - "quantity" : 5.2, - "category" : { - "eClass" : "http://com/univ-nantes/store#//Category", - "$ref" : "/0" - } -} ] \ No newline at end of file diff --git a/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-write.xmi b/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-write.xmi deleted file mode 100644 index 1940c469c5..0000000000 --- a/neoemf-io/src/test/resources/test-output/ReferenceTest/singleReference/test-write.xmi +++ /dev/null @@ -1,5 +0,0 @@ - - - - -