Change DOM invokeRpc to FluentFuture
[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
9 package org.opendaylight.mdsal.dom.broker;
10
11 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
12
13 import com.google.common.util.concurrent.FluentFuture;
14 import javax.annotation.Nonnull;
15 import javax.annotation.Nullable;
16 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
17 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
18 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
19 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
20 import org.opendaylight.mdsal.dom.broker.util.TestModel;
21 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
26 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
28 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
29 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
30 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
31
32 abstract class TestUtils {
33
34     private static final DataContainerChild<?, ?> OUTER_LIST = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
35             .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build();
36
37     private static final String TOP_LEVEL_LIST_FOO_KEY_VALUE = "foo";
38     private static final QName TOP_QNAME = TestModel.ID_QNAME;
39     private static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
40     private static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
41
42     private static final MapEntryNode TOP_LEVEL_LIST_NODE = ImmutableMapEntryNodeBuilder.create()
43             .withNodeIdentifier(
44                     new YangInstanceIdentifier.NodeIdentifierWithPredicates(
45                             TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
46             .withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
47             .build();
48
49     private static final DataContainerChild<?, ?> CHILD_LIST = ImmutableNodes.mapNodeBuilder(TestModel.TEST_QNAME)
50             .withNodeIdentifier(NodeIdentifier.create(TestModel.TEST_QNAME))
51             .withChild(TOP_LEVEL_LIST_NODE)
52             .build();
53
54     static final NormalizedNode<?, ?> TEST_CONTAINER = Builders.containerBuilder()
55             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
56             .withChild(OUTER_LIST)
57             .build();
58
59     static final NormalizedNode<?, ?> TEST_CHILD = Builders.containerBuilder()
60             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
61             .withChild(CHILD_LIST)
62             .build();
63
64     static final String EXCEPTION_TEXT = "TestRpcImplementationException";
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         private TestRpcImplementation() {
74             unknownRpc = FluentFutures.immediateFailedFluentFuture(
75                     new DOMRpcImplementationNotAvailableException(EXCEPTION_TEXT));
76         }
77
78         @Override
79         @Nonnull
80         public FluentFuture<DOMRpcResult> invokeRpc(@Nonnull final DOMRpcIdentifier rpc,
81                 @Nullable final NormalizedNode<?, ?> input) {
82             return unknownRpc;
83         }
84     }
85 }