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
9 package org.opendaylight.mdsal.dom.broker;
11 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
13 import com.google.common.util.concurrent.CheckedFuture;
14 import com.google.common.util.concurrent.Futures;
15 import javax.annotation.Nonnull;
16 import javax.annotation.Nullable;
17 import org.opendaylight.mdsal.dom.api.DOMRpcException;
18 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
19 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
20 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
21 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
22 import org.opendaylight.mdsal.dom.broker.util.TestModel;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
27 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
29 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
30 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
31 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
33 abstract class TestUtils {
35 private static final DataContainerChild<?, ?> OUTER_LIST = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
36 .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build();
38 private static final String TOP_LEVEL_LIST_FOO_KEY_VALUE = "foo";
39 private static final QName TOP_QNAME = TestModel.ID_QNAME;
40 private static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
41 private static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
43 private static final MapEntryNode TOP_LEVEL_LIST_NODE = ImmutableMapEntryNodeBuilder.create()
45 new YangInstanceIdentifier.NodeIdentifierWithPredicates(
46 TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
47 .withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
50 private static final DataContainerChild<?, ?> CHILD_LIST = ImmutableNodes.mapNodeBuilder(TestModel.TEST_QNAME)
51 .withNodeIdentifier(NodeIdentifier.create(TestModel.TEST_QNAME))
52 .withChild(TOP_LEVEL_LIST_NODE)
55 static final NormalizedNode<?, ?> TEST_CONTAINER = Builders.containerBuilder()
56 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
57 .withChild(OUTER_LIST)
60 static final NormalizedNode<?, ?> TEST_CHILD = Builders.containerBuilder()
61 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
62 .withChild(CHILD_LIST)
65 static final String EXCEPTION_TEXT = "TestRpcImplementationException";
67 static TestRpcImplementation getTestRpcImplementation() {
68 return new TestRpcImplementation();
71 private static final class TestRpcImplementation implements DOMRpcImplementation {
72 private final CheckedFuture<DOMRpcResult, DOMRpcException> unknownRpc;
74 private TestRpcImplementation() {
75 unknownRpc = Futures.immediateFailedCheckedFuture(
76 new DOMRpcImplementationNotAvailableException(EXCEPTION_TEXT));
80 public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(
81 @Nonnull final DOMRpcIdentifier rpc, @Nullable final NormalizedNode<?, ?> input) {