incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r886971 - in /incubator/esme/trunk/server/src/test/scala/org/apache/esme: JettySetup.scala api/API2Test.scala api/ApiTest.scala
Date Thu, 03 Dec 2009 22:50:54 GMT
Author: dpp
Date: Thu Dec  3 22:50:53 2009
New Revision: 886971

URL: http://svn.apache.org/viewvc?rev=886971&view=rev
Log:
Added a session so Users can be created outside an S context

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

Modified: incubator/esme/trunk/server/src/test/scala/org/apache/esme/JettySetup.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/test/scala/org/apache/esme/JettySetup.scala?rev=886971&r1=886970&r2=886971&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/test/scala/org/apache/esme/JettySetup.scala (original)
+++ incubator/esme/trunk/server/src/test/scala/org/apache/esme/JettySetup.scala Thu Dec  3
22:50:53 2009
@@ -62,7 +62,11 @@
 
   lazy val start = {
     server_.start()
-    User.create.nickname("hash").save
+    val session = new LiftSession(Helpers.randomString(20), "", Empty)
+
+    S.initIfUninitted(session) {
+      User.create.nickname("hash").save
+    }
   }
 
   def stop() = {

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=886971&r1=886970&r2=886971&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 Thu Dec
 3 22:50:53 2009
@@ -1,6 +1,6 @@
 /**
  * Copyright 2008-2009 WorldWide Conferencing, LLC
- * 
+ *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
  * distributed with this work for additional information
@@ -19,13 +19,13 @@
  * under the License.
  */
 
-package org.apache.esme.api 
+package org.apache.esme.api
 
 import org.specs._
 import org.specs.runner.JUnit3
 import org.specs.runner.ConsoleRunner
 import net.liftweb.util._
-import net.liftweb.common._ 
+import net.liftweb.common._
 import org.specs.matcher._
 import Helpers._
 import net.sourceforge.jwebunit.junit.WebTester
@@ -36,10 +36,10 @@
 import org.apache.esme._
 import model._
 import net.liftweb.http._
-import testing.{ReportFailure, TestKit, HttpResponse, TestFramework}  
+import testing.{ReportFailure, TestKit, HttpResponse, TestFramework}
 
 import net.sourceforge.jwebunit.junit.WebTester
-import _root_.junit.framework.AssertionFailedError                 
+import _root_.junit.framework.AssertionFailedError
 
 class Api2SpecsAsTest extends JUnit3(Api2Specs)
 object Api2SpecsRunner extends ConsoleRunner(Api2Specs)
@@ -48,56 +48,58 @@
   JettyTestServer.start
 
   val baseUrl = JettyTestServer.urlFor("/api2/")
-  
-  val theUser = User.createAndPopulate.nickname("api_test").saveMe
+
+  val session = new LiftSession(Helpers.randomString(20), "", Empty)
+
+  val theUser = S.initIfUninitted(session) {User.createAndPopulate.nickname("api_test").saveMe}
   val token = {
     val toke = AuthToken.create.user(theUser).saveMe
     toke.uniqueId.is
-  }     
+  }
 
   val post_session = post("session", "token" -> token)
