*/
package org.opendaylight.yangtools.yang.data.tree.leafref;
-import com.google.common.collect.ImmutableSet;
-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.AugmentationIdentifier;
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");
private DataTree dataTree;
- @BeforeClass
- public static void beforeClass() {
- schemaContext = YangParserTestUtils.parseYangResource("/yt821.yang");
+ @BeforeAll
+ static void beforeClass() {
+ schemaContext = YangParserTestUtils.parseYang("""
+ module yt821 {
+ namespace "urn:opendaylight:params:xml:ns:yang:foo";
+ prefix foo;
+ revision 2018-07-18;
+
+ container root {
+ list foo {
+ key name;
+ leaf name {
+ type string;
+ }
+ }
+
+ list bar {
+ key name;
+ leaf name {
+ type string;
+ }
+
+ container container-in-list {
+ }
+ }
+ }
+
+ augment /root/bar/container-in-list {
+ leaf ref-from-aug {
+ type leafref {
+ path "/root/foo/name";
+ }
+ }
+ }
+
+ augment /root/bar/ {
+ container container-from-aug {
+ leaf ref-in-container {
+ type leafref {
+ path "/root/foo/name";
+ }
+ }
+ }
+ }
+ }""");
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(Builders.augmentationBuilder()
- .withNodeIdentifier(AugmentationIdentifier.create(ImmutableSet.of(REF_FROM_AUG)))
- .withChild(ImmutableNodes.leafNode(REF_FROM_AUG, refValue))
- .build())
+ .withChild(ImmutableNodes.leafNode(REF_FROM_AUG, refValue))
.build())
.build())
.build())
}
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.augmentationBuilder()
- .withNodeIdentifier(AugmentationIdentifier.create(ImmutableSet.of(CONTAINER_FROM_AUG)))
- .withChild(Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(CONTAINER_FROM_AUG))
- .withChild(ImmutableNodes.leafNode(REF_IN_CONTAINER, refValue))
- .build())
+ .withChild(ImmutableNodes.newContainerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(CONTAINER_FROM_AUG))
+ .withChild(ImmutableNodes.leafNode(REF_IN_CONTAINER, refValue))
.build())
.build())
.build())