stack = new LinkedList();
+ for (final Class i : c.getInterfaces()) {
+ stack.push(i);
+ }
+ while (!stack.isEmpty()) {
+ final Class i = stack.pop();
+ type = VALUES.get(i.getSimpleName());
+ if (type != null) {
+ return type;
+ }
+ for (final Class j : i.getInterfaces()) {
+ stack.push(j);
+ }
+ }
+ throw new IllegalArgumentException(
+ "Unsupported JSON value type: " + c.getSimpleName());
+ }
+
+ /**
+ * Returns JSON value identifier for provided value.
+ *
+ * @param value
+ * JSON value.
+ * @return JSON value identifier for provided class.
+ */
+ public static JsonValueType getType(final Object value) {
+ return value != null ? getType(value.getClass()) : Null;
+ }
+
+ /**
+ * Convert provided value to {@code String} which is part of JSON document.
+ *
+ * @param value
+ * Value be be converted to {@code String}.
+ * @return Value converted to {@code String}.
+ */
+ public static String toStringValue(final Object value) {
+ switch (getType(value)) {
+ case String:
+ return '"' + ((String) value) + '"';
+ case Integer:
+ return ((Integer) value).toString();
+ case Long:
+ return ((Long) value).toString();
+ case BigInteger:
+ return ((BigInteger) value).toString();
+ case Double:
+ return ((Double) value).toString();
+ case BigDecimal:
+ return ((BigDecimal) value).toString();
+ case Boolean:
+ return ((Boolean) value).toString();
+ case JsonValue:
+ return JsonAssert.valueToString((JsonValue) value);
+ case Null:
+ return SimpleValues.NULL;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported JSON value type: " + value.getClass().getSimpleName());
+ }
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/MergeRFCObject.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/MergeRFCObject.java
new file mode 100644
index 00000000..54b6279e
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/MergeRFCObject.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.common;
+
+import jakarta.json.Json;
+import jakarta.json.JsonArray;
+import jakarta.json.JsonObject;
+import jakarta.json.JsonValue;
+
+/*
+ * $Id$
+ */
+/**
+ * {@see RFC 7396}: JavaScript
+ * Object Notation (JSON) Merge Patch compatibility sample object.
+ * Object structure is defined in
+ * {@see RFC 7396: 3.
+ * Example}.
+ */
+public class MergeRFCObject {
+
+ // Following values define JSON object keys from RFC 7396: 3. Example
+ /** RFC 7396 sample JSON object key for {@code /title}. */
+ public static final String KEY_TITLE = "title";
+
+ /** RFC 7396 sample JSON object key for {@code /author/givenName}. */
+ public static final String KEY_GIVEN_NAME = "givenName";
+
+ /** RFC 7396 sample JSON object key for {@code /author/familyName}. */
+ public static final String KEY_FAMILY_NAME = "familyName";
+
+ /** RFC 7396 sample JSON object key for {@code /author}. */
+ public static final String KEY_AUTHOR = "author";
+
+ /** RFC 7396 sample JSON object key for {@code /tags}. */
+ public static final String KEY_TAGS = "tags";
+
+ /** RFC 7396 sample JSON object key for {@code /content}. */
+ public static final String KEY_CONTENT = "content";
+
+ /** RFC 7396 sample JSON object key for {@code /phoneNumber}. */
+ public static final String KEY_PHONE_NUMBER = "phoneNumber";
+
+ // Following values define JSON object source values from RFC 7396: 3. Example
+ /** RFC 7396 sample JSON object source value for {@code /title}. */
+ public static final String VAL_SRC_TITLE = "Goodbye!";
+
+ /** RFC 7396 sample JSON object source value for {@code /author/givenName}. */
+ public static final String VAL_SRC_GIVEN_NAME = "John";
+
+ /**
+ * RFC 7396 sample JSON object source value for {@code /author/familyName}.
+ */
+ public static final String VAL_SRC_FAMILY_NAME = "Doe";
+
+ /** RFC 7396 sample JSON object source value for {@code /author}. */
+ public static final JsonObject VAL_SRC_AUTHOR = SimpleValues
+ .createSimpleObject(new String[] { KEY_GIVEN_NAME, KEY_FAMILY_NAME },
+ new Object[] { VAL_SRC_GIVEN_NAME, VAL_SRC_FAMILY_NAME });
+
+ /** RFC 7396 sample JSON object source value for {@code /tags/0}. */
+ public static final String VAL_SRC_TAGS_0 = "example";
+
+ /** RFC 7396 sample JSON object source value for {@code /tags/1}. */
+ public static final String VAL_SRC_TAGS_1 = "sample";
+
+ /** RFC 7396 sample JSON object source value for {@code /tags}. */
+ public static final JsonArray VAL_SRC_TAGS = SimpleValues
+ .createStringArray(new String[] { VAL_SRC_TAGS_0, VAL_SRC_TAGS_1 });
+
+ /** RFC 7396 sample JSON object source value for {@code /content}. */
+ public static final String VAL_SRC_CONTENT = "This will be unchanged";
+
+ // Following values define JSON object target values from RFC 7396: 3. Example
+ /** RFC 7396 sample JSON object target value for {@code /title}. */
+ public static final String VAL_TRG_TITLE = "Hello!";
+
+ /** RFC 7396 sample JSON object target value for {@code /author}. */
+ public static final JsonObject VAL_TRG_AUTHOR = SimpleValues
+ .createSimpleObject(new String[] { KEY_GIVEN_NAME },
+ new Object[] { VAL_SRC_GIVEN_NAME });
+
+ /** RFC 7396 sample JSON object target value for {@code /phoneNumber}. */
+ public static final String VAL_TRG_PHONE_NUMBER = "+01-123-456-7890";
+
+ /** RFC 7396 sample JSON object target value for {@code /tags/0}. */
+ public static final String VAL_TRG_TAGS_0 = "example";
+
+ /** RFC 7396 sample JSON object target value for {@code /tags}. */
+ public static final JsonArray VAL_TRG_TAGS = SimpleValues
+ .createStringArray(new String[] { VAL_TRG_TAGS_0 });
+
+ // Following values define JSON object patch values from RFC 7396: 3. Example
+ /** RFC 7396 sample JSON object patch value for {@code /author/familyName}. */
+ public static final JsonValue VAL_PATCH_FAMILY_NAME = JsonValue.NULL;
+
+ /** RFC 7396 sample JSON object patch value for {@code /author}. */
+ public static final JsonObject VAL_PATCH_AUTHOR = SimpleValues
+ .createSimpleObject(new String[] { KEY_FAMILY_NAME },
+ new Object[] { VAL_PATCH_FAMILY_NAME });
+
+ /**
+ * Create {@see RFC
+ * 7396 example} source JSON object.
+ *
+ * @return Source object from example.
+ */
+ public static JsonObject createRFCSourceObject() {
+ return Json.createObjectBuilder().add(KEY_TITLE, VAL_SRC_TITLE)
+ .add(KEY_AUTHOR, VAL_SRC_AUTHOR).add(KEY_TAGS, VAL_SRC_TAGS)
+ .add(KEY_CONTENT, VAL_SRC_CONTENT).build();
+ }
+
+ /**
+ * Create {@see RFC
+ * 7396 example} target JSON object.
+ *
+ * @return Target object from example.
+ */
+ public static JsonObject createRFCTargetObject() {
+ return Json.createObjectBuilder().add(KEY_TITLE, VAL_TRG_TITLE)
+ .add(KEY_AUTHOR, VAL_TRG_AUTHOR).add(KEY_TAGS, VAL_TRG_TAGS)
+ .add(KEY_CONTENT, VAL_SRC_CONTENT)
+ .add(KEY_PHONE_NUMBER, VAL_TRG_PHONE_NUMBER).build();
+ }
+
+ /**
+ * Create {@see RFC
+ * 7396 example} patch JSON object.
+ *
+ * @return Patch object from example.
+ */
+ public static JsonObject createRFCPatchObject() {
+ return Json.createObjectBuilder().add(KEY_TITLE, VAL_TRG_TITLE)
+ .add(KEY_PHONE_NUMBER, VAL_TRG_PHONE_NUMBER)
+ .add(KEY_AUTHOR, VAL_PATCH_AUTHOR).add(KEY_TAGS, VAL_TRG_TAGS).build();
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/ObjectBuilder.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/ObjectBuilder.java
new file mode 100644
index 00000000..e31f468a
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/ObjectBuilder.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.common;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import jakarta.json.JsonObjectBuilder;
+import jakarta.json.JsonValue;
+
+// $Id$
+/**
+ * {@link JsonObjectBuilder} manipulation helper.
+ */
+public class ObjectBuilder {
+
+ /**
+ * Add {@code value} with {@code name} to provided JSON object builder.
+ *
+ * @param builder
+ * Target JSON object builder.
+ * @param name
+ * Name of value to be added.
+ * @param value
+ * Value to be added.
+ * @return JSON object builder containing new {@code value}.
+ */
+ @SuppressWarnings("UnnecessaryUnboxing")
+ public static JsonObjectBuilder add(final JsonObjectBuilder builder,
+ final String name, final Object value) {
+ switch (JsonValueType.getType(value)) {
+ case String:
+ return builder.add(name, (String) value);
+ case Integer:
+ return builder.add(name, ((Integer) value).intValue());
+ case Long:
+ return builder.add(name, ((Long) value).intValue());
+ case BigInteger:
+ return builder.add(name, ((BigInteger) value));
+ case Double:
+ return builder.add(name, ((Double) value).doubleValue());
+ case BigDecimal:
+ return builder.add(name, ((BigDecimal) value));
+ case Boolean:
+ return builder.add(name, ((Boolean) value).booleanValue());
+ case JsonValue:
+ return builder.add(name, (JsonValue) value);
+ case Null:
+ return builder.addNull(name);
+ default:
+ throw new IllegalArgumentException(
+ "Value does not match known JSON value type");
+ }
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/PointerRFCObject.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/PointerRFCObject.java
new file mode 100644
index 00000000..b648d3c0
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/PointerRFCObject.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.common;
+
+import jakarta.json.Json;
+import jakarta.json.JsonArray;
+import jakarta.json.JsonObject;
+
+/*
+ * $Id$
+ */
+/**
+ * {@see RFC 6901}: JavaScript
+ * Object Notation (JSON) Pointer compatibility sample object.
+ * Object structure is defined in
+ * {@see RFC 6901: 5.
+ * JSON String Representation}.
+ */
+public class PointerRFCObject {
+
+ // Following values define JSON object from
+ // RFC 6901: 5. JSON String Representation
+ // https://tools.ietf.org/html/rfc6901#section-5
+ /** RFC 6901 sample JSON object key for the whole document. */
+ public static final String RFC_KEY_WHOLE = "";
+
+ /** RFC 6901 sample JSON object key for 1st value. */
+ public static final String RFC_KEY1 = "foo";
+
+ /** RFC 6901 sample JSON object pointer for 1st value. */
+ public static final String RFC_PTR1 = "/foo";
+
+ /** RFC 6901 sample JSON object pointer for 1st item of 1st value. */
+ public static final String RFC_PTR1_ITEM1 = "/foo/0";
+
+ /** RFC 6901 sample JSON object pointer for 2nd item of 1st value. */
+ public static final String RFC_PTR1_ITEM2 = "/foo/1";
+
+ /** RFC 6901 sample JSON object 1st value: array 1st item. */
+ public static final String RFC_VAL1_ITEM1 = "bar";
+
+ /** RFC 6901 sample JSON object 1st value: array 2nd item. */
+ public static final String RFC_VAL1_ITEM2 = "baz";
+
+ /** RFC 6901 sample JSON object 1st value. */
+ public static final JsonArray RFC_VAL1 = SimpleValues
+ .createStringArray(RFC_VAL1_ITEM1, RFC_VAL1_ITEM2);
+
+ /** RFC 6901 sample JSON object key for 2nd value. */
+ public static final String RFC_KEY2 = "";
+
+ /** RFC 6901 sample JSON object pointer for 2nd value. */
+ public static final String RFC_PTR2 = "/";
+
+ /** RFC 6901 sample JSON object 2nd value. */
+ public static final int RFC_VAL2 = 0;
+
+ /** RFC 6901 sample JSON object key for 3rd value. */
+ public static final String RFC_KEY3 = "a/b";
+
+ /** RFC 6901 sample JSON object pointer for 3rd value. */
+ public static final String RFC_PTR3_ENC = "/a~1b";
+
+ /** RFC 6901 sample JSON object pointer for 3rd value. */
+ public static final String RFC_PTR3 = "/a/b";
+
+ /** RFC 6901 sample JSON object 3rd value. */
+ public static final int RFC_VAL3 = 1;
+
+ /** RFC 6901 sample JSON object key for 4th value. */
+ public static final String RFC_KEY4 = "c%d";
+
+ /** RFC 6901 sample JSON object pointer for 4th value. */
+ public static final String RFC_PTR4 = "/c%d";
+
+ /** RFC 6901 sample JSON object 4th value. */
+ public static final int RFC_VAL4 = 2;
+
+ /** RFC 6901 sample JSON object key for 5th value. */
+ public static final String RFC_KEY5 = "e^f";
+
+ /** RFC 6901 sample JSON object pointer for 5th value. */
+ public static final String RFC_PTR5 = "/e^f";
+
+ /** RFC 6901 sample JSON object 5th value. */
+ public static final int RFC_VAL5 = 3;
+
+ /** RFC 6901 sample JSON object key for 6th value. */
+ public static final String RFC_KEY6 = "g|h";
+
+ /** RFC 6901 sample JSON object pointer for 6th value. */
+ public static final String RFC_PTR6 = "/g|h";
+
+ /** RFC 6901 sample JSON object 6th value. */
+ public static final int RFC_VAL6 = 4;
+
+ /** RFC 6901 sample JSON object key for 7th value. */
+ public static final String RFC_KEY7 = "i\\j";
+
+ /** RFC 6901 sample JSON object pointer for 7th value. */
+ public static final String RFC_PTR7 = "/i\\j";
+
+ /** RFC 6901 sample JSON object 7th value. */
+ public static final int RFC_VAL7 = 5;
+
+ /** RFC 6901 sample JSON object key for 8th value. */
+ public static final String RFC_KEY8 = "k\"l";
+
+ /** RFC 6901 sample JSON object pointer for 8th value. */
+ public static final String RFC_PTR8 = "/k\"l";
+
+ /** RFC 6901 sample JSON object 8th value. */
+ public static final int RFC_VAL8 = 6;
+
+ /** RFC 6901 sample JSON object key for 9th value. */
+ public static final String RFC_KEY9 = " ";
+
+ /** RFC 6901 sample JSON object pointer for 9th value. */
+ public static final String RFC_PTR9 = "/ ";
+
+ /** RFC 6901 sample JSON object 9th value. */
+ public static final int RFC_VAL9 = 7;
+
+ /** RFC 6901 sample JSON object key for 10th value. */
+ public static final String RFC_KEY10 = "m~n";
+
+ /** RFC 6901 sample JSON object encoded pointer for 10th value. */
+ public static final String RFC_KEY10_ENC = "/m~0n";
+
+ /** RFC 6901 sample JSON object pointer for 10th value. */
+ public static final String RFC_PTR10 = "/m~n";
+
+ /** RFC 6901 sample JSON object 10th value. */
+ public static final int RFC_VAL10 = 8;
+
+ /** RFC 6901 sample JSON object key for 11th value. */
+ public static final String RFC_KEY11 = "o~1p";
+
+ /** RFC 6901 sample JSON object encoded pointer for 11th value. */
+ public static final String RFC_PTR11_ENC = "/o~01p";
+
+ /** RFC 6901 sample JSON object pointer for 11th value. */
+ public static final String RFC_PTR11 = "/o~1p";
+
+ /** RFC 6901 sample JSON object 11th value. */
+ public static final int RFC_VAL11 = 9;
+
+ /**
+ * Creates RFC 6901 sample JSON object.
+ * {@see RFC 6901: 5.
+ * JSON String Representation}
+ *
+ * @return RFC 6901 sample JSON object.
+ */
+ public static JsonObject createRFC6901Object() {
+ return Json.createObjectBuilder().add(RFC_KEY1, RFC_VAL1)
+ .add(RFC_KEY2, RFC_VAL2).add(RFC_KEY3, RFC_VAL3).add(RFC_KEY4, RFC_VAL4)
+ .add(RFC_KEY5, RFC_VAL5).add(RFC_KEY6, RFC_VAL6).add(RFC_KEY7, RFC_VAL7)
+ .add(RFC_KEY8, RFC_VAL8).add(RFC_KEY9, RFC_VAL9)
+ .add(RFC_KEY10, RFC_VAL10).add(RFC_KEY11, RFC_VAL11).build();
+ }
+
+ /**
+ * Create an instance of RFC 6901 object class is not allowed.
+ */
+ private PointerRFCObject() {
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/SimpleValues.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/SimpleValues.java
new file mode 100644
index 00000000..7ebe2b5f
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/SimpleValues.java
@@ -0,0 +1,1155 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.common;
+
+import java.io.StringWriter;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import jakarta.json.Json;
+import jakarta.json.JsonArray;
+import jakarta.json.JsonArrayBuilder;
+import jakarta.json.JsonException;
+import jakarta.json.JsonObject;
+import jakarta.json.JsonObjectBuilder;
+import jakarta.json.JsonPatch;
+import jakarta.json.JsonValue;
+import jakarta.json.JsonWriter;
+
+// $Id$
+/**
+ * RFC 6902: JavaScript Object Notation (JSON) Patch compatibility tests.
+ * {@see RFC 6902}.
+ *
+ * Build various simple values for testing.
+ */
+public class SimpleValues {
+
+ /** Name of JSON {@code String} value used in tests. */
+ public static final String STR_NAME = "address";
+
+ /** Path of JSON {@code String} value used in tests. */
+ public static final String STR_PATH = "/" + STR_NAME;
+
+ /** JSON {@code String} value used in tests. */
+ public static final String STR_VALUE = "In a galaxy far far away";
+
+ /** JSON {@code String} second value used in tests. */
+ public static final String STR_VALUE2 = "In a land of myth";
+
+ /** Name of JSON {@code int} value used in tests. */
+ public static final String INT_NAME = "age";
+
+ /** Path of JSON {@code int} value used in tests. */
+ public static final String INT_PATH = "/" + INT_NAME;
+
+ /** JSON {@code int} value used in tests. */
+ public static final int INT_VALUE = 42;
+
+ /** JSON {@code int} second value used in tests. */
+ public static final int INT_VALUE2 = 32;
+
+ /** Name of JSON {@code boolean} value used in tests. */
+ public static final String BOOL_NAME = "married";
+
+ /** Path of JSON {@code boolean} value used in tests. */
+ public static final String BOOL_PATH = "/" + BOOL_NAME;
+
+ /** JSON {@code boolean} value used in tests. */
+ public static final boolean BOOL_VALUE = true;
+
+ /** JSON {@code boolean} second value used in tests. */
+ public static final boolean BOOL_VALUE2 = false;
+
+ /** Name of JSON {@code JsonObject} value used in tests. */
+ public static final String OBJ_NAME = "wife";
+
+ /** Path of JSON {@code JsonObject} value used in tests. */
+ public static final String OBJ_PATH = "/" + OBJ_NAME;
+
+ /** JSON {@code JsonObject} value used in tests. */
+ public static final JsonObject OBJ_VALUE = createSimpleObject(
+ new String[] { "name", "age" }, new Object[] { "Sarah Connor", 32 });
+
+ /** JSON {@code JsonObject} second value used in tests. */
+ public static final JsonObject OBJ_VALUE2 = createSimpleObject(
+ new String[] { "name", "age" }, new Object[] { "Kyle Reese", 35 });
+
+ /** Name of JSON default value stored in simple object. */
+ public static final String DEF_NAME = "name";
+
+ /** Name of JSON default value stored in simple object. */
+ public static final String DEF_PATH = "/" + DEF_NAME;
+
+ /** JSON default value stored in simple object. */
+ public static final String DEF_VALUE = "John Smith";
+
+ /** Name of JSON object stored in compound object. */
+ public static final String DEF_OBJ_NAME = "child";
+
+ /** Path of JSON object stored in compound object. */
+ public static final String DEF_OBJ_PATH = "/child";
+
+ /** JSON default object stored in simple object. */
+ public static final JsonObject DEF_OBJ_VALUE = createSimpleObject(
+ new String[] { "name", "age" }, new Object[] { "John Connor", 6 });
+
+ /** JSON default object stored in simple object with name changed. */
+ public static final JsonObject DEF_OBJ_VALUE2 = createSimpleObject(
+ new String[] { "name", "age" }, new Object[] { "John Smith", 6 });
+
+ /** Value of JSON {@code String} array at index 0. */
+ public static final String STR_VALUE_1 = "First value";
+
+ /** Value of JSON {@code String} array at index 1. */
+ public static final String STR_VALUE_2 = "Second value";
+
+ /** Value of JSON {@code String} array at index 2. */
+ public static final String STR_VALUE_3 = "Third value";
+
+ /** Value of JSON {@code String} array at index 3. */
+ public static final String STR_VALUE_4 = "Fourth value";
+
+ /** Value of JSON {@code String} array at index 4. */
+ public static final String STR_VALUE_5 = "Fifth value";
+
+ /** Value of JSON {@code String} array at index 5. */
+ public static final String STR_VALUE_6 = "Sixth value";
+
+ /** Value of JSON {@code String} array at index 6. */
+ public static final String STR_VALUE_7 = "Seventh value";
+
+ /** Value of JSON {@code int} array at index 0. */
+ public static final int INT_VALUE_1 = 1;
+
+ /** Value of JSON {@code int} array at index 1. */
+ public static final int INT_VALUE_2 = 2;
+
+ /** Value of JSON {@code int} array at index 2. */
+ public static final int INT_VALUE_3 = 3;
+
+ /** Value of JSON {@code int} array at index 3. */
+ public static final int INT_VALUE_4 = 4;
+
+ /** Value of JSON {@code int} array at index 4. */
+ public static final int INT_VALUE_5 = 5;
+
+ /** Value of JSON {@code JsonObject} array at index 0. */
+ public static final JsonObject OBJ_VALUE_1 = createSimpleObject(
+ new String[] { "first" }, new String[] { STR_VALUE_1 });
+
+ /** Value of JSON {@code JsonObject} array at index 1. */
+ public static final JsonObject OBJ_VALUE_2 = createSimpleObject(
+ new String[] { "second" }, new String[] { STR_VALUE_2 });
+
+ /** Value of JSON {@code JsonObject} array at index 2. */
+ public static final JsonObject OBJ_VALUE_3 = createSimpleObject(
+ new String[] { "third" }, new String[] { STR_VALUE_3 });
+
+ /** Value of JSON {@code JsonObject} array at index 3. */
+ public static final JsonObject OBJ_VALUE_4 = createSimpleObject(
+ new String[] { "fourth" }, new String[] { STR_VALUE_4 });
+
+ /** Value of JSON {@code JsonObject} array at index 4. */
+ public static final JsonObject OBJ_VALUE_5 = createSimpleObject(
+ new String[] { "fifth" }, new String[] { STR_VALUE_5 });
+
+ /** JSON {@code boolean} value: {@code true}. */
+ public static final boolean BOOL_TRUE = true;
+
+ /** JSON {@code boolean} value: {@code false}. */
+ public static final boolean BOOL_FALSE = false;
+
+ /** JSON {@code long} value used in tests. */
+ public static final long LNG_VALUE = Long.MAX_VALUE - 42;
+
+ /** JSON {@code BigInteger} value used in tests. */
+ public static final BigInteger BIN_VALUE = new BigInteger(
+ "123456789012345678901234567890");
+
+ /** JSON {@code double} value used in tests. */
+ public static final double DBL_VALUE = 0x1.f5c926b3a0942P+1014;
+
+ /** JSON {@code BigDecimal} value used in tests. */
+ public static final BigDecimal BDC_VALUE = new BigDecimal(
+ new BigInteger("1234567890123456789012345678901234567890"), 10);
+
+ /** Message content: null String. */
+ public static final String NULL = "null";
+
+ /**
+ * Creates empty JSON object.
+ *
+ * @return Empty JSON object.
+ */
+ public static JsonObject createEmptyObject() {
+ return Json.createObjectBuilder().build();
+ }
+
+ /**
+ * Creates empty JSON object after ADD STR_NAME STR_VALUE operation.
+ *
+ * @return Empty JSON object after ADD STR_NAME STR_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectStr() {
+ return Json.createObjectBuilder().add(STR_NAME, STR_VALUE).build();
+ }
+
+ /**
+ * Creates empty JSON object after ADD INT_NAME INT_VALUE operation.
+ *
+ * @return Empty JSON object after ADD INT_NAME INT_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectInt() {
+ return Json.createObjectBuilder().add(INT_NAME, INT_VALUE).build();
+ }
+
+ /**
+ * Creates empty JSON object after ADD BOOL_NAME BOOL_VALUE operation.
+ *
+ * @return Empty JSON object after ADD BOOL_NAME BOOL_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectBool() {
+ return Json.createObjectBuilder().add(BOOL_NAME, BOOL_VALUE).build();
+ }
+
+ /**
+ * Creates empty JSON object after ADD OBJ_NAME OBJ_VALUE operation.
+ *
+ * @return Empty JSON object after ADD OBJ_NAME OBJ_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectObject() {
+ return Json.createObjectBuilder().add(OBJ_NAME, OBJ_VALUE).build();
+ }
+
+ /**
+ * Creates JSON patch to remove STR_NAME attribute from object.
+ *
+ * @return JSON patch
+ */
+ public static JsonObject createPatchRemoveStr() {
+ return Json.createObjectBuilder().add(STR_NAME, JsonValue.NULL).build();
+ }
+
+ /**
+ * Creates JSON patch to remove INT_NAME attribute from object.
+ *
+ * @return JSON patch
+ */
+ public static JsonObject createPatchRemoveInt() {
+ return Json.createObjectBuilder().add(INT_NAME, JsonValue.NULL).build();
+ }
+
+ /**
+ * Creates JSON patch to remove BOOL_NAME attribute from object.
+ *
+ * @return JSON patch
+ */
+ public static JsonObject createPatchRemoveBool() {
+ return Json.createObjectBuilder().add(BOOL_NAME, JsonValue.NULL).build();
+ }
+
+ /**
+ * Creates JSON patch to remove OBJ_NAME attribute from object.
+ *
+ * @return JSON patch
+ */
+ public static JsonObject createPatchRemoveObject() {
+ return Json.createObjectBuilder().add(OBJ_NAME, JsonValue.NULL).build();
+ }
+
+ /**
+ * Creates empty JSON array.
+ *
+ * @return Empty JSON array.
+ */
+ public static JsonArray createEmptyArray() {
+ return Json.createArrayBuilder().build();
+ }
+
+ /**
+ * Creates empty JSON array after ADD STR_VALUE operation.
+ *
+ * @return Empty JSON array after ADD STR_VALUE operation.
+ */
+ public static JsonArray createEmptyArrayWithStr() {
+ return Json.createArrayBuilder().add(STR_VALUE).build();
+ }
+
+ /**
+ * Creates empty JSON array after ADD INT_VALUE operation.
+ *
+ * @return Empty JSON array after ADD INT_VALUE operation.
+ */
+ public static JsonArray createEmptyArrayWithInt() {
+ return Json.createArrayBuilder().add(INT_VALUE).build();
+ }
+
+ /**
+ * Creates empty JSON array after ADD BOOL_VALUE operation.
+ *
+ * @return Empty JSON array after ADD BOOL_VALUE operation.
+ */
+ public static JsonArray createEmptyArrayWithBool() {
+ return Json.createArrayBuilder().add(BOOL_VALUE).build();
+ }
+
+ /**
+ * Creates empty JSON array after ADD OBJ_VALUE operation.
+ *
+ * @return Empty JSON array after ADD OBJ_VALUE operation.
+ */
+ public static JsonArray createEmptyArrayWithObject() {
+ return Json.createArrayBuilder().add(OBJ_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object.
+ *
+ * @return Simple JSON object.
+ */
+ public static JsonObject createSimpleObject() {
+ return Json.createObjectBuilder().add(DEF_NAME, DEF_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after ADD STR_NAME STR_VALUE operation.
+ *
+ * @return Simple JSON object after ADD STR_NAME STR_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectWithStr() {
+ return Json.createObjectBuilder().add(DEF_NAME, DEF_VALUE)
+ .add(STR_NAME, STR_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after REPLACE STR_NAME STR_VALUE operation.
+ *
+ * @return Simple JSON object after REPLACE STR_NAME STR_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectReplaceStr() {
+ return Json.createObjectBuilder().add(STR_NAME, STR_VALUE2).build();
+ }
+
+ /**
+ * Creates simple JSON object after MOVE STR_NAME DEF_NAME operation.
+ *
+ * @return Simple JSON object after MOVE STR_NAME DEF_NAME operation.
+ */
+ public static JsonObject createSimpleObjectMoveStr() {
+ return Json.createObjectBuilder().add(DEF_NAME, STR_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after COPY STR_NAME DEF_NAME operation.
+ *
+ * @return Simple JSON object after COPY STR_NAME DEF_NAME operation.
+ */
+ public static JsonObject createSimpleObjectCopyStr() {
+ return Json.createObjectBuilder().add(STR_NAME, STR_VALUE)
+ .add(DEF_NAME, STR_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after ADD INT_NAME INT_VALUE operation.
+ *
+ * @return Simple JSON object after ADD INT_NAME INT_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectWithInt() {
+ return Json.createObjectBuilder().add(DEF_NAME, DEF_VALUE)
+ .add(INT_NAME, INT_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after REPLACE INT_NAME INT_VALUE operation.
+ *
+ * @return Simple JSON object after REPLACE INT_NAME INT_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectReplaceInt() {
+ return Json.createObjectBuilder().add(INT_NAME, INT_VALUE2).build();
+ }
+
+ /**
+ * Creates simple JSON object after MOVE INT_NAME DEF_NAME operation.
+ *
+ * @return Simple JSON object after MOVE INT_NAME DEF_NAME operation.
+ */
+ public static JsonObject createSimpleObjectMoveInt() {
+ return Json.createObjectBuilder().add(DEF_NAME, INT_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after COPY INT_NAME DEF_NAME operation.
+ *
+ * @return Simple JSON object after COPY INT_NAME DEF_NAME operation.
+ */
+ public static JsonObject createSimpleObjectCopyInt() {
+ return Json.createObjectBuilder().add(INT_NAME, INT_VALUE)
+ .add(DEF_NAME, INT_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after ADD BOOL_NAME BOOL_VALUE operation.
+ *
+ * @return Simple JSON object after ADD BOOL_NAME BOOL_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectWithBool() {
+ return Json.createObjectBuilder().add(DEF_NAME, DEF_VALUE)
+ .add(BOOL_NAME, BOOL_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after REPLACE BOOL_NAME BOOL_VALUE operation.
+ *
+ * @return Simple JSON object after REPLACE BOOL_NAME BOOL_VALUE operation.
+ */
+ public static JsonObject createSimpleObjectReplaceBool() {
+ return Json.createObjectBuilder().add(BOOL_NAME, BOOL_VALUE2).build();
+ }
+
+ /**
+ * Creates simple JSON object after MOVE BOOL_NAME DEF_NAME operation.
+ *
+ * @return Simple JSON object after MOVE BOOL_NAME DEF_NAME operation.
+ */
+ public static JsonObject createSimpleObjectMoveBool() {
+ return Json.createObjectBuilder().add(DEF_NAME, BOOL_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after COPY BOOL_NAME DEF_NAME operation.
+ *
+ * @return Simple JSON object after COPY BOOL_NAME DEF_NAME operation.
+ */
+ public static JsonObject createSimpleObjectCopyBool() {
+ return Json.createObjectBuilder().add(BOOL_NAME, BOOL_VALUE)
+ .add(DEF_NAME, BOOL_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object.
+ *
+ * @return Simple JSON object.
+ */
+ public static JsonObject createCompoundObject() {
+ return Json.createObjectBuilder().add(DEF_NAME, DEF_VALUE)
+ .add(DEF_OBJ_NAME, DEF_OBJ_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after ADD OBJ_NAME OBJ_VALUE operation.
+ *
+ * @return Simple JSON object after ADD OBJ_NAME OBJ_VALUE operation.
+ */
+ public static JsonObject createCompoundObjectWithObject() {
+ return Json.createObjectBuilder().add(DEF_NAME, DEF_VALUE)
+ .add(DEF_OBJ_NAME, DEF_OBJ_VALUE).add(OBJ_NAME, OBJ_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after ADD OBJ_NAME OBJ_VALUE operation.
+ *
+ * @return Simple JSON object after ADD OBJ_NAME OBJ_VALUE operation.
+ */
+ public static JsonObject createCompoundObjectReplaceObject() {
+ return Json.createObjectBuilder().add(DEF_NAME, DEF_VALUE)
+ .add(DEF_OBJ_NAME, DEF_OBJ_VALUE).add(OBJ_NAME, OBJ_VALUE2).build();
+ }
+
+ /**
+ * Creates simple JSON object after MOVE DEF_PATH DEF_OBJ_PATH+DEF_PATH.
+ *
+ * @return Simple JSON object.
+ */
+ public static JsonObject createCompoundObjectMoveValue() {
+ return Json.createObjectBuilder().add(DEF_OBJ_NAME, DEF_OBJ_VALUE2).build();
+ }
+
+ /**
+ * Creates simple JSON object after COPY DEF_PATH DEF_OBJ_PATH+DEF_PATH.
+ *
+ * @return Simple JSON object.
+ */
+ public static JsonObject createCompoundObjectCopyValue() {
+ return Json.createObjectBuilder().add(DEF_NAME, DEF_VALUE)
+ .add(DEF_OBJ_NAME, DEF_OBJ_VALUE2).build();
+ }
+
+ /**
+ * Creates simple JSON object after MOVE OBJ_NAME DEF_NAME operation.
+ *
+ * @return Simple JSON object after MOVE OBJ_NAME DEF_NAME operation.
+ */
+ public static JsonObject createSimpleObjectMoveObject() {
+ return Json.createObjectBuilder().add(DEF_NAME, OBJ_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON object after COPY OBJ_NAME DEF_NAME operation.
+ *
+ * @return Simple JSON object after COPY OBJ_NAME DEF_NAME operation.
+ */
+ public static JsonObject createSimpleObjectCopyObject() {
+ return Json.createObjectBuilder().add(OBJ_NAME, OBJ_VALUE)
+ .add(DEF_NAME, OBJ_VALUE).build();
+ }
+
+ /**
+ * Creates compound JSON object after ADD DEF_OBJ_NAME,
+ * createSimpleStringArray5().
+ *
+ * @return compound JSON object with ADD operation applied.
+ */
+ public static JsonObject createCompoundObjectWithObjectReplaced() {
+ return Json.createObjectBuilder().add(DEF_NAME, DEF_VALUE)
+ .add(DEF_OBJ_NAME, createSimpleStringArray5()).build();
+ }
+
+ /**
+ * Creates simple JSON object with provided {@code name[i]} and
+ * {@code value[i]} pairs.
+ *
+ * @param names
+ * Names of JSON values to be added. Pairs of {@code names[i]} and
+ * {@code values[i]} are used for add operations.
+ * @param values
+ * JSON values to be added for specified names.
+ * @return Simple JSON object.
+ */
+ @SuppressWarnings("UnnecessaryUnboxing")
+ public static JsonObject createSimpleObject(final String[] names,
+ final Object[] values) {
+ if (names.length != values.length) {
+ throw new IllegalArgumentException(
+ "Number of paths does not match number of indexes");
+ }
+ JsonObjectBuilder builder = Json.createObjectBuilder();
+ for (int i = 0; i < names.length; i++) {
+ switch (JsonValueType.getType(values[i].getClass())) {
+ case String:
+ builder = builder.add(names[i], (String) values[i]);
+ break;
+ case Integer:
+ builder = builder.add(names[i], ((Integer) values[i]).intValue());
+ break;
+ case Boolean:
+ builder = builder.add(names[i], ((Boolean) values[i]).booleanValue());
+ break;
+ case JsonValue:
+ builder = builder.add(names[i], (JsonValue) values[i]);
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Value does not match known JSON value type");
+ }
+ }
+ return builder.build();
+ }
+
+ /**
+ * Creates simple JSON array with specified {@code String} values.
+ *
+ * @param values
+ * JSON array {@code String} values.
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createStringArray(final String... values) {
+ JsonArrayBuilder builder = Json.createArrayBuilder();
+ if (values != null) {
+ for (final String value : values) {
+ builder = builder.add(value);
+ }
+ }
+ return builder.build();
+ }
+
+ /**
+ * Creates simple JSON array with single {@code String}.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createStringArray1() {
+ return Json.createArrayBuilder().add(STR_VALUE_1).build();
+ }
+
+ /**
+ * Creates simple JSON array after ADD STR_VALUE operation before existing
+ * element.
+ *
+ * @return Simple JSON array after ADD STR_VALUE operation before existing
+ * element.
+ */
+ public static JsonArray createSimpleStringArrayWithStrBefore() {
+ return Json.createArrayBuilder().add(STR_VALUE).add(STR_VALUE_1).build();
+ }
+
+ /**
+ * Creates simple JSON array after ADD STR_VALUE operation after existing
+ * element.
+ *
+ * @return Simple JSON array after ADD STR_VALUE operation after existing
+ * element.
+ */
+ public static JsonArray createSimpleStringArrayWithStrAfter() {
+ return Json.createArrayBuilder().add(STR_VALUE_1).add(STR_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON array after REPLACE STR_VALUE operation on existing
+ * element.
+ *
+ * @return Simple JSON array after REPLACE STR_VALUE operation on existing
+ * element.
+ */
+ public static JsonArray createSimpleStringArrayReplaceStr() {
+ return Json.createArrayBuilder().add(STR_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON array with two {@code String} values.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createStringArray2() {
+ return Json.createArrayBuilder().add(STR_VALUE_2).add(STR_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with two {@code String} values in reversed order.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createStringArray2R() {
+ return Json.createArrayBuilder().add(STR_VALUE_4).add(STR_VALUE_2).build();
+ }
+
+ /**
+ * Creates simple JSON array with two {@code String} values to be inserted
+ * into another array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createStringInnerArray2() {
+ return Json.createArrayBuilder().add(STR_VALUE_6).add(STR_VALUE_7).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code String} values as a result of
+ * COPY 2nd element to the beginning of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createStringArray2Copy1to0() {
+ return Json.createArrayBuilder().add(STR_VALUE_4).add(STR_VALUE_2)
+ .add(STR_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code String} values as a result of
+ * COPY 1st element to the end of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createStringArray2Copy0to2() {
+ return Json.createArrayBuilder().add(STR_VALUE_2).add(STR_VALUE_4)
+ .add(STR_VALUE_2).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code String} values as a result of
+ * COPY 1st element to the middle of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createStringArray2Copy0to1() {
+ return Json.createArrayBuilder().add(STR_VALUE_2).add(STR_VALUE_2)
+ .add(STR_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with five {@code String} values.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createSimpleStringArray5() {
+ return Json.createArrayBuilder().add(STR_VALUE_1).add(STR_VALUE_2)
+ .add(STR_VALUE_3).add(STR_VALUE_4).add(STR_VALUE_5).build();
+ }
+
+ /**
+ * Creates simple JSON array with five {@code String} values in reversed
+ * order.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createSimpleStringArray5R() {
+ return Json.createArrayBuilder().add(STR_VALUE_5).add(STR_VALUE_4)
+ .add(STR_VALUE_3).add(STR_VALUE_2).add(STR_VALUE_1).build();
+ }
+
+ /**
+ * Creates simple JSON array after ADD [STR_VALUE_6, STR_VALUE_7] operation
+ * between two existing elements.
+ *
+ * @return Simple JSON array after ADD operation.
+ */
+ public static JsonArray createStringArray2WithStringArrayInTheMiddle() {
+ return Json.createArrayBuilder().add(STR_VALUE_2)
+ .add(createStringInnerArray2()).add(STR_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with single {@code int}.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createIntArray1() {
+ return Json.createArrayBuilder().add(INT_VALUE_1).build();
+ }
+
+ /**
+ * Creates simple JSON array after ADD INT_VALUE operation before existing
+ * element.
+ *
+ * @return Simple JSON array after ADD INT_VALUE operation before existing
+ * element.
+ */
+ public static JsonArray createSimpleIntArrayWithIntBefore() {
+ return Json.createArrayBuilder().add(INT_VALUE).add(INT_VALUE_1).build();
+ }
+
+ /**
+ * Creates simple JSON array after ADD INT_VALUE operation after existing
+ * element.
+ *
+ * @return Simple JSON array after ADD INT_VALUE operation after existing
+ * element.
+ */
+ public static JsonArray createSimpleIntArrayWithIntAfter() {
+ return Json.createArrayBuilder().add(INT_VALUE_1).add(INT_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON array after REPLACE INT_VALUE operation on existing
+ * element.
+ *
+ * @return Simple JSON array after REPLACE INT_VALUE operation on existing
+ * element.
+ */
+ public static JsonArray createSimpleIntArrayReplaceInt() {
+ return Json.createArrayBuilder().add(INT_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON array with two {@code int} values.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createIntArray2() {
+ return Json.createArrayBuilder().add(INT_VALUE_2).add(INT_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with two {@code int} values in reversed order.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createIntArray2R() {
+ return Json.createArrayBuilder().add(INT_VALUE_4).add(INT_VALUE_2).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code int} values as a result of COPY
+ * 2nd element to the beginning of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createIntArray2Copy1to0() {
+ return Json.createArrayBuilder().add(INT_VALUE_4).add(INT_VALUE_2)
+ .add(INT_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code int} values as a result of COPY
+ * 1st element to the end of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createIntArray2Copy0to2() {
+ return Json.createArrayBuilder().add(INT_VALUE_2).add(INT_VALUE_4)
+ .add(INT_VALUE_2).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code int} values as a result of COPY
+ * 1st element to the middle of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createIntArray2Copy0to1() {
+ return Json.createArrayBuilder().add(INT_VALUE_2).add(INT_VALUE_2)
+ .add(INT_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with five {@code int} values.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createSimpleIntArray5() {
+ return Json.createArrayBuilder().add(INT_VALUE_1).add(INT_VALUE_2)
+ .add(INT_VALUE_3).add(INT_VALUE_4).add(INT_VALUE_5).build();
+ }
+
+ /**
+ * Creates simple JSON array with five {@code int} values in reversed order.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createSimpleIntArray5R() {
+ return Json.createArrayBuilder().add(INT_VALUE_5).add(INT_VALUE_4)
+ .add(INT_VALUE_3).add(INT_VALUE_2).add(INT_VALUE_1).build();
+ }
+
+ /**
+ * Creates simple JSON array with single {@code boolean}.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createBoolArray1() {
+ return Json.createArrayBuilder().add(BOOL_TRUE).build();
+ }
+
+ /**
+ * Creates simple JSON array after ADD BOOL_FALSE operation before existing
+ * element (BOOL_TRUE).
+ *
+ * @return Simple JSON array after ADD BOOL_FALSE operation before existing
+ * element.
+ */
+ public static JsonArray createSimpleBoolArrayWithBoolBefore() {
+ return Json.createArrayBuilder().add(BOOL_FALSE).add(BOOL_TRUE).build();
+ }
+
+ /**
+ * Creates simple JSON array after ADD BOOL_FALSE operation after existing
+ * element (BOOL_TRUE).
+ *
+ * @return Simple JSON array after ADD BOOL_FALSE operation after existing
+ * element.
+ */
+ public static JsonArray createSimpleBoolArrayWithBoolAfter() {
+ return Json.createArrayBuilder().add(BOOL_TRUE).add(BOOL_FALSE).build();
+ }
+
+ /**
+ * Creates simple JSON array after REPLACE BOOL_FALSE operation on existing
+ * element.
+ *
+ * @return Simple JSON array after REPLACE BOOL_FALSE operation on existing
+ * element.
+ */
+ public static JsonArray createSimpleBoolArrayReplaceBool() {
+ return Json.createArrayBuilder().add(BOOL_FALSE).build();
+ }
+
+ /**
+ * Creates simple JSON array with two {@code boolean} values.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createBoolArray2() {
+ return Json.createArrayBuilder().add(BOOL_TRUE).add(BOOL_FALSE).build();
+ }
+
+ /**
+ * Creates simple JSON array with two {@code boolean} values in reverse order.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createBoolArray2R() {
+ return Json.createArrayBuilder().add(BOOL_FALSE).add(BOOL_TRUE).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code boolean} values as a result of
+ * COPY 2nd element to the beginning of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createBoolArray2Copy1to0() {
+ return Json.createArrayBuilder().add(BOOL_FALSE).add(BOOL_TRUE)
+ .add(BOOL_FALSE).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code boolean} values as a result of
+ * COPY 1st element to the end of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createBoolArray2Copy0to2() {
+ return Json.createArrayBuilder().add(BOOL_TRUE).add(BOOL_FALSE)
+ .add(BOOL_TRUE).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code boolean} values as a result of
+ * COPY 1st element to the middle of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createBoolArray2Copy0to1() {
+ return Json.createArrayBuilder().add(BOOL_TRUE).add(BOOL_TRUE)
+ .add(BOOL_FALSE).build();
+ }
+
+ /**
+ * Creates simple JSON array with five {@code boolean} values.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createSimpleBoolArray5() {
+ return Json.createArrayBuilder().add(BOOL_FALSE).add(BOOL_TRUE)
+ .add(BOOL_TRUE).add(BOOL_FALSE).add(BOOL_TRUE).build();
+ }
+
+ /**
+ * Creates simple JSON array with five {@code boolean} values in reversed
+ * order.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createSimpleBoolArray5R() {
+ return Json.createArrayBuilder().add(BOOL_TRUE).add(BOOL_FALSE)
+ .add(BOOL_TRUE).add(BOOL_TRUE).add(BOOL_FALSE).build();
+ }
+
+ /**
+ * Creates simple JSON array with single {@code JsonObject}.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createObjectArray1() {
+ return Json.createArrayBuilder().add(OBJ_VALUE_1).build();
+ }
+
+ /**
+ * Creates simple JSON array after ADD OBJ_VALUE operation before existing
+ * element.
+ *
+ * @return Simple JSON array after ADD OBJ_VALUE operation before existing
+ * element.
+ */
+ public static JsonArray createSimpleObjectArrayWithObjectBefore() {
+ return Json.createArrayBuilder().add(OBJ_VALUE).add(OBJ_VALUE_1).build();
+ }
+
+ /**
+ * Creates simple JSON array after ADD OBJ_VALUE operation after existing
+ * element.
+ *
+ * @return Simple JSON array after ADD OBJ_VALUE operation after existing
+ * element.
+ */
+ public static JsonArray createSimpleObjectArrayWithObjectAfter() {
+ return Json.createArrayBuilder().add(OBJ_VALUE_1).add(OBJ_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON array after REPLACE OBJ_VALUE operation on existing
+ * element.
+ *
+ * @return Simple JSON array after REPLACE OBJ_VALUE operation on existing
+ * element.
+ */
+ public static JsonArray createSimpleObjectArrayReplaceObject() {
+ return Json.createArrayBuilder().add(OBJ_VALUE).build();
+ }
+
+ /**
+ * Creates simple JSON array with two {@code JsonObject} values.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createObjectArray2() {
+ return Json.createArrayBuilder().add(OBJ_VALUE_2).add(OBJ_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with two {@code JsonObject} values in reverse
+ * order.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createObjectArray2R() {
+ return Json.createArrayBuilder().add(OBJ_VALUE_4).add(OBJ_VALUE_2).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code JsonObject} values as a result
+ * of COPY 2nd element to the beginning of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createObjectArray2Copy1to0() {
+ return Json.createArrayBuilder().add(OBJ_VALUE_4).add(OBJ_VALUE_2)
+ .add(OBJ_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code JsonObject} values as a result
+ * of COPY 1st element to the end of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createObjectArray2Copy0to2() {
+ return Json.createArrayBuilder().add(OBJ_VALUE_2).add(OBJ_VALUE_4)
+ .add(OBJ_VALUE_2).build();
+ }
+
+ /**
+ * Creates simple JSON array with three {@code JsonObject} values as a result
+ * of COPY 1st element to the middle of the array.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createObjectArray2Copy0to1() {
+ return Json.createArrayBuilder().add(OBJ_VALUE_2).add(OBJ_VALUE_2)
+ .add(OBJ_VALUE_4).build();
+ }
+
+ /**
+ * Creates simple JSON array with five {@code JsonObject} values.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createSimpleObjectArray5() {
+ return Json.createArrayBuilder().add(OBJ_VALUE_1).add(OBJ_VALUE_2)
+ .add(OBJ_VALUE_3).add(OBJ_VALUE_4).add(OBJ_VALUE_5).build();
+ }
+
+ /**
+ * Creates simple JSON array with five {@code JsonObject} values in reversed
+ * order.
+ *
+ * @return Newly created JSON array.
+ */
+ public static JsonArray createSimpleObjectArray5R() {
+ return Json.createArrayBuilder().add(OBJ_VALUE_5).add(OBJ_VALUE_4)
+ .add(OBJ_VALUE_3).add(OBJ_VALUE_2).add(OBJ_VALUE_1).build();
+ }
+
+ /**
+ * Convert provided {@code Object} instance to {@code JsonValue}.
+ *
+ * @param value
+ * {@code Object} instance to be converted.
+ * @return JsonValue instance containing provided {@code Object};
+ */
+ @SuppressWarnings("UnnecessaryUnboxing")
+ public static JsonValue toJsonValue(final Object value) {
+ if (value == null) {
+ return JsonValue.NULL;
+ }
+ switch (JsonValueType.getType(value.getClass())) {
+ case String:
+ return Json.createValue((String) value);
+ case Integer:
+ return Json.createValue(((Integer) value).intValue());
+ case Long:
+ return Json.createValue(((Long) value).longValue());
+ case BigInteger:
+ return Json.createValue((BigInteger) value);
+ case Double:
+ return Json.createValue(((Double) value).doubleValue());
+ case BigDecimal:
+ return Json.createValue((BigDecimal) value);
+ case Boolean:
+ return ((Boolean) value).booleanValue() ? JsonValue.TRUE
+ : JsonValue.FALSE;
+ case JsonValue:
+ return (JsonValue) value;
+ case Null:
+ return JsonValue.NULL;
+ default:
+ throw new IllegalArgumentException(
+ "Value does not match known JSON value type");
+ }
+ }
+
+ /**
+ * Convert JSON value to {@code String} containing value stored in JSON
+ * format.
+ *
+ * @param value
+ * JSON value to be converted.
+ * @return Provided value stored in JSON format.
+ */
+ public static String jsonData(final JsonValue value) {
+ final StringWriter strWriter = new StringWriter();
+ try (final JsonWriter writer = Json.createWriter(strWriter)) {
+ writer.write(value);
+ } catch (JsonException ex) {
+ System.out.println(
+ "Could not initialize JSON data: " + ex.getLocalizedMessage());
+ throw ex;
+ }
+ return strWriter.toString();
+ }
+
+ /**
+ * Apply patch on provided JSON {@code value} using {@code apply()} method of
+ * {@code JsonPatch}.
+ *
+ * @param patch
+ * {@code JsonPatch} with patch operations.
+ * @param value
+ * JSON {@code value} to be patched.
+ * @return Result of JSON {@code value} patching.
+ */
+ public static JsonValue patchApply(final JsonPatch patch,
+ final JsonValue value) {
+ switch (value.getValueType()) {
+ case OBJECT:
+ return patch.apply((JsonObject) value);
+ case ARRAY:
+ return patch.apply((JsonArray) value);
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported JSON value type to be pached");
+ }
+ }
+
+ /**
+ * Convert {@code boolean} value to {@code JsonValue}.
+ *
+ * @param value
+ * Source {@code boolean} value.
+ * @return {@code JsonValue.TRUE} if provided {@code value} is {@code true} or
+ * {@code JsonValue.FALSE} otherwise.
+ */
+ public static JsonValue booleanValue(final boolean value) {
+ return value ? JsonValue.TRUE : JsonValue.FALSE;
+ }
+
+ /**
+ * Creates an instance of RFC 6902 operation test.
+ */
+ private SimpleValues() {
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/TestFail.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/TestFail.java
new file mode 100644
index 00000000..630c286b
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/TestFail.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.common;
+
+/**
+ * Test failure notification.
+ */
+public class TestFail {
+
+ /** Test failure name and message separator. */
+ private static final String NM_SEP = ": ";
+
+ /** Name of test that failed. */
+ private final String name;
+
+ /** Error message. */
+ private final String message;
+
+ /**
+ * Creates an instance of test failure notification.
+ *
+ * @param name
+ * Test name.
+ * @param message
+ * Error message.
+ */
+ public TestFail(final String name, final String message) {
+ this.name = name;
+ this.message = message;
+ }
+
+ /**
+ * Returns human readable content of test failure notification.
+ *
+ * @return Human readable content of test failure notification.
+ */
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder(
+ name.length() + message.length() + NM_SEP.length());
+ sb.append(name);
+ sb.append(NM_SEP);
+ sb.append(message);
+ return sb.toString();
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/TestResult.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/TestResult.java
new file mode 100644
index 00000000..69309f2e
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/common/TestResult.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.common;
+
+import jakarta.jsonp.tck.api.common.TestFail;
+import jakarta.jsonp.tck.lib.harness.Fault;
+
+import java.util.LinkedList;
+
+/**
+ * Tests result record.
+ */
+public class TestResult {
+
+ /** Name of test suite. */
+ private final String name;
+
+ /** List of test failures. */
+ private final LinkedList fails;
+
+ /**
+ * Creates an instance of tests result record.
+ *
+ * @param name
+ * Name of test suite.
+ */
+ public TestResult(final String name) {
+ this.name = name;
+ this.fails = new LinkedList<>();
+ }
+
+ /**
+ * Records test failure.
+ *
+ * @param name
+ * Test name.
+ * @param message
+ * Error message.
+ */
+ public void fail(final String name, final String message) {
+ fails.addLast(new TestFail(name, message));
+ }
+
+ /**
+ * Evaluate test results.
+ *
+ * @throws Fault
+ * when any test failed.
+ */
+ public void eval() throws Fault {
+ if (fails.isEmpty()) {
+ return;
+ }
+ final StringBuilder sb = new StringBuilder();
+ sb.append(name);
+ sb.append(" failed:");
+ for (TestFail fail : fails) {
+ sb.append('\n');
+ sb.append(fail.toString());
+ }
+ throw new Fault(sb.toString());
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/exceptiontests/ClientTests.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/exceptiontests/ClientTests.java
new file mode 100644
index 00000000..4ee38c97
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/exceptiontests/ClientTests.java
@@ -0,0 +1,292 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package jakarta.jsonp.tck.api.exceptiontests;
+
+import jakarta.json.*;
+import jakarta.json.stream.*;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import jakarta.jsonp.tck.common.*;
+import jakarta.jsonp.tck.lib.harness.Fault;
+
+@RunWith(Arquillian.class)
+public class ClientTests {
+
+ @Deployment
+ public static WebArchive createTestArchive() {
+ return ShrinkWrap.create(WebArchive.class)
+ .addPackages(true, ClientTests.class.getPackage().getName());
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: jsonExceptionConstructorTest1
+ *
+ * @assertion_ids: JSONP:JAVADOC:37;
+ *
+ * @test_Strategy: Test API: JsonException ret = new JsonException(String)
+ */
+ @Test
+ public void jsonExceptionConstructorTest1() throws Fault {
+ boolean pass = true;
+
+ try {
+ String message = "This JSON is incorrect.";
+
+ System.out.println("Test JsonException(String)");
+ JsonException exception = new JsonException(message);
+ try {
+ throw exception;
+ } catch (JsonException e) {
+ if (!e.getMessage().equals(message)) {
+ System.err.println("Incorrect message: expected " + message + ", received "
+ + e.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Fault("jsonExceptionConstructorTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Fault("jsonExceptionConstructorTest1 Failed:");
+ }
+
+ /*
+ * @testName: jsonExceptionConstructorTest2
+ *
+ * @assertion_ids: JSONP:JAVADOC:38;
+ *
+ * @test_Strategy: Test API: JsonException ret = new JsonException(String,
+ * Throwable)
+ */
+ @Test
+ public void jsonExceptionConstructorTest2() throws Fault {
+ boolean pass = true;
+
+ try {
+ String message = "This JSON is incorrect due to foo.";
+ Exception foo = new Exception("This is a foo exception");
+
+ System.out.println("Test JsonException(String, Throwable)");
+ JsonException exception = new JsonException(message, foo);
+
+ try {
+ throw exception;
+ } catch (JsonException e) {
+ if (!e.getCause().equals(foo)) {
+ System.err.println("Incorrect cause: expected " + foo + ", received "
+ + e.getCause());
+ pass = false;
+ }
+ if (!e.getMessage().equals(message)) {
+ System.err.println("Incorrect message: expected " + message + ", received "
+ + e.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Fault("jsonExceptionConstructorTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Fault("jsonExceptionConstructorTest2 Failed:");
+ }
+
+ /*
+ * @testName: jsonParsingExceptionConstructorTest1
+ *
+ * @assertion_ids: JSONP:JAVADOC:285; JSONP:JAVADOC:478; JSONP:JAVADOC:474;
+ * JSONP:JAVADOC:475; JSONP:JAVADOC:476;
+ *
+ * @test_Strategy: Test API: JsonParsingException ret = new
+ * JsonParsingException(String, JsonLocation)
+ */
+ @Test
+ public void jsonParsingExceptionConstructorTest1() throws Fault {
+ boolean pass = true;
+
+ try {
+ String message = "This JSON is incorrect.";
+ MyJsonLocation expLoc = new MyJsonLocation(10, 20, 30);
+ System.out.println("MyJsonLocation");
+ JSONP_Util.dumpLocation(expLoc);
+
+ System.out.println("Test JsonParsingException(String, JsonLocation)");
+ JsonParsingException exception = new JsonParsingException(message,
+ expLoc);
+ try {
+ throw exception;
+ } catch (JsonParsingException e) {
+ if (!e.getMessage().equals(message)) {
+ System.err.println("Incorrect message: expected " + message + ", received "
+ + e.getMessage());
+ pass = false;
+ }
+ }
+ JsonLocation actLoc = exception.getLocation();
+ System.out.println("JsonParsingException.getLocation()");
+ JSONP_Util.dumpLocation(actLoc);
+ if (!JSONP_Util.assertEquals(expLoc, actLoc))
+ pass = false;
+ } catch (Exception e) {
+ throw new Fault("jsonParsingExceptionConstructorTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Fault("jsonParsingExceptionConstructorTest1 Failed:");
+ }
+
+ /*
+ * @testName: jsonParsingExceptionConstructorTest2
+ *
+ * @assertion_ids: JSONP:JAVADOC:286; JSONP:JAVADOC:478; JSONP:JAVADOC:474;
+ * JSONP:JAVADOC:475; JSONP:JAVADOC:476;
+ *
+ * @test_Strategy: Test API: JsonParsingException ret = new
+ * JsonParsingException(String, Throwable, JsonLocation)
+ */
+ @Test
+ public void jsonParsingExceptionConstructorTest2() throws Fault {
+ boolean pass = true;
+
+ try {
+ String message = "This JSON is incorrect due to foo.";
+ Exception foo = new Exception("This is a foo exception");
+ MyJsonLocation expLoc = new MyJsonLocation(10, 20, 30);
+ System.out.println("MyJsonLocation");
+ JSONP_Util.dumpLocation(expLoc);
+
+ System.out.println("Test JsonParsingException(String, Throwable)");
+ JsonParsingException exception = new JsonParsingException(message, foo,
+ expLoc);
+
+ try {
+ throw exception;
+ } catch (JsonParsingException e) {
+ if (!e.getCause().equals(foo)) {
+ System.err.println("Incorrect cause: expected " + foo + ", received "
+ + e.getCause());
+ pass = false;
+ }
+ if (!e.getMessage().equals(message)) {
+ System.err.println("Incorrect message: expected " + message + ", received "
+ + e.getMessage());
+ pass = false;
+ }
+ }
+ JsonLocation actLoc = exception.getLocation();
+ System.out.println("JsonParsingException.getLocation()");
+ JSONP_Util.dumpLocation(actLoc);
+ if (!JSONP_Util.assertEquals(expLoc, actLoc))
+ pass = false;
+ } catch (Exception e) {
+ throw new Fault("jsonParsingExceptionConstructorTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Fault("jsonParsingExceptionConstructorTest2 Failed:");
+ }
+
+ /*
+ * @testName: jsonGenerationExceptionConstructorTest1
+ *
+ * @assertion_ids: JSONP:JAVADOC:278;
+ *
+ * @test_Strategy: Test API: JsonGenerationException ret = new
+ * JsonGenerationException(String)
+ */
+ @Test
+ public void jsonGenerationExceptionConstructorTest1() throws Fault {
+ boolean pass = true;
+
+ try {
+ String message = "This JSON is incorrect.";
+
+ System.out.println("Test JsonGenerationException(String)");
+ JsonGenerationException exception = new JsonGenerationException(message);
+ try {
+ throw exception;
+ } catch (JsonGenerationException e) {
+ if (!e.getMessage().equals(message)) {
+ System.err.println("Incorrect message: expected " + message + ", received "
+ + e.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Fault("jsonGenerationExceptionConstructorTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Fault("jsonGenerationExceptionConstructorTest1 Failed:");
+ }
+
+ /*
+ * @testName: jsonGenerationExceptionConstructorTest2
+ *
+ * @assertion_ids: JSONP:JAVADOC:279;
+ *
+ * @test_Strategy: Test API: JsonGenerationException ret = new
+ * JsonGenerationException(String, Throwable)
+ */
+ @Test
+ public void jsonGenerationExceptionConstructorTest2() throws Fault {
+ boolean pass = true;
+
+ try {
+ String message = "This JSON is incorrect due to foo.";
+ Exception foo = new Exception("This is a foo exception");
+
+ System.out.println("Test JsonGenerationException(String, Throwable)");
+ JsonGenerationException exception = new JsonGenerationException(message,
+ foo);
+
+ try {
+ throw exception;
+ } catch (JsonGenerationException e) {
+ if (!e.getCause().equals(foo)) {
+ System.err.println("Incorrect cause: expected " + foo + ", received "
+ + e.getCause());
+ pass = false;
+ }
+ if (!e.getMessage().equals(message)) {
+ System.err.println("Incorrect message: expected " + message + ", received "
+ + e.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Fault("jsonGenerationExceptionConstructorTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Fault("jsonGenerationExceptionConstructorTest2 Failed:");
+ }
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuildAdd.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuildAdd.java
new file mode 100644
index 00000000..3c6f463f
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuildAdd.java
@@ -0,0 +1,618 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.jsonarraytests;
+
+import jakarta.jsonp.tck.api.common.ArrayBuilder;
+import jakarta.jsonp.tck.api.common.JsonIO;
+import jakarta.jsonp.tck.api.common.JsonValueType;
+import jakarta.jsonp.tck.api.common.TestResult;
+import jakarta.json.Json;
+import jakarta.json.JsonArray;
+import jakarta.json.JsonArrayBuilder;
+import jakarta.json.JsonObject;
+import jakarta.json.JsonObjectBuilder;
+import jakarta.json.JsonValue;
+
+import static jakarta.jsonp.tck.api.common.JsonAssert.*;
+import static jakarta.jsonp.tck.api.common.SimpleValues.*;
+
+// $Id$
+/**
+ * JavaScript Object Notation (JSON) compatibility tests:
+ * {@link JsonArrayBuilder} API add() methods added in JSON-P 1.1.
+ */
+public class ArrayBuildAdd extends ArrayCommon {
+
+ /**
+ * Creates an instance of {@link JsonArrayBuilder} API add() methods added in
+ * JSON-P 1.1 test.
+ */
+ ArrayBuildAdd() {
+ super();
+ }
+
+ /**
+ * Test {@link JsonArrayBuilder} API add() methods added in JSON-P 1.1.
+ *
+ * @return Result of all tests in this suite.
+ */
+ TestResult test() {
+ final TestResult result = new TestResult(
+ "JsonArrayBuilder API add() methods added in JSON-P 1.1.");
+ System.out.println("JsonArrayBuilder API add() methods added in JSON-P 1.1.");
+ testAdd(result);
+ testAddNullBuilder(result);
+ testAddOutOfBounds(result);
+ testAddNull(result);
+ testAddNullOutOfBounds(result);
+ testAddArrayBuilder(result);
+ testAddArrayBuilderNull(result);
+ testAddArrayBuilderOutOfBounds(result);
+ testAddObjectBuilder(result);
+ testAddObjectBuilderNull(result);
+ testAddObjectBuilderOutOfBounds(result);
+ testAddAllString(result);
+ testAddAllInt(result);
+ testAddAllBool(result);
+ testAddAllObject(result);
+ testAddAllNull(result);
+ return result;
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder add(int, Object)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAdd(final TestResult result) {
+ final Object[] values = new Object[] { OBJ_VALUE, // add(int,JsonValue)
+ STR_VALUE, // add(int,String)
+ INT_VALUE, // add(int,int)
+ LNG_VALUE, // add(int,long)
+ DBL_VALUE, // add(int,double)
+ BIN_VALUE, // add(int,BigInteger)
+ BDC_VALUE, // add(int,BigDecimal)
+ BOOL_VALUE // add(int,boolean)
+ };
+ for (Object value : values) {
+ final String typeName = JsonValueType.getType(value).name();
+ System.out.println(" - add(int," + typeName + ")");
+ final String json = "[" + JsonValueType.toStringValue(value) + "]";
+ final JsonValue check = JsonIO.read(json);
+ final JsonArrayBuilder builder = createArrayBuilder(0, value);
+ final JsonValue out = builder.build();
+ if (operationFailed(check, out)) {
+ result.fail("add(" + typeName + ")", "Builder output "
+ + valueToString(out) + " value shall be " + valueToString(check));
+ }
+ }
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder add(int, Object)} method on {@code String}
+ * array with index being out of range
+ * ({@code index < 0 || index > array size}).
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddOutOfBounds(final TestResult result) {
+ final Object[] values = new Object[] { OBJ_VALUE, // add(int,JsonValue)
+ STR_VALUE, // add(int,String)
+ INT_VALUE, // add(int,int)
+ LNG_VALUE, // add(int,long)
+ DBL_VALUE, // add(int,double)
+ BIN_VALUE, // add(int,BigInteger)
+ BDC_VALUE, // add(int,BigDecimal)
+ BOOL_VALUE // add(int,boolean)
+ };
+ final int[] indexes = new int[] { -1, 2, 3 };
+ for (Object value : values) {
+ final String typeName = JsonValueType.getType(value).name();
+ System.out.println(" - add(int," + typeName + ")");
+ final String json = "[" + JsonValueType.toStringValue(value) + "]";
+ // Add value into the array for the first time to het array of size 1.
+ JsonArrayBuilder builder = createArrayBuilder(value);
+ for (int index : indexes) {
+ try {
+ // Add value on out of bounds index
+ builder = updateOperationBuilder(builder, index, value);
+ result.fail("add(int," + typeName + ")",
+ "Calling method with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ System.out.println(" - Expected exception for index=" + index + ": "
+ + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("add(int,(" + typeName + ")null)",
+ "Calling method with with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder add(int, Object)} method on {@code String}
+ * array with null value.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddNullBuilder(final TestResult result) {
+ final JsonValueType[] types = new JsonValueType[] { JsonValueType.JsonValue, // add(int,(JsonValue)null)
+ JsonValueType.String, // add(int,(String)null)
+ JsonValueType.BigInteger, // add(int,(BigInteger)null)
+ JsonValueType.BigDecimal // add(int,(BigDecimal)null)
+ };
+ for (JsonValueType type : types) {
+ final String typeName = type.name();
+ System.out.println(" - add(int,(" + typeName + ")null)");
+ try {
+ ArrayBuilder.add(Json.createArrayBuilder(), 0, type);
+ result.fail("add(int,(" + typeName + ")null)",
+ "Calling method with null argument shall throw NullPointerException");
+ } catch (NullPointerException e) {
+ System.out.println(" - Expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("add(int,(" + typeName + ")null)",
+ "Calling method with null argument shall throw NullPointerException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder addNull(int)} method on {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddNull(final TestResult result) {
+ System.out.println(" - addNull(int)");
+ final Object value = null;
+ final String json = "[" + JsonValueType.toStringValue(value) + "]";
+ final JsonValue check = JsonIO.read(json);
+ final JsonArrayBuilder builder = createArrayBuilder(0, value);
+ final JsonValue out = builder.build();
+ if (operationFailed(check, out)) {
+ result.fail("addNull(int)", "Builder output " + valueToString(out)
+ + " value shall be " + valueToString(check));
+ }
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder addNull(int)} method on {@code String} array
+ * with index being out of range ({@code index < 0 || index > array size}).
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddNullOutOfBounds(final TestResult result) {
+ final int[] indexes = new int[] { -1, 2, 3 };
+ System.out.println(" - addNull(int)");
+ final Object value = null;
+ JsonArrayBuilder builder = createArrayBuilder(value);
+ for (int index : indexes) {
+ try {
+ // Add value on out of bounds index
+ builder = updateOperationBuilder(builder, index, value);
+ result.fail("addNull(int)", "Calling method with out of bounds index="
+ + index + " argument shall throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ System.out.println(" - Expected exception for index=" + index + ": "
+ + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("addNull(int)",
+ "Calling method with with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder add(int,JsonArrayBuilder)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddArrayBuilder(final TestResult result) {
+ System.out.println(" - add(int,JsonArrayBuilder)");
+ final JsonValue checkBeg = JsonIO
+ .read("[[" + JsonValueType.toStringValue(STR_VALUE_1) + ","
+ + JsonValueType.toStringValue(STR_VALUE_2) + ","
+ + JsonValueType.toStringValue(STR_VALUE_3) + ","
+ + JsonValueType.toStringValue(STR_VALUE_4) + "],"
+ + JsonValueType.toStringValue(STR_VALUE_5) + "]");
+ final JsonValue checkEnd = JsonIO
+ .read("[" + JsonValueType.toStringValue(STR_VALUE_1) + ",["
+ + JsonValueType.toStringValue(STR_VALUE_2) + ","
+ + JsonValueType.toStringValue(STR_VALUE_3) + ","
+ + JsonValueType.toStringValue(STR_VALUE_4) + ","
+ + JsonValueType.toStringValue(STR_VALUE_5) + "]]");
+ final JsonArrayBuilder inBeg = createArrayBuilder(STR_VALUE_5);
+ final JsonArrayBuilder inEnd = createArrayBuilder(STR_VALUE_1);
+ final JsonArrayBuilder argBeg = createArrayBuilder(STR_VALUE_1)
+ .add(STR_VALUE_2).add(STR_VALUE_3).add(STR_VALUE_4);
+ final JsonArrayBuilder argEnd = createArrayBuilder(STR_VALUE_2)
+ .add(STR_VALUE_3).add(STR_VALUE_4).add(STR_VALUE_5);
+ verifyAddBuilder(result, checkBeg, 0, argBeg, inBeg);
+ verifyAddBuilder(result, checkEnd, 1, argEnd, inEnd);
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder add(int,(JsonArrayBuilder)null)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddArrayBuilderNull(final TestResult result) {
+ System.out.println(" - add(int,(JsonArrayBuilder)null)");
+ final JsonArrayBuilder in = createArrayBuilder(DEF_VALUE);
+ final JsonArrayBuilder arg = null;
+ try {
+ in.add(0, arg);
+ result.fail("add(int,(JsonArrayBuilder)null)",
+ "Calling method with null argument shall throw NullPointerException");
+ } catch (NullPointerException e) {
+ System.out.println(" - Expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("add(int,(JsonArrayBuilder)null)",
+ "Calling method with null argument shall throw NullPointerException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder add(int,JsonArrayBuilder)} method on
+ * {@code String} array with index being out of range
+ * ({@code index < 0 || index > array size}).
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddArrayBuilderOutOfBounds(final TestResult result) {
+ System.out.println(" - add(int,JsonArrayBuilder)");
+ final int[] indexes = new int[] { -1, 5, 6 };
+ final JsonArrayBuilder in = createArrayBuilder(STR_VALUE_1).add(STR_VALUE_2)
+ .add(STR_VALUE_3).add(STR_VALUE_4);
+ final JsonArrayBuilder arg = createArrayBuilder(STR_VALUE_5);
+ for (int index : indexes) {
+ try {
+ // Add value on out of bounds index
+ in.add(index, arg);
+ result.fail("add(int,JsonArrayBuilder)",
+ "Calling method with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ System.out.println(" - Expected exception for index=" + index + ": "
+ + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("add(int,JsonArrayBuilder)",
+ "Calling method with with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder add(int,JsonObjectBuilder)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddObjectBuilder(final TestResult result) {
+ System.out.println(" - add(int,JsonObjectBuilder)");
+ final JsonValue checkBeg = JsonIO
+ .read("[{" + JsonValueType.toStringValue(STR_NAME) + ":"
+ + JsonValueType.toStringValue(STR_VALUE) + "},"
+ + JsonValueType.toStringValue(STR_VALUE_1) + "]");
+ final JsonValue checkEnd = JsonIO
+ .read("[" + JsonValueType.toStringValue(STR_VALUE_1) + ",{"
+ + JsonValueType.toStringValue(STR_NAME) + ":"
+ + JsonValueType.toStringValue(STR_VALUE) + "}]");
+ final JsonArrayBuilder inBeg = createArrayBuilder(STR_VALUE_1);
+ final JsonArrayBuilder inEnd = createArrayBuilder(STR_VALUE_1);
+ final JsonObjectBuilder argBeg = Json.createObjectBuilder().add(STR_NAME,
+ STR_VALUE);
+ final JsonObjectBuilder argEnd = Json.createObjectBuilder().add(STR_NAME,
+ STR_VALUE);
+ verifyAddBuilder(result, checkBeg, 0, argBeg, inBeg);
+ verifyAddBuilder(result, checkEnd, 1, argEnd, inEnd);
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder add(int,(JsonObjectBuilder)null)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddObjectBuilderNull(final TestResult result) {
+ System.out.println(" - add(int,(JsonObjectBuilder)null)");
+ final JsonArrayBuilder in = createArrayBuilder(DEF_VALUE);
+ final JsonObjectBuilder arg = null;
+ try {
+ in.add(0, arg);
+ result.fail("add(int,(JsonObjectBuilder)null)",
+ "Calling method with null argument shall throw NullPointerException");
+ } catch (NullPointerException e) {
+ System.out.println(" - Expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("add(int,(JsonObjectBuilder)null)",
+ "Calling method with null argument shall throw NullPointerException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder add(int,JsonObjectBuilder)} method on
+ * {@code String} array with index being out of range
+ * ({@code index < 0 || index > array size}).
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddObjectBuilderOutOfBounds(final TestResult result) {
+ System.out.println(" - add(int,JsonObjectBuilder)");
+ final int[] indexes = new int[] { -1, 5, 6 };
+ final JsonArrayBuilder in = createArrayBuilder(STR_VALUE_1).add(STR_VALUE_2)
+ .add(STR_VALUE_3).add(STR_VALUE_4);
+ final JsonObjectBuilder arg = Json.createObjectBuilder().add(STR_NAME,
+ STR_VALUE);
+ for (int index : indexes) {
+ try {
+ // Add value on out of bounds index
+ in.add(index, arg);
+ result.fail("add(int,JsonObjectBuilder)",
+ "Calling method with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ System.out.println(" - Expected exception for index=" + index + ": "
+ + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("add(int,JsonObjectBuilder)",
+ "Calling method with with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder addAll(JsonArrayBuilder)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddAllString(final TestResult result) {
+ System.out.println(" - addAll(JsonArrayBuilder) for String array");
+ final JsonArray check = createSimpleStringArray5();
+ final String[] strings = new String[] { STR_VALUE_1, STR_VALUE_2,
+ STR_VALUE_3, STR_VALUE_4, STR_VALUE_5 };
+ verifyAddAll(result, check, strings);
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder addAll(JsonArrayBuilder)} method on
+ * {@code int) array. @param result Test suite result.
+ */
+ private void testAddAllInt(final TestResult result) {
+ System.out.println(" - addAll(JsonArrayBuilder) for int array");
+ final JsonArray check = createSimpleIntArray5();
+ final Integer[] ints = new Integer[] { INT_VALUE_1, INT_VALUE_2,
+ INT_VALUE_3, INT_VALUE_4, INT_VALUE_5 };
+ verifyAddAll(result, check, ints);
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder addAll(JsonArrayBuilder)} method on
+ * {@code boolean) array. @param result Test suite result.
+ */
+ private void testAddAllBool(final TestResult result) {
+ System.out.println(" - addAll(JsonArrayBuilder) for boolean array");
+ final JsonArray check = createSimpleBoolArray5();
+ final Boolean[] bools = new Boolean[] { BOOL_FALSE, BOOL_TRUE, BOOL_TRUE,
+ BOOL_FALSE, BOOL_TRUE };
+ verifyAddAll(result, check, bools);
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder addAll(JsonArrayBuilder)} method on
+ * {@code JsonObject) array. @param result Test suite result.
+ */
+ private void testAddAllObject(final TestResult result) {
+ System.out.println(" - addAll(JsonArrayBuilder) for JsonObject array");
+ final JsonArray check = createSimpleObjectArray5();
+ final JsonObject[] bools = new JsonObject[] { OBJ_VALUE_1, OBJ_VALUE_2,
+ OBJ_VALUE_3, OBJ_VALUE_4, OBJ_VALUE_5 };
+ verifyAddAll(result, check, bools);
+ }
+
+ /**
+ * Test {@code JsonArrayBuilder addAll(JsonArrayBuilder)} method on
+ * {@code null} builder argument.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testAddAllNull(final TestResult result) {
+ System.out.println(" - addAll(JsonArrayBuilder) for null builder argument");
+ JsonArrayBuilder builder = Json.createArrayBuilder();
+ try {
+ builder.addAll((JsonArrayBuilder) null);
+ result.fail("addAll(null)",
+ "Calling method with null argument shall throw NullPointerException");
+ } catch (NullPointerException e) {
+ System.out.println(" - Expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("addAll(null)",
+ "Calling method with null argument shall throw NullPointerException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+
+ /**
+ * Test helper: Verify
+ * {@code default JsonArrayBuilder addAll(JsonArrayBuilder)} method on
+ * provided array.
+ *
+ * @param result
+ * Test suite result.
+ * @param check
+ * Expected value (used for operation check).
+ * @param values
+ * Values used to build JSON array builder.
+ */
+ private void verifyAddAll(final TestResult result, final JsonArray check,
+ final Object[] values) {
+ JsonArrayBuilder builderIn = Json.createArrayBuilder();
+ for (Object value : values) {
+ builderIn = updateOperationBuilder(builderIn, value);
+ }
+ final JsonArrayBuilder builderOut = Json.createArrayBuilder();
+ builderOut.addAll(builderIn);
+ final JsonArray out = builderOut.build();
+ if (operationFailed(check, out)) {
+ result.fail("addAll(JsonArrayBuilder)", "Output builder "
+ + valueToString(out) + " value shall be " + valueToString(check));
+ }
+ }
+
+ /**
+ * Test helper: Verify
+ * {@code default JsonArrayBuilder add(int,JsonArrayBuilder)} method on
+ * provided builders.
+ *
+ * @param result
+ * Test suite result.
+ * @param check
+ * Expected value (used for operation check).
+ * @param src
+ * Source builder (the one to be added).
+ * @param target
+ * Target builder (to which to add).
+ */
+ private void verifyAddBuilder(final TestResult result, final JsonValue check,
+ final int index, final JsonArrayBuilder src,
+ final JsonArrayBuilder target) {
+ final JsonArray out = target.add(index, src).build();
+ if (operationFailed(check, out)) {
+ result.fail("add(int,JsonArrayBuilder)", "Output builder "
+ + valueToString(out) + " value shall be " + valueToString(check));
+ }
+ }
+
+ /**
+ * Test helper: Verify
+ * {@code default JsonArrayBuilder add(int,JsonObjectBuilder)} method on
+ * provided builders.
+ *
+ * @param result
+ * Test suite result.
+ * @param check
+ * Expected value (used for operation check).
+ * @param src
+ * Source builder (the one to be added).
+ * @param target
+ * Target builder (to which to add).
+ */
+ private void verifyAddBuilder(final TestResult result, final JsonValue check,
+ final int index, final JsonObjectBuilder src,
+ final JsonArrayBuilder target) {
+ final JsonArray out = target.add(index, src).build();
+ if (operationFailed(check, out)) {
+ result.fail("add(int,JsonObjectBuilder)", "Output builder "
+ + valueToString(out) + " value shall be " + valueToString(check));
+ }
+ }
+
+ /**
+ * Create and initialize array builder to contain single value. Child class
+ * callback.
+ *
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder containing value.
+ */
+ @Override
+ protected JsonArrayBuilder createArrayBuilder(final Object value) {
+ return ArrayBuilder.add(Json.createArrayBuilder(), value);
+ }
+
+ /**
+ * Create and initialize array builder to contain single value. Child class
+ * callback.
+ *
+ * @param index
+ * Position in the array where value is added.
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder containing value.
+ */
+ @Override
+ protected JsonArrayBuilder createArrayBuilder(final int index,
+ final Object value) {
+ return ArrayBuilder.add(Json.createArrayBuilder(), index, value);
+ }
+
+ /**
+ * Update array builder to contain next value. Child class callback.
+ *
+ * @param builder
+ * JSON array builder to update.
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder with value updated.
+ */
+ @Override
+ protected JsonArrayBuilder updateOperationBuilder(
+ final JsonArrayBuilder builder, final Object value) {
+ return ArrayBuilder.add(builder, value);
+ }
+
+ /**
+ * Update array builder to contain next value. Child class callback.
+ *
+ * @param builder
+ * JSON array builder to update.
+ * @param index
+ * Position in the array where value is added.
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder with value updated.
+ */
+ @Override
+ protected JsonArrayBuilder updateOperationBuilder(
+ final JsonArrayBuilder builder, final int index, final Object value) {
+ return ArrayBuilder.add(builder, index, value);
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuildRemove.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuildRemove.java
new file mode 100644
index 00000000..2f5b061d
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuildRemove.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.jsonarraytests;
+
+import jakarta.jsonp.tck.api.common.ArrayBuilder;
+import jakarta.jsonp.tck.api.common.JsonIO;
+import jakarta.jsonp.tck.api.common.JsonValueType;
+import jakarta.jsonp.tck.api.common.TestResult;
+import jakarta.json.Json;
+import jakarta.json.JsonArrayBuilder;
+import jakarta.json.JsonValue;
+
+import static jakarta.jsonp.tck.api.common.JsonAssert.*;
+import static jakarta.jsonp.tck.api.common.SimpleValues.*;
+
+// $Id$
+/**
+ * JavaScript Object Notation (JSON) compatibility tests:
+ * {@link JsonArrayBuilder} API remove() methods added in JSON-P 1.1.
+ */
+public class ArrayBuildRemove extends ArrayCommon {
+
+ /**
+ * Creates an instance of {@link JsonArrayBuilder} API remove() methods added
+ * in JSON-P 1.1 test.
+ */
+ ArrayBuildRemove() {
+ super();
+ }
+
+ /**
+ * {@link JsonArrayBuilder} API remove() methods added in JSON-P 1.1.
+ *
+ * @return Result of all tests in this suite.
+ */
+ TestResult test() {
+ final TestResult result = new TestResult(
+ "JsonArrayBuilder API remove() methods added in JSON-P 1.1.");
+ System.out.println("JsonArrayBuilder API remove() methods added in JSON-P 1.1.");
+ testRemove(result);
+ testRemoveOutOfBounds(result);
+ return result;
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder remove(int, Object)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testRemove(final TestResult result) {
+ final Object[] values = new Object[] { OBJ_VALUE, // remove(int,JsonValue)
+ STR_VALUE, // remove(int,String)
+ INT_VALUE, // remove(int,int)
+ LNG_VALUE, // remove(int,long)
+ DBL_VALUE, // remove(int,double)
+ BIN_VALUE, // remove(int,BigInteger)
+ BDC_VALUE, // remove(int,BigDecimal)
+ BOOL_VALUE // remove(int,boolean)
+ };
+ for (Object value : values) {
+ final String typeName = JsonValueType.getType(value).name();
+ System.out.println(" - remove(int," + typeName + ")");
+ final String json = "[]";
+ final JsonValue check = JsonIO.read(json);
+ JsonArrayBuilder builder = ArrayBuilder.add(Json.createArrayBuilder(),
+ value);
+ builder = updateOperationBuilder(builder, 0, null);
+ final JsonValue out = builder.build();
+ if (operationFailed(check, out)) {
+ result.fail("remove(" + typeName + ")", "Builder output "
+ + valueToString(out) + " value shall be " + valueToString(check));
+ }
+ }
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder remove(int, Object)} method on
+ * {@code String} array with index being out of range
+ * ({@code index < 0 || index > array size}).
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testRemoveOutOfBounds(final TestResult result) {
+ final Object[] values = new Object[] { OBJ_VALUE, // remove(int,JsonValue)
+ STR_VALUE, // remove(int,String)
+ INT_VALUE, // remove(int,int)
+ LNG_VALUE, // remove(int,long)
+ DBL_VALUE, // remove(int,double)
+ BIN_VALUE, // remove(int,BigInteger)
+ BDC_VALUE, // remove(int,BigDecimal)
+ BOOL_VALUE // remove(int,boolean)
+ };
+ final int[] indexes = new int[] { -1, 2, 3 };
+ for (Object value : values) {
+ final String typeName = JsonValueType.getType(value).name();
+ System.out.println(" - remove(int," + typeName + ")");
+ final String json = "[" + JsonValueType.toStringValue(value) + "]";
+ // Add value into the array for the first time to het array of size 1.
+ JsonArrayBuilder builder = ArrayBuilder.add(Json.createArrayBuilder(),
+ value);
+ for (int index : indexes) {
+ try {
+ // Add value on out of bounds index
+ builder = updateOperationBuilder(builder, index, null);
+ result.fail("remove(int," + typeName + ")",
+ "Calling method with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ System.out.println(" - Expected exception for index=" + index + ": "
+ + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("remove(int,(" + typeName + ")null)",
+ "Calling method with with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ /**
+ * Create and initialize array builder. Unsupported method call for remove()
+ * method.
+ *
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder containing value.
+ */
+ @Override
+ protected JsonArrayBuilder createArrayBuilder(Object value) {
+ throw new UnsupportedOperationException(
+ "Method remove is not implemented.");
+ }
+
+ /**
+ * Create and initialize array builder. Unsupported method call for remove()
+ * method.
+ *
+ * @param index
+ * Position in the array where value is added.
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder containing value.
+ */
+ @Override
+ protected JsonArrayBuilder createArrayBuilder(final int index,
+ final Object value) {
+ throw new UnsupportedOperationException(
+ "Method remove is not implemented.");
+ }
+
+ /**
+ * Update array builder. Unsupported method call for remove() method.
+ *
+ * @param builder
+ * JSON array builder to update.
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder with value updated.
+ */
+ @Override
+ protected JsonArrayBuilder updateOperationBuilder(JsonArrayBuilder builder,
+ Object value) {
+ throw new UnsupportedOperationException(
+ "Method remove is not implemented.");
+ }
+
+ /**
+ * Update array builder with value removal at specified index. Child class
+ * callback.
+ *
+ * @param builder
+ * JSON array builder to update.
+ * @param index
+ * Position in the array where value is added.
+ * @param value
+ * JSON value argument is ignored.
+ * @return JSON array builder with value updated.
+ */
+ @Override
+ protected JsonArrayBuilder updateOperationBuilder(
+ final JsonArrayBuilder builder, final int index, final Object value) {
+ return ArrayBuilder.remove(builder, index);
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuildSet.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuildSet.java
new file mode 100644
index 00000000..e41ebe19
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuildSet.java
@@ -0,0 +1,494 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.jsonarraytests;
+
+import jakarta.jsonp.tck.api.common.ArrayBuilder;
+import jakarta.jsonp.tck.api.common.JsonIO;
+import jakarta.jsonp.tck.api.common.JsonValueType;
+import jakarta.jsonp.tck.api.common.TestResult;
+import jakarta.json.Json;
+import jakarta.json.JsonArray;
+import jakarta.json.JsonArrayBuilder;
+import jakarta.json.JsonObjectBuilder;
+import jakarta.json.JsonValue;
+
+import static jakarta.jsonp.tck.api.common.JsonAssert.*;
+import static jakarta.jsonp.tck.api.common.SimpleValues.*;
+
+// $Id$
+/**
+ * JavaScript Object Notation (JSON) compatibility tests:
+ * {@link JsonArrayBuilder} API set() methods added in JSON-P 1.1.
+ */
+public class ArrayBuildSet extends ArrayCommon {
+
+ /**
+ * Creates an instance of {@link JsonArrayBuilder} API set() methods added in
+ * JSON-P 1.1 test.
+ */
+ ArrayBuildSet() {
+ super();
+ }
+
+ /**
+ * {@link JsonArrayBuilder} API set() methods added in JSON-P 1.1.
+ *
+ * @return Result of all tests in this suite.
+ */
+ TestResult test() {
+ final TestResult result = new TestResult(
+ "JsonArrayBuilder API set() methods added in JSON-P 1.1.");
+ System.out.println("JsonArrayBuilder API set() methods added in JSON-P 1.1.");
+ testSet(result);
+ testSetOutOfBounds(result);
+ testSetNullBuilder(result);
+ testSetNull(result);
+ testSetNullOutOfBounds(result);
+ testSetArrayBuilder(result);
+ testSetArrayBuilderNull(result);
+ testSetArrayBuilderOutOfBounds(result);
+ testSetObjectBuilder(result);
+ testSetObjectBuilderNull(result);
+ testSetObjectBuilderOutOfBounds(result);
+ return result;
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder set(int, Object)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSet(final TestResult result) {
+ final Object[] values = new Object[] { OBJ_VALUE, // set(int,JsonValue)
+ STR_VALUE, // set(int,String)
+ INT_VALUE, // set(int,int)
+ LNG_VALUE, // set(int,long)
+ DBL_VALUE, // set(int,double)
+ BIN_VALUE, // set(int,BigInteger)
+ BDC_VALUE, // set(int,BigDecimal)
+ BOOL_VALUE // set(int,boolean)
+ };
+ for (Object value : values) {
+ final String typeName = JsonValueType.getType(value).name();
+ System.out.println(" - set(int," + typeName + ")");
+ final String json = "[" + JsonValueType.toStringValue(value) + "]";
+ final JsonValue check = JsonIO.read(json);
+ final JsonArrayBuilder builder = updateOperationBuilder(
+ Json.createArrayBuilder().add(DEF_OBJ_VALUE), 0, value);
+ final JsonValue out = builder.build();
+ if (operationFailed(check, out)) {
+ result.fail("set(" + typeName + ")", "Builder output "
+ + valueToString(out) + " value shall be " + valueToString(check));
+ }
+ }
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder set(int, Object)} method on
+ * {@code String} array with index being out of range
+ * ({@code index < 0 || index > array size}).
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetOutOfBounds(final TestResult result) {
+ final Object[] values = new Object[] { OBJ_VALUE, // set(int,JsonValue)
+ STR_VALUE, // set(int,String)
+ INT_VALUE, // set(int,int)
+ LNG_VALUE, // set(int,long)
+ DBL_VALUE, // set(int,double)
+ BIN_VALUE, // set(int,BigInteger)
+ BDC_VALUE, // set(int,BigDecimal)
+ BOOL_VALUE // set(int,boolean)
+ };
+ final int[] indexes = new int[] { -1, 2, 3 };
+ for (Object value : values) {
+ final String typeName = JsonValueType.getType(value).name();
+ System.out.println(" - set(int," + typeName + ")");
+ final String json = "[" + JsonValueType.toStringValue(value) + "]";
+ JsonArrayBuilder builder = ArrayBuilder.add(Json.createArrayBuilder(),
+ DEF_OBJ_VALUE);
+ for (int index : indexes) {
+ try {
+ builder = updateOperationBuilder(
+ Json.createArrayBuilder().add(DEF_OBJ_VALUE), index, value);
+ } catch (IndexOutOfBoundsException e) {
+ System.out.println(" - Expected exception for index=" + index + ": "
+ + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("set(int," + typeName + ")",
+ "Calling method with with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder set(int, Object)} method on
+ * {@code String} array with null value.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetNullBuilder(final TestResult result) {
+ final JsonValueType[] types = new JsonValueType[] { JsonValueType.JsonValue, // set(int,(JsonValue)null)
+ JsonValueType.String, // set(int,(String)null)
+ JsonValueType.BigInteger, // set(int,(BigInteger)null)
+ JsonValueType.BigDecimal // set(int,(BigDecimal)null)
+ };
+ for (JsonValueType type : types) {
+ final String typeName = type.name();
+ System.out.println(" - set(int,(" + typeName + ")null)");
+ try {
+ ArrayBuilder.set(Json.createArrayBuilder(), 0, type);
+ result.fail("set(int,(" + typeName + ")null)",
+ "Calling method with null argument shall throw NullPointerException");
+ } catch (NullPointerException e) {
+ System.out.println(" - Expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("set(int,(" + typeName + ")null)",
+ "Calling method with null argument shall throw NullPointerException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder setNull(int)} method on {@code String}
+ * array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetNull(final TestResult result) {
+ System.out.println(" - setNull(int)");
+ final Object value = null;
+ final String json = "[" + JsonValueType.toStringValue(null) + "]";
+ final JsonValue check = JsonIO.read(json);
+ final JsonArrayBuilder builder = ArrayBuilder
+ .set(Json.createArrayBuilder().add(DEF_OBJ_VALUE), 0, value);
+ final JsonValue out = builder.build();
+ if (operationFailed(check, out)) {
+ result.fail("setNull(int)", "Builder output " + valueToString(out)
+ + " value shall be " + valueToString(check));
+ }
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder setNull(int)} method on {@code String}
+ * array with index being out of range
+ * ({@code index < 0 || index > array size}).
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetNullOutOfBounds(final TestResult result) {
+ final int[] indexes = new int[] { -1, 2, 3 };
+ System.out.println(" - setNull(int)");
+ final Object value = null;
+ JsonArrayBuilder builder = ArrayBuilder.add(Json.createArrayBuilder(),
+ value);
+ for (int index : indexes) {
+ try {
+ // Add value on out of bounds index
+ builder = updateOperationBuilder(builder, index, value);
+ result.fail("setNull(int)", "Calling method with out of bounds index="
+ + index + " argument shall throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ System.out.println(" - Expected exception for index=" + index + ": "
+ + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("setNull(int)",
+ "Calling method with with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder set(int,JsonArrayBuilder)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetArrayBuilder(final TestResult result) {
+ System.out.println(" - set(int,JsonArrayBuilder)");
+ final JsonValue check = JsonIO
+ .read("[[" + JsonValueType.toStringValue(STR_VALUE_1) + ","
+ + JsonValueType.toStringValue(STR_VALUE_2) + ","
+ + JsonValueType.toStringValue(STR_VALUE_3) + ","
+ + JsonValueType.toStringValue(STR_VALUE_4) + "]]");
+ final JsonArrayBuilder in = Json.createArrayBuilder().add(STR_VALUE_5);
+ final JsonArrayBuilder arg = Json.createArrayBuilder().add(STR_VALUE_1)
+ .add(STR_VALUE_2).add(STR_VALUE_3).add(STR_VALUE_4);
+ verifySetBuilder(result, check, 0, arg, in);
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder set(int,(JsonArrayBuilder)null)}
+ * method on {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetArrayBuilderNull(final TestResult result) {
+ System.out.println(" - set(int,(JsonArrayBuilder)null)");
+ final JsonArrayBuilder in = Json.createArrayBuilder().add(DEF_VALUE);
+ final JsonArrayBuilder arg = null;
+ try {
+ in.set(0, arg);
+ result.fail("set(int,(JsonArrayBuilder)null)",
+ "Calling method with null argument shall throw NullPointerException");
+ } catch (NullPointerException e) {
+ System.out.println(" - Expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("set(int,(JsonArrayBuilder)null)",
+ "Calling method with null argument shall throw NullPointerException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder set(int,JsonArrayBuilder)} method on
+ * {@code String} array with index being out of range
+ * ({@code index < 0 || index > array size}).
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetArrayBuilderOutOfBounds(final TestResult result) {
+ System.out.println(" - set(int,JsonArrayBuilder)");
+ final int[] indexes = new int[] { -1, 5, 6 };
+ final JsonArrayBuilder in = Json.createArrayBuilder().add(STR_VALUE_1)
+ .add(STR_VALUE_2).add(STR_VALUE_3).add(STR_VALUE_4);
+ final JsonArrayBuilder arg = Json.createArrayBuilder().add(STR_VALUE_5);
+ for (int index : indexes) {
+ try {
+ // Add value on out of bounds index
+ in.set(index, arg);
+ result.fail("set(int,JsonArrayBuilder)",
+ "Calling method with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ System.out.println(" - Expected exception for index=" + index + ": "
+ + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("set(int,JsonArrayBuilder)",
+ "Calling method with with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder set(int,JsonObjectBuilder)} method on
+ * {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetObjectBuilder(final TestResult result) {
+ System.out.println(" - set(int,JsonObjectBuilder)");
+ final JsonValue check = JsonIO
+ .read("[{" + JsonValueType.toStringValue(STR_NAME) + ":"
+ + JsonValueType.toStringValue(STR_VALUE) + "}]");
+ final JsonArrayBuilder in = Json.createArrayBuilder().add(STR_VALUE_1);
+ final JsonObjectBuilder arg = Json.createObjectBuilder().add(STR_NAME,
+ STR_VALUE);
+ verifySetBuilder(result, check, 0, arg, in);
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder set(int,(JsonObjectBuilder)null)}
+ * method on {@code String} array.
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetObjectBuilderNull(final TestResult result) {
+ System.out.println(" - set(int,(JsonObjectBuilder)null)");
+ final JsonArrayBuilder in = Json.createArrayBuilder().add(DEF_VALUE);
+ final JsonObjectBuilder arg = null;
+ try {
+ in.set(0, arg);
+ result.fail("set(int,(JsonObjectBuilder)null)",
+ "Calling method with null argument shall throw NullPointerException");
+ } catch (NullPointerException e) {
+ System.out.println(" - Expected exception: " + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("set(int,(JsonObjectBuilder)null)",
+ "Calling method with null argument shall throw NullPointerException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+
+ /**
+ * Test {@code default JsonArrayBuilder set(int,JsonObjectBuilder)} method on
+ * {@code String} array with index being out of range
+ * ({@code index < 0 || index > array size}).
+ *
+ * @param result
+ * Test suite result.
+ */
+ private void testSetObjectBuilderOutOfBounds(final TestResult result) {
+ System.out.println(" - set(int,JsonObjectBuilder)");
+ final int[] indexes = new int[] { -1, 5, 6 };
+ final JsonArrayBuilder in = Json.createArrayBuilder().add(STR_VALUE_1)
+ .add(STR_VALUE_2).add(STR_VALUE_3).add(STR_VALUE_4);
+ final JsonObjectBuilder arg = Json.createObjectBuilder().add(STR_NAME,
+ STR_VALUE);
+ for (int index : indexes) {
+ try {
+ // Add value on out of bounds index
+ in.set(index, arg);
+ result.fail("set(int,JsonObjectBuilder)",
+ "Calling method with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ System.out.println(" - Expected exception for index=" + index + ": "
+ + e.getMessage());
+ } catch (Throwable t) {
+ result.fail("set(int,JsonObjectBuilder)",
+ "Calling method with with out of bounds index=" + index
+ + " argument shall throw IndexOutOfBoundsException, not "
+ + t.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /**
+ * Test helper: Verify
+ * {@code default JsonArrayBuilder set(int,JsonArrayBuilder)} method on
+ * provided builders.
+ *
+ * @param result
+ * Test suite result.
+ * @param check
+ * Expected value (used for operation check).
+ * @param src
+ * Source builder (the one to be added).
+ * @param target
+ * Target builder (to which to add).
+ */
+ private void verifySetBuilder(final TestResult result, final JsonValue check,
+ final int index, final JsonArrayBuilder src,
+ final JsonArrayBuilder target) {
+ final JsonArray out = target.set(index, src).build();
+ if (operationFailed(check, out)) {
+ result.fail("set(int,JsonArrayBuilder)", "Output builder "
+ + valueToString(out) + " value shall be " + valueToString(check));
+ }
+ }
+
+ /**
+ * Test helper: Verify
+ * {@code default JsonArrayBuilder set(int,JsonObjectBuilder)} method on
+ * provided builders.
+ *
+ * @param result
+ * Test suite result.
+ * @param check
+ * Expected value (used for operation check).
+ * @param src
+ * Source builder (the one to be added).
+ * @param target
+ * Target builder (to which to add).
+ */
+ private void verifySetBuilder(final TestResult result, final JsonValue check,
+ final int index, final JsonObjectBuilder src,
+ final JsonArrayBuilder target) {
+ final JsonArray out = target.set(index, src).build();
+ if (operationFailed(check, out)) {
+ result.fail("set(int,JsonObjectBuilder)", "Output builder "
+ + valueToString(out) + " value shall be " + valueToString(check));
+ }
+ }
+
+ /**
+ * Create and initialize array builder to contain single value. Unsupported
+ * method call for set() method.
+ *
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder containing value.
+ */
+ @Override
+ protected JsonArrayBuilder createArrayBuilder(Object value) {
+ throw new UnsupportedOperationException("Method set is not implemented.");
+ }
+
+ /**
+ * Create and initialize array builder to contain single value. Child class
+ * callback.
+ *
+ * @param index
+ * Position in the array where value is added.
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder containing value.
+ */
+ @Override
+ protected JsonArrayBuilder createArrayBuilder(final int index,
+ final Object value) {
+ return ArrayBuilder.set(Json.createArrayBuilder(), index, value);
+ }
+
+ /**
+ * Update array builder to contain next value. Unsupported method call for
+ * set() method.
+ *
+ * @param builder
+ * JSON array builder to update.
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder with value updated.
+ */
+ @Override
+ protected JsonArrayBuilder updateOperationBuilder(JsonArrayBuilder builder,
+ Object value) {
+ throw new UnsupportedOperationException("Method set is not implemented.");
+ }
+
+ /**
+ * Update array builder to contain next value. Child class callback.
+ *
+ * @param builder
+ * JSON array builder to update.
+ * @param index
+ * Position in the array where value is added.
+ * @param value
+ * JSON value stored in the builder. Value of {@code null} is stored
+ * as JSON {@code null} keyword.
+ * @return JSON array builder with value updated.
+ */
+ @Override
+ protected JsonArrayBuilder updateOperationBuilder(
+ final JsonArrayBuilder builder, final int index, final Object value) {
+ return ArrayBuilder.set(builder, index, value);
+ }
+
+}
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuilders.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuilders.java
new file mode 100644
index 00000000..9a71d271
--- /dev/null
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsonarraytests/ArrayBuilders.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package jakarta.jsonp.tck.api.jsonarraytests;
+
+import jakarta.jsonp.tck.api.common.TestResult;
+import java.util.ArrayList;
+import jakarta.json.Json;
+import jakarta.json.JsonArray;
+import jakarta.json.JsonArrayBuilder;
+import jakarta.json.JsonString;
+import jakarta.json.JsonValue;
+
+import static jakarta.jsonp.tck.api.common.JsonAssert.*;
+import static jakarta.jsonp.tck.api.common.SimpleValues.*;
+import java.util.Iterator;
+import java.util.List;
+import jakarta.json.JsonNumber;
+
+// $Id$
+/**
+ * JavaScript Object Notation (JSON) compatibility tests:
+ * {@link JsonArrayBuilder} API factory methods added in JSON-P 1.1.
+ */
+public class ArrayBuilders {
+
+ /**
+ * Creates an instance of {@link JsonArrayBuilder} API factory methods added
+ * in JSON-P 1.1 test.
+ */
+ ArrayBuilders() {
+ super();
+ }
+
+ /**
+ * Test {@link JsonArrayBuilder} factory method added in JSON-P 1.1.
+ *
+ * @return Result of all tests in this suite.
+ */
+ TestResult test() {
+ final TestResult result = new TestResult(
+ "JsonArrayBuilder API factory methods added in JSON-P 1.1.");
+ System.out.println("JsonArrayBuilder API factory methods added in JSON-P 1.1.");
+ testCreateFromCollection(result);
+ testCreateFromJsonArray(result);
+ testGetStringValuesAs(result);
+ testGetIntValuesAs(result);
+ return result;
+ }
+
+ /**
+ * Test {@link Json#createArrayBuilder(Collection