Search in sources :

Example 71 with JsonValue

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

the class MapPredicateJsonTest method testQueryOnNumberPropertyOnKey_whenSomeEntriesDoNotHaveTheField_shouldNotFail.

@Test
public void testQueryOnNumberPropertyOnKey_whenSomeEntriesDoNotHaveTheField_shouldNotFail() {
    IMap<JsonValue, String> 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);
    String p1 = putWithJsonStringKey(map, val1, "a");
    String p2 = putWithJsonStringKey(map, val2, "b");
    String p3 = putWithJsonStringKey(map, val3, "c");
    Collection<String> vals = map.values(Predicates.equal("__key.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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 72 with JsonValue

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

use of com.hazelcast.internal.json.JsonValue 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)

Example 74 with JsonValue

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

the class AbstractJsonSchemaTest method validateJsonObject.

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

Example 75 with JsonValue

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

the class AbstractJsonSchemaTest method testPaths.

protected void testPaths(WriterConfig config) throws IOException {
    for (JsonValue value : TestJsonValues.LIST) {
        String jsonString = value.toString(config);
        validateJson(jsonString, value);
    }
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue)

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