- @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());
- }
-