Search in sources :

Example 1 with IRSchemaSource

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource 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)

Example 2 with IRSchemaSource

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource in project yangtools by opendaylight.

the class SchemaContextFactoryDeviationsTest method createSchemaContext.

private static ListenableFuture<EffectiveModelContext> createSchemaContext(final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations, final String... resources) throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-deviations-test");
    final Collection<SourceIdentifier> requiredSources = new ArrayList<>();
    for (final String resource : resources) {
        final SettableSchemaProvider<IRSchemaSource> yangSource = getImmediateYangSourceProviderFromResource(resource);
        yangSource.register(sharedSchemaRepository);
        yangSource.setResult();
        requiredSources.add(yangSource.getId());
    }
    final SchemaContextFactoryConfiguration config = SchemaContextFactoryConfiguration.builder().setModulesDeviatedByModules(modulesWithSupportedDeviations).build();
    return sharedSchemaRepository.createEffectiveModelContextFactory(config).createEffectiveModelContext(requiredSources);
}
Also used : SchemaContextFactoryConfiguration(org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration) IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) ArrayList(java.util.ArrayList)

Example 3 with IRSchemaSource

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource in project yangtools by opendaylight.

the class SharedSchemaRepositoryWithFeaturesTest method testSharedSchemaRepositoryWithAllFeaturesSupported.

@Test
public void testSharedSchemaRepositoryWithAllFeaturesSupported() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-features-test");
    final SettableSchemaProvider<IRSchemaSource> 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"));
    final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(QName.create(module.getQNameModule(), "test-leaf-a"));
    final ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(), "test-container-b"));
    final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(QName.create(module.getQNameModule(), "test-leaf-b"));
    final ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(), "test-container-c"));
    final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(QName.create(module.getQNameModule(), "test-leaf-c"));
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) 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 4 with IRSchemaSource

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource in project yangtools by opendaylight.

the class SharedSchemaRepositoryWithFeaturesTest method testSharedSchemaRepositoryWithNoFeaturesSupported.

@Test
public void testSharedSchemaRepositoryWithNoFeaturesSupported() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-features-test");
    final SettableSchemaProvider<IRSchemaSource> foobar = getImmediateYangSourceProviderFromResource("/if-feature-resolution-test/shared-schema-repository/foobar.yang");
    foobar.register(sharedSchemaRepository);
    foobar.setResult();
    final ListenableFuture<EffectiveModelContext> testSchemaContextFuture = sharedSchemaRepository.createEffectiveModelContextFactory(SchemaContextFactoryConfiguration.builder().setSupportedFeatures(ImmutableSet.of()).build()).createEffectiveModelContext(foobar.getId());
    assertTrue(testSchemaContextFuture.isDone());
    assertSchemaContext(testSchemaContextFuture.get(), 1);
    final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
    assertNotNull(module);
    assertEquals(1, module.getChildNodes().size());
    final ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(), "test-container-c"));
    final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(QName.create(module.getQNameModule(), "test-leaf-c"));
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) 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 5 with IRSchemaSource

use of org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource in project yangtools by opendaylight.

the class SharedSchemaRepositoryTest method testDifferentCosts.

@Test
public void testDifferentCosts() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
    final SettableSchemaProvider<IRSchemaSource> immediateInetTypesYang = spy(getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
    immediateInetTypesYang.register(sharedSchemaRepository);
    immediateInetTypesYang.setResult();
    final SettableSchemaProvider<IRSchemaSource> remoteInetTypesYang = spy(getRemoteYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
    remoteInetTypesYang.register(sharedSchemaRepository);
    remoteInetTypesYang.setResult();
    final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
    final ListenableFuture<EffectiveModelContext> schemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId());
    assertSchemaContext(schemaContextFuture.get(), 1);
    final SourceIdentifier id = immediateInetTypesYang.getId();
    verify(remoteInetTypesYang, times(0)).getSource(id);
    verify(immediateInetTypesYang).getSource(id);
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)23 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)14 Test (org.junit.Test)13 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)9 EffectiveModelContextFactory (org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory)8 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)5 Objects.requireNonNull (java.util.Objects.requireNonNull)4 NonNull (org.eclipse.jdt.annotation.NonNull)4 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)3 Stopwatch (com.google.common.base.Stopwatch)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 File (java.io.File)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2 ExecutionException (java.util.concurrent.ExecutionException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2