Revert "Update RPC invocation to take 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.mdsal.dom.broker.util.TestModel;
19 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
23 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
24 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
27 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
28 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
29
30 abstract class TestUtils {
31
32     private static final DataContainerChild<?, ?> OUTER_LIST = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
33             .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build();
34
35     private static final String TOP_LEVEL_LIST_FOO_KEY_VALUE = "foo";
36     private static final QName TOP_QNAME = TestModel.ID_QNAME;
37     private static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
38     private static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
39
40     private static final MapEntryNode TOP_LEVEL_LIST_NODE = ImmutableMapEntryNodeBuilder.create()
41             .withNodeIdentifier(
42                     NodeIdentifierWithPredicates.of(
43                             TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
44             .withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
45             .build();
46
47     private static final DataContainerChild<?, ?> CHILD_LIST = ImmutableNodes.mapNodeBuilder(TestModel.TEST_QNAME)
48             .withNodeIdentifier(NodeIdentifier.create(TestModel.TEST_QNAME))
49             .withChild(TOP_LEVEL_LIST_NODE)
50             .build();
51
52     static final NormalizedNode<?, ?> TEST_CONTAINER = Builders.containerBuilder()
53             .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
54             .withChild(OUTER_LIST)
55             .build();
56
57     static final NormalizedNode<?, ?> TEST_CHILD = Builders.containerBuilder()
58             .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
59             .withChild(CHILD_LIST)
60             .build();
61
62     static final String EXCEPTION_TEXT = "TestRpcImplementationException";
63
64     static TestRpcImplementation getTestRpcImplementation() {
65         return new TestRpcImplementation();
66     }
67
68     private static final class TestRpcImplementation implements DOMRpcImplementation {
69         private final FluentFuture<DOMRpcResult> unknownRpc;
70
71         TestRpcImplementation() {
72             unknownRpc = FluentFutures.immediateFailedFluentFuture(
73                     new DOMRpcImplementationNotAvailableException(EXCEPTION_TEXT));
74         }
75
76         @Override
77         public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
78             requireNonNull(input);
79             return unknownRpc;
80         }
81     }
82 }