Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
A las Barricadas! Upgraded to specs2 and rejiggered specs to comply w…
Browse files Browse the repository at this point in the history
…ith structural and syntax changes.
  • Loading branch information
rktoomey committed Mar 10, 2011
1 parent bd86c3b commit 493247f
Show file tree
Hide file tree
Showing 21 changed files with 234 additions and 230 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Expand Up @@ -33,7 +33,7 @@
<commons.lang.version>2.5</commons.lang.version>
<slf4j.simple.version>1.6.0</slf4j.simple.version>
<!-- Test dependencies -->
<specs.version>1.6.7</specs.version>
<specs2.version>1.0.1</specs2.version>
<!-- Build properties -->
<maven-jar-plugin.version>2.2</maven-jar-plugin.version>
<jar.dependency.dist.dir>lib</jar.dependency.dist.dir>
Expand Down Expand Up @@ -101,9 +101,9 @@
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs_2.8.1</artifactId>
<version>${specs.version}</version>
<groupId>org.specs2</groupId>
<artifactId>specs2_2.8.1</artifactId>
<version>${specs2.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
11 changes: 9 additions & 2 deletions project/build/SalatProject.scala
Expand Up @@ -11,12 +11,19 @@ class SalatProject(info: ProjectInfo) extends ParentProject(info) with posterous
abstract class BaseSalatProject(info: ProjectInfo) extends DefaultProject(info) {
override def compileOptions = super.compileOptions ++ Seq(Unchecked, Deprecation)

val specs = "org.scala-tools.testing" %% "specs" % "1.6.7" % "test->default" withSources()
// val specs = "org.scala-tools.testing" %% "specs" % "1.6.7" % "test->default" withSources()
val specs2 = "org.specs2" %% "specs2" % "1.0.1" % "test->default"
val commonsLang = "commons-lang" % "commons-lang" % "2.5" % "test->default" withSources()
val slf4jSimple = "org.slf4j" % "slf4j-simple" % "1.6.0" % "test->default" withSources()

override def packageSrcJar= defaultJarPath("-sources.jar")
override def packageSrcJar = defaultJarPath("-sources.jar")

override def packageToPublishActions = super.packageToPublishActions ++ Seq(packageSrc)

def specs2Framework = new TestFramework("org.specs2.runner.SpecsFramework")

override def testFrameworks = super.testFrameworks ++ Seq(specs2Framework)

}

class SalatCoreProject(info: ProjectInfo) extends BaseSalatProject(info) {
Expand Down
Expand Up @@ -36,15 +36,15 @@ class BasicCaseObjectSpec extends SalatSpec {
log.info("after : %s", dbo.asDBObject)

dbo must havePair("a" -> e.a)
dbo must notHaveKey("aa")
dbo must not have key("aa")
dbo must havePair("aaa" -> e.aaa.get)

dbo must havePair("b" -> e.b)
dbo must notHaveKey("bb")
dbo must not have key("bb")
dbo must havePair("bbb" -> e.bbb.get)

dbo must havePair("c" -> e.c)
dbo must notHaveKey("cc")
dbo must not have key("cc")
dbo must havePair("ccc" -> e.ccc.get)
}

Expand Down
Expand Up @@ -26,12 +26,9 @@ import com.novus.salat.test.model._
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.Implicits._
import java.math.{RoundingMode, MathContext}
import org.specs.specification.PendingUntilFixed
import scala.math.{BigDecimal => ScalaBigDecimal}

class BigDecimalPrecisionTest extends SalatSpec with PendingUntilFixed {


class BigDecimalPrecisionTest extends SalatSpec {

"Salat grater" should {
"preserve ScalaBigDecimal precision to 16 places" in {
Expand All @@ -46,19 +43,19 @@ class BigDecimalPrecisionTest extends SalatSpec with PendingUntilFixed {
val dbo: MongoDBObject = grater[George].asDBObject(g)
dbo must havePair("number" -> PrecisePi)
dbo must havePair("someNumber" -> PrecisePi)
dbo must notHaveKey("noNumber")
dbo must not have key("noNumber")

val coll = MongoConnection()(SalatSpecDb)("scala_math_big_decimal_precision_test")
val wr = coll.insert(dbo)
// println("WR: %s".format(wr))

val g_* = grater[George].asObject(coll.findOne().get)
g_* mustEqual g
g_*.number.precision mustEqual 16
g_*.someNumber.get.precision mustEqual 16
g_* must_== g
g_*.number.precision must_== 16
g_*.someNumber.get.precision must_== 16

g_*.number mustNotEq MorePrecisePi
g_*.number mustEqual MorePrecisePi(mc)
g_*.number must not be equalTo(MorePrecisePi)
g_*.number must_== MorePrecisePi(mc)

}

Expand All @@ -74,19 +71,19 @@ class BigDecimalPrecisionTest extends SalatSpec with PendingUntilFixed {
val dbo: MongoDBObject = grater[George2].asDBObject(h)
dbo must havePair("number" -> PrecisePi)
dbo must havePair("someNumber" -> PrecisePi)
dbo must notHaveKey("noNumber")
dbo must not have key("noNumber")

val coll = MongoConnection()(SalatSpecDb)("scala_big_decimal_precision_test")
val wr = coll.insert(dbo)
// println("WR: %s".format(wr))

val h_* = grater[George2].asObject(coll.findOne().get)
h_* mustEqual h
h_*.number.precision mustEqual 16
h_*.someNumber.get.precision mustEqual 16
h_* must_== h
h_*.number.precision must_== 16
h_*.someNumber.get.precision must_== 16

h_*.number mustNotEq MorePrecisePi
h_*.number mustEqual MorePrecisePi(mc)
h_*.number must not be equalTo(MorePrecisePi)
h_*.number must_== MorePrecisePi(mc)

}
}
Expand All @@ -106,7 +103,7 @@ class BigDecimalPrecisionTest extends SalatSpec with PendingUntilFixed {
// println("WR: %s".format(wr))

val i_* = grater[Ida].asObject(coll.findOne().get)
i_* mustEqual i
i_* must_== i

}

Expand All @@ -122,7 +119,7 @@ class BigDecimalPrecisionTest extends SalatSpec with PendingUntilFixed {
// println("WR: %s".format(wr))

val i_* = grater[Ida].asObject(coll.findOne().get)
i_* mustEqual i
i_* must_== i
}
}

Expand Down
Expand Up @@ -21,7 +21,6 @@
package com.novus.salat.test

import com.novus.salat._
import com.novus.salat.util._
import com.novus.salat.global._
import com.novus.salat.test.model._
import com.mongodb.casbah.Imports._
Expand All @@ -42,7 +41,7 @@ class BigIntSpec extends SalatSpec {

val l_* = grater[Leo].asObject(coll.findOne().get)
// println(MapPrettyPrinter(l_*))
l_* mustEqual l
l_* must_== l
}
}
}
Expand Up @@ -35,12 +35,15 @@ class CaseObjectSupport extends SalatSpec {
val dbo: MongoDBObject = grater[Wardrobe].asDBObject(mine)
log.info("dbo : %s", dbo)
val suits = dbo.expand[BasicDBList]("suits")
suits must beSome[BasicDBList].which {
suits => val suit: MongoDBObject = suits(0).asInstanceOf[DBObject]
val th = suit.expand[String]("_typeHint")
th must beSome[String].which {
th => th == Zoot.getClass.getName
suits must beSome[BasicDBList]
suits.getOrElse(throw new Exception("argh, someone stole my wardrobe")) // TODO: where did which go?
suits match {
case Some(suits) => {
val suit: MongoDBObject = suits(0).asInstanceOf[DBObject]
val th = suit.expand[String]("_typeHint")
th must beSome(Zoot.getClass.getName)
}
case None => throw new Exception("where are my suits?") // TODO: where did fail go?
}
}

Expand Down
Expand Up @@ -21,7 +21,6 @@
package com.novus.salat.test

import com.novus.salat._
import com.novus.salat.util._
import com.novus.salat.global._
import com.novus.salat.test.model._
import com.mongodb.casbah.Imports._
Expand All @@ -42,7 +41,7 @@ class CharacterSpec extends SalatSpec {
// println("WR: %s".format(wr))

val k_* = grater[Kate].asObject(coll.findOne().get)
k_* mustEqual k
k_* must_== k
}
}

Expand Down
Expand Up @@ -43,7 +43,7 @@ class ContextSpec extends SalatSpec {
}

"by type" in {
ctx.lookup_![James] mustEqual grater[James]
ctx.lookup_![James] must_== grater[James]
}
}
}
Expand All @@ -63,7 +63,7 @@ class ContextSpec extends SalatSpec {
}

"by type" in {
ctx.lookup_![James] mustEqual grater[James]
ctx.lookup_![James] must_== grater[James]
}
}
}
Expand All @@ -90,7 +90,7 @@ class ContextSpec extends SalatSpec {
}

