incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esjew...@apache.org
Subject svn commit: r895390 - in /incubator/esme/trunk/server/src: main/scala/org/apache/esme/api/API2.scala main/scala/org/apache/esme/api/XMLHelper.scala test/scala/org/apache/esme/api/API2Test.scala
Date Sun, 03 Jan 2010 13:44:51 GMT
Author: esjewett
Date: Sun Jan  3 13:44:50 2010
New Revision: 895390

URL: http://svn.apache.org/viewvc?rev=895390&view=rev
Log:
[ESME-150] POST /api2/pools/POOLID/users method does not work (403 - unauthorized) - also
updates the tag format of the message response from the API so that it is possible to differentiate
tags

Modified:
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/XMLHelper.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=895390&r1=895389&r2=895390&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 Sun Jan  3 13:44:50
2010
@@ -129,7 +129,7 @@
     case Req("api2" :: "pools" :: Nil, _, GetRequest) => allPools 
     case Req("api2" :: "pools" :: Nil, _, PostRequest) => () => addPool 
     case Req("api2" :: "pools" :: poolId :: "users" :: Nil, _, PostRequest) => () 
-			=> addUserToPool(Box(List(poolId)))
+			=> addUserToPool(poolId)
     case Req("api2" :: "pools" :: poolId :: "messages" :: Nil, _, GetRequest)
  	  if S.param("timeout").isDefined => () => waitForPoolMsgs(poolId)
     case Req("api2" :: "pools" :: poolId :: "messages" :: Nil, _, GetRequest)
@@ -333,7 +333,6 @@
                         p <- AccessPool.findPool(poolName,
                         S.param("realm") openOr AccessPool.Native)
                         ) yield p.id.is
-
         val xml: Box[Elem] = 
           S.param("metadata").flatMap(md =>
             tryo(XML.loadString(md)))
@@ -566,16 +565,16 @@
 	r
   } 
 
