use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class AbstractJsonSchemaTest method validateJsonLiteral.
protected void validateJsonLiteral(JsonValue expectedValue, String originalString, JsonPattern expectedPattern, JsonSchemaNode description, NavigableJsonInputAdapter input, String path) throws IOException {
JsonPathCursor pathArray = splitPath(path);
JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, pathArray);
String failureString = String.format("Path ( %s ) failed on ( %s )", path, originalString);
assertEquals(failureString, expectedPattern, pattern);
pathArray.reset();
input.reset();
JsonValue foundValue = JsonSchemaHelper.findValueWithPattern(input, description, pattern, pathArray);
assertEquals(failureString, expectedValue, foundValue);
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class AbstractJsonSchemaTest method validateJsonArray.
private void validateJsonArray(String originalString, JsonPattern patternPrefix, JsonArray jsonArray, JsonSchemaNode description, NavigableJsonInputAdapter input, String pathPrefix) throws IOException {
for (int i = 0; i < jsonArray.size(); i++) {
JsonValue item = jsonArray.get(i);
JsonPattern copy = new JsonPattern(patternPrefix);
copy.add(i);
String nextPath = "[" + i + "]";
if (pathPrefix != null) {
nextPath = pathPrefix + nextPath;
}
if (item.isObject()) {
validateJsonObject(originalString, copy, item.asObject(), description, input, nextPath);
} else if (item.isArray()) {
validateJsonArray(originalString, copy, item.asArray(), description, input, nextPath);
} else {
validateJsonLiteral(item, originalString, copy, description, input, nextPath);
}
}
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class JsonSchemaHelperNullTest method test_givenWrongPattern_returnNull.
private void test_givenWrongPattern_returnNull(String jsonString, String patternPath, String queryPath) throws IOException {
NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(jsonString));
JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, splitPath(patternPath));
JsonValue found = JsonSchemaHelper.findValueWithPattern(input, description, pattern, splitPath(queryPath));
assertNull(found);
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testQueryOnStringProperty.
@Test
public void testQueryOnStringProperty() {
IMap<String, JsonValue> map = instance.getMap(randomMapName());
HazelcastJsonValue p1 = putJsonString(map, "a", 30, true);
HazelcastJsonValue p2 = putJsonString(map, "b", 20, false);
HazelcastJsonValue p3 = putJsonString(map, "c", 10, true);
Collection<JsonValue> vals = map.values(Predicates.greaterEqual("name", "b"));
assertEquals(2, vals.size());
assertTrue(vals.contains(p2));
assertTrue(vals.contains(p3));
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testArrayInNestedQuery_whenOneArrayIsShort_shouldNotThrow.
@Test
public void testArrayInNestedQuery_whenOneArrayIsShort_shouldNotThrow() {
JsonObject object1 = Json.object();
JsonObject nested1 = Json.object();
JsonObject object2 = Json.object();
JsonObject nested2 = Json.object();
JsonArray array1 = Json.array(new int[] { 1, 2, 3, 4, 5, 6 });
JsonArray array2 = Json.array(new int[] { 10 });
nested1.add("arr", array1);
nested2.add("arr", array2);
object1.add("inner", nested1);
object2.add("inner", nested2);
IMap<String, JsonValue> map = instance.getMap(randomMapName());
HazelcastJsonValue p1 = putJsonString(map, "one", object1);
putJsonString(map, "two", object2);
Collection<JsonValue> vals = map.values(Predicates.lessEqual("inner.arr[2]", 20));
assertEquals(1, vals.size());
assertTrue(vals.contains(p1));
}
Aggregations