Rework body formatting wiring
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / jaxrs / 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.jaxrs;
9
10 import org.junit.jupiter.api.Test;
11 import org.junit.jupiter.api.extension.ExtendWith;
12 import org.mockito.junit.jupiter.MockitoExtension;
13 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
14 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
15
16 @ExtendWith(MockitoExtension.class)
17 class Netconf822Test extends AbstractRestconfTest {
18     private static final EffectiveModelContext MODEL_CONTEXT =
19         YangParserTestUtils.parseYangResourceDirectory("/nc822");
20
21     @Override
22     EffectiveModelContext modelContext() {
23         return MODEL_CONTEXT;
24     }
25
26     @Test
27     void testOperationsContent() {
28         final var body = assertFormattableBody(200, ar -> restconf.operationsGET(ar));
29
30         assertFormat("""
31             {
32               "ietf-restconf:operations" : {
33                 "foo:new" : [null],
34                 "foo:new1" : [null]
35               }
36             }""", body::formatToJSON, true);
37         assertFormat("""
38             <operations xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf">
39               <new xmlns="foo"/>
40               <new1 xmlns="foo"/>
41             </operations>""", body::formatToXML, true);
42     }
43
44     @Test
45     void testOperationsContentByIdentifier() {
46         final var body = assertFormattableBody(200, ar -> restconf.operationsGET(apiPath("foo:new1"), ar));
47
48         assertFormat("""
49             { "foo:new1" : [null] }""", body::formatToJSON, false);
50         assertFormat("""
51             <new1 xmlns="foo"/>""", body::formatToXML, false);
52     }
53 }