Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2019-02-03 03:37:04 -0500
committerEike Stepper2019-02-03 03:37:04 -0500
commit9b86d2e358a5d6785be4cf1c4502fcde0f5406c0 (patch)
tree757c7a05c79ea03dbcba7cd7de92ee32ff023d8d /plugins/org.eclipse.emf.cdo.tests/src
parent5a214bcbdf877c8f9bcca90ad5d1d09ede54fc05 (diff)
downloadcdo-9b86d2e358a5d6785be4cf1c4502fcde0f5406c0.tar.gz
cdo-9b86d2e358a5d6785be4cf1c4502fcde0f5406c0.tar.xz
cdo-9b86d2e358a5d6785be4cf1c4502fcde0f5406c0.zip
[544075] Add setBasename() and setExtension() methods to CDOResourceNode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=544075
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java82
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334995_Test.java66
2 files changed, 125 insertions, 23 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java
index 6e3e3630b5..ffe071c98a 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java
@@ -2218,6 +2218,88 @@ public class ResourceTest extends AbstractCDOTest
}
}
+ public void testNameChecks()
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource1 = transaction.createResource(getResourcePath("/my/resource1"));
+
+ assertEquals("resource1", resource1.getName());
+ assertEquals("resource1", resource1.getBasename());
+ assertEquals("", resource1.getExtension());
+
+ try
+ {
+ resource1.setName("/resource1");
+ fail("IllegalArgumentException expected");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ // SUCCESS
+ }
+
+ resource1.setExtension("tar.gz");
+ assertEquals("resource1.tar.gz", resource1.getName());
+ assertEquals("resource1", resource1.getBasename());
+ assertEquals("tar.gz", resource1.getExtension());
+
+ resource1.setBasename("model");
+ assertEquals("model.tar.gz", resource1.getName());
+ assertEquals("model", resource1.getBasename());
+ assertEquals("tar.gz", resource1.getExtension());
+
+ try
+ {
+ resource1.setBasename("model.xyz");
+ fail("IllegalArgumentException expected");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ // SUCCESS
+ }
+
+ resource1.setExtension("");
+ assertEquals("model", resource1.getName());
+ assertEquals("model", resource1.getBasename());
+ assertEquals("", resource1.getExtension());
+
+ resource1.setExtension("ecore");
+ resource1.setBasename("");
+ assertEquals(".ecore", resource1.getName());
+ assertEquals("", resource1.getBasename());
+ assertEquals("ecore", resource1.getExtension());
+
+ try
+ {
+ resource1.setName(null);
+ fail("IllegalArgumentException expected");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ // SUCCESS
+ }
+
+ try
+ {
+ resource1.setName("");
+ fail("IllegalArgumentException expected");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ // SUCCESS
+ }
+
+ try
+ {
+ resource1.setName(".");
+ fail("IllegalArgumentException expected");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ // SUCCESS
+ }
+ }
+
/**
* @author Eike Stepper
*/
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334995_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334995_Test.java
index 79ea70ff09..873eddf9d4 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334995_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334995_Test.java
@@ -18,6 +18,8 @@ import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.ecore.resource.Resource;
+
import java.util.Map.Entry;
/**
@@ -30,37 +32,55 @@ public class Bugzilla_334995_Test extends AbstractCDOTest
/**
* The following test seems obsolete because (as of bug xxxxxx) no local changes can create resource duplicates.
*/
- public void _test() throws CommitException
+ public void testURIClash() throws CommitException
{
- CDOID resourceID = persistResources("/res1")[0];
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resourceA = transaction.createResource(getResourcePath("/resA"));
+ resourceA.getContents().add(getModel1Factory().createCustomer());
+ transaction.commit();
+ System.out.println("Persisted resource: " + resourceA);
- {
- CDOSession session = openSession();
- CDOTransaction transaction = session.openTransaction();
+ CDOSession session2 = openSession();
+ CDOTransaction transaction2 = session2.openTransaction();
+ CDOResource resourceB2 = transaction2.createResource(getResourcePath("/resB"));
+ resourceB2.getContents().add(getModel1Factory().createSupplier());
- CDOResource resource = transaction.createResource(getResourcePath("/res1"));
- msg("New resource: " + resource);
- msg("newObjects:");
+ resourceA.setName("resB");
+ commitAndSync(transaction, transaction2);
- for (Entry<CDOID, CDOObject> entry : transaction.getNewObjects().entrySet())
- {
- msg(" " + entry + ", state: " + entry.getValue().cdoState());
- assertNew(entry.getValue(), transaction);
- }
+ System.out.println("newObjects:");
+ for (Entry<CDOID, CDOObject> entry : transaction2.getNewObjects().entrySet())
+ {
+ System.out.println(" " + entry + ", state: " + entry.getValue().cdoState());
+ assertNew(entry.getValue(), transaction2);
+ }
- // Fetch the persisted resource that has the same URI
- CDOResource resource1 = (CDOResource)transaction.getObject(resourceID);
- msg("Persisted resource: " + resource1);
+ System.out.println("resources:");
+ for (Resource resource : transaction2.getResourceSet().getResources())
+ {
+ System.out.println(" " + resource);
+ }
- msg("newObjects:");
- for (Entry<CDOID, CDOObject> entry : transaction.getNewObjects().entrySet())
- {
- msg(" " + entry + ", state: " + entry.getValue().cdoState());
- assertNew(entry.getValue(), transaction);
- }
+ // Fetch the persisted resource that has the same URI
+ CDOResource resourceA2 = (CDOResource)transaction2.getObject(resourceA.cdoID());
+ System.out.println("Remote resource: " + resourceA2);
+ System.out.println("Local resource: " + resourceB2);
- transaction.commit();
+ System.out.println("newObjects:");
+ for (Entry<CDOID, CDOObject> entry : transaction2.getNewObjects().entrySet())
+ {
+ System.out.println(" " + entry + ", state: " + entry.getValue().cdoState());
+ assertNew(entry.getValue(), transaction2);
}
+
+ System.out.println("resources:");
+ for (Resource resource : transaction2.getResourceSet().getResources())
+ {
+ System.out.println(" " + resource);
+ }
+
+ transaction2.commit();
}
public void testRename() throws CommitException

Back to the top