Search in sources :

Example 6 with ParseException

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

the class JsonParser_Test method assertParseException.

private void assertParseException(int offset, String message, final String json) {
    ParseException exception = assertException(ParseException.class, new Runnable() {

        public void run() {
            parser.parse(json);
        }
    });
    assertEquals(offset, exception.getLocation().offset);
    assertThat(exception.getMessage(), startsWith(message + " at"));
}
Also used : ParseException(com.hazelcast.internal.json.ParseException)

Example 7 with ParseException

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

the class JsonParser_Test method parse_failsOnTooDeeplyNestedArray.

@Test
public void parse_failsOnTooDeeplyNestedArray() {
    JsonArray array = new JsonArray();
    for (int i = 0; i < 1001; i++) {
        array = new JsonArray().add(array);
    }
    final String input = array.toString();
    ParseException exception = assertException(ParseException.class, new RunnableEx() {

        public void run() throws IOException {
            parser.parse(input);
        }
    });
    assertEquals("Nesting too deep at 1:1002", exception.getMessage());
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) RunnableEx(com.hazelcast.internal.json.TestUtil.RunnableEx) ParseException(com.hazelcast.internal.json.ParseException) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with ParseException

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

the class JsonParser_Test method parse_handlesPositionsCorrectlyWhenInputExceedsBufferSize.

@Test
public void parse_handlesPositionsCorrectlyWhenInputExceedsBufferSize() {
    final String input = "{\n  \"a\": 23,\n  \"b\": 42,\n}";
    ParseException exception = assertException(ParseException.class, new RunnableEx() {

        public void run() throws IOException {
            parser.parse(new StringReader(input), 3);
        }
    });
    assertEquals(new Location(24, 4, 1), exception.getLocation());
}
Also used : StringReader(java.io.StringReader) RunnableEx(com.hazelcast.internal.json.TestUtil.RunnableEx) ParseException(com.hazelcast.internal.json.ParseException) IOException(java.io.IOException) Location(com.hazelcast.internal.json.Location) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ParseException (com.hazelcast.internal.json.ParseException)8 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 RunnableEx (com.hazelcast.internal.json.TestUtil.RunnableEx)5 IOException (java.io.IOException)5 JsonObject (com.hazelcast.internal.json.JsonObject)3 JsonArray (com.hazelcast.internal.json.JsonArray)2 StringReader (java.io.StringReader)2 HazelcastException (com.hazelcast.core.HazelcastException)1 JsonReducedValueParser (com.hazelcast.internal.json.JsonReducedValueParser)1 JsonValue (com.hazelcast.internal.json.JsonValue)1 Location (com.hazelcast.internal.json.Location)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1