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

The following examples show how to use org.opendaylight.yangtools.yang.model.api.Module#getDataChildByName() . 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: Bug9241Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testImplicitInputAndOutputInAction() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug9241/foo.yang");
    assertNotNull(schemaContext);

    final Module fooModule = schemaContext.findModule("foo", Revision.of("2017-10-13")).get();

    final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(
            fooModule.getQNameModule(), "action-cont"));
    assertNotNull(actionCont);

    final ActionDefinition actionInCont = actionCont.getActions().iterator().next();

    final ContainerSchemaNode input = actionInCont.getInput();
    assertNotNull(input);
    assertEquals(1, input.getChildNodes().size());
    assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) input).getStatementSource());

    final ContainerSchemaNode output = actionInCont.getOutput();
    assertNotNull(output);
    assertEquals(1, output.getChildNodes().size());
    assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) output).getStatementSource());
}
 
Example 2
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 3
Source File: Bug6972Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static UnitsEffectiveStatement getEffectiveUnits(final Module module, final QName containerQName,
        final QName leafQName) {
    UnitsEffectiveStatement units = null;

    final ContainerSchemaNode cont = (ContainerSchemaNode) module.getDataChildByName(containerQName);
    assertNotNull(cont);
    final LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName);
    assertNotNull(leaf);

    for (EffectiveStatement<?, ?> effStmt : ((LeafEffectiveStatement) leaf).effectiveSubstatements()) {
        if (effStmt instanceof UnitsEffectiveStatement) {
            units = (UnitsEffectiveStatement) effStmt;
            break;
        }
    }

    return units;
}
 
Example 4
Source File: MoreRevisionsTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static void checkNetconfMonitoringModuleSimpleTest(final SchemaContext context,
        final Revision rev20130715, final QName dateTimeTypeDef20130715) {
    URI monitoringNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring");
    final QNameModule monitoring19700101 = QNameModule.create(monitoringNS);
    QName lockedTime = QName.create(monitoring19700101, "locked-time");

    Module monitoringModule19700101 = context.findModule("ietf-netconf-monitoring").get();
    DataSchemaNode leafLockedTime = monitoringModule19700101.getDataChildByName(lockedTime);
    assertNotNull(leafLockedTime);

    assertTrue(leafLockedTime instanceof LeafSchemaNode);
    QName lockedTimeTypeQName = ((LeafSchemaNode) leafLockedTime).getType().getQName();
    assertEquals(dateTimeTypeDef20130715, lockedTimeTypeQName);

    Collection<? extends ModuleImport> imports = monitoringModule19700101.getImports();
    assertEquals(1, imports.size());
    ModuleImport monitoringImport = imports.iterator().next();
    assertEquals("ietf-yang-types", monitoringImport.getModuleName());
    assertEquals(Optional.of(rev20130715), monitoringImport.getRevision());
}
 
Example 5
Source File: MoreRevisionsTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static void checkInterfacesModuleSimpleTest(final SchemaContext context,
        final Revision rev20100924, final QName dateTimeTypeDef20100924) {
    URI interfacesNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-interfaces");
    Revision rev20121115 = Revision.of("2012-11-15");
    final QNameModule interfacesNS20121115 = QNameModule.create(interfacesNS, rev20121115);
    QName lastChange = QName.create(interfacesNS20121115, "last-change");

    Module interfacesModule20121115 = context.findModule("ietf-interfaces", rev20121115).get();
    DataSchemaNode leafLastChange = interfacesModule20121115.getDataChildByName(lastChange);
    assertNotNull(leafLastChange);

    assertTrue(leafLastChange instanceof LeafSchemaNode);
    QName lastChangeTypeQName = ((LeafSchemaNode) leafLastChange).getType().getQName();
    assertEquals(dateTimeTypeDef20100924, lastChangeTypeQName);

    Collection<? extends ModuleImport> imports = interfacesModule20121115.getImports();
    assertEquals(1, imports.size());
    ModuleImport interfacesImport = imports.iterator().next();
    assertEquals("ietf-yang-types", interfacesImport.getModuleName());
    assertEquals(Optional.of(rev20100924), interfacesImport.getRevision());
}
 
