Skip to main content
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorslewis2011-08-19 01:29:25 +0000
committerslewis2011-08-19 01:29:25 +0000
commitedccd1ae619681604b2b664002dc74b39e7f8dde (patch)
tree6103d335521d70068502e102e8b11da0e0fc0196 /tests
parentea25ef76141361e9477cba59fd11e0c1081ad6d2 (diff)
downloadorg.eclipse.ecf-edccd1ae619681604b2b664002dc74b39e7f8dde.tar.gz
org.eclipse.ecf-edccd1ae619681604b2b664002dc74b39e7f8dde.tar.xz
org.eclipse.ecf-edccd1ae619681604b2b664002dc74b39e7f8dde.zip
Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=355180
Diffstat (limited to 'tests')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/URIIDTest.java137
1 files changed, 137 insertions, 0 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/URIIDTest.java b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/URIIDTest.java
new file mode 100644
index 000000000..c962348b8
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/URIIDTest.java
@@ -0,0 +1,137 @@
+/****************************************************************************
+* Copyright (c) 2011 Composent, Inc. 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:
+* Composent, Inc. - initial API and implementation
+*****************************************************************************/
+package org.eclipse.ecf.tests.core.identity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.NotSerializableException;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.core.identity.URIID;
+
+public class URIIDTest extends IDAbstractTestCase {
+
+ public static final String URIIDNAMESPACE = URIID.class.getName();
+ public static final String URI1 = "http://lala/lala/lala";
+ public static final String URI2 = "zooo:barbarbarbarbarbarbarbar";
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.tests.IDTestCase#createID()
+ */
+ protected ID createID() throws IDCreateException {
+ return createID(URI1);
+ }
+
+ protected ID createID(String val) throws IDCreateException {
+ return IDFactory.getDefault().createID(URIIDNAMESPACE,val);
+ }
+
+ public void testCreate() throws Exception {
+ final ID newID = createID();
+ assertNotNull(newID);
+ }
+
+ public void testNullCreate() throws Exception {
+ try {
+ createID(null);
+ fail();
+ } catch (final IDCreateException e) {
+ // success
+ }
+ }
+
+ public void testGetName() throws Exception {
+ final ID id = createID(URI1);
+ assertTrue(id.getName().equals(URI1));
+ }
+
+ public void testToExternalForm() throws Exception {
+ final ID id = createID(URI1);
+ assertNotNull(id.toExternalForm());
+ }
+
+ public void testToString() throws Exception {
+ final ID id = createID(URI1);
+ assertNotNull(id.toString());
+ }
+
+ public void testIsEqual() throws Exception {
+ final ID id1 = createID();
+ final ID id2 = createID();
+ assertTrue(id1.equals(id2));
+ }
+
+ public void testHashCode() throws Exception {
+ final ID id1 = createID();
+ final ID id2 = createID();
+ assertTrue(id1.hashCode() == id2.hashCode());
+ }
+
+ public void testCompareToEqual() throws Exception {
+ final ID id1 = createID();
+ final ID id2 = createID();
+ assertTrue(id1.compareTo(id2) == 0);
+ assertTrue(id2.compareTo(id1) == 0);
+ }
+
+ public void testCompareToNotEqual() throws Exception {
+ final ID id1 = createID(URI1);
+ final ID id2 = createID(URI2);
+ assertTrue(id1.compareTo(id2) < 0);
+ assertTrue(id2.compareTo(id1) > 0);
+ }
+
+ public void testGetNamespace() throws Exception {
+ final ID id = createID();
+ final Namespace ns = id.getNamespace();
+ assertNotNull(ns);
+ }
+
+ public void testEqualNamespaces() throws Exception {
+ final ID id1 = createID();
+ final ID id2 = createID();
+ final Namespace ns1 = id1.getNamespace();
+ final Namespace ns2 = id2.getNamespace();
+ assertTrue(ns1.equals(ns2));
+ assertTrue(ns2.equals(ns2));
+ }
+
+ public void testSerializable() throws Exception {
+ final ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ final ObjectOutputStream out = new ObjectOutputStream(buf);
+ try {
+ out.writeObject(createID());
+ } catch (final NotSerializableException ex) {
+ fail(ex.getLocalizedMessage());
+ } finally {
+ out.close();
+ }
+ }
+
+ public void testCreateFromExternalForm() throws Exception {
+ final ID id1 = createID();
+ final String externalForm = id1.toExternalForm();
+ final ID id2 = IDFactory.getDefault().createID(id1.getNamespace(), externalForm);
+ assertTrue(id1.equals(id2));
+ }
+
+ public void testCreateFromURIForm() throws Exception {
+ final ID id1 = IDFactory.getDefault().createID(URIIDNAMESPACE,new Object[] { new URI(URI1) });
+ final String externalForm = id1.toExternalForm();
+ final ID id2 = IDFactory.getDefault().createID(id1.getNamespace(), externalForm);
+ assertTrue(id1.equals(id2));
+ }
+
+}

Back to the top