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.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
13 import org.junit.jupiter.api.BeforeAll;
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.restconf.nb.rfc8040.AbstractInstanceIdentifierTest;
16 import org.opendaylight.restconf.server.api.DatabindContext;
17 import org.opendaylight.restconf.server.api.DatabindPath.Action;
18 import org.opendaylight.restconf.server.api.DatabindPath.Rpc;
19 import org.opendaylight.restconf.server.api.OperationInputBody;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.common.Uint32;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
24 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
25 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
27 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
28 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
30 abstract class AbstractOperationInputBodyTest extends AbstractInstanceIdentifierTest {
31 private static final NodeIdentifier INPUT_NID = new NodeIdentifier(QName.create(CONT_QNAME, "input"));
33 private static Action RESET_PATH;
36 static final void setupInference() {
37 final var stack = SchemaInferenceStack.ofDataTreePath(IID_SCHEMA, CONT_QNAME, CONT1_QNAME);
38 final var action = assertInstanceOf(ActionEffectiveStatement.class, stack.enterSchemaTree(RESET_QNAME));
40 RESET_PATH = new Action(IID_DATABIND, stack.toInference(), YangInstanceIdentifier.of(CONT_QNAME, CONT1_QNAME),
45 final void moduleSubContainerDataPostActionTest() throws Exception {
46 final var body = moduleSubContainerDataPostActionBody();
48 assertEquals(ImmutableNodes.newContainerBuilder()
49 .withNodeIdentifier(INPUT_NID)
50 .withChild(ImmutableNodes.leafNode(DELAY_QNAME, Uint32.valueOf(600)))
51 .build(), body.toContainerNode(RESET_PATH));
54 abstract OperationInputBody moduleSubContainerDataPostActionBody();
57 final void testEmpty() throws Exception {
58 final var body = testEmptyBody();
59 assertEquals(ImmutableNodes.newContainerBuilder().withNodeIdentifier(INPUT_NID).build(),
60 body.toContainerNode(RESET_PATH));
63 abstract OperationInputBody testEmptyBody();
66 final void testRpcModuleInput() throws Exception {
67 final var rpcTest = QName.create("invoke:rpc:module", "2013-12-03", "rpc-test");
68 final var modelContext = YangParserTestUtils.parseYangResourceDirectory("/invoke-rpc");
69 final var stack = SchemaInferenceStack.of(modelContext);
70 final var rpc = assertInstanceOf(RpcEffectiveStatement.class, stack.enterSchemaTree(rpcTest));
72 final var body = testRpcModuleInputBody();
74 assertEquals(ImmutableNodes.newContainerBuilder()
75 .withNodeIdentifier(new NodeIdentifier(QName.create(rpcTest, "input")))
76 .withChild(ImmutableNodes.newContainerBuilder()
77 .withNodeIdentifier(new NodeIdentifier(QName.create(rpcTest, "cont")))
78 .withChild(ImmutableNodes.leafNode(QName.create(rpcTest, "lf"), "lf-test"))
81 body.toContainerNode(new Rpc(DatabindContext.ofModel(modelContext), stack.toInference(), rpc)));
84 abstract OperationInputBody testRpcModuleInputBody();