import static org.junit.Assert.assertTrue;
import java.util.Collection;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
private static final QName Q1 = QName.create(BAR, "ifEntry");
private static final QName Q2 = QName.create(BAZ, "augment-holder");
- @Test
- public void testAugmentParsing() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
- .toURI());
+ private static EffectiveModelContext AUGMENT_IN_AUGMENT;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ AUGMENT_IN_AUGMENT = TestUtils.loadModules("/augment-test/augment-in-augment");
+ }
+ @Test
+ public void testAugmentParsing() {
// foo.yang
- final Module module1 = context.findModules("foo").iterator().next();
+ final Module module1 = AUGMENT_IN_AUGMENT.findModules("foo").iterator().next();
Collection<? extends AugmentationSchemaNode> augmentations = module1.getAugmentations();
assertEquals(1, augmentations.size());
final AugmentationSchemaNode augment = augmentations.iterator().next();
assertFalse(odl.isAugmenting());
// baz.yang
- final Module module3 = context.findModules("baz").iterator().next();
+ final Module module3 = AUGMENT_IN_AUGMENT.findModules("baz").iterator().next();
augmentations = module3.getAugmentations();
assertEquals(3, augmentations.size());
AugmentationSchemaNode augment1 = null;
}
@Test
- public void testAugmentResolving() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
- .toURI());
- final Module module2 = context.findModules("bar").iterator().next();
+ public void testAugmentResolving() {
+ final Module module2 = AUGMENT_IN_AUGMENT.findModules("bar").iterator().next();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
module2.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
}
@Test
- public void testAugmentedChoice() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
- .toURI());
- final Module module2 = context.findModules("bar").iterator().next();
+ public void testAugmentedChoice() {
+ final Module module2 = AUGMENT_IN_AUGMENT.findModules("bar").iterator().next();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
module2.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
@Test
public void testAugmentRpc() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").toURI());
+ final EffectiveModelContext context = TestUtils.loadModules("/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");
@Test
public void testAugmentInUsesResolving() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-uses")
- .toURI());
+ final EffectiveModelContext context = TestUtils.loadModules("/augment-test/augment-in-uses");
assertEquals(1, context.getModules().size());
final Module test = context.getModules().iterator().next();
*/
package org.opendaylight.yangtools.yang.stmt;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
public class AugmentToExtensionTest {
- private SchemaContext context;
-
- @Test(expected = SomeModifiersUnresolvedException.class)
+ @Test
public void testIncorrectPath() throws Exception {
- context = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI());
+ final var ex = assertThrows(SomeModifiersUnresolvedException.class,
+ () -> TestUtils.loadModules("/augment-to-extension-test/incorrect-path"));
+ final var cause = ex.getCause();
+
+ // FIXME: this should not be here
+ assertThat(cause, instanceOf(InferenceException.class));
+ assertThat(cause.getMessage(), startsWith("Yang model processing phase EFFECTIVE_MODEL failed [at "));
+
+ final var firstCause = cause.getCause();
+ assertThat(firstCause, instanceOf(InferenceException.class));
+ assertThat(firstCause.getMessage(), startsWith("Augment target "
+ + "'Descendant{qnames=[(uri:augment-module?revision=2014-10-07)my-extension-name-a, input]}'"
+ + " not found [at "));
}
/*
*/
@Test
public void testCorrectPathIntoUnsupportedTarget() throws Exception {
-
- context = TestUtils.loadModules(getClass().getResource(
- "/augment-to-extension-test/correct-path-into-unsupported-target").toURI());
-
- final Module devicesModule = context.findModules("augment-module").iterator().next();
+ final Module devicesModule =
+ TestUtils.loadModules("/augment-to-extension-test/correct-path-into-unsupported-target")
+ .findModules("augment-module").iterator().next();
final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(
QName.create(devicesModule.getQNameModule(), "my-container"));
for (final UsesNode usesNode : devicesContainer.getUses()) {
@Test
public void testCorrectAugment() throws Exception {
- context = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
-
- final Module devicesModule = context.findModules("augment-module").iterator().next();
+ final Module devicesModule = TestUtils.loadModules("/augment-to-extension-test/correct-augment")
+ .findModules("augment-module").iterator().next();
final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
.create(devicesModule.getQNameModule(), "my-container"));
@Test
public void test() throws Exception {
- final Module bug1412 = TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI())
- .findModules("bug1412").iterator().next();
+ final Module bug1412 = TestUtils.loadModules("/bugs/bug1412").findModules("bug1412").iterator().next();
final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create(
bug1412.getQNameModule(), "node"));
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.util.Collection;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
public class Bug1413Test {
@Test
public void test() throws Exception {
- Collection<? extends ExtensionDefinition> extensions = TestUtils.loadModules(
- getClass().getResource("/bugs/bug1413").toURI())
- .findModules("bug1413").iterator().next().getExtensionSchemaNodes();
+ var extensions = TestUtils.loadModules("/bugs/bug1413").findModules("bug1413").iterator().next()
+ .getExtensionSchemaNodes();
assertEquals(1, extensions.size());
ExtensionDefinition info = extensions.iterator().next();
public class Bug3859Test {
@Test
public void test() throws Exception {
- assertEquals(1, TestUtils.loadModules(getClass().getResource("/bugs/bug3859").toURI())
- .findModules("reference-in-unknown").size());
+ assertEquals(1, TestUtils.loadModules("/bugs/bug3859").findModules("reference-in-unknown").size());
}
}
import java.util.Collection;
import java.util.Iterator;
+import java.util.Set;
import java.util.stream.Collectors;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
public class Bug394Test {
@Test
public void testParseList() throws Exception {
- final SchemaContext context = TestUtils.loadModules(getClass().getResource("/bugs/bug394-retest").toURI());
+ final SchemaContext context = TestUtils.loadModules("/bugs/bug394-retest");
final Module bug394 = context.findModules("bug394").iterator().next();
final Module bug394_ext = context.findModules("bug394-ext").iterator().next();
.declaredSubstatements(UnrecognizedStatement.class);
assertEquals(2, nodes.size());
- final Collection<QName> extensions = bug394_ext.getExtensionSchemaNodes()
- .stream().map(ExtensionDefinition::getQName).collect(Collectors.toUnmodifiableList());
+ final Set<QName> extensions = bug394_ext.getExtensionSchemaNodes().stream()
+ .map(ExtensionDefinition::getQName)
+ .collect(Collectors.toUnmodifiableSet());
assertEquals(3, extensions.size());
final Iterator<? extends UnrecognizedStatement> it = nodes.iterator();
package org.opendaylight.yangtools.yang.stmt;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
public class Bug7865Test {
- private static final String NS = "foo";
-
@Test
public void test() throws Exception {
- final SchemaContext context = TestUtils.parseYangSources("/bugs/bug7865");
- assertNotNull(context);
-
+ final EffectiveModelContext context = TestUtils.loadModules("/bugs/bug7865");
final DataSchemaNode root = context.getDataChildByName(foo("root"));
assertTrue(root instanceof ContainerSchemaNode);
final Collection<? extends UnrecognizedStatement> unknownSchemaNodes = ((ContainerSchemaNode) root)
}
private static QName foo(final String localName) {
- return QName.create(NS, localName);
+ return QName.create("foo", localName);
}
}
@Test
public void test() throws Exception {
- final ModuleEffectiveStatement module = TestUtils.parseYangSources("/bugs/bug7879")
+ final ModuleEffectiveStatement module = TestUtils.loadModules("/bugs/bug7879")
.getModuleStatement(QName.create(NS, "my-model"));
final SchemaTreeEffectiveStatement<?> container = module.findSchemaTreeNode(
*/
package org.opendaylight.yangtools.yang.stmt;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
public class Bug8831Test {
@Test
public void test() throws Exception {
- final SchemaContext context = TestUtils.parseYangSources("/bugs/bug8831/valid");
- assertNotNull(context);
+ assertNotNull(TestUtils.loadModules("/bugs/bug8831/valid"));
}
@Test
- public void invalidModelsTest() throws Exception {
- try {
- TestUtils.parseYangSource("/bugs/bug8831/invalid/inv-model.yang");
- fail("Test should fails due to invalid yang 1.1 model");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(
- e.getCause().getMessage().contains("has default value 'any' marked with an if-feature statement"));
- }
+ public void invalidModelsTest() {
+ final var ex = assertThrows(SomeModifiersUnresolvedException.class,
+ () -> TestUtils.parseYangSource("/bugs/bug8831/invalid/inv-model.yang"));
+ final var cause = ex.getCause();
+ assertThat(cause, instanceOf(SourceException.class));
+ assertThat(cause.getMessage(), containsString("has default value 'any' marked with an if-feature statement"));
}
@Test
- public void invalidModelsTest2() throws Exception {
- try {
- TestUtils.parseYangSource("/bugs/bug8831/invalid/inv-model2.yang");
- fail("Test should fails due to invalid yang 1.1 model");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(
- e.getCause().getMessage().contains("has default value 'any' marked with an if-feature statement"));
- }
+ public void invalidModelsTest2() {
+ final var ex = assertThrows(SomeModifiersUnresolvedException.class,
+ () -> TestUtils.parseYangSource("/bugs/bug8831/invalid/inv-model2.yang"));
+ final var cause = ex.getCause();
+ assertThat(cause, instanceOf(SourceException.class));
+ assertThat(cause.getMessage(), containsString("has default value 'any' marked with an if-feature statement"));
}
}
@Test
public void testAddedByUsesLeafTypeQName() throws Exception {
- final EffectiveModelContext loadModules = TestUtils.parseYangSources("/added-by-uses-leaf-test");
+ final EffectiveModelContext loadModules = TestUtils.loadModules("/added-by-uses-leaf-test");
assertEquals(2, loadModules.getModules().size());
final Module foo = Iterables.getOnlyElement(loadModules.findModules("foo"));
return parseYangSources(files.toArray(new File[files.size()]));
}
- public static EffectiveModelContext parseYangSources(final String yangSourcesDirectoryPath)
- throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
-
- URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath);
- File testSourcesDir = new File(resourceDir.toURI());
-
- return parseYangSources(testSourcesDir.listFiles(
- (dir, name) -> name.endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION)));
- }
-
public static EffectiveModelContext parseYangSource(final String yangSourceFilePath)
throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {