--- /dev/null
+/*
+ * 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.yang.parser.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.FileNotFoundException;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AugmentationSchema;
+import org.opendaylight.controller.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
+import org.opendaylight.controller.yang.model.util.Leafref;
+
+import com.google.common.collect.Lists;
+
+public class AugmentTest {
+
+ private final URI types1NS = URI.create("urn:simple.nodes.test");
+ private final URI types2NS = URI.create("urn:simple.types.test");
+ private final URI types3NS = URI.create("urn:custom.nodes.test");
+ private Date types1Rev;
+ private Date types2Rev;
+ private Date types3Rev;
+ private final String t1 = "n";
+ private final String t2 = "t";
+ private final String t3 = "c";
+ private QName q0;
+ private QName q1;
+ private QName q2;
+
+ private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ private Set<Module> modules;
+
+ @Before
+ public void init() throws FileNotFoundException, ParseException {
+ types1Rev = simpleDateFormat.parse("2013-02-27");
+ types2Rev = simpleDateFormat.parse("2013-07-03");
+ types3Rev = simpleDateFormat.parse("2013-02-27");
+
+ q0 = new QName(types2NS, types2Rev, t2, "interfaces");
+ q1 = new QName(types2NS, types2Rev, t2, "ifEntry");
+ q2 = new QName(types3NS, types3Rev, t3, "augment-holder");
+
+ modules = TestUtils.loadModules(getClass().getResource("/model").getPath());
+ assertEquals(3, modules.size());
+ }
+
+ @Test
+ public void testAugmentParsing() {
+ SchemaPath expectedPath = null;
+ QName[] qnames = null;
+
+ // testfile1
+ Module module1 = TestUtils.findModule(modules, "nodes");
+ Set<AugmentationSchema> augmentations = module1.getAugmentations();
+ assertEquals(1, augmentations.size());
+ AugmentationSchema augment = augmentations.iterator().next();
+
+ Set<DataSchemaNode> augmentChildren = augment.getChildNodes();
+ assertEquals(5, augmentChildren.size());
+ for(DataSchemaNode dsn : augmentChildren) {
+ assertTrue(dsn.isAugmenting());
+ }
+
+ LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName("ds0ChannelNumber");
+ LeafSchemaNode interfaceId = (LeafSchemaNode) augment.getDataChildByName("interface-id");
+ LeafSchemaNode myType = (LeafSchemaNode) augment.getDataChildByName("my-type");
+ ContainerSchemaNode schemas = (ContainerSchemaNode) augment.getDataChildByName("schemas");
+ ChoiceNode odl = (ChoiceNode)augment.getDataChildByName("odl");
+
+ assertNotNull(ds0ChannelNumber);
+ assertNotNull(interfaceId);
+ assertNotNull(myType);
+ assertNotNull(schemas);
+ assertNotNull(odl);
+
+ qnames = new QName[4];
+ qnames[0] = q0;
+ qnames[1] = q1;
+ qnames[2] = q2;
+
+ // leaf ds0ChannelNumber
+ qnames[3] = new QName(types1NS, types1Rev, t1, "ds0ChannelNumber");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, ds0ChannelNumber.getPath());
+
+ // leaf interface-id
+ qnames[3] = new QName(types1NS, types1Rev, t1, "interface-id");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, interfaceId.getPath());
+
+ // leaf my-type
+ qnames[3] = new QName(types1NS, types1Rev, t1, "my-type");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, myType.getPath());
+
+ // container schemas
+ qnames[3] = new QName(types1NS, types1Rev, t1, "schemas");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, schemas.getPath());
+
+ // choice odl
+ qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, odl.getPath());
+
+
+ // testfile3
+ Module module3 = TestUtils.findModule(modules, "custom");
+ augmentations = module3.getAugmentations();
+ assertEquals(3, augmentations.size());
+ AugmentationSchema augment1 = null;
+ AugmentationSchema augment2 = null;
+ AugmentationSchema augment3 = null;
+ for (AugmentationSchema as : augmentations) {
+ if("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
+ augment1 = as;
+ } else if("if:ifType='ds2'".equals(as.getWhenCondition().toString())) {
+ augment2 = as;
+ } else if ("if:leafType='ds1'".equals(as.getWhenCondition().toString())) {
+ augment3 = as;
+ }
+ }
+ assertNotNull(augment1);
+ assertNotNull(augment2);
+ assertNotNull(augment3);
+
+ assertEquals(1, augment1.getChildNodes().size());
+ ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment1.getDataChildByName("augment-holder");
+ assertTrue(augmentHolder.isAugmenting());
+
+ assertEquals(1, augment2.getChildNodes().size());
+ ContainerSchemaNode augmentHolder2 = (ContainerSchemaNode) augment2.getDataChildByName("augment-holder2");
+ assertTrue(augmentHolder2.isAugmenting());
+
+ assertEquals(1, augment3.getChildNodes().size());
+ LeafSchemaNode linkleaf = (LeafSchemaNode) augment3.getDataChildByName("linkleaf");
+ assertTrue(linkleaf.isAugmenting());
+ }
+
+ @Test
+ public void testAugmentResolving() throws ParseException {
+ SchemaPath expectedPath = null;
+ QName[] qnames = null;
+
+ Module module2 = TestUtils.findModule(modules, "types");
+ ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces");
+ ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
+ ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder");
+
+ // testfile1.yang
+ // augment "/data:interfaces/data:ifEntry/t3:augment-holder"
+ LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentedContainer.getDataChildByName("ds0ChannelNumber");
+ LeafSchemaNode interfaceId = (LeafSchemaNode) augmentedContainer.getDataChildByName("interface-id");
+ LeafSchemaNode myType = (LeafSchemaNode) augmentedContainer.getDataChildByName("my-type");
+ ContainerSchemaNode schemas = (ContainerSchemaNode) augmentedContainer.getDataChildByName("schemas");
+ ChoiceNode odl = (ChoiceNode)augmentedContainer.getDataChildByName("odl");
+
+ assertNotNull(ds0ChannelNumber);
+ assertNotNull(interfaceId);
+ assertNotNull(myType);
+ assertNotNull(schemas);
+ assertNotNull(odl);
+
+ qnames = new QName[4];
+ qnames[0] = q0;
+ qnames[1] = q1;
+ qnames[2] = q2;
+
+ // leaf ds0ChannelNumber
+ qnames[3] = new QName(types1NS, types1Rev, t1, "ds0ChannelNumber");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, ds0ChannelNumber.getPath());
+
+ // leaf interface-id
+ qnames[3] = new QName(types1NS, types1Rev, t1, "interface-id");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, interfaceId.getPath());
+
+ // leaf my-type
+ qnames[3] = new QName(types1NS, types1Rev, t1, "my-type");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, myType.getPath());
+
+ // container schemas
+ qnames[3] = new QName(types1NS, types1Rev, t1, "schemas");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, schemas.getPath());
+
+ // choice odl
+ qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, odl.getPath());
+
+ // testfile3.yang
+ // augment "/data:interfaces/data:ifEntry/t3:augment-holder/t1:schemas"
+ LeafSchemaNode linkleaf = (LeafSchemaNode) schemas.getDataChildByName("linkleaf");
+ assertNotNull(linkleaf);
+
+ qnames = new QName[5];
+ qnames[0] = q0;
+ qnames[1] = q1;
+ qnames[2] = q2;
+ qnames[3] = new QName(types1NS, types1Rev, t1, "schemas");
+ qnames[4] = new QName(types3NS, types3Rev, t3, "linkleaf");
+ expectedPath = new SchemaPath(Arrays.asList(qnames), true);
+ assertEquals(expectedPath, linkleaf.getPath());
+ }
+
+ @Test
+ public void testAugmentChoice() throws ParseException {
+ SchemaPath expectedPath = null;
+ QName[] qnames = null;
+
+ Module module2 = TestUtils.findModule(modules, "types");
+ ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces");
+ ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
+ ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder");
+
+ // testfile1.yang
+ // augment "/data:interfaces/data:ifEntry/t3:augment-holder"
+ ChoiceNode odl = (ChoiceNode)augmentedContainer.getDataChildByName("odl");
+ assertNotNull(odl);
+ Set<ChoiceCaseNode> cases = odl.getCases();
+ assertEquals(4, cases.size());
+
+ ChoiceCaseNode id = null;
+ ChoiceCaseNode node1 = null;
+ ChoiceCaseNode node2 = null;
+ ChoiceCaseNode node3 = null;
+
+ for(ChoiceCaseNode ccn : cases) {
+ if("id".equals(ccn.getQName().getLocalName())) {
+ id = ccn;
+ } else if("node1".equals(ccn.getQName().getLocalName())) {
+ node1 = ccn;
+ } else if("node2".equals(ccn.getQName().getLocalName())) {
+ node2 = ccn;
+ } else if("node3".equals(ccn.getQName().getLocalName())) {
+ node3 = ccn;
+ }
+ }
+
+ assertNotNull(id);
+ assertNotNull(node1);
+ assertNotNull(node2);
+ assertNotNull(node3);
+
+ qnames = new QName[5];
+ qnames[0] = q0;
+ qnames[1] = q1;
+ qnames[2] = q2;
+ qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
+
+ // case id
+ qnames[4] = new QName(types1NS, types1Rev, t1, "id");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, id.getPath());
+ Set<DataSchemaNode> idChildren = id.getChildNodes();
+ assertEquals(1, idChildren.size());
+
+ // case node1
+ qnames[4] = new QName(types1NS, types1Rev, t1, "node1");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, node1.getPath());
+ Set<DataSchemaNode> node1Children = node1.getChildNodes();
+ assertTrue(node1Children.isEmpty());
+
+ // case node2
+ qnames[4] = new QName(types1NS, types1Rev, t1, "node2");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, node2.getPath());
+ Set<DataSchemaNode> node2Children = node2.getChildNodes();
+ assertTrue(node2Children.isEmpty());
+
+ // case node3
+ qnames[4] = new QName(types1NS, types1Rev, t1, "node3");
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, node3.getPath());
+ Set<DataSchemaNode> node3Children = node3.getChildNodes();
+ assertEquals(1, node3Children.size());
+
+ // test cases
+ qnames = new QName[6];
+ qnames[0] = q0;
+ qnames[1] = q1;
+ qnames[2] = q2;
+ qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
+
+ // case id child
+ qnames[4] = new QName(types1NS, types1Rev, t1, "id");
+ qnames[5] = new QName(types1NS, types1Rev, t1, "id");
+ LeafSchemaNode caseIdChild = (LeafSchemaNode)idChildren.iterator().next();
+ assertNotNull(caseIdChild);
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, caseIdChild.getPath());
+
+ // case node3 child
+ qnames[4] = new QName(types1NS, types1Rev, t1, "node3");
+ qnames[5] = new QName(types1NS, types1Rev, t1, "node3");
+ ContainerSchemaNode caseNode3Child = (ContainerSchemaNode)node3Children.iterator().next();
+ assertNotNull(caseNode3Child);
+ expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+ assertEquals(expectedPath, caseNode3Child.getPath());
+ }
+
+ @Test
+ public void testAugmentNodesTypeSchemaPath() throws Exception {
+ Module testModule = TestUtils.findModule(modules, "nodes");
+ Set<AugmentationSchema> augments = testModule.getAugmentations();
+ assertEquals(1, augments.size());
+ AugmentationSchema augment = augments.iterator().next();
+
+ LeafSchemaNode ifcId = (LeafSchemaNode) augment.getDataChildByName("interface-id");
+ Leafref ifcIdType = (Leafref) ifcId.getType();
+ SchemaPath ifcIdTypeSchemaPath = ifcIdType.getPath();
+ List<QName> ifcIdTypePath = ifcIdTypeSchemaPath.getPath();
+
+ Date expectedDate = simpleDateFormat.parse("2013-02-27");
+
+ QName q3 = new QName(types1NS, expectedDate, "data", "interface-id");
+ assertEquals(q0, ifcIdTypePath.get(0));
+ assertEquals(q1, ifcIdTypePath.get(1));
+ assertEquals(q2, ifcIdTypePath.get(2));
+ assertEquals(q3, ifcIdTypePath.get(3));
+
+ LeafSchemaNode myType = (LeafSchemaNode) augment.getDataChildByName("my-type");
+ ExtendedType leafType = (ExtendedType) myType.getType();
+
+ testModule = TestUtils.findModule(modules, "types");
+ TypeDefinition<?> typedef = TestUtils.findTypedef(testModule.getTypeDefinitions(), "int32-ext2");
+
+ assertEquals(typedef, leafType);
+ }
+
+}
import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
import org.opendaylight.controller.yang.model.api.FeatureDefinition;
import org.opendaylight.controller.yang.model.api.GroupingDefinition;
-import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
import org.opendaylight.controller.yang.model.api.ListSchemaNode;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.Int16;
import org.opendaylight.controller.yang.model.util.Int32;
-import org.opendaylight.controller.yang.model.util.Int8;
-import org.opendaylight.controller.yang.model.util.Leafref;
import org.opendaylight.controller.yang.model.util.StringType;
import org.opendaylight.controller.yang.model.util.Uint32;
import org.opendaylight.controller.yang.model.util.UnionType;
public class YangParserTest {
+
+ private final URI nodesNS = URI.create("urn:simple.nodes.test");
+ private final URI typesNS = URI.create("urn:simple.types.test");
+ private final URI customNS = URI.create("urn:custom.nodes.test");
+ private Date nodesRev;
+ private Date typesRev;
+ private Date customRev;
+
private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
private Set<Module> modules;
@Before
- public void init() throws FileNotFoundException {
+ public void init() throws FileNotFoundException, ParseException {
+ nodesRev = simpleDateFormat.parse("2013-02-27");
+ typesRev = simpleDateFormat.parse("2013-07-03");
+ customRev = simpleDateFormat.parse("2013-02-27");
+
modules = TestUtils.loadModules(getClass().getResource("/model").getPath());
assertEquals(3, modules.size());
}
@Test
- public void testHeaders() {
- Module test = TestUtils.findModule(modules, "types1");
+ public void testHeaders() throws ParseException {
+ Module test = TestUtils.findModule(modules, "nodes");
- assertEquals("types1", test.getName());
+ assertEquals("nodes", test.getName());
assertEquals("1", test.getYangVersion());
- URI expectedNamespace = URI.create("urn:simple.container.demo");
- assertEquals(expectedNamespace, test.getNamespace());
- assertEquals("t1", test.getPrefix());
+ assertEquals(nodesNS, test.getNamespace());
+ assertEquals("n", test.getPrefix());
Set<ModuleImport> imports = test.getImports();
assertEquals(2, imports.size());
- ModuleImport import2 = TestUtils.findImport(imports, "data");
- assertEquals("types2", import2.getModuleName());
- assertEquals(TestUtils.createDate("2013-02-27"), import2.getRevision());
+ ModuleImport import2 = TestUtils.findImport(imports, "t");
+ assertEquals("types", import2.getModuleName());
+ assertEquals(typesRev, import2.getRevision());
- ModuleImport import3 = TestUtils.findImport(imports, "t3");
- assertEquals("types3", import3.getModuleName());
- assertEquals(TestUtils.createDate("2013-02-27"), import3.getRevision());
+ ModuleImport import3 = TestUtils.findImport(imports, "c");
+ assertEquals("custom", import3.getModuleName());
+ assertEquals(customRev, import3.getRevision());
assertEquals("opendaylight", test.getOrganization());
assertEquals("http://www.opendaylight.org/", test.getContact());
@Test
public void testOrderingTypedef() {
- Module test = TestUtils.findModule(modules, "types2");
+ Module test = TestUtils.findModule(modules, "types");
Set<TypeDefinition<?>> typedefs = test.getTypeDefinitions();
- String[] expectedOrder = new String[] { "my-base-int32-type", "my-custom-string", "my-decimal-type",
- "my-decimal-type-ext", "my-int-type", "my-int-type-ext", "my-int-type2", "my-string-type",
- "my-string-type-ext", "my-string-type2", "my-type1", "my-union", "my-union-ext", "nested-union1",
- "nested-union2" };
+ String[] expectedOrder = new String[] { "int32-ext1", "int32-ext2", "my-decimal-type", "my-union",
+ "my-union-ext", "nested-union2", "string-ext1", "string-ext2", "string-ext3", "string-ext4" };
String[] actualOrder = new String[typedefs.size()];
int i = 0;
@Test
public void testOrderingChildNodes() {
- Module test = TestUtils.findModule(modules, "types2");
- Set<DataSchemaNode> childNodes = test.getChildNodes();
- String[] expectedOrder = new String[] { "count", "if-name", "interfaces", "name", "nested-type-leaf", "peer",
- "system" };
- String[] actualOrder = new String[childNodes.size()];
+ Module test = TestUtils.findModule(modules, "nodes");
+ AugmentationSchema augment1 = null;
+ for (AugmentationSchema as : test.getAugmentations()) {
+ if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
+ augment1 = as;
+ break;
+ }
+ }
+ assertNotNull(augment1);
+
+ String[] expectedOrder = new String[] { "ds0ChannelNumber", "interface-id", "my-type", "odl", "schemas" };
+ String[] actualOrder = new String[expectedOrder.length];
int i = 0;
- for (DataSchemaNode child : childNodes) {
- actualOrder[i] = child.getQName().getLocalName();
+ for (DataSchemaNode augmentChild : augment1.getChildNodes()) {
+ actualOrder[i] = augmentChild.getQName().getLocalName();
i++;
}
+
assertArrayEquals(expectedOrder, actualOrder);
}
@Test
public void testOrderingNestedChildNodes() {
- Module test = TestUtils.findModule(modules, "types2");
+ Module test = TestUtils.findModule(modules, "custom");
Set<GroupingDefinition> groupings = test.getGroupings();
assertEquals(1, groupings.size());
GroupingDefinition target = groupings.iterator().next();
@Test
public void testParseContainer() {
- Module test = TestUtils.findModule(modules, "types2");
- URI expectedNamespace = URI.create("urn:simple.types.data.demo");
- String expectedPrefix = "t2";
- Date expectedRevision = TestUtils.createDate("2013-02-27");
+ Module test = TestUtils.findModule(modules, "types");
+ URI expectedNamespace = URI.create("urn:simple.types.test");
+ String expectedPrefix = "t";
ContainerSchemaNode interfaces = (ContainerSchemaNode) test.getDataChildByName("interfaces");
// test SchemaNode args
- QName expectedQName = new QName(expectedNamespace, expectedRevision, expectedPrefix, "interfaces");
+ QName expectedQName = new QName(expectedNamespace, typesRev, expectedPrefix, "interfaces");
assertEquals(expectedQName, interfaces.getQName());
- SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, expectedRevision, expectedPrefix,
- "interfaces");
+ SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, typesRev, expectedPrefix, "interfaces");
assertEquals(expectedPath, interfaces.getPath());
assertNull(interfaces.getDescription());
assertNull(interfaces.getReference());
@Test
public void testParseList() {
- Module test = TestUtils.findModule(modules, "types2");
- URI expectedNamespace = URI.create("urn:simple.types.data.demo");
- String expectedPrefix = "t2";
- Date expectedRevision = TestUtils.createDate("2013-02-27");
+ Module test = TestUtils.findModule(modules, "types");
+ URI expectedNamespace = URI.create("urn:simple.types.test");
+ String expectedPrefix = "t";
ContainerSchemaNode interfaces = (ContainerSchemaNode) test.getDataChildByName("interfaces");
ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
// test SchemaNode args
- QName expectedQName = new QName(expectedNamespace, expectedRevision, expectedPrefix, "ifEntry");
+ QName expectedQName = new QName(expectedNamespace, typesRev, expectedPrefix, "ifEntry");
assertEquals(expectedQName, ifEntry.getQName());
- SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, expectedRevision, expectedPrefix,
- "interfaces", "ifEntry");
+ SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, typesRev, expectedPrefix, "interfaces",
+ "ifEntry");
assertEquals(expectedPath, ifEntry.getPath());
assertNull(ifEntry.getDescription());
assertNull(ifEntry.getReference());
assertEquals(2, availableAugmentations.size());
// test ListSchemaNode args
List<QName> expectedKey = new ArrayList<QName>();
- expectedKey.add(new QName(expectedNamespace, expectedRevision, expectedPrefix, "ifIndex"));
+ expectedKey.add(new QName(expectedNamespace, typesRev, expectedPrefix, "ifIndex"));
assertEquals(expectedKey, ifEntry.getKeyDefinition());
assertFalse(ifEntry.isUserOrdered());
// test DataNodeContainer args
assertTrue(ifMtu.getType() instanceof Int32);
}
- @Test
- public void testParseLeaf() throws ParseException {
- Module test = TestUtils.findModule(modules, "types2");
-
- // leaf if-name
- LeafSchemaNode ifName = (LeafSchemaNode) test.getDataChildByName("if-name");
- Leafref ifNameType = (Leafref) ifName.getType();
- QName qname = ifNameType.getQName();
-
- URI baseYangTypeNS = URI.create("urn:ietf:params:xml:ns:yang:1");
- assertEquals(baseYangTypeNS, qname.getNamespace());
- assertNull(qname.getRevision());
- assertEquals("", qname.getPrefix());
- assertEquals("leafref", qname.getLocalName());
-
- // leaf name
- LeafSchemaNode name = (LeafSchemaNode) test.getDataChildByName("name");
- StringType nameType = (StringType) name.getType();
- QName nameQName = nameType.getQName();
-
- assertEquals(baseYangTypeNS, nameQName.getNamespace());
- assertNull(nameQName.getRevision());
- assertEquals("", nameQName.getPrefix());
- assertEquals("string", nameQName.getLocalName());
-
- // leaf count
- LeafSchemaNode count = (LeafSchemaNode) test.getDataChildByName("count");
- ExtendedType countType = (ExtendedType) count.getType();
- QName countTypeQName = countType.getQName();
-
- URI expectedNS = URI.create("urn:simple.types.data.demo");
- Date expectedDate = simpleDateFormat.parse("2013-02-27");
- assertEquals(expectedNS, countTypeQName.getNamespace());
- assertEquals(expectedDate, countTypeQName.getRevision());
- assertEquals("t2", countTypeQName.getPrefix());
- assertEquals("int8", countTypeQName.getLocalName());
-
- Int8 countTypeBase = (Int8) countType.getBaseType();
- QName countTypeBaseQName = countTypeBase.getQName();
-
- assertEquals(baseYangTypeNS, countTypeBaseQName.getNamespace());
- assertNull(countTypeBaseQName.getRevision());
- assertEquals("", countTypeBaseQName.getPrefix());
- assertEquals("int8", countTypeBaseQName.getLocalName());
- }
-
- @Test
- public void testAugmentResolving() {
- // testfile1
- Module module1 = TestUtils.findModule(modules, "types1");
-
- Set<AugmentationSchema> module1Augmentations = module1.getAugmentations();
- AugmentationSchema augment1 = module1Augmentations.iterator().next();
- LeafSchemaNode augmentedLeafDefinition = (LeafSchemaNode) augment1.getDataChildByName("ds0ChannelNumber");
- assertTrue(augmentedLeafDefinition.isAugmenting());
-
- // testfile2
- Module module2 = TestUtils.findModule(modules, "types2");
-
- ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces");
- ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
- ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder");
-
- ContainerSchemaNode schemas = (ContainerSchemaNode) augmentedContainer.getDataChildByName("schemas");
- LeafSchemaNode linkleaf = (LeafSchemaNode) schemas.getDataChildByName("linkleaf");
- assertNotNull(linkleaf);
-
- // augmentation defined in testfile1 and augmentation returned from
- // augmented container have to be same
- Set<AugmentationSchema> augmentedContainerAugments = augmentedContainer.getAvailableAugmentations();
- AugmentationSchema augmentDefinition = augmentedContainerAugments.iterator().next();
- assertEquals(augment1, augmentDefinition);
-
- LeafSchemaNode augmentedLeaf = (LeafSchemaNode) augmentedContainer.getDataChildByName("ds0ChannelNumber");
- assertTrue(augmentedLeaf.isAugmenting());
- assertEquals(augmentedLeafDefinition, augmentedLeaf);
-
- Set<AugmentationSchema> ifEntryAugments = ifEntry.getAvailableAugmentations();
- assertEquals(2, ifEntryAugments.size());
-
- // testfile3
- Module module3 = TestUtils.findModule(modules, "types3");
-
- Set<AugmentationSchema> module3Augmentations = module3.getAugmentations();
- assertEquals(3, module3Augmentations.size());
- AugmentationSchema augment3 = null;
- for (AugmentationSchema as : module3Augmentations) {
- if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
- augment3 = as;
- }
- }
- ContainerSchemaNode augmentedContainerDefinition = (ContainerSchemaNode) augment3
- .getDataChildByName("augment-holder");
- assertTrue(augmentedContainerDefinition.isAugmenting());
-
- // check
- assertEquals(augmentedContainer, augmentedContainerDefinition);
- assertEquals(augmentedLeaf, augmentedLeafDefinition);
- }
-
- @Test
- public void testAugmentTarget() {
- Module test = TestUtils.findModule(modules, "types2");
-
- ContainerSchemaNode interfaces = (ContainerSchemaNode) test.getDataChildByName("interfaces");
- ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
- Set<AugmentationSchema> augmentations = ifEntry.getAvailableAugmentations();
- assertEquals(2, augmentations.size());
-
- AugmentationSchema augment = null;
- for (AugmentationSchema as : augmentations) {
- if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
- augment = as;
- }
- }
- ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment.getDataChildByName("augment-holder");
- assertNotNull(augmentHolder);
- assertTrue(augmentHolder.isAugmenting());
- QName augmentHolderQName = augmentHolder.getQName();
- assertEquals("augment-holder", augmentHolderQName.getLocalName());
- assertEquals("t3", augmentHolderQName.getPrefix());
- assertEquals("Description for augment holder", augmentHolder.getDescription());
- }
-
@Test
public void testTypedefRangesResolving() throws ParseException {
- Module testModule = TestUtils.findModule(modules, "types1");
+ Module testModule = TestUtils.findModule(modules, "nodes");
+ LeafSchemaNode int32Leaf = (LeafSchemaNode) testModule.getDataChildByName("int32-leaf");
- LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("testleaf");
- ExtendedType leafType = (ExtendedType) testleaf.getType();
+ ExtendedType leafType = (ExtendedType) int32Leaf.getType();
QName leafTypeQName = leafType.getQName();
- assertEquals("my-type1", leafTypeQName.getLocalName());
- assertEquals("t1", leafTypeQName.getPrefix());
- assertEquals(URI.create("urn:simple.container.demo"), leafTypeQName.getNamespace());
- Date expectedDate = simpleDateFormat.parse("2013-02-27");
- assertEquals(expectedDate, leafTypeQName.getRevision());
- assertEquals(1, leafType.getRanges().size());
-
- ExtendedType baseType = (ExtendedType) leafType.getBaseType();
- QName baseTypeQName = baseType.getQName();
- assertEquals("my-type1", baseTypeQName.getLocalName());
- assertEquals("t2", baseTypeQName.getPrefix());
- assertEquals(URI.create("urn:simple.types.data.demo"), baseTypeQName.getNamespace());
- assertEquals(expectedDate, baseTypeQName.getRevision());
- assertEquals(2, baseType.getRanges().size());
-
+ assertEquals("int32-ext2", leafTypeQName.getLocalName());
+ assertEquals("n", leafTypeQName.getPrefix());
+ assertEquals(nodesNS, leafTypeQName.getNamespace());
+ assertEquals(nodesRev, leafTypeQName.getRevision());
+ assertNull(leafType.getUnits());
+ assertNull(leafType.getDefaultValue());
+ assertTrue(leafType.getLengths().isEmpty());
+ assertTrue(leafType.getPatterns().isEmpty());
List<RangeConstraint> ranges = leafType.getRanges();
assertEquals(1, ranges.size());
RangeConstraint range = ranges.get(0);
assertEquals(12L, range.getMin());
assertEquals(20L, range.getMax());
+
+ ExtendedType baseType = (ExtendedType) leafType.getBaseType();
+ QName baseTypeQName = baseType.getQName();
+ assertEquals("int32-ext2", baseTypeQName.getLocalName());
+ assertEquals("t", baseTypeQName.getPrefix());
+ assertEquals(typesNS, baseTypeQName.getNamespace());
+ assertEquals(typesRev, baseTypeQName.getRevision());
+ assertEquals("mile", baseType.getUnits());
+ assertEquals("11", baseType.getDefaultValue());
+ assertTrue(leafType.getLengths().isEmpty());
+ assertTrue(leafType.getPatterns().isEmpty());
+ List<RangeConstraint> baseTypeRanges = baseType.getRanges();
+ assertEquals(2, baseTypeRanges.size());
+ RangeConstraint baseTypeRange1 = baseTypeRanges.get(0);
+ assertEquals(3L, baseTypeRange1.getMin());
+ assertEquals(9L, baseTypeRange1.getMax());
+ RangeConstraint baseTypeRange2 = baseTypeRanges.get(1);
+ assertEquals(11L, baseTypeRange2.getMin());
+ assertEquals(20L, baseTypeRange2.getMax());
+
+ ExtendedType base = (ExtendedType) baseType.getBaseType();
+ QName baseQName = base.getQName();
+ assertEquals("int32-ext1", baseQName.getLocalName());
+ assertEquals("t", baseQName.getPrefix());
+ assertEquals(typesNS, baseQName.getNamespace());
+ assertEquals(typesRev, baseQName.getRevision());
+ assertNull(base.getUnits());
+ assertNull(base.getDefaultValue());
+ assertTrue(leafType.getLengths().isEmpty());
+ assertTrue(leafType.getPatterns().isEmpty());
+ List<RangeConstraint> baseRanges = base.getRanges();
+ assertEquals(1, baseRanges.size());
+ RangeConstraint baseRange = baseRanges.get(0);
+ assertEquals(2L, baseRange.getMin());
+ assertEquals(20L, baseRange.getMax());
+
+ assertTrue(base.getBaseType() instanceof Int32);
}
@Test
public void testTypedefPatternsResolving() {
- Module testModule = TestUtils.findModule(modules, "types1");
-
- LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("test-string-leaf");
- ExtendedType testleafType = (ExtendedType) testleaf.getType();
- QName testleafTypeQName = testleafType.getQName();
- assertEquals("my-string-type-ext", testleafTypeQName.getLocalName());
- assertEquals("t2", testleafTypeQName.getPrefix());
-
- List<PatternConstraint> patterns = testleafType.getPatterns();
+ Module testModule = TestUtils.findModule(modules, "nodes");
+ LeafSchemaNode stringleaf = (LeafSchemaNode) testModule.getDataChildByName("string-leaf");
+
+ ExtendedType type = (ExtendedType) stringleaf.getType();
+ QName typeQName = type.getQName();
+ assertEquals("string-ext4", typeQName.getLocalName());
+ assertEquals("t", typeQName.getPrefix());
+ assertEquals(typesNS, typeQName.getNamespace());
+ assertEquals(typesRev, typeQName.getRevision());
+ assertNull(type.getUnits());
+ assertNull(type.getDefaultValue());
+ List<PatternConstraint> patterns = type.getPatterns();
assertEquals(1, patterns.size());
PatternConstraint pattern = patterns.iterator().next();
assertEquals("[e-z]*", pattern.getRegularExpression());
-
- ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
- assertEquals("my-string-type2", baseType.getQName().getLocalName());
-
- patterns = baseType.getPatterns();
+ assertTrue(type.getLengths().isEmpty());
+ assertTrue(type.getRanges().isEmpty());
+
+ ExtendedType baseType1 = (ExtendedType) type.getBaseType();
+ QName baseType1QName = baseType1.getQName();
+ assertEquals("string-ext3", baseType1QName.getLocalName());
+ assertEquals("t", baseType1QName.getPrefix());
+ assertEquals(typesNS, baseType1QName.getNamespace());
+ assertEquals(typesRev, baseType1QName.getRevision());
+ assertNull(baseType1.getUnits());
+ assertNull(baseType1.getDefaultValue());
+ patterns = baseType1.getPatterns();
assertEquals(1, patterns.size());
pattern = patterns.iterator().next();
assertEquals("[b-u]*", pattern.getRegularExpression());
-
- List<LengthConstraint> lengths = testleafType.getLengths();
- assertTrue(lengths.isEmpty());
+ assertTrue(baseType1.getLengths().isEmpty());
+ assertTrue(baseType1.getRanges().isEmpty());
+
+ ExtendedType baseType2 = (ExtendedType) baseType1.getBaseType();
+ QName baseType2QName = baseType2.getQName();
+ assertEquals("string-ext2", baseType2QName.getLocalName());
+ assertEquals("t", baseType2QName.getPrefix());
+ assertEquals(typesNS, baseType2QName.getNamespace());
+ assertEquals(typesRev, baseType2QName.getRevision());
+ assertNull(baseType2.getUnits());
+ assertNull(baseType2.getDefaultValue());
+ assertTrue(baseType2.getPatterns().isEmpty());
+ List<LengthConstraint> baseType2Lengths = baseType2.getLengths();
+ assertEquals(1, baseType2Lengths.size());
+ LengthConstraint length = baseType2Lengths.get(0);
+ assertEquals(6L, length.getMin());
+ assertEquals(10L, length.getMax());
+ assertTrue(baseType2.getRanges().isEmpty());
+
+ ExtendedType baseType3 = (ExtendedType) baseType2.getBaseType();
+ QName baseType3QName = baseType3.getQName();
+ assertEquals("string-ext1", baseType3QName.getLocalName());
+ assertEquals("t", baseType3QName.getPrefix());
+ assertEquals(typesNS, baseType3QName.getNamespace());
+ assertEquals(typesRev, baseType3QName.getRevision());
+ assertNull(baseType3.getUnits());
+ assertNull(baseType3.getDefaultValue());
+ patterns = baseType3.getPatterns();
+ assertEquals(1, patterns.size());
+ pattern = patterns.iterator().next();
+ assertEquals("[a-k]*", pattern.getRegularExpression());
+ List<LengthConstraint> baseType3Lengths = baseType3.getLengths();
+ assertEquals(1, baseType3Lengths.size());
+ length = baseType3Lengths.get(0);
+ assertEquals(5L, length.getMin());
+ assertEquals(11L, length.getMax());
+ assertTrue(baseType3.getRanges().isEmpty());
+
+ assertTrue(baseType3.getBaseType() instanceof StringType);
}
@Test
public void testTypedefLengthsResolving() {
- Module testModule = TestUtils.findModule(modules, "types1");
-
- LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("leaf-with-length");
- ExtendedType testleafType = (ExtendedType) testleaf.getType();
- assertEquals("my-string-type", testleafType.getQName().getLocalName());
-
- List<LengthConstraint> lengths = testleafType.getLengths();
- assertEquals(1, lengths.size());
-
- LengthConstraint length = lengths.get(0);
+ Module testModule = TestUtils.findModule(modules, "nodes");
+
+ LeafSchemaNode lengthLeaf = (LeafSchemaNode) testModule.getDataChildByName("length-leaf");
+ ExtendedType type = (ExtendedType) lengthLeaf.getType();
+
+ QName typeQName = type.getQName();
+ assertEquals("string-ext2", typeQName.getLocalName());
+ assertEquals("n", typeQName.getPrefix());
+ assertEquals(nodesNS, typeQName.getNamespace());
+ assertEquals(nodesRev, typeQName.getRevision());
+ assertNull(type.getUnits());
+ assertNull(type.getDefaultValue());
+ assertTrue(type.getPatterns().isEmpty());
+ List<LengthConstraint> typeLengths = type.getLengths();
+ assertEquals(1, typeLengths.size());
+ LengthConstraint length = typeLengths.get(0);
assertEquals(7L, length.getMin());
assertEquals(10L, length.getMax());
- }
-
- @Test
- public void testTypeDef() {
- Module testModule = TestUtils.findModule(modules, "types2");
-
- LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("nested-type-leaf");
- ExtendedType testleafType = (ExtendedType) testleaf.getType();
- assertEquals("my-type1", testleafType.getQName().getLocalName());
-
- ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
- assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
-
- Int32 int32Type = (Int32) baseType.getBaseType();
- QName qname = int32Type.getQName();
- assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), qname.getNamespace());
- assertNull(qname.getRevision());
- assertEquals("", qname.getPrefix());
- assertEquals("int32", qname.getLocalName());
- List<RangeConstraint> ranges = baseType.getRanges();
- assertEquals(1, ranges.size());
- RangeConstraint range = ranges.get(0);
- assertEquals(2L, range.getMin());
- assertEquals(20L, range.getMax());
+ assertTrue(type.getRanges().isEmpty());
+
+ ExtendedType baseType1 = (ExtendedType) type.getBaseType();
+ QName baseType1QName = baseType1.getQName();
+ assertEquals("string-ext2", baseType1QName.getLocalName());
+ assertEquals("t", baseType1QName.getPrefix());
+ assertEquals(typesNS, baseType1QName.getNamespace());
+ assertEquals(typesRev, baseType1QName.getRevision());
+ assertNull(baseType1.getUnits());
+ assertNull(baseType1.getDefaultValue());
+ assertTrue(baseType1.getPatterns().isEmpty());
+ List<LengthConstraint> baseType2Lengths = baseType1.getLengths();
+ assertEquals(1, baseType2Lengths.size());
+ length = baseType2Lengths.get(0);
+ assertEquals(6L, length.getMin());
+ assertEquals(10L, length.getMax());
+ assertTrue(baseType1.getRanges().isEmpty());
+
+ ExtendedType baseType2 = (ExtendedType) baseType1.getBaseType();
+ QName baseType2QName = baseType2.getQName();
+ assertEquals("string-ext1", baseType2QName.getLocalName());
+ assertEquals("t", baseType2QName.getPrefix());
+ assertEquals(typesNS, baseType2QName.getNamespace());
+ assertEquals(typesRev, baseType2QName.getRevision());
+ assertNull(baseType2.getUnits());
+ assertNull(baseType2.getDefaultValue());
+ List<PatternConstraint> patterns = baseType2.getPatterns();
+ assertEquals(1, patterns.size());
+ PatternConstraint pattern = patterns.iterator().next();
+ assertEquals("[a-k]*", pattern.getRegularExpression());
+ List<LengthConstraint> baseType3Lengths = baseType2.getLengths();
+ assertEquals(1, baseType3Lengths.size());
+ length = baseType3Lengths.get(0);
+ assertEquals(5L, length.getMin());
+ assertEquals(11L, length.getMax());
+ assertTrue(baseType2.getRanges().isEmpty());
+
+ assertTrue(baseType2.getBaseType() instanceof StringType);
}
@Test
public void testTypedefDecimal1() {
- Module testModule = TestUtils.findModule(modules, "types1");
+ Module testModule = TestUtils.findModule(modules, "nodes");
+ LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("decimal-leaf");
- LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("test-decimal-leaf");
ExtendedType type = (ExtendedType) testleaf.getType();
+ QName typeQName = type.getQName();
+ assertEquals("my-decimal-type", typeQName.getLocalName());
+ assertEquals("n", typeQName.getPrefix());
+ assertEquals(nodesNS, typeQName.getNamespace());
+ assertEquals(nodesRev, typeQName.getRevision());
+ assertNull(type.getUnits());
+ assertNull(type.getDefaultValue());
assertEquals(4, (int) type.getFractionDigits());
+ assertTrue(type.getLengths().isEmpty());
+ assertTrue(type.getPatterns().isEmpty());
+ assertTrue(type.getRanges().isEmpty());
ExtendedType typeBase = (ExtendedType) type.getBaseType();
- assertEquals("my-decimal-type", typeBase.getQName().getLocalName());
+ QName typeBaseQName = typeBase.getQName();
+ assertEquals("my-decimal-type", typeBaseQName.getLocalName());
+ assertEquals("t", typeBaseQName.getPrefix());
+ assertEquals(typesNS, typeBaseQName.getNamespace());
+ assertEquals(typesRev, typeBaseQName.getRevision());
+ assertNull(typeBase.getUnits());
+ assertNull(typeBase.getDefaultValue());
assertNull(typeBase.getFractionDigits());
+ assertTrue(typeBase.getLengths().isEmpty());
+ assertTrue(typeBase.getPatterns().isEmpty());
+ assertTrue(typeBase.getRanges().isEmpty());
Decimal64 decimal = (Decimal64) typeBase.getBaseType();
assertEquals(6, (int) decimal.getFractionDigits());
@Test
public void testTypedefDecimal2() {
- Module testModule = TestUtils.findModule(modules, "types1");
+ Module testModule = TestUtils.findModule(modules, "nodes");
+ LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("decimal-leaf2");
- LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("test-decimal-leaf2");
- TypeDefinition<?> baseType = testleaf.getType().getBaseType();
- assertTrue(testleaf.getType().getBaseType() instanceof Decimal64);
- Decimal64 baseTypeCast = (Decimal64) baseType;
- assertEquals(5, (int) baseTypeCast.getFractionDigits());
+ ExtendedType type = (ExtendedType) testleaf.getType();
+ QName typeQName = type.getQName();
+ assertEquals("my-decimal-type", typeQName.getLocalName());
+ assertEquals("t", typeQName.getPrefix());
+ assertEquals(typesNS, typeQName.getNamespace());
+ assertEquals(typesRev, typeQName.getRevision());
+ assertNull(type.getUnits());
+ assertNull(type.getDefaultValue());
+ assertNull(type.getFractionDigits());
+ assertTrue(type.getLengths().isEmpty());
+ assertTrue(type.getPatterns().isEmpty());
+ assertTrue(type.getRanges().isEmpty());
+
+ Decimal64 baseTypeDecimal = (Decimal64) type.getBaseType();
+ assertEquals(6, (int) baseTypeDecimal.getFractionDigits());
}
@Test
public void testTypedefUnion() {
- Module testModule = TestUtils.findModule(modules, "types1");
-
- LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("union-leaf");
- ExtendedType testleafType = (ExtendedType) testleaf.getType();
- assertEquals("my-union-ext", testleafType.getQName().getLocalName());
-
- ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
- assertEquals("my-union", baseType.getQName().getLocalName());
-
- UnionType unionBase = (UnionType) baseType.getBaseType();
+ Module testModule = TestUtils.findModule(modules, "nodes");
+ LeafSchemaNode unionleaf = (LeafSchemaNode) testModule.getDataChildByName("union-leaf");
+
+ ExtendedType type = (ExtendedType) unionleaf.getType();
+ QName typeQName = type.getQName();
+ assertEquals("my-union-ext", typeQName.getLocalName());
+ assertEquals("t", typeQName.getPrefix());
+ assertEquals(typesNS, typeQName.getNamespace());
+ assertEquals(typesRev, typeQName.getRevision());
+ assertNull(type.getUnits());
+ assertNull(type.getDefaultValue());
+ assertNull(type.getFractionDigits());
+ assertTrue(type.getLengths().isEmpty());
+ assertTrue(type.getPatterns().isEmpty());
+ assertTrue(type.getRanges().isEmpty());
+
+ ExtendedType baseType = (ExtendedType) type.getBaseType();
+ QName baseTypeQName = baseType.getQName();
+ assertEquals("my-union", baseTypeQName.getLocalName());
+ assertEquals("t", baseTypeQName.getPrefix());
+ assertEquals(typesNS, baseTypeQName.getNamespace());
+ assertEquals(typesRev, baseTypeQName.getRevision());
+ assertNull(baseType.getUnits());
+ assertNull(baseType.getDefaultValue());
+ assertNull(baseType.getFractionDigits());
+ assertTrue(baseType.getLengths().isEmpty());
+ assertTrue(baseType.getPatterns().isEmpty());
+ assertTrue(baseType.getRanges().isEmpty());
+
+ UnionType unionType = (UnionType) baseType.getBaseType();
+ List<TypeDefinition<?>> unionTypes = unionType.getTypes();
+ assertEquals(2, unionTypes.size());
- List<TypeDefinition<?>> unionTypes = unionBase.getTypes();
ExtendedType unionType1 = (ExtendedType) unionTypes.get(0);
+ QName unionType1QName = baseType.getQName();
+ assertEquals("my-union", unionType1QName.getLocalName());
+ assertEquals("t", unionType1QName.getPrefix());
+ assertEquals(typesNS, unionType1QName.getNamespace());
+ assertEquals(typesRev, unionType1QName.getRevision());
+ assertNull(unionType1.getUnits());
+ assertNull(unionType1.getDefaultValue());
+ assertNull(unionType1.getFractionDigits());
+ assertTrue(unionType1.getLengths().isEmpty());
+ assertTrue(unionType1.getPatterns().isEmpty());
List<RangeConstraint> ranges = unionType1.getRanges();
assertEquals(1, ranges.size());
RangeConstraint range = ranges.get(0);
assertEquals(1L, range.getMin());
assertEquals(100L, range.getMax());
-
assertTrue(unionType1.getBaseType() instanceof Int16);
- assertTrue(unionTypes.get(1) instanceof Int32);
- }
-
- @Test
- public void testNestedUnionResolving1() {
- Module testModule = TestUtils.findModule(modules, "types1");
-
- LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("nested-union-leaf");
-
- ExtendedType nestedUnion1 = (ExtendedType) testleaf.getType();
- assertEquals("nested-union1", nestedUnion1.getQName().getLocalName());
-
- ExtendedType nestedUnion2 = (ExtendedType) nestedUnion1.getBaseType();
- assertEquals("nested-union2", nestedUnion2.getQName().getLocalName());
-
- UnionType unionType1 = (UnionType) nestedUnion2.getBaseType();
- List<TypeDefinition<?>> unionTypes = unionType1.getTypes();
- assertEquals(2, unionTypes.size());
- assertTrue(unionTypes.get(0) instanceof StringType);
- assertTrue(unionTypes.get(1) instanceof ExtendedType);
-
- ExtendedType extendedUnion = (ExtendedType) unionTypes.get(1);
- ExtendedType extendedUnionBase = (ExtendedType) extendedUnion.getBaseType();
- assertEquals("my-union", extendedUnionBase.getQName().getLocalName());
- UnionType extendedTargetUnion = (UnionType) extendedUnionBase.getBaseType();
- List<TypeDefinition<?>> extendedTargetTypes = extendedTargetUnion.getTypes();
- assertTrue(extendedTargetTypes.get(0).getBaseType() instanceof Int16);
- assertTrue(extendedTargetTypes.get(1) instanceof Int32);
-
- ExtendedType int16 = (ExtendedType) extendedTargetTypes.get(0);
- assertTrue(int16.getBaseType() instanceof Int16);
- List<RangeConstraint> ranges = int16.getRanges();
- assertEquals(1, ranges.size());
- RangeConstraint range = ranges.get(0);
- assertEquals(1L, range.getMin());
- assertEquals(100L, range.getMax());
+ assertTrue(unionTypes.get(1) instanceof Int32);
}
@Test
- public void testNestedUnionResolving2() {
- Module testModule = TestUtils.findModule(modules, "types1");
-
+ public void testNestedUnionResolving() {
+ Module testModule = TestUtils.findModule(modules, "nodes");
LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("custom-union-leaf");
- ExtendedType testleafType = (ExtendedType) testleaf.getType();
- QName testleafTypeQName = testleafType.getQName();
- assertEquals(URI.create("urn:simple.container.demo.test"), testleafTypeQName.getNamespace());
- assertEquals(TestUtils.createDate("2013-02-27"), testleafTypeQName.getRevision());
- assertEquals("t3", testleafTypeQName.getPrefix());
+ ExtendedType type = (ExtendedType) testleaf.getType();
+ QName testleafTypeQName = type.getQName();
+ assertEquals(customNS, testleafTypeQName.getNamespace());
+ assertEquals(customRev, testleafTypeQName.getRevision());
+ assertEquals("c", testleafTypeQName.getPrefix());
assertEquals("union1", testleafTypeQName.getLocalName());
+ assertNull(type.getUnits());
+ assertNull(type.getDefaultValue());
+ assertNull(type.getFractionDigits());
+ assertTrue(type.getLengths().isEmpty());
+ assertTrue(type.getPatterns().isEmpty());
+ assertTrue(type.getRanges().isEmpty());
- ExtendedType union2 = (ExtendedType) testleafType.getBaseType();
- QName union2QName = union2.getQName();
- assertEquals(URI.create("urn:simple.container.demo.test"), union2QName.getNamespace());
- assertEquals(TestUtils.createDate("2013-02-27"), union2QName.getRevision());
- assertEquals("t3", union2QName.getPrefix());
- assertEquals("union2", union2QName.getLocalName());
+ ExtendedType typeBase = (ExtendedType) type.getBaseType();
+ QName typeBaseQName = typeBase.getQName();
+ assertEquals(customNS, typeBaseQName.getNamespace());
+ assertEquals(customRev, typeBaseQName.getRevision());
+ assertEquals("c", typeBaseQName.getPrefix());
+ assertEquals("union2", typeBaseQName.getLocalName());
+ assertNull(typeBase.getUnits());
+ assertNull(typeBase.getDefaultValue());
+ assertNull(typeBase.getFractionDigits());
+ assertTrue(typeBase.getLengths().isEmpty());
+ assertTrue(typeBase.getPatterns().isEmpty());
+ assertTrue(typeBase.getRanges().isEmpty());
- UnionType union2Base = (UnionType) union2.getBaseType();
- List<TypeDefinition<?>> unionTypes = union2Base.getTypes();
+ UnionType union = (UnionType) typeBase.getBaseType();
+ List<TypeDefinition<?>> unionTypes = union.getTypes();
assertEquals(2, unionTypes.size());
assertTrue(unionTypes.get(0) instanceof Int32);
assertTrue(unionTypes.get(1) instanceof ExtendedType);
- ExtendedType nestedUnion2 = (ExtendedType) unionTypes.get(1);
- QName nestedUnion2QName = nestedUnion2.getQName();
- assertEquals(URI.create("urn:simple.types.data.demo"), nestedUnion2QName.getNamespace());
- assertEquals(TestUtils.createDate("2013-02-27"), nestedUnion2QName.getRevision());
- assertEquals("t2", nestedUnion2QName.getPrefix());
- assertEquals("nested-union2", nestedUnion2QName.getLocalName());
-
- UnionType nestedUnion2Base = (UnionType) nestedUnion2.getBaseType();
- List<TypeDefinition<?>> nestedUnion2Types = nestedUnion2Base.getTypes();
+ ExtendedType unionType1 = (ExtendedType) unionTypes.get(1);
+ QName uniontType1QName = unionType1.getQName();
+ assertEquals(typesNS, uniontType1QName.getNamespace());
+ assertEquals(typesRev, uniontType1QName.getRevision());
+ assertEquals("t", uniontType1QName.getPrefix());
+ assertEquals("nested-union2", uniontType1QName.getLocalName());
+ assertNull(unionType1.getUnits());
+ assertNull(unionType1.getDefaultValue());
+ assertNull(unionType1.getFractionDigits());
+ assertTrue(unionType1.getLengths().isEmpty());
+ assertTrue(unionType1.getPatterns().isEmpty());
+ assertTrue(unionType1.getRanges().isEmpty());
+
+ UnionType nestedUnion = (UnionType) unionType1.getBaseType();
+ List<TypeDefinition<?>> nestedUnion2Types = nestedUnion.getTypes();
assertEquals(2, nestedUnion2Types.size());
assertTrue(nestedUnion2Types.get(0) instanceof StringType);
assertTrue(nestedUnion2Types.get(1) instanceof ExtendedType);
ExtendedType myUnionExt = (ExtendedType) nestedUnion2Types.get(1);
QName myUnionExtQName = myUnionExt.getQName();
- assertEquals(URI.create("urn:simple.types.data.demo"), myUnionExtQName.getNamespace());
- assertEquals(TestUtils.createDate("2013-02-27"), myUnionExtQName.getRevision());
- assertEquals("t2", myUnionExtQName.getPrefix());
+ assertEquals(typesNS, myUnionExtQName.getNamespace());
+ assertEquals(typesRev, myUnionExtQName.getRevision());
+ assertEquals("t", myUnionExtQName.getPrefix());
assertEquals("my-union-ext", myUnionExtQName.getLocalName());
+ assertNull(myUnionExt.getUnits());
+ assertNull(myUnionExt.getDefaultValue());
+ assertNull(myUnionExt.getFractionDigits());
+ assertTrue(myUnionExt.getLengths().isEmpty());
+ assertTrue(myUnionExt.getPatterns().isEmpty());
+ assertTrue(myUnionExt.getRanges().isEmpty());
ExtendedType myUnion = (ExtendedType) myUnionExt.getBaseType();
QName myUnionQName = myUnion.getQName();
- assertEquals(URI.create("urn:simple.types.data.demo"), myUnionQName.getNamespace());
- assertEquals(TestUtils.createDate("2013-02-27"), myUnionQName.getRevision());
- assertEquals("t2", myUnionQName.getPrefix());
+ assertEquals(typesNS, myUnionQName.getNamespace());
+ assertEquals(typesRev, myUnionQName.getRevision());
+ assertEquals("t", myUnionQName.getPrefix());
assertEquals("my-union", myUnionQName.getLocalName());
+ assertNull(myUnion.getUnits());
+ assertNull(myUnion.getDefaultValue());
+ assertNull(myUnion.getFractionDigits());
+ assertTrue(myUnion.getLengths().isEmpty());
+ assertTrue(myUnion.getPatterns().isEmpty());
+ assertTrue(myUnion.getRanges().isEmpty());
UnionType myUnionBase = (UnionType) myUnion.getBaseType();
List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
assertEquals(2, myUnionBaseTypes.size());
- assertTrue(myUnionBaseTypes.get(0).getBaseType() instanceof Int16);
+ assertTrue(myUnionBaseTypes.get(0) instanceof ExtendedType);
assertTrue(myUnionBaseTypes.get(1) instanceof Int32);
- ExtendedType int16 = (ExtendedType) myUnionBaseTypes.get(0);
- List<RangeConstraint> ranges = int16.getRanges();
+
+ ExtendedType int16Ext = (ExtendedType) myUnionBaseTypes.get(0);
+ QName int16ExtQName = int16Ext.getQName();
+ assertEquals(typesNS, int16ExtQName.getNamespace());
+ assertEquals(typesRev, int16ExtQName.getRevision());
+ assertEquals("t", int16ExtQName.getPrefix());
+ assertEquals("int16", int16ExtQName.getLocalName());
+ assertNull(int16Ext.getUnits());
+ assertNull(int16Ext.getDefaultValue());
+ assertNull(int16Ext.getFractionDigits());
+ assertTrue(int16Ext.getLengths().isEmpty());
+ assertTrue(int16Ext.getPatterns().isEmpty());
+ List<RangeConstraint> ranges = int16Ext.getRanges();
assertEquals(1, ranges.size());
RangeConstraint range = ranges.get(0);
assertEquals(1L, range.getMin());
assertEquals(100L, range.getMax());
+
+ assertTrue(int16Ext.getBaseType() instanceof Int16);
}
@Test
public void testChoice() {
- Module testModule = TestUtils.findModule(modules, "types1");
- ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
- ChoiceNode how = (ChoiceNode) peer.getDataChildByName("how");
+ Module testModule = TestUtils.findModule(modules, "nodes");
+ ContainerSchemaNode transfer = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
+ ChoiceNode how = (ChoiceNode) transfer.getDataChildByName("how");
Set<ChoiceCaseNode> cases = how.getCases();
assertEquals(5, cases.size());
ChoiceCaseNode input = null;
@Test
public void testAnyXml() {
- Module testModule = TestUtils.findModule(modules, "types1");
+ Module testModule = TestUtils.findModule(modules, "nodes");
AnyXmlSchemaNode data = (AnyXmlSchemaNode) testModule.getDataChildByName("data");
- assertNotNull(data);
+ assertNotNull("anyxml data not found", data);
+
+ // test SchemaNode args
+ QName qname = data.getQName();
+ assertEquals("data", qname.getLocalName());
+ assertEquals("n", qname.getPrefix());
+ assertEquals(nodesNS, qname.getNamespace());
+ assertEquals(nodesRev, qname.getRevision());
+ assertTrue(data.getDescription().contains("Copy of the source typesstore subset that matched"));
+ assertNull(data.getReference());
+ assertEquals(Status.OBSOLETE, data.getStatus());
+ assertEquals(0, data.getUnknownSchemaNodes().size());
+ // test DataSchemaNode args
+ assertFalse(data.isAugmenting());
+ assertTrue(data.isConfiguration());
+ ConstraintDefinition constraints = data.getConstraints();
+ assertNull(constraints.getWhenCondition());
+ assertEquals(0, constraints.getMustConstraints().size());
+ assertFalse(constraints.isMandatory());
+ assertNull(constraints.getMinElements());
+ assertNull(constraints.getMaxElements());
}
@Test
public void testDeviation() {
- Module testModule = TestUtils.findModule(modules, "types1");
+ Module testModule = TestUtils.findModule(modules, "nodes");
Set<Deviation> deviations = testModule.getDeviations();
assertEquals(1, deviations.size());
-
Deviation dev = deviations.iterator().next();
- SchemaPath expectedPath = TestUtils.createPath(true, null, null, "data", "system", "user");
+
+ assertEquals("system/user ref", dev.getReference());
+
+ List<QName> path = new ArrayList<QName>();
+ path.add(new QName(typesNS, typesRev, "t", "interfaces"));
+ path.add(new QName(typesNS, typesRev, "t", "ifEntry"));
+ SchemaPath expectedPath = new SchemaPath(path, true);
+
assertEquals(expectedPath, dev.getTargetPath());
assertEquals(Deviate.ADD, dev.getDeviate());
}
@Test
public void testUnknownNode() {
- Module testModule = TestUtils.findModule(modules, "types3");
+ Module testModule = TestUtils.findModule(modules, "custom");
ContainerSchemaNode network = (ContainerSchemaNode) testModule.getDataChildByName("network");
List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
assertEquals(1, unknownNodes.size());
@Test
public void testFeature() {
- Module testModule = TestUtils.findModule(modules, "types3");
+ Module testModule = TestUtils.findModule(modules, "custom");
Set<FeatureDefinition> features = testModule.getFeatures();
assertEquals(1, features.size());
}
@Test
public void testExtension() {
- Module testModule = TestUtils.findModule(modules, "types3");
+ Module testModule = TestUtils.findModule(modules, "custom");
List<ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
assertEquals(1, extensions.size());
ExtensionDefinition extension = extensions.get(0);
assertEquals("name", extension.getArgument());
- assertFalse(extension.isYinElement());
+ assertTrue(extension.isYinElement());
}
@Test
public void testNotification() {
- Module testModule = TestUtils.findModule(modules, "types3");
- URI expectedNamespace = URI.create("urn:simple.container.demo.test");
- String expectedPrefix = "t3";
- Date expectedRevision = TestUtils.createDate("2013-02-27");
+ Module testModule = TestUtils.findModule(modules, "custom");
+ String expectedPrefix = "c";
Set<NotificationDefinition> notifications = testModule.getNotifications();
assertEquals(1, notifications.size());
NotificationDefinition notification = notifications.iterator().next();
// test SchemaNode args
- QName expectedQName = new QName(expectedNamespace, expectedRevision, expectedPrefix, "event");
+ QName expectedQName = new QName(customNS, customRev, expectedPrefix, "event");
assertEquals(expectedQName, notification.getQName());
- SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, expectedRevision, expectedPrefix,
- "event");
+ SchemaPath expectedPath = TestUtils.createPath(true, customNS, customRev, expectedPrefix, "event");
assertEquals(expectedPath, notification.getPath());
assertNull(notification.getDescription());
assertNull(notification.getReference());
@Test
public void testRpc() {
- Module testModule = TestUtils.findModule(modules, "types3");
+ Module testModule = TestUtils.findModule(modules, "custom");
Set<RpcDefinition> rpcs = testModule.getRpcs();
assertEquals(1, rpcs.size());
assertNotNull(output.getDataChildByName("data"));
}
- @Test
- public void testAugmentNodesTypesSchemaPath() throws Exception {
- Module testModule = TestUtils.findModule(modules, "types1");
- Set<AugmentationSchema> augments = testModule.getAugmentations();
- assertEquals(1, augments.size());
- AugmentationSchema augment = augments.iterator().next();
-
- LeafSchemaNode ifcId = (LeafSchemaNode) augment.getDataChildByName("interface-id");
- Leafref ifcIdType = (Leafref) ifcId.getType();
- SchemaPath ifcIdTypeSchemaPath = ifcIdType.getPath();
- List<QName> ifcIdTypePath = ifcIdTypeSchemaPath.getPath();
-
- URI types1URI = URI.create("urn:simple.container.demo");
- URI types2URI = URI.create("urn:simple.types.data.demo");
- URI types3URI = URI.create("urn:simple.container.demo.test");
- Date expectedDate = simpleDateFormat.parse("2013-02-27");
-
- QName q0 = new QName(types2URI, expectedDate, "data", "interfaces");
- QName q1 = new QName(types2URI, expectedDate, "data", "ifEntry");
- QName q2 = new QName(types3URI, expectedDate, "data", "augment-holder");
- QName q3 = new QName(types1URI, expectedDate, "data", "interface-id");
- assertEquals(q0, ifcIdTypePath.get(0));
- assertEquals(q1, ifcIdTypePath.get(1));
- assertEquals(q2, ifcIdTypePath.get(2));
- assertEquals(q3, ifcIdTypePath.get(3));
-
- LeafListSchemaNode higherLayer = (LeafListSchemaNode) augment.getDataChildByName("higher-layer-if");
- Leafref higherLayerType = (Leafref) higherLayer.getType();
- SchemaPath higherLayerTypeSchemaPath = higherLayerType.getPath();
- List<QName> higherLayerTypePath = higherLayerTypeSchemaPath.getPath();
- assertEquals(q0, higherLayerTypePath.get(0));
- assertEquals(q1, higherLayerTypePath.get(1));
- assertEquals(q2, higherLayerTypePath.get(2));
- q3 = new QName(types1URI, expectedDate, "data", "higher-layer-if");
- assertEquals(q3, higherLayerTypePath.get(3));
-
- LeafSchemaNode myType = (LeafSchemaNode) augment.getDataChildByName("my-type");
- ExtendedType leafType = (ExtendedType) myType.getType();
-
- testModule = TestUtils.findModule(modules, "types2");
- TypeDefinition<?> typedef = TestUtils.findTypedef(testModule.getTypeDefinitions(), "my-type1");
-
- assertEquals(typedef, leafType);
- }
-
@Test
public void testTypePath() throws ParseException {
- Module test = TestUtils.findModule(modules, "types2");
+ Module test = TestUtils.findModule(modules, "types");
Set<TypeDefinition<?>> types = test.getTypeDefinitions();
// my-base-int32-type
- ExtendedType int32Typedef = (ExtendedType) TestUtils.findTypedef(types, "my-base-int32-type");
+ ExtendedType int32Typedef = (ExtendedType) TestUtils.findTypedef(types, "int32-ext1");
QName int32TypedefQName = int32Typedef.getQName();
- URI expectedNS = URI.create("urn:simple.types.data.demo");
- Date expectedDate = simpleDateFormat.parse("2013-02-27");
- assertEquals(expectedNS, int32TypedefQName.getNamespace());
- assertEquals(expectedDate, int32TypedefQName.getRevision());
- assertEquals("t2", int32TypedefQName.getPrefix());
- assertEquals("my-base-int32-type", int32TypedefQName.getLocalName());
+ assertEquals(typesNS, int32TypedefQName.getNamespace());
+ assertEquals(typesRev, int32TypedefQName.getRevision());
+ assertEquals("t", int32TypedefQName.getPrefix());
+ assertEquals("int32-ext1", int32TypedefQName.getLocalName());
SchemaPath typeSchemaPath = int32Typedef.getPath();
List<QName> typePath = typeSchemaPath.getPath();
@Test
public void testTypePath2() throws ParseException {
- Module test = TestUtils.findModule(modules, "types2");
+ Module test = TestUtils.findModule(modules, "types");
Set<TypeDefinition<?>> types = test.getTypeDefinitions();
// my-base-int32-type
ExtendedType myDecType = (ExtendedType) TestUtils.findTypedef(types, "my-decimal-type");
QName myDecTypeQName = myDecType.getQName();
- URI expectedNS = URI.create("urn:simple.types.data.demo");
- Date expectedDate = simpleDateFormat.parse("2013-02-27");
- assertEquals(expectedNS, myDecTypeQName.getNamespace());
- assertEquals(expectedDate, myDecTypeQName.getRevision());
- assertEquals("t2", myDecTypeQName.getPrefix());
+ assertEquals(typesNS, myDecTypeQName.getNamespace());
+ assertEquals(typesRev, myDecTypeQName.getRevision());
+ assertEquals("t", myDecTypeQName.getPrefix());
assertEquals("my-decimal-type", myDecTypeQName.getLocalName());
SchemaPath typeSchemaPath = myDecType.getPath();