From 831791136c1580d26b01074b8654bb1d01291f87 Mon Sep 17 00:00:00 2001 From: Jozef Gloncak Date: Thu, 18 Jul 2013 14:39:14 +0200 Subject: [PATCH] Package names for enclosed Types of TOs were changed to fully qualified. Fully qualified package names are added to enclosed Types of transport objects. In previous version there was bug (name of enclosing type was missing in package name). Signed-off-by: Jozef Gloncak --- .../generator/impl/BindingGeneratorImpl.java | 6 +- .../impl/BitAndUnionTOEnclosingTest.java | 133 ++++++++++++++++++ .../test/resources/bit_and_union_in_leaf.yang | 55 ++++++++ 3 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/bit_and_union_in_leaf.yang diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java index ec57cb4a3c..6700b470fa 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java @@ -1187,10 +1187,10 @@ public final class BindingGeneratorImpl implements BindingGenerator { GeneratedTOBuilder genTOBuilder = null; if (typeDef instanceof UnionType) { genTOBuilder = ((TypeProviderImpl) typeProvider).addUnionGeneratedTypeDefinition( - typeBuilder.getPackageName(), typeDef, className); + typeBuilder.getFullyQualifiedName(), typeDef, className); } else if (typeDef instanceof BitsTypeDefinition) { - genTOBuilder = ((TypeProviderImpl) typeProvider).bitsTypedefToTransferObject(typeBuilder.getPackageName(), - typeDef, className); + genTOBuilder = ((TypeProviderImpl) typeProvider).bitsTypedefToTransferObject( + typeBuilder.getFullyQualifiedName(), typeDef, className); } if (genTOBuilder != null) { typeBuilder.addEnclosingTransferObject(genTOBuilder); diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java new file mode 100644 index 0000000000..3ca4f3e70e --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2013 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.controller.sal.binding.generator.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator; +import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty; +import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject; +import org.opendaylight.controller.sal.binding.model.api.GeneratedType; +import org.opendaylight.controller.sal.binding.model.api.Type; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.SchemaContext; +import org.opendaylight.controller.yang.model.parser.api.YangModelParser; +import org.opendaylight.controller.yang.parser.impl.YangParserImpl; + +public class BitAndUnionTOEnclosingTest { + + private final static List testModels = new ArrayList(); + + @BeforeClass + public static void loadTestResources() { + final File listModelFile = new File(ExtendedTypedefTest.class.getResource("/bit_and_union_in_leaf.yang") + .getPath()); + testModels.add(listModelFile); + } + + @Test + public void bitAndUnionEnclosingTest() { + final YangModelParser parser = new YangParserImpl(); + final Set modules = parser.parseYangModels(testModels); + final SchemaContext context = parser.resolveSchemaContext(modules); + + assertNotNull(context); + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + + GeneratedType parentContainer = null; + + for (Type type : genTypes) { + if ((type instanceof GeneratedType) && !(type instanceof GeneratedTransferObject)) { + GeneratedType genTO = (GeneratedType) type; + if (genTO.getName().equals("ParentContainer")) { + parentContainer = genTO; + break; + } + } + } + + assertNotNull("Parent container object wasn't found.", parentContainer); + + GeneratedTransferObject bitLeaf = null; + GeneratedTransferObject unionLeaf = null; + List enclosedTypes = parentContainer.getEnclosedTypes(); + for (GeneratedType genType : enclosedTypes) { + if (genType instanceof GeneratedTransferObject) { + if (genType.getName().equals("BitLeaf")) { + bitLeaf = (GeneratedTransferObject) genType; + } else if (genType.getName().equals("UnionLeaf")) { + unionLeaf = (GeneratedTransferObject) genType; + } + } + } + + assertNotNull("BitLeaf TO builder wasn't found.", bitLeaf); + assertNotNull("UnionLeaf TO builder wasn't found.", unionLeaf); + + assertEquals("BitLeaf has incorrect package name.", + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer", + bitLeaf.getPackageName()); + assertEquals("UnionLeaf has incorrect package name.", + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer", + bitLeaf.getPackageName()); + + List propertiesBitLeaf = bitLeaf.getProperties(); + GeneratedProperty firstBitProperty = null; + GeneratedProperty secondBitProperty = null; + GeneratedProperty thirdBitProperty = null; + for (GeneratedProperty genProperty : propertiesBitLeaf) { + if (genProperty.getName().equals("firstBit")) { + firstBitProperty = genProperty; + } else if (genProperty.getName().equals("secondBit")) { + secondBitProperty = genProperty; + } else if (genProperty.getName().equals("thirdBit")) { + thirdBitProperty = genProperty; + } + } + + assertNotNull("firstBit property wasn't found", firstBitProperty); + assertNotNull("secondBit property wasn't found", secondBitProperty); + assertNotNull("thirdBit property wasn't found", thirdBitProperty); + + assertEquals("firstBit property has incorrect type", "Boolean", firstBitProperty.getReturnType().getName()); + assertEquals("secondBit property has incorrect type", "Boolean", secondBitProperty.getReturnType().getName()); + assertEquals("thirdBit property has incorrect type", "Boolean", thirdBitProperty.getReturnType().getName()); + + GeneratedProperty uint32Property = null; + GeneratedProperty stringProperty = null; + GeneratedProperty uint8Property = null; + List propertiesUnionLeaf = unionLeaf.getProperties(); + for (GeneratedProperty genProperty : propertiesUnionLeaf) { + if (genProperty.getName().equals("int32")) { + uint32Property = genProperty; + } else if (genProperty.getName().equals("string")) { + stringProperty = genProperty; + } else if (genProperty.getName().equals("uint8")) { + uint8Property = genProperty; + } + } + + assertNotNull("uint32 property wasn't found", uint32Property); + assertNotNull("string property wasn't found", stringProperty); + assertNotNull("uint8 property wasn't found", uint8Property); + + assertEquals("uint32 property has incorrect type", "Integer", uint32Property.getReturnType().getName()); + assertEquals("string property has incorrect type", "String", stringProperty.getReturnType().getName()); + assertEquals("uint8 property has incorrect type", "Short", uint8Property.getReturnType().getName()); + + } +} diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/bit_and_union_in_leaf.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/bit_and_union_in_leaf.yang new file mode 100644 index 0000000000..e254dd224f --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/bit_and_union_in_leaf.yang @@ -0,0 +1,55 @@ +module bit-and-union-in-leaf { + + namespace "urn:bit:union:in:leaf"; + prefix "sbd"; + + organization "OPEN DAYLIGHT"; + contact "http://www.opendaylight.org/"; + + revision 2013-06-26 { + + } + + typedef union-typedef { + type union { + type string { + pattern "[a-g]"; + }; + type int16; + } + } + + typedef union-typedef2 { + type union { + type string; + type int16; + } + } + + container parent-container { + leaf bit-leaf { + type bits { + bit first-bit; + bit second-bit; + bit third-bit; + } + } + + leaf union-leaf { + type union { + type int32; + type string { + pattern "[a-z]"; + }; + type string { + pattern "[0-9]*" + }; + type string { + pattern "[a-d]*"; + pattern "[0-5]*"; + }; + type uint8; + } + } + } +} \ No newline at end of file -- 2.36.6