@@ -16,9 +16,7 @@ import org.vertx.scala.core.Vertx
16
16
import io .vertx .helpers .VertxScalaHelpers
17
17
import org .vertx .scala .core .json ._
18
18
19
- abstract class SqlTestVerticle extends org.vertx.testtools.TestVerticle with VertxExecutionContext with VertxScalaHelpers {
20
-
21
- lazy val log = container.logger()
19
+ abstract class SqlTestVerticle extends org.vertx.testtools.TestVerticle with BaseVertxIntegrationTest with VertxScalaHelpers {
22
20
23
21
override def start () = {
24
22
initialize()
@@ -44,40 +42,6 @@ abstract class SqlTestVerticle extends org.vertx.testtools.TestVerticle with Ver
44
42
45
43
def getConfig (): JsonObject = Json .emptyObj()
46
44
47
- val address : String
48
-
49
- protected def asyncTest [X ](fn : => Future [X ]) = {
50
- fn recover {
51
- case x =>
52
- log.error(" async fail in test code!" , x)
53
- fail(" Something failed asynchronously: " + x.getClass() + x.getMessage())
54
- } map { _ =>
55
- testComplete()
56
- }
57
- }
58
-
59
- protected def ebSend (q : JsonObject ): Future [JsonObject ] = {
60
- val p = Promise [JsonObject ]
61
- log.info(" sending " + q.encode() + " to " + address)
62
- Vertx (vertx).eventBus.send(address, q) { reply : Message [JsonObject ] =>
63
- log.info(" got a reply: " + reply.body.encode())
64
- p.success(reply.body)
65
- }
66
- p.future
67
- }
68
-
69
- protected def expectOk (q : JsonObject ): Future [JsonObject ] = ebSend(q) map { reply =>
70
- assertEquals(" ok" , reply.getString(" status" ))
71
- reply
72
- }
73
-
74
- protected def expectError (q : JsonObject , errorId : Option [String ] = None , errorMessage : Option [String ] = None ): Future [JsonObject ] = ebSend(q) map { reply =>
75
- assertEquals(" error" , reply.getString(" status" ))
76
- errorId.map(assertEquals(_, reply.getString(" id" )))
77
- errorMessage.map(assertEquals(_, reply.getString(" message" )))
78
- reply
79
- }
80
-
81
45
protected def raw (q : String ) = Json .obj(" action" -> " raw" , " command" -> q)
82
46
83
47
protected def insert (table : String , fields : JsonArray , values : JsonArray ) =
@@ -87,7 +51,16 @@ abstract class SqlTestVerticle extends org.vertx.testtools.TestVerticle with Ver
87
51
88
52
protected def prepared (statement : String , values : JsonArray ) = Json .obj(" action" -> " prepared" , " statement" -> statement, " values" -> values)
89
53
90
- protected def createTable (tableName : String ) = expectOk(raw("""
54
+ protected def createTable (tableName : String ) = expectOk(raw(createTableStatement(tableName))) map { reply =>
55
+ assertEquals(0 , reply.getNumber(" rows" ))
56
+ reply
57
+ }
58
+
59
+ protected def dropTable (tableName : String ) = expectOk(raw(" DROP TABLE " + tableName + " ;" )) map { reply =>
60
+ reply
61
+ }
62
+
63
+ protected def createTableStatement (tableName : String ) = """
91
64
CREATE TABLE """ + tableName + """ (
92
65
id SERIAL,
93
66
name VARCHAR(255),
@@ -97,13 +70,5 @@ CREATE TABLE """ + tableName + """ (
97
70
money FLOAT,
98
71
wedding_date DATE
99
72
);
100
- """ )) map { reply =>
101
- assertEquals(0 , reply.getNumber(" rows" ))
102
- reply
103
- }
104
-
105
- protected def dropTable (tableName : String ) = expectOk(raw(" DROP TABLE " + tableName + " ;" )) map { reply =>
106
- reply
107
- }
108
-
73
+ """
109
74
}
0 commit comments