Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a stamina-testkit-based test for spray-json #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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