Search in sources :

Example 61 with JsonObject

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

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

the class TimedMemberStateTest method testSerialization.

@Test
public void testSerialization() {
    JsonObject serialized = timedMemberState.toJson();
    TimedMemberState deserialized = new TimedMemberState();
    deserialized.fromJson(serialized);
    assertNotNull(deserialized);
    assertEquals("ClusterName", deserialized.getClusterName());
    assertEquals(1827731, deserialized.getTime());
    assertNotNull(deserialized.getMemberState());
    assertTrue(deserialized.isSslEnabled());
    assertTrue(deserialized.isLite());
    assertFalse(deserialized.isScriptingEnabled());
    assertFalse(deserialized.isConsoleEnabled());
    assertTrue(deserialized.isMcDataAccessEnabled());
    assertNotNull(deserialized.toString());
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 63 with JsonObject

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

the class PrettyPrint_Test method testIndentWithSpaces_nestedObject.

@Test
public void testIndentWithSpaces_nestedObject() throws IOException {
    new JsonObject().add("a", 23).add("b", new JsonObject().add("c", 42)).writeTo(output, indentWithSpaces(2));
    assertEquals("{\n  \"a\": 23,\n  \"b\": {\n    \"c\": 42\n  }\n}", output.toString());
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 64 with JsonObject

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

the class PrettyPrint_Test method testIndentWithSpaces_emptyObject.

@Test
public void testIndentWithSpaces_emptyObject() throws IOException {
    new JsonObject().writeTo(output, indentWithSpaces(2));
    assertEquals("{\n  \n}", output.toString());
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 65 with JsonObject

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

the class PrettyPrint_Test method testSingleLine_nestedObject.

@Test
public void testSingleLine_nestedObject() throws IOException {
    new JsonObject().add("a", 23).add("b", new JsonObject().add("c", 42)).writeTo(output, singleLine());
    assertEquals("{\"a\": 23, \"b\": {\"c\": 42}}", output.toString());
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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