"by type" in {
ctx.lookup_![James] mustEqual grater[James]
ctx.lookup_![James] must_== grater[James]
}
}

Expand Down
Expand Up @@ -20,15 +20,13 @@
*/
package com.novus.salat.test

import org.specs.specification.PendingUntilFixed
import com.novus.salat._
import scala.tools.nsc.util.ScalaClassLoader
import com.mongodb.casbah.Imports._
import scala.reflect.Manifest
import com.novus.salat.util.MapPrettyPrinter
import com.novus.salat.test.model.{Ida, James, Alice, Walrus}
import com.novus.salat.test.model.{Ida, Alice, Walrus}

class CustomContextSpec extends SalatSpec with PendingUntilFixed {
class CustomContextSpec extends SalatSpec {

"Salat context" should {

Expand All @@ -40,16 +38,17 @@ class CustomContextSpec extends SalatSpec with PendingUntilFixed {
ctx.name must beSome("CustomContextSpec-1")
// this custom context is using the default classloader
ctx.classLoaders must haveSize(1)
ctx.classLoaders(0) mustEqual ctx.getClass.getClassLoader
ctx.classLoaders(0) must_== ctx.getClass.getClassLoader

// members of com.novus.salat.test.model can be resolved as expected
ctx.classLoaders(0) mustEqual Alice.getClass.getClassLoader
ctx.classLoaders(0) must_== Alice.getClass.getClassLoader
getClassNamed(Alice.getClass.getName)(ctx) must beSome(Alice.getClass)
}

"provide flexible classloader handling" in {

val TestClassName = "com.novus.salat.test.CustomContextSpec$$anonfun$1$$anonfun$apply$10$$anon$2$Ida"
// TODO: somewhat contrived but...
val TestClassName = "com.novus.salat.test.CustomContextSpec$$anonfun$1$$anonfun$apply$15$$anon$2$Ida"

val customCl = new ScalaClassLoader() {
case class Ida(lake: Int = 10, drowned: Boolean = true)
Expand All @@ -76,8 +75,8 @@ class CustomContextSpec extends SalatSpec with PendingUntilFixed {
val custom = ctx.classLoaders(0)
val default = ctx.classLoaders(1)

custom mustEqual customCl
default mustEqual ctx.getClass.getClassLoader
custom must_== customCl
default must_== ctx.getClass.getClassLoader

// we can resolve a class from the default classloader
getClassNamed(Alice.getClass.getName)(ctx) must beSome(Alice.getClass)
Expand Down Expand Up @@ -116,23 +115,23 @@ class CustomContextSpec extends SalatSpec with PendingUntilFixed {

ctx.name must beSome(CustomContextName)
ctx.classLoaders must haveSize(1)
ctx.classLoaders(0) mustEqual customCl
ctx.classLoaders must notContain(ctx.getClass.getClassLoader)
ctx.classLoaders(0) must_== customCl
ctx.classLoaders must not contain(ctx.getClass.getClassLoader)

// try to register another classloader and confirm it didn't work, because we overrode the default impl
val customCl2: ClassLoader = new ScalaClassLoader() {
// some impl
}
ctx.registerClassLoader(customCl2)
ctx.classLoaders must haveSize(1)
ctx.classLoaders(0) mustEqual customCl
ctx.classLoaders must notContain(customCl2)
ctx.classLoaders must notContain(ctx.getClass.getClassLoader)
ctx.classLoaders(0) must_== customCl
ctx.classLoaders must not contain(customCl2)
ctx.classLoaders must not contain(ctx.getClass.getClassLoader)

// resolving a class from the default classloader doesn't work
getClassNamed(Alice.getClass.getName)(ctx) must beNone
// resolving a class from our custom classloader does
getClassNamed(TestClassName)(ctx) must notBeEmpty
getClassNamed(TestClassName)(ctx) must not beEmpty
}

"percolate a custom context down the entire chain" in {
Expand All @@ -153,7 +152,7 @@ class CustomContextSpec extends SalatSpec with PendingUntilFixed {
val dbo: MongoDBObject = grater[Walrus[String]].asDBObject(w)
dbo.get("manyThings") must beSome[AnyRef]
val w_* = grater[Walrus[String]].asObject(dbo)
w_* mustEqual w
w_* must_== w

// we can resolve a class from the custom classloader
getClassNamed(TestClassName) must beSome(testClassForName)
Expand Down Expand Up @@ -181,10 +180,10 @@ class CustomContextSpec extends SalatSpec with PendingUntilFixed {
log.info(MapPrettyPrinter(dbo))
// our global key remap transformed "lake" to "swamp"
dbo must havePair(swamp, 3.14)
dbo must notHaveKey(lake)
dbo must not have key(lake)

val i_* = grater[Ida].asObject(dbo)
i_* mustEqual i
i_* must_== i
}

}
Expand Down
Expand Up @@ -21,7 +21,6 @@
package com.novus.salat.test

import com.novus.salat._
import com.novus.salat.util._
import com.novus.salat.global._
import com.novus.salat.test.model._

Expand All @@ -43,7 +42,7 @@ class DateTimeSpec extends SalatSpec {
val coll = MongoConnection()(SalatSpecDb)("scala_date_test_1")
val wr = coll.insert(dbo)
val n_* = grater[Neville].asObject(coll.findOne().get)
n_* mustEqual n
n_* must_== n
}

"support org.joda.time.DateTime" in {
Expand All @@ -58,15 +57,15 @@ class DateTimeSpec extends SalatSpec {
val coll = MongoConnection()(SalatSpecDb)("scala_date_test_2")
val wr = coll.insert(dbo)
val n_* = grater[Neville].asObject(coll.findOne().get)
n_* mustEqual n
n_* must_== n
}

"support dates parsed from JSON" in {
val n = Neville(asOf = new org.joda.time.DateMidnight().toDateTime)
val json = grater[Neville].asDBObject(n).toString
log.info(json)
val n_* = grater[Neville].asObject(parse(json).asInstanceOf[DBObject])
n_* mustEqual n
n_* must_== n
}

}
Expand Down

0 comments on commit 493247f

Please sign in to comment.