Skip to content

Commit

Permalink
Add a stamina-testkit-based test for spray-json
Browse files Browse the repository at this point in the history
  • Loading branch information
raboof committed Nov 1, 2015
1 parent b45b29f commit b913720
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ object Build extends Build {

lazy val json = Project("stamina-json", file("stamina-json"))
.dependsOn(core)
.dependsOn(testkit % "test")
.settings(libSettings: _*)
.settings(libraryDependencies ++=
compile(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eyJjYXJ0Ijp7ImlkIjoxLCJpdGVtcyI6W3siaWQiOjEsIm5hbWUiOiJXb25rYSBCYXIiLCJwcmljZSI6NTAwfSx7ImlkIjoyLCJuYW1lIjoiRXZlcmxhc3RpbmcgR29ic3RvcHBlciIsInByaWNlIjo0ODl9XX0sInRpbWVzdGFtcCI6MTQ0NjM3NzE5OTk0M30=
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eyJwYXltZW50TWV0aG9kIjoibWFlc3RybyJ9
18 changes: 17 additions & 1 deletion stamina-json/src/test/scala/stamina/json/JsonPersisterSpec.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package stamina
package json

class JsonPersisterSpec extends StaminaJsonSpec {
import stamina.testkit._

class JsonPersisterSpec extends StaminaJsonSpec
with StaminaTestKit {
import JsonTestDomain._
import spray.json.lenses.JsonLenses._
import fommil.sjs.FamilyFormats._
Expand Down Expand Up @@ -56,4 +59,17 @@ class JsonPersisterSpec extends StaminaJsonSpec {
v2Unpersisted.timestamp should (be > 0L and be < System.currentTimeMillis)
}
}

"a persister based on stamina-json and spray-json-shapeless" should {
import fommil.sjs.FamilyFormats._

val persisters = Persisters(List(
persister[CartCreatedV3]("cart-created"),
persister[CheckoutStarted]("checkout-started")
))

persisters.generateTestsFor(
sample(v3CartCreated),
sample(checkoutStarted))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ object JsonTestDomain {
val v3Item1 = ItemV3(1, "Wonka Bar", 500)
val v3Item2 = ItemV3(2, "Everlasting Gobstopper", 489)
val v3Cart = CartV3(1, List(v3Item1, v3Item2))
val v3CartCreated = CartCreatedV3(v3Cart, System.currentTimeMillis)
val v3CartCreated = CartCreatedV3(v3Cart, 1446377199943l)

// Others

case class CheckoutStarted(paymentMethod: String)
val checkoutStarted = CheckoutStarted("maestro")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ class ScalatestTestGenerationSpec extends StaminaTestKitSpec {

import TestDomain._

case class ItemPersister(override val key: String) extends Persister[Item, V1](key) {
def persist(t: Item): Persisted = Persisted(key, currentVersion, ByteString())
def unpersist(p: Persisted): Item = item1
}

"A spec generated by StaminaTestKit" should {
case class ItemPersister(override val key: String) extends Persister[Item, V1](key) {
def persist(t: Item): Persisted = Persisted(key, currentVersion, ByteString())
def unpersist(p: Persisted): Item = item1
}

val persisters = Persisters(ItemPersister("item1"))

val spec = new StaminaTestKit with WordSpecLike {
val persisters = Persisters(ItemPersister("item1"))
"TestDomainSerialization" should {
persisters.generateTestsFor(
sample(item1),
Expand Down

0 comments on commit b913720

Please sign in to comment.