Skip to content

Commit

Permalink
replaced all usage of Date and Timestamp with LocalDate and LocalDate…
Browse files Browse the repository at this point in the history
…Time object
  • Loading branch information
sunitparekh committed Mar 4, 2018
1 parent 26e4cb8 commit d0ba76c
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.4</version>
<version>42.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.github.dataanon.utils.DataAnonTestLogHandler
import io.kotlintest.matchers.*
import io.kotlintest.specs.FunSpec
import java.sql.Date
import java.time.LocalDate
import java.util.logging.Level

class SpecialFeaturesIntegrationTest : FunSpec() {
Expand All @@ -18,8 +19,8 @@ class SpecialFeaturesIntegrationTest : FunSpec() {
test("support to select specific records from table using where clause") {
val sourceDbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val sourceTable = MoviesTable(sourceDbConfig)
.insert(1, "Movie 1", "Drama", Date(1999, 5, 2))
.insert(2, "Movie 2", "Action", Date(2005, 5, 2))
.insert(1, "Movie 1", "Drama", LocalDate.of(1999, 5, 2))
.insert(2, "Movie 2", "Action", LocalDate.of(2005, 5, 2))

val destDbConfig = DbConfig("jdbc:h2:mem:movies_dest", "", "")
val destTable = MoviesTable(destDbConfig)
Expand All @@ -39,7 +40,7 @@ class SpecialFeaturesIntegrationTest : FunSpec() {
val anonymizedRecord = records[0]
anonymizedRecord["MOVIE_ID"] shouldBe 1
anonymizedRecord["TITLE"] shouldBe "MY VALUE"
anonymizedRecord["RELEASE_DATE"] shouldBe Date(1999, 5, 2)
anonymizedRecord["RELEASE_DATE"] shouldBe LocalDate.of(1999, 5, 2)
anonymizedRecord["GENRE"].toString() should match("[a-zA-Z]+")

sourceTable.close()
Expand All @@ -49,7 +50,7 @@ class SpecialFeaturesIntegrationTest : FunSpec() {
test("testing progress bar") {
val dbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val moviesTable = MoviesTable(dbConfig)
.insert(1, "Movie 1", "Drama", Date(1999, 5, 2))
.insert(1, "Movie 1", "Drama", LocalDate.of(1999, 5, 2))

Blacklist(dbConfig)
.table("MOVIES", listOf("MOVIE_ID")) {
Expand All @@ -64,7 +65,7 @@ class SpecialFeaturesIntegrationTest : FunSpec() {
val anonymizedRecord = records[0]
anonymizedRecord["MOVIE_ID"] shouldBe 1
anonymizedRecord["TITLE"] shouldBe "MY VALUE"
anonymizedRecord["RELEASE_DATE"] shouldBe Date(1999, 5, 2)
anonymizedRecord["RELEASE_DATE"] shouldBe LocalDate.of(1999, 5, 2)
anonymizedRecord["GENRE"].toString() should match("[a-zA-Z]+")

moviesTable.close()
Expand All @@ -73,8 +74,8 @@ class SpecialFeaturesIntegrationTest : FunSpec() {
test("limit records for testing") {
val sourceDbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val sourceTable = MoviesTable(sourceDbConfig)
.insert(1, "Movie 1", "Drama", Date(1999, 5, 2))
.insert(2, "Movie 2", "Action", Date(2005, 5, 2))
.insert(1, "Movie 1", "Drama", LocalDate.of(1999, 5, 2))
.insert(2, "Movie 2", "Action", LocalDate.of(2005, 5, 2))

val destDbConfig = DbConfig("jdbc:h2:mem:movies_dest", "", "")
val destTable = MoviesTable(destDbConfig)
Expand All @@ -94,7 +95,7 @@ class SpecialFeaturesIntegrationTest : FunSpec() {
val anonymizedRecord = records[0]
anonymizedRecord["MOVIE_ID"] shouldBe 1
anonymizedRecord["TITLE"] shouldBe "MY VALUE"
anonymizedRecord["RELEASE_DATE"] shouldBe Date(1999, 5, 2)
anonymizedRecord["RELEASE_DATE"] shouldBe LocalDate.of(1999, 5, 2)
anonymizedRecord["GENRE"].toString() should match("[a-zA-Z]+")

sourceTable.close()
Expand All @@ -106,8 +107,8 @@ class SpecialFeaturesIntegrationTest : FunSpec() {

val sourceDbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val sourceTable = MoviesTable(sourceDbConfig)
.insert(1, "Movie 1", "Drama", Date(1999, 5, 2))
.insert(2, "Movie 2", "Action", Date(2005, 5, 2))
.insert(1, "Movie 1", "Drama", LocalDate.of(1999, 5, 2))
.insert(2, "Movie 2", "Action", LocalDate.of(2005, 5, 2))

val destDbConfig = DbConfig("jdbc:h2:mem:movies_new", "", "")

Expand Down Expand Up @@ -156,12 +157,12 @@ class SpecialFeaturesIntegrationTest : FunSpec() {

val sourceDbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val sourceTable = MoviesTable(sourceDbConfig)
.insert(1, "Movie 1", "Really Long Genre To be fail 1", Date(1999, 5, 2))
.insert(2, "Movie 2", "Really Long Genre To be fail 2", Date(2005, 5, 2))
.insert(3, "Movie 3", "Action", Date(2005, 5, 2))
.insert(4, "Movie 4", "Really Long Genre To be fail 3", Date(2005, 5, 2))
.insert(5, "Movie 5", "Really Long Genre To be fail 4", Date(2005, 5, 2))
.insert(6, "Movie 6", "Action", Date(2005, 5, 2))
.insert(1, "Movie 1", "Really Long Genre To be fail 1", LocalDate.of(1999, 5, 2))
.insert(2, "Movie 2", "Really Long Genre To be fail 2", LocalDate.of(2005, 5, 2))
.insert(3, "Movie 3", "Action", LocalDate.of(2005, 5, 2))
.insert(4, "Movie 4", "Really Long Genre To be fail 3", LocalDate.of(2005, 5, 2))
.insert(5, "Movie 5", "Really Long Genre To be fail 4", LocalDate.of(2005, 5, 2))
.insert(6, "Movie 6", "Action", LocalDate.of(2005, 5, 2))

val destDbConfig = DbConfig("jdbc:h2:mem:movies_dest", "", "")
val destTable = MoviesTableHavingGenreSize10(destDbConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.github.dataanon.strategy.string.RandomAlphabetic
import com.github.dataanon.support.MoviesTable
import io.kotlintest.specs.FunSpec
import java.sql.Date
import java.time.LocalDate
import java.util.regex.Pattern
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand All @@ -30,12 +31,12 @@ class BlacklistMoviesNullValueIntegrationTest : FunSpec() {
assertEquals(2, records.size)
assertEquals(1, records[0]["MOVIE_ID"])
assertEquals("MY VALUE", records[0]["TITLE"])
assertEquals(Date(1999, 5, 2), records[0]["RELEASE_DATE"])
assertEquals(LocalDate.of(1999, 5, 2), records[0]["RELEASE_DATE"])
assertEquals(null, records[0]["GENRE"])

assertEquals(2, records[1]["MOVIE_ID"])
assertEquals("MY VALUE", records[1]["TITLE"])
assertEquals(Date(2005, 5, 2), records[1]["RELEASE_DATE"])
assertEquals(LocalDate.of(2005, 5, 2), records[1]["RELEASE_DATE"])
assertTrue(alphabeticPattern.matcher(records[1]["GENRE"].toString()).matches())

moviesTable.close()
Expand All @@ -57,12 +58,12 @@ class BlacklistMoviesNullValueIntegrationTest : FunSpec() {
assertEquals(2, records.size)
assertEquals(1, records[0]["MOVIE_ID"])
assertEquals("MY VALUE", records[0]["TITLE"])
assertEquals(Date(1999, 5, 2), records[0]["RELEASE_DATE"])
assertEquals(LocalDate.of(1999, 5, 2), records[0]["RELEASE_DATE"])
assertEquals(null, records[0]["GENRE"])

assertEquals(2, records[1]["MOVIE_ID"])
assertEquals("MY VALUE", records[1]["TITLE"])
assertEquals(Date(2005, 5, 2), records[1]["RELEASE_DATE"])
assertEquals(LocalDate.of(2005, 5, 2), records[1]["RELEASE_DATE"])
assertTrue(alphabeticPattern.matcher(records[1]["GENRE"].toString()).matches())

moviesTable.close()
Expand All @@ -72,8 +73,8 @@ class BlacklistMoviesNullValueIntegrationTest : FunSpec() {
private fun prepareDataWith2Movies(): Pair<DbConfig, MoviesTable> {
val dbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val moviesTable = MoviesTable(dbConfig)
.insert(1, "Movie 1", null, Date(1999, 5, 2))
.insert(2, "Movie 2", "Action", Date(2005, 5, 2))
.insert(1, "Movie 1", null, LocalDate.of(1999, 5, 2))
.insert(2, "Movie 2", "Action", LocalDate.of(2005, 5, 2))

return Pair(dbConfig, moviesTable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.dataanon.strategy.string.FixedString
import com.github.dataanon.support.MoviesTable
import io.kotlintest.specs.FunSpec
import java.sql.Date
import java.time.LocalDate
import java.util.regex.Pattern
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand All @@ -30,7 +31,7 @@ class BlacklistMoviesSimplePrimaryKeyIntegrationTest : FunSpec() {
assertEquals(1,records.size)
assertEquals(1, records[0]["MOVIE_ID"])
assertEquals("MY VALUE", records[0]["TITLE"])
assertEquals(Date(1999, 5, 2), records[0]["RELEASE_DATE"])
assertEquals(LocalDate.of(1999, 5, 2), records[0]["RELEASE_DATE"])
assertTrue(alphabeticPattern.matcher(records[0]["GENRE"].toString()).matches())

moviesTable.close()
Expand All @@ -52,11 +53,11 @@ class BlacklistMoviesSimplePrimaryKeyIntegrationTest : FunSpec() {
assertEquals(1, records[0]["MOVIE_ID"])
assertEquals("MY VALUE", records[0]["TITLE"])
assertTrue(alphabeticPattern.matcher(records[0]["GENRE"].toString()).matches())
assertEquals(Date(1999, 5, 2), records[0]["RELEASE_DATE"])
assertEquals(LocalDate.of(1999, 5, 2), records[0]["RELEASE_DATE"])
assertEquals(2, records[1]["MOVIE_ID"])
assertEquals("MY VALUE", records[1]["TITLE"])
assertTrue(alphabeticPattern.matcher(records[1]["GENRE"].toString()).matches())
assertEquals(Date(2005, 5, 2), records[1]["RELEASE_DATE"])
assertEquals(LocalDate.of(2005, 5, 2), records[1]["RELEASE_DATE"])

moviesTable.close()
}
Expand All @@ -65,15 +66,15 @@ class BlacklistMoviesSimplePrimaryKeyIntegrationTest : FunSpec() {
private fun prepareDataWith2Movies(): Pair<DbConfig, MoviesTable> {
val dbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val moviesTable = MoviesTable(dbConfig)
.insert(1, "Movie 1", "Drama", Date(1999, 5, 2))
.insert(2, "Movie 2", "Action", Date(2005, 5, 2))
.insert(1, "Movie 1", "Drama", LocalDate.of(1999, 5, 2))
.insert(2, "Movie 2", "Action", LocalDate.of(2005, 5, 2))
return Pair(dbConfig, moviesTable)
}

private fun prepareDataWithSingleMovie(): Pair<DbConfig, MoviesTable> {
val dbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val moviesTable = MoviesTable(dbConfig)
.insert(1, "Movie 1", "Drama", Date(1999, 5, 2))
.insert(1, "Movie 1", "Drama", LocalDate.of(1999, 5, 2))
return Pair(dbConfig, moviesTable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import com.github.dataanon.support.RatingsTable
import io.kotlintest.specs.FunSpec
import java.sql.Date
import java.sql.Timestamp
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.util.regex.Pattern
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand Down Expand Up @@ -37,18 +40,18 @@ class BlacklistMultipleTableIntegrationTest : FunSpec() {
assertEquals(1, moviesRecords.size)
assertEquals(1, moviesRecords[0]["MOVIE_ID"])
assertEquals("MY VALUE", moviesRecords[0]["TITLE"])
assertEquals(Date(1999, 5, 2), moviesRecords[0]["RELEASE_DATE"])
assertEquals(LocalDate.of(1999, 5, 2), moviesRecords[0]["RELEASE_DATE"])
assertTrue(pattern.matcher(moviesRecords[0]["GENRE"].toString()).matches())

assertEquals(2,ratingRecords.size)
assertEquals(1, ratingRecords[0]["MOVIE_ID"])
assertEquals(1, ratingRecords[0]["USER_ID"])
assertEquals(3, ratingRecords[0]["RATING"])
assertEquals(Timestamp(1509701304), ratingRecords[0]["CREATED_AT"])
assertEquals(LocalDateTime.ofEpochSecond(1509701304,0, ZoneOffset.UTC), ratingRecords[0]["CREATED_AT"])
assertEquals(1, ratingRecords[1]["MOVIE_ID"])
assertEquals(2, ratingRecords[1]["USER_ID"])
assertEquals(3, ratingRecords[1]["RATING"])
assertEquals(Timestamp(1509701310), ratingRecords[1]["CREATED_AT"])
assertEquals(LocalDateTime.ofEpochSecond(1509701310,0, ZoneOffset.UTC), ratingRecords[1]["CREATED_AT"])

closeResources(moviesTable, ratingsTable)
}
Expand All @@ -61,10 +64,10 @@ class BlacklistMultipleTableIntegrationTest : FunSpec() {

private fun prepareData(): Triple<DbConfig, MoviesTable, RatingsTable> {
val dbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val moviesTable = MoviesTable(dbConfig).insert(1, "Movie 1", "Drama", Date(1999, 5, 2))
val moviesTable = MoviesTable(dbConfig).insert(1, "Movie 1", "Drama", LocalDate.of(1999, 5, 2))
val ratingsTable = RatingsTable(dbConfig)
.insert(1, 1, 4, Timestamp(1509701304))
.insert(1, 2, 5, Timestamp(1509701310))
.insert(1, 1, 4, LocalDateTime.ofEpochSecond(1509701304,0, ZoneOffset.UTC))
.insert(1, 2, 5, LocalDateTime.ofEpochSecond(1509701310,0, ZoneOffset.UTC))
return Triple(dbConfig, moviesTable, ratingsTable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.github.dataanon.strategy.number.FixedInt
import com.github.dataanon.support.RatingsTable
import io.kotlintest.specs.FunSpec
import java.sql.Timestamp
import java.time.LocalDateTime
import java.time.ZoneOffset
import kotlin.test.assertEquals

class BlacklistRatingsCompositePrimaryKeyIntegrationTest : FunSpec() {
Expand All @@ -25,12 +27,12 @@ class BlacklistRatingsCompositePrimaryKeyIntegrationTest : FunSpec() {
assertEquals(1, records[0]["MOVIE_ID"])
assertEquals(1, records[0]["USER_ID"])
assertEquals(3, records[0]["RATING"])
assertEquals(Timestamp(1509701304), records[0]["CREATED_AT"])
assertEquals(LocalDateTime.ofEpochSecond(1509701304,0, ZoneOffset.UTC), records[0]["CREATED_AT"])

assertEquals(1, records[1]["MOVIE_ID"])
assertEquals(2, records[1]["USER_ID"])
assertEquals(3, records[1]["RATING"])
assertEquals(Timestamp(1509701310), records[1]["CREATED_AT"])
assertEquals(LocalDateTime.ofEpochSecond(1509701310,0, ZoneOffset.UTC), records[1]["CREATED_AT"])

ratingsTable.close()
}
Expand All @@ -39,8 +41,8 @@ class BlacklistRatingsCompositePrimaryKeyIntegrationTest : FunSpec() {
private fun prepareData(): Pair<DbConfig, RatingsTable> {
val dbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val ratingsTable = RatingsTable(dbConfig)
.insert(1, 1, 4, Timestamp(1509701304))
.insert(1, 2, 5, Timestamp(1509701310))
.insert(1, 1, 4, LocalDateTime.ofEpochSecond(1509701304,0, ZoneOffset.UTC))
.insert(1, 2, 5, LocalDateTime.ofEpochSecond(1509701310,0, ZoneOffset.UTC))
return Pair(dbConfig, ratingsTable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.dataanon.strategy.string.FixedString
import com.github.dataanon.support.MoviesTable
import io.kotlintest.specs.FunSpec
import java.sql.Date
import java.time.LocalDate
import java.util.regex.Pattern
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand Down Expand Up @@ -35,11 +36,11 @@ class WhitelistMoviesSimplePrimaryKeyIntegrationTest : FunSpec() {
assertEquals(1, records[0]["MOVIE_ID"])
assertEquals("MY VALUE", records[0]["TITLE"])
assertTrue(alphabeticPattern.matcher(records[0]["GENRE"].toString()).matches())
assertEquals(Date(1999, 5, 2), records[0]["RELEASE_DATE"])
assertEquals(LocalDate.of(1999, 5, 2), records[0]["RELEASE_DATE"])
assertEquals(2, records[1]["MOVIE_ID"])
assertEquals("MY VALUE", records[1]["TITLE"])
assertTrue(alphabeticPattern.matcher(records[1]["GENRE"].toString()).matches())
assertEquals(Date(2005, 5, 2), records[1]["RELEASE_DATE"])
assertEquals(LocalDate.of(2005, 5, 2), records[1]["RELEASE_DATE"])

closeResources(sourceTable, destTable)
}
Expand All @@ -53,8 +54,8 @@ class WhitelistMoviesSimplePrimaryKeyIntegrationTest : FunSpec() {
private fun prepareData(): Pair<DbConfig, MoviesTable> {
val sourceDbConfig = DbConfig("jdbc:h2:mem:movies_source", "", "")
val sourceTable = MoviesTable(sourceDbConfig)
.insert(1, "Movie 1", "Drama", Date(1999, 5, 2))
.insert(2, "Movie 2", "Action", Date(2005, 5, 2))
.insert(1, "Movie 1", "Drama", LocalDate.of(1999, 5, 2))
.insert(2, "Movie 2", "Action", LocalDate.of(2005, 5, 2))
return Pair(sourceDbConfig, sourceTable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.dataanon.support.MoviesTable
import io.kotlintest.matchers.shouldBe
import io.kotlintest.specs.FunSpec
import java.sql.Date
import java.time.LocalDate

class TableReaderIntegrationTest : FunSpec() {

Expand Down Expand Up @@ -42,11 +43,11 @@ class TableReaderIntegrationTest : FunSpec() {
private fun prepareDataWith5Movies(): Pair<DbConfig, MoviesTable> {
val dbConfig = DbConfig("jdbc:h2:mem:movies", "", "")
val moviesTable = MoviesTable(dbConfig)
.insert(1, "Movie 1", "Drama", Date(1999, 5, 2))
.insert(2, "Movie 2", "Action", Date(2005, 5, 2))
.insert(3, "Movie 3", "Comedy", Date(2005, 5, 2))
.insert(4, "Movie 4", "Horror", Date(2005, 5, 2))
.insert(5, "Movie 5", "Fiction", Date(2005, 5, 2))
.insert(1, "Movie 1", "Drama", LocalDate.of(1999, 5, 2))
.insert(2, "Movie 2", "Action", LocalDate.of(2005, 5, 2))
.insert(3, "Movie 3", "Comedy", LocalDate.of(2005, 5, 2))
.insert(4, "Movie 4", "Horror", LocalDate.of(2005, 5, 2))
.insert(5, "Movie 5", "Fiction", LocalDate.of(2005, 5, 2))
return Pair(dbConfig, moviesTable)
}
}
8 changes: 5 additions & 3 deletions src/test/kotlin/com/github/dataanon/support/MoviesTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.github.dataanon.support
import com.github.dataanon.model.DbConfig
import java.sql.Connection
import java.sql.Date
import java.sql.JDBCType
import java.time.LocalDate

class MoviesTable(dbConfig: DbConfig) {
private val conn: Connection = dbConfig.connection()
Expand All @@ -18,12 +20,12 @@ class MoviesTable(dbConfig: DbConfig) {
conn.createStatement().executeUpdate(createMovieTable)
}

fun insert(movieId: Int, title: String, genre: String?, releaseDate: Date): MoviesTable {
fun insert(movieId: Int, title: String, genre: String?, releaseDate: LocalDate): MoviesTable {
val stmt = conn.prepareStatement("INSERT INTO MOVIES(MOVIE_ID,TITLE,GENRE,RELEASE_DATE) VALUES(?,?,?,?)")
stmt.setInt(1, movieId)
stmt.setString(2, title)
stmt.setString(3, genre)
stmt.setDate(4, releaseDate)
stmt.setDate(4, Date.valueOf(releaseDate))
stmt.executeUpdate()
stmt.close()
return this
Expand All @@ -37,7 +39,7 @@ class MoviesTable(dbConfig: DbConfig) {
record["MOVIE_ID"] = rs.getInt("MOVIE_ID")
record["TITLE"] = rs.getString("TITLE")
record["GENRE"] = rs.getString("GENRE")
record["RELEASE_DATE"] = rs.getDate("RELEASE_DATE")
record["RELEASE_DATE"] = rs.getDate("RELEASE_DATE").toLocalDate()
records.add(record)
}
rs.close()
Expand Down
Loading

0 comments on commit d0ba76c

Please sign in to comment.