use of org.folio.cql2pgjson.CQL2PgJSON in project raml-module-builder by folio-org.
the class PostgresClientIT method getCQLWrapperWithFacets.
@Test
public void getCQLWrapperWithFacets(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);
CQL2PgJSON cql2pgJson = new CQL2PgJSON("jsonb");
List<FacetField> facets = List.of(new FacetField("jsonb->>'edition'"));
{
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(1, retFacets.size());
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, "*", cqlWrapper, true, true, facets, distinctOn, handler -> {
context.assertTrue(handler.succeeded());
ResultInfo resultInfo = handler.result().getResultInfo();
context.assertEquals(4, resultInfo.getTotalRecords());
List<Facet> retFacets = resultInfo.getFacets();
context.assertEquals(1, retFacets.size());
async.complete();
});
async.awaitSuccess();
}
{
CQLWrapper cqlWrapper = new CQLWrapper(cql2pgJson, "order_format==Other");
Async async = context.async();
postgresClient.get(MOCK_POLINES_TABLE, Object.class, "*", cqlWrapper, true, true, facets, distinctOn, context.asyncAssertSuccess(res -> {
ResultInfo resultInfo = res.getResultInfo();
context.assertEquals(1, resultInfo.getTotalRecords());
List<Object> objs = res.getResults();
ObjectMapper mapper = new ObjectMapper();
List<Facet> retFacets = resultInfo.getFacets();
context.assertEquals(1, retFacets.size());
context.assertEquals("edition", retFacets.get(0).getType());
context.assertEquals(1, retFacets.get(0).getFacetValues().get(0).getCount());
context.assertEquals("First edition", retFacets.get(0).getFacetValues().get(0).getValue().toString());
context.assertEquals(1, objs.size());
try {
context.assertEquals("70fb4e66-cdf1-11e8-a8d5-f2801f1b9fd1", new JsonObject(mapper.writeValueAsString(objs.get(0))).getString("id"));
} catch (JsonProcessingException e) {
context.fail(e);
}
async.complete();
}));
async.awaitSuccess();
}
{
CQLWrapper cqlWrapper = new CQLWrapper(cql2pgJson, "order_format==Other");
Async async = context.async();
postgresClient.get(MOCK_POLINES_TABLE, Poline.class, "*", cqlWrapper, true, true, facets, distinctOn, context.asyncAssertSuccess(res -> {
ResultInfo resultInfo = res.getResultInfo();
context.assertEquals(1, resultInfo.getTotalRecords());
List<Poline> objs = res.getResults();
List<Facet> retFacets = resultInfo.getFacets();
context.assertEquals(1, retFacets.size());
context.assertEquals("edition", retFacets.get(0).getType());
context.assertEquals(1, retFacets.get(0).getFacetValues().get(0).getCount());
context.assertEquals("First edition", retFacets.get(0).getFacetValues().get(0).getValue().toString());
context.assertEquals(1, objs.size());
context.assertEquals("70fb4e66-cdf1-11e8-a8d5-f2801f1b9fd1", objs.get(0).getId());
async.complete();
}));
async.awaitSuccess();
}
}
use of org.folio.cql2pgjson.CQL2PgJSON in project raml-module-builder by folio-org.
the class PostgresClientIT method assertCQLWrapper.
private void assertCQLWrapper(TestContext context, Function<CQLWrapper, Future<Results<StringPojo>>> function) {
try {
JsonArray ids = new JsonArray().add(randomUuid()).add(randomUuid());
insertXAndSingleQuotePojo(context, ids);
CQLWrapper cqlWrapper = new CQLWrapper(new CQL2PgJSON("jsonb"), "key = x");
function.apply(cqlWrapper).onComplete(context.asyncAssertSuccess(res -> {
assertThat(res.getResults().size(), is(1));
assertThat(res.getResults().get(0).getId(), is(ids.getString(0)));
}));
} catch (FieldException e) {
context.fail(e);
}
}
use of org.folio.cql2pgjson.CQL2PgJSON in project raml-module-builder by folio-org.
the class PostgresClientIT method streamGetWithFacetsZeroHits.
@Test
public void streamGetWithFacetsZeroHits(TestContext context) throws FieldException {
AtomicInteger objectCount = new AtomicInteger();
Async async = context.async();
List<FacetField> facets = new ArrayList<FacetField>();
facets.add(new FacetField("jsonb->>'edition'"));
facets.add(new FacetField("jsonb->>'title'"));
createTableWithPoLines(context);
CQLWrapper wrapper = new CQLWrapper(new CQL2PgJSON("jsonb"), "edition=Millenium edition");
postgresClient.streamGet(MOCK_POLINES_TABLE, Object.class, "jsonb", wrapper, true, null, facets, context.asyncAssertSuccess(sr -> {
ResultInfo resultInfo = sr.resultInfo();
context.assertEquals(0, resultInfo.getTotalRecords());
context.assertEquals(0, resultInfo.getFacets().size());
sr.handler(streamHandler -> objectCount.incrementAndGet());
sr.endHandler(x -> {
context.assertEquals(0, objectCount.get());
async.complete();
});
}));
async.awaitSuccess();
}
use of org.folio.cql2pgjson.CQL2PgJSON in project raml-module-builder by folio-org.
the class PostgresClientIT method updateWithCqlWrapper.
@Test
public void updateWithCqlWrapper(TestContext context) throws Exception {
CQLWrapper cqlWrapper = new CQLWrapper(new CQL2PgJSON("jsonb"), "key=x");
createFoo(context).save(FOO, xPojo, context.asyncAssertSuccess(save -> {
postgresClient.update(FOO, singleQuotePojo, cqlWrapper, true, context.asyncAssertSuccess(rowSet -> {
assertThat(rowSet.rowCount(), is(1));
postgresClient.update(FOO, xPojo, cqlWrapper, true, context.asyncAssertSuccess(rowSet2 -> {
assertThat(rowSet2.rowCount(), is(0));
}));
}));
}));
}
use of org.folio.cql2pgjson.CQL2PgJSON in project raml-module-builder by folio-org.
the class PostgresClientIT method streamGetWithFilterZeroHits.
@Test
public void streamGetWithFilterZeroHits(TestContext context) throws FieldException {
AtomicInteger objectCount = new AtomicInteger();
Async async = context.async();
createTableWithPoLines(context);
CQLWrapper wrapper = new CQLWrapper(new CQL2PgJSON("jsonb"), "edition=Millenium edition");
postgresClient.streamGet(MOCK_POLINES_TABLE, Object.class, "jsonb", wrapper, false, null, context.asyncAssertSuccess(sr -> {
context.assertEquals(0, sr.resultInfo().getTotalRecords());
sr.handler(streamHandler -> objectCount.incrementAndGet());
sr.endHandler(x -> {
context.assertEquals(0, objectCount.get());
async.complete();
});
}));
async.awaitSuccess();
}
Aggregations