Java Code Examples for org.opendaylight.yangtools.yang.model.api.SchemaContext#getModules()

The following examples show how to use org.opendaylight.yangtools.yang.model.api.SchemaContext#getModules() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug5531Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug5531");

    assertNotNull(schema);
    assertNotNull(schema.getModules());
    assertEquals(1, schema.getModules().size());

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);

    // write small module of size less than 8kB
    for (Module module : schema.getModules()) {
        YinExportUtils.writeModuleAsYinText(module, bufferedOutputStream);
    }

    String output = byteArrayOutputStream.toString();

    // if all changes were flushed then following conditions are satisfied
    assertNotEquals("Output should not be empty", 0, output.length());
    assertTrue("Output should contains start of the module", output.contains("<module"));
    assertTrue("Output should contains end of the module", output.contains("</module>"));
}
 
Example 2
Source File: ActionStatementTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testActionStatementInDataContainers() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foo.yang");
    assertNotNull(schemaContext);

    assertContainsActions(schemaContext, "root", "grp-action", "aug-action");
    assertContainsActions(schemaContext, "top-list", "top-list-action");
    assertContainsActions(schemaContext, "top", "top-action");

    final Collection<? extends GroupingDefinition> groupings = schemaContext.getGroupings();
    assertEquals(1, groupings.size());
    assertContainsActions(groupings.iterator().next(), "grp-action");

    final Collection<? extends Module> modules = schemaContext.getModules();
    assertEquals(1, modules.size());
    final Module foo = modules.iterator().next();
    final Collection<? extends AugmentationSchemaNode> augmentations = foo.getAugmentations();
    assertEquals(1, augmentations.size());
    assertContainsActions(augmentations.iterator().next(), "aug-action", "grp-action");
}
 
Example 3
Source File: Bug6897Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void notificationsInDataContainersTest() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils
            .parseYangSource("/rfc7950/notifications-in-data-nodes/foo.yang");
    assertNotNull(schemaContext);

    assertContainsNotifications(schemaContext, "root", "grp-notification", "aug-notification");
    assertContainsNotifications(schemaContext, "top-list", "top-list-notification");
    assertContainsNotifications(schemaContext, "top", "top-notification");

    final Collection<? extends GroupingDefinition> groupings = schemaContext.getGroupings();
    assertEquals(1, groupings.size());
    assertContainsNotifications(groupings.iterator().next(), "grp-notification");

    final Collection<? extends Module> modules = schemaContext.getModules();
    assertEquals(1, modules.size());
    final Module foo = modules.iterator().next();
    final Collection<? extends AugmentationSchemaNode> augmentations = foo.getAugmentations();
    assertEquals(1, augmentations.size());
    assertContainsNotifications(augmentations.iterator().next(), "aug-notification", "grp-notification");
}
 
Example 4
Source File: Bug7480Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void libSourcesTest() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug7480/files", "/bugs/bug7480/lib");
    assertNotNull(context);

    final Collection<? extends Module> modules = context.getModules();
    assertEquals(8, modules.size());

    assertNotNull(context.findModule(new URI("foo-imp"), Revision.of("2017-01-23")));
    assertEquals(1, context.findModules(new URI("foo-imp-2")).size());
    assertEquals(1, context.findModules(new URI("foo-imp-imp")).size());
    assertEquals(1, context.findModules(new URI("bar")).size());
    assertEquals(1, context.findModules(new URI("baz")).size());
    assertTrue(context.findModule(new URI("baz-imp"), Revision.of("2002-01-01")).isPresent());
    final Collection<? extends Module> foo = context.findModules(new URI("foo"));
    assertEquals(1, foo.size());
    final Collection<? extends Module> subFoos = foo.iterator().next().getSubmodules();
    assertEquals(1, subFoos.size());

    final Module parentMod = context.findModule(new URI("parent-mod-ns"), Revision.of("2017-09-07")).get();
    assertEquals(1, parentMod.getSubmodules().size());
}
 
Example 5
Source File: AbstractYinExportTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
final void exportYinModules(final String yangDir, final String yinDir) throws IOException, SAXException,
        XMLStreamException {
    final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory(yangDir);
    final Collection<? extends Module> modules = schemaContext.getModules();
    assertNotEquals(0, modules.size());

    for (Module module : modules) {
        readAndValidateModule(schemaContext, module, yinDir);

        for (Module submodule : module.getSubmodules()) {
            readAndValidateSubmodule(schemaContext, module, submodule, yinDir);
        }
    }
}
 
