From: Martin Ciglan Date: Wed, 3 Aug 2016 09:41:59 +0000 (+0200) Subject: BUG-865: remove String-based getDataChildByName() X-Git-Tag: release/boron~17 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=mdsal.git;a=commitdiff_plain;h=31b156a4ff193800a8975b5b5ae57b5fce9ebb63 BUG-865: remove String-based getDataChildByName() This is follow-up patch to reflect Yangtools changes and needs to be merged after https://git.opendaylight.org/gerrit/#/c/42898 Note: based on information from YT devs, relying on string-based choice node local-name when lookup by QName failed was useful when dealing with augmented cases. This is supposed to be fixed now in YT and MDSAL should rely on lookup by QName only. See patch: https://git.opendaylight.org/gerrit/#/c/40158/ Change-Id: I1300f3ee01ad678757d564ae76e23ce2c57c76fb Signed-off-by: Martin Ciglan --- diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java index a1b8a70c48..f604a7c9c6 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java @@ -912,10 +912,9 @@ public class BindingGeneratorImpl implements BindingGenerator { final GroupingDefinition grouping = (GroupingDefinition) targetGrouping; SchemaNode result = grouping; for (final QName node : targetPath.getPathFromRoot()) { - // finding by local name is valid, grouping cannot contain nodes - // with same name and different namespace if (result instanceof DataNodeContainer) { - result = ((DataNodeContainer) result).getDataChildByName(node.getLocalName()); + final QName resultNode = QName.create(result.getQName().getModule(), node.getLocalName()); + result = ((DataNodeContainer) result).getDataChildByName(resultNode); } else if (result instanceof ChoiceSchemaNode) { result = ((ChoiceSchemaNode) result).getCaseNodeByName(node.getLocalName()); } diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingSchemaContextUtils.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingSchemaContextUtils.java index a43cf39ec4..1ecb3fd7e8 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingSchemaContextUtils.java +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingSchemaContextUtils.java @@ -169,7 +169,6 @@ public final class BindingSchemaContextUtils { } - // TODO Auto-generated method stub return augmentations; } @@ -179,10 +178,6 @@ public final class BindingSchemaContextUtils { public static Optional findInstantiatedChoice(final DataNodeContainer ctxNode, final QName choiceName) { DataSchemaNode potential = ctxNode.getDataChildByName(choiceName); - if (potential == null) { - potential = ctxNode.getDataChildByName(choiceName.getLocalName()); - } - if (potential instanceof ChoiceSchemaNode) { return Optional.of((ChoiceSchemaNode) potential); } diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/TypeProviderIntegrationTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/TypeProviderIntegrationTest.java index 6aab883503..bb711b5418 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/TypeProviderIntegrationTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/TypeProviderIntegrationTest.java @@ -18,6 +18,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; @@ -48,194 +49,229 @@ public class TypeProviderIntegrationTest { @Test public void testGetTypeDefaultConstructionBinary() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-binary"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-binary"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new byte[] {77, 97, 110}", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-binary"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-binary"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyBinary(new byte[] {77, 97, 110})", actual); } @Test public void testGetTypeDefaultConstructionBits() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-bits"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-bits"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "TestData.LeafBits(false, false, true)", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-bits"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-bits"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyBits(false, false, true)", actual); } @Test public void testGetTypeDefaultConstructionBoolean() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-boolean"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-boolean"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.lang.Boolean(\"true\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-boolean"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-boolean"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyBoolean(new java.lang.Boolean(\"true\"))", actual); } @Test public void testGetTypeDefaultConstructionDecimal() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-decimal64"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-decimal64"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.math.BigDecimal(\"3.14\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-decimal64"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-decimal64"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyDecimal64(new java.math.BigDecimal(\"3.14\"))", actual); } @Test public void testGetTypeDefaultConstructionEmpty() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-empty"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-empty"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.lang.Boolean(\"false\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-empty"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-empty"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyEmpty(new java.lang.Boolean(\"false\"))", actual); } @Test public void testGetTypeDefaultConstructionEnumeration() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-enumeration"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-enumeration"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.LeafEnumeration.Seven", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-enumeration"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-enumeration"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals(PKG + "MyEnumeration.Seven", actual); } @Test public void testGetTypeDefaultConstructionInt8() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-int8"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-int8"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.lang.Byte(\"11\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-int8"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-int8"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyInt8(new java.lang.Byte(\"11\"))", actual); } @Test public void testGetTypeDefaultConstructionInt16() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-int16"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-int16"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.lang.Short(\"111\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-int16"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-int16"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyInt16(new java.lang.Short(\"111\"))", actual); } @Test public void testGetTypeDefaultConstructionInt32() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-int32"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-int32"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.lang.Integer(\"1111\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-int32"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-int32"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyInt32(new java.lang.Integer(\"1111\"))", actual); } @Test public void testGetTypeDefaultConstructionInt64() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-int64"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-int64"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.lang.Long(\"11111\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-int64"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-int64"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyInt64(new java.lang.Long(\"11111\"))", actual); } @Test public void testGetTypeDefaultConstructionLeafref1() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-leafref"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-leafref"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.math.BigDecimal(\"1.234\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-leafref"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-leafref"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.math.BigDecimal(\"1.234\")", actual); } @Test public void testGetTypeDefaultConstructionLeafref2() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-leafref1"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-leafref1"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyBinary(new byte[] {77, 97, 110})", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-leafref1"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-leafref1"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyBinary(new byte[] {77, 97, 110})", actual); } @Test public void testGetTypeDefaultConstructionString() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-string"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-string"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("\"name\"", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-string"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-string"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyString(\"name\")", actual); } @Test public void testGetTypeDefaultConstructionUint8() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-uint8"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-uint8"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.lang.Short(\"11\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-uint8"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-uint8"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyUint8(new java.lang.Short(\"11\"))", actual); } @Test public void testGetTypeDefaultConstructionUint16() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-uint16"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-uint16"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.lang.Integer(\"111\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-uint16"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-uint16"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyUint16(new java.lang.Integer(\"111\"))", actual); } @Test public void testGetTypeDefaultConstructionUint32() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-uint32"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-uint32"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.lang.Long(\"1111\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-uint32"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-uint32"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyUint32(new java.lang.Long(\"1111\"))", actual); } @Test public void testGetTypeDefaultConstructionUint64() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-uint64"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-uint64"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new java.math.BigInteger(\"11111\")", actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-uint64"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-uint64"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); assertEquals("new " + PKG + "MyUint64(new java.math.BigInteger(\"11111\"))", actual); } @Test public void testGetTypeDefaultConstruction() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("ip-leaf"); + final QName leafNode = QName.create(m.getQNameModule(), "ip-leaf"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode); String actual = provider.getTypeDefaultConstruction(leaf); String exp = "new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address(\"0.0.0.1\")"; assertEquals(exp, actual); @@ -243,12 +279,14 @@ public class TypeProviderIntegrationTest { @Test public void testGetTypeDefaultConstructionUnion() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-union"); + final QName leafNode1 = QName.create(m.getQNameModule(), "leaf-union"); + LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName(leafNode1); String actual = provider.getTypeDefaultConstruction(leaf); String expected = "new " + PKG + "TestData.LeafUnion(\"111\".toCharArray())"; assertEquals(expected, actual); - leaf = (LeafSchemaNode) m.getDataChildByName("ext-union"); + final QName leafNode2 = QName.create(m.getQNameModule(), "ext-union"); + leaf = (LeafSchemaNode) m.getDataChildByName(leafNode2); actual = provider.getTypeDefaultConstruction(leaf); expected = "new " + PKG + "MyUnion(\"111\".toCharArray())"; assertEquals(expected, actual); @@ -256,10 +294,14 @@ public class TypeProviderIntegrationTest { @Test public void testGetTypeDefaultConstructionUnionNested() throws ParseException { - ContainerSchemaNode c1 = (ContainerSchemaNode) m.getDataChildByName("c1"); - ContainerSchemaNode c2 = (ContainerSchemaNode) c1.getDataChildByName("c2"); - ContainerSchemaNode c3 = (ContainerSchemaNode) c2.getDataChildByName("c3"); - LeafSchemaNode leaf = (LeafSchemaNode) c3.getDataChildByName("id"); + final QName containerNode1 = QName.create(m.getQNameModule(), "c1"); + ContainerSchemaNode c1 = (ContainerSchemaNode) m.getDataChildByName(containerNode1); + final QName containerNode2 = QName.create(m.getQNameModule(), "c2"); + ContainerSchemaNode c2 = (ContainerSchemaNode) c1.getDataChildByName(containerNode2); + final QName containerNode3 = QName.create(m.getQNameModule(), "c3"); + ContainerSchemaNode c3 = (ContainerSchemaNode) c2.getDataChildByName(containerNode3); + final QName leafNode = QName.create(m.getQNameModule(), "id"); + LeafSchemaNode leaf = (LeafSchemaNode) c3.getDataChildByName(leafNode); String actual = provider.getTypeDefaultConstruction(leaf); String expected = "new " + PKG + "NestedUnion(\"111\".toCharArray())"; diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/Bug4621.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/Bug4621.java index 1789757ff9..c3e98fb964 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/Bug4621.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/Bug4621.java @@ -7,6 +7,8 @@ */ package org.opendaylight.yangtools.sal.binding.yang.types; +import static org.junit.Assert.assertNotNull; + import java.io.File; import java.net.URI; import java.net.URISyntaxException; @@ -14,6 +16,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.opendaylight.yangtools.sal.binding.model.api.Type; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; @@ -43,10 +46,13 @@ public class Bug4621 { expectedEx.expect(IllegalArgumentException.class); - DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName("neighbor")).getDataChildByName - ("neighbor2-id"); + final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor"); + final QName leafrefNode = QName.create(moduleValid.getQNameModule(), "neighbor2-id"); + DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode)) + .getDataChildByName(leafrefNode); LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel; TypeDefinition leafTypeRel = leafRel.getType(); Type leafrefRelResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel); + assertNotNull(leafrefRelResolvedType); } } \ No newline at end of file diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImplTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImplTest.java index d19f1a7ffb..ae7056fef2 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImplTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImplTest.java @@ -52,7 +52,10 @@ public class TypeProviderImplTest { final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrr")).iterator().next(); final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); - DataSchemaNode leafref = ((ListSchemaNode) moduleRelative.getDataChildByName("neighbor")).getDataChildByName("neighbor-id"); + final QName listNode = QName.create(moduleRelative.getQNameModule(), "neighbor"); + final QName leafNode = QName.create(moduleRelative.getQNameModule(), "neighbor-id"); + DataSchemaNode leafref = ((ListSchemaNode) moduleRelative.getDataChildByName(listNode)) + .getDataChildByName(leafNode); LeafSchemaNode leaf = (LeafSchemaNode) leafref; TypeDefinition leafType = leaf.getType(); Type leafrefResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafType, leaf); @@ -66,7 +69,10 @@ public class TypeProviderImplTest { final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lra")).iterator().next(); final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); - DataSchemaNode leafref = ((ListSchemaNode) moduleRelative.getDataChildByName("neighbor")).getDataChildByName("neighbor-id"); + final QName listNode = QName.create(moduleRelative.getQNameModule(), "neighbor"); + final QName leafNode = QName.create(moduleRelative.getQNameModule(), "neighbor-id"); + DataSchemaNode leafref = ((ListSchemaNode) moduleRelative.getDataChildByName(listNode)) + .getDataChildByName(leafNode); LeafSchemaNode leaf = (LeafSchemaNode) leafref; TypeDefinition leafType = leaf.getType(); Type leafrefResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafType, leaf); @@ -80,15 +86,18 @@ public class TypeProviderImplTest { final Module moduleValid = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrv")).iterator().next(); final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); - DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName("neighbor")).getDataChildByName - ("neighbor-id"); + final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor"); + final QName leaf1Node = QName.create(moduleValid.getQNameModule(), "neighbor-id"); + DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode)) + .getDataChildByName(leaf1Node); LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel; TypeDefinition leafTypeRel = leafRel.getType(); Type leafrefRelResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel); assertNotNull(leafrefRelResolvedType); - DataSchemaNode leafrefAbs = ((ListSchemaNode) moduleValid.getDataChildByName("neighbor")).getDataChildByName - ("neighbor2-id"); + final QName leaf2Node = QName.create(moduleValid.getQNameModule(), "neighbor2-id"); + DataSchemaNode leafrefAbs = ((ListSchemaNode) moduleValid.getDataChildByName(listNode)) + .getDataChildByName(leaf2Node); LeafSchemaNode leafAbs = (LeafSchemaNode) leafrefAbs; TypeDefinition leafTypeAbs = leafAbs.getType(); Type leafrefAbsResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafTypeAbs, leafAbs); @@ -97,8 +106,7 @@ public class TypeProviderImplTest { @Test public void testMethodsOfTypeProviderImpl() throws Exception { - final File abstractTopology = new File(getClass().getResource("/base-yang-types.yang") - .toURI()); + final File abstractTopology = new File(getClass().getResource("/base-yang-types.yang").toURI()); final SchemaContext schemaContext = TestUtils.parseYangSources(abstractTopology); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderTest.java index 62300cf970..02269bbecd 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderTest.java @@ -33,6 +33,7 @@ import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; @@ -133,24 +134,28 @@ public class TypeProviderTest { } private static LeafSchemaNode provideLeafNodeFromTopLevelContainer(final Module module, final String containerName, final String leafNodeName) { - final DataSchemaNode rootNode = module.getDataChildByName(containerName); + final QName containerNode = QName.create(module.getQNameModule(), containerName); + final DataSchemaNode rootNode = module.getDataChildByName(containerNode); assertNotNull("Container foo is not present in root of module "+ module.getName(), rootNode); assertTrue(rootNode instanceof DataNodeContainer); + final QName leafNode = QName.create(module.getQNameModule(), leafNodeName); final DataNodeContainer rootContainer = (DataNodeContainer) rootNode; - final DataSchemaNode node = rootContainer.getDataChildByName(leafNodeName); + final DataSchemaNode node = rootContainer.getDataChildByName(leafNode); assertNotNull(node); assertTrue(node instanceof LeafSchemaNode); return (LeafSchemaNode) node; } private static LeafListSchemaNode provideLeafListNodeFromTopLevelContainer(final Module module, final String containerName, final String leafListNodeName) { - final DataSchemaNode rootNode = module.getDataChildByName(containerName); + final QName containerNode = QName.create(module.getQNameModule(), containerName); + final DataSchemaNode rootNode = module.getDataChildByName(containerNode); assertNotNull("Container foo is not present in root of module " + module.getName(), rootNode); assertTrue(rootNode instanceof DataNodeContainer); final DataNodeContainer rootContainer = (DataNodeContainer) rootNode; - final DataSchemaNode node = rootContainer.getDataChildByName(leafListNodeName); + final QName leafListNode = QName.create(module.getQNameModule(), leafListNodeName); + final DataSchemaNode node = rootContainer.getDataChildByName(leafListNode); assertNotNull(node); assertTrue(node instanceof LeafListSchemaNode); return (LeafListSchemaNode) node; @@ -281,7 +286,8 @@ public class TypeProviderTest { assertTrue(leafrefResolvedType1 instanceof GeneratedTransferObject); final Module module = resolveModule("test-type-provider-b"); - final DataSchemaNode rootNode = module.getDataChildByName("id"); + final QName leafNode = QName.create(module.getQNameModule(), "id"); + final DataSchemaNode rootNode = module.getDataChildByName(leafNode); assertNotNull("leaf id is not present in root of module "+ module.getName(), rootNode); assertTrue(rootNode instanceof LeafSchemaNode); leaf = (LeafSchemaNode) rootNode; @@ -300,7 +306,8 @@ public class TypeProviderTest { final Module module = resolveModule("test-type-provider-b"); - final DataSchemaNode enumNode = module.getDataChildByName("enum"); + final QName leafNode = QName.create(module.getQNameModule(), "enum"); + final DataSchemaNode enumNode = module.getDataChildByName(leafNode); assertNotNull("leaf enum is not present in root of module " + module.getName(), enumNode); assertTrue(enumNode instanceof LeafSchemaNode); LeafSchemaNode leaf = (LeafSchemaNode) enumNode; @@ -310,7 +317,8 @@ public class TypeProviderTest { assertNotNull(leafrefResolvedType1); assertTrue(leafrefResolvedType1 instanceof ReferencedTypeImpl); - final DataSchemaNode enumListNode = module.getDataChildByName("enums"); + final QName leafListNode = QName.create(module.getQNameModule(), "enums"); + final DataSchemaNode enumListNode = module.getDataChildByName(leafListNode); assertNotNull("leaf-list enums is not present in root of module "+ module.getName(), enumNode); assertTrue(enumListNode instanceof LeafListSchemaNode); LeafListSchemaNode leafList = (LeafListSchemaNode) enumListNode; @@ -344,7 +352,8 @@ public class TypeProviderTest { final TypeProvider provider = new TypeProviderImpl(schemaContext); final Module module = resolveModule("test-type-provider-b"); - final DataSchemaNode condLeaf = module.getDataChildByName("conditional-leafref"); + final QName leafrefNode = QName.create(module.getQNameModule(), "conditional-leafref"); + final DataSchemaNode condLeaf = module.getDataChildByName(leafrefNode); assertNotNull("leaf conditional-leafref is not present in root of module "+ module.getName(), condLeaf); assertTrue(condLeaf instanceof LeafSchemaNode); LeafSchemaNode leaf = (LeafSchemaNode) condLeaf; @@ -362,7 +371,8 @@ public class TypeProviderTest { final TypeProvider provider = new TypeProviderImpl(schemaContext); final Module module = resolveModule("test-type-provider-b"); - final DataSchemaNode condLeaf = module.getDataChildByName("unreslovable-leafref"); + final QName leafrefNode = QName.create(module.getQNameModule(), "unreslovable-leafref"); + final DataSchemaNode condLeaf = module.getDataChildByName(leafrefNode); assertNotNull("leaf unreslovable-leafref is not present in root of module "+ module.getName(), condLeaf); assertTrue(condLeaf instanceof LeafSchemaNode); LeafSchemaNode leaf = (LeafSchemaNode) condLeaf; @@ -884,7 +894,8 @@ public class TypeProviderTest { result); final Module module = resolveModule("test-type-provider"); - DataSchemaNode rootNode = module.getDataChildByName("root-union-leaf"); + final QName leafUnionNode = QName.create(module.getQNameModule(), "root-union-leaf"); + DataSchemaNode rootNode = module.getDataChildByName(leafUnionNode); assertNotNull("leaf root-union-leaf is not present in root of module "+ module.getName(), rootNode); assertTrue(rootNode instanceof LeafSchemaNode); leaf = (LeafSchemaNode) rootNode; @@ -901,7 +912,8 @@ public class TypeProviderTest { assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangBinary(new byte[] {-45, 23, -33, 125, -9, -33})", result); - rootNode = module.getDataChildByName("root-bits-leaf"); + final QName leafBitsNode = QName.create(module.getQNameModule(), "root-bits-leaf"); + rootNode = module.getDataChildByName(leafBitsNode); assertNotNull("leaf bits-leaf is not present in root of module "+ module.getName(), rootNode); assertTrue(rootNode instanceof LeafSchemaNode); leaf = (LeafSchemaNode) rootNode;