incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esjew...@apache.org
Subject svn commit: r905126 - /incubator/esme/trunk/server/src/test/scala/org/apache/esme/api/API2Test.scala
Date Sun, 31 Jan 2010 21:32:01 GMT
Author: esjewett
Date: Sun Jan 31 21:32:01 2010
New Revision: 905126

URL: http://svn.apache.org/viewvc?rev=905126&view=rev
Log:
Fix API2 tests to use existing tokens rather than creating a new token for each test

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

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=905126&r1=905125&r2=905126&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
31 21:32:01 2010
@@ -24,6 +24,7 @@
 import org.specs.runner.ConsoleRunner
 import net.liftweb.util._
 import net.liftweb.common._
+import net.liftweb.mapper.{By}
 import org.specs.matcher._
 import Helpers._
 import net.sourceforge.jwebunit.junit.WebTester
@@ -51,10 +52,7 @@
   // role in the test.default.props file.
                                                                     
   val theUser = find_or_create_user("api_test")    
-  val token = {
-    val toke = AuthToken.create.user(theUser).saveMe
-    toke.uniqueId.is
-  }           
+  val token = find_or_create_token(theUser)
 
   val post_session = post("session", "token" -> token) 
 
@@ -67,6 +65,17 @@
       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))
+
+    if(token.isDefined)
+      token.open_!.uniqueId.is
+    else {
+      val toke = AuthToken.create.user(tokenUser).saveMe
+      toke.uniqueId.is
+    }
   }
 
   def sleep(wait: Long): Box[Boolean] = {
@@ -164,9 +173,8 @@
       }
 
       "with a valid session but no role authorization returns 403 (forbidden)" in {
-		val new_user = find_or_create_user("tester")
-		val new_toke = AuthToken.create.user(new_user).saveMe
-		val new_token = new_toke.uniqueId.is        
+		val new_user = find_or_create_user("tester2")
+		val new_token = find_or_create_token(new_user)
 		
         for{     
 		  sess <- post("session", "token" -> new_token)
@@ -190,9 +198,8 @@
     }
 
     "/users/USERID/tokens GET" in {
-      val new_user = find_or_create_user("tester")
-	  val new_toke = AuthToken.create.user(new_user).saveMe
-	  val new_token = new_toke.uniqueId.is
+      val new_user = find_or_create_user("tester3")
+	  val new_token = find_or_create_token(new_user)
 
       "with valid session" in {
         for{
@@ -205,9 +212,8 @@
       }
 
       "with valid session but no role authorization returns 403 (forbidden)" in {
-		val new_user = find_or_create_user("tester")
-		val new_toke = AuthToken.create.user(new_user).saveMe
-		val new_token = new_toke.uniqueId.is        
+		val new_user = find_or_create_user("tester4")
+		val new_token = find_or_create_token(new_user)
 		
         for{     
 		  sess <- post("session", "token" -> new_token)
@@ -227,7 +233,7 @@
     }        
 
     "/users/USERID/tokens POST" in {
-      val new_user = find_or_create_user("tester")
+      val new_user = find_or_create_user("tester5")
 
       "with valid session" in {
         for{
@@ -243,9 +249,8 @@
       }
 
       "with valid session but no role authorization returns 403 (forbidden)" in {
-		val new_user = find_or_create_user("tester")
-		val new_toke = AuthToken.create.user(new_user).saveMe
-		val new_token = new_toke.uniqueId.is        
+		val new_user = find_or_create_user("tester6")
+		val new_token = find_or_create_token(new_user)
 		
         for{     
 		  sess <- post("session", "token" -> new_token)
@@ -765,8 +770,7 @@
 
       "with valid session and new messages but no pool authorization returns 403 (forbidden)"
in {
 		val new_user = find_or_create_user("tester6")
-		val new_toke = AuthToken.create.user(new_user).saveMe
-		val new_token = new_toke.uniqueId.is        
+		val new_token = find_or_create_token(new_user)
 		
 		for{
 	      sess <- post_session



Mime
View raw message