Search in sources :

Example 46 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class AugmentTest method testAugmentRpc.

@Test
public void testAugmentRpc() throws Exception {
    final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/rpc");
    final XMLNamespace NS_BAR = XMLNamespace.of("urn:opendaylight:bar");
    final XMLNamespace NS_FOO = XMLNamespace.of("urn:opendaylight:foo");
    final Revision revision = Revision.of("2013-10-11");
    final Module bar = context.findModules("bar").iterator().next();
    final Collection<? extends RpcDefinition> rpcs = bar.getRpcs();
    assertEquals(2, rpcs.size());
    RpcDefinition submit = null;
    for (final RpcDefinition rpc : rpcs) {
        if ("submit".equals(rpc.getQName().getLocalName())) {
            submit = rpc;
            break;
        }
    }
    assertNotNull(submit);
    final QName submitQName = QName.create(NS_BAR, revision, "submit");
    assertEquals(submitQName, submit.getQName());
    final InputSchemaNode input = submit.getInput();
    final QName inputQName = QName.create(NS_BAR, revision, "input");
    assertEquals(inputQName, input.getQName());
    final ChoiceSchemaNode arguments = (ChoiceSchemaNode) input.getDataChildByName(QName.create(NS_BAR, revision, "arguments"));
    final QName argumentsQName = QName.create(NS_BAR, revision, "arguments");
    assertEquals(argumentsQName, arguments.getQName());
    assertFalse(arguments.isAugmenting());
    final Collection<? extends CaseSchemaNode> cases = arguments.getCases();
    assertEquals(3, cases.size());
    CaseSchemaNode attach = null;
    CaseSchemaNode create = null;
    CaseSchemaNode destroy = null;
    for (final CaseSchemaNode child : cases) {
        if ("attach".equals(child.getQName().getLocalName())) {
            attach = child;
        } else if ("create".equals(child.getQName().getLocalName())) {
            create = child;
        } else if ("destroy".equals(child.getQName().getLocalName())) {
            destroy = child;
        }
    }
    assertNotNull(attach);
    assertNotNull(create);
    assertNotNull(destroy);
    assertTrue(attach.isAugmenting());
    assertTrue(create.isAugmenting());
    assertTrue(destroy.isAugmenting());
    // case attach
    assertEquals(QName.create(NS_FOO, revision, "attach"), attach.getQName());
    final Collection<? extends DataSchemaNode> attachChildren = attach.getChildNodes();
    assertEquals(1, attachChildren.size());
    // case create
    assertEquals(QName.create(NS_FOO, revision, "create"), create.getQName());
    final Collection<? extends DataSchemaNode> createChildren = create.getChildNodes();
    assertEquals(1, createChildren.size());
    // case attach
    assertEquals(QName.create(NS_FOO, revision, "destroy"), destroy.getQName());
    final Collection<? extends DataSchemaNode> destroyChildren = destroy.getChildNodes();
    assertEquals(1, destroyChildren.size());
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) QName(org.opendaylight.yangtools.yang.common.QName) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 47 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class Bug6869Test method identityNoFeaureTest.

@Test
public void identityNoFeaureTest() throws Exception {
    final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6869/foo.yang", ImmutableSet.of());
    assertNotNull(schemaContext);
    final Collection<? extends IdentitySchemaNode> identities = getIdentities(schemaContext);
    assertEquals(0, identities.size());
    final DataSchemaNode findNode = schemaContext.findDataTreeChild(ROOT, GRP_LEAF).orElse(null);
    assertThat(findNode, instanceOf(LeafSchemaNode.class));
    final LeafSchemaNode grpLeaf = (LeafSchemaNode) findNode;
    assertFalse(grpLeaf.isMandatory());
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) AbstractYangTest(org.opendaylight.yangtools.yang.stmt.AbstractYangTest) Test(org.junit.Test)

Example 48 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class DeviationResolutionTest method testDeviateDelete.

@Test
public void testDeviateDelete() throws Exception {
    final EffectiveModelContext schemaContext = TestUtils.parseYangSource("/deviation-resolution-test/deviation-delete/foo.yang", "/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());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 49 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class MoreRevisionsTest method multipleRevisionsFullTest.

@Test
public void multipleRevisionsFullTest() throws Exception {
    for (int i = 0; i < 100; i++) {
        EffectiveModelContext context = StmtTestUtils.parseYangSources("/semantic-statement-parser/multiple-revisions/full");
        assertEquals(6, context.getModules().size());
        checkContentFullTest(context);
    }
}
Also used : EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 50 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class MoreRevisionsTest method nodeTest.

@Test
public void nodeTest() throws Exception {
    EffectiveModelContext context = StmtTestUtils.parseYangSources("/semantic-statement-parser/multiple-revisions/node-test");
    QName root = QName.create("foo", "2016-04-06", "foo-root");
    QName container20160404 = QName.create("foo", "2016-04-06", "con20160404");
    DataSchemaNode findDataSchemaNode = context.findDataTreeChild(root, container20160404).orElse(null);
    assertThat(findDataSchemaNode, instanceOf(ContainerSchemaNode.class));
    QName container20160405 = QName.create("foo", "2016-04-06", "con20160405");
    findDataSchemaNode = context.findDataTreeChild(root, container20160405).orElse(null);
    assertThat(findDataSchemaNode, instanceOf(ContainerSchemaNode.class));
    QName container20160406 = QName.create("foo", "2016-04-06", "con20160406");
    assertEquals(Optional.empty(), context.findDataTreeChild(root, container20160406));
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)182 Test (org.junit.Test)99 Module (org.opendaylight.yangtools.yang.model.api.Module)37 QName (org.opendaylight.yangtools.yang.common.QName)29 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)28 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)26 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)24 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)24 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)18 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)16 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)16 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)16 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)14 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)13 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)13 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 IOException (java.io.IOException)9 Collection (java.util.Collection)9