~ factorize POST method
authorAlexandre Bertails <bertails@w3.org>
Wed, 24 Aug 2011 14:43:50 -0400
changeset 64 764b4cf0f325
parent 63 6ff1023ed3dd
child 65 f959fad73852
~ factorize POST method
src/main/scala/Util.scala
src/test/scala/RecordAPISpec.scala
--- a/src/main/scala/Util.scala	Wed Aug 24 14:33:51 2011 -0400
+++ b/src/main/scala/Util.scala	Wed Aug 24 14:43:50 2011 -0400
@@ -7,6 +7,13 @@
 import java.net.{URL, URLDecoder}
 import org.slf4j.{Logger, LoggerFactory}
 
+object RequestHelper {
+  import dispatch._
+  
+  def POST(req:Request, body:String) = (req <<< body).copy(method="POST")
+  
+}
+
 /** useful stuff to read resources from the classpath */
 object ResourceManager {
   
--- a/src/test/scala/RecordAPISpec.scala	Wed Aug 24 14:33:51 2011 -0400
+++ b/src/test/scala/RecordAPISpec.scala	Wed Aug 24 14:43:50 2011 -0400
@@ -1,5 +1,7 @@
 package org.w3.virtualtrainer
 
+import org.w3.virtualtrainer.util.RequestHelper
+
 import org.specs._
 import java.net.URL
 
@@ -35,12 +37,11 @@
  ]
 }
 """
-  
     
   "POST record" should {
     val POSTrun = host / "user" / "jdoe" / "run"
     "return a location telling where the record is GETtable" in {
-      val locationHeader:String = Http((POSTrun <<< record).copy(method="POST") >:> { headers =>
+      val locationHeader:String = Http(RequestHelper.POST(POSTrun, record) >:> { headers =>
         headers get "Location" getOrElse sys.error("no Location header") head
       })
       val locationURL = new URL(locationHeader)