*/
package org.opendaylight.yangtools.yang.parser.impl;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-import java.util.Iterator;
-import java.util.List;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.DeclarationInText;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
public class YT1193Test {
@Test
- public void testDeclarationReference() throws Exception {
- final List<DeclaredStatement<?>> declaredRoots = new DefaultYangParserFactory()
+ void testDeclarationReference() throws Exception {
+ final var declaredRoots = new DefaultYangParserFactory()
.createParser(YangParserConfiguration.builder().retainDeclarationReferences(true).build())
.addSource(YangTextSchemaSource.forResource(getClass(), "/yt1193/foo.yang"))
.addSource(YangTextSchemaSource.forResource(getClass(), "/yt1193/bar.yang"))
.buildDeclaredModel();
assertEquals(3, declaredRoots.size());
- for (DeclaredStatement<?> stmt : declaredRoots) {
+ for (var stmt : declaredRoots) {
switch (stmt.rawArgument()) {
case "foo" -> assertFooReferences(stmt);
case "bar" -> assertBarReferences(stmt);
private static void assertFooReferences(final DeclaredStatement<?> foo) {
assertReference(foo, YangStmtMapping.MODULE, 1, 1);
- final Iterator<? extends DeclaredStatement<?>> it = foo.declaredSubstatements().iterator();
+ final var it = foo.declaredSubstatements().iterator();
assertReference(it.next(), YangStmtMapping.NAMESPACE, 2, 3);
assertReference(it.next(), YangStmtMapping.PREFIX, 3, 3);
assertReference(it.next(), YangStmtMapping.YANG_VERSION, 4, 3);
private static void assertFooContainerReferences(final DeclaredStatement<?> foo) {
assertReference(foo, YangStmtMapping.CONTAINER, 13, 3);
- final Iterator<? extends DeclaredStatement<?>> it = foo.declaredSubstatements().iterator();
+ final var it = foo.declaredSubstatements().iterator();
assertReference(it.next(), YangStmtMapping.ACTION, 14, 5);
assertReference(it.next(), YangStmtMapping.PRESENCE, 22, 5);
assertFalse(it.hasNext());
private static void assertDeprLeafListReferences(final DeclaredStatement<?> depr) {
assertReference(depr, YangStmtMapping.LEAF_LIST, 28, 3);
- final Iterator<? extends DeclaredStatement<?>> it = depr.declaredSubstatements().iterator();
+ final var it = depr.declaredSubstatements().iterator();
assertReference(it.next(), YangStmtMapping.TYPE, 29, 5);
assertReference(it.next(), YangStmtMapping.UNITS, 36, 5);
assertReference(it.next(), YangStmtMapping.STATUS, 37, 5);
private static void assertObsoTypedefReferences(final DeclaredStatement<?> obso) {
assertReference(obso, YangStmtMapping.TYPEDEF, 40, 3);
- final Iterator<? extends DeclaredStatement<?>> it = obso.declaredSubstatements().iterator();
+ final var it = obso.declaredSubstatements().iterator();
assertReference(it.next(), YangStmtMapping.TYPE, 41, 5);
assertReference(it.next(), YangStmtMapping.STATUS, 44, 5);
assertFalse(it.hasNext());
private static void assertBarReferences(final DeclaredStatement<?> bar) {
assertReference(bar, YangStmtMapping.MODULE, 1, 1);
- final Iterator<? extends DeclaredStatement<?>> it = bar.declaredSubstatements().iterator();
+ final var it = bar.declaredSubstatements().iterator();
assertReference(it.next(), YangStmtMapping.NAMESPACE, 2, 3);
assertReference(it.next(), YangStmtMapping.PREFIX, 3, 3);
assertReference(it.next(), YangStmtMapping.YANG_VERSION, 4, 3);
private static void assertBazReferences(final DeclaredStatement<?> baz) {
assertReference(baz, YangStmtMapping.SUBMODULE, 1, 1);
- final Iterator<? extends DeclaredStatement<?>> it = baz.declaredSubstatements().iterator();
+ final var it = baz.declaredSubstatements().iterator();
assertReference(it.next(), YangStmtMapping.YANG_VERSION, 2, 3);
assertReference(it.next(), YangStmtMapping.BELONGS_TO, 4, 3);
assertReference(it.next(), YangStmtMapping.EXTENSION, 8, 3);
final int column) {
assertEquals(def, foo.statementDefinition());
- final DeclarationReference ref = foo.declarationReference().orElseThrow();
- assertThat(ref, instanceOf(DeclarationInText.class));
- final DeclarationInText inText = (DeclarationInText) ref;
-
+ final var inText = assertInstanceOf(DeclarationInText.class, foo.declarationReference().orElseThrow());
assertEquals(line, inText.startLine());
assertEquals(column, inText.startColumn());
}
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.SetMultimap;
import com.google.common.util.concurrent.Futures;
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
public class DependencyResolverTest {
@Test
public void testModulesWithoutRevisionAndImport() throws Exception {
- final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
+ final var map = new HashMap<SourceIdentifier, YangModelDependencyInfo>();
addToMap(map, "/no-revision/imported.yang");
addToMap(map, "/no-revision/imported@2012-12-12.yang");
addToMap(map, "/no-revision/top@2012-10-10.yang");
- final DependencyResolver resolved = RevisionDependencyResolver.create(map);
-
+ final var resolved = RevisionDependencyResolver.create(map);
assertEquals(0, resolved.getUnresolvedSources().size());
assertEquals(0, resolved.getUnsatisfiedImports().size());
}
@Test
public void testSubmoduleNoModule() throws Exception {
- final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
+ final var map = new HashMap<SourceIdentifier, YangModelDependencyInfo>();
// Subfoo does not have parent in reactor
addToMap(map, "/model/subfoo.yang");
addToMap(map, "/model/bar.yang");
addToMap(map, "/model/baz.yang");
- final DependencyResolver resolved = RevisionDependencyResolver.create(map);
-
+ final var resolved = RevisionDependencyResolver.create(map);
assertEquals(2, resolved.getResolvedSources().size());
assertEquals(1, resolved.getUnresolvedSources().size());
assertEquals(0, resolved.getUnsatisfiedImports().size());
@Test
public void testSubmodule() throws Exception {
- final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
+ final var map = new HashMap<SourceIdentifier, YangModelDependencyInfo>();
addToMap(map, "/model/subfoo.yang");
addToMap(map, "/model/foo.yang");
addToMap(map, "/model/bar.yang");
addToMap(map, "/model/baz.yang");
- final DependencyResolver resolved = RevisionDependencyResolver.create(map);
+ final var resolved = RevisionDependencyResolver.create(map);
assertEquals(0, resolved.getUnresolvedSources().size());
assertEquals(0, resolved.getUnsatisfiedImports().size());
assertEquals(4, resolved.getResolvedSources().size());
}
- private static void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map,
- final String yangFileName) throws Exception {
+ private static void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map, final String yangFileName)
+ throws Exception {
final var info = ModuleDependencyInfo.forYangText(YangTextSchemaSource.forResource(DependencyResolverTest.class,
yangFileName));
map.put(new SourceIdentifier(info.getName(), info.getFormattedRevision()), info);
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
@Test
public void testYang11() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
- "shared-schema-repo-multiple-rev-import-test");
-
- final SettableSchemaProvider<YangIRSchemaSource> foo = getSourceProvider(
- "/rfc7950/bug6875/yang1-1/foo.yang");
- final SettableSchemaProvider<YangIRSchemaSource> bar1 = getSourceProvider(
- "/rfc7950/bug6875/yang1-1/bar@1999-01-01.yang");
- final SettableSchemaProvider<YangIRSchemaSource> bar2 = getSourceProvider(
- "/rfc7950/bug6875/yang1-1/bar@2017-02-06.yang");
- final SettableSchemaProvider<YangIRSchemaSource> bar3 = getSourceProvider(
- "/rfc7950/bug6875/yang1-1/bar@1970-01-01.yang");
+ final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-multiple-rev-import-test");
+
+ final var foo = getSourceProvider("/rfc7950/bug6875/yang1-1/foo.yang");
+ final var bar1 = getSourceProvider("/rfc7950/bug6875/yang1-1/bar@1999-01-01.yang");
+ final var bar2 = getSourceProvider("/rfc7950/bug6875/yang1-1/bar@2017-02-06.yang");
+ final var bar3 = getSourceProvider("/rfc7950/bug6875/yang1-1/bar@1970-01-01.yang");
setAndRegister(sharedSchemaRepository, foo);
setAndRegister(sharedSchemaRepository, bar1);
setAndRegister(sharedSchemaRepository, bar2);
setAndRegister(sharedSchemaRepository, bar3);
- final ListenableFuture<EffectiveModelContext> schemaContextFuture =
- sharedSchemaRepository.createEffectiveModelContextFactory().createEffectiveModelContext(
- foo.getId(), bar1.getId(), bar2.getId(), bar3.getId());
+ final var schemaContextFuture = sharedSchemaRepository.createEffectiveModelContextFactory()
+ .createEffectiveModelContext(foo.getId(), bar1.getId(), bar2.getId(), bar3.getId());
assertTrue(schemaContextFuture.isDone());
- final SchemaContext context = schemaContextFuture.get();
+ final var context = schemaContextFuture.get();
assertEquals(context.getModules().size(), 4);
- assertThat(context.findDataTreeChild(foo("root"), foo("my-container-1")).orElse(null),
- instanceOf(ContainerSchemaNode.class));
- assertThat(context.findDataTreeChild(foo("root"), foo("my-container-2")).orElse(null),
- instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class,
+ context.findDataTreeChild(foo("root"), foo("my-container-1")).orElse(null));
+ assertInstanceOf(ContainerSchemaNode.class,
+ context.findDataTreeChild(foo("root"), foo("my-container-2")).orElse(null));
- assertThat(context.findDataTreeChild(bar3("root"), foo("my-container-1")).orElse(null),
- instanceOf(ContainerSchemaNode.class));
- assertThat(context.findDataTreeChild(bar3("root"), foo("my-container-2")).orElse(null),
- instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class,
+ context.findDataTreeChild(bar3("root"), foo("my-container-1")).orElse(null));
+ assertInstanceOf(ContainerSchemaNode.class,
+ context.findDataTreeChild(bar3("root"), foo("my-container-2")).orElse(null));
assertEquals(Optional.empty(), context.findDataTreeChild(bar2("root"), foo("my-container-1")));
assertEquals(Optional.empty(), context.findDataTreeChild(bar2("root"), foo("my-container-2")));
@Test
public void testYang10() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
- "shared-schema-repo-multiple-rev-import-test");
+ final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-multiple-rev-import-test");
- final SettableSchemaProvider<YangIRSchemaSource> foo = getSourceProvider(
- "/rfc7950/bug6875/yang1-0/foo.yang");
- final SettableSchemaProvider<YangIRSchemaSource> bar1 = getSourceProvider(
- "/rfc7950/bug6875/yang1-0/bar@1999-01-01.yang");
- final SettableSchemaProvider<YangIRSchemaSource> bar2 = getSourceProvider(
- "/rfc7950/bug6875/yang1-0/bar@2017-02-06.yang");
+ final var foo = getSourceProvider("/rfc7950/bug6875/yang1-0/foo.yang");
+ final var bar1 = getSourceProvider("/rfc7950/bug6875/yang1-0/bar@1999-01-01.yang");
+ final var 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());
+ final var 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));
+ final var ex = assertThrows(ExecutionException.class, schemaContextFuture::get);
+ final var cause = assertInstanceOf(IllegalArgumentException.class, ex.getCause());
assertThat(cause.getMessage(), startsWith("Module:bar imported twice with different revisions"));
}
private static SettableSchemaProvider<YangIRSchemaSource> getSourceProvider(final String resourceName)
throws Exception {
- final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
- return SettableSchemaProvider.createImmediate(TextToIRTransformer.transformText(yangSource),
+ return SettableSchemaProvider.createImmediate(
+ TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
YangIRSchemaSource.class);
}
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.google.common.util.concurrent.ListenableFuture;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
public class OpenconfigVerSharedSchemaRepositoryTest {
@Test
public void testSharedSchemaRepository() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-test");
+ final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-test");
- final SettableSchemaProvider<YangIRSchemaSource> bar = getImmediateYangSourceProviderFromResource(
+ final var bar = getImmediateYangSourceProviderFromResource(
"/openconfig-version/shared-schema-repository/bar@2016-01-01.yang");
bar.register(sharedSchemaRepository);
bar.setResult();
- final SettableSchemaProvider<YangIRSchemaSource> foo = getImmediateYangSourceProviderFromResource(
+ final var foo = getImmediateYangSourceProviderFromResource(
"/openconfig-version/shared-schema-repository/foo.yang");
foo.register(sharedSchemaRepository);
foo.setResult();
- final SettableSchemaProvider<YangIRSchemaSource> semVer = getImmediateYangSourceProviderFromResource(
+ final var semVer = getImmediateYangSourceProviderFromResource(
"/openconfig-version/shared-schema-repository/openconfig-extensions.yang");
semVer.register(sharedSchemaRepository);
semVer.setResult();
- final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
- final ListenableFuture<EffectiveModelContext> inetAndTopologySchemaContextFuture =
+ final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
+ final var inetAndTopologySchemaContextFuture =
fact.createEffectiveModelContext(bar.getId(), foo.getId(), semVer.getId());
assertTrue(inetAndTopologySchemaContextFuture.isDone());
assertSchemaContext(inetAndTopologySchemaContextFuture.get(), 3);
- final ListenableFuture<EffectiveModelContext> barSchemaContextFuture =
- fact.createEffectiveModelContext(bar.getId(), semVer.getId());
+ final var barSchemaContextFuture = fact.createEffectiveModelContext(bar.getId(), semVer.getId());
assertTrue(barSchemaContextFuture.isDone());
assertSchemaContext(barSchemaContextFuture.get(), 2);
}
- private static void assertSchemaContext(final SchemaContext schemaContext, final int moduleSize) {
+ private static void assertSchemaContext(final EffectiveModelContext schemaContext, final int moduleSize) {
assertNotNull(schemaContext);
assertEquals(moduleSize, schemaContext.getModules().size());
}
static SettableSchemaProvider<YangIRSchemaSource> getImmediateYangSourceProviderFromResource(
final String resourceName) throws Exception {
- final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
- return SettableSchemaProvider.createImmediate(TextToIRTransformer.transformText(yangSource),
+ return SettableSchemaProvider.createImmediate(
+ TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
YangIRSchemaSource.class);
}
}
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSetMultimap;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
@Test
public void shouldFailOnAttemptToDeviateTheSameModule2() {
- final var cause = Throwables.getRootCause(assertExecutionException(null, BAR_INVALID, BAZ_INVALID));
-
- assertThat(cause, instanceOf(InferenceException.class));
+ final var cause = assertInstanceOf(InferenceException.class,
+ Throwables.getRootCause(assertExecutionException(null, BAR_INVALID, BAZ_INVALID)));
assertThat(cause.getMessage(),
startsWith("Deviation must not target the same module as the one it is defined in"));
}
package org.opendaylight.yangtools.yang.parser.repo;
import static java.util.Objects.requireNonNull;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.ExecutionException;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class SharedEffectiveModelContextFactoryTest {
-
private final SharedSchemaRepository repository = new SharedSchemaRepository("test");
-
private final SchemaContextFactoryConfiguration config = SchemaContextFactoryConfiguration.getDefault();
+
private SourceIdentifier s1;
private SourceIdentifier s2;
- @Before
+ @BeforeEach
public void setUp() {
- final YangTextSchemaSource source1 = YangTextSchemaSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
- final YangTextSchemaSource source2 = YangTextSchemaSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
+ final var source1 = YangTextSchemaSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
+ final var source2 = YangTextSchemaSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
s1 = new SourceIdentifier("ietf-inet-types", "2010-09-24");
s2 = new SourceIdentifier("iana-timezones", "2012-07-09");
- final TextToIRTransformer transformer = TextToIRTransformer.create(repository, repository);
+ final var transformer = TextToIRTransformer.create(repository, repository);
repository.registerSchemaSourceListener(transformer);
repository.registerSchemaSource(sourceIdentifier -> immediateFluentFuture(source1),
}
@Test
- public void testCreateSchemaContextWithDuplicateRequiredSources() throws InterruptedException, ExecutionException {
- final SharedEffectiveModelContextFactory sharedSchemaContextFactory =
- new SharedEffectiveModelContextFactory(repository, config);
- final ListenableFuture<EffectiveModelContext> schemaContext =
- sharedSchemaContextFactory.createEffectiveModelContext(s1, s1, s2);
+ public void testCreateSchemaContextWithDuplicateRequiredSources() throws Exception {
+ final var sharedSchemaContextFactory = new SharedEffectiveModelContextFactory(repository, config);
+ final var schemaContext = sharedSchemaContextFactory.createEffectiveModelContext(s1, s1, s2);
assertNotNull(schemaContext.get());
}
@Test
public void testSourceRegisteredWithDifferentSI() throws Exception {
- final YangTextSchemaSource source1 = YangTextSchemaSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
- final YangTextSchemaSource source2 = YangTextSchemaSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
+ final var source1 = YangTextSchemaSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
+ final var source2 = YangTextSchemaSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
s1 = source1.getIdentifier();
s2 = source2.getIdentifier();
- final SettableSchemaProvider<YangIRSchemaSource> provider =
- SharedSchemaRepositoryTest.getImmediateYangSourceProviderFromResource(
- "/no-revision/imported@2012-12-12.yang");
+ final var provider = SharedSchemaRepositoryTest.getImmediateYangSourceProviderFromResource(
+ "/no-revision/imported@2012-12-12.yang");
provider.setResult();
provider.register(repository);
// Register the same provider under source id without revision
- final SourceIdentifier sIdWithoutRevision = new SourceIdentifier(provider.getId().name());
- repository.registerSchemaSource(provider, PotentialSchemaSource.create(
- sIdWithoutRevision, YangIRSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
-
- final SharedEffectiveModelContextFactory sharedSchemaContextFactory =
- new SharedEffectiveModelContextFactory(repository, config);
- final ListenableFuture<EffectiveModelContext> schemaContext =
- sharedSchemaContextFactory.createEffectiveModelContext(sIdWithoutRevision, provider.getId());
+ final var sIdWithoutRevision = new SourceIdentifier(provider.getId().name());
+ repository.registerSchemaSource(provider, PotentialSchemaSource.create(sIdWithoutRevision,
+ YangIRSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
+
+ final var sharedSchemaContextFactory = new SharedEffectiveModelContextFactory(repository, config);
+ final var schemaContext = sharedSchemaContextFactory.createEffectiveModelContext(
+ sIdWithoutRevision, provider.getId());
assertNotNull(schemaContext.get());
}
YangTextSchemaSource.forResource("/ietf/network-topology@2013-10-21.yang")),
PotentialSchemaSource.create(s3, YangTextSchemaSource.class, 1));
- final SharedEffectiveModelContextFactory sharedSchemaContextFactory =
- new SharedEffectiveModelContextFactory(repository, config);
+ final var sharedSchemaContextFactory = new SharedEffectiveModelContextFactory(repository, config);
- ListenableFuture<EffectiveModelContext> schemaContext =
- sharedSchemaContextFactory.createEffectiveModelContext(s1, s3);
+ var schemaContext = sharedSchemaContextFactory.createEffectiveModelContext(s1, s3);
- final ExecutionException exception = assertThrows(ExecutionException.class, schemaContext::get);
- assertThat(exception.getCause(), instanceOf(MissingSchemaSourceException.class));
+ final var exception = assertThrows(ExecutionException.class, schemaContext::get);
+ assertInstanceOf(MissingSchemaSourceException.class, exception.getCause());
// check if future is invalidated and resolution of source is retried after failure
schemaContext = sharedSchemaContextFactory.createEffectiveModelContext(s1, s3);
* to simulate transient failures of source retrieval.
*/
private static final class TransientFailureProvider implements SchemaSourceProvider<YangTextSchemaSource> {
-
private final YangTextSchemaSource schemaSource;
+
private boolean shouldFail = true;
private TransientFailureProvider(final YangTextSchemaSource schemaSource) {
}
@Override
- public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
+ public ListenableFuture<YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
if (shouldFail) {
shouldFail = false;
return immediateFailedFluentFuture(new Exception("Transient test failure."));
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.ExecutionException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
+import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
public class SharedSchemaRepositoryTest {
@Test
public void testSourceWithAndWithoutRevision() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
+ final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
- final SourceIdentifier idNoRevision = loadAndRegisterSource(sharedSchemaRepository,
- "/no-revision/imported.yang");
- final SourceIdentifier id2 = loadAndRegisterSource(sharedSchemaRepository,
- "/no-revision/imported@2012-12-12.yang");
+ final var idNoRevision = loadAndRegisterSource(sharedSchemaRepository, "/no-revision/imported.yang");
+ final var id2 = loadAndRegisterSource(sharedSchemaRepository, "/no-revision/imported@2012-12-12.yang");
- ListenableFuture<YangIRSchemaSource> source = sharedSchemaRepository.getSchemaSource(idNoRevision,
- YangIRSchemaSource.class);
+ var source = sharedSchemaRepository.getSchemaSource(idNoRevision, YangIRSchemaSource.class);
assertEquals(idNoRevision, source.get().getIdentifier());
source = sharedSchemaRepository.getSchemaSource(id2, YangIRSchemaSource.class);
assertEquals(id2, source.get().getIdentifier());
private static SourceIdentifier loadAndRegisterSource(final SharedSchemaRepository sharedSchemaRepository,
final String resourceName) throws Exception {
- final SettableSchemaProvider<YangIRSchemaSource> sourceProvider = getImmediateYangSourceProviderFromResource(
- resourceName);
+ final var sourceProvider = getImmediateYangSourceProviderFromResource(resourceName);
sourceProvider.setResult();
- final SourceIdentifier idNoRevision = sourceProvider.getId();
+ final var idNoRevision = sourceProvider.getId();
sourceProvider.register(sharedSchemaRepository);
return idNoRevision;
}
@Test
public void testSimpleSchemaContext() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
+ final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
- final SettableSchemaProvider<YangIRSchemaSource> remoteInetTypesYang =
+ final var remoteInetTypesYang =
getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
remoteInetTypesYang.register(sharedSchemaRepository);
- final ListenableFuture<YangIRSchemaSource> registeredSourceFuture = sharedSchemaRepository.getSchemaSource(
+ final var registeredSourceFuture = sharedSchemaRepository.getSchemaSource(
remoteInetTypesYang.getId(), YangIRSchemaSource.class);
assertFalse(registeredSourceFuture.isDone());
- final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
- final ListenableFuture<EffectiveModelContext> schemaContextFuture =
- fact.createEffectiveModelContext(remoteInetTypesYang.getId());
-
+ final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
+ final var schemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId());
assertFalse(schemaContextFuture.isDone());
// Make source appear
// Verify schema created successfully
assertTrue(schemaContextFuture.isDone());
- final SchemaContext firstSchemaContext = schemaContextFuture.get();
+ final var firstSchemaContext = schemaContextFuture.get();
assertSchemaContext(firstSchemaContext, 1);
// Try same schema second time
- final ListenableFuture<EffectiveModelContext> secondSchemaFuture =
- sharedSchemaRepository.createEffectiveModelContextFactory().createEffectiveModelContext(
- remoteInetTypesYang.getId());
+ final var secondSchemaFuture = sharedSchemaRepository.createEffectiveModelContextFactory()
+ .createEffectiveModelContext(remoteInetTypesYang.getId());
// Verify second schema created successfully immediately
assertTrue(secondSchemaFuture.isDone());
@Test
public void testTwoSchemaContextsSharingSource() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
+ final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
- final SettableSchemaProvider<YangIRSchemaSource> remoteInetTypesYang =
+ final var remoteInetTypesYang =
getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
remoteInetTypesYang.register(sharedSchemaRepository);
remoteInetTypesYang.setResult();
- final SettableSchemaProvider<YangIRSchemaSource> remoteTopologyYang =
+ final var remoteTopologyYang =
getImmediateYangSourceProviderFromResource("/ietf/network-topology@2013-10-21.yang");
remoteTopologyYang.register(sharedSchemaRepository);
remoteTopologyYang.setResult();
- final SettableSchemaProvider<YangIRSchemaSource> remoteModuleNoRevYang =
- getImmediateYangSourceProviderFromResource("/no-revision/module-without-revision.yang");
+ final var remoteModuleNoRevYang =
+ getImmediateYangSourceProviderFromResource("/no-revision/module-without-revision.yang");
remoteModuleNoRevYang.register(sharedSchemaRepository);
- final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
- final ListenableFuture<EffectiveModelContext> inetAndTopologySchemaContextFuture = fact
- .createEffectiveModelContext(remoteInetTypesYang.getId(), remoteTopologyYang.getId());
+ final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
+ final var inetAndTopologySchemaContextFuture = fact.createEffectiveModelContext(
+ remoteInetTypesYang.getId(), remoteTopologyYang.getId());
assertTrue(inetAndTopologySchemaContextFuture.isDone());
assertSchemaContext(inetAndTopologySchemaContextFuture.get(), 2);
- final ListenableFuture<EffectiveModelContext> inetAndNoRevSchemaContextFuture =
- fact.createEffectiveModelContext(remoteInetTypesYang.getId(), remoteModuleNoRevYang.getId());
+ final var inetAndNoRevSchemaContextFuture = fact.createEffectiveModelContext(
+ remoteInetTypesYang.getId(), remoteModuleNoRevYang.getId());
assertFalse(inetAndNoRevSchemaContextFuture.isDone());
remoteModuleNoRevYang.setResult();
@Test
public void testFailedSchemaContext() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
+ final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
- final SettableSchemaProvider<YangIRSchemaSource> remoteInetTypesYang =
+ final var remoteInetTypesYang =
getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
remoteInetTypesYang.register(sharedSchemaRepository);
- final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
+ final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
// Make source appear
- final Throwable ex = new IllegalStateException("failed schema");
- remoteInetTypesYang.setException(ex);
-
- final ListenableFuture<EffectiveModelContext> schemaContextFuture = fact.createEffectiveModelContext(
- remoteInetTypesYang.getId());
-
- try {
- schemaContextFuture.get();
- } catch (final ExecutionException e) {
- assertNotNull(e.getCause());
- assertNotNull(e.getCause().getCause());
- assertSame(ex, e.getCause().getCause());
- return;
- }
-
- fail("Schema context creation should have failed");
+ final var ise = new IllegalStateException("failed schema");
+ remoteInetTypesYang.setException(ise);
+
+ final var schemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId());
+ final var ex = assertThrows(ExecutionException.class, schemaContextFuture::get);
+ final var cause = assertInstanceOf(MissingSchemaSourceException.class, ex.getCause());
+ assertSame(ise, cause.getCause());
}
@Test
public void testDifferentCosts() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
+ final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
- final SettableSchemaProvider<YangIRSchemaSource> immediateInetTypesYang = spy(
+ final var immediateInetTypesYang = spy(
getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
immediateInetTypesYang.register(sharedSchemaRepository);
immediateInetTypesYang.setResult();
- final SettableSchemaProvider<YangIRSchemaSource> remoteInetTypesYang = spy(
+ final var 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());
+ final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
+ final var schemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId());
assertSchemaContext(schemaContextFuture.get(), 1);
- final SourceIdentifier id = immediateInetTypesYang.getId();
+ final var id = immediateInetTypesYang.getId();
verify(remoteInetTypesYang, times(0)).getSource(id);
verify(immediateInetTypesYang).getSource(id);
}
- private static void assertSchemaContext(final SchemaContext schemaContext, final int moduleSize) {
+ private static void assertSchemaContext(final EffectiveModelContext schemaContext, final int moduleSize) {
assertNotNull(schemaContext);
assertEquals(moduleSize, schemaContext.getModules().size());
}
static SettableSchemaProvider<YangIRSchemaSource> getRemoteYangSourceProviderFromResource(final String resourceName)
throws Exception {
- final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
- return SettableSchemaProvider.createRemote(TextToIRTransformer.transformText(yangSource),
+ return SettableSchemaProvider.createRemote(
+ TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
YangIRSchemaSource.class);
}
static SettableSchemaProvider<YangIRSchemaSource> getImmediateYangSourceProviderFromResource(
final String resourceName) throws Exception {
- final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
- return SettableSchemaProvider.createImmediate(TextToIRTransformer.transformText(yangSource),
+ return SettableSchemaProvider.createImmediate(
+ TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
YangIRSchemaSource.class);
}
}
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.google.common.util.concurrent.ListenableFuture;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
public class SharedSchemaRepositoryWithFeaturesTest {
-
@Test
public void testSharedSchemaRepositoryWithSomeFeaturesSupported() throws Exception {
- final FeatureSet supportedFeatures = FeatureSet.of(QName.create("foobar-namespace", "test-feature-1"));
+ final var supportedFeatures = FeatureSet.of(QName.create("foobar-namespace", "test-feature-1"));
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
- "shared-schema-repo-with-features-test");
+ final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-features-test");
- final SettableSchemaProvider<YangIRSchemaSource> foobar = getImmediateYangSourceProviderFromResource(
+ final var foobar = getImmediateYangSourceProviderFromResource(
"/if-feature-resolution-test/shared-schema-repository/foobar.yang");
foobar.register(sharedSchemaRepository);
foobar.setResult();
- final ListenableFuture<EffectiveModelContext> testSchemaContextFuture =
- sharedSchemaRepository.createEffectiveModelContextFactory(
+ final var testSchemaContextFuture = sharedSchemaRepository.createEffectiveModelContextFactory(
SchemaContextFactoryConfiguration.builder().setSupportedFeatures(supportedFeatures).build())
.createEffectiveModelContext(foobar.getId());
assertTrue(testSchemaContextFuture.isDone());
assertSchemaContext(testSchemaContextFuture.get(), 1);
- final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
+ final var module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
assertNotNull(module);
assertEquals(2, 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 var testContainerA = assertInstanceOf(ContainerSchemaNode.class,
+ module.dataChildByName(QName.create(module.getQNameModule(), "test-container-a")));
+ assertInstanceOf(LeafSchemaNode.class,
+ testContainerA.dataChildByName(QName.create(module.getQNameModule(), "test-leaf-a")));
- final ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.dataChildByName(
- QName.create(module.getQNameModule(), "test-container-b"));
- assertNull(testContainerB);
+ assertNull(module.dataChildByName(QName.create(module.getQNameModule(), "test-container-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"));
+ final var testContainerC = assertInstanceOf(ContainerSchemaNode.class,
+ module.dataChildByName(QName.create(module.getQNameModule(), "test-container-c")));
+ assertInstanceOf(LeafSchemaNode.class,
+ testContainerC.dataChildByName(QName.create(module.getQNameModule(), "test-leaf-c")));
}
@Test
public void testSharedSchemaRepositoryWithAllFeaturesSupported() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
- "shared-schema-repo-with-features-test");
+ final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-features-test");
- final SettableSchemaProvider<YangIRSchemaSource> foobar = getImmediateYangSourceProviderFromResource(
+ final var 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());
+ final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
+ final var testSchemaContextFuture = fact.createEffectiveModelContext(foobar.getId());
assertTrue(testSchemaContextFuture.isDone());
assertSchemaContext(testSchemaContextFuture.get(), 1);
- final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
+ final var 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 var testContainerA = assertInstanceOf(ContainerSchemaNode.class,
+ module.dataChildByName(QName.create(module.getQNameModule(), "test-container-a")));
+ assertInstanceOf(LeafSchemaNode.class,
+ testContainerA.dataChildByName(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 var testContainerB = assertInstanceOf(ContainerSchemaNode.class,
+ module.dataChildByName(QName.create(module.getQNameModule(), "test-container-b")));
+ assertInstanceOf(LeafSchemaNode.class,
+ testContainerB.dataChildByName(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"));
+ final var testContainerC = assertInstanceOf(ContainerSchemaNode.class,
+ module.dataChildByName(QName.create(module.getQNameModule(), "test-container-c")));
+ assertInstanceOf(LeafSchemaNode.class,
+ testContainerC.dataChildByName(QName.create(module.getQNameModule(), "test-leaf-c")));
}
@Test
public void testSharedSchemaRepositoryWithNoFeaturesSupported() throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
- "shared-schema-repo-with-features-test");
+ final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-features-test");
- final SettableSchemaProvider<YangIRSchemaSource> foobar = getImmediateYangSourceProviderFromResource(
+ final var 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(FeatureSet.of()).build())
- .createEffectiveModelContext(foobar.getId());
+ final var testSchemaContextFuture = sharedSchemaRepository.createEffectiveModelContextFactory(
+ SchemaContextFactoryConfiguration.builder().setSupportedFeatures(FeatureSet.of()).build())
+ .createEffectiveModelContext(foobar.getId());
assertTrue(testSchemaContextFuture.isDone());
assertSchemaContext(testSchemaContextFuture.get(), 1);
- final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
+ final var 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"));
+ final var testContainerC = assertInstanceOf(ContainerSchemaNode.class,
+ module.dataChildByName(QName.create(module.getQNameModule(), "test-container-c")));
+ assertInstanceOf(LeafSchemaNode.class,
+ testContainerC.dataChildByName(QName.create(module.getQNameModule(), "test-leaf-c")));
}
private static SettableSchemaProvider<YangIRSchemaSource> getImmediateYangSourceProviderFromResource(
final String resourceName) throws Exception {
- final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
- return SettableSchemaProvider.createImmediate(TextToIRTransformer.transformText(yangSource),
+ return SettableSchemaProvider.createImmediate(
+ TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
YangIRSchemaSource.class);
}
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
public class YT1428Test extends AbstractSchemaRepositoryTest {
@Test
public void testDeviateSourceReported() {
- final var cause = assertExecutionException(null, "/yt1428/orig.yang", "/yt1428/deviate.yang").getCause();
- assertThat(cause, instanceOf(SchemaResolutionException.class));
- assertEquals(new SourceIdentifier("deviate"), ((SchemaResolutionException) cause).getFailedSource());
+ final var ex = assertExecutionException(null, "/yt1428/orig.yang", "/yt1428/deviate.yang");
+ assertEquals(new SourceIdentifier("deviate"),
+ assertInstanceOf(SchemaResolutionException.class, ex.getCause()).getFailedSource());
}
}
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import java.net.URL;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
-import org.junit.Test;
-import org.opendaylight.yangtools.concepts.Registration;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
public class YangTextSchemaContextResolverTest {
-
@Test
public void testYangTextSchemaContextResolver() throws Exception {
- final YangTextSchemaContextResolver yangTextSchemaContextResolver =
- YangTextSchemaContextResolver.create("test-bundle");
+ final var yangTextSchemaContextResolver = YangTextSchemaContextResolver.create("test-bundle");
assertNotNull(yangTextSchemaContextResolver);
- final URL yangFile1 = getClass().getResource("/yang-text-schema-context-resolver-test/foo.yang");
+ final var yangFile1 = getClass().getResource("/yang-text-schema-context-resolver-test/foo.yang");
assertNotNull(yangFile1);
- final URL yangFile2 = getClass().getResource("/yang-text-schema-context-resolver-test/bar.yang");
+ final var yangFile2 = getClass().getResource("/yang-text-schema-context-resolver-test/bar.yang");
assertNotNull(yangFile2);
- final URL yangFile3 = getClass().getResource("/yang-text-schema-context-resolver-test/baz.yang");
+ final var yangFile3 = getClass().getResource("/yang-text-schema-context-resolver-test/baz.yang");
assertNotNull(yangFile2);
- final YangTextSchemaSourceRegistration registration1 =
- yangTextSchemaContextResolver.registerSource(yangFile1);
+ final var registration1 = yangTextSchemaContextResolver.registerSource(yangFile1);
assertNotNull(registration1);
- final YangTextSchemaSourceRegistration registration2 =
- yangTextSchemaContextResolver.registerSource(yangFile2);
+ final var registration2 = yangTextSchemaContextResolver.registerSource(yangFile2);
assertNotNull(registration2);
- final YangTextSchemaSourceRegistration registration3 =
- yangTextSchemaContextResolver.registerSource(yangFile3);
+ final var registration3 = yangTextSchemaContextResolver.registerSource(yangFile3);
assertNotNull(registration3);
assertEquals(3, yangTextSchemaContextResolver.getAvailableSources().size());
- final SourceIdentifier fooModuleId = new SourceIdentifier("foo", "2016-09-26");
- final ListenableFuture<YangTextSchemaSource> foo = yangTextSchemaContextResolver.getSource(fooModuleId);
+ final var fooModuleId = new SourceIdentifier("foo", "2016-09-26");
+ final var foo = yangTextSchemaContextResolver.getSource(fooModuleId);
assertTrue(foo.isDone());
assertEquals(fooModuleId, foo.get().getIdentifier());
- final SourceIdentifier barModuleId = new SourceIdentifier("bar", "2016-09-26");
- final ListenableFuture<YangTextSchemaSource> bar = yangTextSchemaContextResolver.getSource(barModuleId);
+ final var barModuleId = new SourceIdentifier("bar", "2016-09-26");
+ final var bar = yangTextSchemaContextResolver.getSource(barModuleId);
assertTrue(bar.isDone());
assertEquals(barModuleId, bar.get().getIdentifier());
- final SourceIdentifier bazModuleId = new SourceIdentifier("baz", "2016-09-26");
- final ListenableFuture<YangTextSchemaSource> baz =
- yangTextSchemaContextResolver.getSource(bazModuleId);
+ final var bazModuleId = new SourceIdentifier("baz", "2016-09-26");
+ final var baz = yangTextSchemaContextResolver.getSource(bazModuleId);
assertTrue(baz.isDone());
assertEquals(bazModuleId, baz.get().getIdentifier());
- final SourceIdentifier foobarModuleId = new SourceIdentifier("foobar", "2016-09-26");
- final ListenableFuture<YangTextSchemaSource> foobar = yangTextSchemaContextResolver.getSource(foobarModuleId);
+ final var foobarModuleId = new SourceIdentifier("foobar", "2016-09-26");
+ final var foobar = yangTextSchemaContextResolver.getSource(foobarModuleId);
assertTrue(foobar.isDone());
- final Throwable cause = assertThrows(ExecutionException.class, foobar::get).getCause();
- assertThat(cause, instanceOf(MissingSchemaSourceException.class));
+ final var cause = assertInstanceOf(MissingSchemaSourceException.class,
+ assertThrows(ExecutionException.class, foobar::get).getCause());
assertEquals("URL for SourceIdentifier [foobar@2016-09-26] not registered", cause.getMessage());
var schemaContextOptional = yangTextSchemaContextResolver.getEffectiveModelContext();
@Test
public void testFeatureRegistration() throws Exception {
- final YangTextSchemaContextResolver yangTextSchemaContextResolver =
- YangTextSchemaContextResolver.create("feature-test-bundle");
+ final var yangTextSchemaContextResolver = YangTextSchemaContextResolver.create("feature-test-bundle");
assertNotNull(yangTextSchemaContextResolver);
- final URL yangFile1 = getClass().getResource("/yang-text-schema-context-resolver-test/foo-feature.yang");
+ final var yangFile1 = getClass().getResource("/yang-text-schema-context-resolver-test/foo-feature.yang");
assertNotNull(yangFile1);
- final URL yangFile2 = getClass().getResource("/yang-text-schema-context-resolver-test/aux-feature.yang");
+ final var yangFile2 = getClass().getResource("/yang-text-schema-context-resolver-test/aux-feature.yang");
assertNotNull(yangFile2);
- final YangTextSchemaSourceRegistration registration1 =
- yangTextSchemaContextResolver.registerSource(yangFile1);
+ final var registration1 = yangTextSchemaContextResolver.registerSource(yangFile1);
assertNotNull(registration1);
- final YangTextSchemaSourceRegistration registration2 =
- yangTextSchemaContextResolver.registerSource(yangFile2);
+ final var registration2 = yangTextSchemaContextResolver.registerSource(yangFile2);
assertNotNull(registration2);
final QName cont = QName.create("foo-feature-namespace", "2016-09-26", "bar-feature-container");
final QName usedFeature = QName.create("foo-feature-namespace", "2016-09-26", "used-feature");
final QName unusedFeature = QName.create("foo-feature-namespace", "2016-09-26", "unused-feature");
- Iterable<QName> pathToConditional = List.of(cont, condLeaf);
- Iterable<QName> pathToUnconditional = List.of(cont, uncondLeaf);
- Iterable<QName> pathToAuxiliary = List.of(auxCont);
+ final var pathToConditional = List.of(cont, condLeaf);
+ final var pathToUnconditional = List.of(cont, uncondLeaf);
+ final var pathToAuxiliary = List.of(auxCont);
- final EffectiveModelContext context1 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
+ final var context1 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
assertTrue(isModulePresent(context1, condLeaf.getModule(), pathToConditional));
assertTrue(isModulePresent(context1, uncondLeaf.getModule(), pathToUnconditional));
assertTrue(isModulePresent(context1, auxCont.getModule(), pathToAuxiliary));
- final Registration featRegistration1 = yangTextSchemaContextResolver.registerSupportedFeatures(
+ final var featRegistration1 = yangTextSchemaContextResolver.registerSupportedFeatures(
unusedFeature.getModule(), Set.of(unusedFeature.getLocalName()));
- final EffectiveModelContext context2 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
+ final var context2 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
assertFalse(isModulePresent(context2, condLeaf.getModule(), pathToConditional));
assertTrue(isModulePresent(context2, uncondLeaf.getModule(), pathToUnconditional));
assertTrue(isModulePresent(context2, auxCont.getModule(), pathToAuxiliary));
- final Registration featRegistration2 = yangTextSchemaContextResolver.registerSupportedFeatures(
+ final var featRegistration2 = yangTextSchemaContextResolver.registerSupportedFeatures(
unusedFeature.getModule(), Set.of(usedFeature.getLocalName()));
- final EffectiveModelContext context3 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
+ final var context3 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
assertTrue(isModulePresent(context3, condLeaf.getModule(), pathToConditional));
- final Registration featRegistration3 = yangTextSchemaContextResolver.registerSupportedFeatures(
+ final var featRegistration3 = yangTextSchemaContextResolver.registerSupportedFeatures(
unusedFeature.getModule(), Set.of(usedFeature.getLocalName(), unusedFeature.getLocalName()));
featRegistration1.close();
featRegistration2.close();
- final EffectiveModelContext context4 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
+ final var context4 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
assertTrue(isModulePresent(context4, condLeaf.getModule(), pathToConditional));
assertTrue(isModulePresent(context4, auxCont.getModule(), pathToAuxiliary));
featRegistration3.close();
- final Registration featRegistration4 = yangTextSchemaContextResolver.registerSupportedFeatures(
+ final var featRegistration4 = yangTextSchemaContextResolver.registerSupportedFeatures(
auxCont.getModule(), Set.of());
- final EffectiveModelContext context5 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
+ final var context5 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
assertTrue(isModulePresent(context5, condLeaf.getModule(), pathToConditional));
assertFalse(isModulePresent(context5, auxCont.getModule(), pathToAuxiliary));
featRegistration4.close();
- final EffectiveModelContext context6 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
+ final var context6 = yangTextSchemaContextResolver.getEffectiveModelContext().orElseThrow();
assertTrue(isModulePresent(context6, auxCont.getModule(), pathToAuxiliary));
}
private static boolean isModulePresent(final EffectiveModelContext context, final QNameModule qnameModule,
- final Iterable<QName> path) {
+ final List<QName> path) {
for (var module : context.getModules()) {
if (module.getQNameModule().equals(qnameModule)) {
return module.findDataTreeChild(path).isPresent();