Search in sources :

Example 26 with EffectiveModelContext

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

the class Bug5830Test method testPresenceContainer.

private static void testPresenceContainer() throws DataValidationFailedException {
    final EffectiveModelContext schemaContext = TestModel.createTestContext("/bug-5830/foo-presence.yang");
    assertNotNull("Schema context must not be null.", schemaContext);
    testContainerIsNotPresent(schemaContext);
    try {
        testContainerIsPresent(schemaContext);
        fail("Should fail due to missing mandatory node under present presence container.");
    } catch (IllegalArgumentException e) {
        assertEquals("Node (foo?revision=2016-05-17)task-data is missing mandatory descendant /(foo?revision=2016-05-17)" + "mandatory-data", e.getMessage());
    }
    testMandatoryDataLeafIsPresent(schemaContext);
}
Also used : EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 27 with EffectiveModelContext

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

the class Bug6856Test method testImplicitInputAndOutputInRpc.

@Test
public void testImplicitInputAndOutputInRpc() throws Exception {
    final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class, "/bugs/bug-6856/foo.yang");
    assertNotNull(schemaContext);
    final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
    final Module fooModule = schemaContext.findModule("foo", Revision.of("2017-02-28")).get();
    YinExportUtils.writeModuleAsYinText(fooModule.asEffectiveStatement(), bufferedOutputStream);
    final String output = byteArrayOutputStream.toString();
    assertNotNull(output);
    assertFalse(output.isEmpty());
    assertFalse(output.contains("<input>"));
    assertFalse(output.contains("<output>"));
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Module(org.opendaylight.yangtools.yang.model.api.Module) BufferedOutputStream(java.io.BufferedOutputStream) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 28 with EffectiveModelContext

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

the class SimpleModuleTest method testSetOfModules.

private void testSetOfModules(final Collection<SourceIdentifier> source) throws Exception {
    final EffectiveModelContext schemaContext = schemaContextFactory.createEffectiveModelContext(source).get();
    final File outDir = new File("target/collection");
    outDir.mkdirs();
    for (final Module module : schemaContext.getModules()) {
        exportModule(module, outDir);
    }
}
Also used : Module(org.opendaylight.yangtools.yang.model.api.Module) File(java.io.File) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 29 with EffectiveModelContext

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

the class YT588Test method test.

@Test
public void test() {
    EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt588.yang");
    QName root = QName.create(NS, REV, "root");
    QName leafRef2 = QName.create(NS, REV, "leaf-ref-2");
    QName conGrp = QName.create(NS, REV, "con-grp");
    QName leafRef = QName.create(NS, REV, "leaf-ref");
    SchemaNode findDataSchemaNode = context.findDataTreeChild(root, conGrp, leafRef).get();
    SchemaNode findDataSchemaNode2 = context.findDataTreeChild(root, leafRef2).get();
    assertThat(findDataSchemaNode, isA(LeafSchemaNode.class));
    assertThat(findDataSchemaNode2, isA(LeafSchemaNode.class));
    LeafSchemaNode leafRefNode = (LeafSchemaNode) findDataSchemaNode;
    LeafSchemaNode leafRefNode2 = (LeafSchemaNode) findDataSchemaNode2;
    assertThat(leafRefNode.getType(), isA(LeafrefTypeDefinition.class));
    assertThat(leafRefNode2.getType(), isA(LeafrefTypeDefinition.class));
    EffectiveStatement<?, ?> found = SchemaInferenceStack.ofDataTreePath(context, root, conGrp, leafRef).resolvePathExpression(((LeafrefTypeDefinition) leafRefNode.getType()).getPathStatement());
    assertThat(((TypedDataSchemaNode) found).getType(), isA(BinaryTypeDefinition.class));
    found = SchemaInferenceStack.ofDataTreePath(context, root, leafRef2).resolvePathExpression(((LeafrefTypeDefinition) leafRefNode2.getType()).getPathStatement());
    assertThat(((TypedDataSchemaNode) found).getType(), isA(Int16TypeDefinition.class));
}
Also used : SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Int16TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition) LeafrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition) QName(org.opendaylight.yangtools.yang.common.QName) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) BinaryTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 30 with EffectiveModelContext

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

the class MultipleRevImportBug6875Test method testYang10.

@Test
public void testYang10() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-multiple-rev-import-test");
    final SettableSchemaProvider<IRSchemaSource> foo = getSourceProvider("/rfc7950/bug6875/yang1-0/foo.yang");
    final SettableSchemaProvider<IRSchemaSource> bar1 = getSourceProvider("/rfc7950/bug6875/yang1-0/bar@1999-01-01.yang");
    final SettableSchemaProvider<IRSchemaSource> bar2 = getSourceProvider("/rfc7950/bug6875/yang1-0/bar@2017-02-06.yang");
    setAndRegister(sharedSchemaRepository, foo);
    setAndRegister(sharedSchemaRepository, bar1);
    setAndRegister(sharedSchemaRepository, bar2);
    final ListenableFuture<EffectiveModelContext> schemaContextFuture = sharedSchemaRepository.createEffectiveModelContextFactory().createEffectiveModelContext(foo.getId(), bar1.getId(), bar2.getId());
    assertTrue(schemaContextFuture.isDone());
    final ExecutionException ex = assertThrows(ExecutionException.class, schemaContextFuture::get);
    final Throwable cause = ex.getCause();
    assertThat(cause, instanceOf(IllegalArgumentException.class));
    assertThat(cause.getMessage(), startsWith("Module:bar imported twice with different revisions"));
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) ExecutionException(java.util.concurrent.ExecutionException) 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