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=cc9e9b288bbe3a6d7d362272ef738b6d7a781f26;hp=8c8631089c47859d03237ab5dca82214be3fd7f3;hb=HEAD;hpb=608760751ce7fcf4e84e86a8b33d43bc1d9984d6 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..d8bbdcf71d 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 @@ -5,56 +5,61 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - 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 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.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; public class NormalizedNodeAggregatorTest { @Test - public void testAggregate() throws InterruptedException, ExecutionException, ReadFailedException, DataValidationFailedException { - SchemaContext schemaContext = SchemaContextHelper.full(); - NormalizedNode expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); - NormalizedNode expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME); + public void testAggregate() throws InterruptedException, ExecutionException, DataValidationFailedException { + EffectiveModelContext schemaContext = SchemaContextHelper.full(); + NormalizedNode expectedNode1 = ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)) + .build(); + NormalizedNode expectedNode2 = ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(CarsModel.CARS_QNAME)) + .build(); - Optional> optional = NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.builder().build(), - Lists.newArrayList( - Optional.>of(getRootNode(expectedNode1, schemaContext)), - Optional.>of(getRootNode(expectedNode2, schemaContext))), - schemaContext); + Optional optional = NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.of(), + ImmutableList.of( + Optional.of(getRootNode(expectedNode1, schemaContext)), + Optional.of(getRootNode(expectedNode2, schemaContext))), + schemaContext, LogicalDatastoreType.CONFIGURATION); - NormalizedNode normalizedNode = optional.get(); + NormalizedNode normalizedNode = optional.orElseThrow(); - assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection); + assertTrue("Expect value to be a Collection", normalizedNode.body() instanceof Collection); - Collection> collection = (Collection>) normalizedNode.getValue(); + @SuppressWarnings("unchecked") + Collection collection = (Collection) normalizedNode.body(); - for(NormalizedNode node : collection){ + for (NormalizedNode node : collection) { assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode); } @@ -70,37 +75,35 @@ 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); - - DOMStoreWriteTransaction writeTransaction = store.newWriteOnlyTransaction(); + public static NormalizedNode getRootNode(final NormalizedNode moduleNode, + final EffectiveModelContext schemaContext) throws ExecutionException, InterruptedException { + try (InMemoryDOMDataStore store = new InMemoryDOMDataStore("test", Executors.newSingleThreadExecutor())) { + store.onModelContextUpdated(schemaContext); - writeTransaction.merge(YangInstanceIdentifier.builder().node(moduleNode.getNodeType()).build(), moduleNode); + DOMStoreWriteTransaction writeTransaction = store.newWriteOnlyTransaction(); - DOMStoreThreePhaseCommitCohort ready = writeTransaction.ready(); + writeTransaction.merge(YangInstanceIdentifier.of(moduleNode.name().getNodeType()), moduleNode); - ready.canCommit().get(); - ready.preCommit().get(); - ready.commit().get(); + DOMStoreThreePhaseCommitCohort ready = writeTransaction.ready(); - DOMStoreReadTransaction readTransaction = store.newReadOnlyTransaction(); + ready.canCommit().get(); + ready.preCommit().get(); + ready.commit().get(); - CheckedFuture>, ReadFailedException> read = readTransaction.read(YangInstanceIdentifier.builder().build()); + DOMStoreReadTransaction readTransaction = store.newReadOnlyTransaction(); - Optional> nodeOptional = read.checkedGet(); - - return nodeOptional.get(); + return readTransaction.read(YangInstanceIdentifier.of()).get().orElseThrow(); + } } - public static NormalizedNode findChildWithQName(Collection> collection, QName qName) { - for(NormalizedNode node : collection){ - if(node.getNodeType().equals(qName)){ + public static NormalizedNode findChildWithQName(final Collection collection, + final QName qname) { + for (NormalizedNode node : collection) { + if (node.name().getNodeType().equals(qname)) { return node; } } return null; } - -} \ No newline at end of file +}