incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vdic...@apache.org
Subject svn commit: r950750 - in /incubator/esme/trunk/server/src: main/scala/org/apache/esme/api/API2.scala main/scala/org/apache/esme/model/AuthToken.scala test/scala/org/apache/esme/api/API2Test.scala
Date Wed, 02 Jun 2010 20:34:22 GMT
Author: vdichev
Date: Wed Jun  2 20:34:22 2010
New Revision: 950750

URL: http://svn.apache.org/viewvc?rev=950750&view=rev
Log:
Formatting changes.

Modified:
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AuthToken.scala
    incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/API2Test.scala

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala?rev=950750&r1=950749&r2=950750&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala Wed Jun  2 20:34:22 2010
@@ -18,14 +18,14 @@
  */
 
 /*
- * API2.scala                        
+ * API2.scala
  *
  * The structure of the API2 object is a dispatch rule table,
  * which is a match against the Lift request object Req(). The match
  * determines a function to call. The convention in our case is that
  * the function has a return type of
  * Box[Tuple3[Int,Map[String,String],Box[Elem]]]
- * 
+ *
  * This return type is inspired by Rack/WSGI and is implicitly
  * converted to the correct type of Lift Response by the ApiHelper
  * trait.
@@ -38,12 +38,12 @@
  *   2. A Map(String,String) representing response headers
  *   3. A Box[Elem] containing the response body.
  *
- */            
+ */
 
 package org.apache.esme.api
 
 import net.liftweb._
-import http._  
+import http._
 import auth._
 import actor._
 import rest._
@@ -59,7 +59,7 @@ import org.apache.esme.actor._
 import scala.xml.{NodeSeq, Text, Elem, XML, Node}
 
 import scala.collection.mutable.ListBuffer
- 
+
 
 import org.compass.annotations._
 import bootstrap.liftweb.Compass.compass
