import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.net.URI;
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 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.YangModelParser;
+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, URISyntaxException {
+ public void init() throws IOException, URISyntaxException {
modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
assertEquals(3, modules.size());
}
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());
}
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);
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);
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);
assertNotNull(port_g);
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);
assertNotNull(addresses_g);
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();
assertNotNull(data_g);
assertFalse(data_g.isAddedByUses());
assertFalse(data_u.equals(data_g));
+ assertEquals(data_g, SchemaNodeUtils.getRootOriginalIfPossible(data_u));
ChoiceNode how_u = (ChoiceNode) foo.getDataChildByName("how");
assertNotNull(how_u);
assertNotNull(how_g);
TestUtils.checkIsAddedByUses(how_g, false);
assertFalse(how_u.equals(how_g));
+ assertEquals(how_g, SchemaNodeUtils.getRootOriginalIfPossible(how_u));
LeafSchemaNode address_u = (LeafSchemaNode) foo.getDataChildByName("address");
assertNotNull(address_u);
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) foo.getDataChildByName("port");
assertNotNull(port_u);
assertNotNull(port_g);
TestUtils.checkIsAddedByUses(port_g, false);
assertFalse(port_u.equals(port_g));
+ assertEquals(port_g, SchemaNodeUtils.getRootOriginalIfPossible(port_u));
ListSchemaNode addresses_u = (ListSchemaNode) foo.getDataChildByName("addresses");
assertNotNull(addresses_u);
assertNotNull(addresses_g);
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 = foo.getGroupings();
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);
@Test
public void testCascadeUses() throws Exception {
File yangFile = new File(getClass().getResource("/grouping-test/cascade-uses.yang").toURI());
- YangModelParser parser = new YangParserImpl();
- modules = parser.parseYangModels(Collections.singletonList(yangFile));
+ YangContextParser parser = new YangParserImpl();
+ modules = parser.parseFiles(Collections.singleton(yangFile)).getModules();
assertEquals(1, modules.size());
Module testModule = TestUtils.findModule(modules, "cascade-uses");
SchemaPath expectedPath;
// grouping-U
- Set<DataSchemaNode> childNodes = gu.getChildNodes();
+ Collection<DataSchemaNode> childNodes = gu.getChildNodes();
assertEquals(7, childNodes.size());
- LeafSchemaNode leafGroupingU = null;
+
+ LeafSchemaNode leafGroupingU = (LeafSchemaNode) gu.getDataChildByName("leaf-grouping-U");
+ assertNotNull(leafGroupingU);
+ assertFalse(leafGroupingU.isAddedByUses());
+ assertFalse(SchemaNodeUtils.getOriginalIfPossible(leafGroupingU).isPresent());
+
for (DataSchemaNode childNode : childNodes) {
- if ("leaf-grouping-U".equals(childNode.getQName().getLocalName())) {
- leafGroupingU = (LeafSchemaNode) childNode;
- } else {
+ if (!(childNode.getQName().equals(leafGroupingU.getQName()))) {
TestUtils.checkIsAddedByUses(childNode, true);
}
}
- assertNotNull(leafGroupingU);
- assertFalse(leafGroupingU.isAddedByUses());
// grouping-V
childNodes = gv.getChildNodes();
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")));
}
}