Removes code duplicity in parser unit tests.
Part two of https://git.opendaylight.org/gerrit/c/yangtools/+/100136
JIRA: YANGTOOLS-1345
Change-Id: I31ec3700d425cb1e0732c9225a629d01b6d84b5c
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class YT826Test {
+public class YT826Test extends AbstractYangTest {
@Test
- public void testWhenExpressionWhitespace() throws Exception {
- StmtTestUtils.parseYangSource("/bugs/yangtools826/example.yang");
+ public void testWhenExpressionWhitespace() {
+ assertEffectiveModel("/bugs/yangtools826/example.yang");
}
}
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6878Test {
+public class Bug6878Test extends AbstractYangTest {
@Test
- public void testParsingXPathWithYang11Functions() throws Exception {
+ public void testParsingXPathWithYang11Functions() {
final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo.yang");
assertFalse(testLog.contains("Could not find function: "));
}
@Test
- public void shouldLogInvalidYang10XPath() throws Exception {
+ public void shouldLogInvalidYang10XPath() {
final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid.yang");
assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
}
@Test
- public void shouldLogInvalidYang10XPath2() throws Exception {
+ public void shouldLogInvalidYang10XPath2() {
final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid-2.yang");
assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
}
@SuppressWarnings("checkstyle:regexpSinglelineJava")
- private static String parseAndcaptureLog(final String yangFile) throws Exception {
+ private static String parseAndcaptureLog(final String yangFile) {
final PrintStream stdout = System.out;
final ByteArrayOutputStream output = new ByteArrayOutputStream();
try (PrintStream out = new PrintStream(output, true, StandardCharsets.UTF_8)) {
System.setOut(out);
- StmtTestUtils.parseYangSource(yangFile);
+ assertEffectiveModel(yangFile);
} finally {
System.setOut(stdout);
}
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 java.io.IOException;
-import java.net.URISyntaxException;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6885Test {
+public class Bug6885Test extends AbstractYangTest {
@Test
- public void validYang10Test() throws Exception {
+ public void validYang10Test() {
// Yang 1.0 allows "if-feature" and "when" on list keys
- final SchemaContext schemaContext =
- StmtTestUtils.parseYangSource("/rfc7950/list-keys-test/correct-list-keys-test.yang");
- assertNotNull(schemaContext);
+ assertEffectiveModel("/rfc7950/list-keys-test/correct-list-keys-test.yang");
}
@Test
- public void invalidListLeafKeyTest1() throws Exception {
+ public void invalidListLeafKeyTest1() {
final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)when statement is not allowed in "
+ "(incorrect-list-keys-test?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
- testForWhen("/rfc7950/list-keys-test/incorrect-list-keys-test.yang", exceptionMessage);
+ assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test.yang");
}
@Test
- public void invalidListLeafKeyTest2() throws Exception {
+ public void invalidListLeafKeyTest2() {
final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
+ "(incorrect-list-keys-test1?revision=2017-02-06)b leaf statement which is specified as a list key.";
- testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test1.yang", exceptionMessage);
+ assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test1.yang");
}
@Test
- public void invalidListUsesLeafKeyTest() throws Exception {
+ public void invalidListUsesLeafKeyTest() {
final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
+ "(incorrect-list-keys-test2?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
- testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test2.yang", exceptionMessage);
+ assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test2.yang");
}
@Test
- public void invalidListUsesLeafKeyTest1() throws Exception {
+ public void invalidListUsesLeafKeyTest1() {
final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)when statement is not allowed in "
+ "(incorrect-list-keys-test3?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
- testForWhen("/rfc7950/list-keys-test/incorrect-list-keys-test3.yang", exceptionMessage);
+ assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test3.yang");
}
@Test
- public void invalidListUsesLeafKeyTest2() throws Exception {
+ public void invalidListUsesLeafKeyTest2() {
final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
+ "(incorrect-list-keys-test4?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
- testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test4.yang", exceptionMessage);
+ assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test4.yang");
}
@Test
- public void invalidListUsesRefineLeafKeyTest() throws Exception {
+ public void invalidListUsesRefineLeafKeyTest() {
final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
+ "(incorrect-list-keys-test5?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
- testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test5.yang", exceptionMessage);
- }
-
- private static void testForIfFeature(final String yangSrcPath, final String exMsg) throws URISyntaxException,
- SourceException, IOException, YangSyntaxErrorException {
- try {
- StmtTestUtils.parseYangSource(yangSrcPath);
- fail("Test must fail: IF-FEATURE substatement is not allowed in LIST keys");
- } catch (final ReactorException e) {
- final Throwable cause = e.getCause();
- assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().startsWith(exMsg));
- }
- }
-
- private static void testForWhen(final String yangSrcPath, final String exMsg) throws URISyntaxException,
- SourceException, IOException, YangSyntaxErrorException {
- try {
- StmtTestUtils.parseYangSource(yangSrcPath);
- fail("Test must fail: WHEN substatement is not allowed in LIST keys");
- } catch (final ReactorException e) {
- final Throwable cause = e.getCause();
- assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().startsWith(exMsg));
- }
+ assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test5.yang");
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
-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.assertNotNull;
-import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import org.opendaylight.yangtools.yang.common.Uint32;
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.type.BitsTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
import org.opendaylight.yangtools.yang.model.ri.type.BitBuilder;
import org.opendaylight.yangtools.yang.model.ri.type.EnumPairBuilder;
-import org.opendaylight.yangtools.yang.model.ri.type.InvalidBitDefinitionException;
-import org.opendaylight.yangtools.yang.model.ri.type.InvalidEnumDefinitionException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6887Test {
+public class Bug6887Test extends AbstractYangTest {
@Test
- public void testRestrictedEnumeration() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo.yang");
- assertNotNull(schemaContext);
+ public void testRestrictedEnumeration() {
+ final var context = assertEffectiveModel("/rfc7950/bug6887/foo.yang");
- final Module foo = schemaContext.findModule("foo", Revision.of("2017-01-26")).get();
+ final Module foo = context.findModule("foo", Revision.of("2017-01-26")).get();
final LeafSchemaNode myEnumerationLeaf = (LeafSchemaNode) foo.getDataChildByName(
QName.create(foo.getQNameModule(), "my-enumeration-leaf"));
@Test
public void testInvalidRestrictedEnumeration() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo-invalid.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Enum 'purple' is not a subset of its base enumeration type "
- + "(foo?revision=2017-02-02)my-derived-enumeration-type."));
+ assertSourceException(startsWith("Enum 'purple' is not a subset of its base enumeration type "
+ + "(foo?revision=2017-02-02)my-derived-enumeration-type."), "/rfc7950/bug6887/foo-invalid.yang");
}
@Test
public void testInvalidRestrictedEnumeration2() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo-invalid-2.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidEnumDefinitionException.class));
- assertThat(cause.getMessage(), startsWith("Enum 'magenta' is not a subset of its base enumeration type "
- + "(foo?revision=2017-02-02)my-base-enumeration-type."));
+ assertInvalidEnumDefinitionException(startsWith("Enum 'magenta' is not a subset of its base enumeration type "
+ + "(foo?revision=2017-02-02)my-base-enumeration-type."), "/rfc7950/bug6887/foo-invalid-2.yang");
}
@Test
public void testInvalidRestrictedEnumeration3() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo-invalid-3.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidEnumDefinitionException.class));
- assertThat(cause.getMessage(), startsWith("Value of enum 'red' must be the same as the value of "
- + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
- + "my-derived-enumeration-type."));
+ assertInvalidEnumDefinitionException(startsWith("Value of enum 'red' must be the same as the value of "
+ + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
+ + "my-derived-enumeration-type."), "/rfc7950/bug6887/foo-invalid-3.yang");
}
@Test
public void testInvalidRestrictedEnumeration4() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo-invalid-4.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidEnumDefinitionException.class));
- assertThat(cause.getMessage(), startsWith("Value of enum 'black' must be the same as the value of "
- + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
- + "my-base-enumeration-type."));
+ assertInvalidEnumDefinitionException(startsWith("Value of enum 'black' must be the same as the value of "
+ + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
+ + "my-base-enumeration-type."), "/rfc7950/bug6887/foo-invalid-4.yang");
}
@Test
- public void testValidYang10EnumerationWithUnknownStatements() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo10-valid.yang");
- assertNotNull(schemaContext);
+ public void testValidYang10EnumerationWithUnknownStatements() {
+ assertEffectiveModel("/rfc7950/bug6887/foo10-valid.yang");
}
@Test
public void testInvalidYang10RestrictedEnumeration() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo10-invalid.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "));
+ assertSourceException(startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "),
+ "/rfc7950/bug6887/foo10-invalid.yang");
}
@Test
public void testInvalidYang10RestrictedEnumeration2() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo10-invalid-2.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "));
+ assertSourceException(startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "),
+ "/rfc7950/bug6887/foo10-invalid-2.yang");
}
@Test
- public void testRestrictedBits() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar.yang");
- assertNotNull(schemaContext);
+ public void testRestrictedBits() {
+ final var context = assertEffectiveModel("/rfc7950/bug6887/bar.yang");
- final Module bar = schemaContext.findModule("bar", Revision.of("2017-02-02")).get();
+ final Module bar = context.findModule("bar", Revision.of("2017-02-02")).get();
final LeafSchemaNode myBitsLeaf = (LeafSchemaNode) bar.getDataChildByName(
QName.create(bar.getQNameModule(), "my-bits-leaf"));
@Test
public void testInvalidRestrictedBits() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar-invalid.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Bit 'bit-w' is not a subset of its base bits type "
- + "(bar?revision=2017-02-02)my-derived-bits-type."));
+ assertSourceException(startsWith("Bit 'bit-w' is not a subset of its base bits type "
+ + "(bar?revision=2017-02-02)my-derived-bits-type."), "/rfc7950/bug6887/bar-invalid.yang");
}
@Test
public void testInvalidRestrictedBits2() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar-invalid-2.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidBitDefinitionException.class));
- assertThat(cause.getMessage(), startsWith("Bit 'bit-x' is not a subset of its base bits type "
- + "(bar?revision=2017-02-02)my-base-bits-type."));
+ assertInvalidBitDefinitionException(startsWith("Bit 'bit-x' is not a subset of its base bits type "
+ + "(bar?revision=2017-02-02)my-base-bits-type."), "/rfc7950/bug6887/bar-invalid-2.yang");
}
@Test
public void testInvalidRestrictedBits3() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar-invalid-3.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidBitDefinitionException.class));
- assertThat(cause.getMessage(), startsWith("Position of bit 'bit-c' must be the same as the position of "
- + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-derived-bits-type."));
+ assertInvalidBitDefinitionException(startsWith("Position of bit 'bit-c' must be the same as the position of "
+ + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-derived-bits-type."),
+ "/rfc7950/bug6887/bar-invalid-3.yang");
}
@Test
public void testInvalidRestrictedBits4() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar-invalid-4.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidBitDefinitionException.class));
- assertThat(cause.getMessage(), startsWith("Position of bit 'bit-d' must be the same as the position of "
- + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-base-bits-type."));
+ assertInvalidBitDefinitionException(startsWith("Position of bit 'bit-d' must be the same as the position of "
+ + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-base-bits-type."),
+ "/rfc7950/bug6887/bar-invalid-4.yang");
}
@Test
- public void testValidYang10BitsWithUnknownStatements() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar10-valid.yang");
- assertNotNull(schemaContext);
+ public void testValidYang10BitsWithUnknownStatements() {
+ assertEffectiveModel("/rfc7950/bug6887/bar10-valid.yang");
}
@Test
public void testInvalidYang10RestrictedBits() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar10-invalid.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Restricted bits type is not allowed in YANG version 1 [at "));
+ assertSourceException(startsWith("Restricted bits type is not allowed in YANG version 1 [at "),
+ "/rfc7950/bug6887/bar10-invalid.yang");
}
@Test
public void testInvalidYang10RestrictedBits2() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar10-invalid-2.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Restricted bits type is not allowed in YANG version 1 [at "));
+ assertSourceException(startsWith("Restricted bits type is not allowed in YANG version 1 [at "),
+ "/rfc7950/bug6887/bar10-invalid-2.yang");
}
private static EnumPair createEnumPair(final String name, final int value) {
import org.eclipse.jdt.annotation.NonNull;
import org.hamcrest.Matcher;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.ri.type.InvalidBitDefinitionException;
+import org.opendaylight.yangtools.yang.model.ri.type.InvalidEnumDefinitionException;
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;
return ret;
}
- public static <E extends SourceException> @NonNull E assertException(final Class<E> cause,
+ public static <E extends RuntimeException> @NonNull E assertException(final Class<E> cause,
final String... yangResourceName) {
final var ex = assertThrows(SomeModifiersUnresolvedException.class,
() -> TestUtils.parseYangSource(yangResourceName));
return ret;
}
+ public static <E extends IllegalArgumentException> @NonNull E assertArgumentException(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,
return assertExceptionDir(yangResourceName, InvalidSubstatementException.class, matcher);
}
+ public static @NonNull InvalidEnumDefinitionException assertInvalidEnumDefinitionException(
+ final Matcher<String> matcher, final String... yangResourceName) {
+ return assertArgumentException(InvalidEnumDefinitionException.class, matcher, yangResourceName);
+ }
+
+ public static @NonNull InvalidBitDefinitionException assertInvalidBitDefinitionException(
+ final Matcher<String> matcher, final String... yangResourceName) {
+ return assertArgumentException(InvalidBitDefinitionException.class, matcher, yangResourceName);
+ }
+
public static @NonNull SourceException assertSourceException(final Matcher<String> matcher,
final String... yangResourceName) {
final var ret = assertException(SourceException.class, matcher, yangResourceName);
import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-public class Bug5101Test {
+public class Bug5101Test extends AbstractYangTest {
@Test
public void test() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/bug5101.yang")
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/bug5101.yang")
.getModuleStatement(QName.create("foo", "2016-01-29", "foo"));
final ContainerEffectiveStatement myContainerInGrouping = module
import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-public class EffectiveUsesRefineAndConstraintsTest {
+public class EffectiveUsesRefineAndConstraintsTest extends AbstractYangTest {
@Test
public void refineTest() throws Exception {
- final EffectiveModelContext result = StmtTestUtils.parseYangSource("/stmt-test/uses/refine-test.yang");
+ final EffectiveModelContext result = assertEffectiveModel("/stmt-test/uses/refine-test.yang");
final ModuleEffectiveStatement module = Iterables.getOnlyElement(result.getModuleStatements().values());
final QNameModule qnameModule = module.localQNameModule();
public class OrderingTest extends AbstractModelTest {
@Test
- public void testOrderingTypedef() throws Exception {
+ public void testOrderingTypedef() {
final Collection<? extends TypeDefinition<?>> typedefs = BAR.getTypeDefinitions();
final String[] expectedOrder = { "int32-ext1", "int32-ext2", "string-ext1", "string-ext2", "string-ext3",
"string-ext4", "multiple-pattern-string", "my-decimal-type", "my-union", "my-union-ext", "nested-union2"
}
@Test
- public void testOrderingChildNodes() throws Exception {
+ public void testOrderingChildNodes() {
AugmentationSchemaNode augment1 = null;
for (final AugmentationSchemaNode as : FOO.getAugmentations()) {
if (as.getChildNodes().size() == 5) {
}
@Test
- public void testOrderingNestedChildNodes1() throws Exception {
+ public void testOrderingNestedChildNodes1() {
final Collection<? extends DataSchemaNode> childNodes = FOO.getChildNodes();
final String[] expectedOrder = { "int32-leaf", "string-leaf", "multiple-pattern-string-leaf",
"multiple-pattern-direct-string-def-leaf", "length-leaf", "decimal-leaf", "decimal-leaf2", "ext",
}
@Test
- public void testOrderingNestedChildNodes2() throws Exception {
+ public void testOrderingNestedChildNodes2() {
final Collection<? extends GroupingDefinition> groupings = BAZ.getGroupings();
assertEquals(1, groupings.size());
final GroupingDefinition target = groupings.iterator().next();
}
@Test
- public void testOrderingNestedChildNodes3() throws Exception {
- final Module justFoo = StmtTestUtils.parseYangSource("/ordering/foo.yang").getModules().iterator().next();
+ public void testOrderingNestedChildNodes3() {
+ final Module justFoo = assertEffectiveModel("/ordering/foo.yang").getModules().iterator().next();
final ContainerSchemaNode x = (ContainerSchemaNode) justFoo
.getDataChildByName(QName.create(justFoo.getQNameModule(), "x"));
final Collection<? extends DataSchemaNode> childNodes = x.getChildNodes();
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
-public class YT1089Test {
+public class YT1089Test extends AbstractYangTest {
@Test
- public void testPlusLexing() throws Exception {
- final EffectiveModelContext ctx = StmtTestUtils.parseYangSource("/bugs/YT1089/foo.yang");
+ public void testPlusLexing() {
+ final EffectiveModelContext ctx = assertEffectiveModel("/bugs/YT1089/foo.yang");
assertEquals(1, ctx.getModuleStatements().size());
final Iterator<? extends EffectiveStatement<?, ?>> it =
import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-public class YT1195Test {
+public class YT1195Test extends AbstractYangTest {
@Test
- public void testKeyStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1195/key.yang")
+ public void testKeyStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1195/key.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final ListEffectiveStatement grpFoo = module
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-public class YT1200Test {
+public class YT1200Test extends AbstractYangTest {
private static final QName FOO = QName.create("urn:foo", "foo");
@Test
- public void testKeyParsing() throws Exception {
- final DataSchemaNode foo = StmtTestUtils.parseYangSource("/bugs/YT1200/foo.yang").getDataChildByName(FOO);
+ public void testKeyParsing() {
+ final DataSchemaNode foo = assertEffectiveModel("/bugs/YT1200/foo.yang").getDataChildByName(FOO);
assertThat(foo, instanceOf(ListSchemaNode.class));
assertEquals(List.of(FOO, QName.create(FOO, "bar"), QName.create(FOO, "baz")),
((ListSchemaNode) foo).getKeyDefinition());
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UsesEffectiveStatement;
-public class YT1208Test {
+public class YT1208Test extends AbstractYangTest {
@Test
- public void testAugmentStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/augment.yang")
+ public void testAugmentStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/augment.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final NotificationEffectiveStatement notif = module
}
@Test
- public void testCaseStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/case.yang")
+ public void testCaseStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/case.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final NotificationEffectiveStatement notif = module
}
@Test
- public void testChoiceStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/choice.yang")
+ public void testChoiceStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/choice.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final NotificationEffectiveStatement notif = module
}
@Test
- public void testGroupingStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/grouping.yang")
+ public void testGroupingStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/grouping.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final NotificationEffectiveStatement notif = module
}
@Test
- public void testLeafStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/leaf.yang")
+ public void testLeafStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/leaf.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
assertNotNull(module);
}
@Test
- public void testLeafListStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/leaflist.yang")
+ public void testLeafListStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/leaflist.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final NotificationEffectiveStatement notif = module
}
@Test
- public void testListStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/list.yang")
+ public void testListStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/list.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final NotificationEffectiveStatement notif = module
}
@Test
- public void testTypedefStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/typedef.yang")
+ public void testTypedefStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/typedef.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final TypedefEffectiveStatement grpBar = module
}
@Test
- public void testUsesStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/uses.yang")
+ public void testUsesStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/uses.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
assertNotNull(module);
final List<GroupingEffectiveStatement> groupings = module
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.WhenEffectiveStatement;
-public class YT1209Test {
+public class YT1209Test extends AbstractYangTest {
@Test
- public void testWhenStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1209/when.yang")
+ public void testWhenStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1209/when.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final LeafEffectiveStatement grpFoo = module
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
-public class YT1212Test {
+public class YT1212Test extends AbstractYangTest {
@Test
- public void testActiontatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/anyxml.yang")
+ public void testActiontatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1212/anyxml.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final AnyxmlEffectiveStatement grpFoo = module
}
@Test
- public void testLeafStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/leaf.yang")
+ public void testLeafStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1212/leaf.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final LeafEffectiveStatement grpFoo = module
}
@Test
- public void testContainerStatementReuse() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/container.yang")
+ public void testContainerStatementReuse() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1212/container.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final NotificationEffectiveStatement notif =
import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-public class YT1312Test {
+public class YT1312Test extends AbstractYangTest {
@Test
- public void testRefineDefault() throws Exception {
- final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1312/foo.yang")
+ public void testRefineDefault() {
+ final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1312/foo.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final LeafListEffectiveStatement grpFoo = module
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.CoreMatchers.startsWith;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-public class YT893Test {
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void testCR() throws Exception {
- StmtTestUtils.parseYangSource("/bugs/YT893/cr.yang");
+public class YT893Test extends AbstractYangTest {
+ @Test
+ public void testCR() {
+ assertSourceException(startsWith("Failed to parse node"), "/bugs/YT893/cr.yang");
}
@Test
- public void testCRLF() throws Exception {
- assertNotNull(StmtTestUtils.parseYangSource("/bugs/YT893/crlf.yang"));
+ public void testCRLF() {
+ assertEffectiveModel("/bugs/YT893/crlf.yang");
}
@Test
- public void testHTAB() throws Exception {
- assertNotNull(StmtTestUtils.parseYangSource("/bugs/YT893/ht.yang"));
+ public void testHTAB() {
+ assertEffectiveModel("/bugs/YT893/ht.yang");
}
@Test
- public void testLF() throws Exception {
- assertNotNull(StmtTestUtils.parseYangSource("/bugs/YT893/lf.yang"));
+ public void testLF() {
+ assertEffectiveModel("/bugs/YT893/lf.yang");
}
}
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class YT911Test {
+public class YT911Test extends AbstractYangTest {
private static final QName FOO = QName.create("foo", "2018-10-22", "foo");
private static final QName BAR = QName.create(FOO, "bar");
@Test
- public void testAugmentationConfig() throws Exception {
- final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/YT911/foo.yang");
+ public void testAugmentationConfig() {
+ final var context = assertEffectiveModel("/bugs/YT911/foo.yang");
final DataSchemaNode foo = context.findDataChildByName(FOO).get();
assertEquals(Optional.of(Boolean.FALSE), foo.effectiveConfig());
assertTrue(foo instanceof ContainerSchemaNode);
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class YT983Test {
+public class YT983Test extends AbstractYangTest {
private static final QName FOO = QName.create("foo", "2019-04-30", "foo");
@Test
- public void testAugmentationConfig() throws Exception {
- final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/YT983/foo.yang");
+ public void testAugmentationConfig() {
+ final var context = assertEffectiveModel("/bugs/YT983/foo.yang");
final DataSchemaNode foo = context.findDataChildByName(FOO).get();
assertTrue(foo instanceof LeafSchemaNode);
}
*/
package org.opendaylight.yangtools.yang.stmt;
+import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-public class YangParserIdentityTest {
+public class YangParserIdentityTest extends AbstractYangTest {
// base identity name equals identity name
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void testParsingIdentityTestModule() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/identity/identitytest.yang");
- } catch (SomeModifiersUnresolvedException e) {
- StmtTestUtils.log(e, " ");
- throw e;
- }
+ @Test
+ public void testParsingIdentityTestModule() {
+ assertInferenceException(startsWith("Unable to resolve identity (urn:test.identitytest?revision="
+ + "2014-09-17)test and base identity"), "/identity/identitytest.yang");
}
// same module prefixed base identity name equals identity name
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void testParsingPrefixIdentityTestModule() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/identity/prefixidentitytest.yang");
- } catch (SomeModifiersUnresolvedException e) {
- StmtTestUtils.log(e, " ");
- throw e;
- }
+ @Test
+ public void testParsingPrefixIdentityTestModule() {
+ assertInferenceException(startsWith("Unable to resolve identity (urn:test.prefixidentitytest?revision="
+ + "2014-09-24)prefixtest and base identity"), "/identity/prefixidentitytest.yang");
}
// imported module prefixed base identity name equals identity name, but