@@ -73,7 +73,7 @@ object API2 extends ApiHelper with XmlHe
 
   def authorizationRules: LiftRules.DispatchPF = {
     case Req("api2" :: "users" :: Nil, _, PostRequest)
-      if !User.checkRole("integration-admin") => unAuthorized  
+      if !User.checkRole("integration-admin") => unAuthorized
     case Req("api2" :: "users" :: _ :: tokens :: Nil, _, GetRequest)
       if !User.checkRole("integration-admin") => unAuthorized
     case Req("api2" :: "users" :: _ :: tokens :: Nil, _, PostRequest)
@@ -87,145 +87,145 @@ object API2 extends ApiHelper with XmlHe
 
   def dispatch: LiftRules.DispatchPF = {
     case Req("api2" :: "session" :: Nil, _, GetRequest) => allSessions
-    case Req("api2" :: "session" :: Nil, _, PostRequest) => addSession          
-    case Req("api2" :: "session" :: Nil, _, DeleteRequest) => removeSession                      
-	
-    case Req("api2" :: "users" :: Nil, _, GetRequest) => allUsers 
-    case Req("api2" :: "users" :: Nil, _, PostRequest) => addUser  
+    case Req("api2" :: "session" :: Nil, _, PostRequest) => addSession
+    case Req("api2" :: "session" :: Nil, _, DeleteRequest) => removeSession
+
+    case Req("api2" :: "users" :: Nil, _, GetRequest) => allUsers
+    case Req("api2" :: "users" :: Nil, _, PostRequest) => addUser
     case Req("api2" :: "users" :: id :: "tokens" :: Nil, _, GetRequest) => () => allTokens(id)
     case Req("api2" :: "users" :: id :: "tokens" :: Nil, _, PostRequest) => () => addToken(id)
-                                                                          
+
     case Req("api2" :: "user" :: "messages" :: Nil, _, GetRequest)
- 	  if S.param("timeout").isDefined => waitForMsgs
+      if S.param("timeout").isDefined => waitForMsgs
     case Req("api2" :: "user" :: "messages" :: Nil, _, GetRequest)
-      if S.param("history").isDefined => allUserMsgs   
-    case Req("api2" :: "user" :: "messages" :: Nil, _, GetRequest) => getNewMsgs    
+      if S.param("history").isDefined => allUserMsgs
+    case Req("api2" :: "user" :: "messages" :: Nil, _, GetRequest) => getNewMsgs
     case Req("api2" :: "user" :: "messages" :: Nil, _, PostRequest) => () => addMsg
 
     case Req("api2" :: "tags" :: tag :: "messages" :: Nil, _, GetRequest)
-  		    => () => allTagMsgs(tag)                                                 
+            => () => allTagMsgs(tag)
 
-    case Req("api2" :: "user" :: "followees" :: Nil, _, GetRequest) => allFollowees         
+    case Req("api2" :: "user" :: "followees" :: Nil, _, GetRequest) => allFollowees
     case Req("api2" :: "user" :: "followees" :: Nil, _, PostRequest) => addFollowee
-    case Req("api2" :: "user" :: "followees" :: userId :: Nil, _, DeleteRequest) 
-			=> removeFollow(Box(List(userId)))
+    case Req("api2" :: "user" :: "followees" :: userId :: Nil, _, DeleteRequest)
+            => removeFollow(Box(List(userId)))
 
-    case Req("api2" :: "user" :: "followers" :: Nil, _, GetRequest) => allFollowers         
+    case Req("api2" :: "user" :: "followers" :: Nil, _, GetRequest) => allFollowers
 
     case Req("api2" :: "user" :: "tracks" :: Nil, _, GetRequest) => allTracking
     case Req("api2" :: "user" :: "tracks" :: Nil, _, PostRequest) => addTracking
-    case Req("api2" :: "user" :: "tracks" :: trackId :: Nil, _, DeleteRequest) => () 
-			=> removeTracking(Box(List(trackId)))
+    case Req("api2" :: "user" :: "tracks" :: trackId :: Nil, _, DeleteRequest) => ()
+            => removeTracking(Box(List(trackId)))
 
-    case Req("api2" :: "user" :: "actions" :: Nil, _, GetRequest) => allActions 
+    case Req("api2" :: "user" :: "actions" :: Nil, _, GetRequest) => allActions
     case Req("api2" :: "user" :: "actions" :: Nil, _, PostRequest) => addAction
-    case Req("api2" :: "user" :: "actions" :: actionId :: Nil, _, PutRequest) => () 
-			=> changeAction(Box(List(actionId)))
-    case Req("api2" :: "user" :: "actions" :: actionId :: Nil, _, DeleteRequest) => () 
-			=> removeAction(Box(List(actionId)))
-                                                                                
-    case Req("api2" :: "pools" :: Nil, _, GetRequest) => allPools 
-    case Req("api2" :: "pools" :: Nil, _, PostRequest) => () => addPool 
-    case Req("api2" :: "pools" :: poolId :: "users" :: Nil, _, PostRequest) => () 
-			=> addUserToPool(poolId)
+    case Req("api2" :: "user" :: "actions" :: actionId :: Nil, _, PutRequest) => ()
+            => changeAction(Box(List(actionId)))
+    case Req("api2" :: "user" :: "actions" :: actionId :: Nil, _, DeleteRequest) => ()
+            => removeAction(Box(List(actionId)))
+
+    case Req("api2" :: "pools" :: Nil, _, GetRequest) => allPools
+    case Req("api2" :: "pools" :: Nil, _, PostRequest) => () => addPool
+    case Req("api2" :: "pools" :: poolId :: "users" :: Nil, _, PostRequest) => ()
+            => addUserToPool(poolId)
     case Req("api2" :: "pools" :: poolId :: "messages" :: Nil, _, GetRequest)
- 	  if S.param("timeout").isDefined => () => waitForPoolMsgs(poolId)
+      if S.param("timeout").isDefined => () => waitForPoolMsgs(poolId)
     case Req("api2" :: "pools" :: poolId :: "messages" :: Nil, _, GetRequest)
-      if S.param("history").isDefined => () => histPoolMsgs(poolId)   
-    case Req("api2" :: "pools" :: poolId :: "messages" :: Nil, _, GetRequest) => () 
+      if S.param("history").isDefined => () => histPoolMsgs(poolId)
+    case Req("api2" :: "pools" :: poolId :: "messages" :: Nil, _, GetRequest) => ()
             => getPoolMsgs(poolId)
-    
-    case Req("api2" :: "conversations" :: conversationId :: Nil, _, GetRequest) => () 
-			=> getConversation(Box(List(conversationId)))
+
+    case Req("api2" :: "conversations" :: conversationId :: Nil, _, GetRequest) => ()
+            => getConversation(Box(List(conversationId)))
   }
 
   def allSessions(): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
-	  for (user <- User.currentUser)
-      yield { 
-		(200,Map(),Full(<session>{userToXml(user)}</session>))
-	  }
-
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((404,Map(),Empty))
-	
-	r
-  }      
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      for (user <- User.currentUser)
+      yield {
+        (200,Map(),Full(<session>{userToXml(user)}</session>))
+      }
+
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((404,Map(),Empty))
+
+    r
+  }
 
   def addSession(): LiftResponse = {
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = if (User.loggedIn_?) Empty else
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = if (User.loggedIn_?) Empty else
     for(token <- S.param("token")) yield {
       val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = for {
         auth <- AuthToken.find(By(AuthToken.uniqueId, token))
-        user <- auth.user.obj 
+        user <- auth.user.obj
         val user_xml: Elem = <session>{userToXml(user)}</session>
       } yield {
         User.logUserIn(user)
         val myActor = buildActor(user.id)
-        messageRestActor(Full(myActor))   
+        messageRestActor(Full(myActor))
         userRoles(AuthRole("integration-admin"))
-        (200,Map(),Full(user_xml))     
+        (200,Map(),Full(user_xml))
       }
 
-      ret openOr (403,Map(),Empty)   
+      ret openOr (403,Map(),Empty)
     }
 
     r
-  } 
+  }
 
   def removeSession(): LiftResponse = {
-    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       if (User.loggedIn_?) {
-		User.logUserOut()
-    	Full((200,Map(),Empty))
-	  } else Full((404,Map(),Empty))  
-	
-	r
-  } 
+        User.logUserOut()
+        Full((200,Map(),Empty))
+      } else Full((404,Map(),Empty))
+
+    r
+  }
 
 
-  def allUsers(): LiftResponse = {      	
-  	val users: NodeSeq = for (user <- User.findAll) yield userToXml(user)
-    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
+  def allUsers(): LiftResponse = {
+    val users: NodeSeq = for (user <- User.findAll) yield userToXml(user)
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       Full(if (User.loggedIn_?) (200,Map(),Full(<users>{users}</users>)) else (403,Map(),Empty))
 
-	r
+    r
   }
 
   def addUser(): LiftResponse = {
     val moduleName: String = "upw"
-    
+
     val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = {
       for{
         nickName <- S.param("nickname")
-        passWord <- S.param("password")      
+        passWord <- S.param("password")
       } yield {
-       	User.findByNickname(nickName) match {
+        User.findByNickname(nickName) match {
           case user :: _ => (200,Map(),Full(userToXml(user)))
           case _ =>
-            val user = User.createAndPopulate.nickname(nickName).saveMe                                
+            val user = User.createAndPopulate.nickname(nickName).saveMe
             val salt = randomString(10)
-	        val md5 = Helpers.md5(salt + passWord)
-	        UserAuth.create
-	                .user(user)
-	                .authType(moduleName)
-	                .authKey(nickName)
-	                .authData(salt+";"+md5)
-	                .save
+            val md5 = Helpers.md5(salt + passWord)
+            UserAuth.create
+                    .user(user)
+                    .authType(moduleName)
+                    .authKey(nickName)
+                    .authData(salt+";"+md5)
+                    .save
             (200,Map(),Full(userToXml(user)))
         }
       }
     }
 
     r
-  } 
+  }
 
   def allTokens(userId: String): LiftResponse = {
     val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = {
       for{
         user <- User.find(userId)
-      } yield {                  
-        val tokens: NodeSeq = user.authTokens.map(t => tokenToXml(t)) 
+      } yield {
+        val tokens: NodeSeq = user.authTokens.map(t => tokenToXml(t))
         (200,Map(),Full(<tokens>{tokens}</tokens>))
       }
     }
@@ -248,11 +248,11 @@ object API2 extends ApiHelper with XmlHe
 
     r
   }
-       
+
   def allUserMsgs(): LiftResponse = {
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
-		val num = S.param("history").map(_.toInt) openOr 40;
+        val num = S.param("history").map(_.toInt) openOr 40;
         val lst = Mailbox.mostRecentMessagesFor(user.id, num))
       yield (200,Map(),Full(<messages>{lst.flatMap{ case (msg, reason, _) => msgToXml(msg) }}</messages>))
 
@@ -264,16 +264,16 @@ object API2 extends ApiHelper with XmlHe
 
   def getNewMsgs(): LiftResponse = {
     val future = new LAFuture[List[(Message, MailboxReason)]]()
-  
-    def waitForAnswer: Box[List[(Message, MailboxReason)]] = 
+
+    def waitForAnswer: Box[List[(Message, MailboxReason)]] =
       future.get(60L * 1000L)
 
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (act <- messageRestActor.is ?~ S.?("base_rest_api_err_no_rest_actor");
-		   val ignore = act ! ListenFor(future, 0 seconds);
-	       answer <- waitForAnswer ?~ S.?("base_rest_api_err_no_answer")) 
-      yield { 
-        if(answer.isEmpty) (304,Map(),Empty)          
+           val ignore = act ! ListenFor(future, 0 seconds);
+           answer <- waitForAnswer ?~ S.?("base_rest_api_err_no_answer"))
+      yield {
+        if(answer.isEmpty) (304,Map(),Empty)
         else (200,Map(),Full(<messages>{answer.flatMap{ case (msg, reason) => msgToXml(msg) }}</messages>))
       }
 
@@ -281,21 +281,21 @@ object API2 extends ApiHelper with XmlHe
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
     r
-  } 
+  }
 
   def waitForMsgs(): LiftResponse = {
     val future = new LAFuture[List[(Message, MailboxReason)]]()
-    
-    def waitForAnswer: Box[List[(Message, MailboxReason)]] = 
+
+    def waitForAnswer: Box[List[(Message, MailboxReason)]] =
       future.get(6L * 60L * 1000L)
 
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =  
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (act <- messageRestActor.is ?~ "No REST actor";
-		length <- S.param("timeout").map(_.toInt * 1000);
+        length <- S.param("timeout").map(_.toInt * 1000);
         val ignore = act ! ListenFor(future, TimeSpan(length));
         answer <- waitForAnswer ?~ "Didn't get an answer")
       yield {
-        if(answer.isEmpty) (304,Map(),Empty)          
+        if(answer.isEmpty) (304,Map(),Empty)
         else (200,Map(),Full(<messages>{answer.flatMap{ case (msg, reason) => msgToXml(msg) }}</messages>))
       }
 
@@ -306,23 +306,23 @@ object API2 extends ApiHelper with XmlHe
   }
 
   def allTagMsgs(tag: String): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =  
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
            tagName <- Box(List(tag));
            tag <- Tag.find(By(Tag.name, tagName)))
       yield {
-	    val tag_xml = <tag><name>{tag.name}</name><messages>{tag.findMessages.map(msgToXml(_))}</messages></tag>
-	    (200,Map(),Full(tag_xml))
-	  }
-	
+        val tag_xml = <tag><name>{tag.name}</name><messages>{tag.findMessages.map(msgToXml(_))}</messages></tag>
+        (200,Map(),Full(tag_xml))
+      }
+
     val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-    r	
-  } 
+    r
+  }
 
-  def addMsg(): LiftResponse = {      
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
+  def addMsg(): LiftResponse = {
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser.map(_.id.is);
            msg <- S.param("message"))
       yield {
@@ -331,7 +331,7 @@ object API2 extends ApiHelper with XmlHe
                         p <- AccessPool.findPool(poolName,
                         S.param("realm") openOr AccessPool.Native)
                         ) yield p.id.is
-        val xml: Box[Elem] = 
+        val xml: Box[Elem] =
           S.param("metadata").flatMap(md =>
             tryo(XML.loadString(md)))
 
@@ -345,7 +345,7 @@ object API2 extends ApiHelper with XmlHe
                                        pool) match {
            case Full(m: Message) => (200,Map(),Full(msgToXml(m)))
            case other => (200,Map(),Empty)
-		}
+        }
 //		(200,Map(),Empty)
       }
 
@@ -353,53 +353,53 @@ object API2 extends ApiHelper with XmlHe
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
     r
-  }      
+  }
 
 
   def allFollowees(): LiftResponse = {
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for(user <- User.currentUser)
       yield {
-        val followees: NodeSeq = 
+        val followees: NodeSeq =
           User.currentUser.map(_.following)
-		                  .map(_.map(userToXml(_)))
-		                  .openOr(<no_followees/>)
-		(200,Map(),Full(<followees>{followees}</followees>))
-	  }
+                          .map(_.map(userToXml(_)))
+                          .openOr(<no_followees/>)
+        (200,Map(),Full(<followees>{followees}</followees>))
+      }
 
     val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
     r
-  }         
+  }
 
   def addFollowee(): LiftResponse = {
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
         userName <- S.param("userId");
         other <- User.findFromWeb(userName))
-      yield { 	
-		user.follow(other)
-		(200,Map(),Full(userToXml(other)))
+      yield {
+        user.follow(other)
+        (200,Map(),Full(userToXml(other)))
       }
-    
+
     val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
     r
-  }   
+  }
+
 
-  
   def removeFollow(userName: Box[String])(): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
         userName <- userName;
         other <- User.findFromWeb(userName))
       yield {
-        user.unfollow(other)        
+        user.unfollow(other)
         (200,Map(),Empty)
       }
-    
+
     val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
@@ -410,18 +410,18 @@ object API2 extends ApiHelper with XmlHe
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for(user <- User.currentUser)
       yield {
-        val followees: NodeSeq = 
+        val followees: NodeSeq =
           User.currentUser.map(_.following)
-		                  .map(_.map(userToXml(_)))
-		                  .openOr(<no_followees/>)
-		(200,Map(),Full(<followees>{followees}</followees>))
-	  }
+                          .map(_.map(userToXml(_)))
+                          .openOr(<no_followees/>)
+        (200,Map(),Full(<followees>{followees}</followees>))
+      }
 
     val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
     r
-  }     
+  }
 
   def allTracking(): LiftResponse = {
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
@@ -430,25 +430,25 @@ object API2 extends ApiHelper with XmlHe
         val track_lst = Tracking.findAll(By(Tracking.user, user)).flatMap(_.toXml)
         (200,Map(),Full(<tracks>{track_lst}</tracks>))
       }
-    
+
     val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
     r
-  }   
+  }
 
   def addTracking(): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
            toTrack <- S.param("track") if toTrack.trim.length > 0)
       yield
         (200,Map(),Full(<track>{Tracking.create.user(user).regex(toTrack).save}</track>))
 
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
-  }      
+    r
+  }
 
   def removeTracking(trackId: Box[String]): LiftResponse = {
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
@@ -461,22 +461,22 @@ object API2 extends ApiHelper with XmlHe
         (200,Map(),Empty)
       }
 
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
-  } 
+    r
+  }
 
   def allActions(): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =       
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser ?~ S.?("base_rest_api_err_not_logged_in"))
       yield (200,Map(),Full(<actions>{user.performingwithdisabled.flatMap(_.toXml)}</actions>))
 
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
-  }     
+    r
+  }
 
   def addAction(): LiftResponse = {
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
@@ -491,11 +491,11 @@ object API2 extends ApiHelper with XmlHe
          (200,Map(),Full(a3.saveMe.toXml))
        }
 
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
-  } 
+    r
+  }
 
   def changeAction(actionId: Box[String]): LiftResponse = {
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
@@ -506,30 +506,30 @@ object API2 extends ApiHelper with XmlHe
         action.disabled(!enabled).save
         (200,Map(),Full(action.toXml))
       }
-  
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+    r
   }
 
   def removeAction(actionId: Box[String]): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =  
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
-           action <- findAction(actionId)) 
+           action <- findAction(actionId))
       yield {
         action.removed(true).save
         (200,Map(),Empty)
       }
-    
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
-  }              
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+    r
+  }
 
   def allPools(): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =  
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser ?~ S.?("base_rest_api_err_not_logged_in"))
       yield {
         val pools_lst = AccessPool.findAll(In(AccessPool.id,
@@ -540,14 +540,14 @@ object API2 extends ApiHelper with XmlHe
         (200,Map(),Full(<pools>{pools_lst}</pools>))
       }
 
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
-  }      
+    r
+  }
 
   def addPool(): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =   
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
            pool <- AccessPool.create.realm(AccessPool.Native).setName(S.param("poolName").openOr(""));
            privilegeSaved = Privilege.create.pool(pool.saveMe)
@@ -558,19 +558,19 @@ object API2 extends ApiHelper with XmlHe
         if (privilegeSaved) Distributor ! Distributor.AllowUserInPool(user.id.is, pool.id.is)
         (200,Map(),Full(pool.toXml))
     }