-  
+
   "API2" should {
-	"/session POST" in {  
-	  "Attempt to log in with a valid token should succeed with a 200 response" in {
-	    for{
-	      session <- post_session    
-	    } {
-	      (session.xml \ "session" \ "user" \ "id").text must be equalTo(theUser.id.toString)
-		  session.code must be equalTo 200
-	    } 
-	  }
-
-	  "Attempt to create session with an invalid token returns 403 response" in {
-	    for{
-	      session <- post("session", "token" -> "000000")
-	    } {                  
+    "/session POST" in {
+      "Attempt to log in with a valid token should succeed with a 200 response" in {
+        for{
+          session <- post_session
+        } {
+          (session.xml \ "session" \ "user" \ "id").text must be equalTo (theUser.id.toString)
+          session.code must be equalTo 200
+        }
+      }
+
+      "Attempt to create session with an invalid token returns 403 response" in {
+        for{
+          session <- post("session", "token" -> "000000")
+        } {
           session.code must be equalTo 403
-	    } 
-	  }
-	}
-	
-	"/session GET" in {
-	  "with valid session" in {
-	    for {
-	      session <- post_session
+        }
+      }
+    }
+
+    "/session GET" in {
+      "with valid session" in {
+        for{
+          session <- post_session
           session_response <- session.get("session")
-	    } {
-	      session_response.code must be equalTo 200
-	      ( session_response.xml \ "session" \ "user" \ "id").text must be equalTo(theUser.id.toString)
-	    }
-	  }
-	
-	  "with no session returns 404 (not found)" in {
-	    for(session_res <- get("session")) {
-	      session_res.code must be equalTo 404
-	    }
-	  }  
+        } {
+          session_response.code must be equalTo 200
+          (session_response.xml \ "session" \ "user" \ "id").text must be equalTo (theUser.id.toString)
+        }
+      }
+
+      "with no session returns 404 (not found)" in {
+        for (session_res <- get("session")) {
+          session_res.code must be equalTo 404
+        }
+      }
     }
 
     "/session DELETE" in {
       "with valid session" in {
-        for {
+        for{
           session <- post_session
           session_del_response <- session.delete("session")
           //session_response <- session.get("session")
@@ -107,16 +109,16 @@
         }
       }
 
-	  "with no session returns 404 (not found)" in {
-	    for(session_res <- delete("session")) {
-	      session_res.code must be equalTo 404
-	    }
-	  }
-    }	
+      "with no session returns 404 (not found)" in {
+        for (session_res <- delete("session")) {
+          session_res.code must be equalTo 404
+        }
+      }
+    }
 
     "/users GET" in {
-      "with valid session" in {     
-        for {
+      "with valid session" in {
+        for{
           session <- post_session
           users <- session.get("users")
         } {
@@ -124,16 +126,16 @@
         }
       }
 
-	  "with no session returns 403 (forbidden)" in {
-	    for(session_res <- get("users")) {
-	      session_res.code must be equalTo 403
-	    }
-	  }
+      "with no session returns 403 (forbidden)" in {
+        for (session_res <- get("users")) {
+          session_res.code must be equalTo 403
+        }
+      }
     }
 
     "/user/messages GET" in {
       "with valid session" in {
-        for {
+        for{
           session <- post_session
           mess_res <- session.get("user/messages")
         } {
@@ -141,320 +143,322 @@
         }
       }
 
-	  "with no session returns 403 (forbidden)" in {
-	    for(session_res <- get("user/messages")) {
-	      session_res.code must be equalTo 403
-	    }
-	  }
+      "with no session returns 403 (forbidden)" in {
+        for (session_res <- get("user/messages")) {
+          session_res.code must be equalTo 403
+        }
+      }
     }
 
     "/user/messages?history=10 GET" in {
       "with valid session" in {
-        for {
+        for{
           session <- post_session
           res <- session.get("user/messages?history=10")
         } {
           res.code must be equalTo 200
-        }                     
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(session_res <- get("user/messages?history=10")) {
-	      session_res.code must be equalTo 403
-	    }
-	  }
+        for (session_res <- get("user/messages?history=10")) {
+          session_res.code must be equalTo 403
+        }
+      }
     }
 
     "/user/messages?timeout=2 GET" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
           res <- sess.get("user/messages?timeout=2")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(session_res <- get("user/messages?timeout=2")) {
-	      session_res.code must be equalTo 403
-	    }
-	  }
-    } 
+        for (session_res <- get("user/messages?timeout=2")) {
+          session_res.code must be equalTo 403
+        }
+      }
+    }
 
     "/user/messages POST" in {
       "with valid session" in {
-        for {
+        for{
           session <- post_session
-          mess_res <- session.post("user/messages","message"->"test message")
+          mess_res <- session.post("user/messages", "message" -> "test message")
         } {
           mess_res.code must be equalTo 200
         }
       }
 
-	  "with no session returns 403 (forbidden)" in {
-	    for(session_res <- post("user/messages","message"->"test message")) {
-	      session_res.code must be equalTo 403
-	    }
-	  }
+      "with no session returns 403 (forbidden)" in {
+        for (session_res <- post("user/messages", "message" -> "test message")) {
+          session_res.code must be equalTo 403
+        }
+      }
     }
 
     "/user/followees GET" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
           res <- sess.get("user/followees")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(session_res <- get("user/followees")) {
-	      session_res.code must be equalTo 403
-	    }
-	  }
+        for (session_res <- get("user/followees")) {
+          session_res.code must be equalTo 403
+        }
+      }
     }
 
     "/user/followees POST" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
           res <- sess.post("user/followees", "userId" -> "1")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(res <- post("user/followees", "userId" -> "1")) {
-	      res.code must be equalTo 403
-	    }
-	  }
-    } 
+        for (res <- post("user/followees", "userId" -> "1")) {
+          res.code must be equalTo 403
+        }
+      }
+    }
 
     "/user/followers GET" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
           res <- sess.get("user/followers")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(session_res <- get("user/followers")) {
-	      session_res.code must be equalTo 403
-	    }
-	  }
+        for (session_res <- get("user/followers")) {
+          session_res.code must be equalTo 403
+        }
+      }
     }
 
     "/user/tracks GET" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
           res <- sess.get("user/tracks")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(session_res <- get("user/tracks")) {
-	      session_res.code must be equalTo 403
-	    }
-	  }
+        for (session_res <- get("user/tracks")) {
+          session_res.code must be equalTo 403
+        }
+      }
     }
 
     "/user/tracks POST" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
