Search in sources :

Example 6 with NavigableJsonInputAdapter

use of com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter 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 7 with NavigableJsonInputAdapter

use of com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter 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 8 with NavigableJsonInputAdapter

use of com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter in project hazelcast by hazelcast.

the class AbstractJsonSchemaTest method validateJson.

protected void validateJson(String originalString, JsonValue jsonValue) throws IOException {
    NavigableJsonInputAdapter input = toAdapter(new HazelcastJsonValue(originalString));
    JsonSchemaNode description = JsonSchemaHelper.createSchema(createParserFromInput(input));
    if (jsonValue.isObject()) {
        validateJsonObject(originalString, new JsonPattern(), jsonValue.asObject(), description, input, null);
    } else if (jsonValue.isArray()) {
        validateJsonArray(originalString, new JsonPattern(), jsonValue.asArray(), description, input, null);
    } else {
        // shoult not reach here
        fail();
    }
}
Also used : NavigableJsonInputAdapter(com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue)

Example 9 with NavigableJsonInputAdapter

use of com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter 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 10 with NavigableJsonInputAdapter

use of com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter in project hazelcast by hazelcast.

the class JsonSchemaHelperMultiValueTest method testAnyPattern.

@Test
public void testAnyPattern() 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]"));
    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)

Aggregations

HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)12 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 JsonObject (com.hazelcast.internal.json.JsonObject)6 JsonArray (com.hazelcast.internal.json.JsonArray)2 JsonValue (com.hazelcast.internal.json.JsonValue)2