-    
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
-  } 
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+    r
+  }
 
   def addUserToPool(poolId: String): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (adminUser <- User.currentUser;
            realm <- (S.param("realm") or Full(AccessPool.Native));
            pool <- AccessPool.find(By(AccessPool.id, poolId.toLong),
-	                    By(AccessPool.realm, realm));
+                        By(AccessPool.realm, realm));
            userName <- S.param("userId");
            user <- User.findFromWeb(userName);
            permissionName <- (S.param("permission") or Full("Write"));
@@ -586,20 +586,20 @@ object API2 extends ApiHelper with XmlHe
           if (result) Distributor ! Distributor.AllowUserInPool(user.id.is, pool.id.is)
             (200,Map(),Full(userToXml(user)))
         } else (403,Map(),Empty) // "User has no permission to administer pool"
-    
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
-  }      
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+    r
+  }
 
   def histPoolMsgs(poolId: String): LiftResponse = {
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
         val poolNum = poolId.toInt;
-		val num = S.param("history").map(_.toInt) openOr 40)		
+        val num = S.param("history").map(_.toInt) openOr 40)
       yield {
-        val boxed_lst: Box[List[Message]] = 
+        val boxed_lst: Box[List[Message]] =
         for(session <- compass.map(_.openSession()); user <- User.currentUser)
         yield {
           var tx:CompassTransaction = null
@@ -613,22 +613,22 @@ object API2 extends ApiHelper with XmlHe
 
             for(tags <- S.param("filter_tags");
                 tag <- tags.split(",")) {
-              tagQuery.addMust(queryBuilder.term("tags", tag.split(" ").mkString("_")))   
+              tagQuery.addMust(queryBuilder.term("tags", tag.split(" ").mkString("_")))
             }
 
             val non_tag_query = queryBuilder.bool()
               .addMust(queryBuilder.term("pool", poolNum))
 
-            
+
             val query = if(S.param("filter_tags").isDefined)
-              non_tag_query.addMust(tagQuery.toQuery).toQuery()                             
+              non_tag_query.addMust(tagQuery.toQuery).toQuery()
             else
               non_tag_query.toQuery()
 
             val hitlist = query
               .addSort("when", CompassQuery.SortPropertyType.STRING, CompassQuery.SortDirection.REVERSE)
               .hits().detach(0, num)
-             
+
             val resourceList = hitlist.getResources.toList.asInstanceOf[List[Resource]]
 
             val msgIds = resourceList.map(_.getId.toLong)
@@ -643,30 +643,30 @@ object API2 extends ApiHelper with XmlHe
           returnValue
         }
 
-        val lst: List[Message] = boxed_lst.openOr(List()) 
+        val lst: List[Message] = boxed_lst.openOr(List())
 
         (200,Map(),Full(<messages>{lst.flatMap(msgToXml(_))}</messages>))
-      } 
+      }
 
     val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
     r
-  }    
+  }
 
   def getPoolMsgs(poolId: String): LiftResponse = {
     val future = new LAFuture[List[(Message, MailboxReason)]]()
-  
-    def waitForAnswer: Box[List[(Message, MailboxReason)]] = 
+
+    def waitForAnswer: Box[List[(Message, MailboxReason)]] =
       future.get(60L * 1000L)
 
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
-      for (user <- User.currentUser;     
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      for (user <- User.currentUser;
            act <- poolRestActors.findOrCreate(poolId.toLong);
-		   val ignore = act ! ListenFor(future, 0 seconds);
-	       answer <- waitForAnswer) 
-      yield { 
-        if(answer.isEmpty) (304,Map(),Empty)          
+           val ignore = act ! ListenFor(future, 0 seconds);
+           answer <- waitForAnswer)
+      yield {
+        if(answer.isEmpty) (304,Map(),Empty)
         else (200,Map(),Full(<messages>{answer.flatMap{ case (msg, reason) => msgToXml(msg) }}</messages>))
       }
 
@@ -674,22 +674,22 @@ object API2 extends ApiHelper with XmlHe
       if(ret.isDefined) ret else Full((403,Map(),Empty))
 
     r
-  } 
+  }
 
   def waitForPoolMsgs(poolId: String): LiftResponse = {
     val future = new LAFuture[List[(Message, MailboxReason)]]()
-    
-    def waitForAnswer: Box[List[(Message, MailboxReason)]] = 
+
+    def waitForAnswer: Box[List[(Message, MailboxReason)]] =
       future.get(6L * 60L * 1000L)
 
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =  
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
            act <- poolRestActors.findOrCreate(poolId.toLong);
-	       length <- S.param("timeout").map(_.toInt * 1000);
+           length <- S.param("timeout").map(_.toInt * 1000);
            val ignore = act ! ListenFor(future, TimeSpan(length));
            answer <- waitForAnswer)
       yield {
-        if(answer.isEmpty) (304,Map(),Empty)          
+        if(answer.isEmpty) (304,Map(),Empty)
         else (200,Map(),Full(<messages>{answer.flatMap{ case (msg, reason) => msgToXml(msg) }}</messages>))
       }
 
@@ -700,55 +700,55 @@ object API2 extends ApiHelper with XmlHe
   }
 
   def getConversation(conversationId: Box[String]): LiftResponse = {
-    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
       for (user <- User.currentUser;
            id <- conversationId.map(toLong))
       yield {
-        val messages = 
+        val messages =
           Message.findAndPrime(By(Message.conversation, id),
                                OrderBy(Message.id, Ascending))
-        
+
         if(messages.isEmpty)
           (404,Map(),Empty)
         else
           (200,Map(),Full(<conversation id={id.toString}>{messages.map(msgToXml(_))}</conversation>))
       }
 
-	val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
-	  if(ret.isDefined) ret else Full((403,Map(),Empty))
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
 
-	r
-  }   
+    r
+  }
 
   def unAuthorized(): LiftResponse = {
     Full((403,Map(),Empty))
   }
 
   private def findAction(actionId: Box[String]): Box[Action] =
-  	for (user <- User.currentUser ?~ S.?("base_rest_api_err_not_logged_in");
+    for (user <- User.currentUser ?~ S.?("base_rest_api_err_not_logged_in");
          id <- actionId ?~ S.?("base_rest_api_err_missing_param", "id");
          action <- Action.find(By(Action.user, user),
                              By(Action.id, id.toLong),
                              By(Action.removed, false))) yield action
 
   def createTag(in: NodeSeq) = <api>{in}</api>
-  
+
   private def buildActor(userId: Long): RestActor = {
     val ret = new RestActor
     ret ! StartUp(userId)
     ret
-  } 
+  }
 
   private def buildPublicTimelineActor(matcher: Function1[Message,Boolean]): RestActor = {
     val ret = new RestActor(matcher)
     ret ! StartUpPublic
     ret
-  }                  
+  }
 
   object messageRestActor extends SessionVar[Box[RestActor]](Empty) {
     override def onShutdown(session: LiftSession) = this.is.map(_ ! ByeBye)
   }
