Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-03-06 19:24:16 +0000
committerslewis2007-03-06 19:24:16 +0000
commitc6bea368361f2d7b0c272c8f731834791d81db0b (patch)
tree7ac74ecf40816d7b820896682381d8e1f57776e7 /tests/bundles
parent39dbbf8b35af51bff842100123f1eb68b0f1ad27 (diff)
downloadorg.eclipse.ecf-c6bea368361f2d7b0c272c8f731834791d81db0b.tar.gz
org.eclipse.ecf-c6bea368361f2d7b0c272c8f731834791d81db0b.tar.xz
org.eclipse.ecf-c6bea368361f2d7b0c272c8f731834791d81db0b.zip
Added IDFactory service. The service interface is org.eclipse.ecf.identity.IIDFactory. Added test code in org.eclipse.ecf.tests.IDFactoryServiceTest
Diffstat (limited to 'tests/bundles')
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/internal/tests/Activator.java16
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/IDFactoryServiceTest.java90
2 files changed, 106 insertions, 0 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/internal/tests/Activator.java b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/internal/tests/Activator.java
index ebf349725..6ae52a599 100755
--- a/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/internal/tests/Activator.java
+++ b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/internal/tests/Activator.java
@@ -1,7 +1,9 @@
package org.eclipse.ecf.internal.tests;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.ecf.core.identity.IIDFactory;
import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
/**
* The activator class controls the plug-in life cycle
@@ -14,6 +16,9 @@ public class Activator extends Plugin {
// The shared instance
private static Activator plugin;
+ private static ServiceTracker serviceTracker;
+ private static IIDFactory idFactory;
+
/**
* The constructor
*/
@@ -26,6 +31,9 @@ public class Activator extends Plugin {
*/
public void start(BundleContext context) throws Exception {
super.start(context);
+ serviceTracker = new ServiceTracker(context,IIDFactory.class.getName(), null);
+ serviceTracker.open();
+ idFactory = (IIDFactory) serviceTracker.getService();
plugin = this;
}
@@ -35,6 +43,11 @@ public class Activator extends Plugin {
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
+ idFactory = null;
+ if (serviceTracker != null) {
+ serviceTracker.close();
+ serviceTracker = null;
+ }
super.stop(context);
}
@@ -47,4 +60,7 @@ public class Activator extends Plugin {
return plugin;
}
+ public IIDFactory getIDFactory() {
+ return idFactory;
+ }
}
diff --git a/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/IDFactoryServiceTest.java b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/IDFactoryServiceTest.java
new file mode 100755
index 000000000..147fdb58d
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/IDFactoryServiceTest.java
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * Copyright (c) 2004 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.util.List;
+
+import org.eclipse.ecf.core.identity.GUID;
+import org.eclipse.ecf.core.identity.IIDFactory;
+import org.eclipse.ecf.core.identity.LongID;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.core.identity.StringID;
+import org.eclipse.ecf.internal.tests.Activator;
+
+public class IDFactoryServiceTest extends NamespaceTest {
+
+ IIDFactory fixture = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ fixture = Activator.getDefault().getIDFactory();
+ assertNotNull(fixture);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ fixture = null;
+ assertNull(fixture);
+ }
+
+ public void testIDFactoryGetNamespaces() {
+ List namespaces = fixture.getNamespaces();
+ assertNotNull(namespaces);
+ assertTrue(namespaces.size() > 0);
+ }
+
+ public void testIDFactoryGetStringIDNamespaceByName() {
+ Namespace namespace = fixture.getNamespaceByName(StringID.class
+ .getName());
+ assertNotNull(namespace);
+ }
+
+ public void testIDFactoryGetGUIDIDNamespaceByName() {
+ Namespace namespace = fixture.getNamespaceByName(GUID.class.getName());
+ assertNotNull(namespace);
+ }
+
+ public void testIDFactoryGetLongIDNamespaceByName() {
+ Namespace namespace = fixture
+ .getNamespaceByName(LongID.class.getName());
+ assertNotNull(namespace);
+ }
+
+ public void testIDFactoryAddNamespace() {
+ Namespace namespace = createNamespace();
+ int currentSize = fixture.getNamespaces().size();
+ Namespace ns = fixture.addNamespace(namespace);
+ assertNull(ns);
+ assertTrue(fixture.getNamespaces().size() == (currentSize + 1));
+ }
+
+ public void testIDFactoryRemoveNamespace() {
+ Namespace namespace = fixture.getNamespaceByName(StringID.class
+ .getName());
+ int currentSize = fixture.getNamespaces().size();
+ Namespace removed = fixture.removeNamespace(namespace);
+ assertNotNull(removed);
+ assertTrue(fixture.getNamespaces().size() == (currentSize - 1));
+ // Put it back
+ fixture.addNamespace(removed);
+ }
+}

Back to the top