use of org.folio.rest.persist.helpers.Poline 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();
}
}
Aggregations