PostgresQuery { Future<RowSet<Row>> query(String sql, Tuple tuple) { return getCon().compose(x -> x.preparedQuery(sql).execute(tuple)).onFailure(x -> close()); } PostgresQuery(PostgresHandle pg);   }
@Test public void testQueryWithParams(TestContext context) { Async async = context.async(); JsonObject obj = new JsonObject(); FakeHandle h = new FakeHandle(vertx, obj); PostgresQuery q = new PostgresQuery(h); q.query("select", Tuple.of("id")).onComplete(res -> { context.assertTrue(res.failed()); context.assertEquals("fake query failed", res.cause().getMessage()); async.complete(); }); }
@Test public void testQuery(TestContext context) { Async async = context.async(); JsonObject obj = new JsonObject(); FakeHandle h = new FakeHandle(vertx, obj); PostgresQuery q = new PostgresQuery(h); q.close(); q.query("select").onComplete(res -> { context.assertTrue(res.failed()); context.assertEquals("fake query failed", res.cause().getMessage()); async.complete(); }); }
@Test public void testGetConnectionFailed1(TestContext context) { Async async = context.async(); JsonObject obj = new JsonObject(); obj.put("postgres_port", "0"); FakeHandle h = new FakeHandle(vertx, obj); PostgresQuery q = new PostgresQuery(h); q.query("select").onComplete(res -> { context.assertTrue(res.failed()); context.assertEquals("getConnection failed", res.cause().getMessage()); async.complete(); }); }
@Test public void testGetConnectionFailed2(TestContext context) { Async async = context.async(); JsonObject obj = new JsonObject(); obj.put("postgres_port", "0"); FakeHandle h = new FakeHandle(vertx, obj); PostgresQuery q = new PostgresQuery(h); q.query("select", Tuple.of("id")).onComplete(res -> { context.assertTrue(res.failed()); context.assertEquals("getConnection failed", res.cause().getMessage()); async.complete(); }); }