Example 6
Source File: TypesResolutionTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testBitsType1() {
    Module tested = TestUtils.findModule(context, "custom-types-test").get();
    LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
            QName.create(tested.getQNameModule(), "mybits"));
    BitsTypeDefinition leafType = (BitsTypeDefinition) leaf.getType();
    Iterator<? extends Bit> bits = leafType.getBits().iterator();

    Bit bit1 = bits.next();
    assertEquals("disable-nagle", bit1.getName());
    assertEquals(Uint32.ZERO, bit1.getPosition());

    Bit bit2 = bits.next();
    assertEquals("auto-sense-speed", bit2.getName());
    assertEquals(Uint32.ONE, bit2.getPosition());

    Bit bit3 = bits.next();
    assertEquals("only-10-Mb", bit3.getName());
    assertEquals(Uint32.TWO, bit3.getPosition());

    assertFalse(bits.hasNext());
}
 
Example 7
Source File: YangParserWithContextTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTypeFromContext() throws ReactorException {
    final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(IETF)
            .addSource(sourceForResource("/types/[email protected]"))
            .addSource(sourceForResource("/context-test/test1.yang"))
            .buildEffective();

    final Module module = context.findModule("test1", Revision.of("2013-06-18")).get();
    final LeafSchemaNode leaf = (LeafSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(),
            "id"));

    assertTrue(leaf.getType() instanceof Uint16TypeDefinition);
    final Uint16TypeDefinition leafType = (Uint16TypeDefinition) leaf.getType();
    QName qname = leafType.getQName();
    assertEquals(URI.create("urn:simple.demo.test1"), qname.getNamespace());
    assertEquals(Revision.ofNullable("2013-06-18"), qname.getRevision());
    assertEquals("port-number", qname.getLocalName());

    final Uint16TypeDefinition leafBaseType = leafType.getBaseType();
    qname = leafBaseType.getQName();
    assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-inet-types"), qname.getNamespace());
    assertEquals(Revision.ofNullable("2010-09-24"), qname.getRevision());
    assertEquals("port-number", qname.getLocalName());

    final Uint8TypeDefinition dscpExt = (Uint8TypeDefinition) TestUtils.findTypedef(module.getTypeDefinitions(),
        "dscp-ext");
    final Set<? extends Range<?>> ranges = dscpExt.getRangeConstraint().get().getAllowedRanges().asRanges();
    assertEquals(1, ranges.size());
    final Range<?> range = ranges.iterator().next();
    assertEquals(Uint8.valueOf(0), range.lowerEndpoint());
    assertEquals(Uint8.valueOf(63), range.upperEndpoint());
}
 
Example 8
Source File: ChoiceStmtTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void choiceAndCaseTest() throws ReactorException {
    final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(CHOICE_MODULE, IMPORTED_MODULE1, IMPORTED_MODULE2, INCLUDED_MODULE)
            .buildEffective();
    assertNotNull(result);

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

    final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
            testModule.getQNameModule(), "transfer"));
    assertNotNull(container);

    final ChoiceSchemaNode choice = (ChoiceSchemaNode) container.getDataChildByName(QName.create(
            testModule.getQNameModule(), "how"));
    assertNotNull(choice);
    assertEquals(5, choice.getCases().size());

    CaseSchemaNode caseNode = choice.findCaseNodes("input").iterator().next();
    assertNotNull(caseNode);
    caseNode = choice.findCaseNodes("output").iterator().next();
    assertNotNull(caseNode);
    caseNode = choice.findCaseNodes("interval").iterator().next();
    assertNotNull(caseNode);
    caseNode = choice.findCaseNodes("daily").iterator().next();
    assertNotNull(caseNode);
    caseNode = choice.findCaseNodes("manual").iterator().next();
    assertNotNull(caseNode);
    assertEquals("interval", choice.getDefaultCase().get().getQName().getLocalName());
}
 
