Java Code Examples for org.opendaylight.yangtools.yang.model.api.Module#getExtensionSchemaNodes()

The following examples show how to use org.opendaylight.yangtools.yang.model.api.Module#getExtensionSchemaNodes() . 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: Bug394Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testParseList() throws Exception {
    final SchemaContext context = TestUtils.loadModules(getClass().getResource("/bugs/bug394-retest").toURI());
    final Module bug394 = TestUtils.findModule(context, "bug394").get();
    final Module bug394_ext = TestUtils.findModule(context, "bug394-ext").get();

    final ContainerSchemaNode logrecords = (ContainerSchemaNode) bug394.getDataChildByName(QName.create(
            bug394.getQNameModule(), "logrecords"));
    assertNotNull(logrecords);

    final Collection<? extends UnknownSchemaNode> nodes = logrecords.getUnknownSchemaNodes();
    assertEquals(2, nodes.size());

    final Collection<? extends ExtensionDefinition> extensions = bug394_ext.getExtensionSchemaNodes();
    assertEquals(3, extensions.size());

    final Iterator<? extends UnknownSchemaNode> it = nodes.iterator();
    assertTrue(extensions.contains(it.next().getExtensionDefinition()));
    assertTrue(extensions.contains(it.next().getExtensionDefinition()));
}
 
Example 2
Source File: ExtensionStmtTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testExtensionDefinition() throws ReactorException {
    final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSource(sourceForResource("/model/bar.yang"))
            .buildEffective();
    assertNotNull(result);

    final Module testModule = result.findModules("bar").iterator().next();
    assertNotNull(testModule);

    assertEquals(1, testModule.getExtensionSchemaNodes().size());

    final Collection<? extends ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
    final ExtensionDefinition extension = extensions.iterator().next();
    assertEquals("opendaylight", extension.getQName().getLocalName());
    assertEquals("name", extension.getArgument());
    assertTrue(extension.isYinElement());
}
 
Example 3
Source File: Bug1413Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    final Module bug1413 = TestUtils.findModule(
        TestUtils.loadModules(getClass().getResource("/bugs/bug1413").toURI()), "bug1413").get();
    assertNotNull(bug1413);

    Collection<? extends ExtensionDefinition> extensions = bug1413.getExtensionSchemaNodes();
    assertEquals(1, extensions.size());

    ExtensionDefinition info = extensions.iterator().next();
    assertEquals("text", info.getArgument());
    assertTrue(info.isYinElement());
}
 
Example 4
Source File: ExtensionStmtTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testExtensionUsage() throws ReactorException {
    final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSource(sourceForResource("/semantic-statement-parser/ext-typedef.yang"))
            .addSource(sourceForResource("/semantic-statement-parser/ext-use.yang"))
            .buildEffective();
    assertNotNull(result);

    final Module testModule1 = result.findModules("ext-typedef").iterator().next();
    assertNotNull(testModule1);

    assertEquals(1, testModule1.getExtensionSchemaNodes().size());

    final Collection<? extends ExtensionDefinition> extensions = testModule1.getExtensionSchemaNodes();
    final ExtensionDefinition extensionDefinition = extensions.iterator().next();

    final Module testModule2 = result.findModules("ext-use").iterator().next();
    assertNotNull(testModule2);

    final LeafSchemaNode leaf = (LeafSchemaNode) testModule2.getDataChildByName(
        QName.create(testModule2.getQNameModule(), "value"));
    assertNotNull(leaf);

    assertEquals(1, leaf.getUnknownSchemaNodes().size());
    final Collection<? extends UnknownSchemaNode> unknownNodes = leaf.getUnknownSchemaNodes();
    final UnknownSchemaNode extensionUse = unknownNodes.iterator().next();
    assertEquals(extensionDefinition.getQName().getLocalName(), extensionUse.getExtensionDefinition().getQName()
            .getLocalName());
    assertEquals(extensionDefinition.getArgument(), extensionUse.getExtensionDefinition().getArgument());

    assertEquals("key:value", extensionUse.getNodeParameter());
}
 
Example 5
Source File: EffectiveModuleTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void effectiveBuildTest() throws SourceException, ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(ROOT_MODULE, IMPORTED_MODULE, SUBMODULE)
            .buildEffective();

    assertNotNull(result);

    Module rootModule = result.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 Module> 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(URI.create("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(FEATURE1_SCHEMA_PATH, featureStmt.getPath());
    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());
}
 
