|
Lift Framework example source code file (CustomSerializersSpec.scala)
The Lift Framework CustomSerializersSpec.scala source code
/*
* Copyright 2010-2011 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
import java.util.{Calendar, Date, TimeZone}
import org.bson.types.ObjectId
import org.specs.Specification
package customserializersspecs {
/*
* Date as String
*/
case class Person(_id: String, birthDate: Date)
extends MongoDocument[Person]
{
def meta = Person
}
object Person extends MongoDocumentMeta[Person]
/*
* Date as Date
*/
case class Person2(_id: ObjectId, birthDate: Date) extends MongoDocument[Person2] {
def meta = Person2
}
object Person2 extends MongoDocumentMeta[Person2] {
override def formats = allFormats
}
}
/**
* Systems under specification for CustomSerializers.
*/
object CustomSerializersSpec extends Specification("CustomSerializers Specification") with MongoTestKit {
import customserializersspecs._
val utc = TimeZone.getTimeZone("UTC")
"CustomSerializers" should {
"handle Date as String value" in {
checkMongoIsRunning
// test data
val bdjack = Calendar.getInstance
bdjack.setTimeZone(utc)
bdjack.setTimeInMillis(1288742280000L)
val jack = Person(ObjectId.get.toString, bdjack.getTime)
// save the Person document
jack.save
// retrieve it and compare
val jack2 = Person.find(jack._id)
jack2 must notBeEmpty
jack2 foreach { j =>
j._id mustEqual jack._id
j.birthDate mustEqual jack.birthDate
}
}
"handle Date as Date value using DateSerializer" in {
checkMongoIsRunning
// test data
val bdjack = Calendar.getInstance
bdjack.setTimeZone(utc)
bdjack.setTimeInMillis(1288742280000L)
val jack = Person2(ObjectId.get, bdjack.getTime)
// save the Person document
jack.save
// retrieve it and compare
val findJack = Person2.find(jack._id)
findJack must notBeEmpty
findJack foreach { j =>
j._id mustEqual jack._id
j.birthDate mustEqual jack.birthDate
}
}
}
}
Other Lift Framework examples (source code examples)Here is a short list of links related to this Lift Framework CustomSerializersSpec.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.