Search in sources :

Example 46 with JsonObject

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

the class JsonSchemaHelperTest method testQuerySimpleNestedQuery.

@Test
public void testQuerySimpleNestedQuery() throws IOException {
    JsonObject object = Json.object().add("inner", Json.object().add("a", 3).add("b", 5));
    NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(object.toString()));
    JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
    JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, splitPath("inner.b"));
    assertEquals(new JsonPattern(asList(0, 1)), 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 47 with JsonObject

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

the class JsonSchemaHelperTest method testOneLevelObject.

@Test
public void testOneLevelObject() throws IOException {
    JsonObject object = Json.object().add("a", true).add("b", false).add("c", Json.NULL).add("d", 4).add("e", "asd");
    NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(object.toString()));
    JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
    JsonPattern pattern = JsonSchemaHelper.createPattern(input, description, splitPath("b"));
    assertEquals(new JsonPattern(asList(1)), pattern);
    JsonValue found = JsonSchemaHelper.findValueWithPattern(input, description, pattern, splitPath("b"));
    assertEquals(Json.FALSE, 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) JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with JsonObject

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

the class MapPredicateJsonTest method testNestedQueryInArray.

@Test
public void testNestedQueryInArray() {
    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);
    HazelcastJsonValue p1 = new HazelcastJsonValue(obj1.toString());
    HazelcastJsonValue p2 = new HazelcastJsonValue(obj2.toString());
    HazelcastJsonValue p3 = new HazelcastJsonValue(obj3.toString());
    IMap<String, HazelcastJsonValue> map = instance.getMap(randomMapName());
    map.put("one", p1);
    map.put("two", p2);
    map.put("three", p3);
    Collection<HazelcastJsonValue> vals = map.values(Predicates.greaterEqual("arr[2].age", 20));
    assertEquals(2, vals.size());
    assertTrue(vals.contains(p1));
    assertTrue(vals.contains(p2));
}
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 49 with JsonObject

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

Example 50 with JsonObject

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

the class WanRESTTest method assertUuid.

private void assertUuid(String jsonResult, UUID expectedUuid) {
    JsonObject result = Json.parse(jsonResult).asObject();
    assertEquals(expectedUuid.toString(), result.getString("uuid", null));
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject)

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