Search in sources :

Example 31 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class MapAggregationJsonTest method test_nested_json.

@Test
public void test_nested_json() {
    IMap<Integer, HazelcastJsonValue> map = instance.getMap(randomMapName());
    map.put(1, new HazelcastJsonValue(nestedJsonString()));
    Long sum = map.aggregate(Aggregators.longSum("list[any].secondLevelItem.thirdLevelItem"));
    assertEquals(6L, sum.longValue());
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class JsonSchemaHelperNullTest method test_givenInvalidPattern_createNullPattern.

private void test_givenInvalidPattern_createNullPattern(String jsonString, String path) throws IOException {
    NavigableJsonInputAdapter inputAdapter = toAdapter(new HazelcastJsonValue(jsonString));
    JsonSchemaNode schemaNode = JsonSchemaHelper.createSchema(createParserFromInput(inputAdapter));
    JsonPattern pattern = JsonSchemaHelper.createPattern(inputAdapter, schemaNode, splitPath(path));
    assertNull(pattern);
}
Also used : NavigableJsonInputAdapter(com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue)

Example 33 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue 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 34 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue 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)

Example 35 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue 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)

Aggregations

HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)99 Test (org.junit.Test)80 QuickTest (com.hazelcast.test.annotation.QuickTest)74 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)67 JsonObject (com.hazelcast.internal.json.JsonObject)25 JsonValue (com.hazelcast.internal.json.JsonValue)19 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)12 JsonArray (com.hazelcast.internal.json.JsonArray)9 IMap (com.hazelcast.map.IMap)9 Map (java.util.Map)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 Data (com.hazelcast.internal.serialization.Data)5 JsonSchemaNode (com.hazelcast.json.internal.JsonSchemaNode)3 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 CompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord)2 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)2 StringUtil.bytesToString (com.hazelcast.internal.util.StringUtil.bytesToString)2 ExpressionValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionValue)2