Example 6
Source File: SimpleModuleTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private void testSetOfModules(final Collection<SourceIdentifier> source) throws Exception {
    final SchemaContext schemaContext = schemaContextFactory.createSchemaContext(source).get();
    final File outDir = new File("target/collection");
    outDir.mkdirs();
    for (final Module module : schemaContext.getModules()) {
        exportModule(module, outDir);
    }
}
 
Example 7
Source File: NormalizedDataBuilderTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public static DataSchemaNode getSchemaNode(final SchemaContext context, final String moduleName,
        final String childNodeName) {
    for (Module module : context.getModules()) {
        if (module.getName().equals(moduleName)) {
            DataSchemaNode found = findChildNode(module, childNodeName);
            checkState(found != null, "Unable to find %s", childNodeName);
            return found;
        }
    }
    throw new IllegalStateException("Unable to find child node " + childNodeName);
}
 
Example 8
Source File: NormalizedNodeXmlTranslationTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static DataSchemaNode getSchemaNode(final SchemaContext context, final String moduleName,
                                           final String childNodeName) {
    for (Module module : context.getModules()) {
        if (module.getName().equals(moduleName)) {
            DataSchemaNode found = findChildNode(module, childNodeName);
            checkState(found != null, "Unable to find %s", childNodeName);
            return found;
        }
    }
    throw new IllegalStateException("Unable to find child node " + childNodeName);
}
 
Example 9
Source File: MoreRevisionsTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void twoRevisionsTest2() throws ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021, IETF_TYPES)
            .buildEffective();
    assertNotNull(result);
    Collection<? extends Module> modules = result.getModules();

    assertEquals(3, modules.size());
    assertEquals(2, StmtTestUtils.findModules(modules, "network-topology").size());
}
 
