Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-09-01 06:34:08 +0000
committerEike Stepper2013-09-01 06:34:08 +0000
commit5bea4933cd44c99626e357a5a6e9a1264ed567c8 (patch)
tree14f5c8ba1a5dbc7b1d75cddb76b004652e5cfbdc
parent68eaf83fe7e9e187edee65c6f449dc04bdf50f4a (diff)
downloadcdo-5bea4933cd44c99626e357a5a6e9a1264ed567c8.tar.gz
cdo-5bea4933cd44c99626e357a5a6e9a1264ed567c8.tar.xz
cdo-5bea4933cd44c99626e357a5a6e9a1264ed567c8.zip
[416303] CDOResourceNodes do not support reflective access to derived
path attribute https://bugs.eclipse.org/bugs/show_bug.cgi?id=416303
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_416298_Test.java120
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java28
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java30
3 files changed, 177 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_416298_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_416298_Test.java
new file mode 100644
index 0000000000..b7562764a4
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_416298_Test.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2013 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:
+ * Christian W. Damus (CEA LIST) - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
+import org.eclipse.emf.cdo.eresource.EresourcePackage;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAttribute;
+
+import org.eclipse.core.runtime.Path;
+
+/**
+ * Bug 416298: CDOResourceNodes do not support reflective access to derived path attribute
+ *
+ * @author Christian W. Damus (CEA LIST)
+ */
+public class Bugzilla_416298_Test extends AbstractCDOTest
+{
+ private static final EAttribute URI_ATTRIBUTE = EresourcePackage.eINSTANCE.getCDOResource_URI();
+
+ private static final EAttribute PATH_ATTRIBUTE = EresourcePackage.eINSTANCE.getCDOResourceNode_Path();
+
+ public void testGetSetResourceURI() throws Exception
+ {
+ String path = getResourcePath("/path/to/resource");
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(path);
+
+ URI uri = (URI)resource.eGet(URI_ATTRIBUTE);
+ assertEquals(createURI(path), uri);
+
+ URI newURI = createURI(getParent(path) + "/new-resource");
+ resource.eSet(URI_ATTRIBUTE, newURI);
+ assertEquals(newURI, resource.getURI());
+ assertEquals(newURI, resource.eGet(URI_ATTRIBUTE));
+
+ transaction.commit();
+ assertEquals(newURI, resource.getURI());
+ assertEquals(newURI, resource.eGet(URI_ATTRIBUTE));
+
+ resource.eSet(URI_ATTRIBUTE, uri);
+ assertEquals(uri, resource.getURI());
+ assertEquals(uri, resource.eGet(URI_ATTRIBUTE));
+ }
+
+ public void testGetSetResourcePath() throws Exception
+ {
+ String path = getResourcePath("/path/to/resource");
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(path);
+ assertEquals(path, resource.eGet(PATH_ATTRIBUTE));
+
+ String newPath = getResourcePath("/new/folder/resource");
+ resource.eSet(PATH_ATTRIBUTE, newPath);
+ assertEquals(newPath, resource.getPath());
+ assertEquals(transaction.getResourceFolder(getParent(newPath)), resource.getFolder());
+
+ transaction.commit();
+ assertEquals(newPath, resource.getPath());
+ assertEquals(transaction.getResourceFolder(getParent(newPath)), resource.getFolder());
+
+ resource.eSet(PATH_ATTRIBUTE, path);
+ assertEquals(path, resource.getPath());
+ assertEquals(transaction.getResourceFolder(getParent(path)), resource.getFolder());
+ assertEquals(path, resource.eGet(PATH_ATTRIBUTE));
+ }
+
+ public void testGetSetFolderPath() throws Exception
+ {
+ String path = getResourcePath("/path/to/folder");
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResourceFolder folder = transaction.createResourceFolder(path);
+ assertEquals(path, folder.eGet(PATH_ATTRIBUTE));
+
+ String newPath = getResourcePath("/atRoot"); // At root of test case folder namespace!
+ folder.eSet(PATH_ATTRIBUTE, newPath);
+ assertEquals(newPath, folder.getPath());
+ assertEquals(newPath, folder.eGet(PATH_ATTRIBUTE));
+ assertEquals(transaction.getResourceFolder(getParent(newPath)), folder.getFolder());
+
+ transaction.commit();
+ assertEquals(newPath, folder.getPath());
+ assertEquals(newPath, folder.eGet(PATH_ATTRIBUTE));
+ assertEquals(transaction.getResourceFolder(getParent(newPath)), folder.getFolder());
+
+ folder.eSet(PATH_ATTRIBUTE, path);
+ assertEquals(path, folder.getPath());
+ assertEquals(path, folder.eGet(PATH_ATTRIBUTE));
+ assertEquals(transaction.getResourceFolder(getParent(path)), folder.getFolder());
+ }
+
+ private URI createURI(String path)
+ {
+ return URI.createURI("cdo://" + getRepository().getUUID() + path);
+ }
+
+ private String getParent(String path)
+ {
+ return new Path(path).removeLastSegments(1).toString();
+ }
+}
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 67fff423a7..3ac5c5c9b5 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
@@ -347,6 +347,34 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements InternalCDOR
setPath(newPath);
}
+
+ @Override
+ public Object eGet(int featureID, boolean resolve, boolean coreType)
+ {
+ switch (featureID)
+ {
+ case EresourcePackage.CDO_RESOURCE__URI:
+ return getURI();
+
+ default:
+ return super.eGet(featureID, resolve, coreType);
+ }
+ }
+
+ @Override
+ public void eSet(int featureID, Object newValue)
+ {
+ switch (featureID)
+ {
+ case EresourcePackage.CDO_RESOURCE__URI:
+ setURI((URI)newValue);
+ break;
+
+ default:
+ super.eSet(featureID, newValue);
+ }
+ }
+
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java
index ddd9534f57..17ca11c8da 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008-2012 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2008-2013 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Christian W. Damus (CEA LIST) - bug 416298: CDOResourceNodes do not support reflective access to derived path attribute
*/
package org.eclipse.emf.cdo.eresource.impl;
@@ -255,4 +256,31 @@ public abstract class CDOResourceNodeImpl extends CDOObjectImpl implements CDORe
throw new CDOException(MessageFormat.format(Messages.getString("CDOResourceNodeImpl.5"), newPath)); //$NON-NLS-1$
}
}
+
+ @Override
+ public Object eGet(int featureID, boolean resolve, boolean coreType)
+ {
+ switch (featureID)
+ {
+ case EresourcePackage.CDO_RESOURCE_NODE__PATH:
+ return getPath();
+
+ default:
+ return super.eGet(featureID, resolve, coreType);
+ }
+ }
+
+ @Override
+ public void eSet(int featureID, Object newValue)
+ {
+ switch (featureID)
+ {
+ case EresourcePackage.CDO_RESOURCE_NODE__PATH:
+ setPath((String)newValue);
+ break;
+
+ default:
+ super.eSet(featureID, newValue);
+ }
+ }
} // CDOResourceNodeImpl

Back to the top