Package names for enclosed Types of TOs were changed to fully qualified. 12/612/1
authorJozef Gloncak <jgloncak@cisco.com>
Thu, 18 Jul 2013 12:39:14 +0000 (14:39 +0200)
committerJozef Gloncak <jgloncak@cisco.com>
Thu, 18 Jul 2013 12:39:14 +0000 (14:39 +0200)
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 <jgloncak@cisco.com>
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/bit_and_union_in_leaf.yang [new file with mode: 0644]

index ec57cb4a3ca73185fe428bd25ccae4b6e0d7d60f..6700b470faee489b0789dfde840b4a1e65c47448 100644 (file)
@@ -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 (file)
index 0000000..3ca4f3e
--- /dev/null
@@ -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<File> testModels = new ArrayList<File>();
+
+    @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<Module> modules = parser.parseYangModels(testModels);
+        final SchemaContext context = parser.resolveSchemaContext(modules);
+
+        assertNotNull(context);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
+        final List<Type> 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<GeneratedType> 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<GeneratedProperty> 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<GeneratedProperty> 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 (file)
index 0000000..e254dd2
--- /dev/null
@@ -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