2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.restconf.nb.rfc8040.databind;
10 import static org.junit.Assert.assertEquals;
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;
24 abstract class AbstractOperationInputBodyTest extends AbstractInstanceIdentifierTest {
25 private static final NodeIdentifier INPUT_NID = new NodeIdentifier(QName.create(CONT_QNAME, "input"));
27 private static OperationsPostPath RESET_PATH;
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());
37 public final void moduleSubContainerDataPostActionTest() throws Exception {
38 final var body = moduleSubContainerDataPostActionBody();
40 assertEquals(ImmutableNodes.newContainerBuilder()
41 .withNodeIdentifier(INPUT_NID)
42 .withChild(ImmutableNodes.leafNode(DELAY_QNAME, Uint32.valueOf(600)))
43 .build(), body.toContainerNode(RESET_PATH));
46 abstract OperationInputBody moduleSubContainerDataPostActionBody();
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));
55 abstract OperationInputBody testEmptyBody();
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);
64 final var body = testRpcModuleInputBody();
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"))
73 body.toContainerNode(new OperationsPostPath(DatabindContext.ofModel(modelContext), stack.toInference())));
76 abstract OperationInputBody testRpcModuleInputBody();