Search in sources :

Example 1 with BuildCQL

use of org.folio.rest.tools.client.BuildCQL in project raml-module-builder by folio-org.

the class BuildCQLTest method check.

@Test
public void check() {
    JsonObject j = new JsonObject();
    JsonArray j22 = new JsonArray();
    JsonArray j33 = new JsonArray();
    j.put("arr", j22);
    j.put("arr2", j33);
    j22.add("librarian3");
    j22.add("librarian2");
    JsonObject j44 = new JsonObject();
    j44.put("o", new JsonObject("{\"bbb\":\"aaa\"}"));
    j33.add(j44);
    Response r = new Response();
    r.setBody(j);
    String g = new BuildCQL(r, "arr2[0]", "group").buildCQL();
    assertEquals("?query=" + PercentCodec.encode("group=={\"o\":{\"bbb\":\"aaa\"}}"), g);
    g = new BuildCQL(r, "arr", "group").buildCQL();
    assertEquals("?query=" + PercentCodec.encode("group==[\"librarian3\",\"librarian2\"]"), g);
    g = new BuildCQL(r, "arr[0]", "group").buildCQL();
    assertEquals("?query=" + PercentCodec.encode("group==librarian3"), g);
    g = new BuildCQL(r, "arr[*]", "group").buildCQL();
    assertEquals("?query=" + PercentCodec.encode("group==librarian3 or group==librarian2"), g);
    g = new BuildCQL(r, "arr[*]", "group", "query1").buildCQL();
    assertEquals("?query1=" + PercentCodec.encode("group==librarian3 or group==librarian2"), g);
    g = new BuildCQL(r, "arr[*]", "group", "query1", false, "and").buildCQL();
    assertEquals("&query1=" + PercentCodec.encode("group==librarian3 and group==librarian2"), g);
    // build cql by requesting values from a non existent field in the json, should be an emptry string ""
    g = new BuildCQL(r, "arr3", "group").buildCQL();
    assertEquals("", g);
    g = new BuildCQL(r, "arr[*]", "group", "query1", false, "and", "=").buildCQL();
    assertEquals("&query1=" + PercentCodec.encode("group=librarian3 and group=librarian2"), g);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.rest.tools.client.Response) BuildCQL(org.folio.rest.tools.client.BuildCQL) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 BuildCQL (org.folio.rest.tools.client.BuildCQL)1 Response (org.folio.rest.tools.client.Response)1 Test (org.junit.Test)1