-  
+
   object poolRestActors extends SessionVar[Map[Long,RestActor]](Map()) {
     override def onShutdown(session: LiftSession) = this.is.values.map(_ ! ByeByePublic)
 
@@ -761,7 +761,7 @@ object API2 extends ApiHelper with XmlHe
         val newActor: RestActor = buildPublicTimelineActor(partialMatcher _)
         this.update((oldMap) => oldMap+((pool, newActor)))
         newActor
-      }))                                                               
+      }))
     }
   }
 
@@ -770,7 +770,7 @@ object API2 extends ApiHelper with XmlHe
     private var msgs: List[(Message, MailboxReason)] = Nil
     private var listener: Box[LAFuture[List[(Message, MailboxReason)]]] = Empty
 
-    def this() = this((msgToTest: Message) => true)                      
+    def this() = this((msgToTest: Message) => true)
 
     protected def messageHandler = {
       case StartUp(userId) =>
@@ -781,18 +781,18 @@ object API2 extends ApiHelper with XmlHe
         Distributor ! Distributor.PublicTimelineListeners(this)
 
       case ByeBye =>
-        Distributor ! Distributor.Unlisten(userId.openOr(0), this)  
+        Distributor ! Distributor.Unlisten(userId.openOr(0), this)
 
       case ByeByePublic =>
         Distributor ! Distributor.PublicTimelineUnlisteners(this)
-          
+
       case UserActor.MessageReceived(msg, reason) =>
         reason match {
           case r: RegularReason => {}
           case _ =>
             msg match {
               case _ if msgMatch(msg) =>
-                msgs = (msg, reason) :: msgs    
+                msgs = (msg, reason) :: msgs
                 listener.foreach {
                   who =>
                     who.satisfy(msgs)
@@ -800,12 +800,12 @@ object API2 extends ApiHelper with XmlHe
                     msgs = Nil
                 }
             }
-        } 
-                                                                 
+        }
+
       case Distributor.NewMessage(msg) =>
         msg match {
           case _ if msgMatch(msg) =>
-            msgs = (msg, NoReason) :: msgs                          
+            msgs = (msg, NoReason) :: msgs
             listener.foreach {
               who =>
                 who.satisfy(msgs)
@@ -813,18 +813,18 @@ object API2 extends ApiHelper with XmlHe
                 msgs = Nil
             }
         }
-      
+
       case ReleaseListener =>
         listener.foreach(_.satisfy(Nil))
         listener = Empty
-      
+
       case ListenFor(who, len) =>
         msgs match {
           case Nil =>
             listener.foreach(_.satisfy(Nil))
             listener = Full(who)
             ActorPing.schedule(this, ReleaseListener, len)
-             
+
           case xs =>
             who.satisfy(xs)
             msgs = Nil
@@ -834,28 +834,28 @@ object API2 extends ApiHelper with XmlHe
   }
 
 
-  private case class StartUp(userId: Long) 
+  private case class StartUp(userId: Long)
   private case object StartUpPublic
-  private case object ByeBye      
+  private case object ByeBye
   private case object ByeByePublic
   private case class ListenFor(who: LAFuture[List[(Message, MailboxReason)]],
-			       howLong: TimeSpan)                                  
-  private case object ReleaseListener       
-}                                                          
+                   howLong: TimeSpan)
+  private case object ReleaseListener
+}
 
 // TODO:
-// 1. Make addMsg() return the created message when successful. 
-// 2. Add a method to get detail for a specific user                                                              
+// 1. Make addMsg() return the created message when successful.
+// 2. Add a method to get detail for a specific user
 // 3. Change changeAction so that if the "enabled" parameter doesn't show up it will simply use
 //    the current value for the action, not throw an error.
-// 4. Match based on the return content type header to determine what to return (default to XML)   
-// 5. Add a method to get detail for a specific track (or messages for the track?)    
+// 4. Match based on the return content type header to determine what to return (default to XML)
+// 5. Add a method to get detail for a specific track (or messages for the track?)
 // 6. Add a method to get detail of a specific action
 // 7. Add a method to delete pool
 // 8. Add a method to get the detail for a pool
 // 9. Add a method to get the list of users in a pool
-// 10. Add a method to delete a user from a pool   
+// 10. Add a method to delete a user from a pool
 // 11. Add a method to get the messages from a pool
-// 12. Add a method to post a new message to a pool        
+// 12. Add a method to post a new message to a pool
 // 13. Add a method to get list of conversations
-// 14. Add a method to post a message to a conversation??                          
+// 14. Add a method to post a message to a conversation??

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AuthToken.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AuthToken.scala?rev=950750&r1=950749&r2=950750&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AuthToken.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AuthToken.scala Wed Jun  2 20:34:22 2010
@@ -17,13 +17,13 @@ package org.apache.esme.model
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
- 
- 	override def create: AuthToken = {
-		val ap = super.create
-		ap.createdDate(new Date())
-		ap
-    } 
-    
+
+  override def create: AuthToken = {
+    val ap = super.create
+    ap.createdDate(new Date())
+    ap
+    }
+
  */
 
 import net.liftweb._
