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