-
Notifications
You must be signed in to change notification settings - Fork 306
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 #1898 from softwaremill/1862_Bady_serializer_for_J…
…SON_AST_types Add tests to check serialization and deserialization
- Loading branch information
Showing
16 changed files
with
256 additions
and
9 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
26 changes: 26 additions & 0 deletions
26
json/json4s/src/test/scala/sttp/client4/BackendStubJson4sTests.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,26 @@ | ||
package sttp.client4 | ||
|
||
import org.scalatest.concurrent.ScalaFutures | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sttp.client4.testing.SyncBackendStub | ||
import sttp.model.Uri | ||
import org.json4s.{native, DefaultFormats} | ||
|
||
case class Person(name: String) | ||
|
||
class BackendStubJson4sTests extends AnyFlatSpec with Matchers with ScalaFutures { | ||
|
||
implicit val serialization = native.Serialization | ||
implicit val formats = DefaultFormats | ||
|
||
import json4s._ | ||
|
||
it should "deserialize to json using a string stub" in { | ||
val backend = SyncBackendStub.whenAnyRequest.thenRespond("""{"name": "John"}""") | ||
val r = basicRequest.get(Uri("http://example.org")).response(asJson[Person]).send(backend) | ||
|
||
r.is200 should be(true) | ||
r.body should be(Right(Person("John"))) | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
json/jsoniter/src/test/scala/sttp/client4/jsoniter/BackendStubJsoniterTests.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,28 @@ | ||
package sttp.client4.jsoniter | ||
|
||
import org.scalatest.concurrent.ScalaFutures | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sttp.client4.testing.SyncBackendStub | ||
import sttp.model.Uri | ||
import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec | ||
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker | ||
|
||
case class Person(name: String) | ||
|
||
object Person { | ||
implicit val personJsonValueCodec: JsonValueCodec[Person] = JsonCodecMaker.make | ||
} | ||
|
||
class BackendStubJsoniterTests extends AnyFlatSpec with Matchers with ScalaFutures { | ||
|
||
import sttp.client4.basicRequest | ||
|
||
it should "deserialize to json using a string stub" in { | ||
val backend = SyncBackendStub.whenAnyRequest.thenRespond("""{"name": "John"}""") | ||
val r = basicRequest.get(Uri("http://example.org")).response(asJson[Person]).send(backend) | ||
|
||
r.is200 should be(true) | ||
r.body should be(Right(Person("John"))) | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
json/play-json/src/test/scala/sttp/client4/BackendStubPlayJsonTests.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,27 @@ | ||
package sttp.client4 | ||
|
||
import org.scalatest.concurrent.ScalaFutures | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sttp.client4.testing.SyncBackendStub | ||
import sttp.model.Uri | ||
import play.api.libs.json.Json | ||
import play.api.libs.json.OFormat | ||
import playJson._ | ||
|
||
case class Person(name: String) | ||
|
||
object Person { | ||
implicit val personFormat: OFormat[Person] = Json.format[Person] | ||
} | ||
|
||
class BackendStubPlayJsonTests extends AnyFlatSpec with Matchers with ScalaFutures { | ||
|
||
it should "deserialize to json using a string stub" in { | ||
val backend = SyncBackendStub.whenAnyRequest.thenRespond("""{"name": "John"}""") | ||
val r = basicRequest.get(Uri("http://example.org")).response(asJson[Person]).send(backend) | ||
|
||
r.is200 should be(true) | ||
r.body should be(Right(Person("John"))) | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
json/spray-json/src/test/scala/sttp/client4/BackendStubSprayJsonTests.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,27 @@ | ||
package sttp.client4 | ||
|
||
import org.scalatest.concurrent.ScalaFutures | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sttp.client4.testing.SyncBackendStub | ||
import sttp.model.Uri | ||
import spray.json.DefaultJsonProtocol.{jsonFormat1, StringJsonFormat} | ||
import spray.json.RootJsonFormat | ||
import sprayJson._ | ||
|
||
case class Person(name: String) | ||
|
||
object Person { | ||
implicit val personRootJsonFormat: RootJsonFormat[Person] = jsonFormat1(Person.apply) | ||
} | ||
|
||
class BackendStubSprayJsonTests extends AnyFlatSpec with Matchers with ScalaFutures { | ||
|
||
it should "deserialize to json using a string stub" in { | ||
val backend = SyncBackendStub.whenAnyRequest.thenRespond("""{"name": "John"}""") | ||
val r = basicRequest.get(Uri("http://example.org")).response(asJson[Person]).send(backend) | ||
|
||
r.is200 should be(true) | ||
r.body should be(Right(Person("John"))) | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
json/zio-json/src/test/scala/sttp/client4/ziojson/BackendStubZioJsonTests.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,27 @@ | ||
package sttp.client4.ziojson | ||
|
||
import org.scalatest.concurrent.ScalaFutures | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sttp.client4.basicRequest | ||
import sttp.client4.testing.SyncBackendStub | ||
import sttp.model.Uri | ||
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder} | ||
|
||
case class Person(name: String) | ||
|
||
object Person { | ||
implicit val encoder: JsonEncoder[Person] = DeriveJsonEncoder.gen[Person] | ||
implicit val codec: JsonDecoder[Person] = DeriveJsonDecoder.gen[Person] | ||
} | ||
|
||
class BackendStubJson4sTests extends AnyFlatSpec with Matchers with ScalaFutures { | ||
|
||
it should "deserialize to json using a string stub" in { | ||
val backend = SyncBackendStub.whenAnyRequest.thenRespond("""{"name": "John"}""") | ||
val r = basicRequest.get(Uri("http://example.org")).response(asJson[Person]).send(backend) | ||
|
||
r.is200 should be(true) | ||
r.body should be(Right(Person("John"))) | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
json/zio1-json/src/test/scala/sttp/client4/ziojson/BackendStubZioJsonTests.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,27 @@ | ||
package sttp.client4.ziojson | ||
|
||
import org.scalatest.concurrent.ScalaFutures | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sttp.client4.testing.SyncBackendStub | ||
import sttp.model.Uri | ||
import sttp.client4.basicRequest | ||
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder} | ||
|
||
case class Person(name: String) | ||
|
||
object Person { | ||
implicit val encoder: JsonEncoder[Person] = DeriveJsonEncoder.gen[Person] | ||
implicit val codec: JsonDecoder[Person] = DeriveJsonDecoder.gen[Person] | ||
} | ||
|
||
class BackendStubJson4sTests extends AnyFlatSpec with Matchers with ScalaFutures { | ||
|
||
it should "deserialize to json using a string stub" in { | ||
val backend = SyncBackendStub.whenAnyRequest.thenRespond("""{"name": "John"}""") | ||
val r = basicRequest.get(Uri("http://example.org")).response(asJson[Person]).send(backend) | ||
|
||
r.is200 should be(true) | ||
r.body should be(Right(Person("John"))) | ||
} | ||
} |
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