Document RestconfServer.invokeRpc()
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / Netconf822Test.java
1 /*
2  * Copyright (c) 2021 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.nb.rfc8040.rests.services.impl;
9
10 import static org.junit.Assert.assertEquals;
11
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
16 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
17 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
18 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
19
20 public class Netconf822Test {
21     private static final Absolute NEW1 = Absolute.of(QName.create("foo", "2021-09-30", "new1"));
22
23     private static EffectiveModelContext SCHEMA;
24
25     @BeforeClass
26     public static void beforeClass() {
27         SCHEMA = YangParserTestUtils.parseYangResourceDirectory("/nc822");
28     }
29
30     @Test
31     public void testOperationsContentJSON() {
32         assertEquals("""
33             {
34               "ietf-restconf:operations" : {
35                 "foo:new": [null],
36                 "foo:new1": [null]
37               }
38             }""", OperationsContent.JSON.bodyFor(SchemaInferenceStack.of(SCHEMA).toInference()));
39     }
40
41     @Test
42     public void testOperationsContentByIdentifierJSON() {
43         assertEquals("""
44             {
45               "ietf-restconf:operations" : {
46                 "foo:new1": [null]
47               }
48             }""", OperationsContent.JSON.bodyFor(SchemaInferenceStack.of(SCHEMA, NEW1).toInference()));
49     }
50
51     @Test
52     public void testOperationsContentXML() {
53         assertEquals("""
54             <?xml version="1.0" encoding="UTF-8"?>
55             <operations xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"
56                         xmlns:ns0="foo" >
57               <ns0:new/>
58               <ns0:new1/>
59             </operations>""", OperationsContent.XML.bodyFor(SchemaInferenceStack.of(SCHEMA).toInference()));
60     }
61
62     @Test
63     public void testOperationsContentByIdentifierXML() {
64         assertEquals("""
65             <?xml version="1.0" encoding="UTF-8"?>
66             <operations xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"
67                         xmlns:ns0="foo" >
68               <ns0:new1/>
69             </operations>""", OperationsContent.XML.bodyFor(SchemaInferenceStack.of(SCHEMA, NEW1).toInference()));
70     }
71 }