Add ImmutableNode.newXYXBuilder() methods
[yangtools.git] / data / yang-data-tree-ri / src / test / java / org / opendaylight / yangtools / yang / data / tree / leafref / YT821Test.java
index 890dcae5e71605b80635527bc4c8c952c2ef7e08..9c1d8f661ef9bbf8caf02ab8f2e786502da7b378 100644 (file)
@@ -7,26 +7,25 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.leafref;
 
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 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.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-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.data.tree.api.DataTree;
-import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
-import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
-public class YT821Test {
+class YT821Test {
     private static final QName ROOT = QName.create("urn:opendaylight:params:xml:ns:yang:foo", "2018-07-18", "root");
     private static final QName FOO = QName.create(ROOT, "foo");
     private static final QName BAR = QName.create(ROOT, "bar");
@@ -42,8 +41,8 @@ public class YT821Test {
 
     private DataTree dataTree;
 
-    @BeforeClass
-    public static void beforeClass() {
+    @BeforeAll
+    static void beforeClass() {
         schemaContext = YangParserTestUtils.parseYang("""
             module yt821 {
               namespace "urn:opendaylight:params:xml:ns:yang:foo";
@@ -90,75 +89,79 @@ public class YT821Test {
         leafRefContext = LeafRefContext.create(schemaContext);
     }
 
-    @AfterClass
-    public static void afterClass() {
+    @AfterAll
+    static void afterClass() {
         schemaContext = null;
         leafRefContext = null;
     }
 
-    @Before
-    public void before() {
+    @BeforeEach
+    void before() {
         dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
     }
 
     @Test
-    public void testValidRefFromAugmentation() throws Exception {
-        final DataTreeModification writeModification = dataTree.takeSnapshot().newModification();
+    void testValidRefFromAugmentation() throws Exception {
+        final var writeModification = dataTree.takeSnapshot().newModification();
         writeModification.write(ROOT_ID, refFromAug("foo1"));
         writeModification.ready();
-        final DataTreeCandidate writeContributorsCandidate = dataTree.prepare(writeModification);
+        final var writeContributorsCandidate = dataTree.prepare(writeModification);
 
         LeafRefValidation.validate(writeContributorsCandidate, leafRefContext);
         dataTree.commit(writeContributorsCandidate);
     }
 
-    @Test(expected = LeafRefDataValidationFailedException.class)
-    public void testInvalidRefFromAugmentation() throws Exception {
-        final DataTreeModification writeModification = dataTree.takeSnapshot().newModification();
-        writeModification.write(ROOT_ID, refFromAug("foo2"));
-        writeModification.ready();
-        final DataTreeCandidate writeContributorsCandidate = dataTree.prepare(writeModification);
-
-        LeafRefValidation.validate(writeContributorsCandidate, leafRefContext);
+    @Test
+    void testInvalidRefFromAugmentation() throws Exception {
+        assertThrows(LeafRefDataValidationFailedException.class, () -> {
+            final var writeModification = dataTree.takeSnapshot().newModification();
+            writeModification.write(ROOT_ID, refFromAug("foo2"));
+            writeModification.ready();
+            final var writeContributorsCandidate = dataTree.prepare(writeModification);
+
+            LeafRefValidation.validate(writeContributorsCandidate, leafRefContext);
+        });
     }
 
     @Test
-    public void testValidRefInContainerFromAugmentation() throws Exception {
-        final DataTreeModification writeModification = dataTree.takeSnapshot().newModification();
+    void testValidRefInContainerFromAugmentation() throws Exception {
+        final var writeModification = dataTree.takeSnapshot().newModification();
         writeModification.write(ROOT_ID, refInContainer("foo1"));
         writeModification.ready();
-        final DataTreeCandidate writeContributorsCandidate = dataTree.prepare(writeModification);
+        final var writeContributorsCandidate = dataTree.prepare(writeModification);
 
         LeafRefValidation.validate(writeContributorsCandidate, leafRefContext);
         dataTree.commit(writeContributorsCandidate);
     }
 
-    @Test(expected = LeafRefDataValidationFailedException.class)
-    public void testInvalidRefInContainerFromAugmentation() throws Exception {
-        final DataTreeModification writeModification = dataTree.takeSnapshot().newModification();
-        writeModification.write(ROOT_ID, refInContainer("foo2"));
-        writeModification.ready();
-        final DataTreeCandidate writeContributorsCandidate = dataTree.prepare(writeModification);
-
-        LeafRefValidation.validate(writeContributorsCandidate, leafRefContext);
+    @Test
+    void testInvalidRefInContainerFromAugmentation() throws Exception {
+        assertThrows(LeafRefDataValidationFailedException.class, () -> {
+            final var writeModification = dataTree.takeSnapshot().newModification();
+            writeModification.write(ROOT_ID, refInContainer("foo2"));
+            writeModification.ready();
+            final var writeContributorsCandidate = dataTree.prepare(writeModification);
+
+            LeafRefValidation.validate(writeContributorsCandidate, leafRefContext);
+        });
     }
 
     private static ContainerNode refFromAug(final String refValue) {
-        return Builders.containerBuilder()
+        return ImmutableNodes.newContainerBuilder()
                 .withNodeIdentifier(new NodeIdentifier(ROOT))
-                .withChild(Builders.mapBuilder()
+                .withChild(ImmutableNodes.newSystemMapBuilder()
                     .withNodeIdentifier(new NodeIdentifier(FOO))
-                    .withChild(Builders.mapEntryBuilder()
+                    .withChild(ImmutableNodes.newMapEntryBuilder()
                         .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, NAME, "foo1"))
                         .withChild(ImmutableNodes.leafNode(NAME, "foo1"))
                         .build())
                     .build())
-                .withChild(Builders.mapBuilder()
+                .withChild(ImmutableNodes.newSystemMapBuilder()
                     .withNodeIdentifier(new NodeIdentifier(BAR))
-                    .withChild(Builders.mapEntryBuilder()
+                    .withChild(ImmutableNodes.newMapEntryBuilder()
                         .withNodeIdentifier(NodeIdentifierWithPredicates.of(BAR, NAME, "bar1"))
                         .withChild(ImmutableNodes.leafNode(NAME, "bar1"))
-                        .withChild(Builders.containerBuilder()
+                        .withChild(ImmutableNodes.newContainerBuilder()
                             .withNodeIdentifier(new NodeIdentifier(CONTAINER_IN_LIST))
                             .withChild(ImmutableNodes.leafNode(REF_FROM_AUG, refValue))
                             .build())
@@ -168,21 +171,21 @@ public class YT821Test {
     }
 
     private static ContainerNode refInContainer(final String refValue) {
-        return Builders.containerBuilder()
+        return ImmutableNodes.newContainerBuilder()
                 .withNodeIdentifier(new NodeIdentifier(ROOT))
-                .withChild(Builders.mapBuilder()
+                .withChild(ImmutableNodes.newSystemMapBuilder()
                     .withNodeIdentifier(new NodeIdentifier(FOO))
-                    .withChild(Builders.mapEntryBuilder()
+                    .withChild(ImmutableNodes.newMapEntryBuilder()
                         .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, NAME, "foo1"))
                         .withChild(ImmutableNodes.leafNode(NAME, "foo1"))
                         .build())
                     .build())
-                .withChild(Builders.mapBuilder()
+                .withChild(ImmutableNodes.newSystemMapBuilder()
                     .withNodeIdentifier(new NodeIdentifier(BAR))
-                    .withChild(Builders.mapEntryBuilder()
+                    .withChild(ImmutableNodes.newMapEntryBuilder()
                         .withNodeIdentifier(NodeIdentifierWithPredicates.of(BAR, NAME, "bar1"))
                         .withChild(ImmutableNodes.leafNode(NAME, "bar1"))
-                        .withChild(Builders.containerBuilder()
+                        .withChild(ImmutableNodes.newContainerBuilder()
                             .withNodeIdentifier(new NodeIdentifier(CONTAINER_FROM_AUG))
                             .withChild(ImmutableNodes.leafNode(REF_IN_CONTAINER, refValue))
                             .build())