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.impl.schema.Builders;
21 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
22 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 abstract class AbstractOperationInputBodyTest extends AbstractInstanceIdentifierTest {
26 private static final NodeIdentifier INPUT_NID = new NodeIdentifier(QName.create(CONT_QNAME, "input"));
28 private static OperationsPostPath RESET_PATH;
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());
38 public final void moduleSubContainerDataPostActionTest() throws Exception {
39 final var body = moduleSubContainerDataPostActionBody();
41 assertEquals(Builders.containerBuilder()
42 .withNodeIdentifier(INPUT_NID)
43 .withChild(ImmutableNodes.leafNode(DELAY_QNAME, Uint32.valueOf(600)))
44 .build(), body.toContainerNode(RESET_PATH));
47 abstract OperationInputBody moduleSubContainerDataPostActionBody();
50 public final void testEmpty() throws Exception {
51 final var body = testEmptyBody();
52 assertEquals(Builders.containerBuilder().withNodeIdentifier(INPUT_NID).build(),
53 body.toContainerNode(RESET_PATH));
56 abstract OperationInputBody testEmptyBody();
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);
65 final var body = testRpcModuleInputBody();
67 assertEquals(Builders.containerBuilder()
68 .withNodeIdentifier(new NodeIdentifier(QName.create(rpcTest, "input")))
69 .withChild(Builders.containerBuilder()
70 .withNodeIdentifier(new NodeIdentifier(QName.create(rpcTest, "cont")))
71 .withChild(ImmutableNodes.leafNode(QName.create(rpcTest, "lf"), "lf-test"))
74 body.toContainerNode(new OperationsPostPath(DatabindContext.ofModel(modelContext), stack.toInference())));
77 abstract OperationInputBody testRpcModuleInputBody();