forked from lift/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request lift#1552 from lift/tcn_issue_1498_2
Issue lift#1498 - Mongo -> MongoClient Transition Deprecates old constructors that interact with Mongo and Lift's abstractions over it and adds versions that deal with MongoClient. Also deals with WriteConcern differences in MongoClient vs Mongo, and adds a couple of new convenience methods to MongoRecord.
- Loading branch information
Showing
19 changed files
with
508 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...stence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/MongoClientSaveSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2014 WorldWide Conferencing, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.liftweb | ||
package mongodb | ||
package record | ||
|
||
import net.liftweb.common._ | ||
import net.liftweb.record.field._ | ||
|
||
import org.specs2.mutable.Specification | ||
|
||
import com.mongodb._ | ||
|
||
|
||
package mongoclientsaverecords { | ||
|
||
import field._ | ||
|
||
class SaveDoc private () extends MongoRecord[SaveDoc] with ObjectIdPk[SaveDoc] { | ||
def meta = SaveDoc | ||
|
||
object name extends StringField(this, 12) | ||
} | ||
object SaveDoc extends SaveDoc with MongoMetaRecord[SaveDoc] { | ||
import BsonDSL._ | ||
|
||
ensureIndex(("name" -> 1), true) // unique name | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Systems under specification for MongoClientSave. | ||
*/ | ||
class MongoClientSaveSpec extends Specification with MongoTestKit { | ||
"MongoClientSave Specification".title | ||
|
||
import mongoclientsaverecords._ | ||
|
||
override def mongo = new MongoClient("127.0.0.1", 27017) | ||
|
||
"MongoMetaRecord with Mongo save" in { | ||
|
||
checkMongoIsRunning | ||
|
||
val sd1 = SaveDoc.createRecord.name("MongoSession") | ||
val sd2 = SaveDoc.createRecord.name("MongoSession") | ||
val sd3 = SaveDoc.createRecord.name("MongoDB") | ||
|
||
// save to db | ||
sd1.save() | ||
sd2.save(false) // no exception thrown | ||
sd2.save(true) must throwA[MongoException] | ||
sd2.saveBox() must beLike { | ||
case Failure(msg, _, _) => msg must contain("E11000 duplicate key error index") // exception thrown | ||
} | ||
sd3.save() | ||
|
||
success | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.