Use YangInstanceIdentifier.EMPTY
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / NormalizedNodeAggregatorTest.java
index 8c8631089c47859d03237ab5dca82214be3fd7f3..453262a8bd6442e42a0f4f9ce2b303e77c905b02 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.controller.cluster.datastore.utils;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
+import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.CheckedFuture;
 import java.util.Collection;
 import java.util.concurrent.ExecutionException;
@@ -41,8 +41,8 @@ public class NormalizedNodeAggregatorTest {
         NormalizedNode<?, ?> expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
         NormalizedNode<?, ?> expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
 
-        Optional<NormalizedNode<?, ?>> optional = NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.builder().build(),
-                Lists.newArrayList(
+        Optional<NormalizedNode<?, ?>> optional = NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.EMPTY,
+                ImmutableList.of(
                         Optional.<NormalizedNode<?, ?>>of(getRootNode(expectedNode1, schemaContext)),
                         Optional.<NormalizedNode<?, ?>>of(getRootNode(expectedNode2, schemaContext))),
                 schemaContext);
@@ -70,27 +70,30 @@ public class NormalizedNodeAggregatorTest {
 
     }
 
-    public static NormalizedNode<?,?> getRootNode(NormalizedNode<?, ?> moduleNode, SchemaContext schemaContext) throws ReadFailedException, ExecutionException, InterruptedException {
-        InMemoryDOMDataStore store = new InMemoryDOMDataStore("test", Executors.newSingleThreadExecutor());
-        store.onGlobalContextUpdated(schemaContext);
+    public static NormalizedNode<?, ?> getRootNode(NormalizedNode<?, ?> moduleNode, SchemaContext schemaContext)
+            throws ReadFailedException, ExecutionException, InterruptedException {
+        try (InMemoryDOMDataStore store = new InMemoryDOMDataStore("test", Executors.newSingleThreadExecutor())) {
+            store.onGlobalContextUpdated(schemaContext);
 
-        DOMStoreWriteTransaction writeTransaction = store.newWriteOnlyTransaction();
+            DOMStoreWriteTransaction writeTransaction = store.newWriteOnlyTransaction();
 
-        writeTransaction.merge(YangInstanceIdentifier.builder().node(moduleNode.getNodeType()).build(), moduleNode);
+            writeTransaction.merge(YangInstanceIdentifier.of(moduleNode.getNodeType()), moduleNode);
 
-        DOMStoreThreePhaseCommitCohort ready = writeTransaction.ready();
+            DOMStoreThreePhaseCommitCohort ready = writeTransaction.ready();
 
-        ready.canCommit().get();
-        ready.preCommit().get();
-        ready.commit().get();
+            ready.canCommit().get();
+            ready.preCommit().get();
+            ready.commit().get();
 
-        DOMStoreReadTransaction readTransaction = store.newReadOnlyTransaction();
+            DOMStoreReadTransaction readTransaction = store.newReadOnlyTransaction();
 
-        CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = readTransaction.read(YangInstanceIdentifier.builder().build());
+            CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = readTransaction
+                    .read(YangInstanceIdentifier.EMPTY);
 
-        Optional<NormalizedNode<?, ?>> nodeOptional = read.checkedGet();
+            Optional<NormalizedNode<?, ?>> nodeOptional = read.checkedGet();
 
-        return nodeOptional.get();
+            return nodeOptional.get();
+        }
     }
 
     public static NormalizedNode<?,?> findChildWithQName(Collection<NormalizedNode<?, ?>> collection, QName qName) {