final Collection<? extends DataSchemaNode> augmentChildren = augment.getChildNodes();
assertEquals(4, augmentChildren.size());
for (final DataSchemaNode dsn : augmentChildren) {
- TestUtils.checkIsAugmenting(dsn, false);
+ checkIsAugmenting(dsn, false);
}
final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName(QName.create(
// augment "/br:interfaces/br:ifEntry" {
final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(BAZ,
"augment-holder"));
- TestUtils.checkIsAugmenting(augmentHolder, true);
+ checkIsAugmenting(augmentHolder, true);
assertEquals(Q2, augmentHolder.getQName());
// foo.yang
module2.getQNameModule(), "ifEntry"));
final ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(
BAZ, "augment-holder"));
- TestUtils.checkIsAugmenting(augmentedHolder, true);
+ checkIsAugmenting(augmentedHolder, true);
// foo.yang
// augment "/br:interfaces/br:ifEntry/bz:augment-holder"
final LeafSchemaNode id = (LeafSchemaNode) node.getDataChildByName(QName.create(test.getQNameModule(), "id"));
assertTrue(id.isAugmenting());
}
+
+ /**
+ * Test if node has augmenting flag set to expected value. In case this is DataNodeContainer/ChoiceNode, check its
+ * child nodes/case nodes too.
+ *
+ * @param node node to check
+ * @param expected expected value
+ */
+ private static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) {
+ assertEquals(expected, node.isAugmenting());
+ if (node instanceof DataNodeContainer) {
+ for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
+ checkIsAugmenting(child, expected);
+ }
+ } else if (node instanceof ChoiceSchemaNode) {
+ for (CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
+ checkIsAugmenting(caseNode, expected);
+ }
+ }
+ }
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Collection;
import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-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.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YinStatementStreamSource;
.buildEffective();
}
- public static EffectiveModelContext loadModuleResources(final Class<?> refClass, final String... resourceNames)
- throws IOException, ReactorException, YangSyntaxErrorException {
- final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild();
-
- for (String resourceName : resourceNames) {
- reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(refClass,
- resourceName)));
+ public static EffectiveModelContext parseYangSource(final String... yangSourceFilePath) throws Exception {
+ final var reactor = RFC7950Reactors.defaultReactor().newBuild();
+ for (var resourcePath : yangSourceFilePath) {
+ reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forPath(Path.of(
+ TestUtils.class.getResource(resourcePath).toURI()))));
}
-
return reactor.buildEffective();
}
+ // FIXME: these remain unaudited
+
public static EffectiveModelContext loadYinModules(final URI resourceDirectory)
throws ReactorException, SAXException, IOException {
final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild();
}
return null;
}
-
- /**
- * Test if node has augmenting flag set to expected value. In case this is
- * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too.
- *
- * @param node
- * node to check
- * @param expected
- * expected value
- */
- public static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) {
- assertEquals(expected, node.isAugmenting());
- if (node instanceof DataNodeContainer) {
- for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
- checkIsAugmenting(child, expected);
- }
- } else if (node instanceof ChoiceSchemaNode) {
- for (CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
- checkIsAugmenting(caseNode, expected);
- }
- }
- }
-
- public static EffectiveModelContext parseYangSource(final String... yangSourceFilePath) throws Exception {
- final var reactor = RFC7950Reactors.defaultReactor().newBuild();
- for (var resourcePath : yangSourceFilePath) {
- reactor.addSource(sourceForResource(resourcePath));
- }
- return reactor.buildEffective();
- }
-
- public static YangStatementStreamSource sourceForResource(final String resourceName) throws Exception {
- return YangStatementStreamSource.create(YangTextSchemaSource.forPath(Path.of(
- TestUtils.class.getResource(resourceName).toURI())));
- }
}
@Test
public void testInvalidImport() {
final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile1.yang"));
+ () -> TestUtils.parseYangSource("/negative-scenario/testfile1.yang"));
final Throwable rootCause = Throwables.getRootCause(ex);
assertThat(rootCause, isA(InferenceException.class));
@Test
public void testTypeNotFound() {
final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile2.yang"));
+ () -> TestUtils.parseYangSource("/negative-scenario/testfile2.yang"));
final Throwable rootCause = Throwables.getRootCause(ex);
assertThat(rootCause, isA(InferenceException.class));
assertThat(rootCause.getMessage(),
@Test
public void testInvalidAugmentTarget() {
final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModuleResources(getClass(),
+ () -> TestUtils.parseYangSource(
"/negative-scenario/testfile0.yang", "/negative-scenario/testfile3.yang"));
final Throwable rootCause = Throwables.getRootCause(ex);
assertThat(rootCause, isA(InferenceException.class));
@Test
public void testInvalidRefine() {
final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile4.yang"));
+ () -> TestUtils.parseYangSource("/negative-scenario/testfile4.yang"));
final Throwable cause = ex.getCause();
assertThat(cause, isA(SourceException.class));
assertThat(cause.getMessage(), containsString("Error in module 'test4' in the refine of uses "
@Test
public void testInvalidLength() {
final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile5.yang"));
+ () -> TestUtils.parseYangSource("/negative-scenario/testfile5.yang"));
final Throwable cause = ex.getCause();
assertThat(cause, isA(SourceException.class));
assertThat(cause.getMessage(), containsString("Invalid length constraint [4..10]"));
@Test
public void testDuplicityInAugmentTarget1() {
final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModuleResources(getClass(),
+ () -> TestUtils.parseYangSource(
"/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment1.yang"));
final Throwable cause = ex.getCause();
assertThat(cause, isA(InferenceException.class));
@Test
public void testDuplicityInAugmentTarget2() {
final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModuleResources(getClass(),
+ () -> TestUtils.parseYangSource(
"/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment2.yang"));
final Throwable rootCause = Throwables.getRootCause(ex);
assertThat(rootCause, isA(SubstatementIndexingException.class));
@Test
public void testMandatoryInAugment() {
final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModuleResources(getClass(),
+ () -> TestUtils.parseYangSource(
"/negative-scenario/testfile8.yang", "/negative-scenario/testfile7.yang"));
final Throwable cause = ex.getCause();
assertThat(cause, isA(InferenceException.class));