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.spi.node.ImmutableNodes;
26 final class TestUtils {
27 private static final MapNode OUTER_LIST = ImmutableNodes.newSystemMapBuilder()
28 .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME))
29 .withChild(ImmutableNodes.newMapEntryBuilder()
30 .withNodeIdentifier(NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1))
31 .withChild(ImmutableNodes.leafNode(TestModel.ID_QNAME, 1))
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");
40 private static final MapEntryNode TOP_LEVEL_LIST_NODE = ImmutableNodes.newMapEntryBuilder()
41 .withNodeIdentifier(NodeIdentifierWithPredicates.of(
42 TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
43 .withChild(ImmutableNodes.leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
46 private static final MapNode CHILD_LIST = ImmutableNodes.newSystemMapBuilder()
47 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
48 .withChild(TOP_LEVEL_LIST_NODE)
51 static final ContainerNode TEST_CONTAINER = ImmutableNodes.newContainerBuilder()
52 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
53 .withChild(OUTER_LIST)
56 static final ContainerNode TEST_CHILD = ImmutableNodes.newContainerBuilder()
57 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
58 .withChild(CHILD_LIST)
61 static final String EXCEPTION_TEXT = "TestRpcImplementationException";
67 static MapEntryNode mapEntry(final QName listName, final QName keyName, final Object keyValue) {
68 return ImmutableNodes.newMapEntryBuilder()
69 .withNodeIdentifier(NodeIdentifierWithPredicates.of(listName, keyName, keyValue))
70 .withChild(ImmutableNodes.leafNode(keyName, keyValue))
74 static TestRpcImplementation getTestRpcImplementation() {
75 return new TestRpcImplementation();
78 private static final class TestRpcImplementation implements DOMRpcImplementation {
79 private final FluentFuture<DOMRpcResult> unknownRpc;
81 TestRpcImplementation() {
82 unknownRpc = FluentFutures.immediateFailedFluentFuture(
83 new DOMRpcImplementationNotAvailableException(EXCEPTION_TEXT));
87 public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
88 requireNonNull(input);