2 * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.dom.broker;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.util.concurrent.FluentFuture;
13 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
14 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
15 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
16 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
17 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
21 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
24 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
25 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
27 final class TestUtils {
28 private static final MapNode OUTER_LIST = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
29 .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1))
32 private static final String TOP_LEVEL_LIST_FOO_KEY_VALUE = "foo";
33 private static final QName TOP_QNAME = TestModel.ID_QNAME;
34 private static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
35 private static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
37 private static final MapEntryNode TOP_LEVEL_LIST_NODE = Builders.mapEntryBuilder()
38 .withNodeIdentifier(NodeIdentifierWithPredicates.of(
39 TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
40 .withChild(ImmutableNodes.leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
43 private static final MapNode CHILD_LIST = ImmutableNodes.mapNodeBuilder(TestModel.TEST_QNAME)
44 .withNodeIdentifier(NodeIdentifier.create(TestModel.TEST_QNAME))
45 .withChild(TOP_LEVEL_LIST_NODE)
48 static final ContainerNode TEST_CONTAINER = Builders.containerBuilder()
49 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
50 .withChild(OUTER_LIST)
53 static final ContainerNode TEST_CHILD = Builders.containerBuilder()
54 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
55 .withChild(CHILD_LIST)
58 static final String EXCEPTION_TEXT = "TestRpcImplementationException";
64 static TestRpcImplementation getTestRpcImplementation() {
65 return new TestRpcImplementation();
68 private static final class TestRpcImplementation implements DOMRpcImplementation {
69 private final FluentFuture<DOMRpcResult> unknownRpc;
71 TestRpcImplementation() {
72 unknownRpc = FluentFutures.immediateFailedFluentFuture(
73 new DOMRpcImplementationNotAvailableException(EXCEPTION_TEXT));
77 public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
78 requireNonNull(input);