Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-data-codec-gson / src / test / java / org / opendaylight / yangtools / yang / data / codec / gson / YT1029Test.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.codec.gson;
9
10 import static org.junit.Assert.assertEquals;
11
12 import java.io.IOException;
13 import java.io.StringWriter;
14 import java.io.Writer;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
17 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19
20 public class YT1029Test extends AbstractComplexJsonTest {
21     @Test
22     public void testMultipleRootChildren() throws IOException {
23         final Writer writer = new StringWriter();
24         final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter(
25             lhotkaCodecFactory, SchemaPath.ROOT, null, JsonWriterFactory.createJsonWriter(writer, 2));
26         try (NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream)) {
27             nodeWriter.write(CONT1_WITH_EMPTYLEAF);
28             nodeWriter.write(CONT1_WITH_EMPTYLEAF);
29         }
30
31         assertEquals("{\n"
32                 + "  \"complexjson:cont1\": {\n"
33                 + "    \"empty\": [\n"
34                 + "      null\n"
35                 + "    ]\n"
36                 + "  },\n"
37                 + "  \"complexjson:cont1\": {\n"
38                 + "    \"empty\": [\n"
39                 + "      null\n"
40                 + "    ]\n"
41                 + "  }\n"
42                 + "}", writer.toString());
43     }
44 }