@@ -43,46 +43,46 @@ import scala.xml.{Text, Node, Elem => Xm
 
 object AuthToken extends AuthToken with LongKeyedMetaMapper[AuthToken] {
 
-	override def create: AuthToken = {	
-	    val ap = super.create
-            ap.createdDate(new Date())
-            ap
-		
-    } 
+  override def create: AuthToken = {
+    val ap = super.create
+        ap.createdDate(new Date())
+        ap
+
+  }
 }
 
 class AuthToken extends LongKeyedMapper[AuthToken] {
-	def getSingleton = AuthToken // what's the "meta" server
-	def primaryKeyField = id
+  def getSingleton = AuthToken // what's the "meta" server
+  def primaryKeyField = id
 
-	object id extends MappedLongIndex(this)
-	object user extends MappedLongForeignKey(this, User)
-	object description extends MappedPoliteString(this, 64) {
-
-		private def validateDescription(str: String): List[FieldError] = {
-		                
-				val others = getSingleton.findByDescription(str)
-				others.map{u => 
-				val msg = S.?("base_token_err_duplicate_token", str)
-						S.error(msg)
-						FieldError(this, Text(msg))
-				}
-		}
-
-
-		override def validations = validateDescription _ :: super.validations
-	}
-	//define created on field
-	object createdDate extends MappedDateTime(this)
-	object uniqueId extends MappedUniqueId(this, 32) {
-		override def dbIndexed_? = true
-
-	}
-	
-	/**
-          * Method to find all tokens by a description
-          */
-	def findByDescription(str: String): List[AuthToken] =
-		AuthToken.findAll(By(description, str), By(user,User.currentUser))
+  object id extends MappedLongIndex(this)
+  object user extends MappedLongForeignKey(this, User)
+  object description extends MappedPoliteString(this, 64) {
+
+    private def validateDescription(str: String): List[FieldError] = {
+
+      val others = getSingleton.findByDescription(str)
+      others.map{u =>
+      val msg = S.?("base_token_err_duplicate_token", str)
+          S.error(msg)
+          FieldError(this, Text(msg))
+      }
+    }
+
+
+    override def validations = validateDescription _ :: super.validations
+  }
+  //define created on field
+  object createdDate extends MappedDateTime(this)
+  object uniqueId extends MappedUniqueId(this, 32) {
+    override def dbIndexed_? = true
+
+  }
+
+  /**
+   * Method to find all tokens by a description
+   */
+  def findByDescription(str: String): List[AuthToken] =
+    AuthToken.findAll(By(description, str), By(user,User.currentUser))
 }
 

Modified: incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/API2Test.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/API2Test.scala?rev=950750&r1=950749&r2=950750&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/API2Test.scala (original)
+++ incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/API2Test.scala Wed Jun  2 20:34:22 2010
@@ -31,7 +31,7 @@ import org.apache.esme._
 import model._
 import net.liftweb.http._
 import testing.{ReportFailure, TestKit, HttpResponse, TestFramework, Response}
-                                                 
+
 import _root_.junit.framework.AssertionFailedError
 
 class Api2SpecsAsTest extends JUnit3(Api2Specs)
@@ -40,26 +40,26 @@ object Api2SpecsRunner extends ConsoleRu
 object Api2Specs extends Specification with TestKit {
   JettyTestServer.start
 
-  val baseUrl = JettyTestServer.urlFor("/api2/")  
+  val baseUrl = JettyTestServer.urlFor("/api2/")
 
   // Note "api_test" user is special. It has been set up with the integration-admin
   // role in the test.default.props file.
-                                                                    
-  val theUser = find_or_create_user("api_test")    
+
+  val theUser = find_or_create_user("api_test")
   val token = find_or_create_token(theUser)
 
-  val post_session = post[Response]("session", "token" -> token) 
+  val post_session = post[Response]("session", "token" -> token)
 
   def find_or_create_user(userName: String): User = {
     val users = User.findByNickname(userName)
 
     if(users.length > 0)
       users.head
-    else { 
-      val session = new LiftSession(Helpers.randomString(20), "", Empty)                          
+    else {
+      val session = new LiftSession(Helpers.randomString(20), "", Empty)
       S.initIfUninitted(session) {User.createAndPopulate.nickname(userName).saveMe}
     }
-  }  
+  }
 
   def find_or_create_token(tokenUser: User): String = {
     val token: Box[AuthToken] = AuthToken.find(By(AuthToken.user,tokenUser))
@@ -84,7 +84,7 @@ object Api2Specs extends Specification w
           session <- post_session
         } {
           (session.xml \ "session" \ "user" \ "id").text must be equalTo (theUser.id.toString)
-          (session.xml \ "session" \ "user" \ "nickname").text must be equalTo (theUser.niceName) 
+          (session.xml \ "session" \ "user" \ "nickname").text must be equalTo (theUser.niceName)
           session.code must be equalTo 200
         }
       }
@@ -140,7 +140,7 @@ object Api2Specs extends Specification w
         for{
           session <- post_session
           users <- session.get[Response]("users")
-        } {                         
+        } {
           users.code must be equalTo 200
         }
       }
@@ -150,35 +150,35 @@ object Api2Specs extends Specification w
           session_res.code must be equalTo 403
         }
       }
-    } 
+    }
 
     "/users POST" in {
       "with valid session" in {
         for{
-          session <- post_session        
+          session <- post_session
           added_user <- session.post[Response]("users",
             "nickname" -> "test_user5",
-            "password" -> "test_password")  
-          all_users <- session.get[Response]("users") 
-        } {                                                                                                        
+            "password" -> "test_password")
+          all_users <- session.get[Response]("users")
+        } {
           added_user.code must be equalTo 200
           (all_users.xml \ "users") must \\(<nickname>test_user5</nickname>)
         }
       }
 
       "with a valid session but no role authorization returns 403 (forbidden)" in {
-		val new_user = find_or_create_user("tester2")
-		val new_token = find_or_create_token(new_user)
-		
-        for{     
-		  sess <- post[Response]("session", "token" -> new_token)
-		  added_user <- sess.post[Response]("users",
+        val new_user = find_or_create_user("tester2")
+        val new_token = find_or_create_token(new_user)
+
+        for{
+          sess <- post[Response]("session", "token" -> new_token)
+          added_user <- sess.post[Response]("users",
             "nickname" -> "test_user3",
             "password" -> "test_password")
-        } {                 
+        } {
           added_user.code must be equalTo 403
         }
-      } 
+      }
 
       "with no session returns 403 (forbidden)" in {
         for{
@@ -193,73 +193,73 @@ object Api2Specs extends Specification w
 
     "/users/USERID/tokens GET" in {
       val new_user = find_or_create_user("tester3")
-	  val new_token = find_or_create_token(new_user)
+      val new_token = find_or_create_token(new_user)
 
       "with valid session" in {
         for{
-          session <- post_session          
-          tokens <- session.get[Response]("users/"+new_user.id+"/tokens") 
-        } {                                                                                                        
+          session <- post_session
+          tokens <- session.get[Response]("users/"+new_user.id+"/tokens")
+        } {
           tokens.code must be equalTo 200
           tokens.xml must \\(<id>{new_token}</id>)
         }
       }
 
       "with valid session but no role authorization returns 403 (forbidden)" in {
-		val new_user = find_or_create_user("tester4")
-		val new_token = find_or_create_token(new_user)
-		
-        for{     
-		  sess <- post[Response]("session", "token" -> new_token)
-		  tokens <- sess.get[Response]("users/"+theUser.id+"/tokens")
-        } {                 
+        val new_user = find_or_create_user("tester4")
+        val new_token = find_or_create_token(new_user)
+
+        for{
+          sess <- post[Response]("session", "token" -> new_token)
+          tokens <- sess.get[Response]("users/"+theUser.id+"/tokens")
+        } {
           tokens.code must be equalTo 403
         }
-      } 
+      }
 
       "with no session returns 403 (forbidden)" in {
         for{
           tokens <- get[Response]("users/"+theUser.id+"/tokens")
-        } {                     
+        } {
           tokens.code must be equalTo 403
         }
       }
-    }        
+    }
 
     "/users/USERID/tokens POST" in {
       val new_user = find_or_create_user("tester5")
 
       "with valid session" in {
         for{
-          session <- post_session          
+          session <- post_session
           new_token <- session.post[Response]("users/"+new_user.id+"/tokens",
             "description" -> "test token")
           tokens <- session.get[Response]("users/"+new_user.id+"/tokens")
-        } {                                                                                                        
+        } {
           new_token.code must be equalTo 200
-          new_token.xml must \\(<description>test token</description>) 
+          new_token.xml must \\(<description>test token</description>)
           tokens.xml must \\(<description>test token</description>)
         }
       }
 
       "with valid session but no role authorization returns 403 (forbidden)" in {
-		val new_user = find_or_create_user("tester6")
-		val new_token = find_or_create_token(new_user)
-		
-        for{     
-		  sess <- post[Response]("session", "token" -> new_token)
-		  new_token <- sess.post[Response]("users/"+theUser.id+"/tokens",
-		    "description" -> "test token 2")
-        } {                 
+        val new_user = find_or_create_user("tester6")
+        val new_token = find_or_create_token(new_user)
+
+        for{
+          sess <- post[Response]("session", "token" -> new_token)
+          new_token <- sess.post[Response]("users/"+theUser.id+"/tokens",
+            "description" -> "test token 2")
+        } {
           new_token.code must be equalTo 403
         }
-      } 
+      }
 
       "with no session returns 403 (forbidden)" in {
         for{
           new_token <- post[Response]("users/"+theUser.id+"/tokens",
-		    "description" -> "test token 2")
-        } {                     
+            "description" -> "test token 2")
+        } {
           new_token.code must be equalTo 403
         }
       }
@@ -269,13 +269,13 @@ object Api2Specs extends Specification w
       "with valid session and new messages" in {
         for{
           session <- post_session
-          mess_res1 <- session.post[Response]("user/messages", "message" -> "test message") 
+          mess_res1 <- session.post[Response]("user/messages", "message" -> "test message")
           timeout <- sleep(2000)
           mess_res <- session.get[Response]("user/messages")
-        } {                  
+        } {
           mess_res.code must be equalTo 200
 
-          // Message structure   
+          // Message structure
           (mess_res.xml \ "messages" \ "message" \ "author" \ "id").text must be equalTo (theUser.id.toString)
         }
       }
@@ -292,9 +292,9 @@ object Api2Specs extends Specification w
         for (session <- post_session;
              session_res1 <- session.get[Response]("user/messages");
              session_res <- session.get[Response]("user/messages"))
-        {             
+        {
           session_res.code must be equalTo 204
-        }                                                   
+        }
       }
     }
 
