Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban Dugueperoux2015-01-22 14:17:03 +0000
committerEsteban Dugueperoux2015-01-23 09:06:28 +0000
commite1cbba7d2374b6c0142c5cb599f3ebe5a965c3ae (patch)
tree399687181a6763b2f732d552375ada33392c0236
parent127f85dfd388e0c2704536dc88ba5b1959e39041 (diff)
downloadcdo-e1cbba7d2374b6c0142c5cb599f3ebe5a965c3ae.tar.gz
cdo-e1cbba7d2374b6c0142c5cb599f3ebe5a965c3ae.tar.xz
cdo-e1cbba7d2374b6c0142c5cb599f3ebe5a965c3ae.zip
[458149] Not active: CDOTransactionImpl on CDOResource.getURI()
Change-Id: If21b93e7306debc1c9fc52eb8a84606553f7d225 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=458149 Signed-off-by: Esteban Dugueperoux <esteban.dugueperoux@obeo.fr>
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_458149_Test.java79
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java2
2 files changed, 80 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_458149_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_458149_Test.java
new file mode 100644
index 0000000000..17d37f7b35
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_458149_Test.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Esteban Dugueperoux - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
+import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig;
+import org.eclipse.emf.cdo.util.CDOURIData;
+import org.eclipse.emf.cdo.view.CDOView;
+
+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.XMIResource;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+
+import java.util.Collections;
+
+/**
+ * Bug 458149 about {@link CDOResource#getURI()} call when the {@link CDOResource} is removed from its {@link ResourceSet}.
+ *
+ * @author Esteban Dugueperoux
+ */
+@Requires("TCP")
+public class Bugzilla_458149_Test extends AbstractCDOTest
+{
+ /**
+ * Test {@link CDOResource#getURI()} when the resource is in a {@link ResourceSet} and also once removed from it.
+ */
+ public void testCDOResource_getURI() throws Exception
+ {
+ getRepository();
+ ResourceSet resourceSet = new ResourceSetImpl();
+
+ URI sharedResourceURI = URI.createURI(
+ CDONet4jUtil.PROTOCOL_TCP + "://localhost/" + RepositoryConfig.REPOSITORY_NAME
+ + getResourcePath("/sharedResource")).appendQuery(CDOURIData.TRANSACTIONAL_PARAMETER + "=true");
+ Resource sharedResource = resourceSet.createResource(sharedResourceURI);
+ sharedResource.save(Collections.emptyMap());
+ assertEquals(sharedResourceURI, sharedResource.getURI());
+
+ CDOView view = ((CDOResource)sharedResource).cdoView();
+ view.close();
+ view.getSession().close();
+
+ resourceSet.getResources().remove(sharedResource);
+ assertEquals(sharedResourceURI, sharedResource.getURI());
+ }
+
+ /**
+ * Test {@link XMIResource#getURI()} when the resource is in a {@link ResourceSet} and also once removed from it.
+ */
+ public void testXMIResource_getURI() throws Exception
+ {
+ Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
+ registry.getExtensionToFactoryMap().put("model1", new XMIResourceFactoryImpl());
+ ResourceSet resourceSet = new ResourceSetImpl();
+
+ URI localResourceURI = URI.createFileURI(createTempFile("resource", ".model1").getCanonicalPath());
+ Resource localResource = resourceSet.createResource(localResourceURI);
+ localResource.save(Collections.emptyMap());
+ assertEquals(localResourceURI, localResource.getURI());
+
+ resourceSet.getResources().remove(localResource);
+ assertEquals(localResourceURI, localResource.getURI());
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
index 9e5cd5b99e..6145e41011 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
@@ -308,7 +308,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
@Override
public URI getURI()
{
- if (cdoID() == null && initialURI != null)
+ if ((cdoID() == null || cdoView() == null || cdoView().isClosed()) && initialURI != null)
{
return initialURI;
}

Back to the top