Example 9
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 10
Source File: MustAndWhenStmtTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void whenStmtTest() throws ReactorException {
    final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSource(sourceForResource("/must-when-stmt-test/when-test.yang"))
            .buildEffective();
    assertNotNull(result);

    final Module testModule = result.findModules("when-test").iterator().next();
    assertNotNull(testModule);

    final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(
        QName.create(testModule.getQNameModule(), "test-container"));
    assertNotNull(container);
    assertEquals("conditional-leaf = 'autumn-leaf'", container.getWhenCondition().get().getOriginalString());
}
 
Example 11
Source File: TypesResolutionTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testIdentityref() {
    Module tested = TestUtils.findModule(context, "custom-types-test").get();
    Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
    TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "service-type-ref");
    IdentityrefTypeDefinition baseType = (IdentityrefTypeDefinition) testedType.getBaseType();
    QName identity = baseType.getIdentities().iterator().next().getQName();
    assertEquals(URI.create("urn:custom.types.demo"), identity.getNamespace());
    assertEquals(Revision.ofNullable("2012-04-16"), identity.getRevision());
    assertEquals("service-type", identity.getLocalName());

    LeafSchemaNode type = (LeafSchemaNode) tested.getDataChildByName(QName.create(tested.getQNameModule(), "type"));
    assertNotNull(type);
}
 
Example 12
Source File: YangParserWithContextTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testUsesFromContext() throws ReactorException {
    final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(BAZ, FOO, BAR, SUBFOO, sourceForResource("/context-test/test2.yang"))
            .buildEffective();

    final Module testModule = context.findModule("test2", Revision.of("2013-06-18")).get();
    final Module contextModule = context.findModules(URI.create("urn:opendaylight.baz")).iterator().next();
    assertNotNull(contextModule);
    final Collection<? extends GroupingDefinition> groupings = contextModule.getGroupings();
    assertEquals(1, groupings.size());
    final GroupingDefinition grouping = groupings.iterator().next();

    // get node containing uses
    final ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
            testModule.getQNameModule(), "peer"));
    final ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName(QName.create(
            testModule.getQNameModule(), "destination"));

    // check uses
    final Collection<? extends UsesNode> uses = destination.getUses();
    assertEquals(1, uses.size());

    // check uses process
    final AnyxmlSchemaNode data_u = (AnyxmlSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "data"));
    assertNotNull(data_u);
    assertTrue(data_u.isAddedByUses());

    final AnyxmlSchemaNode data_g = (AnyxmlSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "data"));
    assertNotNull(data_g);
    assertFalse(data_g.isAddedByUses());
    assertFalse(data_u.equals(data_g));

    final ChoiceSchemaNode how_u = (ChoiceSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "how"));
    assertNotNull(how_u);
    assertTrue(how_u.isAddedByUses());

    final ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "how"));
    assertNotNull(how_g);
    assertFalse(how_g.isAddedByUses());
    assertFalse(how_u.equals(how_g));

    final LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "address"));
    assertNotNull(address_u);
    assertTrue(address_u.isAddedByUses());

    final LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "address"));
    assertNotNull(address_g);
    assertFalse(address_g.isAddedByUses());
    assertFalse(address_u.equals(address_g));

    final ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "port"));
    assertNotNull(port_u);
    assertTrue(port_u.isAddedByUses());

    final ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "port"));
    assertNotNull(port_g);
    assertFalse(port_g.isAddedByUses());
    assertFalse(port_u.equals(port_g));

    final ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "addresses"));
    assertNotNull(addresses_u);
    assertTrue(addresses_u.isAddedByUses());

    final ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "addresses"));
    assertNotNull(addresses_g);
    assertFalse(addresses_g.isAddedByUses());
    assertFalse(addresses_u.equals(addresses_g));

    // grouping defined by 'uses'
    final Collection<? extends GroupingDefinition> groupings_u = destination.getGroupings();
    assertEquals(0, groupings_u.size());

    // grouping defined in 'grouping' node
    final Collection<? extends GroupingDefinition> groupings_g = grouping.getGroupings();
    assertEquals(1, groupings_g.size());
    final GroupingDefinition grouping_g = groupings_g.iterator().next();
    assertFalse(grouping_g.isAddedByUses());

    final Collection<? extends UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
    assertEquals(1, nodes_u.size());
    final UnknownSchemaNode node_u = nodes_u.iterator().next();
    assertTrue(node_u.isAddedByUses());

    final Collection<? extends UnknownSchemaNode> nodes_g = grouping.getUnknownSchemaNodes();
    assertEquals(1, nodes_g.size());
    final UnknownSchemaNode node_g = nodes_g.iterator().next();
    assertFalse(node_g.isAddedByUses());
    assertFalse(node_u.equals(node_g));
}
 
Example 13
Source File: Bug6887Test.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testRestrictedBits() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar.yang");
    assertNotNull(schemaContext);

    final Module bar = schemaContext.findModule("bar", Revision.of("2017-02-02")).get();
    final LeafSchemaNode myBitsLeaf = (LeafSchemaNode) bar.getDataChildByName(
            QName.create(bar.getQNameModule(), "my-bits-leaf"));
    assertNotNull(myBitsLeaf);

    BitsTypeDefinition bitsType = (BitsTypeDefinition) myBitsLeaf.getType();

    Collection<? extends Bit> bits = bitsType.getBits();
    assertEquals(2, bits.size());
    Bit bitB = createBit("bit-b", 2);
    Bit bitC = createBit("bit-c", 3);
    assertContainsBits(bits, bitB, bitC);

    bitsType = bitsType.getBaseType();
    bits = bitsType.getBits();
    assertEquals(3, bits.size());
    bitB = createBit("bit-b", 2);
    bitC = createBit("bit-c", 3);
    Bit bitD = createBit("bit-d", 4);
    assertContainsBits(bits, bitB, bitC, bitD);

    bitsType = bitsType.getBaseType();
    bits = bitsType.getBits();
    assertEquals(4, bits.size());
    final Bit bitA = createBit("bit-a", 1);
    bitB = createBit("bit-b", 2);
    bitC = createBit("bit-c", 3);
    bitD = createBit("bit-d", 4);
    assertContainsBits(bits, bitA, bitB, bitC, bitD);

    final LeafSchemaNode myBitsLeaf2 = (LeafSchemaNode) bar.getDataChildByName(
            QName.create(bar.getQNameModule(), "my-bits-leaf-2"));
    assertNotNull(myBitsLeaf2);

    bitsType = (BitsTypeDefinition) myBitsLeaf2.getType();
    bits = bitsType.getBits();
    assertEquals(3, bits.size());
    bitB = createBit("bit-b", 2);
    bitC = createBit("bit-c", 3);
    bitD = createBit("bit-d", 4);
    assertContainsBits(bits, bitB, bitC, bitD);
}
 
