Skip to content

Test for Date, Datetime, Timestamp #42

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

Merged
merged 2 commits into from
Sep 18, 2014
Merged
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
2 changes: 1 addition & 1 deletion src/main/resources/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Joern Bernhardt",

// Optional fields
//"developers": ["Other Dev 1", "Other Dev 2"],
"developers": ["Max Stemplinger"],
"keywords": ["db", "database", "mysql", "postgresql"],
"homepage": "https://github.com/vert-x/mod-mysql-postgresql"
}
36 changes: 32 additions & 4 deletions src/test/scala/io/vertx/asyncsql/test/BaseSqlTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait BaseSqlTests {

protected def isMysql: Boolean = false

private def failedTest: PartialFunction[Throwable, Unit] = {
protected def failedTest: PartialFunction[Throwable, Unit] = {
case ex: Throwable =>
logger.warn("failed in test", ex)
fail("test failed. see warning above")
Expand Down Expand Up @@ -49,10 +49,10 @@ trait BaseSqlTests {
(msg._1, msg._2)
}

private def sendOk(json: JsonObject): Future[(Message[JsonObject], JsonObject)] =
protected def sendOk(json: JsonObject): Future[(Message[JsonObject], JsonObject)] =
sendWithTimeout(json) map checkOkay(json)

private def sendFail(json: JsonObject): Future[(Message[JsonObject], JsonObject)] =
protected def sendFail(json: JsonObject): Future[(Message[JsonObject], JsonObject)] =
sendWithTimeout(json) map checkError(json)

private def replyOk(msg: Message[JsonObject], json: JsonObject): Future[(Message[JsonObject], JsonObject)] =
Expand Down Expand Up @@ -439,4 +439,32 @@ trait BaseSqlTests {
testComplete()
}) recover failedTest
}
}

@Test
def dateTest(): Unit = (for {
_ <- setupTableTest()
(msg, insertReply) <- sendOk(raw("INSERT INTO some_test (name, wedding_date) VALUES ('tester', '2015-04-04');"))
(msg, reply) <- sendOk(prepared("SELECT wedding_date FROM some_test WHERE name=?", Json.arr("tester")))
} yield {
val receivedFields = reply.getArray("fields")
assertEquals(Json.arr("wedding_date"), receivedFields)
assertEquals("2015-04-04", reply.getArray("results").get[JsonArray](0).get[String](0))
testComplete()
}) recover failedTest

@Test
def timestampTest(): Unit = (for {
(m, r) <- sendOk(raw("DROP TABLE IF EXISTS date_test"))
(msg, r2) <- sendOk(raw(createDateTable("timestamp")))
(msg, insertReply) <- sendOk(raw("INSERT INTO date_test (test_date) VALUES ('2015-04-04T10:04:00.000');"))
(msg, reply) <- sendOk(raw("SELECT test_date FROM date_test"))
} yield {
val receivedFields = reply.getArray("fields")
assertEquals(Json.arr("test_date"), receivedFields)
logger.info("date is: " + reply.getArray("results").get[JsonArray](0).get[String](0))
assertEquals("2015-04-04T10:04:00.000", reply.getArray("results").get[JsonArray](0).get[String](0))
testComplete()
}) recover failedTest

}

9 changes: 8 additions & 1 deletion src/test/scala/io/vertx/asyncsql/test/SqlTestVerticle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class SqlTestVerticle extends TestVerticle with BaseVertxIntegrationTes
val p = Promise[Unit]
container.deployModule(System.getProperty("vertx.modulename"), getConfig(), 1, { deploymentID: AsyncResult[String] =>
if (deploymentID.failed()) {
logger.info(deploymentID.cause())
logger.info(s"Deployment failed, cause: ${deploymentID.cause()}")
p.failure(deploymentID.cause())
}
assertTrue("deploymentID should not be null", deploymentID.succeeded())
Expand Down Expand Up @@ -67,6 +67,13 @@ abstract class SqlTestVerticle extends TestVerticle with BaseVertxIntegrationTes
reply
}

protected def createDateTable(dateDataType :String) = s"""
| CREATE TABLE date_test (
| id SERIAL,
| test_date $dateDataType
| );
""".stripMargin

protected def createTableStatement(tableName: String) = """
DROP TABLE IF EXISTS """ + tableName + """;
CREATE TABLE """ + tableName + """ (
Expand Down
30 changes: 27 additions & 3 deletions src/test/scala/io/vertx/asyncsql/test/mysql/MySqlTest.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.vertx.asyncsql.test.mysql

import org.vertx.scala.core.json.Json
import io.vertx.asyncsql.test.{BaseSqlTests, SqlTestVerticle}
import org.junit.Test
import org.vertx.scala.core.json._
import org.vertx.testtools.VertxAssert._

class MySqlTest extends SqlTestVerticle with BaseSqlTests {

Expand All @@ -14,6 +16,14 @@ class MySqlTest extends SqlTestVerticle with BaseSqlTests {

override def getConfig = config

override def createDateTable(dateDataType: String) = s"""
| CREATE TABLE date_test (
| id INT NOT NULL AUTO_INCREMENT,
| test_date $dateDataType,
| PRIMARY KEY(id)
| );
""".stripMargin

override def createTableStatement(tableName: String) = """
CREATE TABLE """ + tableName + """ (
id INT NOT NULL AUTO_INCREMENT,
Expand All @@ -24,7 +34,21 @@ CREATE TABLE """ + tableName + """ (
money FLOAT,
wedding_date DATE,
PRIMARY KEY (id)
);
"""
);"""

@Test
def datetimeTest(): Unit =
(for {
(m, r) <- sendOk(raw("DROP TABLE IF EXISTS date_test"))
(msg, r2) <- sendOk(raw(createDateTable("datetime")))
(msg, insertReply) <- sendOk(raw("INSERT INTO date_test (test_date) VALUES ('2015-04-04');"))
(msg, reply) <- sendOk(raw("SELECT test_date FROM date_test"))
} yield {
val receivedFields = reply.getArray("fields")
assertEquals(Json.arr("test_date"), receivedFields)
logger.info("date is: " + reply.getArray("results").get[JsonArray](0).get[String](0));
assertEquals("2015-04-04T00:00:00.000", reply.getArray("results").get[JsonArray](0).get[String](0))
testComplete()
}) recover failedTest

}