From: Robert Varga Date: Sat, 27 Jan 2024 14:42:41 +0000 (+0100) Subject: Migrate sal-clusering-commons tests X-Git-Tag: v9.0.1~69 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=0b6c3618e21fac01d7b287688b79e374f226f498 Migrate sal-clusering-commons tests Migrate most users of deprecated Builders/ImmutableNodes. Change-Id: I676f248cc524ebc51120352951e93e8539b1dd88 Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SerializationUtilsTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SerializationUtilsTest.java index 1facd072ca..630ebecb4e 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SerializationUtilsTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SerializationUtilsTest.java @@ -30,8 +30,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; 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.spi.node.ImmutableNodes; import org.xmlunit.builder.DiffBuilder; public class SerializationUtilsTest { @@ -49,7 +48,7 @@ public class SerializationUtilsTest { public void testSerializeDeserializeAnyXmlNode() throws Exception { final var parse = UntrustedXML.newDocumentBuilder().parse( new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))); - final var anyXmlNode = Builders.anyXmlBuilder() + final var anyXmlNode = ImmutableNodes.newAnyxmlBuilder(DOMSource.class) .withNodeIdentifier(id("anyXmlNode")) .withValue(new DOMSource(parse)) .build(); @@ -120,16 +119,16 @@ public class SerializationUtilsTest { private static ContainerNode createNormalizedNode() { final var stringLeaf = createLeaf("stringLeaf", "stringValue"); - final var entry1 = Builders.mapEntryBuilder() + final var entry1 = ImmutableNodes.newMapEntryBuilder() .withNodeIdentifier(listId("mapNode", "key", "key1")) .withChild(stringLeaf) .build(); - final var entry2 = Builders.mapEntryBuilder() + final var entry2 = ImmutableNodes.newMapEntryBuilder() .withNodeIdentifier(listId("mapNode", "key", "key2")) .withChild(stringLeaf) .build(); - return Builders.containerBuilder() + return ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(CONTAINER1)) .withChild(createLeaf("booleanLeaf", true)) .withChild(createLeaf("byteLeaf", (byte) 0)) @@ -140,40 +139,40 @@ public class SerializationUtilsTest { .withChild(createLeaf("longStringLeaf", "0123456789".repeat(1000))) .withChild(createLeaf("stringLeaf", QName.create("base", "qName"))) .withChild(createLeaf("stringLeaf", YangInstanceIdentifier.of(QName.create("test", "test")))) - .withChild(Builders.mapBuilder() + .withChild(ImmutableNodes.newSystemMapBuilder() .withNodeIdentifier(id("mapNode")) .withChild(entry1) .withChild(entry2) .build()) - .withChild(Builders.orderedMapBuilder() + .withChild(ImmutableNodes.newUserMapBuilder() .withNodeIdentifier(id("orderedMapNode")) .withChild(entry2) .withChild(entry1) .build()) - .withChild(Builders.unkeyedListBuilder() + .withChild(ImmutableNodes.newUnkeyedListBuilder() .withNodeIdentifier(id("unkeyedList")) - .withChild(Builders.unkeyedListEntryBuilder() + .withChild(ImmutableNodes.newUnkeyedListEntryBuilder() .withNodeIdentifier(id("unkeyedList")) .withChild(stringLeaf) .build()) - .withChild(Builders.unkeyedListEntryBuilder() + .withChild(ImmutableNodes.newUnkeyedListEntryBuilder() .withNodeIdentifier(id("unkeyedList")) .withChild(stringLeaf) .build()) .build()) - .withChild(Builders.leafSetBuilder() + .withChild(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(id("leafSetNode")) .withChild(createLeafSetEntry("leafSetNode", "leafSetValue1")) .withChild(createLeafSetEntry("leafSetNode", "leafSetValue2")) .build()) - .withChild(Builders.orderedLeafSetBuilder() + .withChild(ImmutableNodes.newUserLeafSetBuilder() .withNodeIdentifier(id("orderedLeafSetNode")) .withChild(createLeafSetEntry("orderedLeafSetNode", "value1")) .withChild(createLeafSetEntry("orderedLeafSetNode", "value2")) .build()) .withChild(createLeaf("aug1", "aug1Value")) .withChild(createLeaf("aug2", "aug2Value")) - .withChild(Builders.choiceBuilder() + .withChild(ImmutableNodes.newChoiceBuilder() .withNodeIdentifier(id("choiceNode")) .withChild(createLeaf("choiceLeaf", 12)) .build()) @@ -185,10 +184,7 @@ public class SerializationUtilsTest { } private static LeafSetEntryNode createLeafSetEntry(final String leafSet, final String value) { - return Builders.leafSetEntryBuilder() - .withNodeIdentifier(leafSetId(leafSet, value)) - .withValue(value) - .build(); + return ImmutableNodes.leafSetEntry(leafSetId(leafSet, value)); } private static NodeIdentifier id(final String name) { diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodePrunerTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodePrunerTest.java index e8a4a88080..6b150131b3 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodePrunerTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodePrunerTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; +import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.containerNode; 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; @@ -26,16 +27,15 @@ import org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeNa import org.opendaylight.controller.cluster.datastore.util.TestModel; 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.AnyxmlNode; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode; +import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; -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; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; @RunWith(MockitoJUnitRunner.StrictStubs.class) @@ -75,7 +75,6 @@ public class NormalizedNodePrunerTest { NormalizedNode actual = pruner.getResult().orElseThrow(); assertEquals(expected, actual); - } @Test(expected = IllegalStateException.class) @@ -93,10 +92,8 @@ public class NormalizedNodePrunerTest { assertEquals(expected, actual); NormalizedNodeWriter.forStreamWriter(pruner).write(expected); - } - @Test public void testNodesPrunedWhenAugmentationSchemaMissing() throws IOException { AbstractNormalizedNodePruner pruner = prunerNoAugSchema(TestModel.TEST_PATH); @@ -133,7 +130,6 @@ public class NormalizedNodePrunerTest { // Asserting true here instead of checking actual value because I don't want this assertion to be fragile assertTrue(countNodes(expected, "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test") > 0); - } private static int countNodes(final NormalizedNode normalizedNode, final String namespaceFilter) { @@ -153,8 +149,7 @@ public class NormalizedNodePrunerTest { @Test public void testLeafNodeNotPrunedWhenHasNoParent() throws IOException { AbstractNormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.DESC_QNAME)); - NormalizedNode input = Builders.leafBuilder().withNodeIdentifier( - new NodeIdentifier(TestModel.DESC_QNAME)).withValue("test").build(); + NormalizedNode input = ImmutableNodes.leafNode(TestModel.DESC_QNAME, "test"); NormalizedNodeWriter.forStreamWriter(pruner).write(input); assertEquals("normalizedNode", input, pruner.getResult().orElseThrow()); @@ -172,8 +167,7 @@ public class NormalizedNodePrunerTest { @Test public void testLeafSetEntryNodeNotPrunedWhenHasNoParent() throws IOException { AbstractNormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.SHOE_QNAME)); - LeafSetEntryNode input = Builders.leafSetEntryBuilder().withValue("puma").withNodeIdentifier( - new NodeWithValue<>(TestModel.SHOE_QNAME, "puma")).build(); + LeafSetEntryNode input = ImmutableNodes.leafSetEntry(TestModel.SHOE_QNAME, "puma"); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode actual = pruner.getResult().orElseThrow(); @@ -183,10 +177,10 @@ public class NormalizedNodePrunerTest { @Test public void testLeafSetEntryNodeNotPrunedWhenHasParent() throws IOException { AbstractNormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.SHOE_QNAME)); - LeafSetEntryNode child = Builders.leafSetEntryBuilder().withValue("puma").withNodeIdentifier( - new NodeWithValue<>(TestModel.SHOE_QNAME, "puma")).build(); - NormalizedNode input = Builders.leafSetBuilder().withNodeIdentifier( - new NodeIdentifier(TestModel.SHOE_QNAME)).withChild(child).build(); + SystemLeafSetNode input = ImmutableNodes.newSystemLeafSetBuilder() + .withNodeIdentifier(new NodeIdentifier(TestModel.SHOE_QNAME)) + .withChildValue("puma") + .build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode actual = pruner.getResult().orElseThrow(); @@ -196,8 +190,7 @@ public class NormalizedNodePrunerTest { @Test public void testLeafSetEntryNodePrunedWhenHasNoParentAndSchemaMissing() throws IOException { AbstractNormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.INVALID_QNAME)); - NormalizedNode input = Builders.leafSetEntryBuilder().withValue("test").withNodeIdentifier( - new NodeWithValue<>(TestModel.INVALID_QNAME, "test")).build(); + LeafSetEntryNode input = ImmutableNodes.leafSetEntry(TestModel.INVALID_QNAME, "test"); NormalizedNodeWriter.forStreamWriter(pruner).write(input); assertEquals(Optional.empty(), pruner.getResult()); @@ -206,11 +199,10 @@ public class NormalizedNodePrunerTest { @Test public void testLeafSetEntryNodePrunedWhenHasParentAndSchemaMissing() throws IOException { AbstractNormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.INVALID_QNAME)); - LeafSetEntryNode child = Builders.leafSetEntryBuilder().withValue("test").withNodeIdentifier( - new NodeWithValue<>(TestModel.INVALID_QNAME, "test")).build(); - NormalizedNode input = Builders.leafSetBuilder().withNodeIdentifier( - new NodeIdentifier(TestModel.INVALID_QNAME)).withChild(child).build(); - NormalizedNodeWriter.forStreamWriter(pruner).write(input); + NormalizedNodeWriter.forStreamWriter(pruner).write(ImmutableNodes.newSystemLeafSetBuilder() + .withNodeIdentifier(new NodeIdentifier(TestModel.INVALID_QNAME)) + .withChildValue("test") + .build()); assertEquals(Optional.empty(), pruner.getResult()); } @@ -218,32 +210,37 @@ public class NormalizedNodePrunerTest { @Test public void testAnyXMLNodeNotPrunedWhenHasNoParent() throws IOException { AbstractNormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.ANY_XML_QNAME)); - NormalizedNode input = Builders.anyXmlBuilder().withNodeIdentifier( - new NodeIdentifier(TestModel.ANY_XML_QNAME)).withValue(mock(DOMSource.class)).build(); + AnyxmlNode input = ImmutableNodes.newAnyxmlBuilder(DOMSource.class) + .withNodeIdentifier(new NodeIdentifier(TestModel.ANY_XML_QNAME)) + .withValue(mock(DOMSource.class)) + .build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); - NormalizedNode actual = pruner.getResult().orElseThrow(); - assertEquals("normalizedNode", input, actual); + assertEquals(input, pruner.getResult().orElseThrow()); } @Test public void testAnyXMLNodeNotPrunedWhenHasParent() throws IOException { final var pruner = prunerFullSchema(TestModel.TEST_PATH); - final var child = Builders.anyXmlBuilder().withNodeIdentifier( - new NodeIdentifier(TestModel.ANY_XML_QNAME)).withValue(mock(DOMSource.class)).build(); - final var input = Builders.containerBuilder().withNodeIdentifier( - new NodeIdentifier(TestModel.TEST_QNAME)).withChild(child).build(); + final var input = ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)) + .withChild(ImmutableNodes.newAnyxmlBuilder(DOMSource.class) + .withNodeIdentifier(new NodeIdentifier(TestModel.ANY_XML_QNAME)) + .withValue(mock(DOMSource.class)) + .build()) + .build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); - assertEquals("normalizedNode", input, pruner.getResult().orElseThrow()); + assertEquals(input, pruner.getResult().orElseThrow()); } @Test public void testAnyXmlNodePrunedWhenHasNoParentAndSchemaMissing() throws IOException { AbstractNormalizedNodePruner pruner = prunerNoTestSchema(TestModel.TEST_PATH.node(TestModel.ANY_XML_QNAME)); - NormalizedNode input = Builders.anyXmlBuilder().withNodeIdentifier( - new NodeIdentifier(TestModel.ANY_XML_QNAME)).withValue(mock(DOMSource.class)).build(); - NormalizedNodeWriter.forStreamWriter(pruner).write(input); + NormalizedNodeWriter.forStreamWriter(pruner).write(ImmutableNodes.newAnyxmlBuilder(DOMSource.class) + .withNodeIdentifier(new NodeIdentifier(TestModel.ANY_XML_QNAME)) + .withValue(mock(DOMSource.class)) + .build()); assertEquals(Optional.empty(), pruner.getResult()); } @@ -256,11 +253,10 @@ public class NormalizedNodePrunerTest { .node(TestModel.INNER_CONTAINER_QNAME).build(); AbstractNormalizedNodePruner pruner = prunerFullSchema(path); - NormalizedNode input = ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME); + ContainerNode input = containerNode(TestModel.INNER_CONTAINER_QNAME); NormalizedNodeWriter.forStreamWriter(pruner).write(input); - NormalizedNode actual = pruner.getResult().orElseThrow(); - assertEquals("normalizedNode", input, actual); + assertEquals(input, pruner.getResult().orElseThrow()); } @Test @@ -271,8 +267,7 @@ public class NormalizedNodePrunerTest { .node(TestModel.INVALID_QNAME).build(); AbstractNormalizedNodePruner pruner = prunerFullSchema(path); - ContainerNode input = ImmutableNodes.containerNode(TestModel.INVALID_QNAME); - NormalizedNodeWriter.forStreamWriter(pruner).write(input); + NormalizedNodeWriter.forStreamWriter(pruner).write(containerNode(TestModel.INVALID_QNAME)); assertEquals(Optional.empty(), pruner.getResult()); } @@ -284,18 +279,20 @@ public class NormalizedNodePrunerTest { .build(); AbstractNormalizedNodePruner pruner = prunerFullSchema(path); - MapNode innerList = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( - TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild( - ImmutableNodes.containerNode(TestModel.INVALID_QNAME)).build()).build(); - MapEntryNode input = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) - .withChild(innerList).build(); - NormalizedNodeWriter.forStreamWriter(pruner).write(input); + NormalizedNodeWriter.forStreamWriter(pruner) + .write(mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) + .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) + .withChild(mapEntryBuilder(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one") + .withChild(containerNode(TestModel.INVALID_QNAME)) + .build()) + .build()) + .build()); - MapEntryNode expected = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) - .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( - TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").build()).build()).build(); - NormalizedNode actual = pruner.getResult().orElseThrow(); - assertEquals("normalizedNode", expected, actual); + assertEquals(mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) + .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) + .withChild(mapEntryBuilder(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").build()) + .build()) + .build(), pruner.getResult().orElseThrow()); } @Test @@ -305,13 +302,14 @@ public class NormalizedNodePrunerTest { .node(TestModel.INNER_LIST_QNAME).build(); AbstractNormalizedNodePruner pruner = prunerFullSchema(path); - MapNode input = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( - TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild( - ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); + SystemMapNode input = mapNodeBuilder(TestModel.INNER_LIST_QNAME) + .withChild(mapEntryBuilder(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one") + .withChild(containerNode(TestModel.INNER_CONTAINER_QNAME)) + .build()) + .build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); - NormalizedNode actual = pruner.getResult().orElseThrow(); - assertEquals("normalizedNode", input, actual); + assertEquals(input, pruner.getResult().orElseThrow()); } @Test @@ -321,10 +319,11 @@ public class NormalizedNodePrunerTest { .node(TestModel.INVALID_QNAME).build(); AbstractNormalizedNodePruner pruner = prunerFullSchema(path); - MapNode input = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder( - TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild( - ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); - NormalizedNodeWriter.forStreamWriter(pruner).write(input); + NormalizedNodeWriter.forStreamWriter(pruner).write(mapNodeBuilder(TestModel.INVALID_QNAME) + .withChild(mapEntryBuilder(TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one") + .withChild(containerNode(TestModel.INNER_CONTAINER_QNAME)) + .build()) + .build()); assertEquals(Optional.empty(), pruner.getResult()); } @@ -336,37 +335,27 @@ public class NormalizedNodePrunerTest { .build(); AbstractNormalizedNodePruner pruner = prunerFullSchema(path); - MapNode innerList = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder( - TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild( - ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); - NormalizedNode input = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) - .withChild(innerList).build(); - NormalizedNodeWriter.forStreamWriter(pruner).write(input); + NormalizedNodeWriter.forStreamWriter(pruner) + .write(mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) + .withChild(mapNodeBuilder(TestModel.INVALID_QNAME) + .withChild(mapEntryBuilder(TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one") + .withChild(containerNode(TestModel.INNER_CONTAINER_QNAME)) + .build()) + .build()) + .build()); - NormalizedNode expected = mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1); - NormalizedNode actual = pruner.getResult().orElseThrow(); - assertEquals("normalizedNode", expected, actual); + assertEquals(mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1), + pruner.getResult().orElseThrow()); } - private static NormalizedNode createTestContainer() { - byte[] bytes1 = {1, 2, 3}; - LeafSetEntryNode entry1 = Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)) - .withValue(bytes1) - .build(); - - byte[] bytes2 = {}; - LeafSetEntryNode entry2 = Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)) - .withValue(bytes2).build(); - + private static ContainerNode createTestContainer() { return TestModel.createBaseTestContainerBuilder() - .withChild(Builders.leafSetBuilder() - .withNodeIdentifier(new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME)) - .withChild(entry1) - .withChild(entry2) - .build()) - .withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[]{1, 2, 3, 4})) - .build(); + .withChild(ImmutableNodes.newSystemLeafSetBuilder() + .withNodeIdentifier(new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME)) + .withChildValue(new byte[] {1, 2, 3}) + .withChildValue(new byte[0]) + .build()) + .withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[] {1, 2, 3, 4})) + .build(); } } diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/UintAdaptingPrunerTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/UintAdaptingPrunerTest.java index 59ceafba63..b29113cc8e 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/UintAdaptingPrunerTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/UintAdaptingPrunerTest.java @@ -22,11 +22,9 @@ import org.opendaylight.yangtools.yang.common.Uint8; 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.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; -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; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -55,9 +53,9 @@ public class UintAdaptingPrunerTest { @Test public void testListTranslation() throws IOException { - assertEquals(Builders.mapBuilder() + assertEquals(ImmutableNodes.newSystemMapBuilder() .withNodeIdentifier(new NodeIdentifier(LST)) - .withChild(Builders.mapEntryBuilder() + .withChild(ImmutableNodes.newMapEntryBuilder() .withNodeIdentifier(NodeIdentifierWithPredicates.of(LST, ImmutableMap.builder() .put(A, (byte) 1) .put(B, (short) 1) @@ -78,9 +76,9 @@ public class UintAdaptingPrunerTest { .withChild(ImmutableNodes.leafNode(H, Uint64.ONE)) .build()) .build(), - prune(Builders.mapBuilder() + prune(ImmutableNodes.newSystemMapBuilder() .withNodeIdentifier(new NodeIdentifier(LST)) - .withChild(Builders.mapEntryBuilder() + .withChild(ImmutableNodes.newMapEntryBuilder() .withNodeIdentifier(NodeIdentifierWithPredicates.of(LST, ImmutableMap.builder() .put(A, (byte) 1) .put(B, (short) 1) @@ -105,7 +103,7 @@ public class UintAdaptingPrunerTest { @Test public void testContainerTranslation() throws IOException { - assertEquals(Builders.containerBuilder() + assertEquals(ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(CONT)) .withChild(ImmutableNodes.leafNode(A, (byte) 1)) .withChild(ImmutableNodes.leafNode(B, (short) 1)) @@ -116,7 +114,7 @@ public class UintAdaptingPrunerTest { .withChild(ImmutableNodes.leafNode(G, Uint32.ONE)) .withChild(ImmutableNodes.leafNode(H, Uint64.ONE)) .build(), - prune(Builders.containerBuilder() + prune(ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(CONT)) .withChild(ImmutableNodes.leafNode(A, (byte) 1)) .withChild(ImmutableNodes.leafNode(B, (short) 1)) @@ -131,73 +129,49 @@ public class UintAdaptingPrunerTest { @Test public void testLeafList8() throws IOException { - assertEquals(Builders.leafSetBuilder() + assertEquals(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(LFLST8)) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(LFLST8, Uint8.ONE)) - .withValue(Uint8.ONE) - .build()) + .withChildValue(Uint8.ONE) .build(), - prune(Builders.leafSetBuilder() + prune(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(LFLST8)) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(LFLST8, (short) 1)) - .withValue((short) 1) - .build()) + .withChildValue((short) 1) .build())); } @Test public void testLeafList16() throws IOException { - assertEquals(Builders.leafSetBuilder() + assertEquals(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(LFLST16)) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(LFLST16, Uint16.ONE)) - .withValue(Uint16.ONE) - .build()) + .withChildValue(Uint16.ONE) .build(), - prune(Builders.leafSetBuilder() + prune(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(LFLST16)) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(LFLST16, 1)) - .withValue(1) - .build()) + .withChildValue(1) .build())); } @Test public void testLeafList32() throws IOException { - assertEquals(Builders.leafSetBuilder() + assertEquals(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(LFLST32)) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(LFLST32, Uint32.ONE)) - .withValue(Uint32.ONE) - .build()) + .withChildValue(Uint32.ONE) .build(), - prune(Builders.leafSetBuilder() + prune(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(LFLST32)) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(LFLST32, 1L)) - .withValue(1L) - .build()) + .withChildValue(1L) .build())); } @Test public void testLeafList64() throws IOException { - assertEquals(Builders.leafSetBuilder() + assertEquals(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(LFLST64)) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(LFLST64, Uint64.ONE)) - .withValue(Uint64.ONE) - .build()) + .withChildValue(Uint64.ONE) .build(), - prune(Builders.leafSetBuilder() + prune(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(LFLST64)) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(LFLST64, BigInteger.ONE)) - .withValue(BigInteger.ONE) - .build()) + .withChildValue(BigInteger.ONE) .build())); } diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java index ca0dbe5245..37d102d0f3 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java @@ -7,10 +7,10 @@ */ package org.opendaylight.controller.cluster.datastore.util; -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 com.google.common.collect.ImmutableSet; import java.io.InputStream; @@ -25,7 +25,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithV 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.builder.DataContainerNodeBuilder; -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.EffectiveModelContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -176,7 +176,7 @@ public final class TestModel { new NodeWithValue<>(QName.create(TEST_QNAME, "leaf-list-entry"), "foo")); // Create the document - return Builders.containerBuilder() + return ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) // Create a bits leaf .withChild(leafNode(QName.create(TEST_QNAME, "my-bits"), ImmutableSet.of("foo", "bar"))) @@ -188,54 +188,39 @@ public final class TestModel { .withChild(leafNode(TestModel.BIGDECIMAL_LEAF_QNAME, Decimal64.valueOf("1.2").scaleTo(2))) .withChild(leafNode(SOME_REF_QNAME, instanceID)) .withChild(leafNode(MYIDENTITY_QNAME, DESC_QNAME)) - .withChild(Builders.unkeyedListBuilder() + .withChild(ImmutableNodes.newUnkeyedListBuilder() .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)) // Create unkeyed list entry - .withChild(Builders.unkeyedListEntryBuilder() + .withChild(ImmutableNodes.newUnkeyedListEntryBuilder() .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)) .withChild(leafNode(NAME_QNAME, "unkeyed-entry-name")) .build()) .build()) - .withChild(Builders.choiceBuilder() + .withChild(ImmutableNodes.newChoiceBuilder() .withNodeIdentifier(new NodeIdentifier(TWO_THREE_QNAME)) .withChild(leafNode(TWO_QNAME, "two")).build()) - .withChild(Builders.orderedMapBuilder() + .withChild(ImmutableNodes.newUserMapBuilder() .withNodeIdentifier(new NodeIdentifier(ORDERED_LIST_QNAME)) .withValue(List.of( mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "1").build(), mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "2").build())) .build()) - .withChild(Builders.leafSetBuilder() + .withChild(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(SHOE_QNAME)) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(SHOE_QNAME, "nike")) - .withValue("nike") - .build()) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(SHOE_QNAME, "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(Builders.containerBuilder() + .withChild(ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(SWITCH_FEATURES_QNAME)) // Test a leaf-list where each entry contains an identity - .withChild(Builders.leafSetBuilder() + .withChild(ImmutableNodes.newSystemLeafSetBuilder() .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "capability"))) - .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "capability"), DESC_QNAME)) - .withValue(DESC_QNAME) - .build()) + .withChildValue(DESC_QNAME) .build()) .build()) .withChild(mapNodeBuilder(AUGMENTED_LIST_QNAME) @@ -253,10 +238,10 @@ public final class TestModel { } public static MapEntryNode createAugmentedListEntry(final int id, final String name) { - return Builders.mapEntryBuilder() + return ImmutableNodes.newMapEntryBuilder() .withNodeIdentifier(NodeIdentifierWithPredicates.of(AUGMENTED_LIST_QNAME, ID_QNAME, id)) .withChild(leafNode(ID_QNAME, id)) - .withChild(Builders.containerBuilder() + .withChild(ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(AUG_CONT_QNAME)) .withChild(leafNode(AUG_NAME_QNAME, name)) .build()) @@ -269,9 +254,9 @@ public final class TestModel { .withChild(leafNode(GRAND_CHILD_NUMBER_QNAME,FIRST_GRAND_CHILD_ID)) .withChild(leafNode(GRAND_CHILD_NAME_QNAME, FIRST_GRAND_CHILD_NAME)); - return Builders.containerBuilder() + return ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(FAMILY_QNAME)) - .withChild(mapNodeBuilder() + .withChild(ImmutableNodes.newSystemMapBuilder() .withNodeIdentifier(new NodeIdentifier(CHILDREN_QNAME)) .withChild(mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID) .withChild(leafNode(CHILD_NUMBER_QNAME, FIRST_CHILD_ID))