Move AbstractDOMDataBroker to mdsal-dom-spi
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / TestUtils.java
index 2ca4de66ef5bc42d8bcbaaad1667a4feea70606b..bc3dde7e8bf4c46d546dd4a728d8ab12ffb6750f 100644 (file)
@@ -7,59 +7,70 @@
  */
 package org.opendaylight.mdsal.dom.broker;
 
-import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
+import static java.util.Objects.requireNonNull;
 
 import com.google.common.util.concurrent.FluentFuture;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.mdsal.dom.broker.util.TestModel;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
 
-abstract class TestUtils {
-
-    private static final DataContainerChild<?, ?> OUTER_LIST = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
-            .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build();
+final class TestUtils {
+    private static final MapNode OUTER_LIST = ImmutableNodes.newSystemMapBuilder()
+        .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME))
+        .withChild(ImmutableNodes.newMapEntryBuilder()
+            .withNodeIdentifier(NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1))
+            .withChild(ImmutableNodes.leafNode(TestModel.ID_QNAME, 1))
+            .build())
+        .build();
 
     private static final String TOP_LEVEL_LIST_FOO_KEY_VALUE = "foo";
     private static final QName TOP_QNAME = TestModel.ID_QNAME;
     private static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
     private static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
 
-    private static final MapEntryNode TOP_LEVEL_LIST_NODE = ImmutableMapEntryNodeBuilder.create()
-            .withNodeIdentifier(
-                    NodeIdentifierWithPredicates.of(
-                            TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
-            .withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
-            .build();
+    private static final MapEntryNode TOP_LEVEL_LIST_NODE = ImmutableNodes.newMapEntryBuilder()
+        .withNodeIdentifier(NodeIdentifierWithPredicates.of(
+            TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
+        .withChild(ImmutableNodes.leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
+        .build();
 
-    private static final DataContainerChild<?, ?> CHILD_LIST = ImmutableNodes.mapNodeBuilder(TestModel.TEST_QNAME)
-            .withNodeIdentifier(NodeIdentifier.create(TestModel.TEST_QNAME))
-            .withChild(TOP_LEVEL_LIST_NODE)
-            .build();
+    private static final MapNode CHILD_LIST = ImmutableNodes.newSystemMapBuilder()
+        .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
+        .withChild(TOP_LEVEL_LIST_NODE)
+        .build();
 
-    static final NormalizedNode<?, ?> TEST_CONTAINER = Builders.containerBuilder()
-            .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
-            .withChild(OUTER_LIST)
-            .build();
+    static final ContainerNode TEST_CONTAINER = ImmutableNodes.newContainerBuilder()
+        .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
+        .withChild(OUTER_LIST)
+        .build();
 
-    static final NormalizedNode<?, ?> TEST_CHILD = Builders.containerBuilder()
-            .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
-            .withChild(CHILD_LIST)
-            .build();
+    static final ContainerNode TEST_CHILD = ImmutableNodes.newContainerBuilder()
+        .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
+        .withChild(CHILD_LIST)
+        .build();
 
     static final String EXCEPTION_TEXT = "TestRpcImplementationException";
 
+    private TestUtils() {
+        // Hidden on purpose
+    }
+
+    static MapEntryNode mapEntry(final QName listName, final QName keyName, final Object keyValue) {
+        return ImmutableNodes.newMapEntryBuilder()
+            .withNodeIdentifier(NodeIdentifierWithPredicates.of(listName, keyName, keyValue))
+            .withChild(ImmutableNodes.leafNode(keyName, keyValue))
+            .build();
+    }
+
     static TestRpcImplementation getTestRpcImplementation() {
         return new TestRpcImplementation();
     }
@@ -67,13 +78,14 @@ abstract class TestUtils {
     private static final class TestRpcImplementation implements DOMRpcImplementation {
         private final FluentFuture<DOMRpcResult> unknownRpc;
 
-        private TestRpcImplementation() {
+        TestRpcImplementation() {
             unknownRpc = FluentFutures.immediateFailedFluentFuture(
                     new DOMRpcImplementationNotAvailableException(EXCEPTION_TEXT));
         }
 
         @Override
-        public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
+        public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
+            requireNonNull(input);
             return unknownRpc;
         }
     }