@@ -303,7 +303,7 @@ object Api2Specs extends Specification w
         for{
           session <- post_session
           res <- session.get[Response]("user/messages?history=10")
-        } {           
+        } {
           res.code must be equalTo 200
         }
       }
@@ -318,8 +318,8 @@ object Api2Specs extends Specification w
     "/user/messages?timeout=2 GET" in {
       "with valid session" in {
         for{
-          sess <- post_session   
-          mess_res1 <- sess.post[Response]("user/messages", "message" -> "test message")  
+          sess <- post_session
+          mess_res1 <- sess.post[Response]("user/messages", "message" -> "test message")
           res <- sess.get[Response]("user/messages?timeout=2")
         } {
           res.code must be equalTo 200
@@ -333,13 +333,13 @@ object Api2Specs extends Specification w
       }
 
 // Should be a 304, but this response type isn't implemented in Lift yet...
-	  "when no new messages exist, returns 204 (no content)" in {
+      "when no new messages exist, returns 204 (no content)" in {
         for (session <- post_session;
           session_res1 <- session.get[Response]("user/messages");
           session_res <- session.get[Response]("user/messages?timeout=2"))
-        {             
+        {
           session_res.code must be equalTo 204
-        }                                                   
+        }
       }
     }
 
@@ -354,9 +354,9 @@ object Api2Specs extends Specification w
             "pool" -> "test_pool1")
           timeout <- sleep(1000)
           all_msgs <- session.get[Response]("user/messages?timeout=2")
-        } {                                  
-          mess_res.code must be equalTo 200               
-		  (mess_res.xml \ "message") must \\ (<body>test POST message</body>)
+        } {
+          mess_res.code must be equalTo 200
+          (mess_res.xml \ "message") must \\ (<body>test POST message</body>)
           (mess_res.xml \ "message") must \\ (<tags><tag>Test</tag><tag>Tag</tag></tags>)
           (all_msgs.xml \ "messages") must \\(<body>test POST message</body>)
           (all_msgs.xml \ "messages") must \\(<tags><tag>Test</tag><tag>Tag</tag></tags>)
@@ -455,14 +455,14 @@ object Api2Specs extends Specification w
       }
     }
 
