Bug 2480: Union objects are generated incorrectly when using bits type
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / GroupingTest.java
index eb7581681d880f4f21c0f3daba80a25a2d3deac7..a4360a5a67a93345f8e121781ae64ac4bee919c6 100644 (file)
@@ -7,20 +7,28 @@
  */
 package org.opendaylight.yangtools.yang.parser.impl;
 
-import static org.junit.Assert.*;
-
-import java.io.FileNotFoundException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
 import java.net.URI;
-import java.text.ParseException;
+import java.net.URISyntaxException;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -33,45 +41,49 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
+import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
 
 public class GroupingTest {
     private Set<Module> modules;
 
     @Before
-    public void init() throws FileNotFoundException {
-        modules = TestUtils.loadModules(getClass().getResource("/model").getPath());
+    public void init() throws IOException, URISyntaxException {
+        modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
         assertEquals(3, modules.size());
     }
 
     @Test
     public void testRefine() {
-        Module testModule = TestUtils.findModule(modules, "nodes");
-
+        Module testModule = TestUtils.findModule(modules, "foo");
         ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
         ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
+
         Set<UsesNode> usesNodes = destination.getUses();
         assertEquals(1, usesNodes.size());
         UsesNode usesNode = usesNodes.iterator().next();
         Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
-        assertEquals(3, refines.size());
+        assertEquals(4, refines.size());
 
         LeafSchemaNode refineLeaf = null;
         ContainerSchemaNode refineContainer = null;
         ListSchemaNode refineList = null;
+        LeafSchemaNode refineInnerLeaf = null;
         for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
             SchemaNode value = entry.getValue();
-            if (value instanceof LeafSchemaNode) {
+            if ("address".equals(value.getQName().getLocalName())) {
                 refineLeaf = (LeafSchemaNode) value;
-            } else if (value instanceof ContainerSchemaNode) {
+            } else if ("port".equals(value.getQName().getLocalName())) {
                 refineContainer = (ContainerSchemaNode) value;
-            } else if (value instanceof ListSchemaNode) {
+            } else if ("addresses".equals(value.getQName().getLocalName())) {
                 refineList = (ListSchemaNode) value;
+            } else if ("id".equals(value.getQName().getLocalName())) {
+                refineInnerLeaf = (LeafSchemaNode) value;
             }
         }
 
         // leaf address
         assertNotNull(refineLeaf);
-        assertEquals("address", refineLeaf.getQName().getLocalName());
         assertEquals("IP address of target node", refineLeaf.getDescription());
         assertEquals("address reference added by refine", refineLeaf.getReference());
         assertFalse(refineLeaf.isConfiguration());
@@ -80,6 +92,7 @@ public class GroupingTest {
         assertEquals(1, leafMustConstraints.size());
         MustDefinition leafMust = leafMustConstraints.iterator().next();
         assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString());
+        assertEquals(1, refineLeaf.getUnknownSchemaNodes().size());
 
         // container port
         assertNotNull(refineContainer);
@@ -96,16 +109,20 @@ public class GroupingTest {
         assertEquals("addresses reference added by refine", refineList.getReference());
         assertFalse(refineList.isConfiguration());
         assertEquals(2, (int) refineList.getConstraints().getMinElements());
-        assertEquals(12, (int) refineList.getConstraints().getMaxElements());
+        assertEquals(Integer.MAX_VALUE, (int) refineList.getConstraints().getMaxElements());
+
+        // leaf id
+        assertNotNull(refineInnerLeaf);
+        assertEquals("id of address", refineInnerLeaf.getDescription());
     }
 
     @Test
     public void testGrouping() {
-        Module testModule = TestUtils.findModule(modules, "custom");
+        Module testModule = TestUtils.findModule(modules, "baz");
         Set<GroupingDefinition> groupings = testModule.getGroupings();
         assertEquals(1, groupings.size());
         GroupingDefinition grouping = groupings.iterator().next();
-        Set<DataSchemaNode> children = grouping.getChildNodes();
+        Collection<DataSchemaNode> children = grouping.getChildNodes();
         assertEquals(5, children.size());
     }
 
@@ -114,14 +131,14 @@ public class GroupingTest {
         // suffix _u = added by uses
         // suffix _g = defined in grouping
 
-        Module testModule = TestUtils.findModule(modules, "custom");
+        Module testModule = TestUtils.findModule(modules, "baz");
 
         // get grouping
         Set<GroupingDefinition> groupings = testModule.getGroupings();
         assertEquals(1, groupings.size());
         GroupingDefinition grouping = groupings.iterator().next();
 
-        testModule = TestUtils.findModule(modules, "nodes");
+        testModule = TestUtils.findModule(modules, "foo");
 
         // get node containing uses
         ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
@@ -140,15 +157,19 @@ public class GroupingTest {
         assertNotNull(data_g);
         assertFalse(data_g.isAddedByUses());
         assertFalse(data_u.equals(data_g));
+        assertEquals(data_g,  SchemaNodeUtils.getRootOriginalIfPossible(data_u));
 
         ChoiceNode how_u = (ChoiceNode) destination.getDataChildByName("how");
         assertNotNull(how_u);
-        assertTrue(how_u.isAddedByUses());
+        TestUtils.checkIsAddedByUses(how_u, true);
+        assertEquals(2, how_u.getCases().size());
 
         ChoiceNode how_g = (ChoiceNode) grouping.getDataChildByName("how");
         assertNotNull(how_g);
-        assertFalse(how_g.isAddedByUses());
+        TestUtils.checkIsAddedByUses(how_g, false);
+        assertEquals(2, how_g.getCases().size());
         assertFalse(how_u.equals(how_g));
+        assertEquals(how_g, SchemaNodeUtils.getRootOriginalIfPossible(how_u));
 
         LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName("address");
         assertNotNull(address_u);
@@ -168,36 +189,39 @@ public class GroupingTest {
         assertTrue(address_g.isConfiguration());
         assertFalse(address_u.equals(address_g));
         assertTrue(address_g.getConstraints().isMandatory());
+        assertEquals(address_g, SchemaNodeUtils.getRootOriginalIfPossible(address_u));
 
         ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName("port");
         assertNotNull(port_u);
-        assertTrue(port_u.isAddedByUses());
+        TestUtils.checkIsAddedByUses(port_u, true);
 
         ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName("port");
         assertNotNull(port_g);
-        assertFalse(port_g.isAddedByUses());
+        TestUtils.checkIsAddedByUses(port_g, false);
         assertFalse(port_u.equals(port_g));
+        assertEquals(port_g, SchemaNodeUtils.getRootOriginalIfPossible(port_u));
 
         ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName("addresses");
         assertNotNull(addresses_u);
-        assertTrue(addresses_u.isAddedByUses());
+        TestUtils.checkIsAddedByUses(addresses_u, true);
 
         ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName("addresses");
         assertNotNull(addresses_g);
-        assertFalse(addresses_g.isAddedByUses());
+        TestUtils.checkIsAddedByUses(addresses_g, false);
         assertFalse(addresses_u.equals(addresses_g));
+        assertEquals(addresses_g, SchemaNodeUtils.getRootOriginalIfPossible(addresses_u));
 
         // grouping defined by 'uses'
         Set<GroupingDefinition> groupings_u = destination.getGroupings();
         assertEquals(1, groupings_u.size());
         GroupingDefinition grouping_u = groupings_u.iterator().next();
-        assertTrue(grouping_u.isAddedByUses());
+        TestUtils.checkIsAddedByUses(grouping_u, true);
 
         // grouping defined in 'grouping' node
         Set<GroupingDefinition> groupings_g = grouping.getGroupings();
         assertEquals(1, groupings_g.size());
         GroupingDefinition grouping_g = groupings_g.iterator().next();
-        assertFalse(grouping_g.isAddedByUses());
+        TestUtils.checkIsAddedByUses(grouping_g, false);
         assertFalse(grouping_u.equals(grouping_g));
 
         List<UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
@@ -217,7 +241,7 @@ public class GroupingTest {
         // suffix _u = added by uses
         // suffix _g = defined in grouping
 
-        Module testModule = TestUtils.findModule(modules, "custom");
+        Module testModule = TestUtils.findModule(modules, "baz");
 
         // get grouping
         Set<GroupingDefinition> groupings = testModule.getGroupings();
@@ -225,14 +249,14 @@ public class GroupingTest {
         GroupingDefinition grouping = groupings.iterator().next();
 
         // get node containing uses
-        Module destination = TestUtils.findModule(modules, "nodes");
+        Module foo = TestUtils.findModule(modules, "foo");
 
         // check uses
-        Set<UsesNode> uses = destination.getUses();
+        Set<UsesNode> uses = foo.getUses();
         assertEquals(1, uses.size());
 
         // check uses process
-        AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) destination.getDataChildByName("data");
+        AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) foo.getDataChildByName("data");
         assertNotNull(data_u);
         assertTrue(data_u.isAddedByUses());
 
@@ -240,17 +264,28 @@ public class GroupingTest {
         assertNotNull(data_g);
         assertFalse(data_g.isAddedByUses());
         assertFalse(data_u.equals(data_g));
+        assertEquals(data_g, SchemaNodeUtils.getRootOriginalIfPossible(data_u));
 
-        ChoiceNode how_u = (ChoiceNode) destination.getDataChildByName("how");
+        ChoiceNode how_u = (ChoiceNode) foo.getDataChildByName("how");
         assertNotNull(how_u);
-        assertTrue(how_u.isAddedByUses());
+        TestUtils.checkIsAddedByUses(how_u, true);
+        assertFalse(how_u.isAugmenting());
+        Set<ChoiceCaseNode> cases_u = how_u.getCases();
+        assertEquals(2, cases_u.size());
+        ChoiceCaseNode interval = how_u.getCaseNodeByName("interval");
+        assertFalse(interval.isAugmenting());
+        LeafSchemaNode name = (LeafSchemaNode) interval.getDataChildByName("name");
+        assertTrue(name.isAugmenting());
+        LeafSchemaNode intervalLeaf = (LeafSchemaNode) interval.getDataChildByName("interval");
+        assertFalse(intervalLeaf.isAugmenting());
 
         ChoiceNode how_g = (ChoiceNode) grouping.getDataChildByName("how");
         assertNotNull(how_g);
-        assertFalse(how_g.isAddedByUses());
+        TestUtils.checkIsAddedByUses(how_g, false);
         assertFalse(how_u.equals(how_g));
+        assertEquals(how_g, SchemaNodeUtils.getRootOriginalIfPossible(how_u));
 
-        LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName("address");
+        LeafSchemaNode address_u = (LeafSchemaNode) foo.getDataChildByName("address");
         assertNotNull(address_u);
         assertNull(address_u.getDefault());
         assertEquals("Target IP address", address_u.getDescription());
@@ -266,39 +301,42 @@ public class GroupingTest {
         assertNull(address_g.getReference());
         assertTrue(address_g.isConfiguration());
         assertFalse(address_u.equals(address_g));
+        assertEquals(address_g, SchemaNodeUtils.getRootOriginalIfPossible(address_u));
 
-        ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName("port");
+        ContainerSchemaNode port_u = (ContainerSchemaNode) foo.getDataChildByName("port");
         assertNotNull(port_u);
-        assertTrue(port_u.isAddedByUses());
+        TestUtils.checkIsAddedByUses(port_u, true);
 
         ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName("port");
         assertNotNull(port_g);
-        assertFalse(port_g.isAddedByUses());
+        TestUtils.checkIsAddedByUses(port_g, false);
         assertFalse(port_u.equals(port_g));
+        assertEquals(port_g, SchemaNodeUtils.getRootOriginalIfPossible(port_u));
 
-        ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName("addresses");
+        ListSchemaNode addresses_u = (ListSchemaNode) foo.getDataChildByName("addresses");
         assertNotNull(addresses_u);
-        assertTrue(addresses_u.isAddedByUses());
+        TestUtils.checkIsAddedByUses(addresses_u, true);
 
         ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName("addresses");
         assertNotNull(addresses_g);
-        assertFalse(addresses_g.isAddedByUses());
+        TestUtils.checkIsAddedByUses(addresses_g, false);
         assertFalse(addresses_u.equals(addresses_g));
+        assertEquals(addresses_g, SchemaNodeUtils.getRootOriginalIfPossible(addresses_u));
 
         // grouping defined by 'uses'
-        Set<GroupingDefinition> groupings_u = destination.getGroupings();
+        Set<GroupingDefinition> groupings_u = foo.getGroupings();
         assertEquals(1, groupings_u.size());
         GroupingDefinition grouping_u = groupings_u.iterator().next();
-        assertTrue(grouping_u.isAddedByUses());
+        TestUtils.checkIsAddedByUses(grouping_u, true);
 
         // grouping defined in 'grouping' node
         Set<GroupingDefinition> groupings_g = grouping.getGroupings();
         assertEquals(1, groupings_g.size());
         GroupingDefinition grouping_g = groupings_g.iterator().next();
-        assertFalse(grouping_g.isAddedByUses());
+        TestUtils.checkIsAddedByUses(grouping_g, false);
         assertFalse(grouping_u.equals(grouping_g));
 
-        List<UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
+        List<UnknownSchemaNode> nodes_u = foo.getUnknownSchemaNodes();
         assertEquals(1, nodes_u.size());
         UnknownSchemaNode node_u = nodes_u.get(0);
         assertTrue(node_u.isAddedByUses());
@@ -314,7 +352,7 @@ public class GroupingTest {
         assertEquals(1, usesAugments.size());
         AugmentationSchema augment = usesAugments.iterator().next();
         assertEquals("inner augment", augment.getDescription());
-        Set<DataSchemaNode> children = augment.getChildNodes();
+        Collection<DataSchemaNode> children = augment.getChildNodes();
         assertEquals(1, children.size());
         DataSchemaNode leaf = children.iterator().next();
         assertTrue(leaf instanceof LeafSchemaNode);
@@ -322,8 +360,12 @@ public class GroupingTest {
     }
 
     @Test
-    public void testCascadeUses() throws FileNotFoundException, ParseException {
-        modules = TestUtils.loadModules(getClass().getResource("/simple-test").getPath());
+    public void testCascadeUses() throws Exception {
+        File yangFile = new File(getClass().getResource("/grouping-test/cascade-uses.yang").toURI());
+        YangContextParser parser = new YangParserImpl();
+        modules = parser.parseFiles(Collections.singleton(yangFile)).getModules();
+        assertEquals(1, modules.size());
+
         Module testModule = TestUtils.findModule(modules, "cascade-uses");
         Set<GroupingDefinition> groupings = testModule.getGroupings();
 
@@ -334,18 +376,27 @@ public class GroupingTest {
         GroupingDefinition gz = null;
         GroupingDefinition gzz = null;
         for (GroupingDefinition gd : groupings) {
-            if ("grouping-U".equals(gd.getQName().getLocalName()))
+            String name = gd.getQName().getLocalName();
+            switch (name) {
+            case "grouping-U":
                 gu = gd;
-            if ("grouping-V".equals(gd.getQName().getLocalName()))
+                break;
+            case "grouping-V":
                 gv = gd;
-            if ("grouping-X".equals(gd.getQName().getLocalName()))
+                break;
+            case "grouping-X":
                 gx = gd;
-            if ("grouping-Y".equals(gd.getQName().getLocalName()))
+                break;
+            case "grouping-Y":
                 gy = gd;
-            if ("grouping-Z".equals(gd.getQName().getLocalName()))
+                break;
+            case "grouping-Z":
                 gz = gd;
-            if ("grouping-ZZ".equals(gd.getQName().getLocalName()))
+                break;
+            case "grouping-ZZ":
                 gzz = gd;
+                break;
+            }
         }
         assertNotNull(gu);
         assertNotNull(gv);
@@ -354,43 +405,144 @@ public class GroupingTest {
         assertNotNull(gz);
         assertNotNull(gzz);
 
-        assertEquals(7, gu.getChildNodes().size());
-        assertEquals(4, gv.getChildNodes().size());
-        assertEquals(2, gx.getChildNodes().size());
-        assertEquals(1, gy.getChildNodes().size());
-        assertEquals(1, gz.getChildNodes().size());
-        assertEquals(1, gzz.getChildNodes().size());
-
         URI expectedNS = URI.create("urn:grouping:cascade-uses");
-        Date expectedRev = TestUtils.simpleDateFormat.parse("2013-07-18");
+        Date expectedRev = new SimpleDateFormat("yyyy-MM-dd").parse("2013-07-18");
         String expectedPref = "cu";
         SchemaPath expectedPath;
 
+        // grouping-U
+        Collection<DataSchemaNode> childNodes = gu.getChildNodes();
+        assertEquals(7, childNodes.size());
+
+        LeafSchemaNode leafGroupingU = (LeafSchemaNode) gu.getDataChildByName("leaf-grouping-U");
+        assertNotNull(leafGroupingU);
+        assertFalse(leafGroupingU.isAddedByUses());
+        assertFalse(SchemaNodeUtils.getOriginalIfPossible(leafGroupingU).isPresent());
+
+        for (DataSchemaNode childNode : childNodes) {
+            if (!(childNode.getQName().equals(leafGroupingU.getQName()))) {
+                TestUtils.checkIsAddedByUses(childNode, true);
+            }
+        }
+
+        // grouping-V
+        childNodes = gv.getChildNodes();
+        assertEquals(4, childNodes.size());
+        LeafSchemaNode leafGroupingV = null;
+        ContainerSchemaNode containerGroupingV = null;
+        for (DataSchemaNode childNode : childNodes) {
+            if ("leaf-grouping-V".equals(childNode.getQName().getLocalName())) {
+                leafGroupingV = (LeafSchemaNode) childNode;
+            } else if ("container-grouping-V".equals(childNode.getQName().getLocalName())) {
+                containerGroupingV = (ContainerSchemaNode) childNode;
+            } else {
+                TestUtils.checkIsAddedByUses(childNode, true);
+            }
+        }
+        assertNotNull(leafGroupingV);
+        assertFalse(leafGroupingV.isAddedByUses());
+
         // grouping-V/container-grouping-V
-        ContainerSchemaNode containerV = (ContainerSchemaNode)gv.getDataChildByName("container-grouping-V");
-        assertNotNull(containerV);
-        assertEquals(2, containerV.getChildNodes().size());
+        assertNotNull(containerGroupingV);
+        assertFalse(containerGroupingV.isAddedByUses());
+        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V",
+                "container-grouping-V");
+        assertEquals(expectedPath, containerGroupingV.getPath());
+        childNodes = containerGroupingV.getChildNodes();
+        assertEquals(2, childNodes.size());
+        for (DataSchemaNode childNode : childNodes) {
+            TestUtils.checkIsAddedByUses(childNode, true);
+        }
+
         // grouping-V/container-grouping-V/leaf-grouping-X
-        LeafSchemaNode leafXinContainerV = (LeafSchemaNode)containerV.getDataChildByName("leaf-grouping-X");
+        LeafSchemaNode leafXinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName("leaf-grouping-X");
         assertNotNull(leafXinContainerV);
-        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V", "container-grouping-V", "leaf-grouping-X");
+        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V",
+                "container-grouping-V", "leaf-grouping-X");
         assertEquals(expectedPath, leafXinContainerV.getPath());
         // grouping-V/container-grouping-V/leaf-grouping-Y
-        LeafSchemaNode leafYinContainerV = (LeafSchemaNode)containerV.getDataChildByName("leaf-grouping-Y");
+        LeafSchemaNode leafYinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName("leaf-grouping-Y");
         assertNotNull(leafYinContainerV);
-        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V", "container-grouping-V", "leaf-grouping-Y");
+        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V",
+                "container-grouping-V", "leaf-grouping-Y");
         assertEquals(expectedPath, leafYinContainerV.getPath());
 
+        // grouping-X
+        childNodes = gx.getChildNodes();
+        assertEquals(2, childNodes.size());
+
         // grouping-X/leaf-grouping-X
-        LeafSchemaNode leafXinGX = (LeafSchemaNode)gx.getDataChildByName("leaf-grouping-X");
+        LeafSchemaNode leafXinGX = (LeafSchemaNode) gx.getDataChildByName("leaf-grouping-X");
         assertNotNull(leafXinGX);
-        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X", "leaf-grouping-X");
+        assertFalse(leafXinGX.isAddedByUses());
+        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X",
+                "leaf-grouping-X");
         assertEquals(expectedPath, leafXinGX.getPath());
+
         // grouping-X/leaf-grouping-Y
-        LeafSchemaNode leafYinGY = (LeafSchemaNode)gx.getDataChildByName("leaf-grouping-Y");
+        LeafSchemaNode leafYinGX = (LeafSchemaNode) gx.getDataChildByName("leaf-grouping-Y");
+        assertNotNull(leafYinGX);
+        assertTrue(leafYinGX.isAddedByUses());
+        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X",
+                "leaf-grouping-Y");
+        assertEquals(expectedPath, leafYinGX.getPath());
+
+        // grouping-Y
+        childNodes = gy.getChildNodes();
+        assertEquals(1, childNodes.size());
+
+        // grouping-Y/leaf-grouping-Y
+        LeafSchemaNode leafYinGY = (LeafSchemaNode) gy.getDataChildByName("leaf-grouping-Y");
         assertNotNull(leafYinGY);
-        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X", "leaf-grouping-Y");
+        assertFalse(leafYinGY.isAddedByUses());
+        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-Y",
+                "leaf-grouping-Y");
         assertEquals(expectedPath, leafYinGY.getPath());
+
+        // grouping-Z
+        childNodes = gz.getChildNodes();
+        assertEquals(1, childNodes.size());
+
+        // grouping-Z/leaf-grouping-Z
+        LeafSchemaNode leafZinGZ = (LeafSchemaNode) gz.getDataChildByName("leaf-grouping-Z");
+        assertNotNull(leafZinGZ);
+        assertFalse(leafZinGZ.isAddedByUses());
+        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-Z",
+                "leaf-grouping-Z");
+        assertEquals(expectedPath, leafZinGZ.getPath());
+
+        // grouping-ZZ
+        childNodes = gzz.getChildNodes();
+        assertEquals(1, childNodes.size());
+
+        // grouping-ZZ/leaf-grouping-ZZ
+        LeafSchemaNode leafZZinGZZ = (LeafSchemaNode) gzz.getDataChildByName("leaf-grouping-ZZ");
+        assertNotNull(leafZZinGZZ);
+        assertFalse(leafZZinGZZ.isAddedByUses());
+        expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-ZZ",
+                "leaf-grouping-ZZ");
+        assertEquals(expectedPath, leafZZinGZZ.getPath());
+
+        // TEST getOriginal from grouping-U
+        assertEquals(gv.getDataChildByName("leaf-grouping-V"), SchemaNodeUtils.getRootOriginalIfPossible(gu.getDataChildByName("leaf-grouping-V")));
+        containerGroupingV = (ContainerSchemaNode) gu.getDataChildByName("container-grouping-V");
+        assertEquals(gv.getDataChildByName("container-grouping-V"), SchemaNodeUtils.getRootOriginalIfPossible(containerGroupingV));
+        assertEquals(gx.getDataChildByName("leaf-grouping-X"), SchemaNodeUtils.getRootOriginalIfPossible(containerGroupingV.getDataChildByName("leaf-grouping-X")
+                ));
+        assertEquals(gy.getDataChildByName("leaf-grouping-Y"), SchemaNodeUtils.getRootOriginalIfPossible(containerGroupingV.getDataChildByName("leaf-grouping-Y")
+                ));
+
+        assertEquals(gz.getDataChildByName("leaf-grouping-Z"), SchemaNodeUtils.getRootOriginalIfPossible(gu.getDataChildByName("leaf-grouping-Z")));
+        assertEquals(gzz.getDataChildByName("leaf-grouping-ZZ"), SchemaNodeUtils.getRootOriginalIfPossible(gu.getDataChildByName("leaf-grouping-ZZ")
+                ));
+
+        // TEST getOriginal from grouping-V
+        assertEquals(gz.getDataChildByName("leaf-grouping-Z"), SchemaNodeUtils.getRootOriginalIfPossible(gv.getDataChildByName("leaf-grouping-Z")));
+        assertEquals(gzz.getDataChildByName("leaf-grouping-ZZ"), SchemaNodeUtils.getRootOriginalIfPossible(gv.getDataChildByName("leaf-grouping-ZZ")
+                ));
+
+        // TEST getOriginal from grouping-X
+        assertEquals(gy.getDataChildByName("leaf-grouping-Y"),SchemaNodeUtils.getRootOriginalIfPossible( gx.getDataChildByName("leaf-grouping-Y")));
     }
 
 }