From feca13033a960d18ec705d8de95fed747ebbfcab Mon Sep 17 00:00:00 2001 From: Juliano Alves Date: Wed, 18 Oct 2023 10:57:10 +0100 Subject: [PATCH] remove jasync related tests (#369) --- .../postgres/ArrayAsyncEncodingSpec.scala | 246 ------------------ .../postgres/PostgresAsyncEncodingSpec.scala | 122 --------- 2 files changed, 368 deletions(-) delete mode 100644 quill-jasync-postgres/src/test/scala/io/getquill/context/jasync/postgres/ArrayAsyncEncodingSpec.scala delete mode 100644 quill-jasync-postgres/src/test/scala/io/getquill/context/jasync/postgres/PostgresAsyncEncodingSpec.scala diff --git a/quill-jasync-postgres/src/test/scala/io/getquill/context/jasync/postgres/ArrayAsyncEncodingSpec.scala b/quill-jasync-postgres/src/test/scala/io/getquill/context/jasync/postgres/ArrayAsyncEncodingSpec.scala deleted file mode 100644 index f7cb816c..00000000 --- a/quill-jasync-postgres/src/test/scala/io/getquill/context/jasync/postgres/ArrayAsyncEncodingSpec.scala +++ /dev/null @@ -1,246 +0,0 @@ -package io.getquill.context.jasync.postgres - -import java.time.{LocalDate, LocalDateTime} -import java.util.{Date, UUID} -import io.getquill.context.sql.EncodingTestType -import io.getquill.context.sql.encoding.ArrayEncodingBaseSpec -import io.getquill.* - -import java.time.temporal.ChronoUnit -import scala.concurrent.ExecutionContext.Implicits.global - -class ArrayAsyncEncodingSpec extends ArrayEncodingBaseSpec { - val ctx = testContext - import ctx._ - - "static" - { - inline def q = quote(query[ArraysTestEntity]) - - "Support all sql base types and `Iterable` implementers" in { - await(ctx.run(q.insertValue(lift(e)))) - val actual = await(ctx.run(q)).head - actual mustEqual e - baseEntityDeepCheck(actual, e) - } - - "Java8 times" in { - case class Java8Times(timestamps: Seq[LocalDateTime], dates: Seq[LocalDate]) - val jE = Java8Times(Seq(LocalDateTime.now().truncatedTo(ChronoUnit.MICROS)), Seq(LocalDate.now())) - inline def jQ = quote(querySchema[Java8Times]("ArraysTestEntity")) - await(ctx.run(jQ.insertValue(lift(jE)))) - val actual = await(ctx.run(jQ)).head - actual.timestamps mustBe jE.timestamps - actual.dates mustBe jE.dates - } - - "Support Iterable encoding basing on MappedEncoding" in { - inline def wrapQ = quote(querySchema[WrapEntity]("ArraysTestEntity")) - await(ctx.run(wrapQ.insertValue(lift(wrapE)))) - await(ctx.run(wrapQ)).head mustBe wrapE - } - - "Arrays in where clause" in { - await(ctx.run(q.insertValue(lift(e)))) - val actual1 = await(ctx.run(q.filter(_.texts == lift(List("test"))))) - val actual2 = await(ctx.run(q.filter(_.texts == lift(List("test2"))))) - baseEntityDeepCheck(actual1.head, e) - actual1 mustEqual List(e) - actual2 mustEqual List() - } - - // Need to have an actual value in the table in order for the decoder to go off. Previously, - // there was guarenteed to be information there due to ordering of build artifacts but not anymore. - "fail if found not an array" in { - case class RealEncodingTestEntity( - v1: String, - v2: BigDecimal, - v3: Boolean, - v4: Byte, - v5: Short, - v6: Int, - v7: Long, - v8: Float, - v9: Double, - v10: Array[Byte], - v11: Date, - v12: EncodingTestType, - v13: LocalDate, - v14: UUID, - o1: Option[String], - o2: Option[BigDecimal], - o3: Option[Boolean], - o4: Option[Byte], - o5: Option[Short], - o6: Option[Int], - o7: Option[Long], - o8: Option[Float], - o9: Option[Double], - o10: Option[Array[Byte]], - o11: Option[Date], - o12: Option[EncodingTestType], - o13: Option[LocalDate], - o14: Option[UUID], - o15: Option[io.getquill.context.sql.Number] - ) - - val insertValue = - RealEncodingTestEntity( - "s", - BigDecimal(1.1), - true, - 11.toByte, - 23.toShort, - 33, - 431L, - 34.4f, - 42d, - Array(1.toByte, 2.toByte), - new Date(31200000), - EncodingTestType("s"), - LocalDate.of(2013, 11, 23), - UUID.randomUUID(), - Some("s"), - Some(BigDecimal(1.1)), - Some(true), - Some(11.toByte), - Some(23.toShort), - Some(33), - Some(431L), - Some(34.4f), - Some(42d), - Some(Array(1.toByte, 2.toByte)), - Some(new Date(31200000)), - Some(EncodingTestType("s")), - Some(LocalDate.of(2013, 11, 23)), - Some(UUID.randomUUID()), - Some(io.getquill.context.sql.Number("0")) - ) - - inline def realEntity = quote { - querySchema[RealEncodingTestEntity]("EncodingTestEntity") - } - await(ctx.run(realEntity.insertValue(lift(insertValue)))) - - case class EncodingTestEntity(v1: List[String]) - intercept[IllegalStateException](await(ctx.run(query[EncodingTestEntity]))) - } - } - - "dynamic" - { - val q = quote(query[ArraysTestEntity]) - - "Support all sql base types and `Iterable` implementers" in { - await(ctx.run(q.insertValue(lift(e)))) - val actual = await(ctx.run(q)).head - actual mustEqual e - baseEntityDeepCheck(actual, e) - } - - "Java8 times" in { - case class Java8Times(timestamps: Seq[LocalDateTime], dates: Seq[LocalDate]) - val jE = Java8Times(Seq(LocalDateTime.now().truncatedTo(ChronoUnit.MICROS)), Seq(LocalDate.now())) - val jQ = quote(querySchema[Java8Times]("ArraysTestEntity")) - await(ctx.run(jQ.insertValue(lift(jE)))) - val actual = await(ctx.run(jQ)).head - actual.timestamps mustBe jE.timestamps - actual.dates mustBe jE.dates - } - - "Support Iterable encoding basing on MappedEncoding" in { - val wrapQ = quote(querySchema[WrapEntity]("ArraysTestEntity")) - await(ctx.run(wrapQ.insertValue(lift(wrapE)))) - await(ctx.run(wrapQ)).head mustBe wrapE - } - - "Arrays in where clause" in { - await(ctx.run(q.insertValue(lift(e)))) - val actual1 = await(ctx.run(q.filter(_.texts == lift(List("test"))))) - val actual2 = await(ctx.run(q.filter(_.texts == lift(List("test2"))))) - baseEntityDeepCheck(actual1.head, e) - actual1 mustEqual List(e) - actual2 mustEqual List() - } - - // Need to have an actual value in the table in order for the decoder to go off. Previously, - // there was guarenteed to be information there due to ordering of build artifacts but not anymore. - "fail if found not an array" in { - case class RealEncodingTestEntity( - v1: String, - v2: BigDecimal, - v3: Boolean, - v4: Byte, - v5: Short, - v6: Int, - v7: Long, - v8: Float, - v9: Double, - v10: Array[Byte], - v11: Date, - v12: EncodingTestType, - v13: LocalDate, - v14: UUID, - o1: Option[String], - o2: Option[BigDecimal], - o3: Option[Boolean], - o4: Option[Byte], - o5: Option[Short], - o6: Option[Int], - o7: Option[Long], - o8: Option[Float], - o9: Option[Double], - o10: Option[Array[Byte]], - o11: Option[Date], - o12: Option[EncodingTestType], - o13: Option[LocalDate], - o14: Option[UUID], - o15: Option[io.getquill.context.sql.Number] - ) - - val insertValue = - RealEncodingTestEntity( - "s", - BigDecimal(1.1), - true, - 11.toByte, - 23.toShort, - 33, - 431L, - 34.4f, - 42d, - Array(1.toByte, 2.toByte), - new Date(31200000), - EncodingTestType("s"), - LocalDate.of(2013, 11, 23), - UUID.randomUUID(), - Some("s"), - Some(BigDecimal(1.1)), - Some(true), - Some(11.toByte), - Some(23.toShort), - Some(33), - Some(431L), - Some(34.4f), - Some(42d), - Some(Array(1.toByte, 2.toByte)), - Some(new Date(31200000)), - Some(EncodingTestType("s")), - Some(LocalDate.of(2013, 11, 23)), - Some(UUID.randomUUID()), - Some(io.getquill.context.sql.Number("0")) - ) - - val realEntity = quote { - querySchema[RealEncodingTestEntity]("EncodingTestEntity") - } - await(ctx.run(realEntity.insertValue(lift(insertValue)))) - - case class EncodingTestEntity(v1: List[String]) - intercept[IllegalStateException](await(ctx.run(query[EncodingTestEntity]))) - } - } - - override protected def beforeEach(): Unit = { - await(ctx.run(query[ArraysTestEntity].delete)) - () - } -} diff --git a/quill-jasync-postgres/src/test/scala/io/getquill/context/jasync/postgres/PostgresAsyncEncodingSpec.scala b/quill-jasync-postgres/src/test/scala/io/getquill/context/jasync/postgres/PostgresAsyncEncodingSpec.scala deleted file mode 100644 index efa5943e..00000000 --- a/quill-jasync-postgres/src/test/scala/io/getquill/context/jasync/postgres/PostgresAsyncEncodingSpec.scala +++ /dev/null @@ -1,122 +0,0 @@ -package io.getquill.context.jasync.postgres - -import java.time.{LocalDate, LocalDateTime, ZonedDateTime} -import io.getquill.context.sql.EncodingSpec - -import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.Await -import scala.concurrent.duration.Duration -import java.util.Date -import java.util.UUID -import io.getquill.* -import org.scalatest.* - -import java.time.temporal.ChronoUnit - -class PostgresAsyncEncodingSpec extends EncodingSpec { - - val context = testContext - import testContext._ - - "encodes and decodes types" in { - val r = - for { - _ <- testContext.run(delete) - r <- testContext.run(liftQuery(insertValues).foreach(e => insert(e))) - result <- testContext.run(query[EncodingTestEntity]) - } yield result - - verify(Await.result(r, Duration.Inf).toList) - } - - "encodes and decodes uuids" in { - case class EncodingUUIDTestEntity(v1: UUID) - val testUUID = UUID.fromString("e5240c08-6ee7-474a-b5e4-91f79c48338f") - - //delete old values - val q0 = quote(query[EncodingUUIDTestEntity].delete) - val rez0 = Await.result(testContext.run(q0), Duration.Inf) - - //insert new uuid - val rez1 = Await.result(testContext.run(query[EncodingUUIDTestEntity].insertValue(lift(EncodingUUIDTestEntity(testUUID)))), Duration.Inf) - - //verify you can get the uuid back from the db - val q2 = quote(query[EncodingUUIDTestEntity].map(p => p.v1)) - val rez2 = Await.result(testContext.run(q2), Duration.Inf) - - rez2 mustEqual List(testUUID) - } - - "fails if the column has the wrong type" - { - "numeric" in { - Await.result(testContext.run(liftQuery(insertValues).foreach(e => insert(e))), Duration.Inf) - case class EncodingTestEntity(v1: Int) - val e = intercept[IllegalStateException] { - Await.result(testContext.run(query[EncodingTestEntity]), Duration.Inf) - } - } - "non-numeric" in { - Await.result(testContext.run(liftQuery(insertValues).foreach(e => insert(e))), Duration.Inf) - case class EncodingTestEntity(v1: Date) - val e = intercept[IllegalStateException] { - Await.result(testContext.run(query[EncodingTestEntity]), Duration.Inf) - } - } - } - - "encodes sets" in { - inline def q = quote { - (set: Query[Int]) => - query[EncodingTestEntity].filter(t => set.contains(t.v6)) - } - val fut = - for { - _ <- testContext.run(query[EncodingTestEntity].delete) - _ <- testContext.run(liftQuery(insertValues).foreach(e => query[EncodingTestEntity].insertValue(e))) - r <- testContext.run(q(liftQuery(insertValues.map(_.v6)))) - } yield { - r - } - verify(Await.result(fut, Duration.Inf).toList) - } - - "returning UUID" in { - val success = for { - uuid <- Await.result(testContext.run(insertBarCode(lift(barCodeEntry))), Duration.Inf) - barCode <- Await.result(testContext.run(findBarCodeByUuid(uuid)), Duration.Inf).headOption - } yield { - verifyBarcode(barCode) - } - success must not be empty - } - - "decodes LocalDate and LocalDateTime types" in { - case class DateEncodingTestEntity(v1: LocalDate, v2: LocalDateTime, v3: ZonedDateTime) - val entity = DateEncodingTestEntity( - LocalDate.now, - LocalDateTime.now.truncatedTo(ChronoUnit.MICROS), - ZonedDateTime.now(testContext.dateTimeZone).truncatedTo(ChronoUnit.MICROS) - ) - val r = for { - _ <- testContext.run(query[DateEncodingTestEntity].delete) - _ <- testContext.run(query[DateEncodingTestEntity].insertValue(lift(entity))) - result <- testContext.run(query[DateEncodingTestEntity]) - } yield result - Await.result(r, Duration.Inf) mustBe Seq(entity) - } - - "encodes custom type inside singleton object" in { - object Singleton { - def apply()(implicit c: TestContext) = { - import c._ - for { - _ <- c.run(query[EncodingTestEntity].delete) - result <- c.run(liftQuery(insertValues).foreach(e => query[EncodingTestEntity].insertValue(e))) - } yield result - } - } - - implicit val c = testContext - Await.result(Singleton(), Duration.Inf) - } -}