Example 10
Source File: Bug6240Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testModels() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6240/correct");
    assertNotNull(context);

    final Collection<? extends Module> modules = context.getModules();
    assertEquals(2, modules.size());

    Module bar = null;
    for (final Module module : modules) {
        if ("bar".equals(module.getName())) {
            bar = module;
            break;
        }
    }

    assertNotNull(bar);
    assertTrue(bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")) instanceof ContainerSchemaNode);
    assertTrue(bar.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")) instanceof ContainerSchemaNode);

    assertEquals(1, bar.getSubmodules().size());

    final DataSchemaNode dataChildByName = bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con"));
    assertTrue(dataChildByName instanceof ContainerSchemaNode);
    final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;

    assertTrue(subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")) instanceof ContainerSchemaNode);
    assertTrue(subBarCon.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con"))
        instanceof ContainerSchemaNode);
}
 
Example 11
Source File: Bug3799Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug3799");
    assertNotNull(schema);

    Collection<? extends Module> modules = schema.getModules();
    assertNotNull(modules);
    assertEquals(1, modules.size());

    Module testModule = modules.iterator().next();
    Collection<? extends Module> subModules = testModule.getSubmodules();
    assertNotNull(subModules);
    assertEquals(1, subModules.size());

    Module testSubmodule = subModules.iterator().next();

    Collection<? extends NotificationDefinition> notifications = testSubmodule.getNotifications();
    assertNotNull(notifications);
    assertEquals(1, notifications.size());

    NotificationDefinition bazNotification = notifications.iterator().next();
    Collection<? extends DataSchemaNode> childNodes = bazNotification.getChildNodes();
    assertNotNull(childNodes);
    assertEquals(1, childNodes.size());

    DataSchemaNode child = childNodes.iterator().next();
    assertTrue(child instanceof LeafSchemaNode);

    LeafSchemaNode leafBar = (LeafSchemaNode) child;
    String bar = leafBar.getQName().getLocalName();
    assertEquals("bar", bar);
}
 
Example 12
Source File: Bug6410Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTypedefsInRpc() throws ReactorException {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/foo.yang"));

    final Collection<? extends Module> modules = schemaContext.getModules();
    assertEquals(1, modules.size());
    final Module module = modules.iterator().next();

    final Collection<? extends RpcDefinition> rpcs = module.getRpcs();
    assertEquals(1, rpcs.size());
    final RpcDefinition rpc = rpcs.iterator().next();

    final Collection<? extends TypeDefinition<?>> typeDefs = rpc.getTypeDefinitions();
    assertEquals(2, typeDefs.size());
}
 
Example 13
Source File: SchemaContextUtil.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Extract the identifiers of all modules and submodules which were used to create a particular SchemaContext.
 *
 * @param context SchemaContext to be examined
 * @return Set of ModuleIdentifiers.
 */
public static Set<SourceIdentifier> getConstituentModuleIdentifiers(final SchemaContext context) {
    final Set<SourceIdentifier> ret = new HashSet<>();

    for (Module module : context.getModules()) {
        ret.add(moduleToIdentifier(module));

        for (Module submodule : module.getSubmodules()) {
            ret.add(moduleToIdentifier(submodule));
        }
    }

    return ret;
}
 
Example 14
Source File: AnnotationSchemaNode.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find all annotations supported by a SchemaContext.
 *
 * @param context SchemaContext to search
 * @return {@link AnnotationSchemaNode}s supported by the SchemaContext..
 * @throws NullPointerException if context is null
 */
static @NonNull Map<QName, AnnotationSchemaNode> findAll(final SchemaContext context) {
    final Builder<QName, AnnotationSchemaNode> builder = ImmutableMap.builder();
    for (Module module : context.getModules()) {
        for (UnknownSchemaNode node : module.getUnknownSchemaNodes()) {
            if (node instanceof AnnotationSchemaNode) {
                builder.put(node.getQName(), (AnnotationSchemaNode) node);
            }
        }
    }

    return builder.build();
}
 
Example 15
Source File: Bug6869Test.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private static Collection<? extends IdentitySchemaNode> getIdentities(final SchemaContext schemaContext) {
    final Collection<? extends Module> modules = schemaContext.getModules();
    assertEquals(1, modules.size());
    final Module module = modules.iterator().next();
    return module.getIdentities();
}
 
Example 16
Source File: EffectiveUsesRefineAndConstraintsTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void refineTest() throws ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSource(sourceForResource("/stmt-test/uses/refine-test.yang"))
            .buildEffective();
    assertNotNull(result);

    Collection<? extends Module> modules = result.getModules();
    assertNotNull(modules);
    assertEquals(1, modules.size());

    Module module = modules.iterator().next();

    final QNameModule qnameModule = module.getQNameModule();
    final QName rootContainer = QName.create(qnameModule, "root-container");
    final QName grp1 = QName.create(qnameModule, "grp-1");

    final QName containerFromGrouping = QName.create(qnameModule, "container-from-grouping");
    final QName listInContainer = QName.create(qnameModule, "list-in-container");
    final QName choiceFromGrp = QName.create(qnameModule, "choice-from-grp");

    final QName containerFromGrouping2 = QName.create(qnameModule, "container-from-grouping2");
    final QName presenceContainer = QName.create(qnameModule, "presence-container");

    SchemaPath listInContainerPath = SchemaPath.create(true, rootContainer, containerFromGrouping, listInContainer);
    SchemaPath choiceFromGrpPath = SchemaPath.create(true, rootContainer, containerFromGrouping, choiceFromGrp);
    SchemaPath presenceContainerPath = SchemaPath.create(true, rootContainer, containerFromGrouping2,
        presenceContainer);

    checkRefinedList(result, listInContainerPath);
    checkRefinedChoice(result, choiceFromGrpPath);
    checkRefinedContainer(result, presenceContainerPath);

    SchemaPath originalListInContainerPath = SchemaPath.create(true, grp1, containerFromGrouping, listInContainer);
    SchemaPath originalChoiceFromGrpPath = SchemaPath.create(true, grp1, containerFromGrouping, choiceFromGrp);
    SchemaPath originalPresenceContainerPath = SchemaPath.create(true, grp1, containerFromGrouping2,
        presenceContainer);

    checkOriginalList(result, originalListInContainerPath);
    checkOriginalChoice(result, originalChoiceFromGrpPath);
    checkOriginalContainer(result, originalPresenceContainerPath);
}