Search in sources :

Example 76 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class MapPredicateJsonTest method testNestedQueryInArray_whenAnyMatchesMultipleNestedObjects_shouldReturnAllMatching.

@Test
public void testNestedQueryInArray_whenAnyMatchesMultipleNestedObjects_shouldReturnAllMatching() {
    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);
    IMap<String, HazelcastJsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", obj1);
    HazelcastJsonValue p2 = putJsonString(map, "two", obj2);
    HazelcastJsonValue p3 = putJsonString(map, "three", obj3);
    Collection<HazelcastJsonValue> vals = map.values(Predicates.greaterThan("arr[any].age", 40));
    assertEquals(2, vals.size());
    assertTrue(vals.contains(p1));
    assertTrue(vals.contains(p3));
}
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)

Example 77 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class MapPredicateJsonTest method putWithJsonStringKey.

private static String putWithJsonStringKey(Map map, JsonValue key, String value) {
    HazelcastJsonValue lazyKey = new HazelcastJsonValue(key.toString());
    map.put(lazyKey, value);
    return value;
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue)

Example 78 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class MapPredicateJsonTest method putWithJsonStringKey.

private static String putWithJsonStringKey(Map map, String name, int age, boolean onDuty) {
    String f = createNameAgeOnDuty(name, age, onDuty).toString();
    HazelcastJsonValue json = new HazelcastJsonValue(f);
    map.put(json, name);
    return name;
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue)

Example 79 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class JsonSchemaHelperMultiValueTest method testAnyPattern.

@Test
public void testAnyPattern() throws IOException {
    JsonObject object = Json.object().add("array", 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("array[any]"));
    assertEquals(1, pattern.depth());
    assertEquals(0, pattern.get(0));
    assertTrue(pattern.hasAny());
}
Also used : NavigableJsonInputAdapter(com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter) 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)

Example 80 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class JsonSchemaHelperTest method testQueryToNonTerminalValueCreatesPattern.

@Test
public void testQueryToNonTerminalValueCreatesPattern() throws IOException {
    JsonObject object = Json.object().add("a", Json.object().add("x", 1).add("y", 2)).add("b", false);
    NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(object.toString()));
    JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
    JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, splitPath("a"));
    assertEquals(new JsonPattern(asList(0)), pattern);
}
Also used : NavigableJsonInputAdapter(com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter) 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