-          res <- sess.post("user/tracks","track" -> ".*")
+          res <- sess.post("user/tracks", "track" -> ".*")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(session_res <- post("user/tracks","track" -> ".*")) {
-	      session_res.code must be equalTo 403
-	    }
-	  }
+        for (session_res <- post("user/tracks", "track" -> ".*")) {
+          session_res.code must be equalTo 403
+        }
+      }
     }
 
-/*
- *   "/user/tracks/TRACKID DELETE" in {
- *     "with valid session" in {
- *       for {
- *         sess <- post_session
- *         create_track <- sess.post("user/tracks","track"->".*")
- *         res <- sess.delete("user/tracks/1")
- *       } {
- *         res.code must be equalTo 200
- *       }          
- *     }
- *
- *     "with no session returns 403 (forbidden)" in {
- *       for(session_res <- delete("user/tracks/1")) {
- *         session_res.code must be equalTo 403
- *       }
- *     }
- *   } 
- */
+    /*
+    *   "/user/tracks/TRACKID DELETE" in {
+    *     "with valid session" in {
+    *       for {
+    *         sess <- post_session
+    *         create_track <- sess.post("user/tracks","track"->".*")
+    *         res <- sess.delete("user/tracks/1")
+    *       } {
+    *         res.code must be equalTo 200
+    *       }
+    *     }
+    *
+    *     "with no session returns 403 (forbidden)" in {
+    *       for(session_res <- delete("user/tracks/1")) {
+    *         session_res.code must be equalTo 403
+    *       }
+    *     }
+    *   }
+    */
 
     "/user/actions GET" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
           res <- sess.get("user/actions")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(res <- get("user/actions")) {
-	      res.code must be equalTo 403
-	    }
-	  }
+        for (res <- get("user/actions")) {
+          res.code must be equalTo 403
+        }
+      }
     }
 
     "/user/actions POST" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
           res <- sess.post("user/actions",
-                           "name"->"Test action",
-                           "test"->"every 5 mins",
-                           "action"->"rss:http://blog.com/feed.rss")
-        } {
-          res.code must be equalTo 200
-        }          
+            "name" -> "Test action",
+            "test" -> "every 5 mins",
+            "action" -> "rss:http://blog.com/feed.rss")
+        } {
+          res.code must be equalTo 200
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(res <- post("user/actions",
-	                    "name"->"Test action",
-	                    "test"->"every 5 mins",
-	                    "action"->"rss:http://blog.com/feed.rss")) {
-	      res.code must be equalTo 403
-	    }
-	  }
-    }   
-
-/*
- *    "/user/actions/ACTIONID PUT" in {
- *     "with valid session" in {
- *       for {
- *         sess <- post_session
- *         res <- sess.put("user/actions/1","enabled"->0)
- *       } {
- *         res.code must be equalTo 200
- *       }          
- *     }
- *
- *     "with no session returns 403 (forbidden)" in {
- *       for(res <- post("user/actions/1","enabled"->0)) {
- *         res.code must be equalTo 403
- *       }
- *     }
- *   }
- */
+        for (res <- post("user/actions",
+          "name" -> "Test action",
+          "test" -> "every 5 mins",
+          "action" -> "rss:http://blog.com/feed.rss")) {
+          res.code must be equalTo 403
+        }
+      }
+    }
 
