Search in sources :

Example 16 with JsonArray

use of com.hazelcast.internal.json.JsonArray 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 17 with JsonArray

use of com.hazelcast.internal.json.JsonArray 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 18 with JsonArray

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

the class JsonSchemaHelperMultiValueTest method testAnyPattern__whenFirstItem_partsAfterAnyIsOmitted.

@Test
public void testAnyPattern__whenFirstItem_partsAfterAnyIsOmitted() 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].abc.de"));
    assertEquals(0, pattern.depth());
    assertTrue(pattern.hasAny());
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) NavigableJsonInputAdapter(com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with JsonArray

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

Example 20 with JsonArray

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

the class MapPredicateJsonTest method testSkipsNestedObjectsInAnyQuery.

@Test
public void testSkipsNestedObjectsInAnyQuery() {
    JsonObject value1 = Json.object();
    JsonObject value2 = Json.object();
    JsonObject value3 = Json.object();
    JsonObject innerObject = Json.object().add("s1", 1001).add("s2", 1002);
    JsonArray array1 = Json.array();
    array1.add(1).add(2).add(innerObject).add(3).add(4).add(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, HazelcastJsonValue> map = instance.getMap(randomMapName());
    putJsonString(map, "one", value1);
    HazelcastJsonValue p2 = putJsonString(map, "two", value2);
    HazelcastJsonValue p3 = putJsonString(map, "three", value3);
    Collection<HazelcastJsonValue> 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) 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

JsonArray (com.hazelcast.internal.json.JsonArray)74 JsonObject (com.hazelcast.internal.json.JsonObject)42 Test (org.junit.Test)39 QuickTest (com.hazelcast.test.annotation.QuickTest)31 JsonValue (com.hazelcast.internal.json.JsonValue)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 CPMember (com.hazelcast.cp.CPMember)7 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 Address (com.hazelcast.cluster.Address)3 JetException (com.hazelcast.jet.JetException)3 InputStreamReader (java.io.InputStreamReader)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Request (org.elasticsearch.client.Request)3