summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-02-11 09:13:03 (EST)
committerStefan Liebig2008-02-11 09:13:03 (EST)
commit3f9e45c4065ddf2482ff187d7b7363af56840cdc (patch)
tree82b80d48df0968343767f0972744b4fd3085d450
parentb49ee0004ca4a70df2e67ce435a473b7a3e13676 (diff)
downloadorg.eclipse.riena-3f9e45c4065ddf2482ff187d7b7363af56840cdc.zip
org.eclipse.riena-3f9e45c4065ddf2482ff187d7b7363af56840cdc.tar.gz
org.eclipse.riena-3f9e45c4065ddf2482ff187d7b7363af56840cdc.tar.bz2
new service injector tests
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/AllTests.java2
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepOne.java18
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepOneOne.java18
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepTwo.java18
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/IRanking.java19
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/InjectorTest.java183
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/RankingOne.java28
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/RankingTwo.java28
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/Target.java108
9 files changed, 422 insertions, 0 deletions
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/AllTests.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/AllTests.java
index caf7047..b5837cf 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/core/AllTests.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/AllTests.java
@@ -17,6 +17,7 @@ import junit.framework.TestSuite;
import org.eclipse.riena.core.config.ConfigTest;
import org.eclipse.riena.core.exception.ExceptionHandlerManagerTest;
import org.eclipse.riena.core.extension.util.ExtensionUtilTest;
+import org.eclipse.riena.core.service.InjectorTest;
import org.eclipse.riena.core.service.ServiceInjectorTest;
/**
@@ -32,6 +33,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(ExceptionHandlerManagerTest.class);
suite.addTestSuite(ExtensionUtilTest.class);
suite.addTestSuite(ServiceInjectorTest.class);
+ suite.addTestSuite(InjectorTest.class);
return suite;
}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepOne.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepOne.java
new file mode 100644
index 0000000..5bda504
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepOne.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.service;
+
+/**
+ * Test class for injecting
+ */
+public class DepOne {
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepOneOne.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepOneOne.java
new file mode 100644
index 0000000..fd09c11
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepOneOne.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.service;
+
+/**
+ * Test class for injecting
+ */
+public class DepOneOne extends DepOne {
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepTwo.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepTwo.java
new file mode 100644
index 0000000..8e32ab3
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/DepTwo.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.service;
+
+/**
+ * Test class for injecting
+ */
+public class DepTwo {
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/IRanking.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/IRanking.java
new file mode 100644
index 0000000..f0c8770
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/IRanking.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.service;
+
+/**
+ * Test interface for injecting
+ */
+public interface IRanking {
+
+ int getRanking();
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/InjectorTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/InjectorTest.java
new file mode 100644
index 0000000..ad132d5
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/InjectorTest.java
@@ -0,0 +1,183 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.service;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import junit.framework.TestCase;
+
+import org.eclipse.riena.internal.tests.Activator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ *
+ */
+public class InjectorTest extends TestCase {
+
+ private BundleContext context;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ context = Activator.getContext();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ context = null;
+ super.tearDown();
+ }
+
+ public void scribble() {
+ Object target = null;
+
+ new ServiceId("serviceId").injectInto(target).start(context);
+ new ServiceId("serviceId").injectInto(target).bind("bind").unbind("unbind").start(context);
+ new ServiceId("serviceId").useFilter("").injectInto(target).bind("bind").unbind("unbind").start(context);
+ }
+
+ public void testInjectDepOneObviousBindUnbindError() {
+ System.out.println("testInjectDepOneObviousBindUnbindError:");
+ Target target = new Target();
+
+ DepOne depOne = new DepOne();
+ ServiceRegistration reg = context.registerService(DepOne.class.getName(), depOne, null);
+
+ try {
+ new ServiceId(DepOne.class.getName()).injectInto(target).bind("baind").start(context);
+ fail("Well, that should not have happended");
+ } catch (IllegalArgumentException e) {
+ assertTrue(true);
+ }
+
+ reg.unregister();
+ }
+
+ public void testInjectDepOneNotSoObviousBindUnbindError() {
+ System.out.println("testInjectDepOneNotSoObviousBindUnbindError:");
+ Target target = new Target();
+
+ DepTwo depTwo = new DepTwo();
+ ServiceRegistration reg = context.registerService(DepTwo.class.getName(), depTwo, null);
+
+ try {
+ new ServiceId(DepOne.class.getName()).injectInto(target).bind("binde").unbind("entbinde").start(context);
+ } catch (IllegalArgumentException e) {
+ assertTrue(true);
+ }
+
+ reg.unregister();
+ }
+
+ public void testInjectDepOneDefaultBindUnbind() {
+ System.out.println("testInjectDepOneDefaultBindUnbind:");
+ Target target = new Target();
+
+ DepOne depOne = new DepOne();
+ ServiceRegistration reg = context.registerService(DepOne.class.getName(), depOne, null);
+
+ Injector shot = new ServiceId(DepOne.class.getName()).injectInto(target).start(context);
+ assertEquals(1, target.count("bind", DepOne.class));
+
+ shot.stop();
+ assertEquals(0, target.count("bind", DepOne.class));
+
+ reg.unregister();
+ }
+
+ public void testInjectDepOneAndDepTwoDefaultBindUnbind() {
+ System.out.println("testInjectDepOneAndDepTwoDefaultBindUnbind:");
+ Target target = new Target();
+
+ DepOne depOne = new DepOne();
+ ServiceRegistration reg1 = context.registerService(DepOne.class.getName(), depOne, null);
+
+ Injector shot1 = new ServiceId(DepOne.class.getName()).injectInto(target).start(context);
+ assertEquals(1, target.count("bind", DepOne.class));
+
+ Injector shot2 = new ServiceId(DepTwo.class.getName()).injectInto(target).start(context);
+
+ DepTwo depTwo = new DepTwo();
+ ServiceRegistration reg2 = context.registerService(DepTwo.class.getName(), depTwo, null);
+
+ assertEquals(1, target.count("bind", DepTwo.class));
+
+ shot1.stop();
+ assertEquals(0, target.count("bind", DepOne.class));
+
+ shot2.stop();
+ assertEquals(0, target.count("bind", DepTwo.class));
+
+ reg1.unregister();
+ reg2.unregister();
+ }
+
+ public void testInjectDepOneBindeEntbinde() {
+ System.out.println("testInjectDepOneBindeEntbinde:");
+ Target target = new Target();
+
+ DepOne depOne = new DepOne();
+ ServiceRegistration reg = context.registerService(DepOne.class.getName(), depOne, null);
+
+ Injector shot = new ServiceId(DepOne.class.getName()).injectInto(target).bind("binde").unbind("entbinde")
+ .start(context);
+ assertEquals(1, target.count("binde", DepOne.class));
+
+ shot.stop();
+ assertEquals(0, target.count("binde", DepOne.class));
+
+ reg.unregister();
+ }
+
+ public void testInjectRankedServices() {
+ System.out.println("testInjectRankedServices:");
+ Target target = new Target();
+
+ IRanking rank1 = new RankingOne(0);
+ ServiceRegistration reg1 = context.registerService(IRanking.class.getName(), rank1, null);
+
+ IRanking rank2 = new RankingTwo(100);
+ Dictionary<String, Object> dict = new Hashtable<String, Object>();
+ dict.put(Constants.SERVICE_RANKING, Integer.valueOf(100));
+ ServiceRegistration reg2 = context.registerService(IRanking.class.getName(), rank2, dict);
+
+ Injector shot = new ServiceId(IRanking.class.getName()).useRanking().injectInto(target).start(context);
+ assertEquals(1, target.count("bind", IRanking.class));
+
+ assertEquals(100, target.getDepRanking());
+
+ shot.stop();
+ assertEquals(0, target.count("bind", IRanking.class));
+
+ reg1.unregister();
+ reg2.unregister();
+ }
+
+ public void testInjectMostSpecifBindMethod() {
+ System.out.println("testInjectMostSpecifBindMethod:");
+ Target target = new Target();
+
+ DepOne depOne = new DepOneOne();
+ ServiceRegistration reg = context.registerService(DepOne.class.getName(), depOne, null);
+
+ Injector shot = new ServiceId(DepOne.class.getName()).injectInto(target).start(context);
+ assertEquals(1, target.count("bind", DepOneOne.class));
+ assertEquals(0, target.count("bind", DepOne.class));
+
+ shot.stop();
+ assertEquals(0, target.count("bind", DepOneOne.class));
+
+ reg.unregister();
+ }
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/RankingOne.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/RankingOne.java
new file mode 100644
index 0000000..be13562
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/RankingOne.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.service;
+
+/**
+ * Test class for injecting
+ */
+public class RankingOne implements IRanking {
+
+ private int ranking;
+
+ public RankingOne(int ranking) {
+ this.ranking = ranking;
+ }
+
+ public int getRanking() {
+ return ranking;
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/RankingTwo.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/RankingTwo.java
new file mode 100644
index 0000000..a6b6ea8
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/RankingTwo.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.service;
+
+/**
+ * Test class for injecting
+ */
+public class RankingTwo implements IRanking {
+
+ private int ranking;
+
+ public RankingTwo(int ranking) {
+ this.ranking = ranking;
+ }
+
+ public int getRanking() {
+ return ranking;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/Target.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/Target.java
new file mode 100644
index 0000000..da0b842
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/service/Target.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The target for injecting
+ */
+public class Target {
+
+ private Map<String, List<Class<?>>> deps = new HashMap<String, List<Class<?>>>();
+ private IRanking ranking;
+
+ public void bind(DepOne dep) {
+ System.out.print("bind:");
+ add("bind", DepOne.class);
+ }
+
+ public void unbind(DepOne dep) {
+ System.out.print("unbind:");
+ remove("bind", DepOne.class);
+ }
+
+ public void bind(DepTwo dep) {
+ System.out.print("bind:");
+ add("bind", DepTwo.class);
+ }
+
+ public void unbind(DepTwo dep) {
+ System.out.print("unbind:");
+ remove("bind", DepTwo.class);
+ }
+
+ public void binde(DepOne dep) {
+ System.out.print("binde:");
+ add("binde", DepOne.class);
+ }
+
+ public void entbinde(DepOne dep) {
+ System.out.print("entbinde:");
+ remove("binde", DepOne.class);
+ }
+
+ public void bind(IRanking ranking) {
+ System.out.print("bind:");
+ add("bind", IRanking.class);
+ this.ranking = ranking;
+ }
+
+ public void unbind(IRanking ranking) {
+ System.out.print("unbind:");
+ remove("bind", IRanking.class);
+ }
+
+ public void bind(DepOneOne dep) {
+ System.out.print("bind:");
+ add("bind", DepOneOne.class);
+ }
+
+ public void unbind(DepOneOne dep) {
+ System.out.print("unbind:");
+ remove("bind", DepOneOne.class);
+ }
+
+ public int count(String method, Class<?> clazz) {
+ method = method + "(" + clazz.getName() + ")";
+ List<Class<?>> deps4method = deps.get(method);
+ if (deps4method != null)
+ return deps4method.size();
+ return 0;
+ }
+
+ public int getDepRanking() {
+ return ranking.getRanking();
+ }
+
+ private void add(String method, Class<?> depClass) {
+ method = method + "(" + depClass.getName() + ")";
+ List<Class<?>> deps4method = deps.get(method);
+ if (deps4method == null) {
+ deps4method = new ArrayList<Class<?>>();
+ deps.put(method, deps4method);
+ }
+ deps4method.add(depClass);
+ System.out.println(" " + method + " " + depClass.getName());
+ }
+
+ private void remove(String method, Class<?> depClass) {
+ method = method + "(" + depClass.getName() + ")";
+ List<Class<?>> deps4method = deps.get(method);
+ if (deps4method != null)
+ deps4method.remove(depClass);
+ System.out.println(" " + method + " " + depClass.getName());
+ }
+
+}