Search in sources :

Example 56 with HazelcastJsonValue

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());
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 57 with HazelcastJsonValue

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));
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 58 with HazelcastJsonValue

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);
    }
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 59 with HazelcastJsonValue

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));
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 60 with HazelcastJsonValue

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));
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)99 Test (org.junit.Test)80 QuickTest (com.hazelcast.test.annotation.QuickTest)74 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)67 JsonObject (com.hazelcast.internal.json.JsonObject)25 JsonValue (com.hazelcast.internal.json.JsonValue)19 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)12 JsonArray (com.hazelcast.internal.json.JsonArray)9 IMap (com.hazelcast.map.IMap)9 Map (java.util.Map)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 Data (com.hazelcast.internal.serialization.Data)5 JsonSchemaNode (com.hazelcast.json.internal.JsonSchemaNode)3 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 CompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord)2 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)2 StringUtil.bytesToString (com.hazelcast.internal.util.StringUtil.bytesToString)2 ExpressionValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionValue)2