esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r836069 - /incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/ApiTest.scala
Date Sat, 14 Nov 2009 00:09:16 GMT
Author: dpp
Date: Sat Nov 14 00:09:15 2009
New Revision: 836069

URL: http://svn.apache.org/viewvc?rev=836069&view=rev
Log:
Updated to use new TestKit

Modified:
    incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/ApiTest.scala

Modified: incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/ApiTest.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/ApiTest.scala?rev=836069&r1=836068&r2=836069&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/ApiTest.scala (original)
+++ incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/ApiTest.scala Sat Nov 14
00:09:15 2009
@@ -39,17 +39,18 @@
 
 import net.sourceforge.jwebunit.junit.WebTester
 import _root_.junit.framework.AssertionFailedError
-import testing.{HttpResponse, TestFramework}
+import testing.{ReportFailure, TestKit, HttpResponse, TestFramework}
 class ApiSpecsAsTest extends JUnit3(ApiSpecs)
 object ApiSpecsRunner extends ConsoleRunner(ApiSpecs)
 
-object ApiSpecs extends Specification with TestFramework {
+object ApiSpecs extends Specification with TestKit {
   JettyTestServer.start
 
-  def buildRunner = null
-  def tests = Nil
+  val baseUrl = JettyTestServer.urlFor("")
 
-  def baseUrl = JettyTestServer.urlFor("")
+implicit val reportError = new ReportFailure {
+  def fail(msg: String): Nothing = ApiSpecs.this.fail(msg)
+}
 
   val theUser = User.createAndPopulate.nickname("api_test").saveMe
   val token = {
@@ -57,21 +58,24 @@
     toke.uniqueId.is
   }
 
-  "API" should {
-    "Login" in {
-      post("/api/login", "token" -> token) match {
-        case hr: HttpResponse => hr.code must_== 200
 
-        hr.get("/api/status") match {
-          case h2: HttpResponse =>
-          (h2.xml \ "user" \ "@id").text must_== theUser.id.toString
-
-          case x =>  true must_== false
-        }
+  private def testSuccess(resp: HttpResponse) {
+    resp.code must_== 200
+    resp.contentType.toLowerCase().startsWith("text/xml") must_== true
+    (resp.xml \ "@success").text must_== "true"
+  }
 
+  "API" should {
 
-        case _ => true must_== false
+    "Login" in {
+      for {
+        login <- post("/api/login", "token" -> token) !@ "Failed to log in" if (testSuccess(login))
+        status <- login.get("/api/status") !@ "Failed to get status" if (testSuccess(status))
+      } {
+        (status.xml \ "user" \ "@id").text must_== theUser.id.toString
       }
     }
-    }
+
+    
+  }
 }



Mime
View raw message