Example 14
Source File: AugmentTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testAugmentedChoice() throws Exception {
    final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
        .toURI());
    final Module module2 = TestUtils.findModule(context, "bar").get();
    final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
            module2.getQNameModule(), "interfaces"));
    final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
            module2.getQNameModule(), "ifEntry"));
    final ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(
            BAZ, "augment-holder"));
    TestUtils.checkIsAugmenting(augmentedHolder, true);

    // foo.yang
    // augment "/br:interfaces/br:ifEntry/bz:augment-holder"
    final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentedHolder.getDataChildByName(QName.create(FOO, "odl"));
    assertNotNull(odl);
    final Collection<? extends CaseSchemaNode> cases = odl.getCases();
    assertEquals(4, cases.size());

    CaseSchemaNode id = null;
    CaseSchemaNode node1 = null;
    CaseSchemaNode node2 = null;
    CaseSchemaNode node3 = null;

    for (final CaseSchemaNode ccn : cases) {
        if ("id".equals(ccn.getQName().getLocalName())) {
            id = ccn;
        } else if ("node1".equals(ccn.getQName().getLocalName())) {
            node1 = ccn;
        } else if ("node2".equals(ccn.getQName().getLocalName())) {
            node2 = ccn;
        } else if ("node3".equals(ccn.getQName().getLocalName())) {
            node3 = ccn;
        }
    }

    assertNotNull(id);
    assertNotNull(node1);
    assertNotNull(node2);
    assertNotNull(node3);

    final List<QName> qnames = new ArrayList<>();
    qnames.add(Q0);
    qnames.add(Q1);
    qnames.add(Q2);
    qnames.add(QName.create(FOO, "odl"));

    // case id
    QName qname = QName.create(FOO, "id");
    assertEquals(qname, id.getQName());
    qnames.add(qname);
    assertEquals(SchemaPath.create(qnames, true), id.getPath());
    final Collection<? extends DataSchemaNode> idChildren = id.getChildNodes();
    assertEquals(1, idChildren.size());

    // case node1
    qname = QName.create(FOO, "node1");
    assertEquals(qname, node1.getQName());
    qnames.set(4, qname);
    assertEquals(SchemaPath.create(qnames, true), node1.getPath());
    final Collection<? extends DataSchemaNode> node1Children = node1.getChildNodes();
    assertTrue(node1Children.isEmpty());

    // case node2
    qname = QName.create(FOO, "node2");
    assertEquals(qname, node2.getQName());
    qnames.set(4, qname);
    assertEquals(SchemaPath.create(qnames, true), node2.getPath());
    final Collection<? extends DataSchemaNode> node2Children = node2.getChildNodes();
    assertTrue(node2Children.isEmpty());

    // case node3
    qname = QName.create(FOO, "node3");
    assertEquals(qname, node3.getQName());
    qnames.set(4, qname);
    assertEquals(SchemaPath.create(qnames, true), node3.getPath());
    final Collection<? extends DataSchemaNode> node3Children = node3.getChildNodes();
    assertEquals(1, node3Children.size());

    // test cases
    qnames.clear();
    qnames.add(Q0);
    qnames.add(Q1);
    qnames.add(Q2);
    qnames.add(QName.create(FOO, "odl"));

    // case id child
    qnames.add(QName.create(FOO, "id"));
    qnames.add(QName.create(FOO, "id"));
    final LeafSchemaNode caseIdChild = (LeafSchemaNode) idChildren.iterator().next();
    assertNotNull(caseIdChild);
    assertEquals(SchemaPath.create(qnames, true), caseIdChild.getPath());

    // case node3 child
    qnames.set(4, QName.create(FOO, "node3"));
    qnames.set(5, QName.create(FOO, "node3"));
    final ContainerSchemaNode caseNode3Child = (ContainerSchemaNode) node3Children.iterator().next();
    assertNotNull(caseNode3Child);
    assertEquals(SchemaPath.create(qnames, true), caseNode3Child.getPath());
}
 
Example 15
Source File: EffectiveBuildTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void effectiveBuildTest() throws ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSources(SIMPLE_MODULE)
            .buildEffective();

    assertNotNull(result);

    Module simpleModule = result.findModules("simple-module").iterator().next();
    assertNotNull(simpleModule);

    final QName q1 = QName.create(SIMPLE_MODULE_QNAME, "root-container");
    final QName q2 = QName.create(SIMPLE_MODULE_QNAME, "sub-container");
    final QName q3 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container");
    final QName q4 = QName.create(SIMPLE_MODULE_QNAME, "root-container2");
    final QName q5 = QName.create(SIMPLE_MODULE_QNAME, "sub-container2");
    final QName q6 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container2");
    final QName q7 = QName.create(SIMPLE_MODULE_QNAME, "grp");

    ContainerSchemaNode rootCon = (ContainerSchemaNode) simpleModule.getDataChildByName(q1);
    assertNotNull(rootCon);

    ContainerSchemaNode subCon = (ContainerSchemaNode) rootCon.getDataChildByName(q2);
    assertNotNull(subCon);

    ContainerSchemaNode subSubCon = (ContainerSchemaNode) subCon.getDataChildByName(q3);
    assertNotNull(subSubCon);

    ContainerSchemaNode rootCon2 = (ContainerSchemaNode) simpleModule.getDataChildByName(q4);
    assertNotNull(rootCon2);

    ContainerSchemaNode subCon2 = (ContainerSchemaNode) rootCon2.getDataChildByName(q5);
    assertNotNull(subCon2);

    ContainerSchemaNode subSubCon2 = (ContainerSchemaNode) subCon2.getDataChildByName(q6);
    assertNotNull(subSubCon2);

    GroupingDefinition grp = simpleModule.getGroupings().iterator().next();
    assertNotNull(grp);
    assertEquals(q7, grp.getQName());

    ContainerSchemaNode grpSubCon2 = (ContainerSchemaNode) grp.getDataChildByName(q5);
    assertNotNull(grpSubCon2);

    ContainerSchemaNode grpSubSubCon2 = (ContainerSchemaNode) grpSubCon2.getDataChildByName(q6);
    assertNotNull(grpSubSubCon2);

    assertEquals(SchemaPath.create(true, q1, q2, q3), subSubCon.getPath());
    assertEquals(SchemaPath.create(true, q4, q5, q6), subSubCon2.getPath());
    assertEquals(SchemaPath.create(true, q7, q5, q6), grpSubSubCon2.getPath());
}
 
