be4c565546b36e3c51c539f823b0aaebb604ac2f
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / rfc8040 / databind / AbstractOperationInputBodyTest.java
1 /*
2  * Copyright (c) 2023 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.databind;
9
10 import static org.junit.Assert.assertEquals;
11
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14 import org.opendaylight.restconf.nb.rfc8040.AbstractInstanceIdentifierTest;
15 import org.opendaylight.restconf.server.api.DatabindContext;
16 import org.opendaylight.restconf.server.api.OperationsPostPath;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.Uint32;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
20 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
21 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
22 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23
24 abstract class AbstractOperationInputBodyTest extends AbstractInstanceIdentifierTest {
25     private static final NodeIdentifier INPUT_NID = new NodeIdentifier(QName.create(CONT_QNAME, "input"));
26
27     private static OperationsPostPath RESET_PATH;
28
29     @BeforeClass
30     public static final void setupInference() {
31         final var stack = SchemaInferenceStack.ofDataTreePath(IID_SCHEMA, CONT_QNAME, CONT1_QNAME);
32         stack.enterSchemaTree(RESET_QNAME);
33         RESET_PATH = new OperationsPostPath(IID_DATABIND, stack.toInference());
34     }
35
36     @Test
37     public final void moduleSubContainerDataPostActionTest() throws Exception {
38         final var body = moduleSubContainerDataPostActionBody();
39
40         assertEquals(ImmutableNodes.newContainerBuilder()
41             .withNodeIdentifier(INPUT_NID)
42             .withChild(ImmutableNodes.leafNode(DELAY_QNAME, Uint32.valueOf(600)))
43             .build(), body.toContainerNode(RESET_PATH));
44     }
45
46     abstract OperationInputBody moduleSubContainerDataPostActionBody();
47
48     @Test
49     public final void testEmpty() throws Exception {
50         final var body = testEmptyBody();
51         assertEquals(ImmutableNodes.newContainerBuilder().withNodeIdentifier(INPUT_NID).build(),
52             body.toContainerNode(RESET_PATH));
53     }
54
55     abstract OperationInputBody testEmptyBody();
56
57     @Test
58     public final void testRpcModuleInput() throws Exception {
59         final var rpcTest = QName.create("invoke:rpc:module", "2013-12-03", "rpc-test");
60         final var modelContext = YangParserTestUtils.parseYangResourceDirectory("/invoke-rpc");
61         final var stack = SchemaInferenceStack.of(modelContext);
62         stack.enterSchemaTree(rpcTest);
63
64         final var body = testRpcModuleInputBody();
65
66         assertEquals(ImmutableNodes.newContainerBuilder()
67             .withNodeIdentifier(new NodeIdentifier(QName.create(rpcTest, "input")))
68             .withChild(ImmutableNodes.newContainerBuilder()
69                 .withNodeIdentifier(new NodeIdentifier(QName.create(rpcTest, "cont")))
70                 .withChild(ImmutableNodes.leafNode(QName.create(rpcTest, "lf"), "lf-test"))
71                 .build())
72             .build(),
73             body.toContainerNode(new OperationsPostPath(DatabindContext.ofModel(modelContext), stack.toInference())));
74     }
75
76     abstract OperationInputBody testRpcModuleInputBody();
77 }