X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futils%2FNormalizedNodeAggregatorTest.java;h=fd94ef9a4c0b0c390b2c9b2e0c17f16991b59b4f;hp=8c8631089c47859d03237ab5dca82214be3fd7f3;hb=66e553f2098ea61426c4a441be57395673535c2f;hpb=cd5b4bd47e1cfc40751ef15f6fcdf33fc131c1f8 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java index 8c8631089c..fd94ef9a4c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java @@ -10,21 +10,22 @@ 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.util.concurrent.CheckedFuture; + +import com.google.common.collect.ImmutableList; +import com.google.common.util.concurrent.FluentFuture; import java.util.Collection; +import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import org.junit.Test; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction; +import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; +import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction; +import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; @@ -36,25 +37,27 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class NormalizedNodeAggregatorTest { @Test - public void testAggregate() throws InterruptedException, ExecutionException, ReadFailedException, DataValidationFailedException { + public void testAggregate() throws InterruptedException, ExecutionException, + DataValidationFailedException { SchemaContext schemaContext = SchemaContextHelper.full(); NormalizedNode expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); NormalizedNode expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME); - Optional> optional = NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.builder().build(), - Lists.newArrayList( + Optional> optional = NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.empty(), + ImmutableList.of( Optional.>of(getRootNode(expectedNode1, schemaContext)), Optional.>of(getRootNode(expectedNode2, schemaContext))), - schemaContext); + schemaContext, LogicalDatastoreType.CONFIGURATION); NormalizedNode normalizedNode = optional.get(); assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection); + @SuppressWarnings("unchecked") Collection> collection = (Collection>) normalizedNode.getValue(); - for(NormalizedNode node : collection){ + for (NormalizedNode node : collection) { assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode); } @@ -70,37 +73,38 @@ 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 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>, ReadFailedException> read = readTransaction.read(YangInstanceIdentifier.builder().build()); + FluentFuture>> read = readTransaction.read(YangInstanceIdentifier.empty()); - Optional> nodeOptional = read.checkedGet(); + Optional> nodeOptional = read.get(); - return nodeOptional.get(); + return nodeOptional.get(); + } } - public static NormalizedNode findChildWithQName(Collection> collection, QName qName) { - for(NormalizedNode node : collection){ - if(node.getNodeType().equals(qName)){ + public static NormalizedNode findChildWithQName(Collection> collection, QName qname) { + for (NormalizedNode node : collection) { + if (node.getNodeType().equals(qname)) { return node; } } return null; } - -} \ No newline at end of file +}