Bug 2624 - XXX.getQName() should return namespace of module to which XXX 41/15141/1
authorPeter Kajsa <pkajsa@cisco.com>
Wed, 11 Feb 2015 12:53:12 +0000 (13:53 +0100)
committerPeter Kajsa <pkajsa@cisco.com>
Wed, 11 Feb 2015 12:53:12 +0000 (13:53 +0100)
belongs.

For more information, please see the Bug 2624.

Change-Id: I47bdc55bb90ad91a31110f9edfa842a39bcdf9ec
Signed-off-by: Peter Kajsa <pkajsa@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java
yang/yang-parser-impl/src/test/resources/added-by-uses-leaf-test/foo.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/added-by-uses-leaf-test/import-module.yang [new file with mode: 0644]

index 0ca3d88b276ce03c509f8a2705cd469603592de1..55cf82726d8d104a4d9c32facff1bcf6d77bc6ab 100644 (file)
@@ -202,7 +202,7 @@ public final class CopyUtils {
         }
 
         if (old.getType() == null) {
-            copy.setTypedef(copy(old.getTypedef(), copy, updateQName));
+            copy.setTypedef(old.getTypedef());
         } else {
             copy.setType(old.getType());
         }
@@ -235,7 +235,7 @@ public final class CopyUtils {
         }
 
         if (old.getType() == null) {
-            copy.setTypedef(copy(old.getTypedef(), copy, updateQName));
+            copy.setTypedef(old.getTypedef());
         } else {
             copy.setType(old.getType());
         }
index a4360a5a67a93345f8e121781ae64ac4bee919c6..3abb8508e7b337b933fbf1b9d121a789319c7131 100644 (file)
@@ -13,6 +13,8 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+
 import java.io.File;
 import java.io.IOException;
 import java.net.URI;
@@ -545,4 +547,41 @@ public class GroupingTest {
         assertEquals(gy.getDataChildByName("leaf-grouping-Y"),SchemaNodeUtils.getRootOriginalIfPossible( gx.getDataChildByName("leaf-grouping-Y")));
     }
 
+    @Test
+    public void testAddedByUsesLeafTypeQName() throws IOException,
+            URISyntaxException {
+
+        Set<Module> loadModules = TestUtils.loadModules(getClass().getResource(
+                "/added-by-uses-leaf-test").toURI());
+
+        assertEquals(2, loadModules.size());
+
+        Module foo = null;
+        Module imp = null;
+        for (Module module : loadModules) {
+            if (module.getName().equals("foo")) {
+                foo = module;
+            }
+            if (module.getName().equals("import-module")) {
+                imp = module;
+            }
+        }
+
+        LeafSchemaNode leaf = (LeafSchemaNode) ((ContainerSchemaNode) foo
+                .getDataChildByName("my-container"))
+                .getDataChildByName("my-leaf");
+
+        TypeDefinition impType = null;
+        Set<TypeDefinition<?>> typeDefinitions = imp.getTypeDefinitions();
+        for (TypeDefinition<?> typeDefinition : typeDefinitions) {
+            if (typeDefinition.getQName().getLocalName().equals("imp-type")) {
+                impType = typeDefinition;
+                break;
+            }
+        }
+
+        assertEquals(leaf.getType().getQName(), impType.getQName());
+
+    }
+
 }
diff --git a/yang/yang-parser-impl/src/test/resources/added-by-uses-leaf-test/foo.yang b/yang/yang-parser-impl/src/test/resources/added-by-uses-leaf-test/foo.yang
new file mode 100644 (file)
index 0000000..413d7c6
--- /dev/null
@@ -0,0 +1,20 @@
+module foo {
+    prefix foo;
+    namespace "namespace-foo";
+
+    import import-module { prefix imp; revision-date 1970-01-02; } 
+    
+    grouping grp {
+        leaf my-leaf {
+            type imp:imp-type;
+        }
+        
+    }
+    
+    container my-container {
+        uses grp;
+        uses imp:imp_grp;
+    }
+    
+}
+
diff --git a/yang/yang-parser-impl/src/test/resources/added-by-uses-leaf-test/import-module.yang b/yang/yang-parser-impl/src/test/resources/added-by-uses-leaf-test/import-module.yang
new file mode 100644 (file)
index 0000000..6cb9f69
--- /dev/null
@@ -0,0 +1,35 @@
+module import-module {
+    prefix imp;
+    namespace "import-module";
+
+    revision 1970-01-02 {
+        description "Initial revision.";
+    }
+
+    typedef imp-type {
+        type string {
+            length "0..100";
+        }
+    }
+
+    grouping imp_grp {
+        
+        typedef grp-type {
+            type string {
+                length "20..30";
+            }
+        }
+
+        leaf my-leaf2 {
+            type grp-type;
+        }
+        
+        leaf union-leaf {
+            type union {
+                type int16;
+                type string;
+            }
+        }
+    }
+}
+