- private CompositeNode prepareData() {
- MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
- ModifyAction.CREATE, null);
-
- List<Node<?>> childNodes = new ArrayList<>();
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint8Min"), cont, (byte) -128,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint8Max"), cont, (byte) 127,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint16Min"), cont, (short) -32768,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint16Max"), cont, (short) 32767,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint32Min"), cont,
- (int) -2147483648, ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint32Max"), cont, (int) 2147483647,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint64Min"), cont, new Long(
- "-9223372036854775807"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint64Max"), cont, new Long(
- "9223372036854775807"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnuint8Max"), cont, (short) 255,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnuint16Max"), cont, (int) 65535,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnuint32Max"), cont, new Long(
- "4294967295"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfstr"), cont, "lfstr",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfstr1"), cont, "",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbool1"), cont, Boolean.TRUE,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbool2"), cont, Boolean.FALSE,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal1"), cont, new BigDecimal(
- "43.32"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal2"), cont, new BigDecimal(
- "-0.43"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal3"), cont, new BigDecimal(
- "43"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal4"), cont, new BigDecimal(
- "43E3"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal6"), cont, new BigDecimal(
- "33.12345"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfenum"), cont, "enum3",
- ModifyAction.CREATE, null));
-
- HashSet<String> bits = new HashSet<String>();
- bits.add("bit3");
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbits"), cont, bits,
- ModifyAction.CREATE, null));
-
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbinary"), cont, DatatypeConverter
- .parseBase64Binary("AAaacdabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"),
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfempty"), cont, null,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion1"), cont, (int) 324,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion2"), cont, new BigDecimal(
- "33.3"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion3"), cont, "55",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion4"), cont, Boolean.TRUE,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion5"), cont, "true",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion6"), cont, "false",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion7"), cont, null,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion8"), cont, "",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion9"), cont, "",
- ModifyAction.CREATE, null));
-
- HashSet<String> bits2 = new HashSet<String>();
- bits2.add("bt1");
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion10"), cont, bits2,
- ModifyAction.CREATE, null));
-
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion11"), cont, (short) 33,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion12"), cont, Boolean.FALSE,
- ModifyAction.CREATE, null));
- try {
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("identityref1"), cont, new QName(
- new URI("simple:data:types"), "iden"), ModifyAction.CREATE, null));
- } catch (URISyntaxException e) {
+ static class StringVerifier extends LeafVerifier {
+
+ StringVerifier(String expected) {
+ super(expected, JsonToken.STRING);
+ }
+
+ @Override
+ Object getActualValue(JsonReader reader) throws IOException {
+ return reader.nextString();
+ }
+ }
+
+ static class EmptyVerifier extends LeafVerifier {
+
+ EmptyVerifier() {
+ super(null, null);
+ }
+
+ @Override
+ Object getActualValue(JsonReader reader) throws IOException {
+ reader.beginArray();
+ reader.nextNull();
+ reader.endArray();
+ return null;
+ }
+
+ }
+
+ static class ComplexAnyXmlVerifier extends LeafVerifier {
+
+ ComplexAnyXmlVerifier() {
+ super(null, JsonToken.BEGIN_OBJECT);
+ }
+
+ @Override
+ void verify(JsonReader reader, String keyName) throws IOException {
+
+ reader.beginObject();
+ String innerKey = reader.nextName();
+ assertEquals("Json reader child key for " + keyName, "data", innerKey);
+ assertEquals("Json token type for key " + innerKey, JsonToken.BEGIN_OBJECT, reader.peek());
+
+ reader.beginObject();
+ verifyLeaf(reader, innerKey, "leaf1", "leaf1-value");
+ verifyLeaf(reader, innerKey, "leaf2", "leaf2-value");
+
+ String nextName = reader.nextName();
+ assertEquals("Json reader child key for " + innerKey, "leaf-list", nextName);
+ reader.beginArray();
+ assertEquals("Json value for key " + nextName, "leaf-list-value1", reader.nextString());
+ assertEquals("Json value for key " + nextName, "leaf-list-value2", reader.nextString());
+ reader.endArray();
+
+ nextName = reader.nextName();
+ assertEquals("Json reader child key for " + innerKey, "list", nextName);
+ reader.beginArray();
+ verifyNestedLists(reader, 1);
+ verifyNestedLists(reader, 3);
+ reader.endArray();
+
+ reader.endObject();
+ reader.endObject();
+ }
+
+ void verifyNestedLists(JsonReader reader, int leafNum) throws IOException {
+ reader.beginObject();
+
+ String nextName = reader.nextName();
+ assertEquals("Json reader next name", "nested-list", nextName);
+
+ reader.beginArray();
+
+ reader.beginObject();
+ verifyLeaf(reader, "nested-list", "nested-leaf", "nested-value" + leafNum++);
+ reader.endObject();
+
+ reader.beginObject();
+ verifyLeaf(reader, "nested-list", "nested-leaf", "nested-value" + leafNum);
+ reader.endObject();
+
+ reader.endArray();
+ reader.endObject();