Example 16
Source File: DeclaredStatementsTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testDeclaredAnyXml() throws ReactorException {
    final StatementStreamSource anyxmlStmtModule =
            sourceForResource("/declared-statements-test/anyxml-declared-test.yang");

    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(anyxmlStmtModule);
    assertNotNull(schemaContext);

    final Module testModule = schemaContext.findModules("anyxml-declared-test").iterator().next();
    assertNotNull(testModule);

    final AnyxmlSchemaNode anyxmlSchemaNode = (AnyxmlSchemaNode) testModule.getDataChildByName(
            QName.create(testModule.getQNameModule(), "foobar"));
    assertNotNull(anyxmlSchemaNode);
    final AnyxmlStatement anyxmlStatement = ((AnyxmlEffectiveStatement) anyxmlSchemaNode).getDeclared();

    final QName name = anyxmlStatement.getName();
    assertNotNull(name);

    final WhenStatement whenStatement = anyxmlStatement.getWhenStatement().get();
    final RevisionAwareXPath whenRevisionAwareXPath = whenStatement.getCondition();
    assertNotNull(whenRevisionAwareXPath);
    final DescriptionStatement whenStatementDescription = whenStatement.getDescription().get();
    assertTrue(whenStatement.getReference().isPresent());

    final Collection<? extends IfFeatureStatement> ifFeatureStatements = anyxmlStatement.getIfFeatures();
    assertNotNull(ifFeatureStatements);
    assertEquals(1, ifFeatureStatements.size());
    final Predicate<Set<QName>> ifFeaturePredicate = ifFeatureStatements.iterator().next().getIfFeaturePredicate();
    assertNotNull(ifFeaturePredicate);

    final Collection<? extends MustStatement> mustStatements = anyxmlStatement.getMustStatements();
    assertNotNull(mustStatements);
    assertEquals(1, mustStatements.size());
    final MustStatement mustStatement = mustStatements.iterator().next();
    final RevisionAwareXPath mustRevisionAwareXPath = mustStatement.getCondition();
    assertNotNull(mustRevisionAwareXPath);
    assertTrue(mustStatement.getErrorAppTagStatement().isPresent());
    assertTrue(mustStatement.getErrorMessageStatement().isPresent());
    assertTrue(mustStatement.getDescription().isPresent());
    assertTrue(mustStatement.getReference().isPresent());

    final ConfigStatement configStatement = anyxmlStatement.getConfig().get();
    assertFalse(configStatement.getValue());

    final StatusStatement statusStatement = anyxmlStatement.getStatus().get();
    final Status status = statusStatement.getValue();
    assertNotNull(status);

    final DescriptionStatement descriptionStatement = anyxmlStatement.getDescription().get();
    assertEquals("anyxml description", descriptionStatement.getText());

    final ReferenceStatement referenceStatement = anyxmlStatement.getReference().get();
    assertEquals("anyxml reference", referenceStatement.getText());

    assertTrue(anyxmlStatement.getMandatory().isPresent());
}
 
