Rename DOMDataTreeCommitCohortRegistry to CommitCohortExtension
[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
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;
25
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))
32             .build())
33         .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 = 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))
44         .build();
45
46     private static final MapNode CHILD_LIST = ImmutableNodes.newSystemMapBuilder()
47         .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
48         .withChild(TOP_LEVEL_LIST_NODE)
49         .build();
50
51     static final ContainerNode TEST_CONTAINER = ImmutableNodes.newContainerBuilder()
52         .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
53         .withChild(OUTER_LIST)
54         .build();
55
56     static final ContainerNode TEST_CHILD = ImmutableNodes.newContainerBuilder()
57         .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
58         .withChild(CHILD_LIST)
59         .build();
60
61     static final String EXCEPTION_TEXT = "TestRpcImplementationException";
62
63     private TestUtils() {
64         // Hidden on purpose
65     }
66
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))
71             .build();
72     }
73
74     static TestRpcImplementation getTestRpcImplementation() {
75         return new TestRpcImplementation();
76     }
77
78     private static final class TestRpcImplementation implements DOMRpcImplementation {
79         private final FluentFuture<DOMRpcResult> unknownRpc;
80
81         TestRpcImplementation() {
82             unknownRpc = FluentFutures.immediateFailedFluentFuture(
83                     new DOMRpcImplementationNotAvailableException(EXCEPTION_TEXT));
84         }
85
86         @Override
87         public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
88             requireNonNull(input);
89             return unknownRpc;
90         }
91     }
92 }