DOM RPC invocation takes ContainerNode
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / TestUtils.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.dom.broker;
9
10 import static java.util.Objects.requireNonNull;
11 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
12
13 import com.google.common.util.concurrent.FluentFuture;
14 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
15 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
16 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
17 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
18 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
22 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
24 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
25 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
26 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
27 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
28
29 final class TestUtils {
30     private static final MapNode OUTER_LIST = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
31         .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1))
32         .build();
33
34     private static final String TOP_LEVEL_LIST_FOO_KEY_VALUE = "foo";
35     private static final QName TOP_QNAME = TestModel.ID_QNAME;
36     private static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
37     private static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
38
39     private static final MapEntryNode TOP_LEVEL_LIST_NODE = ImmutableMapEntryNodeBuilder.create()
40         .withNodeIdentifier(NodeIdentifierWithPredicates.of(
41             TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
42         .withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
43         .build();
44
45     private static final MapNode CHILD_LIST = ImmutableNodes.mapNodeBuilder(TestModel.TEST_QNAME)
46         .withNodeIdentifier(NodeIdentifier.create(TestModel.TEST_QNAME))
47         .withChild(TOP_LEVEL_LIST_NODE)
48         .build();
49
50     static final ContainerNode TEST_CONTAINER = Builders.containerBuilder()
51         .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
52         .withChild(OUTER_LIST)
53         .build();
54
55     static final ContainerNode TEST_CHILD = Builders.containerBuilder()
56         .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
57         .withChild(CHILD_LIST)
58         .build();
59
60     static final String EXCEPTION_TEXT = "TestRpcImplementationException";
61
62     private TestUtils() {
63         // Hidden on purpose
64     }
65
66     static TestRpcImplementation getTestRpcImplementation() {
67         return new TestRpcImplementation();
68     }
69
70     private static final class TestRpcImplementation implements DOMRpcImplementation {
71         private final FluentFuture<DOMRpcResult> unknownRpc;
72
73         TestRpcImplementation() {
74             unknownRpc = FluentFutures.immediateFailedFluentFuture(
75                     new DOMRpcImplementationNotAvailableException(EXCEPTION_TEXT));
76         }
77
78         @Override
79         public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
80             requireNonNull(input);
81             return unknownRpc;
82         }
83     }
84 }