Permalink
Browse files

more love

  • Loading branch information...
1 parent 763f8c7 commit 7a7ecf4f1b055cd20f68caf32635dc244df0bc4d jtournay committed Jun 26, 2012
@@ -0,0 +1,50 @@
+import org.testng.annotations.*;
+
+import play.mvc.*;
+import play.test.*;
+import play.libs.F.*;
+
+import static play.test.Helpers.*;
+
+import com.linkedin.plugin.*;
+
+@WithFakeApplication
+@Confs({
+ @Conf(key="test.fakeconf", value="fake")
+})
+@Conf(key="test.anotherConf", value="fake")
+public class AllWithFakeApp extends LITests {
+
+ @Test
+ @Confs({
+ @Conf(key="test.loutre", value="oink")
+ })
+ public void aFastTest() {
+ String f = play.Play.application().configuration().getString("test.loutre");
+ if(!f.equals("oink"))
+ throw new RuntimeException("Assertion failed");
+ }
+
+ @Test
+ public void anotherFastTest() {
+ String f = play.Play.application().configuration().getString("test.fakeconf");
+ if(!f.equals("fake"))
+ throw new RuntimeException("Assertion failed");
+ }
+
+ @Test
+ public void testAnotherConf() {
+ String f = play.Play.application().configuration().getString("test.anotherConf");
+ if(!f.equals("fake"))
+ throw new RuntimeException("Assertion failed");
+ }
+
+ @Test
+ @Conf(key="test.singleConf", value="fake")
+ public void testASingleConf() {
+ String f = play.Play.application().configuration().getString("test.singleConf");
+ if(!f.equals("fake"))
+ throw new RuntimeException("Assertion failed");
+ }
+
+}
@@ -16,9 +16,10 @@ public void aFastTest() {
}
@Test
- @WithFakeApplication(configurations = {
- @Conf(key="test.fakeconf", value="fake"),
- @Conf(key="test.loutre", value="oink")
+ @WithFakeApplication
+ @Confs({
+ @Conf(key="test.fakeconf", value="fake"),
+ @Conf(key="test.loutre", value="oink")
})
public void aFailingTest() {
String f = play.Play.application().configuration().getString("test.fakeconf");
@@ -5,3 +5,4 @@ tests:
- name: st
classes:
- SimpleTest
+ - AllWithFakeApp
@@ -6,7 +6,7 @@
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
-@Target(ElementType.METHOD)
+@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Conf {
String key();
@@ -0,0 +1,13 @@
+package com.linkedin.plugin;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Confs {
+ Conf[] value() default {};
+}
@@ -11,13 +11,37 @@
public class LITests implements IHookable{
public void run(final IHookCallBack icb, ITestResult testResult) {
+
+ Class clazz = testResult.getTestClass().getRealClass();
Method m = testResult.getMethod().getConstructorOrMethod().getMethod();
+
+ WithFakeApplication classFakeApp = (WithFakeApplication)clazz.getAnnotation(WithFakeApplication.class);
WithFakeApplication a = m.getAnnotation(WithFakeApplication.class);
-
- if(a != null){
+
+ Confs classConfs = (Confs)clazz.getAnnotation(Confs.class);
+ Conf classConf = (Conf)clazz.getAnnotation(Conf.class);
+ Confs methodConfs = m.getAnnotation(Confs.class);
+ Conf methodConf = m.getAnnotation(Conf.class);
+
+ if(classFakeApp != null || a != null){
Map<String, String> conf = new HashMap<String, String>();
- for(Conf c : a.configurations())
- conf.put(c.key(), c.value());
+
+ if(classConfs != null){
+ for(Conf c : classConfs.value())
+ conf.put(c.key(), c.value());
+ }
+
+ if(classConf != null)
+ conf.put(classConf.key(), classConf.value());
+
+ if(methodConfs != null){
+ for(Conf c : methodConfs.value())
+ conf.put(c.key(), c.value());
+ }
+
+ if(methodConf != null)
+ conf.put(methodConf.key(), methodConf.value());
+
FakeApplication app = fakeApplication(conf);
start(app);
icb.runTestMethod(testResult);
@@ -6,8 +6,7 @@
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
-@Target(ElementType.METHOD)
+@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface WithFakeApplication {
- Conf[] configurations() default {};
}

0 comments on commit 7a7ecf4

Please sign in to comment.