package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
+import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
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.meta.InvalidSubstatementException;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-public class Bug6867BasicTest {
+public class Bug6867BasicTest extends AbstractYangTest {
@Test
public void valid10Test() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/valid-10.yang");
- assertNotNull(schemaContext);
+ assertEffectiveModel("/rfc7950/basic-test/valid-10.yang");
}
@Test
public void valid11Test() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/valid-11.yang");
- assertNotNull(schemaContext);
+ assertEffectiveModel("/rfc7950/basic-test/valid-11.yang");
}
@Test
- public void invalid10Test() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/basic-test/invalid-10.yang");
- fail("Test should fail due to invalid Yang 1.0");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith("NOTIFICATION is not valid for CONTAINER"));
- }
+ public void invalid10Test() {
+ assertException(InvalidSubstatementException.class, startsWith("NOTIFICATION is not valid for CONTAINER"),
+ "/rfc7950/basic-test/invalid-10.yang");
}
@Test
- public void invalid11Test() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/basic-test/invalid-11.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith("RPC is not valid for CONTAINER"));
- }
+ public void invalid11Test() {
+ assertException(InvalidSubstatementException.class, startsWith("RPC is not valid for CONTAINER"),
+ "/rfc7950/basic-test/invalid-11.yang");
}
@Test
public void anyData11Test() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/anydata-11.yang");
- assertNotNull(schemaContext);
+ assertEffectiveModel("/rfc7950/basic-test/anydata-11.yang");
}
@Test
- public void anyData10Test() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/basic-test/anydata-10.yang");
- fail("Test should fail due to invalid Yang 1.0");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith("anydata is not a YANG statement or use of extension"));
- }
+ public void anyData10Test() {
+ assertSourceException(startsWith("anydata is not a YANG statement or use of extension"),
+ "/rfc7950/basic-test/anydata-10.yang");
}
@Test
public void yangModelTest() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/model");
- assertNotNull(schemaContext);
+ assertNotNull(StmtTestUtils.parseYangSources("/rfc7950/model"));
}
@Test
- public void unsupportedVersionTest() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/basic-test/unsupported-version.yang");
- fail("Test should fail due to unsupported Yang version");
- } catch (final SomeModifiersUnresolvedException e) {
- final Throwable cause = e.getCause();
- assertNotNull(cause);
- assertTrue(cause.getMessage().startsWith("Unsupported YANG version 2.3"));
- }
+ public void unsupportedVersionTest() {
+ assertSourceException(startsWith("Unsupported YANG version 2.3"),
+ "/rfc7950/basic-test/unsupported-version.yang");
}
}
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.collect.ImmutableSet;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-public class Bug6869Test {
+public class Bug6869Test extends AbstractYangTest {
private static final QName ROOT = QName.create("foo", "root");
private static final QName GRP_LEAF = QName.create("foo", "grp-leaf");
@Test
public void invalidYang10Test() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6869/invalid10.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("IF_FEATURE is not valid for IDENTITY"));
+ assertInvalidSubstatementException(startsWith("IF_FEATURE is not valid for IDENTITY"),
+ "/rfc7950/bug6869/invalid10.yang");
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
+import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import java.util.Collection;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.MustDefinition;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-
-public class Bug6871Test {
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
+public class Bug6871Test extends AbstractYangTest {
@Test
public void testValidYang11Model() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6871/foo.yang");
- assertNotNull(schemaContext);
-
- final Module foo = schemaContext.findModule("foo", Revision.of("2016-12-14")).get();
+ final Module foo = assertEffectiveModel("/rfc7950/bug6871/foo.yang")
+ .findModule("foo", Revision.of("2016-12-14")).orElseThrow();
- final Collection<? extends NotificationDefinition> notifications = foo.getNotifications();
+ final var notifications = foo.getNotifications();
assertEquals(1, notifications.size());
final NotificationDefinition myNotification = notifications.iterator().next();
- Collection<? extends MustDefinition> mustConstraints = myNotification.getMustConstraints();
+ var mustConstraints = myNotification.getMustConstraints();
assertEquals(2, mustConstraints.size());
- final Collection<? extends RpcDefinition> rpcs = foo.getRpcs();
+ final var rpcs = foo.getRpcs();
assertEquals(1, rpcs.size());
final RpcDefinition myRpc = rpcs.iterator().next();
}
@Test
- public void testInvalidYang10Model() throws Exception {
- assertException("/rfc7950/bug6871/foo10.yang", "MUST is not valid for NOTIFICATION");
- assertException("/rfc7950/bug6871/bar10.yang", "MUST is not valid for INPUT");
- assertException("/rfc7950/bug6871/baz10.yang", "MUST is not valid for OUTPUT");
- }
-
- private static void assertException(final String sourcePath, final String exceptionMessage) throws Exception {
- try {
- StmtTestUtils.parseYangSource(sourcePath);
- fail("Test should fail due to invalid Yang 1.0");
- } catch (final ReactorException ex) {
- assertTrue(ex.getCause().getMessage().startsWith(exceptionMessage));
- }
+ public void testInvalidYang10Model() {
+ assertInvalidSubstatementException(startsWith("MUST is not valid for NOTIFICATION"),
+ "/rfc7950/bug6871/foo10.yang");
+ assertInvalidSubstatementException(startsWith("MUST is not valid for INPUT"), "/rfc7950/bug6871/bar10.yang");
+ assertInvalidSubstatementException(startsWith("MUST is not valid for OUTPUT"), "/rfc7950/bug6871/baz10.yang");
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.startsWith;
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.stmt.StmtTestUtils;
-
-public class Bug6886Test {
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
+public class Bug6886Test extends AbstractYangTest {
@Test
- public void yang11UnquotedStrTest() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang11/foo.yang");
- fail("Test should fail due to invalid yang");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage()
- .startsWith("YANG 1.1: unquoted string (illegalchars\"test1) contains illegal characters"));
- }
+ public void yang11UnquotedStrTest() {
+ assertSourceException(startsWith("YANG 1.1: unquoted string (illegalchars\"test1) contains illegal characters"),
+ "/rfc7950/bug6886/yang11/foo.yang");
}
@Test
public void yang11UnquotedStrTest2() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang11/foo2.yang");
- fail("Test should fail due to invalid yang");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage()
- .startsWith("YANG 1.1: unquoted string (illegalchars'test2) contains illegal characters"));
- }
+ assertSourceException(startsWith("YANG 1.1: unquoted string (illegalchars'test2) contains illegal characters"),
+ "/rfc7950/bug6886/yang11/foo2.yang");
}
@Test
public void yang11DoubleQuotedStrTest() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang11/foo3.yang");
- fail("Test should fail due to invalid yang");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith("YANG 1.1: illegal double quoted string "
- + "(i\\\\\\\\l\\nl\\te\\\"\\galcharstest1). In double quoted string the backslash must be followed "
- + "by one of the following character [n,t,\",\\], but was 'g'."));
- }
+ assertSourceException(startsWith("YANG 1.1: illegal double quoted string "
+ + "(i\\\\\\\\l\\nl\\te\\\"\\galcharstest1). In double quoted string the backslash must be followed "
+ + "by one of the following character [n,t,\",\\], but was 'g'."),
+ "/rfc7950/bug6886/yang11/foo3.yang");
}
@Test
public void yang10UnquotedStrTest() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang10/foo.yang");
- assertNotNull(schemaContext);
+ assertEffectiveModel("/rfc7950/bug6886/yang10/foo.yang");
}
@Test
public void yang10UnquotedStrTest2() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang10/foo2.yang");
- assertNotNull(schemaContext);
+ assertEffectiveModel("/rfc7950/bug6886/yang10/foo2.yang");
}
@Test
public void yang10DoubleQuotedStrTest() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang10/foo3.yang");
- assertNotNull(schemaContext);
+ assertEffectiveModel("/rfc7950/bug6886/yang10/foo3.yang");
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.startsWith;
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.stmt.StmtTestUtils;
-
-public class Bug6901Test {
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
+public class Bug6901Test extends AbstractYangTest {
@Test
public void ifFeature11EnumBitTest() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6901/foo.yang");
- assertNotNull(schemaContext);
+ assertEffectiveModel("/rfc7950/bug6901/foo.yang");
}
@Test
- public void ifFeatureOnDefaultValueEnumTest() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
- }
+ public void ifFeatureOnDefaultValueEnumTest() {
+ assertSourceException(
+ startsWith("Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."),
+ "/rfc7950/bug6901/invalid-foo-enum.yang");
}
@Test
- public void ifFeatureOnDefaultValueEnumTest2() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum-2.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
- }
+ public void ifFeatureOnDefaultValueEnumTest2() {
+ assertSourceException(
+ startsWith("Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."),
+ "/rfc7950/bug6901/invalid-foo-enum-2.yang");
}
@Test
- public void ifFeatureOnDefaultValueEnumTest3() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum-3.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
- }
+ public void ifFeatureOnDefaultValueEnumTest3() {
+ assertSourceException(startsWith(
+ "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."),
+ "/rfc7950/bug6901/invalid-foo-enum-3.yang");
}
@Test
- public void ifFeatureOnDefaultValueBitTest() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-bit.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Typedef '(foo)bits-typedef-2' has default value 'two' marked with an if-feature statement."));
- }
+ public void ifFeatureOnDefaultValueBitTest() {
+ assertSourceException(
+ startsWith("Typedef '(foo)bits-typedef-2' has default value 'two' marked with an if-feature statement."),
+ "/rfc7950/bug6901/invalid-foo-bit.yang");
}
@Test
- public void ifFeatureOnDefaultValueUnionTest() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-union.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo)union-leaf' has default value 'two' marked with an if-feature statement."));
- }
+ public void ifFeatureOnDefaultValueUnionTest() {
+ assertSourceException(
+ startsWith("Leaf '(foo)union-leaf' has default value 'two' marked with an if-feature statement."),
+ "/rfc7950/bug6901/invalid-foo-union.yang");
}
@Test
- public void unsupportedFeatureTest() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(
- e.getCause().getMessage().contains("has default value 'two' marked with an if-feature statement"));
- }
+ public void unsupportedFeatureTest() {
+ assertSourceException(containsString("has default value 'two' marked with an if-feature statement"),
+ "/rfc7950/bug6901/invalid-foo-enum.yang");
}
@Test
- public void ifFeature10EnumTest() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-10-enum.yang");
- fail("Test should fail due to invalid Yang 1.0");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith("IF_FEATURE is not valid for ENUM"));
- }
+ public void ifFeature10EnumTest() {
+ assertInvalidSubstatementException(startsWith("IF_FEATURE is not valid for ENUM"),
+ "/rfc7950/bug6901/invalid-foo-10-enum.yang");
}
@Test
- public void ifFeature10BitTest() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-10-bit.yang");
- fail("Test should fail due to invalid Yang 1.0");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith("IF_FEATURE is not valid for BIT"));
- }
+ public void ifFeature10BitTest() {
+ assertInvalidSubstatementException(startsWith("IF_FEATURE is not valid for BIT"),
+ "/rfc7950/bug6901/invalid-foo-10-bit.yang");
}
}
/**
* Abstract base class for tests of the model context available in {@code src/test/resources/model}.
*/
-public abstract class AbstractModelTest {
+public abstract class AbstractModelTest extends AbstractYangTest {
private static final QNameModule FOO_NS =
QNameModule.create(XMLNamespace.of("urn:opendaylight.foo"), Revision.of("2013-02-27"));
private static final QNameModule BAR_NS =
@BeforeClass
public static void beforeClass() throws Exception {
- CTX = TestUtils.loadModules("/model");
+ CTX = assertEffectiveModelDir("/model");
assertEquals(3, CTX.getModules().size());
FOO = CTX.findModules("foo").iterator().next();
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.stmt;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.hamcrest.Matcher;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InvalidSubstatementException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+/**
+ * Abstract base class containing useful utilities and assertions.
+ */
+public abstract class AbstractYangTest {
+ public static @NonNull EffectiveModelContext assertEffectiveModel(final String... yangResourceName)
+ throws Exception {
+ final var ret = TestUtils.parseYangSource(yangResourceName);
+ assertNotNull(ret);
+ return ret;
+ }
+
+ public static @NonNull EffectiveModelContext assertEffectiveModelDir(final String resourceDirName)
+ throws Exception {
+ final var ret = TestUtils.loadModules(resourceDirName);
+ assertNotNull(ret);
+ return ret;
+ }
+
+ public static <E extends SourceException> @NonNull E assertException(final Class<E> cause,
+ final String... yangResourceName) {
+ final var ex = assertThrows(SomeModifiersUnresolvedException.class,
+ () -> TestUtils.parseYangSource(yangResourceName));
+ final var actual = ex.getCause();
+ assertThat(actual, instanceOf(cause));
+ return cause.cast(actual);
+ }
+
+ public static <E extends SourceException> @NonNull E assertException(final Class<E> cause,
+ final Matcher<String> matcher, final String... yangResourceName) {
+ final var ret = assertException(cause, yangResourceName);
+ assertThat(ret.getMessage(), matcher);
+ return ret;
+ }
+
+ public static <E extends SourceException> @NonNull E assertExceptionDir(final String yangResourceName,
+ final Class<E> cause) {
+ final var ex = assertThrows(SomeModifiersUnresolvedException.class,
+ () -> TestUtils.loadModules(yangResourceName));
+ final var actual = ex.getCause();
+ assertThat(actual, instanceOf(cause));
+ return cause.cast(actual);
+ }
+
+ public static <E extends SourceException> @NonNull E assertExceptionDir(final String yangResourceName,
+ final Class<E> cause, final Matcher<String> matcher) {
+ final var ret = assertExceptionDir(yangResourceName, cause);
+ assertThat(ret.getMessage(), matcher);
+ return ret;
+ }
+
+ public static @NonNull InferenceException assertInferenceException(final Matcher<String> matcher,
+ final String... yangResourceName) {
+ return assertException(InferenceException.class, matcher, yangResourceName);
+ }
+
+ public static @NonNull InferenceException assertInferenceExceptionDir(final String yangResourceName,
+ final Matcher<String> matcher) {
+ return assertExceptionDir(yangResourceName, InferenceException.class, matcher);
+ }
+
+ public static @NonNull InvalidSubstatementException assertInvalidSubstatementException(
+ final Matcher<String> matcher, final String... yangResourceName) {
+ return assertException(InvalidSubstatementException.class, matcher, yangResourceName);
+ }
+
+ public static @NonNull InvalidSubstatementException assertInvalidSubstatementExceptionDir(
+ final String yangResourceName, final Matcher<String> matcher) {
+ return assertExceptionDir(yangResourceName, InvalidSubstatementException.class, matcher);
+ }
+
+ public static @NonNull SourceException assertSourceException(final Matcher<String> matcher,
+ final String... yangResourceName) {
+ final var ret = assertException(SourceException.class, matcher, yangResourceName);
+ // SourceException is the base of the hierarchy, we should normally assert subclasses
+ assertEquals(SourceException.class, ret.getClass());
+ return ret;
+ }
+
+ public static @NonNull SourceException assertSourceExceptionDir(final String yangResourceName,
+ final Matcher<String> matcher) {
+ final var ret = assertExceptionDir(yangResourceName, SourceException.class, matcher);
+ // SourceException is the base of the hierarchy, we should normally assert subclasses
+ assertEquals(SourceException.class, ret.getClass());
+ return ret;
+ }
+}
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
-public class AugmentTest {
+public class AugmentTest extends AbstractYangTest {
private static final QNameModule FOO = QNameModule.create(
XMLNamespace.of("urn:opendaylight.foo"), Revision.of("2013-10-13"));
private static final QNameModule BAR = QNameModule.create(
@BeforeClass
public static void beforeClass() throws Exception {
- AUGMENT_IN_AUGMENT = TestUtils.loadModules("/augment-test/augment-in-augment");
+ AUGMENT_IN_AUGMENT = assertEffectiveModelDir("/augment-test/augment-in-augment");
}
@Test
@Test
public void testAugmentRpc() throws Exception {
- final EffectiveModelContext context = TestUtils.loadModules("/augment-test/rpc");
+ final EffectiveModelContext context = assertEffectiveModelDir("/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 EffectiveModelContext context = TestUtils.loadModules("/augment-test/augment-in-uses");
+ final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/augment-in-uses");
assertEquals(1, context.getModules().size());
final Module test = context.getModules().iterator().next();
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.Module;
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 {
+public class AugmentToExtensionTest extends AbstractYangTest {
@Test
public void testIncorrectPath() throws Exception {
- 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 "));
+ // FIXME: this should not be here, or why do we need encapsulation? Add asserts for that
+ final var cause = assertInferenceExceptionDir("/augment-to-extension-test/incorrect-path",
+ startsWith("Yang model processing phase EFFECTIVE_MODEL failed [at "));
final var firstCause = cause.getCause();
assertThat(firstCause, instanceOf(InferenceException.class));
@Test
public void testCorrectPathIntoUnsupportedTarget() throws Exception {
final Module devicesModule =
- TestUtils.loadModules("/augment-to-extension-test/correct-path-into-unsupported-target")
+ assertEffectiveModelDir("/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"));
@Test
public void testCorrectAugment() throws Exception {
- final Module devicesModule = TestUtils.loadModules("/augment-to-extension-test/correct-augment")
+ final Module devicesModule = assertEffectiveModelDir("/augment-to-extension-test/correct-augment")
.findModules("augment-module").iterator().next();
final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
* <p>
* Note: Everything under unknown node is unknown node.
*/
-public class Bug1412Test {
-
+public class Bug1412Test extends AbstractYangTest {
@Test
public void test() throws Exception {
- final Module bug1412 = TestUtils.loadModules("/bugs/bug1412").findModules("bug1412").iterator().next();
+ final Module bug1412 = assertEffectiveModelDir("/bugs/bug1412").findModules("bug1412").iterator().next();
final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create(
bug1412.getQNameModule(), "node"));
final UnrecognizedStatement action = unknownNodes.iterator().next();
final QNameModule qm = QNameModule.create(XMLNamespace.of("urn:test:bug1412"), Revision.of("2014-07-25"));
- QName expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "action");
- assertEquals(expectedNodeType, action.statementDefinition().getStatementName());
+ assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "action"),
+ action.statementDefinition().getStatementName());
assertEquals("hello", action.argument());
unknownNodes = action.declaredSubstatements(UnrecognizedStatement.class);
}
assertNotNull(info);
- assertNotNull(description);
- assertNotNull(actionPoint);
- assertNotNull(output);
-
- expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info");
- assertEquals(expectedNodeType, info.statementDefinition().getStatementName());
+ assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info"),
+ info.statementDefinition().getStatementName());
assertEquals("greeting", info.argument());
- expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "description");
- assertEquals(expectedNodeType, description.statementDefinition().getStatementName());
+ assertNotNull(description);
+ assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "description"),
+ description.statementDefinition().getStatementName());
assertEquals("say greeting", description.argument());
- expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint");
- assertEquals(expectedNodeType, actionPoint.statementDefinition().getStatementName());
+ assertNotNull(actionPoint);
+ assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint"),
+ actionPoint.statementDefinition().getStatementName());
assertEquals("entry", actionPoint.argument());
- expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "output");
- assertEquals(expectedNodeType, output.statementDefinition().getStatementName());
+ assertNotNull(output);
+ assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "output"),
+ output.statementDefinition().getStatementName());
assertEquals(Empty.getInstance(), output.argument());
}
}
* <p>
* Note: Everything under unknown node is unknown node.
*/
-public class Bug1413Test {
+public class Bug1413Test extends AbstractYangTest {
@Test
public void test() throws Exception {
- var extensions = TestUtils.loadModules("/bugs/bug1413").findModules("bug1413").iterator().next()
+ var extensions = assertEffectiveModelDir("/bugs/bug1413").findModules("bug1413").iterator().next()
.getExtensionSchemaNodes();
assertEquals(1, extensions.size());
import org.junit.Test;
-public class Bug3859Test {
+public class Bug3859Test extends AbstractYangTest {
@Test
public void test() throws Exception {
- assertEquals(1, TestUtils.loadModules("/bugs/bug3859").findModules("reference-in-unknown").size());
+ assertEquals(1, assertEffectiveModelDir("/bugs/bug3859").findModules("reference-in-unknown").size());
}
}
/**
* Test antlr grammar capability to parse nested unknown nodes.
*/
-public class Bug394Test {
+public class Bug394Test extends AbstractYangTest {
@Test
public void testParseList() throws Exception {
- final EffectiveModelContext context = TestUtils.loadModules("/bugs/bug394-retest");
+ final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug394-retest");
final Module bug394 = context.findModules("bug394").iterator().next();
final Module bug394_ext = context.findModules("bug394-ext").iterator().next();
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-public class Bug4623Test {
+public class Bug4623Test extends AbstractYangTest {
private static Module TYPES;
@BeforeClass
public static void beforeClass() throws Exception {
// given
- TYPES = TestUtils.loadModules("/bugs/bug4623").findModules("types").iterator().next();
+ TYPES = assertEffectiveModelDir("/bugs/bug4623").findModules("types").iterator().next();
}
@Test
QName.create(XMLNamespace.of("urn:custom.types.demo"), "leaf-unknown-length-pattern"));
// then
- assertNotNull(leaf);
-
final TypeDefinition<?> type = leaf.getType();
assertNotNull(type);
assertEquals(0, type.getUnknownSchemaNodes().size());
final LengthConstraint lengthConstraints =
((StringTypeDefinition) type).getLengthConstraint().get();
- final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
-
- assertNotNull(lengthConstraints);
- assertNotNull(patternConstraints);
assertEquals(1, lengthConstraints.getAllowedRanges().asRanges().size());
- assertFalse(patternConstraints.size() == 0);
final Range<Integer> lengthConstraint = lengthConstraints.getAllowedRanges().span();
assertEquals(Integer.valueOf(2), lengthConstraint.lowerEndpoint());
assertEquals(Integer.valueOf(10), lengthConstraint.upperEndpoint());
+ final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
+ assertEquals(1, patternConstraints.size());
final PatternConstraint patternConstraint = patternConstraints.get(0);
assertEquals(patternConstraint.getRegularExpressionString(), "[0-9a-fA-F]");
}
@Test
public void augmentTest() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/bug6771/augment.yang")
+ final ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/augment.yang")
.getModuleStatement(NS);
verifyLeafType(module, ROOT, CONT_B, LEAF_CONT_B);
@Test
public void choiceCaseTest() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/bug6771/choice-case.yang")
+ final ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/choice-case.yang")
.getModuleStatement(NS);
final QName myChoice = QName.create(NS, "my-choice");
@Test
public void groupingTest() throws Exception {
- verifyLeafType(StmtTestUtils.parseYangSource("/bugs/bug6771/grouping.yang").getModuleStatement(NS),
+ verifyLeafType(TestUtils.parseYangSource("/bugs/bug6771/grouping.yang").getModuleStatement(NS),
ROOT, CONT_B, LEAF_CONT_B);
}
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-public class Bug7865Test {
+public class Bug7865Test extends AbstractYangTest {
@Test
public void test() throws Exception {
- final EffectiveModelContext context = TestUtils.loadModules("/bugs/bug7865");
+ final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug7865");
final DataSchemaNode root = context.getDataChildByName(foo("root"));
assertTrue(root instanceof ContainerSchemaNode);
final Collection<? extends UnrecognizedStatement> unknownSchemaNodes = ((ContainerSchemaNode) root)
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
-public class Bug7879Test {
+public class Bug7879Test extends AbstractYangTest {
private static final XMLNamespace NS = XMLNamespace.of("my-model-ns");
@Test
public void test() throws Exception {
- final ModuleEffectiveStatement module = TestUtils.loadModules("/bugs/bug7879")
- .getModuleStatement(QName.create(NS, "my-model"));
+ final ModuleEffectiveStatement module = assertEffectiveModelDir("/bugs/bug7879")
+ .getModuleStatement(qn("my-model"));
final SchemaTreeEffectiveStatement<?> container = module.findSchemaTreeNode(
- qN("my-alarm"), qN("my-content"), qN("my-event-container")).orElse(null);
+ qn("my-alarm"), qn("my-content"), qn("my-event-container")).orElse(null);
assertThat(container, instanceOf(ContainerSchemaNode.class));
final SchemaTreeEffectiveStatement<?> leaf = module.findSchemaTreeNode(
- qN("my-alarm"), qN("my-content"), qN("my-event-value")).orElse(null);
+ qn("my-alarm"), qn("my-content"), qn("my-event-value")).orElse(null);
assertThat(leaf, instanceOf(LeafSchemaNode.class));
assertEquals(Optional.of("new description"), ((LeafSchemaNode) leaf).getDescription());
}
- private static QName qN(final String localName) {
+ private static QName qn(final String localName) {
return QName.create(NS, localName);
}
}
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.assertThrows;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class Bug8831Test {
+public class Bug8831Test extends AbstractYangTest {
@Test
public void test() throws Exception {
- assertNotNull(TestUtils.loadModules("/bugs/bug8831/valid"));
+ assertEffectiveModelDir("/bugs/bug8831/valid");
}
@Test
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"));
+ assertSourceException(containsString("has default value 'any' marked with an if-feature statement"),
+ "/bugs/bug8831/invalid/inv-model.yang");
}
@Test
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"));
+ assertSourceException(containsString("has default value 'any' marked with an if-feature statement"),
+ "/bugs/bug8831/invalid/inv-model2.yang");
}
}
@Test
public void testAddedByUsesLeafTypeQName() throws Exception {
- final EffectiveModelContext loadModules = TestUtils.loadModules("/added-by-uses-leaf-test");
+ final EffectiveModelContext loadModules = assertEffectiveModelDir("/added-by-uses-leaf-test");
assertEquals(2, loadModules.getModules().size());
final Module foo = Iterables.getOnlyElement(loadModules.findModules("foo"));
public class ListKeysTest {
@Test
public void correctListKeysTest() throws Exception {
- StmtTestUtils.parseYangSource("/list-keys-test/correct-list-keys-test.yang");
+ TestUtils.parseYangSource("/list-keys-test/correct-list-keys-test.yang");
}
@Test
public void incorrectListKeysTest1() {
final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test.yang"));
+ () -> TestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test.yang"));
final Throwable cause = ex.getCause();
assertThat(cause, instanceOf(SourceException.class));
assertThat(cause.getMessage(), startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
@Test
public void incorrectListKeysTest2() {
final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test2.yang"));
+ () -> TestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test2.yang"));
final Throwable cause = ex.getCause();
assertThat(cause, instanceOf(SourceException.class));
assertThat(cause.getMessage(), startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
@Test
public void incorrectListKeysTest3() {
final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test3.yang"));
+ () -> TestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test3.yang"));
final Throwable cause = ex.getCause();
assertThat(cause, instanceOf(SourceException.class));
assertThat(cause.getMessage(), startsWith("Key 'grp_list' misses node 'grp_list'"));
@Test
public void incorrectListKeysTest4() {
final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test4.yang"));
+ () -> TestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test4.yang"));
final Throwable cause = ex.getCause();
assertThat(cause, instanceOf(SourceException.class));
assertThat(cause.getMessage(), startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));
*/
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 org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
/**
* Test for testing of extensions and their arguments.
*/
-public class ParsingExtensionValueTest {
+public class ParsingExtensionValueTest extends AbstractYangTest {
@Test
public void extensionTest() {
- final var ex = assertThrows(SomeModifiersUnresolvedException.class, () -> TestUtils.loadModules("/extensions"));
- final var cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("ext:id is not a YANG statement or use of extension"));
+ assertSourceExceptionDir("/extensions", startsWith("ext:id is not a YANG statement or use of extension"));
}
}
}
}
+ @Deprecated(forRemoval = true)
+ // TestUtils.parseYangSource() instead, but callers need also further cleanup
public static EffectiveModelContext parseYangSource(final String yangSourcePath) throws ReactorException,
URISyntaxException, IOException, YangSyntaxErrorException {
return parseYangSource(yangSourcePath, YangParserConfiguration.DEFAULT, null);
*/
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.assertEquals;
-import static org.junit.Assert.assertThrows;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InvalidSubstatementException;
import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class SubstatementValidatorTest {
+public class SubstatementValidatorTest extends AbstractYangTest {
@Test
public void noException() throws Exception {
- assertEquals(3, TestUtils.loadModules("/augment-test/augment-in-augment").getModules().size());
+ assertEquals(3, assertEffectiveModelDir("/augment-test/augment-in-augment").getModules().size());
}
@Test
public void undesirableElementException() throws Exception {
- final var ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModules("/substatement-validator/undesirable-element"));
- final var cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidSubstatementException.class));
- assertThat(cause.getMessage(), startsWith("TYPE is not valid for REVISION. Error in module undesirable "
- + "(QNameModule{ns=urn:opendaylight.undesirable, rev=2015-11-11}) [at "));
+ assertInvalidSubstatementExceptionDir("/substatement-validator/undesirable-element",
+ startsWith("TYPE is not valid for REVISION. Error in module undesirable "
+ + "(QNameModule{ns=urn:opendaylight.undesirable, rev=2015-11-11}) [at "));
}
@Test
public void maximalElementCountException() throws Exception {
- final var ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModules("/substatement-validator/maximal-element"));
- final var cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidSubstatementException.class));
- assertThat(cause.getMessage(), startsWith("Maximal count of DESCRIPTION for AUGMENT is 1, detected 2. Error in "
- + "module baz (QNameModule{ns=urn:opendaylight.baz, rev=2015-11-11}) [at "));
+ assertInvalidSubstatementExceptionDir("/substatement-validator/maximal-element",
+ startsWith("Maximal count of DESCRIPTION for AUGMENT is 1, detected 2. Error in module baz "
+ + "(QNameModule{ns=urn:opendaylight.baz, rev=2015-11-11}) [at "));
}
@Test
public void missingElementException() {
- final var ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModules("/substatement-validator/missing-element"));
- final var cause = ex.getCause();
// FIXME: should be MissingSubstatementException?
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Missing prefix statement [at "));
+ assertSourceExceptionDir("/substatement-validator/missing-element",
+ startsWith("Missing prefix statement [at "));
}
@Test
public void bug6173Test() throws Exception {
- assertEquals(1, TestUtils.loadModules("/substatement-validator/empty-element").getModules().size());
+ assertEquals(1, assertEffectiveModelDir("/substatement-validator/empty-element").getModules().size());
}
@Test
public void bug4310test() throws Exception {
- final var ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.loadModules("/substatement-validator/bug-4310"));
- final var cause = ex.getCause();
- assertThat(cause, instanceOf(MissingSubstatementException.class));
- assertThat(cause.getMessage(), startsWith("TYPE is missing TYPE. Minimal count is 1. Error in module bug4310 "
- + "(QNameModule{ns=urn:opendaylight.bug4310}) [at "));
+ assertExceptionDir("/substatement-validator/bug-4310", MissingSubstatementException.class,
+ startsWith("TYPE is missing TYPE. Minimal count is 1. Error in module bug4310 "
+ + "(QNameModule{ns=urn:opendaylight.bug4310}) [at "));
}
}
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.Revision;
-public class TwoRevisionsTest {
+public class TwoRevisionsTest extends AbstractYangTest {
@Test
public void testTwoRevisions() throws Exception {
- var it = TestUtils.loadModules("/ietf").findModuleStatements("network-topology").iterator();
+ var it = assertEffectiveModelDir("/ietf").findModuleStatements("network-topology").iterator();
assertTrue(it.hasNext());
assertEquals(Revision.ofNullable("2013-10-21"), it.next().localQNameModule().getRevision());
assertTrue(it.hasNext());
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
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.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
-public class UsesAugmentTest {
+public class UsesAugmentTest extends AbstractYangTest {
private static final QNameModule UG = QNameModule.create(
XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:uses-grouping"), Revision.of("2013-07-30"));
private static final QNameModule GD = QNameModule.create(
XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:grouping-definitions"), Revision.of("2013-09-04"));
- private static SchemaContext CONTEXT;
+ private static EffectiveModelContext CONTEXT;
@BeforeClass
public static void beforeClass() throws Exception {
- CONTEXT = TestUtils.loadModules("/grouping-test");
+ CONTEXT = assertEffectiveModelDir("/grouping-test");
}
/*
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.MustDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
-public class YangParserSimpleTest {
+public class YangParserSimpleTest extends AbstractYangTest {
private static final XMLNamespace NS = XMLNamespace.of("urn:opendaylight:simple-nodes");
private static final QNameModule SN = QNameModule.create(NS, Revision.of("2013-07-30"));
private static final QName SN_NODES = QName.create(SN, "nodes");
- private static SchemaContext CONTEXT;
private static Module MODULE;
@BeforeClass
public static void beforeClass() throws Exception {
- CONTEXT = TestUtils.loadModules("/simple-test");
- MODULE = CONTEXT.findModules("simple-nodes").iterator().next();
+ MODULE = assertEffectiveModelDir("/simple-test").findModules("simple-nodes").iterator().next();
}
@Test
public void testParseAnyXml() {
final AnyxmlSchemaNode data = (AnyxmlSchemaNode) MODULE.getDataChildByName(
QName.create(MODULE.getQNameModule(), "data"));
- assertNotNull("'anyxml data not found'", data);
assertFalse(data.equals(null));
assertEquals("RegularAnyxmlEffectiveStatement{qname=(urn:opendaylight:simple-nodes?revision=2013-07-30)data}",
data.toString());