From 748dcbc45ff3eac368ba8c22c19f7b29e75f3efd Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 27 Jan 2024 16:15:53 +0100 Subject: [PATCH] Migrate some tests to new ImmutableNodes While the amount of users of deprecated methods is huge here, we byte off a chunk of them. Change-Id: I6722230638b12cd7eede81e532578148b133220e Signed-off-by: Robert Varga --- ...ctDatastoreContextIntrospectorFactory.java | 14 ++++---- .../dds/AbstractProxyTransactionTest.java | 11 ++++--- .../actors/dds/ClientTransactionTest.java | 13 +++----- .../DataTreeChangeListenerSupportTest.java | 15 ++++++--- .../utils/NormalizedNodeAggregatorTest.java | 11 +++++-- .../datastore/model/CompositeModel.java | 33 ++++++------------- .../cluster/datastore/model/PeopleModel.java | 21 ++++++------ 7 files changed, 58 insertions(+), 60 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDatastoreContextIntrospectorFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDatastoreContextIntrospectorFactory.java index 75bd53ade6..b44bf38432 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDatastoreContextIntrospectorFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDatastoreContextIntrospectorFactory.java @@ -14,7 +14,8 @@ import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSeriali import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.distributed.datastore.provider.rev231229.DataStorePropertiesContainer; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; abstract class AbstractDatastoreContextIntrospectorFactory implements DatastoreContextIntrospectorFactory { @Override @@ -35,11 +36,12 @@ abstract class AbstractDatastoreContextIntrospectorFactory implements DatastoreC @VisibleForTesting final @NonNull DatastoreContextIntrospector newInstance(final DatastoreContext context) { - final DataStorePropertiesContainer defaultPropsContainer = (DataStorePropertiesContainer) - serializer().fromNormalizedNode(YangInstanceIdentifier.of(DataStorePropertiesContainer.QNAME), - ImmutableNodes.containerNode(DataStorePropertiesContainer.QNAME)).getValue(); - - return new DatastoreContextIntrospector(context, defaultPropsContainer); + return new DatastoreContextIntrospector(context, (DataStorePropertiesContainer) serializer() + .fromNormalizedNode(YangInstanceIdentifier.of(DataStorePropertiesContainer.QNAME), + ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(DataStorePropertiesContainer.QNAME)) + .build()) + .getValue()); } abstract BindingNormalizedNodeSerializer serializer(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransactionTest.java index 9b975c6ed7..b28c84b09e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransactionTest.java @@ -66,8 +66,9 @@ import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; import org.opendaylight.yangtools.yang.common.Empty; 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.impl.schema.Builders; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot; @@ -86,11 +87,11 @@ public abstract class AbstractProxyTransactionTest { - - private static final YangInstanceIdentifier PATH = YangInstanceIdentifier.builder() - .node(QName.create("ns-1", "node-1")) - .build(); - private static final ContainerNode DATA = Builders.containerBuilder() - .withNodeIdentifier(NodeIdentifier.create(PATH.getLastPathArgument().getNodeType())) - .build(); + private static final YangInstanceIdentifier PATH = YangInstanceIdentifier.of(QName.create("ns-1", "node-1")); + private static final ContainerNode DATA = ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(NodeIdentifier.create(PATH.getLastPathArgument().getNodeType())) + .build(); @Mock private CursorAwareDataTreeModification modification; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java index d6207b2f6e..88653642d2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java @@ -40,7 +40,8 @@ import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNo import org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException; import scala.concurrent.Await; import scala.concurrent.duration.FiniteDuration; @@ -77,7 +78,9 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest { @Test public void testInitialChangeListenerEventWithContainerPath() throws DataValidationFailedException { - writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME)); + writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) + .build()); Entry entry = registerChangeListener(TEST_PATH, 1); MockDataTreeChangeListener listener = entry.getKey(); @@ -87,7 +90,9 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest { listener.reset(1); - writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME)); + writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) + .build()); listener.waitForChangeEvents(); listener.verifyNotifiedData(TEST_PATH); @@ -96,7 +101,9 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest { entry.getValue().tell(CloseDataTreeNotificationListenerRegistration.getInstance(), kit.getRef()); kit.expectMsgClass(Duration.ofSeconds(5), CloseDataTreeNotificationListenerRegistrationReply.class); - writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME)); + writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) + .build()); listener.verifyNoNotifiedData(TEST_PATH); } 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 360a4c6d02..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 @@ -26,9 +26,10 @@ 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.impl.schema.ImmutableNodes; +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; @@ -37,8 +38,12 @@ public class NormalizedNodeAggregatorTest { @Test public void testAggregate() throws InterruptedException, ExecutionException, DataValidationFailedException { EffectiveModelContext schemaContext = SchemaContextHelper.full(); - NormalizedNode expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); - NormalizedNode expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME); + 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.of(), ImmutableList.of( diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/CompositeModel.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/CompositeModel.java index 5750339cf5..582c5f9976 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/CompositeModel.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/CompositeModel.java @@ -7,18 +7,17 @@ */ package org.opendaylight.controller.md.cluster.datastore.model; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode; import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry; import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; +import static org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes.leafNode; 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.YangInstanceIdentifier.NodeWithValue; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -102,31 +101,19 @@ public final class CompositeModel { } public static ContainerNode createTestContainer() { - return Builders.containerBuilder() + return ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) .withChild(leafNode(DESC_QNAME, DESC)) .withChild(leafNode(AUG_QNAME, "First Test")) - .withChild(Builders.leafSetBuilder() + .withChild(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "shoe"))) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "shoe"), "nike")) - .withValue("nike") - .build()) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "shoe"), "puma")) - .withValue("puma") - .build()) + .withChildValue("nike") + .withChildValue("puma") .build()) - .withChild(Builders.leafSetBuilder() + .withChild(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "number"))) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "number"), 5)) - .withValue(5) - .build()) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "number"), 15)) - .withValue(15) - .build()) + .withChildValue(5) + .withChildValue(15) .build()) .withChild(mapNodeBuilder(OUTER_LIST_QNAME) .withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID)) @@ -142,7 +129,7 @@ public final class CompositeModel { .withChild(leafNode(GRAND_CHILD_NAME_QNAME, FIRST_GRAND_CHILD_NAME)) .build(); - return Builders.containerBuilder() + return ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(FAMILY_QNAME)) .withChild(mapNodeBuilder(CHILDREN_QNAME) .withChild(mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/PeopleModel.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/PeopleModel.java index ee2a416cbc..725faf56f1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/PeopleModel.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/PeopleModel.java @@ -7,14 +7,15 @@ */ package org.opendaylight.controller.md.cluster.datastore.model; +import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; + 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.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; public final class PeopleModel { public static final QName BASE_QNAME = QName.create( @@ -33,17 +34,17 @@ public final class PeopleModel { } public static ContainerNode create() { - return Builders.containerBuilder() + return ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(BASE_QNAME)) - .withChild(Builders.mapBuilder() + .withChild(ImmutableNodes.newSystemMapBuilder() .withNodeIdentifier(new NodeIdentifier(PERSON_QNAME)) // Create an entry for the person jack - .withChild(ImmutableNodes.mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, "jack") + .withChild(mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, "jack") .withChild(ImmutableNodes.leafNode(PERSON_NAME_QNAME, "jack")) .withChild(ImmutableNodes.leafNode(PERSON_AGE_QNAME, 100L)) .build()) // Create an entry for the person jill - .withChild(ImmutableNodes.mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, "jill") + .withChild(mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, "jill") .withChild(ImmutableNodes.leafNode(PERSON_NAME_QNAME, "jill")) .withChild(ImmutableNodes.leafNode(PERSON_AGE_QNAME, 200L)) .build()) @@ -52,17 +53,15 @@ public final class PeopleModel { } public static ContainerNode emptyContainer() { - return Builders.containerBuilder() - .withNodeIdentifier(new NodeIdentifier(BASE_QNAME)) - .build(); + return ImmutableNodes.newContainerBuilder().withNodeIdentifier(new NodeIdentifier(BASE_QNAME)).build(); } public static SystemMapNode newPersonMapNode() { - return ImmutableNodes.mapNodeBuilder(PERSON_QNAME).build(); + return ImmutableNodes.newSystemMapBuilder().withNodeIdentifier(new NodeIdentifier(PERSON_QNAME)).build(); } public static MapEntryNode newPersonEntry(final String name) { - return ImmutableNodes.mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, name) + return mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, name) .withChild(ImmutableNodes.leafNode(PERSON_NAME_QNAME, name)) .build(); } -- 2.36.6