Example 6
Source File: YinFileExtensionStmtTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testExtensions() {
    Module testModule = TestUtils.findModule(context, "config").get();
    assertNotNull(testModule);

    Collection<? extends ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
    assertEquals(5, extensions.size());

    Iterator<? extends ExtensionDefinition> extIterator = extensions.iterator();
    ExtensionDefinition extension = extIterator.next();
    assertEquals("name", extension.getArgument());
    assertEquals("java-class", extension.getQName().getLocalName());
    assertEquals(Optional.of("YANG language extension carrying the fully-qualified name of\n"
            + "a Java class. Code generation tools use the provided reference\n"
            + "to tie a specific construct to its Java representation."), extension.getDescription());

    extension = extIterator.next();
    assertEquals("name", extension.getArgument());
    assertEquals("required-identity", extension.getQName().getLocalName());
    assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
            + "leafref, which points to a identityref, should additionally\n"
            + "require the target node is actually set to a descendant to\n"
            + "of a particular identity.\n"
            + "\n"
            + "This is a workaround to two YANG deficiencies:\n"
            + "1) not being able to leafref instances of identityref\n"
            + "2) not being able to refine an identityref\n"
            + "\n"
            + "This extension takes one argument, name, which MUST be the name\n"
            + "of an identity. Furthermore, that identity MUST be based,\n"
            + "directly or indirectly, on the identity, which is referenced by\n"
            + "the leaf reference, which is annotated with this extension."), extension.getDescription());

    extension = extIterator.next();
    assertNull(extension.getArgument());
    assertEquals("inner-state-bean", extension.getQName().getLocalName());
    assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
            + "list located under module's state should be treated as a list\n"
            + "of child state beans instead of just an ordinary list attribute"), extension.getDescription());

    extension = extIterator.next();
    assertEquals("name", extension.getArgument());
    assertEquals("provided-service", extension.getQName().getLocalName());
    assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
            + "module provides certain service. This extension can be placed\n"
            + "on identities that are based on module-type. Zero or more services\n"
            + "can be provided.\n"
            + "This extension takes one argument - name - which MUST be the name\n"
            + "of an identity. Furthermore, this identity MUST be based on\n"
            + "service-type."), extension.getDescription());

    extension = extIterator.next();
    assertEquals("java-prefix", extension.getArgument());
    assertEquals("java-name-prefix", extension.getQName().getLocalName());
    assertEquals(Optional.of("YANG language extension carrying java simple class name prefix\n"
            + "that will be taken into account when generating java code from\n"
            + "identities that are based on module-type."), extension.getDescription());
}
 
Example 7
Source File: Bug4456Test.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void test() throws Exception {
    SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug4456");
    assertNotNull(schema);

    Set<Module> modules = (Set<Module>) schema.findModules(URI.create("foo"));
    assertEquals(1, modules.size());
    Module moduleFoo = modules.iterator().next();

    Collection<? extends ExtensionDefinition> extensionSchemaNodes = moduleFoo.getExtensionSchemaNodes();
    assertEquals(5, extensionSchemaNodes.size());
    for (ExtensionDefinition extensionDefinition : extensionSchemaNodes) {

        Collection<? extends UnknownSchemaNode> unknownSchemaNodes = extensionDefinition.getUnknownSchemaNodes();
        assertEquals(1, unknownSchemaNodes.size());
        UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.iterator().next();
        String unknownNodeExtensionDefName = unknownSchemaNode.getExtensionDefinition().getQName().getLocalName();

        Collection<? extends UnknownSchemaNode> subUnknownSchemaNodes = unknownSchemaNode.getUnknownSchemaNodes();
        assertEquals(1, subUnknownSchemaNodes.size());
        UnknownSchemaNode subUnknownSchemaNode = subUnknownSchemaNodes.iterator().next();
        String subUnknownNodeExtensionDefName = subUnknownSchemaNode.getExtensionDefinition().getQName()
                .getLocalName();

        switch (extensionDefinition.getQName().getLocalName()) {
            case "a":
                assertEquals("b", unknownNodeExtensionDefName);
                assertEquals("c", subUnknownNodeExtensionDefName);
                break;
            case "b":
                assertEquals("c", unknownNodeExtensionDefName);
                assertEquals("a", subUnknownNodeExtensionDefName);
                break;
            case "c":
                assertEquals("a", unknownNodeExtensionDefName);
                assertEquals("b", subUnknownNodeExtensionDefName);
                break;
            case "r":
                assertEquals("r", unknownNodeExtensionDefName);
                assertEquals("r2", subUnknownNodeExtensionDefName);
                break;
            case "r2":
                assertEquals("r2", unknownNodeExtensionDefName);
                assertEquals("r", subUnknownNodeExtensionDefName);
                break;
            default:
                fail("Unexpected extension definition");
        }
    }
}