Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

@FakeApplication

  • Loading branch information...
commit 763f8c706743d2b6a6287628f034956ec9d5c494 1 parent 4a4c834
jtournay authored
View
13 project/Build.scala
@@ -3,6 +3,9 @@ import sbt.Defaults._
import sbt.Keys._
object NGPluginBuild extends Build {
+
+ // TODO: hard coded path...
+ val localrepo = Resolver.file("Play local repo", new File(Path.userHome.absolutePath + "/Documents/jto_Play20/repository/local"))(Resolver.ivyStylePatterns)
lazy val root = Project(
id = "play-testng-helpers",
@@ -10,7 +13,10 @@ object NGPluginBuild extends Build {
settings = Project.defaultSettings ++ commonSettings ++ Seq(
version := "1.0-SNAPSHOT",
crossScalaVersions := Seq("2.9.1"),
- libraryDependencies ++= Seq()))
+ libraryDependencies ++= Seq(
+ "org.testng" % "testng" % "6.4" /*% "provided"*/,
+ "play" %% "play-test" % "2.1-SNAPSHOT" //% "provided"
+ )))
lazy val NGPlugin = Project(
id = "play-plugins-testng",
@@ -28,9 +34,10 @@ object NGPluginBuild extends Build {
lazy val commonSettings: Seq[Setting[_]] = publishSettings ++ Seq(
organization := "com.linkedin",
- scalaVersion := "2.9.1")
+ scalaVersion := "2.9.1",
+ resolvers += localrepo)
lazy val publishSettings: Seq[Setting[_]] = Seq(publishTo := Some(
- Resolver.file("Local repo", new File(Path.userHome.absolutePath + "/Documents/linkedin/play2/repository/local"))(Resolver.ivyStylePatterns)),
+ localrepo),
publishMavenStyle := false)
}
View
25 sample/app/controllers/Application.java
@@ -0,0 +1,25 @@
+package controllers;
+
+import play.*;
+import play.mvc.*;
+import play.data.*;
+import play.data.validation.Constraints.*;
+
+import java.util.*;
+
+import views.html.*;
+
+public class Application extends Controller {
+
+
+
+ /**
+ * Home page
+ */
+ public static Result index() {
+ return ok("Helloworld");
+ }
+
+
+
+}
View
12 sample/app/controllers/Application.scala
@@ -1,12 +0,0 @@
-package controllers
-
-import play.api._
-import play.api.mvc._
-
-object Application extends Controller {
-
- def index = Action {
- Ok(views.html.index("Your new application is ready."))
- }
-
-}
View
25 sample/test/SimpleTest.java
@@ -5,23 +5,24 @@
import play.libs.F.*;
import static play.test.Helpers.*;
-
-public class SimpleTest {
-
+
+import com.linkedin.plugin.*;
+
+public class SimpleTest extends LITests {
+
@Test
public void aFastTest() {
- running(fakeApplication(inMemoryDatabase()), new Runnable() {
- public void run() {
- System.out.println("Fast test");
- }
- });
+ System.out.println("Fast test");
}
@Test
- @com.linkedin.plugin.FakeApplication
+ @WithFakeApplication(configurations = {
+ @Conf(key="test.fakeconf", value="fake"),
+ @Conf(key="test.loutre", value="oink")
+ })
public void aFailingTest() {
- if(true) throw new RuntimeException("FAIL");
- System.out.println("failing test");
+ String f = play.Play.application().configuration().getString("test.fakeconf");
+ if(!f.equals("fake"))
+ throw new RuntimeException("Assertion failed");
}
-
}
View
14 src/main/java/com/linkedin/plugin/Conf.java
@@ -0,0 +1,14 @@
+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)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Conf {
+ String key();
+ String value();
+}
View
9 src/main/java/com/linkedin/plugin/FakeApplication.java
@@ -1,9 +0,0 @@
-package com.linkedin.plugin;
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@Target(ElementType.METHOD)
-public @interface FakeApplication {
- String conf() default "";
-}
View
30 src/main/java/com/linkedin/plugin/LITests.java
@@ -0,0 +1,30 @@
+package com.linkedin.plugin;
+
+import java.util.*;
+
+import java.lang.reflect.*;
+import java.lang.annotation.*;
+import org.testng.*;
+
+import play.test.*;
+import static play.test.Helpers.*;
+
+public class LITests implements IHookable{
+ public void run(final IHookCallBack icb, ITestResult testResult) {
+ Method m = testResult.getMethod().getConstructorOrMethod().getMethod();
+ WithFakeApplication a = m.getAnnotation(WithFakeApplication.class);
+
+ if(a != null){
+ Map<String, String> conf = new HashMap<String, String>();
+ for(Conf c : a.configurations())
+ conf.put(c.key(), c.value());
+ FakeApplication app = fakeApplication(conf);
+ start(app);
+ icb.runTestMethod(testResult);
+ stop(app);
+ }
+ else{
+ icb.runTestMethod(testResult);
+ }
+ }
+}
View
13 src/main/java/com/linkedin/plugin/WithFakeApplication.java
@@ -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)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface WithFakeApplication {
+ Conf[] configurations() default {};
+}
Please sign in to comment.
Something went wrong with that request. Please try again.