Skip to content

Commit

Permalink
Merge branch 'master' into update/testcontainers-scala-0.41.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scala-steward committed Oct 4, 2023
2 parents 9c3a619 + ee02df6 commit fb32b27
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ lazy val `slick-joda-mapper` = project.in(file("."))
name := "slick-joda-mapper",
organization := "com.github.tototoshi",
version := "2.8.0",
crossScalaVersions := Seq("2.12.18", "2.13.11", "3.3.0"),
scalaVersion := "2.13.11",
crossScalaVersions := Seq("2.12.18", "2.13.12", "3.3.0"),
scalaVersion := "2.13.12",
scalacOptions ++= Seq(
"-deprecation",
"-feature",
Expand Down Expand Up @@ -43,13 +43,13 @@ lazy val `slick-joda-mapper` = project.in(file("."))
libraryDependencies ++= Seq(
"joda-time" % "joda-time" % "2.12.5" % "provided",
"org.joda" % "joda-convert" % "2.2.3" % "provided",
"com.h2database" % "h2" % "2.2.220" % "test",
"com.h2database" % "h2" % "2.2.224" % "test",
"com.dimafeng" %% "testcontainers-scala" % "0.40.17" % "test",
"mysql" % "mysql-connector-java" % "8.0.33" % "test",
"com.mysql" % "mysql-connector-j" % "8.1.0" % "test",
"org.postgresql" % "postgresql" % "42.6.0" % "test",
"org.testcontainers" % "mysql" % testContainerVersion % "test",
"org.testcontainers" % "postgresql" % testContainerVersion % "test",
"org.slf4j" % "slf4j-simple" % "2.0.7" % "test",
"org.slf4j" % "slf4j-simple" % "2.0.9" % "test",
"org.scalatest" %% "scalatest" % "3.2.16" % "test",
"com.typesafe.slick" %% "slick" % "3.4.1" % "provided" cross CrossVersion.for3Use2_13
),
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.3
sbt.version=1.9.6
59 changes: 55 additions & 4 deletions src/test/scala/com/github/tototoshi/slick/JodaSupportSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ abstract class JodaSupportSpec extends AnyFunSpec
def jdbcDriver: String
def jdbcUser: String
def jdbcPassword: String
def isWithoutCalender: Boolean

import driver.api._
import jodaSupport._
import slick.sql.SqlProfile.ColumnOption.SqlType

case class Jodas(
dateTimeZone: DateTimeZone,
Expand All @@ -72,8 +74,8 @@ abstract class JodaSupportSpec extends AnyFunSpec
def dateTimeZone = column[DateTimeZone]("date_time_zone")
def localDate = column[LocalDate]("local_date")
def dateTime = column[DateTime]("date_time")
def instant = column[Instant]("instant")
def localDateTime = column[LocalDateTime]("local_date_time")
def instant = column[Instant]("instant", SqlType("timestamp not null default CURRENT_TIMESTAMP"))
def localDateTime = column[LocalDateTime]("local_date_time", SqlType("timestamp not null default CURRENT_TIMESTAMP"))
def localTime = column[LocalTime]("local_time")
def optDateTimeZone = column[Option[DateTimeZone]]("opt_date_time_zone")
def optLocalDate = column[Option[LocalDate]]("opt_local_date")
Expand All @@ -100,7 +102,6 @@ abstract class JodaSupportSpec extends AnyFunSpec
val tz = TimeZone.getTimeZone("Asia/Tokyo")
TimeZone.setDefault(tz)
DateTimeZone.setDefault(DateTimeZone.forID(tz.getID))

db.run(DBIO.seq(jodaTest.schema.create)).await()
}

Expand Down Expand Up @@ -224,6 +225,41 @@ abstract class JodaSupportSpec extends AnyFunSpec
res2.lift(1).map(_.localDate) should not be Some(new LocalDate(2012, 12, 5))
res2.lift(2).map(_.localDate) should not be Some(new LocalDate(2012, 12, 5))
}

private val systemTimeZone = java.util.TimeZone.getDefault().getID
Seq("Asia/Tokyo", "UTC", "Europe/London", "America/New_York").foreach { tz =>
val timeZone = DateTimeZone.forID(tz)
it(s"should be the same in/out joda-time zoned $tz") {
val otherZonedDateTime = new DateTime(2012, 12, 7, 0, 0, 0, 0, timeZone)
val data = Jodas(
DateTimeZone.forID("Asia/Tokyo"),
new LocalDate(2012, 12, 7),
otherZonedDateTime,
new DateTime(2012, 12, 7, 0, 0, 0, 0, DateTimeZone.UTC).toInstant,
new LocalDateTime(2012, 12, 7, 0, 0, 0, 0),
new LocalTime(1000),
Some(DateTimeZone.forID("America/New_York")),
Some(new LocalDate(2012, 12, 6)),
None,
Some(new Instant(1000)),
None,
Some(new LocalTime(1000))
)
db.run(jodaTest += data).await()

val actual = db.run(jodaTest.result).await()
actual should have size 1

actual.foreach { d =>
if (isWithoutCalender)
d.dateTime.getMillis should be(data.dateTime.getMillis)
else if (systemTimeZone == timeZone.getID)
d.dateTime.getMillis should be(data.dateTime.getMillis)
else
pending
}
}
}
}

class H2JodaSupportSpec extends JodaSupportSpec {
Expand All @@ -233,6 +269,7 @@ class H2JodaSupportSpec extends JodaSupportSpec {
override def jdbcDriver = "org.h2.Driver"
override def jdbcUser = "sa"
override def jdbcPassword = null
override val isWithoutCalender = false
}

abstract class TestContainerSpec extends JodaSupportSpec with ForAllTestContainer {
Expand All @@ -242,19 +279,33 @@ abstract class TestContainerSpec extends JodaSupportSpec with ForAllTestContaine
override def jdbcPassword = container.password
}

object MySQLJodaSupportSpec {
val mySQLDockerImageName = "mysql:5.7.41"
}

class MySQLJodaSupportSpec extends TestContainerSpec {
override val container = MySQLContainer(
configurationOverride = "test-mysql-conf",
mysqlImageVersion = DockerImageName.parse("mysql:5.7.41")
mysqlImageVersion = DockerImageName.parse(MySQLJodaSupportSpec.mySQLDockerImageName)
)
override def jdbcDriver = "com.mysql.jdbc.Driver"
override val driver = MySQLProfile
override val jodaSupport = MySQLJodaSupport
override val isWithoutCalender = false
}

class MySQLJodaSupportWithoutCalenderSpec extends TestContainerSpec {
override val container = MySQLContainer(mysqlImageVersion = DockerImageName.parse(MySQLJodaSupportSpec.mySQLDockerImageName))
override def jdbcDriver = "com.mysql.jdbc.Driver"
override val driver = MySQLProfile
override val jodaSupport = new GenericJodaSupport(MySQLProfile, _ => None)
override val isWithoutCalender = true
}

class PostgresJodaSupportSpec extends TestContainerSpec {
override val container = PostgreSQLContainer()
override def jdbcDriver = "org.postgresql.Driver"
override val driver = PostgresProfile
override val jodaSupport = PostgresJodaSupport
override val isWithoutCalender = false
}

0 comments on commit fb32b27

Please sign in to comment.