Search in sources :

Example 1 with RunnableEx

use of com.hazelcast.internal.json.TestUtil.RunnableEx in project hazelcast by hazelcast.

the class JsonParser_Test method parse_failsOnTooDeeplyNestedObject.

@Test
public void parse_failsOnTooDeeplyNestedObject() {
    JsonObject object = new JsonObject();
    for (int i = 0; i < 1001; i++) {
        object = new JsonObject().add("foo", object);
    }
    final String input = object.toString();
    ParseException exception = assertException(ParseException.class, new RunnableEx() {

        public void run() throws IOException {
            parser.parse(input);
        }
    });
    assertEquals("Nesting too deep at 1:7002", exception.getMessage());
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) 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 2 with RunnableEx

use of com.hazelcast.internal.json.TestUtil.RunnableEx in project hazelcast by hazelcast.

the class JsonParser_Test method parse_failsOnTooDeeplyNestedMixedObject.

@Test
public void parse_failsOnTooDeeplyNestedMixedObject() {
    JsonValue value = new JsonObject();
    for (int i = 0; i < 1001; i++) {
        value = i % 2 == 0 ? new JsonArray().add(value) : new JsonObject().add("foo", value);
    }
    final String input = value.toString();
    ParseException exception = assertException(ParseException.class, new RunnableEx() {

        public void run() throws IOException {
            parser.parse(input);
        }
    });
    assertEquals("Nesting too deep at 1:4002", exception.getMessage());
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) 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 3 with RunnableEx

use of com.hazelcast.internal.json.TestUtil.RunnableEx in project hazelcast by hazelcast.

the class JsonValue_Test method writeTo_failsWithNullWriter.

@Test
public void writeTo_failsWithNullWriter() {
    final JsonValue value = new JsonObject();
    assertException(NullPointerException.class, "writer is null", new RunnableEx() {

        public void run() throws IOException {
            value.writeTo(null, WriterConfig.MINIMAL);
        }
    });
}
Also used : RunnableEx(com.hazelcast.internal.json.TestUtil.RunnableEx) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with RunnableEx

use of com.hazelcast.internal.json.TestUtil.RunnableEx in project hazelcast by hazelcast.

the class JsonParser_Test method parse_reader_rejectsEmpty.

@Test
public void parse_reader_rejectsEmpty() {
    ParseException exception = assertException(ParseException.class, new RunnableEx() {

        public void run() throws IOException {
            parser.parse(new StringReader(""));
        }
    });
    assertEquals(0, exception.getLocation().offset);
    assertThat(exception.getMessage(), startsWith("Unexpected end of input at"));
}
Also used : StringReader(java.io.StringReader) 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 5 with RunnableEx

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

Aggregations

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