From: Robert Varga Date: Mon, 1 Feb 2021 09:55:54 +0000 (+0100) Subject: Reformulate LeafRefContext without SchemaPath X-Git-Tag: v8.0.0~258 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=01fa439ddcd0d74548e24ccbe0bee02cb8a39b29;p=yangtools.git Reformulate LeafRefContext without SchemaPath The use of SchemaNode.getPath() is a mistake, which we really want to correct. Use SchemaNodeIdentifier to identify nodes, as that is really what we need -- and the methods are really belong to LeafRefContext, not into a separate LeafRefContextUtils class. JIRA: YANGTOOLS-1092 Change-Id: I012861b8f4ad580b86b49a1265eba785958e3437 Signed-off-by: miroslav.kovac Signed-off-by: Michal Banik Signed-off-by: Robert Varga --- diff --git a/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContext.java b/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContext.java index da800460fc..8c6d32b3eb 100644 --- a/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContext.java +++ b/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContext.java @@ -7,12 +7,20 @@ */ package org.opendaylight.yangtools.yang.data.impl.leafref; +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier; import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider; public final class LeafRefContext extends AbstractEffectiveModelContextProvider { @@ -128,6 +136,118 @@ public final class LeafRefContext extends AbstractEffectiveModelContextProvider return referencedByLeafRefCtx; } + @Beta + public LeafRefContext getLeafRefReferencingContext(final SchemaNodeIdentifier node) { + final Iterator iterator = descendantIterator(node); + LeafRefContext leafRefCtx = null; + LeafRefContext current = this; + while (iterator.hasNext() && current != null) { + final QName qname = iterator.next(); + leafRefCtx = current.getReferencingChildByName(qname); + if (iterator.hasNext()) { + current = leafRefCtx; + } + } + + return leafRefCtx; + } + + @Beta + public LeafRefContext getLeafRefReferencedByContext(final SchemaNodeIdentifier node) { + final Iterator iterator = descendantIterator(node); + LeafRefContext leafRefCtx = null; + LeafRefContext current = this; + while (iterator.hasNext() && current != null) { + final QName qname = iterator.next(); + leafRefCtx = current.getReferencedChildByName(qname); + if (iterator.hasNext()) { + current = leafRefCtx; + } + } + + return leafRefCtx; + } + + private Iterator descendantIterator(final SchemaNodeIdentifier node) { + final Iterator nodeSteps = node.getNodeIdentifiers().iterator(); + if (node instanceof SchemaNodeIdentifier.Absolute) { + final Iterator mySteps = currentNodePath.getPathFromRoot().iterator(); + while (mySteps.hasNext()) { + final QName myNext = mySteps.next(); + checkArgument(nodeSteps.hasNext(), "Node %s is an ancestor of %s", node, currentNodePath); + final QName nodeNext = nodeSteps.next(); + checkArgument(myNext.equals(nodeNext), "Node %s is not a descendant of %s", node, currentNodePath); + } + } + return nodeSteps; + } + + @Beta + public boolean isLeafRef(final SchemaNodeIdentifier node) { + final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node); + return leafRefReferencingContext != null && leafRefReferencingContext.isReferencing(); + } + + @Beta + public boolean hasLeafRefChild(final SchemaNodeIdentifier node) { + final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node); + return leafRefReferencingContext != null && leafRefReferencingContext.hasReferencingChild(); + } + + @Beta + public boolean isReferencedByLeafRef(final SchemaNodeIdentifier node) { + final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node); + return leafRefReferencedByContext != null && leafRefReferencedByContext.isReferenced(); + } + + @Beta + public boolean hasChildReferencedByLeafRef(final SchemaNodeIdentifier node) { + final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node); + return leafRefReferencedByContext != null && leafRefReferencedByContext.hasReferencedChild(); + } + + @Beta + public List findAllLeafRefChilds(final SchemaNodeIdentifier node) { + final LeafRefContext ctx = getLeafRefReferencingContext(node); + return ctx == null ? List.of() : ctx.findAllLeafRefChilds(); + } + + private List findAllLeafRefChilds() { + if (isReferencing()) { + return List.of(this); + } + + final List leafRefChilds = new ArrayList<>(); + for (final Entry child : getReferencingChilds().entrySet()) { + leafRefChilds.addAll(child.getValue().findAllLeafRefChilds()); + } + return leafRefChilds; + } + + @Beta + public List findAllChildsReferencedByLeafRef(final SchemaNodeIdentifier node) { + final LeafRefContext ctx = getLeafRefReferencedByContext(node); + return ctx == null ? List.of() : ctx.findAllChildsReferencedByLeafRef(); + } + + private List findAllChildsReferencedByLeafRef() { + if (isReferenced()) { + return List.of(this); + } + + final List childsReferencedByLeafRef = new ArrayList<>(); + for (final Entry child : getReferencedByChilds().entrySet()) { + childsReferencedByLeafRef.addAll(child.getValue().findAllChildsReferencedByLeafRef()); + } + return childsReferencedByLeafRef; + } + + @Beta + public Map getAllLeafRefsReferencingThisNode(final SchemaNodeIdentifier node) { + final LeafRefContext referencedByContext = getLeafRefReferencedByContext(node); + return referencedByContext == null ? Map.of() : referencedByContext.getAllReferencedByLeafRefCtxs(); + } + LeafRefPath getLeafRefNodePath() { LeafRefPath ret = leafRefNodePath; if (ret == null) { diff --git a/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextBuilder.java b/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextBuilder.java index 420e213bf5..472d09d757 100644 --- a/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextBuilder.java +++ b/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextBuilder.java @@ -40,8 +40,7 @@ final class LeafRefContextBuilder implements Builder { final EffectiveModelContext schemaContext) { this.currentNodeQName = requireNonNull(currentNodeQName); this.currentNodePath = requireNonNull(currentNodePath); - // FIXME: requireNonNull - this.schemaContext = schemaContext; + this.schemaContext = requireNonNull(schemaContext); } @Override diff --git a/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextUtils.java b/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextUtils.java deleted file mode 100644 index 43615f505e..0000000000 --- a/data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextUtils.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.yangtools.yang.data.impl.leafref; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -public final class LeafRefContextUtils { - private LeafRefContextUtils() { - // Hidden on purpose - } - - public static LeafRefContext getLeafRefReferencingContext(final SchemaNode node, final LeafRefContext root) { - final SchemaPath schemaPath = node.getPath(); - return getLeafRefReferencingContext(schemaPath, root); - } - - public static LeafRefContext getLeafRefReferencingContext( - final SchemaPath schemaPath, final LeafRefContext root) { - final Iterable pathFromRoot = schemaPath.getPathFromRoot(); - return getLeafRefReferencingContext(pathFromRoot, root); - } - - public static LeafRefContext getLeafRefReferencingContext(final Iterable pathFromRoot, LeafRefContext root) { - LeafRefContext leafRefCtx = null; - final Iterator iterator = pathFromRoot.iterator(); - while (iterator.hasNext() && root != null) { - final QName qname = iterator.next(); - leafRefCtx = root.getReferencingChildByName(qname); - if (iterator.hasNext()) { - root = leafRefCtx; - } - } - - return leafRefCtx; - } - - public static LeafRefContext getLeafRefReferencedByContext(final SchemaNode node, final LeafRefContext root) { - final SchemaPath schemaPath = node.getPath(); - return getLeafRefReferencedByContext(schemaPath, root); - } - - public static LeafRefContext getLeafRefReferencedByContext( - final SchemaPath schemaPath, final LeafRefContext root) { - final Iterable pathFromRoot = schemaPath.getPathFromRoot(); - return getLeafRefReferencedByContext(pathFromRoot, root); - } - - public static LeafRefContext getLeafRefReferencedByContext(final Iterable pathFromRoot, - LeafRefContext root) { - - LeafRefContext leafRefCtx = null; - final Iterator iterator = pathFromRoot.iterator(); - while (iterator.hasNext() && root != null) { - final QName qname = iterator.next(); - leafRefCtx = root.getReferencedChildByName(qname); - if (iterator.hasNext()) { - root = leafRefCtx; - } - } - - return leafRefCtx; - } - - public static boolean isLeafRef(final SchemaNode node, final LeafRefContext root) { - if (node == null || root == null) { - return false; - } - - final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node, root); - if (leafRefReferencingContext == null) { - return false; - } - - return leafRefReferencingContext.isReferencing(); - } - - public static boolean hasLeafRefChild(final SchemaNode node, final LeafRefContext root) { - if (node == null || root == null) { - return false; - } - - final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node, root); - if (leafRefReferencingContext == null) { - return false; - } - - return leafRefReferencingContext.hasReferencingChild(); - } - - public static boolean isReferencedByLeafRef(final SchemaNode node, final LeafRefContext root) { - if (node == null || root == null) { - return false; - } - - final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node, root); - if (leafRefReferencedByContext == null) { - return false; - } - - return leafRefReferencedByContext.isReferenced(); - } - - public static boolean hasChildReferencedByLeafRef(final SchemaNode node, final LeafRefContext root) { - if (node == null || root == null) { - return false; - } - - final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node, root); - if (leafRefReferencedByContext == null) { - return false; - } - - return leafRefReferencedByContext.hasReferencedChild(); - } - - public static List findAllLeafRefChilds(final SchemaNode node, final LeafRefContext root) { - return findAllLeafRefChilds(node.getPath(), root); - } - - public static List findAllLeafRefChilds(final SchemaPath schemaPath, final LeafRefContext root) { - return findAllLeafRefChilds(schemaPath.getPathFromRoot(), root); - } - - public static List findAllLeafRefChilds(final Iterable pathFromRoot, - final LeafRefContext root) { - final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(pathFromRoot, root); - final List allLeafRefsChilds = findAllLeafRefChilds(leafRefReferencingContext); - - return allLeafRefsChilds; - } - - public static List findAllLeafRefChilds(final LeafRefContext parent) { - final LinkedList leafRefChilds = new LinkedList<>(); - if (parent == null) { - return leafRefChilds; - } - - if (parent.isReferencing()) { - leafRefChilds.add(parent); - return leafRefChilds; - } - - final Set> childs = parent.getReferencingChilds().entrySet(); - for (final Entry child : childs) { - leafRefChilds.addAll(findAllLeafRefChilds(child.getValue())); - } - return leafRefChilds; - } - - public static List findAllChildsReferencedByLeafRef(final SchemaNode node, - final LeafRefContext root) { - return findAllChildsReferencedByLeafRef(node.getPath(), root); - } - - public static List findAllChildsReferencedByLeafRef(final SchemaPath schemaPath, - final LeafRefContext root) { - return findAllChildsReferencedByLeafRef(schemaPath.getPathFromRoot(), root); - } - - public static List findAllChildsReferencedByLeafRef(final Iterable pathFromRoot, - final LeafRefContext root) { - - final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(pathFromRoot, root); - final List allChildsReferencedByLeafRef = - findAllChildsReferencedByLeafRef(leafRefReferencedByContext); - - return allChildsReferencedByLeafRef; - } - - public static List findAllChildsReferencedByLeafRef(final LeafRefContext parent) { - final LinkedList childsReferencedByLeafRef = new LinkedList<>(); - if (parent == null) { - return childsReferencedByLeafRef; - } - - if (parent.isReferenced()) { - childsReferencedByLeafRef.add(parent); - return childsReferencedByLeafRef; - } - - final Set> childs = parent.getReferencedByChilds().entrySet(); - for (final Entry child : childs) { - childsReferencedByLeafRef.addAll(findAllChildsReferencedByLeafRef(child.getValue())); - } - return childsReferencedByLeafRef; - } - - public static Map getAllLeafRefsReferencingThisNode( - final SchemaNode node, final LeafRefContext root) { - return getAllLeafRefsReferencingThisNode(node.getPath(), root); - } - - public static Map getAllLeafRefsReferencingThisNode(final SchemaPath path, - final LeafRefContext root) { - return getAllLeafRefsReferencingThisNode(path.getPathFromRoot(), root); - } - - public static Map getAllLeafRefsReferencingThisNode(final Iterable pathFromRoot, - final LeafRefContext root) { - - final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(pathFromRoot, root); - if (leafRefReferencedByContext == null) { - return new HashMap<>(); - } - - return leafRefReferencedByContext.getAllReferencedByLeafRefCtxs(); - } -} diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java index e9c650fb05..7d993ea50f 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java @@ -18,10 +18,9 @@ import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class LeafRefContextTest { @@ -54,7 +53,6 @@ public class LeafRefContextTest { @Test public void test() { - final QName q1 = QName.create(root, "ref1"); final QName q2 = QName.create(root, "leaf1"); final QName q3 = QName.create(root, "cont1"); @@ -62,28 +60,27 @@ public class LeafRefContextTest { final QName q5 = QName.create(root, "list1"); final QName q6 = QName.create(root, "name"); - final DataSchemaNode leafRefNode = rootMod.findDataChildByName(q1).get(); - final DataSchemaNode targetNode = rootMod.findDataChildByName(q2).get(); - final DataSchemaNode cont1Node = rootMod.findDataChildByName(q3).get(); - final DataSchemaNode cont2Node = rootMod.findDataChildByName(q4).get(); - final DataSchemaNode name1Node = rootMod.findDataChildByName(q3, q5, q6).get(); + final Absolute leafRefNode = Absolute.of(q1); + final Absolute targetNode = Absolute.of(q2); + final Absolute cont1Node = Absolute.of(q3); + final Absolute cont2Node = Absolute.of(q4); + final Absolute name1Node = Absolute.of(q3, q5, q6); - assertTrue(LeafRefContextUtils.isLeafRef(leafRefNode, rootLeafRefContext)); - assertFalse(LeafRefContextUtils.isLeafRef(targetNode, rootLeafRefContext)); + assertTrue(rootLeafRefContext.isLeafRef(leafRefNode)); + assertFalse(rootLeafRefContext.isLeafRef(targetNode)); - assertTrue(LeafRefContextUtils.hasLeafRefChild(cont1Node, rootLeafRefContext)); - assertFalse(LeafRefContextUtils.hasLeafRefChild(leafRefNode, rootLeafRefContext)); + assertTrue(rootLeafRefContext.hasLeafRefChild(cont1Node)); + assertFalse(rootLeafRefContext.hasLeafRefChild(leafRefNode)); - assertTrue(LeafRefContextUtils.isReferencedByLeafRef(targetNode, rootLeafRefContext)); - assertFalse(LeafRefContextUtils.isReferencedByLeafRef(leafRefNode, rootLeafRefContext)); + assertTrue(rootLeafRefContext.isReferencedByLeafRef(targetNode)); + assertFalse(rootLeafRefContext.isReferencedByLeafRef(leafRefNode)); - assertTrue(LeafRefContextUtils.hasChildReferencedByLeafRef(cont2Node, rootLeafRefContext)); - assertFalse(LeafRefContextUtils.hasChildReferencedByLeafRef(leafRefNode, rootLeafRefContext)); + assertTrue(rootLeafRefContext.hasChildReferencedByLeafRef(cont2Node)); + assertFalse(rootLeafRefContext.hasChildReferencedByLeafRef(leafRefNode)); - Map leafRefs = LeafRefContextUtils.getAllLeafRefsReferencingThisNode(name1Node, - rootLeafRefContext); + Map leafRefs = rootLeafRefContext.getAllLeafRefsReferencingThisNode(name1Node); assertEquals(4, leafRefs.size()); - leafRefs = LeafRefContextUtils.getAllLeafRefsReferencingThisNode(leafRefNode, rootLeafRefContext); + leafRefs = rootLeafRefContext.getAllLeafRefsReferencingThisNode(leafRefNode); assertTrue(leafRefs.isEmpty()); } } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java index 7536d1495c..7032c0a5ef 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java @@ -24,10 +24,9 @@ import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute; import org.opendaylight.yangtools.yang.parser.api.YangParserException; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; @@ -155,18 +154,12 @@ public class LeafRefContextTreeBuilderTest { final QName q2 = QName.create(tst, "contributor"); final QName q3 = QName.create(tst, "odl-project-name"); - final LeafRefContext odlContrProjNameCtx = rootLeafRefContext.getReferencingChildByName(q1) - .getReferencingChildByName(q2).getReferencingChildByName(q3); - - final DataSchemaNode odlContrProjNameNode = tstMod.findDataChildByName(q1, q2, q3).get(); - - final LeafRefContext foundOdlContrProjNameCtx = LeafRefContextUtils.getLeafRefReferencingContext( - odlContrProjNameNode, rootLeafRefContext); - - assertNotNull(foundOdlContrProjNameCtx); - assertTrue(foundOdlContrProjNameCtx.isReferencing()); - assertNotNull(foundOdlContrProjNameCtx.getLeafRefTargetPath()); - assertEquals(odlContrProjNameCtx, foundOdlContrProjNameCtx); + final LeafRefContext found = rootLeafRefContext.getLeafRefReferencingContext(Absolute.of(q1, q2, q3)); + assertNotNull(found); + assertTrue(found.isReferencing()); + assertNotNull(found.getLeafRefTargetPath()); + assertEquals(rootLeafRefContext + .getReferencingChildByName(q1).getReferencingChildByName(q2).getReferencingChildByName(q3), found); } @Test @@ -175,46 +168,39 @@ public class LeafRefContextTreeBuilderTest { final QName q2 = QName.create(tst, "project"); final QName q3 = QName.create(tst, "name"); - final LeafRefContext leafRefCtx = rootLeafRefContext.getReferencedChildByName(q1).getReferencedChildByName(q2) - .getReferencedChildByName(q3); + final Absolute node = Absolute.of(q1, q2, q3); + LeafRefContext found = rootLeafRefContext.getLeafRefReferencingContext(node); + assertNull(found); - final DataSchemaNode odlProjNameNode = tstMod.findDataChildByName(q1, q2, q3).get(); + found = rootLeafRefContext.getLeafRefReferencedByContext(node); - LeafRefContext foundOdlProjNameCtx = LeafRefContextUtils.getLeafRefReferencingContext(odlProjNameNode, - rootLeafRefContext); - - assertNull(foundOdlProjNameCtx); - - foundOdlProjNameCtx = LeafRefContextUtils.getLeafRefReferencedByContext(odlProjNameNode, rootLeafRefContext); - - assertNotNull(foundOdlProjNameCtx); - assertTrue(foundOdlProjNameCtx.isReferenced()); - assertFalse(foundOdlProjNameCtx.getAllReferencedByLeafRefCtxs().isEmpty()); - assertEquals(6, foundOdlProjNameCtx.getAllReferencedByLeafRefCtxs().size()); - assertEquals(leafRefCtx, foundOdlProjNameCtx); + assertNotNull(found); + assertTrue(found.isReferenced()); + assertFalse(found.getAllReferencedByLeafRefCtxs().isEmpty()); + assertEquals(6, found.getAllReferencedByLeafRefCtxs().size()); + assertEquals(rootLeafRefContext + .getReferencedChildByName(q1).getReferencedChildByName(q2).getReferencedChildByName(q3), found); } @Test public void leafRefContextUtilsTest3() { final QName q16 = QName.create(tst, "con1"); - final DataSchemaNode con1 = tstMod.findDataChildByName(q16).get(); - final List allLeafRefChilds = LeafRefContextUtils.findAllLeafRefChilds(con1, - rootLeafRefContext); + final Absolute con1 = Absolute.of(q16); + + final List allLeafRefChilds = rootLeafRefContext.findAllLeafRefChilds(con1); assertNotNull(allLeafRefChilds); assertFalse(allLeafRefChilds.isEmpty()); assertEquals(4, allLeafRefChilds.size()); - final QName q17 = QName.create(tst, "odl-contributor"); - final DataSchemaNode odlContributorNode = tstMod.findDataChildByName(q17).get(); - List allChildsReferencedByLeafRef = LeafRefContextUtils.findAllChildsReferencedByLeafRef( - odlContributorNode, rootLeafRefContext); + List allChildsReferencedByLeafRef = rootLeafRefContext.findAllChildsReferencedByLeafRef( + Absolute.of(QName.create(tst, "odl-contributor"))); assertNotNull(allChildsReferencedByLeafRef); assertFalse(allChildsReferencedByLeafRef.isEmpty()); assertEquals(1, allChildsReferencedByLeafRef.size()); - allChildsReferencedByLeafRef = LeafRefContextUtils.findAllChildsReferencedByLeafRef(con1, rootLeafRefContext); + allChildsReferencedByLeafRef = rootLeafRefContext.findAllChildsReferencedByLeafRef(con1); assertNotNull(allChildsReferencedByLeafRef); assertTrue(allChildsReferencedByLeafRef.isEmpty());