Eliminate NormalizedNodePayload
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / server / spi / NormalizedFormattableBodyTest.java
1 /*
2  * Copyright (c) 2022 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.restconf.server.spi;
9
10 import org.junit.jupiter.api.Test;
11 import org.opendaylight.restconf.nb.rfc8040.AbstractInstanceIdentifierTest;
12 import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
13 import org.opendaylight.restconf.server.api.DatabindPath.Data;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
16 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 class NormalizedFormattableBodyTest extends AbstractInstanceIdentifierTest {
20     @Test
21     void testWriteEmptyRootContainer() throws Exception {
22         final var body = NormalizedFormattableBody.of(new Data(IID_DATABIND), ImmutableNodes.newContainerBuilder()
23             .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME))
24             .build(), NormalizedNodeWriterFactory.of());
25
26         // FIXME: NETCONF-855: this is wrong, the namespace should be 'urn:ietf:params:xml:ns:yang:ietf-restconf'
27         AbstractJukeboxTest.assertFormat("<data xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"></data>",
28             body::formatToXML, false);
29         AbstractJukeboxTest.assertFormat("{}", body::formatToJSON, false);
30     }
31
32     @Test
33     void testRootContainerWrite() throws Exception {
34         final var body = NormalizedFormattableBody.of(new Data(IID_DATABIND), ImmutableNodes.newContainerBuilder()
35             .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME))
36             .withChild(ImmutableNodes.newContainerBuilder()
37                 .withNodeIdentifier(new NodeIdentifier(
38                     QName.create("foo:module", "2016-09-29", "foo-bar-container")))
39                 .build())
40             .withChild(ImmutableNodes.newContainerBuilder()
41                 .withNodeIdentifier(new NodeIdentifier(
42                     QName.create("bar:module", "2016-09-29", "foo-bar-container")))
43                 .build())
44             .build(), NormalizedNodeWriterFactory.of());
45
46         // FIXME: NETCONF-855: this is wrong, the namespace should be 'urn:ietf:params:xml:ns:yang:ietf-restconf'
47         AbstractJukeboxTest.assertFormat("""
48             <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\
49             <foo-bar-container xmlns="bar:module"></foo-bar-container>\
50             <foo-bar-container xmlns="foo:module"></foo-bar-container>\
51             </data>""", body::formatToXML, false);
52         AbstractJukeboxTest.assertFormat("""
53             {"bar-module:foo-bar-container":{}}""", body::formatToJSON, false);
54     }
55 }