-/*
- *   "/user/actions/ACTIONID DELETE" in {
- *     "with valid session" in {
- *       for {
- *         sess <- post_session
- *         res <- sess.delete("user/actions/1")
- *       } {
- *         res.code must be equalTo 200
- *       }          
- *     }
- *
- *     "with no session returns 403 (forbidden)" in {
- *       for(res <- delete("user/actions/1")) {
- *         res.code must be equalTo 403
- *       }
- *     }
- *   } 
- */
+    /*
+    *    "/user/actions/ACTIONID PUT" in {
+    *     "with valid session" in {
+    *       for {
+    *         sess <- post_session
+    *         res <- sess.put("user/actions/1","enabled"->0)
+    *       } {
+    *         res.code must be equalTo 200
+    *       }
+    *     }
+    *
+    *     "with no session returns 403 (forbidden)" in {
+    *       for(res <- post("user/actions/1","enabled"->0)) {
+    *         res.code must be equalTo 403
+    *       }
+    *     }
+    *   }
+    */
+
+    /*
+    *   "/user/actions/ACTIONID DELETE" in {
+    *     "with valid session" in {
+    *       for {
+    *         sess <- post_session
+    *         res <- sess.delete("user/actions/1")
+    *       } {
+    *         res.code must be equalTo 200
+    *       }
+    *     }
+    *
+    *     "with no session returns 403 (forbidden)" in {
+    *       for(res <- delete("user/actions/1")) {
+    *         res.code must be equalTo 403
+    *       }
+    *     }
+    *   }
+    */
 
     "conversations/CONVERSATIONID GET" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
           res <- sess.get("conversations/1")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(res <- get("conversations/1")) {
-	      res.code must be equalTo 403
-	    }
-	  }
+        for (res <- get("conversations/1")) {
+          res.code must be equalTo 403
+        }
+      }
     }
 
     "/pools GET" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
           res <- sess.get("pools")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(res <- get("pools")) {
-	      res.code must be equalTo 403
-	    }
-	  }
+        for (res <- get("pools")) {
+          res.code must be equalTo 403
+        }
+      }
     }
 
     "/pools POST" in {
       "with valid session" in {
-        for {
+        for{
           sess <- post_session
-          res <- sess.post("pools","poolName"->"test_pool")
+          res <- sess.post("pools", "poolName" -> "test_pool")
         } {
           res.code must be equalTo 200
-        }          
+        }
       }
 
       "with no session returns 403 (forbidden)" in {
-	    for(res <- post("pools","poolName"->"test_pool")) {
-	      res.code must be equalTo 403
-	    }
-	  }
-    }  
+        for (res <- post("pools", "poolName" -> "test_pool")) {
+          res.code must be equalTo 403
+        }
+      }
+    }
 
     "/pools/POOLID/users POST" in {
 
-/*
- *     "with valid session" in {
- *       for {
- *         sess <- post_session
- *         res <- sess.post("pools/1/users",{"realm"->"test_realm";
- *                                                "userId"->1;
- *                                                "permission"->"Write"})
- *       } {
- *         res.code must be equalTo 200
- *       }          
- *     }
- */
-
-      "with no session returns 403 (forbidden)" in {
-	    for(res <- post("pools/1/users",{"realm"->"test_realm";
-                                                 "userId"->2;
-                                                 "permission"->"Write"})) {
-	      res.code must be equalTo 403
-	    }
-	  }
-    }        
-  }  
+      /*
+      *     "with valid session" in {
+      *       for {
+      *         sess <- post_session
+      *         res <- sess.post("pools/1/users",{"realm"->"test_realm";
+      *                                                "userId"->1;
+      *                                                "permission"->"Write"})
+      *       } {
+      *         res.code must be equalTo 200
+      *       }
+      *     }
+      */
+
+      "with no session returns 403 (forbidden)" in {
+        for (res <- post("pools/1/users", {
+          "realm" -> "test_realm";
+          "userId" -> 2;
+          "permission" -> "Write"
+        })) {
+          res.code must be equalTo 403
+        }
+      }
+    }
+  }
 }
\ No newline at end of file

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=886971&r1=886970&r2=886971&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 Thu Dec 
3 22:50:53 2009
@@ -45,7 +45,7 @@
 object ApiSpecsRunner extends ConsoleRunner(ApiSpecs)
 
 object ApiSpecs extends Specification with TestKit {
- JettyTestServer.start 
+  JettyTestServer.start
 
   val baseUrl = JettyTestServer.urlFor("")
 
@@ -53,7 +53,10 @@
     def fail(msg: String): Nothing = ApiSpecs.this.fail(msg)
   }
 
-  val theUser = User.createAndPopulate.nickname("api_test").saveMe
+  val session = new LiftSession(Helpers.randomString(20), "", Empty)
+
+  val theUser = S.initIfUninitted(session) {User.createAndPopulate.nickname("api_test").saveMe}
+
   val token = {
     val toke = AuthToken.create.user(theUser).saveMe
     toke.uniqueId.is
@@ -88,6 +91,6 @@
 
 
   }
-  
+
 
 }



Mime
View raw message