use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition in project netconf by opendaylight.
the class RestconfImpl method toModuleEntryNode.
private static MapEntryNode toModuleEntryNode(final Module module, final DataSchemaNode moduleSchemaNode) {
checkArgument(moduleSchemaNode instanceof ListSchemaNode, "moduleSchemaNode has to be of type ListSchemaNode");
final ListSchemaNode listModuleSchemaNode = (ListSchemaNode) moduleSchemaNode;
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> moduleNodeValues = SchemaAwareBuilders.mapEntryBuilder(listModuleSchemaNode);
List<DataSchemaNode> instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listModuleSchemaNode, "name");
final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
checkState(nameSchemaNode instanceof LeafSchemaNode);
moduleNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) nameSchemaNode).withValue(module.getName()).build());
final QNameModule qNameModule = module.getQNameModule();
instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listModuleSchemaNode, "revision");
final DataSchemaNode revisionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
checkState(revisionSchemaNode instanceof LeafSchemaNode);
final Optional<Revision> revision = qNameModule.getRevision();
moduleNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) revisionSchemaNode).withValue(revision.map(Revision::toString).orElse("")).build());
instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listModuleSchemaNode, "namespace");
final DataSchemaNode namespaceSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
checkState(namespaceSchemaNode instanceof LeafSchemaNode);
moduleNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) namespaceSchemaNode).withValue(qNameModule.getNamespace().toString()).build());
instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listModuleSchemaNode, "feature");
final DataSchemaNode featureSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
checkState(featureSchemaNode instanceof LeafListSchemaNode);
final ListNodeBuilder<Object, SystemLeafSetNode<Object>> featuresBuilder = SchemaAwareBuilders.leafSetBuilder((LeafListSchemaNode) featureSchemaNode);
for (final FeatureDefinition feature : module.getFeatures()) {
featuresBuilder.withChild(SchemaAwareBuilders.leafSetEntryBuilder((LeafListSchemaNode) featureSchemaNode).withValue(feature.getQName().getLocalName()).build());
}
moduleNodeValues.withChild(featuresBuilder.build());
return moduleNodeValues.build();
}
use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition in project yangtools by opendaylight.
the class YinFileFeatureStmtTest method testFeature.
@Test
public void testFeature() {
Module testModule = context.findModules("yang-with-features").iterator().next();
assertNotNull(testModule);
Collection<? extends FeatureDefinition> features = testModule.getFeatures();
assertEquals(2, features.size());
Iterator<? extends FeatureDefinition> featuresIterator = features.iterator();
FeatureDefinition feature = featuresIterator.next();
assertThat(feature.getQName().getLocalName(), anyOf(is("arbitrary-names"), is("pre-provisioning")));
feature = featuresIterator.next();
assertThat(feature.getQName().getLocalName(), anyOf(is("arbitrary-names"), is("pre-provisioning")));
}
use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition in project yangtools by opendaylight.
the class EffectiveModuleTest method effectiveBuildTest.
@Test
public void effectiveBuildTest() throws Exception {
final Module rootModule = TestUtils.parseYangSource("/semantic-statement-parser/effective-module/root.yang", "/semantic-statement-parser/effective-module/imported.yang", "/semantic-statement-parser/effective-module/submod.yang").findModules("root").iterator().next();
assertNotNull(rootModule);
assertEquals("root-pref", rootModule.getPrefix());
assertEquals(YangVersion.VERSION_1, rootModule.getYangVersion());
assertEquals(Optional.of("cisco"), rootModule.getOrganization());
assertEquals(Optional.of("cisco email"), rootModule.getContact());
final ContainerSchemaNode contSchemaNode = (ContainerSchemaNode) rootModule.getDataChildByName(CONT);
assertNotNull(contSchemaNode);
final Collection<? extends AugmentationSchemaNode> augmentations = rootModule.getAugmentations();
assertEquals(1, augmentations.size());
assertEquals(Absolute.of(CONT), augmentations.iterator().next().getTargetPath());
final Collection<? extends ModuleImport> imports = rootModule.getImports();
assertEquals(1, imports.size());
final ModuleImport importStmt = imports.iterator().next();
assertNotNull(importStmt);
assertEquals("imported", importStmt.getModuleName());
assertEquals(Optional.of(REVISION), importStmt.getRevision());
assertEquals("imp-pref", importStmt.getPrefix());
final Collection<? extends Submodule> submodules = rootModule.getSubmodules();
assertEquals(1, submodules.size());
assertEquals("submod", submodules.iterator().next().getName());
final Collection<? extends NotificationDefinition> notifications = rootModule.getNotifications();
assertEquals(1, notifications.size());
assertEquals("notif1", notifications.iterator().next().getQName().getLocalName());
final Collection<? extends RpcDefinition> rpcs = rootModule.getRpcs();
assertEquals(1, rpcs.size());
assertEquals("rpc1", rpcs.iterator().next().getQName().getLocalName());
final Collection<? extends Deviation> deviations = rootModule.getDeviations();
assertEquals(1, deviations.size());
final Deviation deviationStmt = deviations.iterator().next();
assertNotNull(deviationStmt);
final QNameModule importedModuleQName = QNameModule.create(XMLNamespace.of("imported"), REVISION);
final QName importedContQName = QName.create(importedModuleQName, "cont");
assertEquals(Absolute.of(importedContQName), deviationStmt.getTargetPath());
assertEquals(DeviateKind.ADD, deviationStmt.getDeviates().iterator().next().getDeviateType());
assertEquals(Optional.of("deviate reference"), deviationStmt.getReference());
final Collection<? extends IdentitySchemaNode> identities = rootModule.getIdentities();
assertEquals(1, identities.size());
assertEquals("identity1", identities.iterator().next().getQName().getLocalName());
final Collection<? extends FeatureDefinition> features = rootModule.getFeatures();
assertEquals(1, features.size());
final FeatureDefinition featureStmt = features.iterator().next();
assertNotNull(featureStmt);
assertEquals(FEATURE1, featureStmt.getQName());
assertEquals(Optional.of("feature1 description"), featureStmt.getDescription());
assertEquals(Optional.of("feature1 reference"), featureStmt.getReference());
assertEquals(Status.CURRENT, featureStmt.getStatus());
final Collection<? extends ExtensionDefinition> extensionSchemaNodes = rootModule.getExtensionSchemaNodes();
assertEquals(1, extensionSchemaNodes.size());
assertEquals("ext1", extensionSchemaNodes.iterator().next().getQName().getLocalName());
}
use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition in project yangtools by opendaylight.
the class IncludedStmtsTest method includedFeaturesTest.
@Test
public void includedFeaturesTest() {
final Module testModule = result.findModules("root-module").iterator().next();
assertNotNull(testModule);
final Collection<? extends FeatureDefinition> features = testModule.getFeatures();
assertEquals(2, features.size());
final Iterator<? extends FeatureDefinition> featuresIterator = features.iterator();
FeatureDefinition feature = featuresIterator.next();
assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
feature = featuresIterator.next();
assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
}
use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition in project netconf by opendaylight.
the class SchemaContextHandler method addFeatureLeafList.
/**
* Mapping features of specific module.
*
* @param mapEntryBuilder mapEntryBuilder of parent for mapping children
* @param features features of specific module
*/
private static void addFeatureLeafList(final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder, final Collection<? extends FeatureDefinition> features) {
final ListNodeBuilder<String, SystemLeafSetNode<String>> leafSetBuilder = Builders.<String>leafSetBuilder().withNodeIdentifier(MODULE_FEATURE_NODEID);
for (final FeatureDefinition feature : features) {
leafSetBuilder.withChildValue(feature.getQName().getLocalName());
}
mapEntryBuilder.withChild(leafSetBuilder.build());
}
Aggregations