summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-02-20 08:35:18 (EST)
committerStefan Liebig2008-02-20 08:35:18 (EST)
commit7ef3478695368779f624304a21565672f9cdefa9 (patch)
tree33373322c31ba506f47e8ac1db501633dc67b2b0
parenta68ea99396b08933669bd4470b44d76552ed9ef8 (diff)
downloadorg.eclipse.riena-7ef3478695368779f624304a21565672f9cdefa9.zip
org.eclipse.riena-7ef3478695368779f624304a21565672f9cdefa9.tar.gz
org.eclipse.riena-7ef3478695368779f624304a21565672f9cdefa9.tar.bz2
extended test for ranked services
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/InjectorTest.java65
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/service/Target.java50
2 files changed, 80 insertions, 35 deletions
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
index ad132d5..4e593ee 100644
--- 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
@@ -42,9 +42,9 @@ public class InjectorTest extends TestCase {
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);
+ new ServiceId("serviceId").injectInto(target).andStart(context);
+ new ServiceId("serviceId").injectInto(target).bind("bind").unbind("unbind").andStart(context);
+ new ServiceId("serviceId").useFilter("").injectInto(target).bind("bind").unbind("unbind").andStart(context);
}
public void testInjectDepOneObviousBindUnbindError() {
@@ -55,7 +55,7 @@ public class InjectorTest extends TestCase {
ServiceRegistration reg = context.registerService(DepOne.class.getName(), depOne, null);
try {
- new ServiceId(DepOne.class.getName()).injectInto(target).bind("baind").start(context);
+ new ServiceId(DepOne.class.getName()).injectInto(target).bind("baind").andStart(context);
fail("Well, that should not have happended");
} catch (IllegalArgumentException e) {
assertTrue(true);
@@ -72,7 +72,7 @@ public class InjectorTest extends TestCase {
ServiceRegistration reg = context.registerService(DepTwo.class.getName(), depTwo, null);
try {
- new ServiceId(DepOne.class.getName()).injectInto(target).bind("binde").unbind("entbinde").start(context);
+ new ServiceId(DepOne.class.getName()).injectInto(target).bind("binde").unbind("entbinde").andStart(context);
} catch (IllegalArgumentException e) {
assertTrue(true);
}
@@ -87,7 +87,7 @@ public class InjectorTest extends TestCase {
DepOne depOne = new DepOne();
ServiceRegistration reg = context.registerService(DepOne.class.getName(), depOne, null);
- Injector shot = new ServiceId(DepOne.class.getName()).injectInto(target).start(context);
+ Injector shot = new ServiceId(DepOne.class.getName()).injectInto(target).andStart(context);
assertEquals(1, target.count("bind", DepOne.class));
shot.stop();
@@ -103,10 +103,10 @@ public class InjectorTest extends TestCase {
DepOne depOne = new DepOne();
ServiceRegistration reg1 = context.registerService(DepOne.class.getName(), depOne, null);
- Injector shot1 = new ServiceId(DepOne.class.getName()).injectInto(target).start(context);
+ Injector shot1 = new ServiceId(DepOne.class.getName()).injectInto(target).andStart(context);
assertEquals(1, target.count("bind", DepOne.class));
- Injector shot2 = new ServiceId(DepTwo.class.getName()).injectInto(target).start(context);
+ Injector shot2 = new ServiceId(DepTwo.class.getName()).injectInto(target).andStart(context);
DepTwo depTwo = new DepTwo();
ServiceRegistration reg2 = context.registerService(DepTwo.class.getName(), depTwo, null);
@@ -131,7 +131,7 @@ public class InjectorTest extends TestCase {
ServiceRegistration reg = context.registerService(DepOne.class.getName(), depOne, null);
Injector shot = new ServiceId(DepOne.class.getName()).injectInto(target).bind("binde").unbind("entbinde")
- .start(context);
+ .andStart(context);
assertEquals(1, target.count("binde", DepOne.class));
shot.stop();
@@ -140,8 +140,8 @@ public class InjectorTest extends TestCase {
reg.unregister();
}
- public void testInjectRankedServices() {
- System.out.println("testInjectRankedServices:");
+ public void testInjectRankedServicesServicesRegisteredBefore() {
+ System.out.println("testInjectRankedServicesServicesRegisteredBefore:");
Target target = new Target();
IRanking rank1 = new RankingOne(0);
@@ -152,7 +152,7 @@ public class InjectorTest extends TestCase {
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);
+ Injector shot = new ServiceId(IRanking.class.getName()).useRanking().injectInto(target).andStart(context);
assertEquals(1, target.count("bind", IRanking.class));
assertEquals(100, target.getDepRanking());
@@ -164,6 +164,45 @@ public class InjectorTest extends TestCase {
reg2.unregister();
}
+ public void testInjectRankedServicesServicesRegisteredOnTheRun() {
+ System.out.println("testInjectRankedServicesServicesRegisteredOnTheRun:");
+ Target target = new Target();
+
+ IRanking rank1 = new RankingOne(0);
+ ServiceRegistration reg1 = context.registerService(IRanking.class.getName(), rank1, null);
+
+ Injector shot = new ServiceId(IRanking.class.getName()).useRanking().injectInto(target).andStart(context);
+ assertEquals(1, target.count("bind", IRanking.class));
+ assertEquals(0, target.getDepRanking());
+
+ 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);
+
+ assertEquals(1, target.count("bind", IRanking.class));
+
+ assertEquals(100, target.getDepRanking());
+
+ reg2.unregister();
+
+ assertEquals(1, target.count("bind", IRanking.class));
+
+ assertEquals(0, target.getDepRanking());
+
+ ServiceRegistration reg3 = context.registerService(IRanking.class.getName(), rank2, dict);
+
+ assertEquals(1, target.count("bind", IRanking.class));
+
+ assertEquals(100, target.getDepRanking());
+
+ shot.stop();
+ assertEquals(0, target.count("bind", IRanking.class));
+
+ reg1.unregister();
+ reg3.unregister();
+ }
+
public void testInjectMostSpecifBindMethod() {
System.out.println("testInjectMostSpecifBindMethod:");
Target target = new Target();
@@ -171,7 +210,7 @@ public class InjectorTest extends TestCase {
DepOne depOne = new DepOneOne();
ServiceRegistration reg = context.registerService(DepOne.class.getName(), depOne, null);
- Injector shot = new ServiceId(DepOne.class.getName()).injectInto(target).start(context);
+ Injector shot = new ServiceId(DepOne.class.getName()).injectInto(target).andStart(context);
assertEquals(1, target.count("bind", DepOneOne.class));
assertEquals(0, target.count("bind", DepOne.class));
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
index da0b842..a84faba 100644
--- 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
@@ -24,59 +24,66 @@ public class Target {
private IRanking ranking;
public void bind(DepOne dep) {
- System.out.print("bind:");
+ called("bind", DepOne.class, dep);
add("bind", DepOne.class);
}
public void unbind(DepOne dep) {
- System.out.print("unbind:");
+ called("unbind", DepOne.class, dep);
remove("bind", DepOne.class);
}
public void bind(DepTwo dep) {
- System.out.print("bind:");
+ called("bind", DepTwo.class, dep);
add("bind", DepTwo.class);
}
public void unbind(DepTwo dep) {
- System.out.print("unbind:");
+ called("unbind", DepTwo.class, dep);
remove("bind", DepTwo.class);
}
public void binde(DepOne dep) {
- System.out.print("binde:");
+ called("binde", DepOne.class, dep);
add("binde", DepOne.class);
}
public void entbinde(DepOne dep) {
- System.out.print("entbinde:");
+ called("entbinde", DepOne.class, dep);
remove("binde", DepOne.class);
}
- public void bind(IRanking ranking) {
- System.out.print("bind:");
+ public void bind(IRanking dep) {
+ called("bind", IRanking.class, dep);
add("bind", IRanking.class);
- this.ranking = ranking;
+ this.ranking = dep;
}
- public void unbind(IRanking ranking) {
- System.out.print("unbind:");
+ public void unbind(IRanking dep) {
+ called("unbind", IRanking.class, dep);
remove("bind", IRanking.class);
}
public void bind(DepOneOne dep) {
- System.out.print("bind:");
+ called("bind", DepOneOne.class, dep);
add("bind", DepOneOne.class);
}
public void unbind(DepOneOne dep) {
- System.out.print("unbind:");
+ called("unbind", DepOneOne.class, dep);
remove("bind", DepOneOne.class);
}
+ /**
+ * @param string
+ * @param object
+ */
+ private void called(String methodName, Class<?> type, Object object) {
+ System.out.println(methodName + "(" + type.getSimpleName() + ") -> " + object.getClass().getSimpleName());
+ }
+
public int count(String method, Class<?> clazz) {
- method = method + "(" + clazz.getName() + ")";
- List<Class<?>> deps4method = deps.get(method);
+ List<Class<?>> deps4method = deps.get(key(method, clazz));
if (deps4method != null)
return deps4method.size();
return 0;
@@ -87,22 +94,21 @@ public class Target {
}
private void add(String method, Class<?> depClass) {
- method = method + "(" + depClass.getName() + ")";
- List<Class<?>> deps4method = deps.get(method);
+ List<Class<?>> deps4method = deps.get(key(method, depClass));
if (deps4method == null) {
deps4method = new ArrayList<Class<?>>();
- deps.put(method, deps4method);
+ deps.put(key(method, depClass), 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);
+ List<Class<?>> deps4method = deps.get(key(method, depClass));
if (deps4method != null)
deps4method.remove(depClass);
- System.out.println(" " + method + " " + depClass.getName());
}
+ private String key(String methodKey, Class<?> type) {
+ return methodKey + "(" + type.getName() + ")";
+ }
}