-// fragile   
+// fragile
     "/user/tracks/TRACKID DELETE" in {
       "with valid session" in {
         for {
           sess <- post_session
           create_track <- sess.post[Response]("user/tracks","track"->"hello")
           res <- sess.delete[Response]("user/tracks/2")
-        } {           
+        } {
           res.code must be equalTo 200
         }
       }
@@ -539,17 +539,17 @@ object Api2Specs extends Specification w
     "/user/actions/ACTIONID DELETE" in {
       "with valid session" in {
         for {
-          sess <- post_session 
+          sess <- post_session
           create_action <- sess.post[Response]("user/actions",
                                      "name" -> "Test action",
                                      "test" -> "every 5 mins",
                                      "action" -> "rss:http://blog.com/feed.rss")
           res <- sess.delete[Response]("user/actions/2")
-        } {                     
+        } {
           res.code must be equalTo 200
         }
       }
- 
+
       "with no session returns 403 (forbidden)" in {
         for(res <- delete[Response]("user/actions/1")) {
           res.code must be equalTo 403
@@ -557,20 +557,20 @@ object Api2Specs extends Specification w
       }
     }
 
-// This is very ... shall we say ... brittle                                             
+// This is very ... shall we say ... brittle
     "conversations/CONVERSATIONID GET" in {
       "with valid session" in {
         for{
-          sess <- post_session 
+          sess <- post_session
           mess_res <- sess.post[Response]("user/messages", "message"->"test")
-          wait <- sleep(1000)                                
+          wait <- sleep(1000)
           mess_res <- sess.post[Response]("user/messages",
                                 "message" -> "test_convo",
                                 "replyto" -> 9)
-          wait2 <- sleep(1000)                 
+          wait2 <- sleep(1000)
           res <- sess.get[Response]("conversations/9")
         } {
-          res.code must be equalTo 200  
+          res.code must be equalTo 200
           ( res.xml \\ "message" ).last must \\(<conversation>9</conversation>)
           ( res.xml \\ "message" ).last must \\(<replyto>9</replyto>)
           ( res.xml \\ "message" ).first must \\(<conversation>9</conversation>)
@@ -585,13 +585,13 @@ object Api2Specs extends Specification w
       }
 
       "with an invalid conversation ID return a 404 (not found)" in {
-      	for{
+        for{
           sess <- post_session
           res <- sess.get[Response]("conversations/10000")
         } {
           res.code must be equalTo 404
         }
-      } 
+      }
     }
 
     "/pools GET" in {
@@ -600,7 +600,7 @@ object Api2Specs extends Specification w
           sess <- post_session
           res <- sess.get[Response]("pools")
         } {
-          res.code must be equalTo 200      
+          res.code must be equalTo 200
         }
       }
 
@@ -661,25 +661,25 @@ object Api2Specs extends Specification w
     }
 
     "/pools/POOLID/messages GET" in {
-	  "with valid session and new messages" in {
-	    for{
-	      sess <- post_session 
-     	  pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool4") 
+      "with valid session and new messages" in {
+        for{
+          sess <- post_session
+          pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool4")
           init <- sess.get[Response]("pools/4/messages")
           timeout <- sleep(2000)
-		  mess_res1 <- sess.post[Response]("user/messages",
+          mess_res1 <- sess.post[Response]("user/messages",
             "message" -> "test message for pool delta",
-            "pool" -> "test_pool4") 
+            "pool" -> "test_pool4")
           timeout <- sleep(2000)
           mess_res <- sess.get[Response]("pools/4/messages")
-        } {                                   
+        } {
           mess_res.code must be equalTo 200
 
-          // Message structure   
+          // Message structure
           (mess_res.xml \ "messages") must \\(<id>{theUser.id.toString}</id>)
           (mess_res.xml \ "messages") must \\(<body>test message for pool delta</body>)
         }
-      }  
+      }
 
       "with no session returns 403 (forbidden)" in {
         for (session_res <- get[Response]("pools/1/messages")) {
@@ -692,53 +692,53 @@ object Api2Specs extends Specification w
         for (session <- post_session;
              session_res1 <- session.get[Response]("pools/1/messages");
              session_res <- session.get[Response]("pools/1/messages"))
-        {             
+        {
           session_res.code must be equalTo 204
-        }                                                   
+        }
       }
-    }    
+    }
 
     "/pools/POOLID/messages?history=10 GET" in {
       "with valid session" in {
         for{
-          sess <- post_session 
-          pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool5") 
-		  mess_res <- sess.post[Response]("user/messages",
+          sess <- post_session
+          pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool5")
+          mess_res <- sess.post[Response]("user/messages",
             "message" -> "test message for pool history",
-            "pool" -> "test_pool5")                
+            "pool" -> "test_pool5")
           timeout <- sleep(2000)
           res <- sess.get[Response]("pools/5/messages?history=10")
-        } {                                
-          res.code must be equalTo 200          
+        } {
+          res.code must be equalTo 200
           (res.xml \ "messages") must \\(<id>{theUser.id.toString}</id>)
           (res.xml \ "messages") must \\(<body>test message for pool history</body>)
         }
-      }     
+      }
 
       "with tag restrictions" in {
         for{
-          sess <- post_session 
-          pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool6") 
-		  mess_res <- sess.post[Response]("user/messages",
+          sess <- post_session
+          pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool6")
+          mess_res <- sess.post[Response]("user/messages",
             "message" -> "test message for pool #history",
-            "pool" -> "test_pool6")                      
+            "pool" -> "test_pool6")
+          mess_res <- sess.post[Response]("user/messages",
+            "message" -> "test message for pool history with tags test, tag",
+            "pool" -> "test_pool6",
+            "tags" -> "test, tag")
+          mess_res <- sess.post[Response]("user/messages",
+            "message" -> "test message for pool history with tag test",
+            "pool" -> "test_pool6",
+            "tags" -> "test,crazycrazy")
           mess_res <- sess.post[Response]("user/messages",
-	        "message" -> "test message for pool history with tags test, tag",
-	        "pool" -> "test_pool6",
-	        "tags" -> "test, tag") 
-	      mess_res <- sess.post[Response]("user/messages",
-	        "message" -> "test message for pool history with tag test",
-	        "pool" -> "test_pool6",
-	        "tags" -> "test,crazycrazy")
-	      mess_res <- sess.post[Response]("user/messages",
-	        "message" -> "test message for pool history with tag tag",
-	        "pool" -> "test_pool6",
-	        "tags" -> "tag")     
-	      wait <- sleep(2000)
+            "message" -> "test message for pool history with tag tag",
+            "pool" -> "test_pool6",
+            "tags" -> "tag")
+          wait <- sleep(2000)
           res1 <- sess.get[Response]("pools/6/messages?history=10&filter_tags=test")
           res2 <- sess.get[Response]("pools/6/messages?history=10&filter_tags=test,tag")
-        } {                    
-          res1.code must be equalTo 200   
+        } {
+          res1.code must be equalTo 200
           res2.code must be equalTo 200
           (res1.xml \ "messages") must \\(<id>{theUser.id.toString}</id>)
           (res1.xml \ "messages") must \\(<body>test message for pool history with tag test</body>)
@@ -746,48 +746,48 @@ object Api2Specs extends Specification w
           (res2.xml \ "messages") must \\(<body>test message for pool history with tags test, tag</body>)
           (res2.xml \ "messages").length must be equalTo 1
         }
-      }   
- 
+      }
+
       "with no session returns 403 (forbidden)" in {
         for (session_res <- get[Response]("pools/1/messages?history=10")) {
           session_res.code must be equalTo 403
         }
       }
-    }       
+    }
 
     "/pools/POOLID/messages?timeout=2 GET" in {
       "with valid session" in {
         for{
-          sess <- post_session 
-          pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool6")    
-          init <- sess.get[Response]("pools/6/messages")    
-		  timeout <- sleep(2000)
-		  mess_res <- sess.post[Response]("user/messages",
+          sess <- post_session
+          pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool6")
+          init <- sess.get[Response]("pools/6/messages")
+          timeout <- sleep(2000)
+          mess_res <- sess.post[Response]("user/messages",
             "message" -> "test message for pool timeout",
-            "pool" -> "test_pool6")          
-		  timeout <- sleep(2000)
+            "pool" -> "test_pool6")
+          timeout <- sleep(2000)
           res <- sess.get[Response]("pools/6/messages?timeout=2")
-        } {                   
+        } {
           res.code must be equalTo 200
         }
-      }    
+      }
 
       "with valid session and new messages but no pool authorization returns 403 (forbidden)" in {
-		val new_user = find_or_create_user("tester6")
-		val new_token = find_or_create_token(new_user)
-		
-		for{
-	      sess <- post_session
-	      sessNoAuth <- post[Response]("session", "token" -> new_token)  
-     	  pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool7") 
+        val new_user = find_or_create_user("tester6")
+        val new_token = find_or_create_token(new_user)
+
+        for{
+          sess <- post_session
+          sessNoAuth <- post[Response]("session", "token" -> new_token)
+          pool_res <- sess.post[Response]("pools", "poolName" -> "test_pool7")
           init <- sessNoAuth.get[Response]("pools/7/messages")
           timeout <- sleep(2000)
-		  mess_res1 <- sess.post[Response]("user/messages",
+          mess_res1 <- sess.post[Response]("user/messages",
             "message" -> "test message for pool delta",
-            "pool" -> "test_pool7") 
+            "pool" -> "test_pool7")
           timeout <- sleep(2000)
           mess_res <- sessNoAuth.get[Response]("pools/7/messages")
-        } {                                       
+        } {
           mess_res.code must be equalTo 403
           init.code must be equalTo 403
         }
@@ -799,15 +799,15 @@ object Api2Specs extends Specification w
         }
       }
 
-	// Should be a 304, but this response type isn't implemented in Lift yet...
+    // Should be a 304, but this response type isn't implemented in Lift yet...
       "when no new messages exist, returns 204 (no content)" in {
         for (session <- post_session;
           session_res1 <- session.get[Response]("pools/1/messages");
           session_res <- session.get[Response]("pools/1/messages?timeout=2"))
-        {             
+        {
           session_res.code must be equalTo 204
-        }                                                   
+        }
       }
-    }   
+    }
   }
 }
\ No newline at end of file



Mime
View raw message