Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

lift-mongodb

  • Loading branch information...
commit 5deb066204d41a70826317d3dc1eefa84d69a644 1 parent 4bbec08
@eltimn eltimn authored
View
4 persistence/mongodb/src/test/scala/net/liftweb/mongodb/BsonDSLSpec.scala
@@ -27,11 +27,11 @@ import java.util.{Date, UUID}
import java.util.regex.Pattern
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
import com.mongodb.{BasicDBList, DBObject}
-object BsonDSLSpec extends Specification("BsonDSL Specification") {
+class BsonDSLSpec extends Specification {
"BsonDSL" should {
"Convert ObjectId properly" in {
val oid: ObjectId = ObjectId.get
View
10 persistence/mongodb/src/test/scala/net/liftweb/mongodb/CustomSerializersSpec.scala
@@ -21,7 +21,7 @@ import java.util.{Calendar, Date, TimeZone}
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
package customserializersspecs {
@@ -51,7 +51,7 @@ package customserializersspecs {
/**
* Systems under specification for CustomSerializers.
*/
-object CustomSerializersSpec extends Specification("CustomSerializers Specification") with MongoTestKit {
+class CustomSerializersSpec extends Specification with MongoTestKit {
import customserializersspecs._
@@ -72,11 +72,12 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
// retrieve it and compare
val jack2 = Person.find(jack._id)
- jack2 must notBeEmpty
+ jack2.isDefined must beTrue
jack2 foreach { j =>
j._id mustEqual jack._id
j.birthDate mustEqual jack.birthDate
}
+ success
}
"handle Date as Date value using DateSerializer" in {
@@ -93,11 +94,12 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
// retrieve it and compare
val findJack = Person2.find(jack._id)
- findJack must notBeEmpty
+ findJack.isDefined must beTrue
findJack foreach { j =>
j._id mustEqual jack._id
j.birthDate mustEqual jack.birthDate
}
+ success
}
}
}
View
9 persistence/mongodb/src/test/scala/net/liftweb/mongodb/JObjectParserSpec.scala
@@ -22,11 +22,11 @@ import JsonDSL._
import util.Helpers._
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
import com.mongodb.DBObject
-object JObjectParserSpec extends Specification("JObjectParser Specification") {
+class JObjectParserSpec extends Specification {
def buildTestData: (ObjectId, DBObject) = {
val oid = ObjectId.get
@@ -39,7 +39,7 @@ object JObjectParserSpec extends Specification("JObjectParser Specification") {
val (oid, dbo) = buildTestData
val xval = tryo(dbo.get("x").asInstanceOf[ObjectId])
- xval must notBeEmpty
+ xval.isDefined must beTrue
xval.foreach { x =>
x must_== oid
}
@@ -49,11 +49,12 @@ object JObjectParserSpec extends Specification("JObjectParser Specification") {
val (oid, dbo) = buildTestData
val xval = tryo(dbo.get("x").asInstanceOf[String])
- xval must notBeEmpty
+ xval.isDefined must beTrue
xval.foreach { x =>
x must_== oid.toString
}
}
}
+ success
}
}
View
9 persistence/mongodb/src/test/scala/net/liftweb/mongodb/MongoDirectSpec.scala
@@ -22,7 +22,7 @@ import java.util.regex.Pattern
import com.mongodb.{BasicDBObject, BasicDBObjectBuilder}
-import org.specs.Specification
+import org.specs2.mutable.Specification
import json.DefaultFormats
@@ -30,7 +30,8 @@ import json.DefaultFormats
/**
* System under specification for MongoDirect.
*/
-object MongoDirectSpec extends Specification("MongoDirect Specification") with MongoTestKit {
+class MongoDirectSpec extends Specification with MongoTestKit {
+ args(sequential=true)
def date(s: String) = DefaultFormats.dateFormat.parse(s).get
@@ -96,6 +97,7 @@ object MongoDirectSpec extends Specification("MongoDirect Specification") with M
val six = db.eval(" function() { return 3+3; } ")
six must_== 6
})
+ success
}
"Mongo tutorial 2 example" in {
@@ -193,6 +195,7 @@ object MongoDirectSpec extends Specification("MongoDirect Specification") with M
coll.drop
}
})
+ success
}
"Mongo useSession example" in {
@@ -271,6 +274,7 @@ object MongoDirectSpec extends Specification("MongoDirect Specification") with M
coll.drop
}
})
+ success
}
"UUID Example" in {
@@ -288,6 +292,7 @@ object MongoDirectSpec extends Specification("MongoDirect Specification") with M
dbo2.get("_id") must_== dbo.get("_id")
dbo2.get("name") must_== dbo.get("name")
}
+ success
}
}
View
19 persistence/mongodb/src/test/scala/net/liftweb/mongodb/MongoDocumentExamplesSpec.scala
@@ -25,7 +25,7 @@ import java.util.regex.Pattern
import org.bson.types.ObjectId
import com.mongodb.{BasicDBList, BasicDBObject, DBObject, MongoException}
-import org.specs.Specification
+import org.specs2.mutable.Specification
import json.DefaultFormats
import json.JsonParser._
@@ -176,7 +176,8 @@ package mongotestdocs {
/**
* Systems under specification for MongoDocumentExamples.
*/
-class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Specification") with MongoTestKit {
+class MongoDocumentExamplesSpec extends Specification with MongoTestKit {
+ args(sequential=true)
import mongotestdocs._
override def dbName = "lift_mongodocumentexamples"
@@ -231,6 +232,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
if (!debug) {
SimplePerson.drop
}
+ success
}
"Multiple Simple Person example" in {
@@ -282,6 +284,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
SimplePerson.drop
}
+ success
}
"Person example" in {
@@ -317,6 +320,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
Person.drop
}
+ success
}
"Mongo tutorial example" in {
@@ -332,7 +336,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
// unique index on name
val ixName = ixs.find(dbo => dbo.get("name") == "name_1")
- ixName must notBeEmpty
+ ixName.isDefined must beTrue
ixName foreach { ix =>
ix.containsField("unique") must beTrue
ix.get("unique").asInstanceOf[Boolean] must beTrue
@@ -340,7 +344,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
// non-unique index on dbtype
val ixDbtype = ixs.find(dbo => dbo.get("name") == "dbtype_1")
- ixDbtype must notBeEmpty
+ ixDbtype.isDefined must beTrue
ixDbtype foreach { ix =>
ix.containsField("unique") must beFalse
}
@@ -465,6 +469,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
IDoc.findAll.length must_== 50
IDoc.drop
+ success
}
"Mongo useSession example" in {
@@ -527,6 +532,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
}
})
+ success
}
"Primitives example" in {
@@ -554,6 +560,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
pFromDb.isEmpty must_== true
Primitive.drop
}
+ success
}
"Ref example" in {
@@ -609,6 +616,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
MainJDoc.drop
RefJDoc.drop
+ success
}
"Pattern example" in {
@@ -624,6 +632,7 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
pdoc.regx.pattern must_== pdoc1.regx.pattern
pdoc.regx.flags must_== pdoc1.regx.flags
}
+ success
}
"Issue 586 Date test" in {
@@ -654,6 +663,6 @@ class MongoDocumentExamplesSpec extends Specification("MongoDocumentExamples Spe
sdd2.dt must_== sdd.dt
}
}
-
+ success
}
}
View
9 persistence/mongodb/src/test/scala/net/liftweb/mongodb/MongoDocumentSpec.scala
@@ -18,7 +18,8 @@ package net.liftweb
package mongodb
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.execute.Result
+import org.specs2.mutable.Specification
import common._
import json.ext.JsonBoxSerializer
@@ -90,13 +91,15 @@ package mongodocumentspecs {
/**
* System specification for MongoDocument
*/
-object MongoDocumentSpec extends Specification("MongoDocument Specification") with MongoTestKit {
+class MongoDocumentSpec extends Specification with MongoTestKit {
+ args(sequential=true)
- def passSaveAndRetrieveTests(obj: MongoDocument[_], meta: MongoDocumentMeta[_]): Unit = {
+ def passSaveAndRetrieveTests(obj: MongoDocument[_], meta: MongoDocumentMeta[_]): Result = {
obj.save
val objFromDb = meta.find(obj._id.asInstanceOf[ObjectId])
objFromDb.isDefined must_== true
objFromDb.get must_== obj
+ success
}
"MongoDocument" should {
View
13 persistence/mongodb/src/test/scala/net/liftweb/mongodb/MongoSpec.scala
@@ -17,17 +17,18 @@
package net.liftweb
package mongodb
-import org.specs.Specification
+import org.specs2.execute.Result
+import org.specs2.mutable.Specification
import com.mongodb._
-object MongoSpec extends Specification("Mongo Specification") {
+class MongoSpec extends Specification {
case object TestMongoIdentifier extends MongoIdentifier {
val jndiName = "test_a"
}
- def passDefinitionTests(id: MongoIdentifier, ma: MongoAddress): Unit = {
+ def passDefinitionTests(id: MongoIdentifier, ma: MongoAddress): Result = {
// define the db
MongoDB.close
MongoDB.defineDb(id, ma)
@@ -39,7 +40,7 @@ object MongoSpec extends Specification("Mongo Specification") {
}
}
catch {
- case e: Exception => skip("MongoDB is not running")
+ case e: Exception => skipped("MongoDB is not running")
}
// using an undefined identifier throws an exception
@@ -48,6 +49,7 @@ object MongoSpec extends Specification("Mongo Specification") {
} must throwA(new MongoException("Mongo not found: MongoIdentifier(test)"))
// remove defined db
MongoDB.close
+ success
}
"Mongo" should {
@@ -101,7 +103,7 @@ object MongoSpec extends Specification("Mongo Specification") {
}
}
catch {
- case e: Exception => skip("MongoDB is not running")
+ case e: Exception => skipped("MongoDB is not running")
}
// using an undefined identifier throws an exception
@@ -110,6 +112,7 @@ object MongoSpec extends Specification("Mongo Specification") {
} must throwA(new MongoException("Mongo not found: MongoIdentifier(test)"))
// remove defined db
MongoDB.close
+ success
}
/* Requires a server other than localhost with auth setup.
"Define and authenticate DB with Mongo instance" in {
View
12 persistence/mongodb/src/test/scala/net/liftweb/mongodb/MongoTestKit.scala
@@ -17,12 +17,14 @@
package net.liftweb
package mongodb
-import org.specs.Specification
-
+import org.specs2.mutable.Specification
+import org.specs2.specification.{Fragments, Step}
trait MongoTestKit {
this: Specification =>
+ override def map(fs: => Fragments) = Step(doBeforeSpec) ^ fs ^ Step(doAfterSpec)
+
def dbName = "lift_"+this.getClass.getName
.replace("$", "")
.replace("net.liftweb.mongodb.", "")
@@ -36,7 +38,7 @@ trait MongoTestKit {
def debug = false
- doBeforeSpec {
+ def doBeforeSpec: Unit = {
// define the dbs
dbs foreach { dbtuple =>
MongoDB.defineDb(dbtuple._1, MongoAddress(dbtuple._2, dbtuple._3))
@@ -57,9 +59,9 @@ trait MongoTestKit {
case e: Exception => false
}
- def checkMongoIsRunning = isMongoRunning must beEqualTo(true).orSkipExample
+ def checkMongoIsRunning = isMongoRunning must beEqualTo(true).orSkip("MongoDB is not running")
- doAfterSpec {
+ def doAfterSpec: Unit = {
if (!debug && isMongoRunning) {
// drop the databases
dbs foreach { dbtuple =>
View
4 persistence/mongodb/src/test/scala/net/liftweb/mongodb/QueryExamplesSpec.scala
@@ -24,7 +24,7 @@ import java.util.{Calendar, Date, UUID}
import java.util.regex.Pattern
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
package queryexamplesfixtures {
case class Person(_id: ObjectId, name: String, birthDate: Date, childId: UUID, petId: Option[ObjectId]) extends MongoDocument[Person] {
@@ -40,7 +40,7 @@ package queryexamplesfixtures {
}
}
-object QueryExamplesSpec extends Specification("QueryExamples Specification") with MongoTestKit {
+class QueryExamplesSpec extends Specification with MongoTestKit {
import queryexamplesfixtures._
"Query examples" in {
Please sign in to comment.
Something went wrong with that request. Please try again.