-  def addUserToPool(poolId: Box[String]): LiftResponse = {
+  def addUserToPool(poolId: String): LiftResponse = {
     val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] = 
       for (adminUser <- User.currentUser;
-           poolName <- poolId ?~ S.?("base_rest_api_err_missing_param", "pool");
            realm <- (S.param("realm") or Full(AccessPool.Native));
-           pool <- AccessPool.findPool(poolName, realm) ?~  S.?("base_rest_api_err_param_not_found",
"Pool");
-           userName <- S.param("userId") ?~ S.?("base_rest_api_err_missing_param", "user");
-           user <- User.findFromWeb(userName) ?~  S.?("base_rest_api_err_param_not_found",
"User");
+           pool <- AccessPool.find(By(AccessPool.id, poolId.toLong),
+	                    By(AccessPool.realm, realm));
+           userName <- S.param("userId");
+           user <- User.findFromWeb(userName);
            permissionName <- (S.param("permission") or Full("Write"));
-           permission <- Box(Permission.valueOf(permissionName)) ?~ S.?("base_rest_api_err_param_not_found",
"Permission"))
+           permission <- Box(Permission.valueOf(permissionName)))
       yield
         if(Privilege.hasPermission(adminUser.id.is, pool.id.is, Permission.Admin)) {
           val result = try {

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/XMLHelper.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/XMLHelper.scala?rev=895390&r1=895389&r2=895390&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/XMLHelper.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/XMLHelper.scala Sun Jan
 3 13:44:50 2010
@@ -46,7 +46,11 @@
   protected def msgToXml(msg: Message): Elem = { 
     val replyToTag: Elem =
       if(msg.conversation.defined_?) <replyto>{msg.conversation}</replyto>
-      else <replyto></replyto>
+      else <replyto></replyto>  
+    val tags: NodeSeq = 
+      for(tag<-msg.tags) yield {
+        <tag>{tag}</tag>
+      }
 
     val ret: Elem = <message>
   <id>{msg.id.toString}</id>
@@ -58,7 +62,7 @@
       <author><nickname>{u.niceName}</nickname><id>{u.id.toString}</id></author>
     ) openOr Text("")
   }
-  <tags>{msg.tags}</tags>{replyToTag}
+  <tags>{tags}</tags>{replyToTag}
 </message>
 
    ret        

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=895390&r1=895389&r2=895390&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 Sun Jan
 3 13:44:50 2010
@@ -350,9 +350,17 @@
       "with valid session" in {
         for{
           session <- post_session
-          mess_res <- session.post("user/messages", "message" -> "test message")
-        } {
+          res <- session.post("pools", "poolName" -> "test_pool1")
+          mess_res <- session.post("user/messages",
+            "message" -> "test POST message",
+            "tags" -> "test,tag",
+            "pool" -> 1)
+          all_msgs <- session.get("user/messages?timeout=2")
+        } {          
+          println(all_msgs.xml)
           mess_res.code must be equalTo 200
+          (all_msgs.xml \ "messages") must \\(<body>test POST message</body>)
+          (all_msgs.xml \ "messages") must \\(<tags><tag>Test</tag><tag>Tag</tag></tags>)
         }
       }
 
@@ -604,14 +612,14 @@
       "with valid session" in {
         for{
           sess <- post_session
-          res <- sess.post("pools", "poolName" -> "test_pool")
+          res <- sess.post("pools", "poolName" -> "test_pool2")
         } {
           res.code must be equalTo 200
         }
       }
 
       "with no session returns 403 (forbidden)" in {
-        for (res <- post("pools", "poolName" -> "test_pool")) {
+        for (res <- post("pools", "poolName" -> "failed_test_pool")) {
           res.code must be equalTo 403
         }
       }
@@ -622,8 +630,8 @@
       "with valid session" in {
         for {
           sess <- post_session
-          pool_res <- sess.post("pools", "poolName" -> "test_pool2")
-          res <- sess.post("pools/test_pool2/users","userId"->2)
+          pool_res <- sess.post("pools", "poolName" -> "test_pool3")
+          res <- sess.post("pools/3/users","userId"->2,"permission"->"Write")
         } {
           res.code must be equalTo 200
         }
@@ -653,14 +661,14 @@
 	  "with valid session and new messages" in {
 	    for{
 	      sess <- post_session 
-     	  pool_res <- sess.post("pools", "poolName" -> "test_pool3") 
-          init <- sess.get("pools/3/messages")
+     	  pool_res <- sess.post("pools", "poolName" -> "test_pool4") 
+          init <- sess.get("pools/4/messages")
           timeout <- sleep(2000)
 		  mess_res1 <- sess.post("user/messages",
             "message" -> "test message for pool delta",
-            "pool" -> "test_pool3") 
+            "pool" -> "test_pool4") 
           timeout <- sleep(2000)
-          mess_res <- sess.get("pools/3/messages")
+          mess_res <- sess.get("pools/4/messages")
         } {                                   
           mess_res.code must be equalTo 200
 
@@ -691,11 +699,11 @@
       "with valid session" in {
         for{
           sess <- post_session 
-          pool_res <- sess.post("pools", "poolName" -> "test_pool4") 
+          pool_res <- sess.post("pools", "poolName" -> "test_pool5") 
 		  mess_res <- sess.post("user/messages",
             "message" -> "test message for pool history",
-            "pool" -> "test_pool4")
-          res <- sess.get("pools/4/messages?history=10")
+            "pool" -> "test_pool5")
+          res <- sess.get("pools/5/messages?history=10")
         } {                             
           res.code must be equalTo 200  
           (res.xml \ "messages") must \\(<id>{theUser.id.toString}</id>)
@@ -714,12 +722,12 @@
       "with valid session" in {
         for{
           sess <- post_session 
-          pool_res <- sess.post("pools", "poolName" -> "test_pool5")    
-          init <- sess.get("pool/5/messages") 
+          pool_res <- sess.post("pools", "poolName" -> "test_pool6")    
+          init <- sess.get("pool/6/messages") 
 		  mess_res <- sess.post("user/messages",
             "message" -> "test message for pool timeout",
-            "pool" -> "test_pool5") 
-          res <- sess.get("pools/5/messages?timeout=2")
+            "pool" -> "test_pool6") 
+          res <- sess.get("pools/6/messages?timeout=2")
         } {                               
           res.code must be equalTo 200
         }
@@ -733,14 +741,14 @@
 		for{
 	      sess <- post_session
 	      sessNoAuth <- post("session", "token" -> new_token)  
-     	  pool_res <- sess.post("pools", "poolName" -> "test_pool6") 
-          init <- sessNoAuth.get("pools/6/messages")
+     	  pool_res <- sess.post("pools", "poolName" -> "test_pool7") 
+          init <- sessNoAuth.get("pools/7/messages")
           timeout <- sleep(2000)
 		  mess_res1 <- sess.post("user/messages",
             "message" -> "test message for pool delta",
-            "pool" -> "test_pool6") 
+            "pool" -> "test_pool7") 
           timeout <- sleep(2000)
-          mess_res <- sessNoAuth.get("pools/6/messages")
+          mess_res <- sessNoAuth.get("pools/7/messages")
         } {                                       
           mess_res.code must be equalTo 403
           init.code must be equalTo 403



Mime
View raw message