summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-08-21 11:16:54 (EDT)
committerEike Stepper2006-08-21 11:16:54 (EDT)
commit4d88630d481cd3ceee238bdd62148e43e7679bf0 (patch)
treed8ba61005e9179be5ce89e767b4a1c09c99063cf
parent417bd1ac6efa9f1d680408a47df8bb0d38cf0d0c (diff)
downloadcdo-4d88630d481cd3ceee238bdd62148e43e7679bf0.zip
cdo-4d88630d481cd3ceee238bdd62148e43e7679bf0.tar.gz
cdo-4d88630d481cd3ceee238bdd62148e43e7679bf0.tar.bz2
[154522] Copy from CDO resource to XMI resource does not work
https://bugs.eclipse.org/bugs/show_bug.cgi?id=154389
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java79
1 files changed, 75 insertions, 4 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java
index 9860c3d..0889766 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java
@@ -14,6 +14,7 @@ package org.eclipse.emf.cdo.tests.model1;
import org.eclipse.emf.cdo.client.CDOPersistable;
import org.eclipse.emf.cdo.client.CDOResource;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
@@ -30,7 +31,12 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
public class SerializationTest extends AbstractModel1Test
@@ -58,10 +64,7 @@ public class SerializationTest extends AbstractModel1Test
preLoadResource((CDOResource) loaded.eResource());
EObject copied = EcoreUtil.copy(loaded);
- ResourceSet resourceSet = new ResourceSetImpl();
- Map map = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
- map.put("testmodel1", new XMIResourceFactoryImpl());
-
+ ResourceSet resourceSet = createXMIResourceSet();
URI uri = URI.createFileURI(FILE.getAbsolutePath());
Resource xmiResource = resourceSet.createResource(uri);
xmiResource.getContents().add(copied);
@@ -79,6 +82,74 @@ public class SerializationTest extends AbstractModel1Test
}
}
+ public void testImport() throws Exception
+ {
+ final String RESOURCE = "/test/res";
+ final String ROOT = "root";
+ final String[] CHILDREN = { "a", "b", "c"};
+
+ final File FILE = new File("testExport.testmodel1");
+ final String CONTENT = "<?xml version=\"1.0\" encoding=\"ASCII\"?>\r\n"
+ + "<testmodel1:TreeNode xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:testmodel1=\"http://www.eclipse.org/emf/cdo/2006/TestModel1\" stringFeature=\"root\">\r\n"
+ + " <children stringFeature=\"a\"/>\r\n" + " <children stringFeature=\"b\"/>\r\n"
+ + " <children stringFeature=\"c\"/>\r\n" + "</testmodel1:TreeNode>\r\n";
+
+ try
+ {
+ { // Execution
+ saveFile(FILE, CONTENT);
+
+ ResourceSet resourceSet = createXMIResourceSet();
+ URI uri = URI.createFileURI(FILE.getAbsolutePath());
+ Resource xmiResource = resourceSet.getResource(uri, true);
+ TreeNode root = (TreeNode) xmiResource.getContents().get(0);
+
+ EObject copied = EcoreUtil.copy(root);
+ saveRoot(copied, RESOURCE);
+ }
+
+ { // Verification
+ TreeNode root = (TreeNode) loadRoot(RESOURCE);
+ assertNode(ROOT, root);
+
+ EList children = root.getChildren();
+ assertNode(CHILDREN[0], (TreeNode) children.get(0));
+ assertNode(CHILDREN[1], (TreeNode) children.get(1));
+ assertNode(CHILDREN[2], (TreeNode) children.get(2));
+ }
+ }
+ finally
+ {
+ FILE.delete();
+ }
+ }
+
+ protected ResourceSetImpl createXMIResourceSet()
+ {
+ ResourceSetImpl resourceSet = new ResourceSetImpl();
+ Map map = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
+ map.put("testmodel1", new XMIResourceFactoryImpl());
+ return resourceSet;
+ }
+
+ protected void saveFile(final File file, String content) throws IOException
+ {
+ InputStream is = null;
+ OutputStream os = null;
+
+ try
+ {
+ is = new ByteArrayInputStream(content.getBytes());
+ os = new FileOutputStream(file);
+ IOHelper.copy(is, os);
+ }
+ finally
+ {
+ IOHelper.close(is);
+ IOHelper.close(os);
+ }
+ }
+
protected void preLoadResource(CDOResource cdoResource)
{
for (Iterator it = EcoreUtil.getAllContents(cdoResource, true); it.hasNext();)