Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* CouchDB Record was running tests in parallel, and were failing. Now…

… they run and pass

* Some mongodb/mongodb-record tests were failing because of the change to S.??
  • Loading branch information...
commit 25cfda30cff0a0fef101bdd66b217d1345cf7937 1 parent a53d59f
@fmpwizard fmpwizard authored
View
113 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/MongoRecordExamplesSpec.scala
@@ -32,6 +32,7 @@ import org.specs.Specification
import com.mongodb._
import org.bson.types.ObjectId
+import http.{S, LiftSession}
package mongotestrecords {
@@ -240,66 +241,70 @@ object MongoRecordExamplesSpec extends Specification("MongoRecordExamples Specif
import mongotestrecords._
import net.liftweb.util.TimeHelpers._
+ val session = new LiftSession("hello", "", Empty)
"TstRecord example" in {
checkMongoIsRunning
- val pwd = "test"
- val cal = Calendar.getInstance
- cal.set(2009, 10, 2)
-
- val tr = TstRecord.createRecord
- tr.stringfield("test record string field")
- tr.emailfield("test")
- tr.validate.size must_== 2
- tr.passwordfield.setPassword(pwd)
- tr.emailfield("test@example.com")
- tr.datetimefield(cal)
- tr.patternfield(Pattern.compile("^Mo", Pattern.CASE_INSENSITIVE))
- tr.validate.size must_== 0
-
- // JsonObjectField
- val dob1 = Calendar.getInstance.setYear(2005).setMonth(7).setDay(4)
- val per = Person("joe", 27, Address("Bulevard", "Helsinki"), List(Child("Mary", 5, Some(dob1.getTime)), Child("Mazy", 3, None)))
- tr.person(per)
-
- // save the record in the db
- tr.save
-
- // retrieve from db
- def fromDb = TstRecord.find("_id", tr.id)
-
- fromDb.isDefined must_== true
-
- for (t <- fromDb) {
- t._id.value must_== tr._id.value
- t.booleanfield.value must_== tr.booleanfield.value
- TstRecord.formats.dateFormat.format(t.datetimefield.value.getTime) must_==
- TstRecord.formats.dateFormat.format(tr.datetimefield.value.getTime)
- t.doublefield.value must_== tr.doublefield.value
- t.intfield.value must_== tr.intfield.value
- t.localefield.value must_== tr.localefield.value
- t.longfield.value must_== tr.longfield.value
- t.passwordfield.isMatch(pwd) must_== true
- t.stringfield.value must_== tr.stringfield.value
- t.timezonefield.value must_== tr.timezonefield.value
- t.datetimefield.value must_== tr.datetimefield.value
- t.patternfield.value.pattern must_== tr.patternfield.value.pattern
- t.patternfield.value.flags must_== tr.patternfield.value.flags
- t.datefield.value must_== tr.datefield.value
- t.person.value.name must_== tr.person.value.name
- t.person.value.age must_== tr.person.value.age
- t.person.value.address.street must_== tr.person.value.address.street
- t.person.value.address.city must_== tr.person.value.address.city
- t.person.value.children.size must_== tr.person.value.children.size
- for (i <- List.range(0, t.person.value.children.size-1)) {
- t.person.value.children(i).name must_== tr.person.value.children(i).name
- t.person.value.children(i).age must_== tr.person.value.children(i).age
- t.person.value.children(i).birthdate must_== tr.person.value.children(i).birthdate
+ S.initIfUninitted(session){
+
+ val pwd = "test"
+ val cal = Calendar.getInstance
+ cal.set(2009, 10, 2)
+
+ val tr = TstRecord.createRecord
+ tr.stringfield("test record string field")
+ tr.emailfield("test")
+ tr.validate.size must_== 2
+ tr.passwordfield.setPassword(pwd)
+ tr.emailfield("test@example.com")
+ tr.datetimefield(cal)
+ tr.patternfield(Pattern.compile("^Mo", Pattern.CASE_INSENSITIVE))
+ tr.validate.size must_== 0
+
+ // JsonObjectField
+ val dob1 = Calendar.getInstance.setYear(2005).setMonth(7).setDay(4)
+ val per = Person("joe", 27, Address("Bulevard", "Helsinki"), List(Child("Mary", 5, Some(dob1.getTime)), Child("Mazy", 3, None)))
+ tr.person(per)
+
+ // save the record in the db
+ tr.save
+
+ // retrieve from db
+ def fromDb = TstRecord.find("_id", tr.id)
+
+ fromDb.isDefined must_== true
+
+ for (t <- fromDb) {
+ t._id.value must_== tr._id.value
+ t.booleanfield.value must_== tr.booleanfield.value
+ TstRecord.formats.dateFormat.format(t.datetimefield.value.getTime) must_==
+ TstRecord.formats.dateFormat.format(tr.datetimefield.value.getTime)
+ t.doublefield.value must_== tr.doublefield.value
+ t.intfield.value must_== tr.intfield.value
+ t.localefield.value must_== tr.localefield.value
+ t.longfield.value must_== tr.longfield.value
+ t.passwordfield.isMatch(pwd) must_== true
+ t.stringfield.value must_== tr.stringfield.value
+ t.timezonefield.value must_== tr.timezonefield.value
+ t.datetimefield.value must_== tr.datetimefield.value
+ t.patternfield.value.pattern must_== tr.patternfield.value.pattern
+ t.patternfield.value.flags must_== tr.patternfield.value.flags
+ t.datefield.value must_== tr.datefield.value
+ t.person.value.name must_== tr.person.value.name
+ t.person.value.age must_== tr.person.value.age
+ t.person.value.address.street must_== tr.person.value.address.street
+ t.person.value.address.city must_== tr.person.value.address.city
+ t.person.value.children.size must_== tr.person.value.children.size
+ for (i <- List.range(0, t.person.value.children.size-1)) {
+ t.person.value.children(i).name must_== tr.person.value.children(i).name
+ t.person.value.children(i).age must_== tr.person.value.children(i).age
+ t.person.value.children(i).birthdate must_== tr.person.value.children(i).birthdate
+ }
}
- }
- if (!debug) TstRecord.drop
+ if (!debug) TstRecord.drop
+ }
}
"Ref example" in {
View
342 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/MongoRecordSpec.scala
@@ -32,12 +32,14 @@ import JsonDSL._
import net.liftweb.record.field.Countries
import com.mongodb._
+import http.{S, LiftSession}
/**
* Systems under specification for MongoRecord.
*/
object MongoRecordSpec extends Specification("MongoRecord Specification") with MongoTestKit {
import fixtures._
+ val session = new LiftSession("hello", "", Empty)
"MongoRecord field introspection" should {
checkMongoIsRunning
@@ -328,30 +330,34 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
"save and retrieve 'standard' type fields" in {
checkMongoIsRunning
- fttr.save
+ S.initIfUninitted(session) {
+ fttr.save
- val fttrFromDb = FieldTypeTestRecord.find(fttr.id.value)
- fttrFromDb must notBeEmpty
- fttrFromDb foreach { tr =>
- tr mustEqual fttr
- }
+ val fttrFromDb = FieldTypeTestRecord.find(fttr.id.value)
+ fttrFromDb must notBeEmpty
+ fttrFromDb foreach { tr =>
+ tr mustEqual fttr
+ }
- bftr.save
+ bftr.save
- val bftrFromDb = BinaryFieldTestRecord.find(bftr.id.value)
- bftrFromDb must notBeEmpty
- bftrFromDb foreach { tr =>
- tr mustEqual bftr
+ val bftrFromDb = BinaryFieldTestRecord.find(bftr.id.value)
+ bftrFromDb must notBeEmpty
+ bftrFromDb foreach { tr =>
+ tr mustEqual bftr
+ }
}
}
"delete record properly" in {
checkMongoIsRunning
- fttr.save
- FieldTypeTestRecord.find(fttr.id.value) must notBeEmpty
- fttr.delete_!
- FieldTypeTestRecord.find(fttr.id.value) must beEmpty
+ S.initIfUninitted(session) {
+ fttr.save
+ FieldTypeTestRecord.find(fttr.id.value) must notBeEmpty
+ fttr.delete_!
+ FieldTypeTestRecord.find(fttr.id.value) must beEmpty
+ }
}
"save and retrieve Mongo type fields with set values" in {
@@ -529,116 +535,119 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
"retrieve MongoRef objects properly" in {
checkMongoIsRunning
- val ntr = NullTestRecord.createRecord
- val btr = BoxTestRecord.createRecord
-
- fttr.save
- ltr.save
- mtr.save
- ntr.save
- btr.save
-
- val rftr = RefFieldTestRecord.createRecord
- .mandatoryObjectIdRefField(fttr.id.is)
- .mandatoryUUIDRefField(ltr.id.is)
- .mandatoryStringRefField(mtr.id.is)
- .mandatoryIntRefField(ntr.id.is)
- .mandatoryLongRefField(btr.id.is)
- .mandatoryObjectIdRefListField(List(fttr.id.is))
- .mandatoryUUIDRefListField(List(ltr.id.is))
- .mandatoryStringRefListField(List(mtr.id.is))
- .mandatoryIntRefListField(List(ntr.id.is))
- .mandatoryLongRefListField(List(btr.id.is))
-
- // single objects
- rftr.mandatoryObjectIdRefField.obj mustEqual Full(fttr)
- rftr.mandatoryUUIDRefField.obj mustEqual Full(ltr)
- rftr.mandatoryStringRefField.obj mustEqual Full(mtr)
- rftr.mandatoryIntRefField.obj mustEqual Full(ntr)
- rftr.mandatoryLongRefField.obj mustEqual Full(btr)
-
- val fttr2 = FieldTypeTestRecord.createRecord.save
-
- rftr.mandatoryObjectIdRefField.cached_? mustEqual true
- rftr.mandatoryObjectIdRefField(fttr2.id.is)
- rftr.mandatoryObjectIdRefField.cached_? mustEqual false
- rftr.mandatoryObjectIdRefField.find mustEqual Full(fttr2)
- rftr.mandatoryObjectIdRefField.obj mustEqual Full(fttr2)
- rftr.mandatoryObjectIdRefField.cached_? mustEqual true
-
- // lists
- rftr.mandatoryObjectIdRefListField.objs mustEqual List(fttr)
- rftr.mandatoryUUIDRefListField.objs mustEqual List(ltr)
- rftr.mandatoryStringRefListField.objs mustEqual List(mtr)
- rftr.mandatoryIntRefListField.objs mustEqual List(ntr)
- rftr.mandatoryLongRefListField.objs mustEqual List(btr)
-
- val fttr3 = FieldTypeTestRecord.createRecord.save
- val objList = List(fttr2, fttr3)
-
- rftr.mandatoryObjectIdRefListField.cached_? mustEqual true
- rftr.mandatoryObjectIdRefListField(objList.map(_.id.is))
- rftr.mandatoryObjectIdRefListField.cached_? mustEqual false
- rftr.mandatoryObjectIdRefListField.findAll mustEqual objList
- rftr.mandatoryObjectIdRefListField.objs mustEqual objList
- rftr.mandatoryObjectIdRefListField.cached_? mustEqual true
+ S.initIfUninitted(session) {
+ val ntr = NullTestRecord.createRecord
+ val btr = BoxTestRecord.createRecord
+
+ fttr.save
+ ltr.save
+ mtr.save
+ ntr.save
+ btr.save
+
+ val rftr = RefFieldTestRecord.createRecord
+ .mandatoryObjectIdRefField(fttr.id.is)
+ .mandatoryUUIDRefField(ltr.id.is)
+ .mandatoryStringRefField(mtr.id.is)
+ .mandatoryIntRefField(ntr.id.is)
+ .mandatoryLongRefField(btr.id.is)
+ .mandatoryObjectIdRefListField(List(fttr.id.is))
+ .mandatoryUUIDRefListField(List(ltr.id.is))
+ .mandatoryStringRefListField(List(mtr.id.is))
+ .mandatoryIntRefListField(List(ntr.id.is))
+ .mandatoryLongRefListField(List(btr.id.is))
+
+ // single objects
+ rftr.mandatoryObjectIdRefField.obj mustEqual Full(fttr)
+ rftr.mandatoryUUIDRefField.obj mustEqual Full(ltr)
+ rftr.mandatoryStringRefField.obj mustEqual Full(mtr)
+ rftr.mandatoryIntRefField.obj mustEqual Full(ntr)
+ rftr.mandatoryLongRefField.obj mustEqual Full(btr)
+
+ val fttr2 = FieldTypeTestRecord.createRecord.save
+
+ rftr.mandatoryObjectIdRefField.cached_? mustEqual true
+ rftr.mandatoryObjectIdRefField(fttr2.id.is)
+ rftr.mandatoryObjectIdRefField.cached_? mustEqual false
+ rftr.mandatoryObjectIdRefField.find mustEqual Full(fttr2)
+ rftr.mandatoryObjectIdRefField.obj mustEqual Full(fttr2)
+ rftr.mandatoryObjectIdRefField.cached_? mustEqual true
+
+ // lists
+ rftr.mandatoryObjectIdRefListField.objs mustEqual List(fttr)
+ rftr.mandatoryUUIDRefListField.objs mustEqual List(ltr)
+ rftr.mandatoryStringRefListField.objs mustEqual List(mtr)
+ rftr.mandatoryIntRefListField.objs mustEqual List(ntr)
+ rftr.mandatoryLongRefListField.objs mustEqual List(btr)
+
+ val fttr3 = FieldTypeTestRecord.createRecord.save
+ val objList = List(fttr2, fttr3)
+
+ rftr.mandatoryObjectIdRefListField.cached_? mustEqual true
+ rftr.mandatoryObjectIdRefListField(objList.map(_.id.is))
+ rftr.mandatoryObjectIdRefListField.cached_? mustEqual false
+ rftr.mandatoryObjectIdRefListField.findAll mustEqual objList
+ rftr.mandatoryObjectIdRefListField.objs mustEqual objList
+ rftr.mandatoryObjectIdRefListField.cached_? mustEqual true
+ }
}
"use defaultValue when field is not present in the database" in {
checkMongoIsRunning
-
- val missingFieldDocId = ObjectId.get
-
- // create a dbobject with no fields manually
- val builder = BasicDBObjectBuilder.start
- .add("_id", missingFieldDocId)
-
- FieldTypeTestRecord.useColl { coll => coll.save(builder.get) }
-
- val recFromDb = FieldTypeTestRecord.find(missingFieldDocId)
-
- recFromDb must notBeEmpty
-
- recFromDb foreach { r =>
- r.mandatoryBooleanField.is must_== false
- r.legacyOptionalBooleanField
- r.optionalBooleanField.is must beEmpty
- r.mandatoryCountryField.is must_== Countries.C1
- r.legacyOptionalCountryField.valueBox must beEmpty
- r.optionalCountryField.is must beEmpty
- r.mandatoryDecimalField.is must_== 0.00
- r.legacyOptionalDecimalField.valueBox must beEmpty
- r.optionalDecimalField.is must beEmpty
- r.mandatoryDoubleField.is must_== 0d
- r.legacyOptionalDoubleField.valueBox must beEmpty
- r.optionalDoubleField.is must beEmpty
- r.mandatoryEmailField.is must_== ""
- r.legacyOptionalEmailField.valueBox must beEmpty
- r.optionalEmailField.is must beEmpty
- r.mandatoryEnumField.is must_== MyTestEnum.ONE
- r.legacyOptionalEnumField.valueBox must beEmpty
- r.optionalEnumField.is must beEmpty
- r.mandatoryIntField.is must_== 0
- r.legacyOptionalIntField.valueBox must beEmpty
- r.optionalIntField.is must beEmpty
- r.mandatoryLocaleField.is must_== Locale.getDefault.toString
- r.legacyOptionalLocaleField.valueBox must beEmpty
- r.optionalLocaleField.is must beEmpty
- r.mandatoryLongField.is must_== 0L
- r.legacyOptionalLongField.valueBox must beEmpty
- r.optionalLongField.is must beEmpty
- r.mandatoryPostalCodeField.is must_== ""
- r.legacyOptionalPostalCodeField.valueBox must beEmpty
- r.optionalPostalCodeField.is must beEmpty
- r.mandatoryStringField.is must_== ""
- r.legacyOptionalStringField.valueBox must beEmpty
- r.optionalStringField.is must beEmpty
- r.mandatoryTextareaField.is must_== ""
- r.legacyOptionalTextareaField.valueBox must beEmpty
- r.optionalTextareaField.is must beEmpty
- // r.mandatoryTimeZoneField.is must_== "America/Chicago"
- r.legacyOptionalTimeZoneField.valueBox must beEmpty
- r.optionalTimeZoneField.is must beEmpty
+ S.initIfUninitted(session) {
+ val missingFieldDocId = ObjectId.get
+
+ // create a dbobject with no fields manually
+ val builder = BasicDBObjectBuilder.start
+ .add("_id", missingFieldDocId)
+
+ FieldTypeTestRecord.useColl { coll => coll.save(builder.get) }
+
+ val recFromDb = FieldTypeTestRecord.find(missingFieldDocId)
+
+ recFromDb must notBeEmpty
+
+ recFromDb foreach { r =>
+ r.mandatoryBooleanField.is must_== false
+ r.legacyOptionalBooleanField
+ r.optionalBooleanField.is must beEmpty
+ r.mandatoryCountryField.is must_== Countries.C1
+ r.legacyOptionalCountryField.valueBox must beEmpty
+ r.optionalCountryField.is must beEmpty
+ r.mandatoryDecimalField.is must_== 0.00
+ r.legacyOptionalDecimalField.valueBox must beEmpty
+ r.optionalDecimalField.is must beEmpty
+ r.mandatoryDoubleField.is must_== 0d
+ r.legacyOptionalDoubleField.valueBox must beEmpty
+ r.optionalDoubleField.is must beEmpty
+ r.mandatoryEmailField.is must_== ""
+ r.legacyOptionalEmailField.valueBox must beEmpty
+ r.optionalEmailField.is must beEmpty
+ r.mandatoryEnumField.is must_== MyTestEnum.ONE
+ r.legacyOptionalEnumField.valueBox must beEmpty
+ r.optionalEnumField.is must beEmpty
+ r.mandatoryIntField.is must_== 0
+ r.legacyOptionalIntField.valueBox must beEmpty
+ r.optionalIntField.is must beEmpty
+ r.mandatoryLocaleField.is must_== Locale.getDefault.toString
+ r.legacyOptionalLocaleField.valueBox must beEmpty
+ r.optionalLocaleField.is must beEmpty
+ r.mandatoryLongField.is must_== 0L
+ r.legacyOptionalLongField.valueBox must beEmpty
+ r.optionalLongField.is must beEmpty
+ r.mandatoryPostalCodeField.is must_== ""
+ r.legacyOptionalPostalCodeField.valueBox must beEmpty
+ r.optionalPostalCodeField.is must beEmpty
+ r.mandatoryStringField.is must_== ""
+ r.legacyOptionalStringField.valueBox must beEmpty
+ r.optionalStringField.is must beEmpty
+ r.mandatoryTextareaField.is must_== ""
+ r.legacyOptionalTextareaField.valueBox must beEmpty
+ r.optionalTextareaField.is must beEmpty
+ // r.mandatoryTimeZoneField.is must_== "America/Chicago"
+ r.legacyOptionalTimeZoneField.valueBox must beEmpty
+ r.optionalTimeZoneField.is must beEmpty
+ }
}
}
@@ -655,66 +664,69 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
"update dirty fields for a FieldTypeTestRecord" in {
checkMongoIsRunning
- val fttr = FieldTypeTestRecord.createRecord
- .legacyOptionalStringField("legacy optional string")
- .optionalStringField("optional string")
- .save
+ S.initIfUninitted(session) {
+ val fttr = FieldTypeTestRecord.createRecord
+ .legacyOptionalStringField("legacy optional string")
+ .optionalStringField("optional string")
+ .save
- fttr.mandatoryBooleanField(true)
- fttr.mandatoryBooleanField.dirty_? must_== true
+ fttr.mandatoryBooleanField(true)
+ fttr.mandatoryBooleanField.dirty_? must_== true
- fttr.mandatoryDecimalField(BigDecimal("3.14"))
- fttr.mandatoryDecimalField.dirty_? must_== true
+ fttr.mandatoryDecimalField(BigDecimal("3.14"))
+ fttr.mandatoryDecimalField.dirty_? must_== true
- fttr.mandatoryDoubleField(1999)
- fttr.mandatoryDoubleField.dirty_? must_== true
+ fttr.mandatoryDoubleField(1999)
+ fttr.mandatoryDoubleField.dirty_? must_== true
- fttr.mandatoryEnumField(MyTestEnum.TWO)
- fttr.mandatoryEnumField.dirty_? must_== true
+ fttr.mandatoryEnumField(MyTestEnum.TWO)
+ fttr.mandatoryEnumField.dirty_? must_== true
- fttr.mandatoryIntField(99)
- fttr.mandatoryIntField.dirty_? must_== true
+ fttr.mandatoryIntField(99)
+ fttr.mandatoryIntField.dirty_? must_== true
- fttr.mandatoryLongField(100L)
- fttr.mandatoryLongField.dirty_? must_== true
+ fttr.mandatoryLongField(100L)
+ fttr.mandatoryLongField.dirty_? must_== true
- fttr.mandatoryStringField("string")
- fttr.mandatoryStringField.dirty_? must_== true
+ fttr.mandatoryStringField("string")
+ fttr.mandatoryStringField.dirty_? must_== true
- fttr.optionalStringField(Empty)
- fttr.optionalStringField.dirty_? must_== true
+ fttr.optionalStringField(Empty)
+ fttr.optionalStringField.dirty_? must_== true
- fttr.legacyOptionalStringField(Empty)
- fttr.legacyOptionalStringField.dirty_? must_== true
+ fttr.legacyOptionalStringField(Empty)
+ fttr.legacyOptionalStringField.dirty_? must_== true
- fttr.dirtyFields.length must_== 9
- fttr.update
- fttr.dirtyFields.length must_== 0
+ fttr.dirtyFields.length must_== 9
+ fttr.update
+ fttr.dirtyFields.length must_== 0
- val fromDb = FieldTypeTestRecord.find(fttr.id.is)
- fromDb must notBeEmpty
- fromDb foreach { rec =>
- rec must_== fttr
- rec.dirtyFields.length must_== 0
- }
+ val fromDb = FieldTypeTestRecord.find(fttr.id.is)
+ fromDb must notBeEmpty
+ fromDb foreach { rec =>
+ rec must_== fttr
+ rec.dirtyFields.length must_== 0
+ }
- val fttr2 = FieldTypeTestRecord.createRecord.save
- fttr2.legacyOptionalStringField("legacy optional string")
- fttr2.legacyOptionalStringField.dirty_? must_== true
+ val fttr2 = FieldTypeTestRecord.createRecord.save
- fttr2.optionalStringField("optional string")
- fttr2.optionalStringField.dirty_? must_== true
+ fttr2.legacyOptionalStringField("legacy optional string")
+ fttr2.legacyOptionalStringField.dirty_? must_== true
- fttr2.dirtyFields.length must_== 2
- fttr2.update
- fttr2.dirtyFields.length must_== 0
+ fttr2.optionalStringField("optional string")
+ fttr2.optionalStringField.dirty_? must_== true
- val fromDb2 = FieldTypeTestRecord.find(fttr2.id.is)
- fromDb2 must notBeEmpty
- fromDb2 foreach { rec =>
- rec must_== fttr2
- rec.dirtyFields.length must_== 0
+ fttr2.dirtyFields.length must_== 2
+ fttr2.update
+ fttr2.dirtyFields.length must_== 0
+
+ val fromDb2 = FieldTypeTestRecord.find(fttr2.id.is)
+ fromDb2 must notBeEmpty
+ fromDb2 foreach { rec =>
+ rec must_== fttr2
+ rec.dirtyFields.length must_== 0
+ }
}
}
View
3  project/Build.scala
@@ -139,7 +139,8 @@ object BuildDef extends Build {
lazy val couchdb =
persistenceProject("couchdb")
.dependsOn(record)
- .settings(libraryDependencies += dispatch_http)
+ .settings(libraryDependencies += dispatch_http,
+ parallelExecution in Test := false)
lazy val squeryl_record =
persistenceProject("squeryl-record")
Please sign in to comment.
Something went wrong with that request. Please try again.