use of org.folio.cql2pgjson.exception.FieldException in project raml-module-builder by folio-org.
the class PostgresClientIT method getCQLWrapperNoFacets.
@Test
public void getCQLWrapperNoFacets(TestContext context) throws FieldException {
final String tableDefiniton = "id UUID PRIMARY KEY , jsonb JSONB NOT NULL, distinct_test_field TEXT";
createTableWithPoLines(context, MOCK_POLINES_TABLE, tableDefiniton);
List<FacetField> facets = null;
CQL2PgJSON cql2pgJson = new CQL2PgJSON("jsonb");
{
CQLWrapper cqlWrapper = new CQLWrapper(cql2pgJson, "cql.allRecords=1");
Async async = context.async();
postgresClient.get(MOCK_POLINES_TABLE, Object.class, "*", cqlWrapper, true, true, facets, null, handler -> {
context.assertTrue(handler.succeeded());
ResultInfo resultInfo = handler.result().getResultInfo();
context.assertEquals(6, resultInfo.getTotalRecords());
List<Facet> retFacets = resultInfo.getFacets();
context.assertEquals(0, retFacets.size());
async.complete();
});
async.awaitSuccess();
}
String distinctOn = "jsonb->>'order_format'";
List<FacetField> emptyFacets = new ArrayList<FacetField>();
{
CQLWrapper cqlWrapper = new CQLWrapper(cql2pgJson, "cql.allRecords=1");
Async async = context.async();
postgresClient.get(MOCK_POLINES_TABLE, Object.class, "*", cqlWrapper, true, true, emptyFacets, distinctOn, handler -> {
context.assertTrue(handler.succeeded());
ResultInfo resultInfo = handler.result().getResultInfo();
context.assertEquals(4, resultInfo.getTotalRecords());
List<Facet> retFacets = resultInfo.getFacets();
context.assertEquals(0, retFacets.size());
async.complete();
});
async.awaitSuccess();
}
{
Async async = context.async();
CQLWrapper cqlWrapperNull = null;
postgresClient.get(MOCK_POLINES_TABLE, Object.class, "*", cqlWrapperNull, true, true, facets, null, handler -> {
context.assertTrue(handler.succeeded());
ResultInfo resultInfo = handler.result().getResultInfo();
context.assertEquals(6, resultInfo.getTotalRecords());
List<Facet> retFacets = resultInfo.getFacets();
context.assertEquals(0, retFacets.size());
async.complete();
});
async.awaitSuccess();
}
{
Async async = context.async();
CQLWrapper cqlWrapperNull = null;
postgresClient.get(MOCK_POLINES_TABLE, Object.class, "*", cqlWrapperNull, true, true, facets, distinctOn, handler -> {
context.assertTrue(handler.succeeded());
ResultInfo resultInfo = handler.result().getResultInfo();
context.assertEquals(4, resultInfo.getTotalRecords());
try {
List<Object> objs = handler.result().getResults();
context.assertEquals(4, objs.size());
} catch (Exception ex) {
context.fail(ex);
}
List<Facet> retFacets = resultInfo.getFacets();
context.assertEquals(0, retFacets.size());
async.complete();
});
async.awaitSuccess();
}
}
use of org.folio.cql2pgjson.exception.FieldException in project raml-module-builder by folio-org.
the class PostgresClientIT method testCacheResultCQLSyntaxError.
@Test
public void testCacheResultCQLSyntaxError(TestContext context) throws FieldException {
final String tableDefiniton = "id UUID PRIMARY KEY , jsonb JSONB NOT NULL, distinct_test_field TEXT";
createTableWithPoLines(context, MOCK_POLINES_TABLE, tableDefiniton);
CQLWrapper wrapper = new CQLWrapper(new CQL2PgJSON("jsonb"), "edition=");
postgresClient.persistentlyCacheResult("cache_polines", MOCK_POLINES_TABLE, wrapper, context.asyncAssertFailure(res -> context.assertTrue(res.getMessage().contains("expected index or term"))));
}
use of org.folio.cql2pgjson.exception.FieldException in project raml-module-builder by folio-org.
the class PostgresClientIT method deleteByCriterion.
private void deleteByCriterion(TestContext context, String key) throws FieldException {
Async async = context.async();
Criterion criterion = new Criterion();
criterion.addCriterion(new Criteria().addField("'key'").setOperation("=").setVal(key));
PostgresClient postgresClient = insertXAndSingleQuotePojo(context, new JsonArray().add(randomUuid()).add(randomUuid()));
postgresClient.delete(FOO, criterion, context.asyncAssertSuccess(delete -> {
context.assertEquals(1, delete.rowCount(), "number of records deleted");
postgresClient.selectSingle("SELECT count(*) FROM " + FOO, context.asyncAssertSuccess(select -> {
context.assertEquals(1, select.getInteger(0), "remaining records");
async.complete();
}));
}));
async.await(5000);
}
use of org.folio.cql2pgjson.exception.FieldException in project raml-module-builder by folio-org.
the class PostgresClientIT method deleteByCqlWrapper.
private void deleteByCqlWrapper(TestContext context, String key) throws FieldException {
Async async = context.async();
CQL2PgJSON cql2pgJson = new CQL2PgJSON("jsonb");
CQLWrapper cqlWrapper = new CQLWrapper(cql2pgJson, "key==" + key);
PostgresClient postgresClient = insertXAndSingleQuotePojo(context, new JsonArray().add(randomUuid()).add(randomUuid()));
postgresClient.delete(FOO, cqlWrapper, context.asyncAssertSuccess(delete -> {
context.assertEquals(1, delete.rowCount(), "number of records deleted");
postgresClient.selectSingle("SELECT count(*) FROM " + FOO, context.asyncAssertSuccess(select -> {
context.assertEquals(1, select.getInteger(0), "remaining records");
async.complete();
}));
}));
async.await(5000);
}
use of org.folio.cql2pgjson.exception.FieldException in project raml-module-builder by folio-org.
the class PostgresClientIT method getCQLWrapperJsonbField.
@Test
public void getCQLWrapperJsonbField(TestContext context) throws FieldException {
final String tableDefiniton = "id UUID PRIMARY KEY , jsonb JSONB NOT NULL, distinct_test_field TEXT";
List<FacetField> facets = null;
createTableWithPoLines(context, MOCK_POLINES_TABLE, tableDefiniton);
CQL2PgJSON cql2pgJson = new CQL2PgJSON(MOCK_POLINES_TABLE + ".jsonb");
{
CQLWrapper cqlWrapper = new CQLWrapper(cql2pgJson, "cql.allRecords=1");
Async async = context.async();
postgresClient.get(MOCK_POLINES_TABLE, Object.class, "jsonb", cqlWrapper, true, true, facets, null, handler -> {
context.assertTrue(handler.succeeded());
ResultInfo resultInfo = handler.result().getResultInfo();
context.assertEquals(6, resultInfo.getTotalRecords());
async.complete();
});
async.awaitSuccess();
}
String distinctOn = "jsonb->>'order_format'";
{
CQLWrapper cqlWrapper = new CQLWrapper(cql2pgJson, "cql.allRecords=1");
Async async = context.async();
postgresClient.get(MOCK_POLINES_TABLE, Object.class, "jsonb", cqlWrapper, true, true, facets, distinctOn, handler -> {
context.assertTrue(handler.succeeded());
ResultInfo resultInfo = handler.result().getResultInfo();
context.assertEquals(4, resultInfo.getTotalRecords());
async.complete();
});
async.awaitSuccess();
}
}
Aggregations