use of org.opendaylight.yangtools.yang.model.api.Submodule in project yangtools by opendaylight.
the class EffectiveModulesAndSubmodulesTest method modulesAndSubmodulesSimpleReferencesTest.
@Test
public void modulesAndSubmodulesSimpleReferencesTest() throws ReactorException {
final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSources(ROOT_MODULE, IMPORTED_MODULE, SUBMODULE_1, SUBMODULE_2, SUBMODULE_TO_SUBMODULE_1).buildEffective();
assertNotNull(result);
final Collection<? extends Module> modules = result.getModules();
assertNotNull(modules);
assertEquals(2, modules.size());
Module root = null;
Module imported = null;
for (final Module module : modules) {
switch(module.getName()) {
case "root-module":
root = module;
break;
case "imported-module":
imported = module;
break;
default:
}
printReferences(module, false, "");
printChilds(module.getChildNodes(), " ");
}
assertNotNull(root);
assertNotNull(imported);
final Collection<? extends DataSchemaNode> rootChildNodes = root.getChildNodes();
final Collection<? extends DataSchemaNode> importedChildNodes = imported.getChildNodes();
assertNotNull(rootChildNodes);
assertNotNull(importedChildNodes);
assertEquals(3, rootChildNodes.size());
assertEquals(1, importedChildNodes.size());
final Collection<? extends Submodule> rootSubmodules = root.getSubmodules();
final Collection<? extends Submodule> importedSubmodules = imported.getSubmodules();
assertNotNull(rootSubmodules);
assertNotNull(importedSubmodules);
assertEquals(2, rootSubmodules.size());
assertEquals(0, importedSubmodules.size());
Submodule sub1 = null;
Submodule sub2 = null;
for (final Submodule rootSubmodule : rootSubmodules) {
switch(rootSubmodule.getName()) {
case "submodule-1":
sub1 = rootSubmodule;
break;
case "submodule-2":
sub2 = rootSubmodule;
break;
default:
}
}
assertNotNull(sub1);
assertNotNull(sub2);
assertEquals(ROOT, sub1.getQNameModule());
assertEquals(ROOT, sub2.getQNameModule());
final Collection<? extends DataSchemaNode> sub1ChildNodes = sub1.getChildNodes();
final Collection<? extends DataSchemaNode> sub2ChildNodes = sub2.getChildNodes();
assertNotNull(sub1ChildNodes);
assertNotNull(sub2ChildNodes);
assertEquals(1, sub1ChildNodes.size());
assertEquals(1, sub2ChildNodes.size());
final Collection<? extends Submodule> sub1Submodules = sub1.getSubmodules();
final Collection<? extends Submodule> sub2Submodules = sub2.getSubmodules();
assertNotNull(sub1Submodules);
assertNotNull(sub2Submodules);
assertEquals(1, sub1Submodules.size());
assertEquals(0, sub2Submodules.size());
Submodule sub1Submodule = null;
for (final Submodule submodule : sub1Submodules) {
switch(submodule.getName()) {
case "submodule-to-submodule-1":
sub1Submodule = submodule;
break;
default:
}
}
assertNotNull(sub1Submodule);
assertEquals(ROOT, sub1Submodule.getQNameModule());
final Collection<? extends DataSchemaNode> sub1SubmoduleChildNodes = sub1Submodule.getChildNodes();
assertNotNull(sub1SubmoduleChildNodes);
assertEquals(1, sub1SubmoduleChildNodes.size());
final Collection<? extends Submodule> sub1SubmoduleSubmodules = sub1Submodule.getSubmodules();
assertNotNull(sub1SubmoduleSubmodules);
assertEquals(0, sub1SubmoduleSubmodules.size());
findModulesSubTest(result, root, imported);
getDataChildByNameSubTest(result, root);
}
use of org.opendaylight.yangtools.yang.model.api.Submodule in project yangtools by opendaylight.
the class DeclaredStatementsTest method testDeclaredModuleAndSubmodule.
@Test
public void testDeclaredModuleAndSubmodule() throws ReactorException {
final StatementStreamSource parentModule = sourceForResource("/declared-statements-test/parent-module-declared-test.yang");
final StatementStreamSource childModule = sourceForResource("/declared-statements-test/child-module-declared-test.yang");
final SchemaContext schemaContext = StmtTestUtils.parseYangSources(parentModule, childModule);
assertNotNull(schemaContext);
final Module testModule = schemaContext.findModules("parent-module-declared-test").iterator().next();
assertNotNull(testModule);
final ModuleStatement moduleStatement = ((ModuleEffectiveStatement) testModule).getDeclared();
assertNotNull(moduleStatement.argument());
final YangVersionStatement moduleStatementYangVersion = moduleStatement.getYangVersion();
assertNotNull(moduleStatementYangVersion);
assertNotNull(moduleStatementYangVersion.argument());
final NamespaceStatement moduleStatementNamspace = moduleStatement.getNamespace();
assertNotNull(moduleStatementNamspace);
assertNotNull(moduleStatementNamspace.argument());
final PrefixStatement moduleStatementPrefix = moduleStatement.getPrefix();
assertNotNull(moduleStatementPrefix);
assertNotNull(moduleStatementPrefix.argument());
assertEquals(1, moduleStatement.getIncludes().size());
final IncludeStatement includeStatement = moduleStatement.getIncludes().iterator().next();
assertEquals("child-module-declared-test", includeStatement.argument());
final Collection<? extends Submodule> submodules = testModule.getSubmodules();
assertNotNull(submodules);
assertEquals(1, submodules.size());
final Submodule submodule = submodules.iterator().next();
final SubmoduleStatement submoduleStatement = ((SubmoduleEffectiveStatement) submodule).getDeclared();
assertNotNull(submoduleStatement.argument());
final YangVersionStatement submoduleStatementYangVersion = submoduleStatement.getYangVersion();
assertNotNull(submoduleStatementYangVersion);
final BelongsToStatement belongsToStatement = submoduleStatement.getBelongsTo();
assertNotNull(belongsToStatement);
assertNotNull(belongsToStatement.argument());
assertNotNull(belongsToStatement.getPrefix());
}
use of org.opendaylight.yangtools.yang.model.api.Submodule in project yangtools by opendaylight.
the class IncludedStmtsTest method submoduleNamespaceTest.
@Test
public void submoduleNamespaceTest() {
final Module testModule = result.findModules("root-module").iterator().next();
assertNotNull(testModule);
final Submodule subModule = testModule.getSubmodules().iterator().next();
assertEquals("urn:opendaylight.org/root-module", subModule.getNamespace().toString());
}
use of org.opendaylight.yangtools.yang.model.api.Submodule in project netconf by opendaylight.
the class NetconfDeviceSimulator method parseSchemasToModuleCapabilities.
private Set<Capability> parseSchemasToModuleCapabilities(final SharedSchemaRepository consumer) {
final Set<SourceIdentifier> loadedSources = new HashSet<>();
consumer.registerSchemaSourceListener(TextToIRTransformer.create(consumer, consumer));
consumer.registerSchemaSourceListener(new SchemaSourceListener() {
@Override
public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {
}
@Override
public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> potentialSchemaSources) {
for (final PotentialSchemaSource<?> potentialSchemaSource : potentialSchemaSources) {
loadedSources.add(potentialSchemaSource.getSourceIdentifier());
}
}
@Override
public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {
}
});
if (configuration.getSchemasDir() != null) {
LOG.info("Loading models from directory.");
final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getSchemasDir());
consumer.registerSchemaSourceListener(cache);
} else if (configuration.getModels() != null) {
LOG.info("Loading models from classpath.");
final SchemaSourceCache<YangTextSchemaSource> cache = new SchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getModels());
consumer.registerSchemaSourceListener(cache);
} else {
LOG.info("Custom module loading skipped.");
}
configuration.getDefaultYangResources().forEach(r -> {
final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create(r.getModuleName(), Revision.ofNullable(r.getRevision()));
registerSource(consumer, r.getResourcePath(), sourceIdentifier);
});
try {
// necessary for creating mdsal data stores and operations
this.schemaContext = consumer.createEffectiveModelContextFactory().createEffectiveModelContext(loadedSources).get();
} catch (final InterruptedException | ExecutionException e) {
throw new RuntimeException("Cannot parse schema context. " + "Please read stack trace and check YANG files in schema directory.", e);
}
final Set<Capability> capabilities = new HashSet<>();
for (final Module module : schemaContext.getModules()) {
for (final Submodule subModule : module.getSubmodules()) {
addModuleCapability(consumer, capabilities, subModule);
}
addModuleCapability(consumer, capabilities, module);
}
return capabilities;
}
use of org.opendaylight.yangtools.yang.model.api.Submodule in project yangtools by opendaylight.
the class YinFileIncludeStmtTest method testInclude.
@Test
public void testInclude() throws Exception {
Collection<? extends Submodule> submodules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/include-belongs-to-test").toURI()).findModules("parent").iterator().next().getSubmodules();
assertEquals(1, submodules.size());
Submodule childModule = submodules.iterator().next();
assertEquals("child", childModule.getName());
assertEquals(XMLNamespace.of("urn:opendaylight/parent"), childModule.getNamespace());
}
Aggregations