Search in sources :

Example 41 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class MapPredicateJsonTest method testQueryOnArrayIndex.

@Test
public void testQueryOnArrayIndex() {
    JsonObject value1 = Json.object();
    JsonObject value2 = Json.object();
    JsonObject value3 = Json.object();
    JsonArray array1 = Json.array(new int[] { 1, 2, 3, 4, 5 });
    JsonArray array2 = Json.array(new int[] { 10, 20, 30, 40, 50 });
    JsonArray array3 = Json.array(new int[] { 100, 200, 300, 400, 500 });
    value1.add("numbers", array1);
    value2.add("numbers", array2);
    value3.add("numbers", array3);
    IMap<String, JsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", value1);
    HazelcastJsonValue p2 = putJsonString(map, "two", value2);
    HazelcastJsonValue p3 = putJsonString(map, "three", value3);
    Collection<String> vals = map.keySet(Predicates.greaterEqual("numbers[1]", 20));
    assertEquals(2, vals.size());
    assertTrue(vals.contains("two"));
    assertTrue(vals.contains("three"));
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) 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 42 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class MapPredicateJsonTest method testQueryOnArray_whenAnyIsUsed.

@Test
public void testQueryOnArray_whenAnyIsUsed() {
    JsonObject value1 = Json.object();
    JsonObject value2 = Json.object();
    JsonObject value3 = Json.object();
    JsonArray array1 = Json.array(new int[] { 1, 2, 3, 4, 20 });
    JsonArray array2 = Json.array(new int[] { 10, 20, 30 });
    JsonArray array3 = Json.array(new int[] { 100, 200, 300, 400 });
    value1.add("numbers", array1);
    value2.add("numbers", array2);
    value3.add("numbers", array3);
    IMap<String, JsonValue> map = instance.getMap(randomMapName());
    putJsonString(map, "one", value1);
    HazelcastJsonValue p2 = putJsonString(map, "two", value2);
    HazelcastJsonValue p3 = putJsonString(map, "three", value3);
    Collection<JsonValue> vals = map.values(Predicates.greaterThan("numbers[any]", 20));
    assertEquals(2, vals.size());
    assertTrue(vals.contains(p2));
    assertTrue(vals.contains(p3));
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) 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 43 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class MapAggregationJsonTest method createJsonString.

private String createJsonString(String stringValue, long longValue, double doubleValue, long nestedLongValue) {
    JsonObject object = Json.object();
    JsonArray array = new JsonArray();
    array.add(Json.object().add("nestedArrayObject", Json.object().add("secondary", Json.object().add("nestedObjectLongValue", nestedLongValue))));
    object.add("nestedArray", array);
    object.add("stringValue", stringValue).add("longValue", longValue).add("doubleValue", doubleValue).add("nestedObject", Json.object().add("nestedLongValue", nestedLongValue)).add("stringValueArray", Json.array("nested0 " + stringValue, "nested1 " + stringValue));
    return object.toString();
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 44 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class JsonSchemaHelperMultiValueTest method testAnyPattern_whenNotArrayOrObject_returnsNull.

@Test
public void testAnyPattern_whenNotArrayOrObject_returnsNull() throws IOException {
    JsonObject object = Json.object().add("scalarValue", 4);
    NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(object.toString()));
    JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
    JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, splitPath("scalarValue[any]"));
    assertNull(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)

Example 45 with JsonObject

use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.

the class JsonSchemaHelperMultiValueTest method testAnyPattern_partsAfterAnyIsOmitted.

@Test
public void testAnyPattern_partsAfterAnyIsOmitted() 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].a"));
    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)

Aggregations

JsonObject (com.hazelcast.internal.json.JsonObject)151 Test (org.junit.Test)56 JsonArray (com.hazelcast.internal.json.JsonArray)41 QuickTest (com.hazelcast.test.annotation.QuickTest)38 JsonValue (com.hazelcast.internal.json.JsonValue)34 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)23 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)10 SlowTest (com.hazelcast.test.annotation.SlowTest)9 HashMap (java.util.HashMap)8 CPMember (com.hazelcast.cp.CPMember)7 ArrayList (java.util.ArrayList)7 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)6 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)5 JsonUtil.toJsonObject (com.hazelcast.internal.util.JsonUtil.toJsonObject)5 Map (java.util.Map)5 ClusterService (com.hazelcast.internal.cluster.ClusterService)4 Address (com.hazelcast.cluster.Address)3