use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testNonTerminalAttributeIs_queriedWithEqualsNull_shouldNotReturn.
@Test
public void testNonTerminalAttributeIs_queriedWithEqualsNull_shouldNotReturn() {
String jsonWithNonTerminalQueryField = Json.object().add("user", Json.object().add("name", "abc").add("age", 23)).toString();
IMap<Integer, HazelcastJsonValue> map = instance.getMap(randomMapName());
map.put(1, new HazelcastJsonValue(jsonWithNonTerminalQueryField));
Collection<Integer> keys = map.keySet(Predicates.equal("user", null));
assertEquals(0, keys.size());
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testQueryOnNumberProperty.
@Test
public void testQueryOnNumberProperty() {
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("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 testJsonValueIsJustANumber.
@Test
public void testJsonValueIsJustANumber() {
IMap<Integer, HazelcastJsonValue> map = instance.getMap(randomMapName());
for (int i = 0; i < 10; i++) {
map.put(i, new HazelcastJsonValue(Json.value(i).toString()));
}
Collection<HazelcastJsonValue> vals = map.values(Predicates.greaterEqual("this", 3));
assertEquals(7, vals.size());
for (HazelcastJsonValue value : vals) {
int intValue = Json.parse(value.toString()).asInt();
assertTrue(intValue >= 3);
assertGreaterOrEquals("predicate result ", intValue, 3);
}
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testQueryOnNumberProperty_whenSomeEntriesDoNotHaveTheField_shouldNotFail.
@Test
public void testQueryOnNumberProperty_whenSomeEntriesDoNotHaveTheField_shouldNotFail() {
IMap<String, JsonValue> map = instance.getMap(randomMapName());
JsonValue val1 = createNameAgeOnDuty("a", 30, true);
val1.asObject().add("email", "a@aa.com");
JsonValue val2 = createNameAgeOnDuty("b", 20, false);
JsonValue val3 = createNameAgeOnDuty("c", 10, true);
HazelcastJsonValue p1 = putJsonString(map, "a", val1);
HazelcastJsonValue p2 = putJsonString(map, "b", val2);
HazelcastJsonValue p3 = putJsonString(map, "c", val3);
Collection<JsonValue> vals = map.values(Predicates.equal("email", "a@aa.com"));
assertEquals(1, vals.size());
assertTrue(vals.contains(p1));
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testArrayInsideArray.
@Test
public void testArrayInsideArray() {
JsonValue array1 = Json.array();
array1.asArray().add(Json.array(new int[] { 1, 2, 3, 4 })).add(Json.array(new int[] { 10, 20, 30, 40 }));
JsonObject obj1 = Json.object();
obj1.add("arr", array1);
System.out.println(obj1);
IMap<String, JsonValue> map = instance.getMap(randomMapName());
HazelcastJsonValue p1 = putJsonString(map, "one", obj1);
Collection<JsonValue> vals = map.values(Predicates.greaterEqual("arr[1][3]", 20));
assertEquals(1, vals.size());
assertTrue(vals.contains(p1));
}
Aggregations