Search in sources :

Example 6 with QueryHelper

use of org.folio.rest.persist.PostgresClient.QueryHelper in project raml-module-builder by folio-org.

the class PostgresClientTest method testProcessQuery.

@Test
public void testProcessQuery() {
    PostgresClient testClient = PostgresClient.testClient();
    List<FacetField> facets = new ArrayList<FacetField>() {

        {
            add(new FacetField("jsonb->>'biz'"));
        }
    };
    QueryHelper queryHelper = new QueryHelper("test_jsonb_pojo");
    queryHelper.selectQuery = "SELECT id, foo, bar FROM test_jsonb_pojo LIMIT 30 OFFSET 1";
    int total = 30;
    PgConnection connection = new FakeSqlConnection(Future.succeededFuture(getMockTestJsonbPojoResultSet(total)), true);
    testClient.processQuery(connection, queryHelper, total, "get", totaledResults -> testClient.processResults(totaledResults.set, totaledResults.estimatedTotal, DEFAULT_OFFSET, DEFAULT_LIMIT, TestJsonbPojo.class), reply -> {
        List<TestJsonbPojo> results = reply.result().getResults();
        assertTestJsonbPojoResults(results, total);
    });
}
Also used : QueryHelper(org.folio.rest.persist.PostgresClient.QueryHelper) ArrayList(java.util.ArrayList) PgConnection(io.vertx.pgclient.PgConnection) FacetField(org.folio.rest.persist.facets.FacetField) AESTest(org.folio.rest.security.AESTest) Test(org.junit.Test)

Example 7 with QueryHelper

use of org.folio.rest.persist.PostgresClient.QueryHelper in project raml-module-builder by folio-org.

the class PostgresClientTest method testProcessQueryException.

@Test
public void testProcessQueryException() {
    PostgresClient testClient = PostgresClient.testClient();
    QueryHelper queryHelper = new QueryHelper("test_jsonb_pojo");
    queryHelper.selectQuery = "SELECT foo";
    PgConnection connection = null;
    testClient.processQuery(connection, queryHelper, 30, "get", totaledResults -> testClient.processResults(totaledResults.set, totaledResults.estimatedTotal, DEFAULT_OFFSET, DEFAULT_LIMIT, TestJsonbPojo.class), reply -> {
        assertThat(reply.failed(), is(true));
        assertThat(reply.cause() instanceof NullPointerException, is(true));
    });
}
Also used : QueryHelper(org.folio.rest.persist.PostgresClient.QueryHelper) PgConnection(io.vertx.pgclient.PgConnection) AESTest(org.folio.rest.security.AESTest) Test(org.junit.Test)

Example 8 with QueryHelper

use of org.folio.rest.persist.PostgresClient.QueryHelper in project raml-module-builder by folio-org.

the class PostgresClientTest method testProcessQueryFails.

@Test
public void testProcessQueryFails() {
    PostgresClient testClient = PostgresClient.testClient();
    QueryHelper queryHelper = new QueryHelper("test_jsonb_pojo");
    queryHelper.selectQuery = "SELECT foo";
    PgConnection connection = new FakeSqlConnection(Future.failedFuture("Bad query"), false);
    testClient.processQuery(connection, queryHelper, 30, "get", totaledResults -> testClient.processResults(totaledResults.set, totaledResults.estimatedTotal, DEFAULT_OFFSET, DEFAULT_LIMIT, TestJsonbPojo.class), reply -> {
        assertThat(reply.failed(), is(true));
        assertThat(reply.cause().getMessage(), is("Bad query"));
    });
}
Also used : QueryHelper(org.folio.rest.persist.PostgresClient.QueryHelper) PgConnection(io.vertx.pgclient.PgConnection) AESTest(org.folio.rest.security.AESTest) Test(org.junit.Test)

Aggregations

PgConnection (io.vertx.pgclient.PgConnection)8 ArrayList (java.util.ArrayList)6 QueryHelper (org.folio.rest.persist.PostgresClient.QueryHelper)6 AsyncResult (io.vertx.core.AsyncResult)5 Future (io.vertx.core.Future)5 Handler (io.vertx.core.Handler)5 JsonObject (io.vertx.core.json.JsonObject)5 Row (io.vertx.sqlclient.Row)5 RowSet (io.vertx.sqlclient.RowSet)5 Test (org.junit.Test)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 Promise (io.vertx.core.Promise)4 Vertx (io.vertx.core.Vertx)4 JsonArray (io.vertx.core.json.JsonArray)4 PgNotification (io.vertx.pgclient.PgNotification)4 RowImpl (io.vertx.pgclient.impl.RowImpl)4 PrepareOptions (io.vertx.sqlclient.PrepareOptions)4 PreparedQuery (io.vertx.sqlclient.PreparedQuery)4 PreparedStatement (io.vertx.sqlclient.PreparedStatement)4 Query (io.vertx.sqlclient.Query)4