diff options
author | Eike Stepper | 2013-09-01 06:23:09 +0000 |
---|---|---|
committer | Eike Stepper | 2013-09-01 06:23:09 +0000 |
commit | 4665db834f03a248f50427bf2d4f6872f4c8807e (patch) | |
tree | dc0004c804838167494ca5d192c7b81cae188ec6 | |
parent | 3a04c8cb9825f1312e5899d83f046da98ae4a0f0 (diff) | |
download | cdo-4665db834f03a248f50427bf2d4f6872f4c8807e.tar.gz cdo-4665db834f03a248f50427bf2d4f6872f4c8807e.tar.xz cdo-4665db834f03a248f50427bf2d4f6872f4c8807e.zip |
[416298] CDOResourceNodes do not support reflective access to derived
path attribute
https://bugs.eclipse.org/bugs/show_bug.cgi?id=416298
3 files changed, 107 insertions, 18 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 index aaec704ee1..b7562764a4 100644 --- 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 @@ -10,51 +10,111 @@ */ package org.eclipse.emf.cdo.tests.bugzilla; -import static org.eclipse.emf.cdo.eresource.EresourcePackage.Literals.CDO_RESOURCE_NODE__PATH; - 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: Tests that resource nodes provide proper reflective access to the derived 'path' attribute. + * 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 { - public void testGetSetResourcePath() throws Exception + 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 { - CDOSession session = openSession(); + String path = getResourcePath("/path/to/resource"); + CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.createResource(path); - CDOResource res = transaction.getOrCreateResource("/path/to/resource.model1"); + URI uri = (URI)resource.eGet(URI_ATTRIBUTE); + assertEquals(createURI(path), uri); - assertEquals("/path/to/resource.model1", res.eGet(CDO_RESOURCE_NODE__PATH)); + URI newURI = createURI(getParent(path) + "/new-resource"); + resource.eSet(URI_ATTRIBUTE, newURI); + assertEquals(newURI, resource.getURI()); + assertEquals(newURI, resource.eGet(URI_ATTRIBUTE)); - res.eSet(CDO_RESOURCE_NODE__PATH, "/new/folder/resource.model1"); + transaction.commit(); + assertEquals(newURI, resource.getURI()); + assertEquals(newURI, resource.eGet(URI_ATTRIBUTE)); - assertNotNull(res.getFolder()); - assertEquals("/new/folder", res.getFolder().getPath()); + resource.eSet(URI_ATTRIBUTE, uri); + assertEquals(uri, resource.getURI()); + assertEquals(uri, resource.eGet(URI_ATTRIBUTE)); } - public void testGetSetFolderPath() throws Exception + 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)); - CDOResourceFolder folder = transaction.getOrCreateResourceFolder("/path/to/folder"); + 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()); - assertEquals("/path/to/folder", folder.eGet(CDO_RESOURCE_NODE__PATH)); + transaction.commit(); + assertEquals(newPath, folder.getPath()); + assertEquals(newPath, folder.eGet(PATH_ATTRIBUTE)); + assertEquals(transaction.getResourceFolder(getParent(newPath)), folder.getFolder()); - folder.eSet(CDO_RESOURCE_NODE__PATH, "/atRoot"); + folder.eSet(PATH_ATTRIBUTE, path); + assertEquals(path, folder.getPath()); + assertEquals(path, folder.eGet(PATH_ATTRIBUTE)); + assertEquals(transaction.getResourceFolder(getParent(path)), folder.getFolder()); + } - assertNull(folder.getFolder()); - assertEquals("atRoot", folder.getName()); + 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 c4b7f36246..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 @@ -7,7 +7,7 @@ * * Contributors: * Eike Stepper - initial API and implementation - * Christian W. Damus (CEA LIST) - 416298: reflective access to 'path' attribute + * Christian W. Damus (CEA LIST) - bug 416298: CDOResourceNodes do not support reflective access to derived path attribute */ package org.eclipse.emf.cdo.eresource.impl; @@ -264,6 +264,7 @@ public abstract class CDOResourceNodeImpl extends CDOObjectImpl implements CDORe { case EresourcePackage.CDO_RESOURCE_NODE__PATH: return getPath(); + default: return super.eGet(featureID, resolve, coreType); } @@ -277,9 +278,9 @@ public abstract class CDOResourceNodeImpl extends CDOObjectImpl implements CDORe case EresourcePackage.CDO_RESOURCE_NODE__PATH: setPath((String)newValue); break; + default: super.eSet(featureID, newValue); - break; } } } // CDOResourceNodeImpl |