Example 17
Source File: DeclaredStatementsTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testDeclaredContainer() throws ReactorException {
    final StatementStreamSource containerStmtModule =
            sourceForResource("/declared-statements-test/container-declared-test.yang");

    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(containerStmtModule);
    assertNotNull(schemaContext);

    final Module testModule = schemaContext.findModules("container-declared-test").iterator().next();
    assertNotNull(testModule);

    final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) testModule.getDataChildByName(
            QName.create(testModule.getQNameModule(), "test-container"));
    assertNotNull(containerSchemaNode);
    final ContainerStatement containerStatement =
            ((ContainerEffectiveStatement) containerSchemaNode).getDeclared();

    final QName name = containerStatement.getName();
    assertNotNull(name);

    final WhenStatement containerStatementWhen = containerStatement.getWhenStatement().get();

    final Collection<? extends IfFeatureStatement> containerStatementIfFeatures =
            containerStatement.getIfFeatures();
    assertNotNull(containerStatementIfFeatures);
    assertEquals(1, containerStatementIfFeatures.size());

    final Collection<? extends MustStatement> containerStatementMusts = containerStatement.getMustStatements();
    assertNotNull(containerStatementMusts);
    assertEquals(1, containerStatementMusts.size());

    final PresenceStatement containerStatementPresence = containerStatement.getPresence();
    assertNotNull(containerStatementPresence);
    assertNotNull(containerStatementPresence.getValue());

    assertTrue(containerStatement.getConfig().isPresent());
    assertTrue(containerStatement.getStatus().isPresent());
    assertTrue(containerStatement.getDescription().isPresent());
    assertTrue(containerStatement.getReference().isPresent());

    final Collection<? extends TypedefStatement> containerStatementTypedefs = containerStatement.getTypedefs();
    assertNotNull(containerStatementTypedefs);
    assertEquals(1, containerStatementTypedefs.size());

    final Collection<? extends GroupingStatement> containerStatementGroupings = containerStatement.getGroupings();
    assertNotNull(containerStatementGroupings);
    assertEquals(1, containerStatementGroupings.size());

    final Collection<? extends DataDefinitionStatement> containerStatementDataDefinitions =
            containerStatement.getDataDefinitions();

    assertNotNull(containerStatementDataDefinitions);
    assertEquals(1, containerStatementDataDefinitions.size());
}
 
Example 18
Source File: DeviationResolutionTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testDeviateDelete() throws ReactorException {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(
            sourceForResource("/deviation-resolution-test/deviation-delete/foo.yang"),
            sourceForResource("/deviation-resolution-test/deviation-delete/bar.yang"));
    assertNotNull(schemaContext);

    final Module barModule = schemaContext.findModule("bar", Revision.of("2017-01-20")).get();
    final LeafSchemaNode myLeaf = (LeafSchemaNode) barModule.getDataChildByName(
            QName.create(barModule.getQNameModule(), "my-leaf"));
    assertNotNull(myLeaf);

    assertEquals(Optional.empty(), myLeaf.getType().getDefaultValue());
    assertEquals(Optional.empty(), myLeaf.getType().getUnits());
    assertEquals(0, myLeaf.getUnknownSchemaNodes().size());

    final LeafListSchemaNode myLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
            QName.create(barModule.getQNameModule(), "my-leaf-list"));
    assertNotNull(myLeafList);

    assertEquals(0, myLeafList.getDefaults().size());
    assertEquals(0, myLeafList.getMustConstraints().size());

    final ListSchemaNode myList = (ListSchemaNode) barModule.getDataChildByName(
            QName.create(barModule.getQNameModule(), "my-list"));
    assertNotNull(myList);

    assertEquals(0, myList.getUniqueConstraints().size());
    assertEquals(0, myList.getUnknownSchemaNodes().size());

    final ContainerSchemaNode myCont = (ContainerSchemaNode) barModule.getDataChildByName(
            QName.create(barModule.getQNameModule(), "my-cont"));
    assertNotNull(myCont);

    final LeafSchemaNode myAugLeaf = (LeafSchemaNode) myCont.getDataChildByName(
            QName.create(barModule.getQNameModule(), "my-aug-leaf"));
    assertNotNull(myAugLeaf);
    assertEquals(Optional.empty(), myAugLeaf.getType().getDefaultValue());
    assertEquals(Optional.empty(), myAugLeaf.getType().getUnits());
    assertEquals(0, myAugLeaf.getMustConstraints().size());
    assertEquals(0, myAugLeaf.getUnknownSchemaNodes().size());

    final LeafSchemaNode myUsedLeaf = (LeafSchemaNode) myCont.getDataChildByName(
            QName.create(barModule.getQNameModule(), "my-used-leaf"));
    assertNotNull(myUsedLeaf);
    assertEquals(Optional.empty(), myUsedLeaf.getType().getDefaultValue());
    assertEquals(Optional.empty(), myUsedLeaf.getType().getUnits());
    assertEquals(0, myUsedLeaf.getMustConstraints().size());
    assertEquals(0, myUsedLeaf.getUnknownSchemaNodes().size());
}
 
