Search in sources :

Example 76 with JsonValue

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

the class AbstractJsonSchemaTest method validateJsonLiteral.

protected void validateJsonLiteral(JsonValue expectedValue, String originalString, JsonPattern expectedPattern, JsonSchemaNode description, NavigableJsonInputAdapter input, String path) throws IOException {
    JsonPathCursor pathArray = splitPath(path);
    JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, pathArray);
    String failureString = String.format("Path ( %s ) failed on ( %s )", path, originalString);
    assertEquals(failureString, expectedPattern, pattern);
    pathArray.reset();
    input.reset();
    JsonValue foundValue = JsonSchemaHelper.findValueWithPattern(input, description, pattern, pathArray);
    assertEquals(failureString, expectedValue, foundValue);
}
Also used : JsonPathCursor(com.hazelcast.query.impl.getters.JsonPathCursor) JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue)

Example 77 with JsonValue

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

the class AbstractJsonSchemaTest method validateJsonArray.

private void validateJsonArray(String originalString, JsonPattern patternPrefix, JsonArray jsonArray, JsonSchemaNode description, NavigableJsonInputAdapter input, String pathPrefix) throws IOException {
    for (int i = 0; i < jsonArray.size(); i++) {
        JsonValue item = jsonArray.get(i);
        JsonPattern copy = new JsonPattern(patternPrefix);
        copy.add(i);
        String nextPath = "[" + i + "]";
        if (pathPrefix != null) {
            nextPath = pathPrefix + nextPath;
        }
        if (item.isObject()) {
            validateJsonObject(originalString, copy, item.asObject(), description, input, nextPath);
        } else if (item.isArray()) {
            validateJsonArray(originalString, copy, item.asArray(), description, input, nextPath);
        } else {
            validateJsonLiteral(item, originalString, copy, description, input, nextPath);
        }
    }
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue)

Example 78 with JsonValue

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

the class JsonSchemaHelperNullTest method test_givenWrongPattern_returnNull.

private void test_givenWrongPattern_returnNull(String jsonString, String patternPath, String queryPath) throws IOException {
    NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(jsonString));
    JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
    JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, splitPath(patternPath));
    JsonValue found = JsonSchemaHelper.findValueWithPattern(input, description, pattern, splitPath(queryPath));
    assertNull(found);
}
Also used : NavigableJsonInputAdapter(com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue)

Example 79 with JsonValue

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

the class MapPredicateJsonTest method testQueryOnStringProperty.

@Test
public void testQueryOnStringProperty() {
    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("name", "b"));
    assertEquals(2, vals.size());
    assertTrue(vals.contains(p2));
    assertTrue(vals.contains(p3));
}
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 80 with JsonValue

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

the class MapPredicateJsonTest method testArrayInNestedQuery_whenOneArrayIsShort_shouldNotThrow.

@Test
public void testArrayInNestedQuery_whenOneArrayIsShort_shouldNotThrow() {
    JsonObject object1 = Json.object();
    JsonObject nested1 = Json.object();
    JsonObject object2 = Json.object();
    JsonObject nested2 = Json.object();
    JsonArray array1 = Json.array(new int[] { 1, 2, 3, 4, 5, 6 });
    JsonArray array2 = Json.array(new int[] { 10 });
    nested1.add("arr", array1);
    nested2.add("arr", array2);
    object1.add("inner", nested1);
    object2.add("inner", nested2);
    IMap<String, JsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", object1);
    putJsonString(map, "two", object2);
    Collection<JsonValue> vals = map.values(Predicates.lessEqual("inner.arr[2]", 20));
    assertEquals(1, vals.size());
    assertTrue(vals.contains(p1));
}
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)

Aggregations

JsonValue (com.hazelcast.internal.json.JsonValue)85 Test (org.junit.Test)36 JsonObject (com.hazelcast.internal.json.JsonObject)35 QuickTest (com.hazelcast.test.annotation.QuickTest)30 JsonArray (com.hazelcast.internal.json.JsonArray)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)25 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 KubernetesApiProvider.convertToString (com.hazelcast.kubernetes.KubernetesApiProvider.convertToString)6 EndpointAddress (com.hazelcast.kubernetes.KubernetesClient.EndpointAddress)6 HashSet (java.util.HashSet)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)5 SlowTest (com.hazelcast.test.annotation.SlowTest)5 Address (com.hazelcast.cluster.Address)4 CPMember (com.hazelcast.cp.CPMember)4 IOException (java.io.IOException)4 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)3 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)3