use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class JsonSchemaHelperMultiValueTest method testAnyPattern_whenFirstItem.
@Test
public void testAnyPattern_whenFirstItem() throws IOException {
JsonArray object = Json.array().add(1).add(2).add(3);
NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(object.toString()));
JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, splitPath("[any]"));
assertEquals(0, pattern.depth());
assertTrue(pattern.hasAny());
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class JsonSchemaHelperTest method testQuerySimpleNestedQuery.
@Test
public void testQuerySimpleNestedQuery() throws IOException {
JsonObject object = Json.object().add("inner", Json.object().add("a", 3).add("b", 5));
NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(object.toString()));
JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, splitPath("inner.b"));
assertEquals(new JsonPattern(asList(0, 1)), pattern);
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class JsonSchemaHelperTest method testOneLevelObject.
@Test
public void testOneLevelObject() throws IOException {
JsonObject object = Json.object().add("a", true).add("b", false).add("c", Json.NULL).add("d", 4).add("e", "asd");
NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(object.toString()));
JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, splitPath("b"));
assertEquals(new JsonPattern(asList(1)), pattern);
JsonValue found = JsonSchemaHelper.findValueWithPattern(input, description, pattern, splitPath("b"));
assertEquals(Json.FALSE, found);
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testNestedQueryInArray.
@Test
public void testNestedQueryInArray() {
JsonValue array1 = Json.array();
array1.asArray().add(createNameAgeOnDuty("a", 50, false)).add(createNameAgeOnDuty("b", 30, true)).add(createNameAgeOnDuty("c", 32, true)).add(createNameAgeOnDuty("d", 17, false));
JsonValue array2 = Json.array();
array2.asArray().add(createNameAgeOnDuty("e", 10, false)).add(createNameAgeOnDuty("f", 20, true)).add(createNameAgeOnDuty("g", 30, true)).add(createNameAgeOnDuty("h", 40, false));
JsonValue array3 = Json.array();
array3.asArray().add(createNameAgeOnDuty("i", 26, false)).add(createNameAgeOnDuty("j", 24, true)).add(createNameAgeOnDuty("k", 1, true)).add(createNameAgeOnDuty("l", 90, false));
JsonObject obj1 = Json.object();
obj1.add("arr", array1);
JsonObject obj2 = Json.object();
obj2.add("arr", array2);
JsonObject obj3 = Json.object();
obj3.add("arr", array3);
HazelcastJsonValue p1 = new HazelcastJsonValue(obj1.toString());
HazelcastJsonValue p2 = new HazelcastJsonValue(obj2.toString());
HazelcastJsonValue p3 = new HazelcastJsonValue(obj3.toString());
IMap<String, HazelcastJsonValue> map = instance.getMap(randomMapName());
map.put("one", p1);
map.put("two", p2);
map.put("three", p3);
Collection<HazelcastJsonValue> vals = map.values(Predicates.greaterEqual("arr[2].age", 20));
assertEquals(2, vals.size());
assertTrue(vals.contains(p1));
assertTrue(vals.contains(p2));
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testInvalidJsonValueDoesNotAffectQueryResultForOthers_value.
@Test
public void testInvalidJsonValueDoesNotAffectQueryResultForOthers_value() {
IMap<Integer, HazelcastJsonValue> map = instance.getMap(randomMapName());
String invalidJsonString = "{ \"a: 1 }";
String validString1 = "{ \"a\": 2 }";
String validString2 = "{ \"a\": 3 }";
HazelcastJsonValue invalidJson = new HazelcastJsonValue(invalidJsonString);
HazelcastJsonValue valid1 = new HazelcastJsonValue(validString1);
HazelcastJsonValue valid2 = new HazelcastJsonValue(validString2);
map.put(1, invalidJson);
map.put(2, valid1);
map.put(3, valid2);
Collection<HazelcastJsonValue> values = map.values(Predicates.greaterThan("a", 0));
// values should contain all values except invalidJson
assertEquals(2, values.size());
assertTrue(values.contains(valid1));
assertTrue(values.contains(valid2));
}
Aggregations