Example 19
Source File: SharedSchemaRepositoryWithFeaturesTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testSharedSchemaRepositoryWithAllFeaturesSupported() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
            "shared-schema-repo-with-features-test");

    final SettableSchemaProvider<ASTSchemaSource> foobar = getImmediateYangSourceProviderFromResource(
        "/if-feature-resolution-test/shared-schema-repository/foobar.yang");
    foobar.register(sharedSchemaRepository);
    foobar.setResult();

    final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
    final ListenableFuture<EffectiveModelContext> testSchemaContextFuture =
            fact.createEffectiveModelContext(foobar.getId());
    assertTrue(testSchemaContextFuture.isDone());
    assertSchemaContext(testSchemaContextFuture.get(), 1);

    final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
    assertNotNull(module);
    assertEquals(3, module.getChildNodes().size());

    final ContainerSchemaNode testContainerA = (ContainerSchemaNode) module.getDataChildByName(
            QName.create(module.getQNameModule(), "test-container-a"));
    assertNotNull(testContainerA);
    final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
            QName.create(module.getQNameModule(), "test-leaf-a"));
    assertNotNull(testLeafA);

    final ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.getDataChildByName(
            QName.create(module.getQNameModule(), "test-container-b"));
    assertNotNull(testContainerB);
    final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
            QName.create(module.getQNameModule(), "test-leaf-b"));
    assertNotNull(testLeafB);

    final ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(
            QName.create(module.getQNameModule(), "test-container-c"));
    assertNotNull(testContainerC);
    final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
            QName.create(module.getQNameModule(), "test-leaf-c"));
    assertNotNull(testLeafC);
}
 
Example 20
Source File: SchemaContextUtil.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private static SchemaNode findNodeInModule(final Module module, final Iterable<QName> path) {
    if (!path.iterator().hasNext()) {
        LOG.debug("No node matching {} found in node {}", path, module);
        return null;
    }

    final QName current = path.iterator().next();
    LOG.trace("Looking for node {} in module {}", current, module);

    SchemaNode foundNode = null;
    final Iterable<QName> nextPath = nextLevel(path);

    foundNode = module.getDataChildByName(current);
    if (foundNode != null && nextPath.iterator().hasNext()) {
        foundNode = findNodeIn(foundNode, nextPath);
    }

    if (foundNode == null) {
        foundNode = getGroupingByName(module, current);
        if (foundNode != null && nextPath.iterator().hasNext()) {
            foundNode = findNodeIn(foundNode, nextPath);
        }
    }

    if (foundNode == null) {
        foundNode = getRpcByName(module, current);
        if (foundNode != null && nextPath.iterator().hasNext()) {
            foundNode = findNodeIn(foundNode, nextPath);
        }
    }

    if (foundNode == null) {
        foundNode = getNotificationByName(module, current);
        if (foundNode != null && nextPath.iterator().hasNext()) {
            foundNode = findNodeIn(foundNode, nextPath);
        }
    }

    if (foundNode == null) {
        LOG.debug("No node matching {} found in node {}", path, module);
    }

    return foundNode;
}