@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
InferenceException.throwIf(failed.contains(requiresCtxPrerequisite), stmt,
- "Included submodule '%s' was not found: ", stmt.argument());
+ "Included submodule '%s' was not found", stmt.rawArgument());
}
});
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.antlr;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opendaylight.yangtools.yang.parser.rfc7950.antlr.IRSupport.trimWhitespace;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class IRSupportTest {
+class IRSupportTest {
@Test
- public void testTrimWhitespace() {
+ void testTrimWhitespace() {
assertEquals("\n", trimWhitespace("\n", 0));
assertEquals("\n", trimWhitespace("\n", 5));
assertEquals("\n\n\n\n", trimWhitespace("\n\n\n\n", 0));
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.repo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opendaylight.yangtools.yang.parser.rfc7950.repo.ArgumentContextUtils.unescapeBackslash;
import java.io.File;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-public class ArgumentContextUtilsTest {
+class ArgumentContextUtilsTest {
@Test
- public void testUnescapeNew() {
+ void testUnescapeNew() {
// a\b -----> a\b (invalid for 7950)
assertEquals("\\abc", unescape("\\abc", 0));
assertEquals("abc\\", unescape("abc\\", 3));
}
@Test
- public void stringTestUnescape() throws Exception {
+ void stringTestUnescape() throws Exception {
final SchemaContext schemaContext = StmtTestUtils.parseYangSources(new File(getClass()
- .getResource("/unescape/string-test.yang").toURI()));
+ .getResource("/unescape/string-test.yang").toURI()));
assertNotNull(schemaContext);
assertEquals(1, schemaContext.getModules().size());
final Module module = schemaContext.getModules().iterator().next();
assertEquals(Optional.of(" Unescaping examples: \\,\n,\t \"string enclosed in double quotes\" end\n"
- + "abc \\\\\\ \\t \\\nnn"), module.getDescription());
+ + "abc \\\\\\ \\t \\\nnn"), module.getDescription());
}
private static String unescape(final String str, final int backslash) {
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.repo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-public class YangModelDependencyInfoTest {
+class YangModelDependencyInfoTest {
// Utility
private static YangModelDependencyInfo forResource(final String resourceName) {
final YangStatementStreamSource source = StmtTestUtils.sourceForResource(resourceName);
}
@Test
- public void testModuleWithNoImports() {
+ void testModuleWithNoImports() {
YangModelDependencyInfo info = forResource("/ietf/ietf-inet-types@2010-09-24.yang");
assertNotNull(info);
assertEquals("ietf-inet-types", info.getName());
assertEquals("2010-09-24", info.getFormattedRevision());
assertNotNull(info.getDependencies());
- assertTrue(info.equals(info));
+ assertEquals(info, info);
}
@Test
- public void testModuleWithImports() {
+ void testModuleWithImports() {
YangModelDependencyInfo info = forResource("/parse-methods/dependencies/m2@2013-09-30.yang");
assertNotNull(info);
assertEquals("m2", info.getName());
}
@Test
- public void testModuleWithoutRevision() {
+ void testModuleWithoutRevision() {
YangModelDependencyInfo info = forResource("/no-revision/module-without-revision.yang");
assertNotNull(info);
assertEquals("module-without-revision", info.getName());
}
@Test
- public void testEquals() {
+ void testEquals() {
YangModelDependencyInfo info1 = forResource("/ietf/ietf-inet-types@2010-09-24.yang");
YangModelDependencyInfo info2 = forResource("/no-revision/module-without-revision.yang");
- assertTrue(info1.equals(info1));
- assertFalse(info1.equals(null));
- assertFalse(info1.equals(info2));
+ assertEquals(info1, info1);
+ assertNotEquals(null, info1);
+ assertNotEquals(info1, info2);
}
@Test
- public void testYangtools827() {
+ void testYangtools827() {
// Latest revision needs to be picked up irrespective of ordering
YangModelDependencyInfo info = forResource("/bugs/YT827/foo.yang");
assertEquals("2014-12-24", info.getFormattedRevision());
}
@Test
- public void testHashcode() {
+ void testHashcode() {
YangModelDependencyInfo info = forResource("/no-revision/module-without-revision.yang");
- assertNotEquals("hashcode", 31, info.hashCode());
+ assertNotEquals(31, info.hashCode(), "hashcode");
}
@Test
- public void testMalformedImport() {
+ void testMalformedImport() {
assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-import.yang"));
}
@Test
- public void testMalformedImportRev() {
+ void testMalformedImportRev() {
assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-import-rev.yang"));
}
@Test
- public void testMalformedModule() {
+ void testMalformedModule() {
assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-module.yang"));
}
@Test
- public void testMalformedRev() {
+ void testMalformedRev() {
assertThrows(IllegalArgumentException.class, () -> forResource("/depinfo-malformed/malformed-rev.yang"));
}
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.path;
+import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.isA;
import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doReturn;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.model.api.PathExpression;
import org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps;
import org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps;
-import org.opendaylight.yangtools.yang.model.api.PathExpression.Steps;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.xpath.api.YangQNameExpr;
import org.opendaylight.yangtools.yang.xpath.api.YangXPathAxis;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
+@ExtendWith(MockitoExtension.class)
public class PathExpressionParserTest {
@Mock
public StmtContext<?, ?, ?> ctx;
@SuppressWarnings("exports")
public final PathExpressionParser parser = new PathExpressionParser();
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
doReturn(ref).when(ctx).sourceReference();
}
@Test
- public void testDerefPath() {
+ void testDerefPath() {
// deref() is not valid as per RFC7950, but we tolarate it.
final PathExpression deref = parser.parseExpression(ctx, "deref(../id)/../type");
- final Steps steps = deref.getSteps();
- assertThat(steps, isA(DerefSteps.class));
-
- final DerefSteps derefSteps = (DerefSteps) steps;
+ final DerefSteps derefSteps = assertInstanceOf(DerefSteps.class, deref.getSteps());
assertEquals(YangLocationPath.relative(YangXPathAxis.PARENT.asStep(),
YangXPathAxis.CHILD.asStep(Unqualified.of("type"))), derefSteps.getRelativePath());
assertEquals(YangLocationPath.relative(YangXPathAxis.PARENT.asStep(),
}
@Test
- public void testInvalidLeftParent() {
- try {
- parser.parseExpression(ctx, "foo(");
- fail("SourceException should have been thrown");
- } catch (SourceException e) {
- assertSame(ref, e.getSourceReference());
- assertThat(e.getMessage(), startsWith("extraneous input '(' expecting "));
- assertThat(e.getMessage(), containsString(" at 1:3 [at "));
- }
+ void testInvalidLeftParent() {
+ final var ex = assertThrows(SourceException.class, () -> parser.parseExpression(ctx, "foo("));
+ assertSame(ref, ex.getSourceReference());
+ assertThat(ex.getMessage(), allOf(
+ startsWith("extraneous input '(' expecting "),
+ containsString(" at 1:3 [at ")));
}
@Test
- public void testInvalidRightParent() {
- try {
- parser.parseExpression(ctx, "foo)");
- fail("SourceException should have been thrown");
- } catch (SourceException e) {
- assertSame(ref, e.getSourceReference());
- assertThat(e.getMessage(), startsWith("extraneous input ')' expecting "));
- assertThat(e.getMessage(), containsString(" at 1:3 [at "));
- }
+ void testInvalidRightParent() {
+ final var ex = assertThrows(SourceException.class, () -> parser.parseExpression(ctx, "foo)"));
+ assertSame(ref, ex.getSourceReference());
+ assertThat(ex.getMessage(), allOf(
+ startsWith("extraneous input ')' expecting "),
+ containsString(" at 1:3 [at ")));
}
@Test
- public void testInvalidIdentifier() {
- try {
- parser.parseExpression(ctx, "foo%");
- fail("SourceException should have been thrown");
- } catch (SourceException e) {
- assertSame(ref, e.getSourceReference());
- assertThat(e.getMessage(), startsWith("token recognition error at: '%' at 1:3 [at "));
- }
+ void testInvalidIdentifier() {
+ final var ex = assertThrows(SourceException.class, () -> parser.parseExpression(ctx, "foo%"));
+ assertSame(ref, ex.getSourceReference());
+ assertThat(ex.getMessage(), startsWith("token recognition error at: '%' at 1:3 [at "));
}
@Test
- public void testCurrentPredicateParsing() {
+ void testCurrentPredicateParsing() {
final YangLocationPath path = ((LocationPathSteps) parser.parseExpression(ctx,
"/device_types/device_type[type = current()/../type_text]/desc").getSteps()).getLocationPath();
assertTrue(path.isAbsolute());
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.pattern;
-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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class Bug4079Test {
+class Bug4079Test {
@Test
- public void testValidPatternFix() {
+ void testValidPatternFix() {
assertJavaRegex("^(?:(\\p{InArrows})*+)$", "(\\p{IsArrows})*+");
assertJavaRegex("^(?:(\\p{InDingbats})++)$", "(\\p{IsDingbats})++");
assertJavaRegex("^(?:(\\p{InSpecials})?+)$", "(\\p{IsSpecials})?+");
assertJavaRegex("^(?:(\\p{IsLatin}|\\p{InBasicLatin}){2,})$", "(\\p{IsLatin}|\\p{IsBasicLatin}){2,}");
assertJavaRegex("^(?:(\\p{InBasicLatin}|\\p{IsLatin})*?)$", "(\\p{IsBasicLatin}|\\p{IsLatin})*?");
assertJavaRegex("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{InArrows})+?)$",
- "(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement}|\\p{IsArrows})+?");
+ "(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement}|\\p{IsArrows})+?");
assertJavaRegex("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{IsLatin})??)$",
- "(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}|\\p{IsLatin})??");
+ "(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}|\\p{IsLatin})??");
assertJavaRegex("^(?:(\\\\\\p{InBasicLatin})*+)$", "(\\\\\\p{IsBasicLatin})*+");
assertJavaRegex("^(?:(\\\\\\\\\\p{InBasicLatin})*+)$", "(\\\\\\\\\\p{IsBasicLatin})*+");
assertJavaRegex("^(?:(\\\\\\\\\\\\\\p{InBasicLatin})*+)$", "(\\\\\\\\\\\\\\p{IsBasicLatin})*+");
}
@Test
- public void testInvalidPattern() {
+ void testInvalidPattern() {
String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\p{IsBasicLatin})*+");
assertEquals("^(?:(\\\\p{IsBasicLatin})*+)$", fixedUnicodeScriptPattern);
// should throw exception
}
@Test
- public void testInvalidPattern2() {
+ void testInvalidPattern2() {
String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
"(\\p{IsSpecials}|\\\\\\\\p{IsBasicLatin})*+");
assertEquals("^(?:(\\p{InSpecials}|\\\\\\\\p{IsBasicLatin})*+)$", fixedUnicodeScriptPattern);
}
@Test
- public void testInvalidPattern3() {
+ void testInvalidPattern3() {
String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
"(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+");
assertEquals("^(?:(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+)$", fixedUnicodeScriptPattern);
}
@Test
- public void testCorrectBranches() {
+ void testCorrectBranches() {
String str = RegexUtils.getJavaRegexFromXSD("a|bb");
assertEquals("^(?:a|bb)$", str);
Predicate<String> pred = Pattern.compile(str).asPredicate();
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.pattern;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.google.common.collect.ImmutableList;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class Bug5410Test {
+class Bug5410Test {
@Test
- public void testCaret() {
+ void testCaret() {
testPattern("^", "\\^");
}
@Test
- public void testTextCaret() {
+ void testTextCaret() {
testPattern("abc^", "abc\\^");
}
@Test
- public void testTextDollar() {
+ void testTextDollar() {
testPattern("abc$", "abc\\$");
}
@Test
- public void testCaretCaret() {
+ void testCaretCaret() {
testPattern("^^", "\\^\\^");
}
@Test
- public void testCaretDollar() {
+ void testCaretDollar() {
testPattern("^$", "\\^\\$");
}
@Test
- public void testDot() {
+ void testDot() {
testPattern(".", ".");
}
@Test
- public void testNotColon() {
+ void testNotColon() {
testPattern("[^:]+", "[^:]+");
}
@Test
- public void testDollar() {
+ void testDollar() {
testPattern("$", "\\$");
}
@Test
- public void testDollarOneDollar() {
+ void testDollarOneDollar() {
testPattern("$1$", "\\$1\\$");
}
@Test
- public void testDollarPercentRange() {
+ void testDollarPercentRange() {
testPattern("[$-%]+", "[$-%]+");
}
@Test
- public void testDollarRange() {
+ void testDollarRange() {
testPattern("[$$]+", "[$$]+");
}
@Test
- public void testDollarCaretRange() {
+ void testDollarCaretRange() {
testPattern("[$^]+", "[$^]+");
}
@Test
- public void testSimple() {
+ void testSimple() {
testPattern("abc", "abc");
}
@Test
- public void testDotPlus() {
+ void testDotPlus() {
testPattern(".+", ".+");
}
@Test
- public void testDotStar() {
+ void testDotStar() {
testPattern(".*", ".*");
}
@Test
- public void testSimpleOptional() {
+ void testSimpleOptional() {
testPattern("a?", "a?");
}
@Test
- public void testRangeOptional() {
+ void testRangeOptional() {
testPattern("[a-z]?", "[a-z]?");
}
@Test
- public void testInvalidXSDRegexes() throws UnsupportedEncodingException {
+ void testInvalidXSDRegexes() throws UnsupportedEncodingException {
testInvalidPattern("$^a^[$^\\]", "Unclosed character class");
testInvalidPattern("$(\\)", "Unclosed group");
}
@Test
- public void testJavaPattern() {
- testPattern("^[$^]+$", ImmutableList.of("$^", "^", "$"), ImmutableList.of("\\", "a"));
- testPattern("^[^$-^]$", ImmutableList.of("a", "_", "#"), ImmutableList.of("%", "^", "$", "]", "\\"));
+ void testJavaPattern() {
+ testPattern("^[$^]+$", List.of("$^", "^", "$"), List.of("\\", "a"));
+ testPattern("^[^$-^]$", List.of("a", "_", "#"), List.of("%", "^", "$", "]", "\\"));
}
@Test
- public void testJavaRegexFromXSD() {
- testPattern("^[^:]+$", "^(?:\\^[^:]+\\$)$", ImmutableList.of("^a$", "^abc$"),
- ImmutableList.of("abc$", "^abc", "^a:bc$"));
- testPattern("^[$^]$", "^(?:\\^[$^]\\$)$", ImmutableList.of("^^$", "^$$"),
- ImmutableList.of("^^", "^$", "$^", "$$"));
- testPattern("[$-%]+", "^(?:[$-%]+)$", ImmutableList.of("$", "%", "%$"),
- ImmutableList.of("$-", "$-%", "-", "^"));
- testPattern("[$-&]+", "^(?:[$-&]+)$", ImmutableList.of("$", "%&", "%$", "$%&"),
- ImmutableList.of("#", "$-&", "'"));
+ void testJavaRegexFromXSD() {
+ testPattern("^[^:]+$", "^(?:\\^[^:]+\\$)$", List.of("^a$", "^abc$"), List.of("abc$", "^abc", "^a:bc$"));
+ testPattern("^[$^]$", "^(?:\\^[$^]\\$)$", List.of("^^$", "^$$"), List.of("^^", "^$", "$^", "$$"));
+ testPattern("[$-%]+", "^(?:[$-%]+)$", List.of("$", "%", "%$"), List.of("$-", "$-%", "-", "^"));
+ testPattern("[$-&]+", "^(?:[$-&]+)$", List.of("$", "%&", "%$", "$%&"), List.of("#", "$-&", "'"));
- testPattern("[a-z&&[^m-p]]+", "^(?:[a-z&&[^m-p]]+)$", ImmutableList.of("a", "z", "az"),
- ImmutableList.of("m", "anz", "o"));
- testPattern("^[\\[-b&&[^^-a]]+$", "^(?:\\^[\\[-b&&[^^-a]]+\\$)$", ImmutableList.of("^[$", "^\\$", "^]$", "^b$"),
- ImmutableList.of("^a$", "^^$", "^_$"));
+ testPattern("[a-z&&[^m-p]]+", "^(?:[a-z&&[^m-p]]+)$", List.of("a", "z", "az"), List.of("m", "anz", "o"));
+ testPattern("^[\\[-b&&[^^-a]]+$", "^(?:\\^[\\[-b&&[^^-a]]+\\$)$",
+ List.of("^[$", "^\\$", "^]$", "^b$"), List.of("^a$", "^^$", "^_$"));
// FIXME: YANGTOOLS-887: these patterns are not translated correctly, "&&" is a different construct in XSD
- // testPattern("[^^-~&&[^$-^]]", "^(?:[^^-~&&[^$-^]])$", ImmutableList.of("!", "\"", "#"),
- // ImmutableList.of("a", "A", "z", "Z", "$", "%", "^", "}"));
+ // testPattern("[^^-~&&[^$-^]]", "^(?:[^^-~&&[^$-^]])$",
+ // List.of("!", "\"", "#"), List.of("a", "A", "z", "Z", "$", "%", "^", "}"));
// testPattern("\\\\\\[^[^^-~&&[^$-^]]", "^(?:\\\\\\[\\^[^^-~&&[^$-^]])$",
- // ImmutableList.of("\\[^ ", "\\[^!", "\\[^\"", "\\[^#"),
- // ImmutableList.of("\\[^a", "\\[^A", "\\[^z", "\\[^Z", "\\[^$", "\\[^%", "\\[^^", "\\[^}"));
+ // List.of("\\[^ ", "\\[^!", "\\[^\"", "\\[^#"),
+ // List.of("\\[^a", "\\[^A", "\\[^z", "\\[^Z", "\\[^$", "\\[^%", "\\[^^", "\\[^}"));
// testPattern("^\\[^\\\\[^^-b&&[^\\[-\\]]]\\]^", "^(?:\\^\\[\\^\\\\[^^-b&&[^\\[-\\]]]\\]\\^)$",
- // ImmutableList.of("^[^\\c]^", "^[^\\Z]^"),
- // ImmutableList.of("^[^\\[]^", "^[^\\\\]^", "^[^\\]]^", "^[^\\^]^", "^[^\\_]^", "^[^\\b]^"));
- // testPattern("[\\^]$", "^(?:[\\^]\\$)$", ImmutableList.of("^$"),
- // ImmutableList.of("^", "$", "$^", "\\", "\\^", "\\^\\", "\\^\\$"));
+ // List.of("^[^\\c]^", "^[^\\Z]^"),
+ // List.of("^[^\\[]^", "^[^\\\\]^", "^[^\\]]^", "^[^\\^]^", "^[^\\_]^", "^[^\\b]^"));
+ // testPattern("[\\^]$", "^(?:[\\^]\\$)$",
+ // List.of("^$"), List.of("^", "$", "$^", "\\", "\\^", "\\^\\", "\\^\\$"));
}
@SuppressWarnings("checkstyle:regexpSinglelineJava")
}
private static void testPattern(final String xsdRegex, final String unanchoredJavaRegex) {
- testPattern(xsdRegex, "^(?:" + unanchoredJavaRegex + ")$", ImmutableList.of(), ImmutableList.of());
+ testPattern(xsdRegex, "^(?:" + unanchoredJavaRegex + ")$", List.of(), List.of());
}
private static void testPattern(final String javaRegex, final List<String> positiveMatches,
final List<String> negativeMatches) {
- for (final String value : positiveMatches) {
- assertTrue("Value '" + value + "' does not match java regex '" + javaRegex + "'",
- testMatch(javaRegex, value));
+ for (var value : positiveMatches) {
+ assertTrue(testMatch(javaRegex, value),
+ "Value '" + value + "' does not match java regex '" + javaRegex + "'");
}
- for (final String value : negativeMatches) {
- assertFalse("Value '" + value + "' matches java regex '" + javaRegex + "'", testMatch(javaRegex, value));
+ for (var value : negativeMatches) {
+ assertFalse(testMatch(javaRegex, value), "Value '" + value + "' matches java regex '" + javaRegex + "'");
}
}
final String javaRegexFromXSD = RegexUtils.getJavaRegexFromXSD(xsdRegex);
assertEquals(expectedJavaRegex, javaRegexFromXSD);
- for (final String value : positiveMatches) {
- assertTrue("Value '" + value + "' does not match java regex '" + javaRegexFromXSD + "'",
- testMatch(javaRegexFromXSD, value));
+ for (var value : positiveMatches) {
+ assertTrue(testMatch(javaRegexFromXSD, value),
+ "Value '" + value + "' does not match java regex '" + javaRegexFromXSD + "'");
}
- for (final String value : negativeMatches) {
- assertFalse("Value '" + value + "' matches java regex '" + javaRegexFromXSD + "'",
- testMatch(javaRegexFromXSD, value));
+ for (var value : negativeMatches) {
+ assertFalse(testMatch(javaRegexFromXSD, value),
+ "Value '" + value + "' matches java regex '" + javaRegexFromXSD + "'");
}
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.google.common.collect.ImmutableList;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
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;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug5410Test extends AbstractYangTest {
+class Bug5410Test extends AbstractYangTest {
private static final String FOO_NS = "foo";
@Test
- public void testYangPattern() {
+ void testYangPattern() {
final var context = assertEffectiveModelDir("/bugs/bug5410");
final PatternConstraint pattern = getPatternConstraintOf(context, "leaf-with-pattern");
final String rawRegex = pattern.getRegularExpressionString();
final String expectedYangRegex = "$0$.*|$1$[a-zA-Z0-9./]{1,8}$[a-zA-Z0-9./]{22}|$5$(rounds=\\d+$)?"
- + "[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{43}|$6$(rounds=\\d+$)?[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{86}";
+ + "[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{43}|$6$(rounds=\\d+$)?[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{86}";
assertEquals(expectedYangRegex, rawRegex);
final String javaRegexFromYang = pattern.getJavaPatternString();
final String expectedJavaRegex = "^(?:\\$0\\$.*|\\$1\\$[a-zA-Z0-9./]{1,8}\\$[a-zA-Z0-9./]{22}|\\$5\\$"
- + "(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{43}|\\$6\\$(rounds=\\d+\\$)?"
- + "[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{86})$";
+ + "(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{43}|\\$6\\$(rounds=\\d+\\$)?"
+ + "[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{86})$";
assertEquals(expectedJavaRegex, javaRegexFromYang);
final String value = "$6$AnrKGc0V$B/0/A.pWg4HrrA6YiEJOtFGibQ9Fmm5.4rI/"
- + "00gEz3QeB7joSxBU3YtbHDm6NSkS1dKTQy3BWhwKKDS8nB5S//";
- testPattern(javaRegexFromYang, ImmutableList.of(value), ImmutableList.of());
+ + "00gEz3QeB7joSxBU3YtbHDm6NSkS1dKTQy3BWhwKKDS8nB5S//";
+ testPattern(javaRegexFromYang, List.of(value), List.of());
}
private static PatternConstraint getPatternConstraintOf(final SchemaContext context, final String leafName) {
- final DataSchemaNode dataChildByName = context.getDataChildByName(foo(leafName));
- assertTrue(dataChildByName instanceof LeafSchemaNode);
- final LeafSchemaNode leaf = (LeafSchemaNode) dataChildByName;
- final TypeDefinition<? extends TypeDefinition<?>> type = leaf.getType();
- assertTrue(type instanceof StringTypeDefinition);
- final StringTypeDefinition strType = (StringTypeDefinition) type;
+ final LeafSchemaNode leaf = assertInstanceOf(LeafSchemaNode.class, context.getDataChildByName(foo(leafName)));
+ final StringTypeDefinition strType = assertInstanceOf(StringTypeDefinition.class, leaf.getType());
return strType.getPatternConstraints().iterator().next();
}
private static void testPattern(final String javaRegex, final List<String> positiveMatches,
final List<String> negativeMatches) {
- for (final String value : positiveMatches) {
- assertTrue("Value '" + value + "' does not match java regex '" + javaRegex + "'", value.matches(javaRegex));
+ for (var value : positiveMatches) {
+ assertTrue(value.matches(javaRegex), "Value '" + value + "' does not match java regex '" + javaRegex + "'");
}
- for (final String value : negativeMatches) {
- assertFalse("Value '" + value + "' matches java regex '" + javaRegex + "'", value.matches(javaRegex));
+ for (var value : negativeMatches) {
+ assertFalse(value.matches(javaRegex), "Value '" + value + "' matches java regex '" + javaRegex + "'");
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class YT826Test extends AbstractYangTest {
+class YT826Test extends AbstractYangTest {
@Test
- public void testWhenExpressionWhitespace() {
+ void testWhenExpressionWhitespace() {
assertEffectiveModel("/bugs/yangtools826/example.yang");
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class ElementCountConstraintsTest extends AbstractYangTest {
+class ElementCountConstraintsTest extends AbstractYangTest {
@Test
- public void testElementCountConstraints() {
+ void testElementCountConstraints() {
final var context = assertEffectiveModel("/constraint-definitions-test/foo.yang");
final Module testModule = context.findModule("foo", Revision.of("2016-09-20")).get();
final LeafListSchemaNode constrainedLeafList1 = (LeafListSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "constrained-leaf-list-1"));
+ QName.create(testModule.getQNameModule(), "constrained-leaf-list-1"));
ElementCountConstraint constraints1 = constrainedLeafList1.getElementCountConstraint().get();
final LeafListSchemaNode constrainedLeafList2 = (LeafListSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "constrained-leaf-list-2"));
+ QName.create(testModule.getQNameModule(), "constrained-leaf-list-2"));
ElementCountConstraint constraints2 = constrainedLeafList2.getElementCountConstraint().get();
assertEquals(constraints1.hashCode(), constraints2.hashCode());
assertEquals(constraints1, constraints2);
final LeafListSchemaNode constrainedLeafList3 = (LeafListSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "constrained-leaf-list-3"));
+ QName.create(testModule.getQNameModule(), "constrained-leaf-list-3"));
ElementCountConstraint constraints3 = constrainedLeafList3.getElementCountConstraint().get();
assertNotEquals(constraints2.hashCode(), constraints3.hashCode());
assertNotEquals(constraints2, constraints3);
final LeafListSchemaNode constrainedLeafList4 = (LeafListSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "constrained-leaf-list-4"));
+ QName.create(testModule.getQNameModule(), "constrained-leaf-list-4"));
ElementCountConstraint constraints4 = constrainedLeafList4.getElementCountConstraint().get();
assertNotEquals(constraints3.hashCode(), constraints4.hashCode());
* 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.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class ActionStatementTest extends AbstractYangTest {
+class ActionStatementTest extends AbstractYangTest {
private static final String FOO_NS = "foo-namespace";
private static final String FOO_REV = "2016-12-13";
@Test
- public void testActionStatementInDataContainers() throws Exception {
+ void testActionStatementInDataContainers() throws Exception {
final var context = assertEffectiveModel("/rfc7950/action-stmt/foo.yang");
assertContainsActions(context, "root", "grp-action", "aug-action");
private static void assertContainsActions(final SchemaContext schemaContext, final String dataContainerName,
final String... actionNames) {
final DataSchemaNode dataChildByName = schemaContext.getDataChildByName(QName.create(FOO_NS, FOO_REV,
- dataContainerName));
- assertTrue(dataChildByName instanceof ActionNodeContainer);
- assertContainsActions((ActionNodeContainer) dataChildByName, actionNames);
+ dataContainerName));
+ assertContainsActions(assertInstanceOf(ActionNodeContainer.class, dataChildByName), actionNames);
}
private static void assertContainsActions(final ActionNodeContainer actionContainer,
}
@Test
- public void testActionUnsupportedInYang10() {
+ void testActionUnsupportedInYang10() {
assertSourceException(startsWith("action is not a YANG statement or use of extension"),
- "/rfc7950/action-stmt/foo10.yang");
+ "/rfc7950/action-stmt/foo10.yang");
}
@Test
- public void testActionWithinIllegalAncestor() {
+ void testActionWithinIllegalAncestor() {
assertSourceException(startsWith("Action (foo-namespace?revision=2016-12-13)action-in-grouping is defined"
- + " within a notification, rpc or another action"), "/rfc7950/action-stmt/foo-invalid.yang");
+ + " within a notification, rpc or another action"), "/rfc7950/action-stmt/foo-invalid.yang");
}
@Test
- public void testActionWithinListWithoutKey() {
+ void testActionWithinListWithoutKey() {
assertSourceException(startsWith("Action (bar-namespace?revision=2016-12-13)my-action is defined within a list"
- + " that has no key statement"), "/rfc7950/action-stmt/bar-invalid.yang");
+ + " that has no key statement"), "/rfc7950/action-stmt/bar-invalid.yang");
}
@Test
- public void testActionInUsedGroupingWithinCase() {
+ void testActionInUsedGroupingWithinCase() {
assertSourceException(startsWith("Action (baz-namespace?revision=2016-12-13)action-in-grouping"
- + " is defined within a case statement"), "/rfc7950/action-stmt/baz-invalid.yang");
+ + " is defined within a case statement"), "/rfc7950/action-stmt/baz-invalid.yang");
}
@Test
- public void testActionInUsedGroupingAtTopLevelOfModule() {
+ void testActionInUsedGroupingAtTopLevelOfModule() {
assertSourceException(startsWith("Action (foobar-namespace?revision=2016-12-13)my-action is defined"
- + " at the top level of a module"), "/rfc7950/action-stmt/foobar-invalid.yang");
+ + " at the top level of a module"), "/rfc7950/action-stmt/foobar-invalid.yang");
}
}
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.spi.meta.InvalidSubstatementException;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6867BasicTest extends AbstractYangTest {
+class Bug6867BasicTest extends AbstractYangTest {
@Test
- public void valid10Test() {
+ void valid10Test() {
assertEffectiveModel("/rfc7950/basic-test/valid-10.yang");
}
@Test
- public void valid11Test() {
+ void valid11Test() {
assertEffectiveModel("/rfc7950/basic-test/valid-11.yang");
}
@Test
- public void invalid10Test() {
+ void invalid10Test() {
assertException(InvalidSubstatementException.class, startsWith("NOTIFICATION is not valid for CONTAINER"),
"/rfc7950/basic-test/invalid-10.yang");
}
@Test
- public void invalid11Test() {
+ void invalid11Test() {
assertException(InvalidSubstatementException.class, startsWith("RPC is not valid for CONTAINER"),
"/rfc7950/basic-test/invalid-11.yang");
}
@Test
- public void anyData11Test() {
+ void anyData11Test() {
assertEffectiveModel("/rfc7950/basic-test/anydata-11.yang");
}
@Test
- public void anyData10Test() {
+ void anyData10Test() {
assertSourceException(startsWith("anydata is not a YANG statement or use of extension"),
"/rfc7950/basic-test/anydata-10.yang");
}
@Test
- public void yangModelTest() {
+ void yangModelTest() {
assertEffectiveModelDir("/rfc7950/model");
}
@Test
- public void unsupportedVersionTest() {
+ void unsupportedVersionTest() {
assertSourceException(startsWith("Unsupported YANG version 2.3"),
"/rfc7950/basic-test/unsupported-version.yang");
}
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-public class Bug6868Test extends AbstractYangTest {
+class Bug6868Test extends AbstractYangTest {
private static final String FOO_NS = "foo";
private static final String IMP_NS = "imp";
private static final String IMP_REV = "2017-01-09";
- private static final Set<String> ALL_CONTAINERS = ImmutableSet.of("my-container-1", "my-container-2",
- "my-container-3", "foo", "not-foo", "imp-bar", "imp-bar-2");
+ private static final Set<String> ALL_CONTAINERS = Set.of("my-container-1", "my-container-2",
+ "my-container-3", "foo", "not-foo", "imp-bar", "imp-bar-2");
@Test
- public void ifFeatureYang11ResolutionTest() throws Exception {
+ void ifFeatureYang11ResolutionTest() throws Exception {
assertSchemaContextFor(null, ALL_CONTAINERS);
- assertSchemaContextFor(ImmutableSet.of(), ImmutableSet.of("my-container-1", "my-container-2", "not-foo"));
- assertSchemaContextFor(ImmutableSet.of("foo"), ImmutableSet.of("foo"));
- assertSchemaContextFor(ImmutableSet.of("baz"),
- ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "not-foo"));
- assertSchemaContextFor(ImmutableSet.of("bar", "baz"),
- ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "not-foo"));
- assertSchemaContextFor(ImmutableSet.of("foo", "bar", "baz"),
- ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "foo"));
- assertSchemaContextFor(ImmutableSet.of("foo", "bar", "baz", "imp:bar"),
- ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "foo", "imp-bar"));
- assertSchemaContextFor(ImmutableSet.of("foo", "baz", "imp:bar"),
- ImmutableSet.of("foo", "imp-bar", "imp-bar-2"));
+ assertSchemaContextFor(Set.of(), Set.of("my-container-1", "my-container-2", "not-foo"));
+ assertSchemaContextFor(Set.of("foo"), Set.of("foo"));
+ assertSchemaContextFor(Set.of("baz"), Set.of("my-container-1", "my-container-2", "my-container-3", "not-foo"));
+ assertSchemaContextFor(Set.of("bar", "baz"),
+ Set.of("my-container-1", "my-container-2", "my-container-3", "not-foo"));
+ assertSchemaContextFor(Set.of("foo", "bar", "baz"),
+ Set.of("my-container-1", "my-container-2", "my-container-3", "foo"));
+ assertSchemaContextFor(Set.of("foo", "bar", "baz", "imp:bar"),
+ Set.of("my-container-1", "my-container-2", "my-container-3", "foo", "imp-bar"));
+ assertSchemaContextFor(Set.of("foo", "baz", "imp:bar"),
+ Set.of("foo", "imp-bar", "imp-bar-2"));
}
private static void assertSchemaContextFor(final Set<String> supportedFeatures,
final Set<String> expectedContainers) throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6868/yang11",
+ final var schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6868/yang11",
supportedFeatures != null ? createFeaturesSet(supportedFeatures) : null, YangParserConfiguration.DEFAULT);
assertNotNull(schemaContext);
- for (final String expectedContainer : expectedContainers) {
+ for (var expectedContainer : expectedContainers) {
assertThat(String.format("Expected container %s not found.", expectedContainer),
- schemaContext.findDataTreeChild(QName.create(FOO_NS, expectedContainer)).get(),
- instanceOf(ContainerSchemaNode.class));
+ schemaContext.findDataTreeChild(QName.create(FOO_NS, expectedContainer)).get(),
+ instanceOf(ContainerSchemaNode.class));
}
- final Set<String> unexpectedContainers = Sets.difference(ALL_CONTAINERS, expectedContainers);
- for (final String unexpectedContainer : unexpectedContainers) {
- assertEquals(String.format("Unexpected container %s.", unexpectedContainer), Optional.empty(),
- schemaContext.findDataTreeChild(QName.create(FOO_NS, unexpectedContainer)));
+ for (var unexpectedContainer : Sets.difference(ALL_CONTAINERS, expectedContainers)) {
+ assertEquals(Optional.empty(),
+ schemaContext.findDataTreeChild(QName.create(FOO_NS, unexpectedContainer)),
+ String.format("Unexpected container %s.", unexpectedContainer));
}
}
private static Set<QName> createFeaturesSet(final Set<String> featureNames) {
final Set<QName> supportedFeatures = new HashSet<>();
- for (final String featureName : featureNames) {
+ for (var featureName : featureNames) {
if (featureName.indexOf(':') == -1) {
supportedFeatures.add(QName.create(FOO_NS, featureName));
} else {
supportedFeatures
- .add(QName.create(IMP_NS, IMP_REV, featureName.substring(featureName.indexOf(':') + 1)));
+ .add(QName.create(IMP_NS, IMP_REV, featureName.substring(featureName.indexOf(':') + 1)));
}
}
- return ImmutableSet.copyOf(supportedFeatures);
+ return Set.copyOf(supportedFeatures);
}
@Test
- public void invalidYang10Test() {
+ void invalidYang10Test() {
assertSourceException(startsWith("Invalid identifier '(not foo) or (bar and baz)' [at "),
- "/rfc7950/bug6868/invalid10.yang");
+ "/rfc7950/bug6868/invalid10.yang");
}
-}
\ No newline at end of file
+}
*/
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.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-public class Bug6869Test extends AbstractYangTest {
+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 identityNoFeaureTest() throws Exception {
- final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6869/foo.yang",
- ImmutableSet.of());
+ void identityNoFeaureTest() throws Exception {
+ final var schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6869/foo.yang", Set.of());
assertNotNull(schemaContext);
- final Collection<? extends IdentitySchemaNode> identities = getIdentities(schemaContext);
+ final var identities = getIdentities(schemaContext);
assertEquals(0, identities.size());
- final DataSchemaNode findNode = schemaContext.findDataTreeChild(ROOT, GRP_LEAF).orElse(null);
- assertThat(findNode, instanceOf(LeafSchemaNode.class));
- final LeafSchemaNode grpLeaf = (LeafSchemaNode) findNode;
+ final LeafSchemaNode grpLeaf = assertInstanceOf(LeafSchemaNode.class,
+ schemaContext.findDataTreeChild(ROOT, GRP_LEAF).orElseThrow());
assertFalse(grpLeaf.isMandatory());
}
@Test
- public void identityAllFeauresTest() throws Exception {
- final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6869/foo.yang",
- createFeaturesSet("identity-feature", "mandatory-leaf", "tls", "ssh", "two", "three"));
+ void identityAllFeauresTest() throws Exception {
+ final var schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6869/foo.yang",
+ createFeaturesSet("identity-feature", "mandatory-leaf", "tls", "ssh", "two", "three"));
assertNotNull(schemaContext);
- final Collection<? extends IdentitySchemaNode> identities = getIdentities(schemaContext);
+ final var identities = getIdentities(schemaContext);
assertEquals(1, identities.size());
- final DataSchemaNode findNode = schemaContext.findDataTreeChild(ROOT, GRP_LEAF).orElse(null);
- assertThat(findNode, instanceOf(LeafSchemaNode.class));
- final LeafSchemaNode grpLeaf = (LeafSchemaNode) findNode;
+ final LeafSchemaNode grpLeaf = assertInstanceOf(LeafSchemaNode.class,
+ schemaContext.findDataTreeChild(ROOT, GRP_LEAF).orElseThrow());
assertTrue(grpLeaf.isMandatory());
}
private static Collection<? extends IdentitySchemaNode> getIdentities(final EffectiveModelContext schemaContext) {
- final Collection<? extends Module> modules = schemaContext.getModules();
+ final var modules = schemaContext.getModules();
assertEquals(1, modules.size());
final Module module = modules.iterator().next();
return module.getIdentities();
}
@Test
- public void invalidYang10Test() {
+ void invalidYang10Test() {
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.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import java.util.List;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.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.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.ModifierKind;
-import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6870Test extends AbstractYangTest {
+class Bug6870Test extends AbstractYangTest {
@Test
- public void valid11Test() {
+ void valid11Test() {
final var context = assertEffectiveModel("/rfc7950/bug6870/foo.yang");
assertModifier(context, ModifierKind.INVERT_MATCH, QName.create("foo", "root"), QName.create("foo", "my-leaf"));
assertModifier(context, null, QName.create("foo", "root"), QName.create("foo", "my-leaf-2"));
private static void assertModifier(final EffectiveModelContext schemaContext,
final ModifierKind expectedModifierKind, final QName... qnames) {
final DataSchemaNode findNode = schemaContext.findDataTreeChild(qnames).orElseThrow();
- assertThat(findNode, instanceOf(LeafSchemaNode.class));
- final LeafSchemaNode myLeaf = (LeafSchemaNode) findNode;
+ final LeafSchemaNode myLeaf = assertInstanceOf(LeafSchemaNode.class, findNode);
- final TypeDefinition<? extends TypeDefinition<?>> type = myLeaf.getType();
- assertThat(type, instanceOf(StringTypeDefinition.class));
- final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
+ final var type = myLeaf.getType();
+ final var patternConstraints = assertInstanceOf(StringTypeDefinition.class, type).getPatternConstraints();
assertEquals(1, patternConstraints.size());
assertEquals(Optional.ofNullable(expectedModifierKind), patternConstraints.iterator().next().getModifier());
}
@Test
- public void invalid11Test() {
+ void invalid11Test() {
assertSourceException(startsWith("'Invert-match' is not valid argument of modifier statement"),
"/rfc7950/bug6870/invalid11.yang");
}
@Test
- public void invalid10Test() {
+ void invalid10Test() {
assertSourceException(startsWith("modifier is not a YANG statement or use of extension"),
"/rfc7950/bug6870/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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.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.RpcDefinition;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6871Test extends AbstractYangTest {
+class Bug6871Test extends AbstractYangTest {
@Test
- public void testValidYang11Model() {
+ void testValidYang11Model() {
final Module foo = assertEffectiveModel("/rfc7950/bug6871/foo.yang")
.findModule("foo", Revision.of("2016-12-14")).orElseThrow();
}
@Test
- public void testInvalidYang10Model() {
+ 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");
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6874Test extends AbstractYangTest {
+class Bug6874Test extends AbstractYangTest {
private static final StatementStreamSource ROOT_MODULE = sourceForResource(
"/rfc7950/include-import-stmt-test/valid-11/root-module.yang");
private static final StatementStreamSource CHILD_MODULE = sourceForResource(
"/rfc7950/include-import-stmt-test/valid-11/imported-module.yang");
@Test
- public void valid11Test() {
+ void valid11Test() {
final var schemaContext = assertEffectiveModelDir("/rfc7950/include-import-stmt-test/valid-11");
// Test for valid include statement
}
@Test
- public void invalid10IncludeStmtTest() {
+ void invalid10IncludeStmtTest() {
assertInvalidSubstatementExceptionDir("/rfc7950/include-import-stmt-test/invalid-include-10", anyOf(
startsWith("DESCRIPTION is not valid for INCLUDE"),
startsWith("REFERENCE is not valid for INCLUDE")));
}
@Test
- public void invalid10ImportStmtTest() {
+ void invalid10ImportStmtTest() {
assertInvalidSubstatementExceptionDir("/rfc7950/include-import-stmt-test/invalid-import-10", anyOf(
startsWith("DESCRIPTION is not valid for IMPORT"),
startsWith("REFERENCE is not valid for IMPORT")));
}
@Test
- public void descriptionAndReferenceTest11() throws ReactorException {
+ void descriptionAndReferenceTest11() throws ReactorException {
RFC7950Reactors.defaultReactor().newBuild()
.addSources(ROOT_MODULE, CHILD_MODULE, CHILD_MODULE_1, IMPORTED_MODULE)
- .build().getRootStatements().forEach(declaredStmt -> {
+ .build()
+ .getRootStatements()
+ .forEach(declaredStmt -> {
if (declaredStmt instanceof ModuleStatement) {
declaredStmt.declaredSubstatements().forEach(subStmt -> {
if (subStmt instanceof IncludeStatement && "child-module".equals(subStmt.rawArgument())) {
*/
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.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
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.stmt.AbstractYangTest;
-public class Bug6876Test extends AbstractYangTest {
+class Bug6876Test extends AbstractYangTest {
@Test
- public void yang11Test() {
+ void yang11Test() {
final var context = assertEffectiveModelDir("/rfc7950/bug6876/yang11");
DataSchemaNode node = context.findDataTreeChild(bar("augment-target"), bar("my-leaf")).orElse(null);
- assertThat(node, instanceOf(LeafSchemaNode.class));
+ assertInstanceOf(LeafSchemaNode.class, node);
node = context.findDataTreeChild(bar("augment-target"), foo("mandatory-leaf")).orElse(null);
- assertThat(node, instanceOf(LeafSchemaNode.class));
+ assertInstanceOf(LeafSchemaNode.class, node);
}
@Test
- public void yang10Test() {
+ void yang10Test() {
assertInferenceExceptionDir("/rfc7950/bug6876/yang10", startsWith(
"An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
}
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6878Test extends AbstractYangTest {
+class Bug6878Test extends AbstractYangTest {
@Test
- public void testParsingXPathWithYang11Functions() {
+ void testParsingXPathWithYang11Functions() {
final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo.yang");
assertFalse(testLog.contains("Could not find function: "));
}
@Test
- public void shouldLogInvalidYang10XPath() {
+ 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() {
+ void shouldLogInvalidYang10XPath2() {
final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid-2.yang");
assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
}
*/
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.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import java.util.Collection;
-import org.junit.Test;
+import java.util.Set;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6880Test extends AbstractYangTest {
+class Bug6880Test extends AbstractYangTest {
@Test
- public void valid10Test() {
+ void valid10Test() {
final var context = assertEffectiveModel("/rfc7950/bug6880/foo.yang");
-
- final DataSchemaNode findDataSchemaNode = context.findDataTreeChild(QName.create("foo", "my-leaf-list"))
- .orElse(null);
- assertThat(findDataSchemaNode, instanceOf(LeafListSchemaNode.class));
- final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
-
- final Collection<? extends Object> defaults = myLeafList.getDefaults();
- assertEquals(2, defaults.size());
- assertTrue(defaults.contains("my-default-value-1") && defaults.contains("my-default-value-2"));
+ final var myLeafList = assertInstanceOf(LeafListSchemaNode.class,
+ context.findDataTreeChild(QName.create("foo", "my-leaf-list")).orElseThrow());
+ assertEquals(Set.of("my-default-value-1", "my-default-value-2"), myLeafList.getDefaults());
}
@Test
- public void invalid10Test() {
+ void invalid10Test() {
assertInvalidSubstatementException(startsWith("DEFAULT is not valid for LEAF_LIST"),
- "/rfc7950/bug6880/invalid10.yang");
+ "/rfc7950/bug6880/invalid10.yang");
}
}
\ No newline at end of file
* 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.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Arrays;
import java.util.Optional;
-import java.util.stream.Collectors;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6883Test extends AbstractYangTest {
+class Bug6883Test extends AbstractYangTest {
private static final XMLNamespace FOO = XMLNamespace.of("foo");
private ModuleEffectiveStatement foo;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
foo = assertEffectiveModelDir("/bugs/bug6883").getModuleStatement(QName.create(FOO, "foo"));
}
@Test
- public void test() throws Exception {
- final AnydataSchemaNode topAnyData = assertAnyData("top");
+ void test() throws Exception {
+ final var topAnyData = assertAnyData("top");
assertEquals(Status.DEPRECATED, topAnyData.getStatus());
assertEquals(Optional.of("top anydata"), topAnyData.getDescription());
}
private AnydataSchemaNode assertAnyData(final String... names) {
- final SchemaTreeEffectiveStatement<?> stmt = foo.findSchemaTreeNode(Arrays.stream(names)
- .map(name -> QName.create(FOO, name))
- .collect(Collectors.toList()))
- .orElse(null);
- assertThat(stmt, instanceOf(AnydataSchemaNode.class));
- return (AnydataSchemaNode) stmt;
+ return assertInstanceOf(AnydataSchemaNode.class,
+ foo.findSchemaTreeNode(Arrays.stream(names).map(name -> QName.create(FOO, name)).toList()).orElseThrow());
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6884Test extends AbstractYangTest {
+class Bug6884Test extends AbstractYangTest {
@Test
- public void testYang11() {
+ void testYang11() {
final var schemaContext = assertEffectiveModelDir("/rfc7950/bug6884/yang1-1");
final DataSchemaNode node = schemaContext.findDataTreeChild(foo("sub-root"), foo("sub-foo-2-con")).orElse(null);
- assertThat(node, instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class, node);
}
@Test
- public void testCircularIncludesYang10() {
+ void testCircularIncludesYang10() {
final var schemaContext = assertEffectiveModelDir("/rfc7950/bug6884/circular-includes");
DataSchemaNode node = schemaContext.findDataTreeChild(foo("sub-root"), foo("sub-foo-2-con")).orElse(null);
- assertThat(node, instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class, node);
node = schemaContext.findDataTreeChild(foo("sub-root-2"), foo("sub-foo-con")).orElse(null);
- assertThat(node, instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class, node);
}
private static QName foo(final String localName) {
* 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.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6885Test extends AbstractYangTest {
-
+class Bug6885Test extends AbstractYangTest {
@Test
- public void validYang10Test() {
+ void validYang10Test() {
// Yang 1.0 allows "if-feature" and "when" on list keys
assertEffectiveModel("/rfc7950/list-keys-test/correct-list-keys-test.yang");
}
@Test
- public void invalidListLeafKeyTest1() {
+ 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.";
+ + "(incorrect-list-keys-test?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test.yang");
}
@Test
- public void invalidListLeafKeyTest2() {
+ 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.";
+ + "(incorrect-list-keys-test1?revision=2017-02-06)b leaf statement which is specified as a list key.";
assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test1.yang");
}
@Test
- public void invalidListUsesLeafKeyTest() {
+ 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.";
+ + "(incorrect-list-keys-test2?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test2.yang");
}
@Test
- public void invalidListUsesLeafKeyTest1() {
+ 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.";
+ + "(incorrect-list-keys-test3?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test3.yang");
}
@Test
- public void invalidListUsesLeafKeyTest2() {
+ 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.";
+ + "(incorrect-list-keys-test4?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test4.yang");
}
@Test
- public void invalidListUsesRefineLeafKeyTest() {
+ 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.";
+ + "(incorrect-list-keys-test5?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test5.yang");
}
}
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6886Test extends AbstractYangTest {
+class Bug6886Test extends AbstractYangTest {
@Test
- public void yang11UnquotedStrTest() {
+ void yang11UnquotedStrTest() {
assertSourceException(startsWith("YANG 1.1: unquoted string (illegalchars\"test1) contains illegal characters"),
"/rfc7950/bug6886/yang11/foo.yang");
}
@Test
- public void yang11UnquotedStrTest2() {
+ void yang11UnquotedStrTest2() {
assertSourceException(startsWith("YANG 1.1: unquoted string (illegalchars'test2) contains illegal characters"),
"/rfc7950/bug6886/yang11/foo2.yang");
}
@Test
- public void yang11DoubleQuotedStrTest() {
+ void yang11DoubleQuotedStrTest() {
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'."),
}
@Test
- public void yang10UnquotedStrTest() {
+ void yang10UnquotedStrTest() {
assertEffectiveModel("/rfc7950/bug6886/yang10/foo.yang");
}
@Test
- public void yang10UnquotedStrTest2() {
+ void yang10UnquotedStrTest2() {
assertEffectiveModel("/rfc7950/bug6886/yang10/foo2.yang");
}
@Test
- public void yang10DoubleQuotedStrTest() {
+ void yang10DoubleQuotedStrTest() {
assertEffectiveModel("/rfc7950/bug6886/yang10/foo3.yang");
}
}
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.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.ri.type.EnumPairBuilder;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6887Test extends AbstractYangTest {
+class Bug6887Test extends AbstractYangTest {
@Test
- public void testRestrictedEnumeration() {
+ void testRestrictedEnumeration() {
final var context = assertEffectiveModel("/rfc7950/bug6887/foo.yang");
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"));
+ QName.create(foo.getQNameModule(), "my-enumeration-leaf"));
EnumTypeDefinition enumerationType = (EnumTypeDefinition) myEnumerationLeaf.getType();
assertContainsEnums(enums, whiteEnum, yellowEnum, redEnum, blackEnum);
final LeafSchemaNode myEnumerationLeaf2 = (LeafSchemaNode) foo.getDataChildByName(
- QName.create(foo.getQNameModule(), "my-enumeration-leaf-2"));
+ QName.create(foo.getQNameModule(), "my-enumeration-leaf-2"));
enumerationType = (EnumTypeDefinition) myEnumerationLeaf2.getType();
enums = enumerationType.getValues();
}
@Test
- public void testInvalidRestrictedEnumeration() {
+ void testInvalidRestrictedEnumeration() {
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");
+ + "(foo?revision=2017-02-02)my-derived-enumeration-type."), "/rfc7950/bug6887/foo-invalid.yang");
}
@Test
- public void testInvalidRestrictedEnumeration2() {
+ void testInvalidRestrictedEnumeration2() {
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");
+ + "(foo?revision=2017-02-02)my-base-enumeration-type."), "/rfc7950/bug6887/foo-invalid-2.yang");
}
@Test
- public void testInvalidRestrictedEnumeration3() {
+ void testInvalidRestrictedEnumeration3() {
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");
+ + "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() {
+ void testInvalidRestrictedEnumeration4() {
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");
+ + "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() {
+ void testValidYang10EnumerationWithUnknownStatements() {
assertEffectiveModel("/rfc7950/bug6887/foo10-valid.yang");
}
@Test
- public void testInvalidYang10RestrictedEnumeration() {
+ void testInvalidYang10RestrictedEnumeration() {
assertSourceException(startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "),
- "/rfc7950/bug6887/foo10-invalid.yang");
+ "/rfc7950/bug6887/foo10-invalid.yang");
}
@Test
- public void testInvalidYang10RestrictedEnumeration2() {
+ void testInvalidYang10RestrictedEnumeration2() {
assertSourceException(startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "),
- "/rfc7950/bug6887/foo10-invalid-2.yang");
+ "/rfc7950/bug6887/foo10-invalid-2.yang");
}
@Test
- public void testRestrictedBits() {
+ void testRestrictedBits() {
final var context = assertEffectiveModel("/rfc7950/bug6887/bar.yang");
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"));
+ QName.create(bar.getQNameModule(), "my-bits-leaf"));
BitsTypeDefinition bitsType = (BitsTypeDefinition) myBitsLeaf.getType();
assertContainsBits(bits, bitA, bitB, bitC, bitD);
final LeafSchemaNode myBitsLeaf2 = (LeafSchemaNode) bar.getDataChildByName(
- QName.create(bar.getQNameModule(), "my-bits-leaf-2"));
+ QName.create(bar.getQNameModule(), "my-bits-leaf-2"));
bitsType = (BitsTypeDefinition) myBitsLeaf2.getType();
bits = bitsType.getBits();
}
@Test
- public void testInvalidRestrictedBits() {
+ void testInvalidRestrictedBits() {
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");
+ + "(bar?revision=2017-02-02)my-derived-bits-type."), "/rfc7950/bug6887/bar-invalid.yang");
}
@Test
- public void testInvalidRestrictedBits2() {
+ void testInvalidRestrictedBits2() {
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");
+ + "(bar?revision=2017-02-02)my-base-bits-type."), "/rfc7950/bug6887/bar-invalid-2.yang");
}
@Test
- public void testInvalidRestrictedBits3() {
+ void testInvalidRestrictedBits3() {
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");
+ + "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() {
+ void testInvalidRestrictedBits4() {
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");
+ + "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() {
+ void testValidYang10BitsWithUnknownStatements() {
assertEffectiveModel("/rfc7950/bug6887/bar10-valid.yang");
}
@Test
- public void testInvalidYang10RestrictedBits() {
+ void testInvalidYang10RestrictedBits() {
assertSourceException(startsWith("Restricted bits type is not allowed in YANG version 1 [at "),
- "/rfc7950/bug6887/bar10-invalid.yang");
+ "/rfc7950/bug6887/bar10-invalid.yang");
}
@Test
- public void testInvalidYang10RestrictedBits2() {
+ void testInvalidYang10RestrictedBits2() {
assertSourceException(startsWith("Restricted bits type is not allowed in YANG version 1 [at "),
- "/rfc7950/bug6887/bar10-invalid-2.yang");
+ "/rfc7950/bug6887/bar10-invalid-2.yang");
}
private static EnumPair createEnumPair(final String name, final int value) {
*/
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.hamcrest.collection.IsIn.in;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Collection;
import java.util.stream.Collectors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
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.stmt.AbstractYangTest;
-public class Bug6897Test extends AbstractYangTest {
+class Bug6897Test extends AbstractYangTest {
private static final String FOO_NS = "foo";
@Test
- public void notificationsInDataContainersTest() {
+ void notificationsInDataContainersTest() {
final var context = assertEffectiveModel("/rfc7950/notifications-in-data-nodes/foo.yang");
assertContainsNotifications(context, "root", "grp-notification", "aug-notification");
private static void assertContainsNotifications(final SchemaContext schemaContext, final String dataContainerName,
final String... notificationNames) {
- final DataSchemaNode dataChildByName = schemaContext.getDataChildByName(
- QName.create(FOO_NS, dataContainerName));
- assertThat(dataChildByName, instanceOf(NotificationNodeContainer.class));
- assertContainsNotifications((NotificationNodeContainer) dataChildByName, notificationNames);
+ final var dataChildByName = schemaContext.getDataChildByName(QName.create(FOO_NS, dataContainerName));
+ assertContainsNotifications(assertInstanceOf(NotificationNodeContainer.class, dataChildByName),
+ notificationNames);
}
private static void assertContainsNotifications(final NotificationNodeContainer notificationContainer,
}
@Test
- public void invalid10Test() {
+ void invalid10Test() {
assertInvalidSubstatementException(startsWith("NOTIFICATION is not valid for"),
"/rfc7950/notifications-in-data-nodes/foo10.yang");
}
@Test
- public void invalid11Test() {
+ void invalid11Test() {
assertSourceException(
startsWith("Notification (foo)grp-notification is defined within an rpc, action, or another notification"),
"/rfc7950/notifications-in-data-nodes/foo-invalid.yang");
}
@Test
- public void testNotificationWithinListWithoutKey() {
+ void testNotificationWithinListWithoutKey() {
assertSourceException(
startsWith("Notification (bar-namespace?revision=2016-12-08)my-notification is defined within a list that "
+ "has no key statement"),
}
@Test
- public void testNotificationInUsedGroupingWithinCase() {
+ void testNotificationInUsedGroupingWithinCase() {
assertSourceException(
startsWith("Notification (baz-namespace?revision=2016-12-08)notification-in-grouping is defined within a "
+ "case statement"),
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6901Test extends AbstractYangTest {
+class Bug6901Test extends AbstractYangTest {
@Test
- public void ifFeature11EnumBitTest() {
+ void ifFeature11EnumBitTest() {
assertEffectiveModel("/rfc7950/bug6901/foo.yang");
}
@Test
- public void ifFeatureOnDefaultValueEnumTest() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ void unsupportedFeatureTest() {
assertSourceException(containsString("has default value 'two' marked with an if-feature statement"),
"/rfc7950/bug6901/invalid-foo-enum.yang");
}
@Test
- public void ifFeature10EnumTest() {
+ void ifFeature10EnumTest() {
assertInvalidSubstatementException(startsWith("IF_FEATURE is not valid for ENUM"),
"/rfc7950/bug6901/invalid-foo-10-enum.yang");
}
@Test
- public void ifFeature10BitTest() {
+ void ifFeature10BitTest() {
assertInvalidSubstatementException(startsWith("IF_FEATURE is not valid for BIT"),
"/rfc7950/bug6901/invalid-foo-10-bit.yang");
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug9241Test extends AbstractYangTest {
+class Bug9241Test extends AbstractYangTest {
@Test
- public void testImplicitInputAndOutputInAction() {
+ void testImplicitInputAndOutputInAction() {
final var context = assertEffectiveModel("/rfc7950/bug9241/foo.yang");
final Module fooModule = context.findModule("foo", Revision.of("2017-10-13")).get();
final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(
- fooModule.getQNameModule(), "action-cont"));
+ fooModule.getQNameModule(), "action-cont"));
final ActionDefinition actionInCont = actionCont.getActions().iterator().next();
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class IdentityStatementTest extends AbstractYangTest {
+class IdentityStatementTest extends AbstractYangTest {
@Test
- public void testMultipleBaseIdentities() {
+ void testMultipleBaseIdentities() {
final var context = assertEffectiveModel("/rfc7950/identity-stmt/foo.yang");
final Module foo = context.findModule("foo", Revision.of("2016-12-21")).get();
}
@Test
- public void testInvalidYang10() {
+ void testInvalidYang10() {
assertInvalidSubstatementException(startsWith("Maximal count of BASE for IDENTITY is 1, detected 3."),
- "/rfc7950/identity-stmt/foo10.yang");
+ "/rfc7950/identity-stmt/foo10.yang");
}
}
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class IdentityrefStatementTest extends AbstractYangTest {
+class IdentityrefStatementTest extends AbstractYangTest {
@Test
- public void testIdentityrefWithMultipleBaseIdentities() {
+ void testIdentityrefWithMultipleBaseIdentities() {
final var context = assertEffectiveModel("/rfc7950/identityref-stmt/foo.yang");
final Module foo = context.findModule("foo", Revision.of("2017-01-11")).get();
assertEquals(3, identities.size());
final LeafSchemaNode idrefLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
- "idref-leaf"));
+ "idref-leaf"));
final IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) idrefLeaf.getType();
final var referencedIdentities = idrefType.getIdentities();
assertEquals(3, referencedIdentities.size());
}
@Test
- public void testInvalidYang10() {
+ void testInvalidYang10() {
assertInvalidSubstatementException(startsWith("Maximal count of BASE for TYPE is 1, detected 3."),
- "/rfc7950/identityref-stmt/foo10.yang");
+ "/rfc7950/identityref-stmt/foo10.yang");
}
}
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.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class LeafrefStatementTest extends AbstractYangTest {
+class LeafrefStatementTest extends AbstractYangTest {
@Test
- public void testRequireInstanceInLeafrefs() {
+ void testRequireInstanceInLeafrefs() {
final var context = assertEffectiveModel("/rfc7950/leafref-stmt/foo.yang");
final Module foo = context.findModule("foo", Revision.of("2016-12-20")).get();
assertTrue(leafrefTypeDefinition.requireInstance());
final LeafSchemaNode leafrefA = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
- "leafref-a"));
+ "leafref-a"));
assertRequireInstanceInLeafref(leafrefA, true);
final LeafSchemaNode leafrefB = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
- "leafref-b"));
+ "leafref-b"));
assertRequireInstanceInLeafref(leafrefB, true);
final LeafSchemaNode leafrefC = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
- "leafref-c"));
+ "leafref-c"));
assertRequireInstanceInLeafref(leafrefC, true);
}
}
@Test
- public void testInvalidYang10() {
+ void testInvalidYang10() {
assertInvalidSubstatementException(startsWith("REQUIRE_INSTANCE is not valid for TYPE"),
- "/rfc7950/leafref-stmt/foo10.yang");
+ "/rfc7950/leafref-stmt/foo10.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.eclipse.jdt.annotation.NonNull;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
static Module BAR;
static Module BAZ;
- @BeforeClass
- public static void beforeClass() throws Exception {
+ @BeforeAll
+ static void beforeClass() throws Exception {
CTX = assertEffectiveModelDir("/model");
assertEquals(3, CTX.getModules().size());
*/
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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.base.Throwables;
import java.util.Set;
final var ex = assertThrows(SomeModifiersUnresolvedException.class,
() -> TestUtils.parseYangSource(yangResourceName));
final var actual = ex.getCause();
- assertThat(actual, instanceOf(cause));
- return cause.cast(actual);
+ return assertInstanceOf(cause, actual);
}
public static <E extends SourceException> @NonNull E assertException(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);
+ return assertInstanceOf(cause, actual);
}
public static <E extends SourceException> @NonNull E assertExceptionDir(final String yangResourceName,
*/
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.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
-public class AugmentArgumentParsingTest {
+class AugmentArgumentParsingTest {
private static final StatementStreamSource IMPORTED = sourceForResource(
- "/semantic-statement-parser/augment-arg-parsing/imported.yang");
+ "/semantic-statement-parser/augment-arg-parsing/imported.yang");
private static final StatementStreamSource VALID_ARGS = sourceForResource(
- "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang");
+ "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang");
private static final StatementStreamSource INVALID_REL1 = sourceForResource(
- "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang");
+ "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang");
private static final StatementStreamSource INVALID_REL2 = sourceForResource(
- "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang");
+ "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang");
private static final StatementStreamSource INVALID_ABS = sourceForResource(
- "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang");
+ "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang");
private static final StatementStreamSource INVALID_ABS_PREFIXED_NO_IMP = sourceForResource(
- "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang");
+ "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang");
private static final StatementStreamSource INVALID_EMPTY = sourceForResource(
- "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang");
+ "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang");
private static final StatementStreamSource INVALID_XPATH = sourceForResource(
- "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang");
+ "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang");
@Test
- public void validAugAbsTest() throws ReactorException {
+ void validAugAbsTest() throws ReactorException {
final ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(IMPORTED, VALID_ARGS)
- .build();
+ .addSources(IMPORTED, VALID_ARGS)
+ .build();
assertNotNull(result);
}
@Test
- public void invalidAugRel1Test() {
+ void invalidAugRel1Test() {
assertSourceExceptionCause(assertReactorThrows(INVALID_REL1), "Augment argument './aug1/aug11' is not valid");
}
@Test
- public void invalidAugRel2Test() {
+ void invalidAugRel2Test() {
assertSourceExceptionCause(assertReactorThrows(INVALID_REL2), "Augment argument '../aug1/aug11' is not valid");
}
@Test
- public void invalidAugAbs() {
+ void invalidAugAbs() {
assertSourceExceptionCause(assertReactorThrows(INVALID_ABS),
"Augment argument '//aug1/aug11/aug111' is not valid");
}
@Test
- public void invalidAugAbsPrefixedNoImp() {
+ void invalidAugAbsPrefixedNoImp() {
assertSourceExceptionCause(assertReactorThrows(INVALID_ABS_PREFIXED_NO_IMP), "Failed to parse node 'imp:aug1'");
}
@Test
- public void invalidAugEmptyTest() throws ReactorException {
+ void invalidAugEmptyTest() throws ReactorException {
final ReactorException ex = assertReactorThrows(INVALID_EMPTY);
final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
+ assertInstanceOf(SourceException.class, cause);
assertThat(cause.getMessage(), startsWith("Schema node identifier must not be empty"));
}
@Test
- public void invalidAugXPathTest() throws ReactorException {
+ void invalidAugXPathTest() throws ReactorException {
final ReactorException ex = assertReactorThrows(INVALID_XPATH);
final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
+ assertInstanceOf(SourceException.class, cause);
assertThat(cause.getMessage(), startsWith("Failed to parse node '-' in path '/aug1/-'"));
final Throwable nested = cause.getCause();
- assertThat(nested, instanceOf(SourceException.class));
+ assertInstanceOf(SourceException.class, nested);
assertThat(nested.getMessage(), startsWith("Invalid identifier '-'"));
}
private static void assertSourceExceptionCause(final Throwable exception, final String start) {
final Throwable cause = exception.getCause();
- assertThat(cause, instanceOf(SourceException.class));
+ assertInstanceOf(SourceException.class, cause);
assertThat(cause.getMessage(), startsWith(start));
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-public class AugmentProcessTest extends AbstractYangTest {
+class AugmentProcessTest extends AbstractYangTest {
private static final StatementStreamSource AUGMENTED = sourceForResource("/stmt-test/augments/augmented.yang");
private static final StatementStreamSource ROOT = sourceForResource("/stmt-test/augments/aug-root.yang");
private static final QNameModule AUGMENTED_QNAME_MODULE = QNameModule.create(XMLNamespace.of("aug"));
private final QName augParent1 = QName.create(AUGMENTED_QNAME_MODULE,
- "aug-parent1");
+ "aug-parent1");
private final QName augParent2 = QName.create(AUGMENTED_QNAME_MODULE,
- "aug-parent2");
+ "aug-parent2");
private final QName contTarget = QName.create(AUGMENTED_QNAME_MODULE,
- "cont-target");
+ "cont-target");
private final QName contAdded1 = QName.create(ROOT_QNAME_MODULE,
- "cont-added1");
+ "cont-added1");
private final QName contAdded2 = QName.create(ROOT_QNAME_MODULE,
- "cont-added2");
+ "cont-added2");
private final QName list1 = QName.create(ROOT_QNAME_MODULE, "list1");
private final QName axml = QName.create(ROOT_QNAME_MODULE, "axml");
private final QName contGrp = QName.create(ROOT_QNAME_MODULE,
- "cont-grp");
+ "cont-grp");
private final QName axmlGrp = QName.create(ROOT_QNAME_MODULE,
- "axml-grp");
+ "axml-grp");
private final QName augCont1 = QName.create(ROOT_QNAME_MODULE, "aug-cont1");
private final QName augCont2 = QName.create(ROOT_QNAME_MODULE, "aug-cont2");
private final QName grpCont2 = QName.create(ROOT_QNAME_MODULE, "grp-cont2");
private final QName grpCont22 = QName.create(ROOT_QNAME_MODULE,
- "grp-cont22");
+ "grp-cont22");
private final QName grpAdd = QName.create(ROOT_QNAME_MODULE, "grp-add");
private static final StatementStreamSource MULTIPLE_AUGMENT = sourceForResource(
- "/stmt-test/augments/multiple-augment-test.yang");
+ "/stmt-test/augments/multiple-augment-test.yang");
private static final StatementStreamSource MULTIPLE_AUGMENT_ROOT = sourceForResource(
- "/stmt-test/augments/multiple-augment-root.yang");
+ "/stmt-test/augments/multiple-augment-root.yang");
private static final StatementStreamSource MULTIPLE_AUGMENT_IMPORTED = sourceForResource(
- "/stmt-test/augments/multiple-augment-imported.yang");
+ "/stmt-test/augments/multiple-augment-imported.yang");
private static final StatementStreamSource MULTIPLE_AUGMENT_SUBMODULE = sourceForResource(
- "/stmt-test/augments/multiple-augment-submodule.yang");
+ "/stmt-test/augments/multiple-augment-submodule.yang");
private static final StatementStreamSource MULTIPLE_AUGMENT_INCORRECT = sourceForResource(
- "/stmt-test/augments/multiple-augment-incorrect.yang");
+ "/stmt-test/augments/multiple-augment-incorrect.yang");
private static final StatementStreamSource MULTIPLE_AUGMENT_INCORRECT2 = sourceForResource(
- "/stmt-test/augments/multiple-augment-incorrect2.yang");
+ "/stmt-test/augments/multiple-augment-incorrect2.yang");
@Test
- public void multipleAugmentsAndMultipleModulesTest() throws ReactorException {
+ void multipleAugmentsAndMultipleModulesTest() throws ReactorException {
SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(MULTIPLE_AUGMENT_ROOT, MULTIPLE_AUGMENT_IMPORTED, MULTIPLE_AUGMENT_SUBMODULE)
- .buildEffective();
+ .addSources(MULTIPLE_AUGMENT_ROOT, MULTIPLE_AUGMENT_IMPORTED, MULTIPLE_AUGMENT_SUBMODULE)
+ .buildEffective();
assertNotNull(result);
}
@Test
- public void multipleAugmentTest() throws ReactorException {
+ void multipleAugmentTest() throws ReactorException {
SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(MULTIPLE_AUGMENT)
- .buildEffective();
+ .addSource(MULTIPLE_AUGMENT)
+ .buildEffective();
assertNotNull(result);
}
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void multipleAugmentIncorrectPathTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
+ @Test
+ void multipleAugmentIncorrectPathTest() throws ReactorException {
+ assertThrows(SomeModifiersUnresolvedException.class, () -> {
+ SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
.addSource(MULTIPLE_AUGMENT_INCORRECT)
.buildEffective();
- assertNull(result);
+ assertNull(result);
+ });
}
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void multipleAugmentIncorrectPathAndGrpTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
+ @Test
+ void multipleAugmentIncorrectPathAndGrpTest() throws ReactorException {
+ assertThrows(SomeModifiersUnresolvedException.class, () -> {
+ SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
.addSource(MULTIPLE_AUGMENT_INCORRECT2)
.buildEffective();
- assertNull(result);
+ assertNull(result);
+ });
}
@Test
- public void readAndParseYangFileTest() throws ReactorException {
+ void readAndParseYangFileTest() throws ReactorException {
final SchemaContext root = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(AUGMENTED, ROOT)
- .buildEffective();
+ .addSources(AUGMENTED, ROOT)
+ .buildEffective();
assertNotNull(root);
final Module augmentedModule = root.findModules("augmented").iterator().next();
}
@Test
- public void caseShortHandAugmentingTest() {
+ void caseShortHandAugmentingTest() {
final SchemaContext context = assertEffectiveModelDir("/choice-case-type-test-models");
assertNotNull(context);
final String nsAug = "urn:ietf:params:xml:ns:yang:augment-monitoring";
final ContainerSchemaNode netconf = (ContainerSchemaNode) context.getDataChildByName(QName.create(ns, rev,
- "netconf-state"));
+ "netconf-state"));
final ContainerSchemaNode datastores = (ContainerSchemaNode) netconf.getDataChildByName(QName.create(ns, rev,
- "datastores"));
+ "datastores"));
final ListSchemaNode datastore = (ListSchemaNode) datastores.getDataChildByName(QName.create(ns, rev,
- "datastore"));
+ "datastore"));
final ContainerSchemaNode locks = (ContainerSchemaNode) datastore.getDataChildByName(QName.create(ns, rev,
- "locks"));
+ "locks"));
final ChoiceSchemaNode lockType = (ChoiceSchemaNode) locks.getDataChildByName(QName
- .create(ns, rev, "lock-type"));
+ .create(ns, rev, "lock-type"));
final CaseSchemaNode leafAugCase = lockType.findCaseNodes("leaf-aug-case").iterator().next();
assertTrue(leafAugCase.isAugmenting());
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
-public class AugmentSimplestTest {
+class AugmentSimplestTest {
private static final StatementStreamSource AUGMENTED = sourceForResource(
"/semantic-statement-parser/augmented.yang");
private static final StatementStreamSource ROOT = sourceForResource("/semantic-statement-parser/root.yang");
@Test
- public void readAndParseYangFileTest() throws SourceException, ReactorException {
+ void readAndParseYangFileTest() throws SourceException, ReactorException {
ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(AUGMENTED, ROOT)
- .build();
+ .addSources(AUGMENTED, ROOT)
+ .build();
assertNotNull(result);
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
-public class AugmentTest extends AbstractYangTest {
+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(
private static EffectiveModelContext AUGMENT_IN_AUGMENT;
- @BeforeClass
- public static void beforeClass() throws Exception {
+ @BeforeAll
+ static void beforeClass() throws Exception {
AUGMENT_IN_AUGMENT = assertEffectiveModelDir("/augment-test/augment-in-augment");
}
@Test
- public void testAugmentParsing() {
+ void testAugmentParsing() {
// foo.yang
final Module module1 = AUGMENT_IN_AUGMENT.findModules("foo").iterator().next();
var augmentations = module1.getAugmentations();
}
final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName(QName.create(
- module1.getQNameModule(), "ds0ChannelNumber"));
+ module1.getQNameModule(), "ds0ChannelNumber"));
final LeafSchemaNode interfaceId = (LeafSchemaNode) augment.getDataChildByName(QName.create(
- module1.getQNameModule(), "interface-id"));
+ module1.getQNameModule(), "interface-id"));
final ContainerSchemaNode schemas = (ContainerSchemaNode) augment.getDataChildByName(QName.create(
- module1.getQNameModule(), "schemas"));
+ module1.getQNameModule(), "schemas"));
final ChoiceSchemaNode odl = (ChoiceSchemaNode) augment.getDataChildByName(QName.create(
- module1.getQNameModule(), "odl"));
+ module1.getQNameModule(), "odl"));
assertNotNull(ds0ChannelNumber);
assertNotNull(interfaceId);
assertEquals(1, augment1.getChildNodes().size());
final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment1.getDataChildByName(QName.create(
- module3.getQNameModule(), "augment-holder"));
+ module3.getQNameModule(), "augment-holder"));
assertNotNull(augmentHolder);
assertEquals(1, augment2.getChildNodes().size());
final ContainerSchemaNode augmentHolder2 = (ContainerSchemaNode) augment2.getDataChildByName(QName.create(
- module3.getQNameModule(), "augment-holder2"));
+ module3.getQNameModule(), "augment-holder2"));
assertNotNull(augmentHolder2);
assertEquals(1, augment3.getChildNodes().size());
final CaseSchemaNode pause = (CaseSchemaNode) augment3.getDataChildByName(QName.create(
- module3.getQNameModule(), "pause"));
+ module3.getQNameModule(), "pause"));
assertNotNull(pause);
}
@Test
- public void testAugmentResolving() {
+ void testAugmentResolving() {
final Module module2 = AUGMENT_IN_AUGMENT.findModules("bar").iterator().next();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
- module2.getQNameModule(), "interfaces"));
+ module2.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
- module2.getQNameModule(), "ifEntry"));
+ module2.getQNameModule(), "ifEntry"));
// baz.yang
// augment "/br:interfaces/br:ifEntry" {
final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(BAZ,
- "augment-holder"));
+ "augment-holder"));
checkIsAugmenting(augmentHolder, true);
assertEquals(Q2, augmentHolder.getQName());
// foo.yang
// augment "/br:interfaces/br:ifEntry/bz:augment-holder"
final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO,
- "ds0ChannelNumber"));
+ "ds0ChannelNumber"));
final LeafSchemaNode interfaceId = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO,
- "interface-id"));
+ "interface-id"));
final ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO,
- "schemas"));
+ "schemas"));
final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO, "odl"));
assertNotNull(ds0ChannelNumber);
}
@Test
- public void testAugmentedChoice() {
+ void testAugmentedChoice() {
final Module module2 = AUGMENT_IN_AUGMENT.findModules("bar").iterator().next();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
- module2.getQNameModule(), "interfaces"));
+ module2.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
- module2.getQNameModule(), "ifEntry"));
+ module2.getQNameModule(), "ifEntry"));
final ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(
- BAZ, "augment-holder"));
+ BAZ, "augment-holder"));
checkIsAugmenting(augmentedHolder, true);
// foo.yang
}
@Test
- public void testAugmentRpc() throws Exception {
+ void testAugmentRpc() throws Exception {
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 QName inputQName = QName.create(NS_BAR, revision, "input");
assertEquals(inputQName, input.getQName());
final ChoiceSchemaNode arguments = (ChoiceSchemaNode) input.getDataChildByName(QName.create(NS_BAR, revision,
- "arguments"));
+ "arguments"));
final QName argumentsQName = QName.create(NS_BAR, revision, "arguments");
assertEquals(argumentsQName, arguments.getQName());
assertFalse(arguments.isAugmenting());
}
@Test
- public void testAugmentInUsesResolving() throws Exception {
+ void testAugmentInUsesResolving() throws Exception {
final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/augment-in-uses");
assertEquals(1, context.getModules().size());
final Module test = context.getModules().iterator().next();
final DataNodeContainer links = (DataNodeContainer) test.getDataChildByName(QName.create(test.getQNameModule(),
- "links"));
+ "links"));
final DataNodeContainer link = (DataNodeContainer) links.getDataChildByName(QName.create(test.getQNameModule(),
- "link"));
+ "link"));
final DataNodeContainer nodes = (DataNodeContainer) link.getDataChildByName(QName.create(test.getQNameModule(),
- "nodes"));
+ "nodes"));
final ContainerSchemaNode node = (ContainerSchemaNode) nodes.getDataChildByName(QName.create(
- test.getQNameModule(), "node"));
+ test.getQNameModule(), "node"));
final var augments = node.getAvailableAugmentations();
assertEquals(1, augments.size());
assertEquals(1, node.getChildNodes().size());
package org.opendaylight.yangtools.yang.stmt;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
-public class AugmentToExtensionTest extends AbstractYangTest {
+class AugmentToExtensionTest extends AbstractYangTest {
@Test
- public void testIncorrectPath() throws Exception {
+ void testIncorrectPath() throws Exception {
assertInferenceExceptionDir("/augment-to-extension-test/incorrect-path",
startsWith("Augment target "
- + "'Descendant{qnames=[(uri:augment-module?revision=2014-10-07)my-extension-name-a, input]}'"
- + " not found [at "));
+ + "'Descendant{qnames=[(uri:augment-module?revision=2014-10-07)my-extension-name-a, input]}'"
+ + " not found [at "));
}
/*
* FIXME: Figure way to determine use case of tail-f:input without hacks
*/
@Test
- public void testCorrectPathIntoUnsupportedTarget() throws Exception {
+ void testCorrectPathIntoUnsupportedTarget() throws Exception {
final Module devicesModule =
assertEffectiveModelDir("/augment-to-extension-test/correct-path-into-unsupported-target")
- .findModules("augment-module").iterator().next();
+ .findModules("augment-module").iterator().next();
final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(
QName.create(devicesModule.getQNameModule(), "my-container"));
for (final UsesNode usesNode : devicesContainer.getUses()) {
}
@Test
- public void testCorrectAugment() throws Exception {
+ void testCorrectAugment() throws Exception {
final Module devicesModule = assertEffectiveModelDir("/augment-to-extension-test/correct-augment")
.findModules("augment-module").iterator().next();
final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
- .create(devicesModule.getQNameModule(), "my-container"));
+ .create(devicesModule.getQNameModule(), "my-container"));
boolean augmentationIsInContainer = false;
for (final UsesNode usesNode : devicesContainer.getUses()) {
for (final AugmentationSchemaNode augmentationSchema : usesNode.getAugmentations()) {
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
* <p>
* Note: Everything under unknown node is unknown node.
*/
-public class Bug1412Test extends AbstractYangTest {
+class Bug1412Test extends AbstractYangTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
final Module bug1412 = assertEffectiveModelDir("/bugs/bug1412").findModules("bug1412").iterator().next();
final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create(
- bug1412.getQNameModule(), "node"));
+ bug1412.getQNameModule(), "node"));
var unknownNodes = node.asEffectiveStatement().getDeclared().declaredSubstatements(UnrecognizedStatement.class);
assertEquals(1, unknownNodes.size());
final UnrecognizedStatement action = unknownNodes.iterator().next();
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
/**
* <p>
* Note: Everything under unknown node is unknown node.
*/
-public class Bug1413Test extends AbstractYangTest {
+class Bug1413Test extends AbstractYangTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
var extensions = assertEffectiveModelDir("/bugs/bug1413").findModules("bug1413").iterator().next()
.getExtensionSchemaNodes();
assertEquals(1, extensions.size());
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class Bug2291Test {
+class Bug2291Test {
@Test
- public void testRevisionWithExt() throws Exception {
+ void testRevisionWithExt() throws Exception {
assertNotNull(TestUtils.parseYangSource("/bugs/bug2291/bug2291-ext.yang", "/bugs/bug2291/bug2291.yang",
"/ietf/ietf-inet-types@2010-09-24.yang"));
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import java.util.ArrayList;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
-public class Bug2872Test extends AbstractYangTest {
+class Bug2872Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var schema = assertEffectiveModelDir("/bugs/bug2872");
+ final var myLeaf = assertInstanceOf(LeafSchemaNode.class, schema.getDataChildByName(
+ QName.create("bug2872", "2016-06-08", "bar")));
+ final var myEnum = assertInstanceOf(EnumTypeDefinition.class, myLeaf.getType());
- final QNameModule bug2872module = QNameModule.create(XMLNamespace.of("bug2872"), Revision.of("2016-06-08"));
- final QName foo = QName.create(bug2872module, "bar");
-
- final DataSchemaNode dataSchemaNode = schema.getDataChildByName(foo);
- assertTrue(dataSchemaNode instanceof LeafSchemaNode);
- final LeafSchemaNode myLeaf = (LeafSchemaNode) dataSchemaNode;
-
- final TypeDefinition<?> type = myLeaf.getType();
- assertTrue(type instanceof EnumTypeDefinition);
- final EnumTypeDefinition myEnum = (EnumTypeDefinition) type;
-
- final List<EnumTypeDefinition.EnumPair> values = myEnum.getValues();
- assertEquals(2, values.size());
-
- final List<String> valueNames = new ArrayList<>();
- for (EnumTypeDefinition.EnumPair pair : values) {
- valueNames.add(pair.getName());
- }
- assertTrue(valueNames.contains("value-one"));
- assertTrue(valueNames.contains("value-two"));
+ assertEquals(List.of("value-one", "value-two"), myEnum.getValues().stream().map(EnumPair::getName).toList());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.Submodule;
-public class Bug3799Test extends AbstractYangTest {
+class Bug3799Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var schema = assertEffectiveModelDir("/bugs/bug3799");
var modules = schema.getModules();
assertNotNull(childNodes);
assertEquals(1, childNodes.size());
- DataSchemaNode child = childNodes.iterator().next();
- assertTrue(child instanceof LeafSchemaNode);
-
- LeafSchemaNode leafBar = (LeafSchemaNode) child;
- String bar = leafBar.getQName().getLocalName();
- assertEquals("bar", bar);
+ LeafSchemaNode leafBar = assertInstanceOf(LeafSchemaNode.class, childNodes.iterator().next());
+ assertEquals("bar", leafBar.getQName().getLocalName());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class Bug3859Test extends AbstractYangTest {
+class Bug3859Test extends AbstractYangTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
assertEquals(1, assertEffectiveModelDir("/bugs/bug3859").findModules("reference-in-unknown").size());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.stream.Collectors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
/**
* Test antlr grammar capability to parse nested unknown nodes.
*/
-public class Bug394Test extends AbstractYangTest {
+class Bug394Test extends AbstractYangTest {
@Test
- public void testParseList() throws Exception {
+ void testParseList() throws Exception {
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();
final ContainerSchemaNode logrecords = (ContainerSchemaNode) bug394.getDataChildByName(QName.create(
- bug394.getQNameModule(), "logrecords"));
+ bug394.getQNameModule(), "logrecords"));
assertNotNull(logrecords);
final Collection<? extends UnrecognizedStatement> nodes = logrecords.asEffectiveStatement().getDeclared()
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
-public class Bug4231Test {
+class Bug4231Test {
private static final QNameModule FOO = QNameModule.create(XMLNamespace.of("foo"), Revision.of("2015-09-02"));
@Test
- public void test() throws Exception {
- final SchemaTreeEffectiveStatement<?> stmt = TestUtils.parseYangSource("/bugs/bug4231.yang")
+ void test() throws Exception {
+ assertInstanceOf(LeafListEffectiveStatement.class, TestUtils.parseYangSource("/bugs/bug4231.yang")
.getModuleStatement(FOO)
.findSchemaTreeNode(QName.create(FOO, "augment-target"), QName.create(FOO, "my-container-in-grouping"),
QName.create(FOO, "l2"))
- .orElse(null);
- assertThat(stmt, instanceOf(LeafListEffectiveStatement.class));
+ .orElseThrow());
}
}
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-public class Bug4410Test extends AbstractYangTest {
+class Bug4410Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var cause = assertInferenceExceptionDir("/bugs/bug4410",
startsWith("Yang model processing phase EFFECTIVE_MODEL failed [at ")).getCause();
- assertThat(cause, instanceOf(InferenceException.class));
+ assertInstanceOf(InferenceException.class, cause);
assertThat(cause.getMessage(), allOf(startsWith("Type [(foo)"), containsString("was not found")));
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-public class Bug4456Test extends AbstractYangTest {
+class Bug4456Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var schema = assertEffectiveModelDir("/bugs/bug4456");
var modules = schema.findModules(XMLNamespace.of("foo"));
*/
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.assertNotEquals;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
-public class Bug4610Test extends AbstractYangTest {
+class Bug4610Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var context = assertEffectiveModelDir("/bugs/bug4610");
final Revision revision = Revision.of("2015-12-12");
final SchemaTreeEffectiveStatement<?> rootContainer = context.getModuleStatement(c1Foo.getModule())
.findSchemaTreeNode(QName.create(c1Foo, "root"), c1Foo).orElseThrow();
- assertThat(rootContainer, instanceOf(ContainerEffectiveStatement.class));
+ assertInstanceOf(ContainerEffectiveStatement.class, rootContainer);
assertNotEquals(g1argument, rootContainer.argument());
assertSame(g1original, rootContainer.getDeclared());
}
private static ContainerEffectiveStatement findContainer(final EffectiveModelContext context, final QName grouping,
- final QName container) {
+ final QName container) {
final ModuleEffectiveStatement module = context.getModuleStatement(grouping.getModule());
final GroupingEffectiveStatement grp = module.streamEffectiveSubstatements(GroupingEffectiveStatement.class)
.filter(stmt -> grouping.equals(stmt.argument()))
.findAny().orElseThrow();
final SchemaTreeEffectiveStatement<?> node = grp.findSchemaTreeNode(container).orElse(null);
- assertThat(node, instanceOf(ContainerEffectiveStatement.class));
+ assertInstanceOf(ContainerEffectiveStatement.class, node);
return (ContainerEffectiveStatement) node;
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import com.google.common.collect.Range;
import java.util.Collection;
import java.util.List;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-public class Bug4623Test extends AbstractYangTest {
+class Bug4623Test extends AbstractYangTest {
private static Module TYPES;
- @BeforeClass
- public static void beforeClass() throws Exception {
+ @BeforeAll
+ static void beforeClass() throws Exception {
// given
TYPES = assertEffectiveModelDir("/bugs/bug4623").findModules("types").iterator().next();
}
@Test
- public void testStringTypeWithUnknownSchemaNodeAtTheEndOfTypeDefinition() {
+ void testStringTypeWithUnknownSchemaNodeAtTheEndOfTypeDefinition() {
// when
final LeafSchemaNode leaf = (LeafSchemaNode) TYPES.getDataChildByName(
QName.create(XMLNamespace.of("urn:custom.types.demo"), "leaf-length-pattern-unknown"));
assertEquals(Integer.valueOf(10), span.upperEndpoint());
final PatternConstraint patternConstraint = patternConstraints.get(0);
- assertEquals(patternConstraint.getRegularExpressionString(), "[0-9a-fA-F]");
+ assertEquals("[0-9a-fA-F]", patternConstraint.getRegularExpressionString());
}
@Test
- public void testStringTypeWithUnknownSchemaNodeBetweenStringRestrictionStatements() {
+ void testStringTypeWithUnknownSchemaNodeBetweenStringRestrictionStatements() {
// when
final LeafSchemaNode leaf = (LeafSchemaNode) TYPES.getDataChildByName(
- QName.create(XMLNamespace.of("urn:custom.types.demo"), "leaf-length-unknown-pattern"));
+ QName.create(XMLNamespace.of("urn:custom.types.demo"), "leaf-length-unknown-pattern"));
// then
assertNotNull(leaf);
assertEquals(Integer.valueOf(10), lengthConstraint.upperEndpoint());
final PatternConstraint patternConstraint = patternConstraints.get(0);
- assertEquals(patternConstraint.getRegularExpressionString(), "[0-9a-fA-F]");
+ assertEquals("[0-9a-fA-F]", patternConstraint.getRegularExpressionString());
}
@Test
- public void testStringTypeWithUnknownSchemaNodeOnTheStartOfTypeDefinition() {
+ void testStringTypeWithUnknownSchemaNodeOnTheStartOfTypeDefinition() {
// when
final LeafSchemaNode leaf = (LeafSchemaNode) TYPES.getDataChildByName(
- QName.create(XMLNamespace.of("urn:custom.types.demo"), "leaf-unknown-length-pattern"));
+ QName.create(XMLNamespace.of("urn:custom.types.demo"), "leaf-unknown-length-pattern"));
// then
final TypeDefinition<?> type = leaf.getType();
assertExtension(leaf);
final LengthConstraint lengthConstraints =
- ((StringTypeDefinition) type).getLengthConstraint().get();
+ ((StringTypeDefinition) type).getLengthConstraint().get();
assertEquals(1, lengthConstraints.getAllowedRanges().asRanges().size());
final Range<Integer> lengthConstraint = lengthConstraints.getAllowedRanges().span();
final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
assertEquals(1, patternConstraints.size());
final PatternConstraint patternConstraint = patternConstraints.get(0);
- assertEquals(patternConstraint.getRegularExpressionString(), "[0-9a-fA-F]");
+ assertEquals("[0-9a-fA-F]", patternConstraint.getRegularExpressionString());
}
private static void assertExtension(final LeafSchemaNode leaf) {
package org.opendaylight.yangtools.yang.stmt;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class Bug4933Test extends AbstractYangTest {
+class Bug4933Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var context = assertEffectiveModelDir("/bugs/bug4933/correct");
final Module foo = context.findModules("foo").iterator().next();
}
@Test
- public void incorrectKeywordTest() {
+ void incorrectKeywordTest() {
assertSourceExceptionDir("/bugs/bug4933/incorrect",
startsWith("String 'not_supported' is not valid deviate argument"));
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class Bug5059Test extends AbstractYangTest {
+class Bug5059Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
assertEffectiveModelDir("/bugs/bug5059");
}
}
*/
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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Iterator;
-import java.util.stream.Collectors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-public class Bug5101Test extends AbstractYangTest {
+class Bug5101Test extends AbstractYangTest {
@Test
- public void test() throws Exception {
- final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/bug5101.yang")
+ void test() throws Exception {
+ final var module = assertEffectiveModel("/bugs/bug5101.yang")
.getModuleStatement(QName.create("foo", "2016-01-29", "foo"));
- final ContainerEffectiveStatement myContainerInGrouping = module
+ final var myContainerInGrouping = module
.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow()
- .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElse(null);
- assertThat(myContainerInGrouping, instanceOf(ContainerSchemaNode.class));
- assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) myContainerInGrouping).getStatus());
+ .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
+ assertEquals(Status.DEPRECATED, assertInstanceOf(ContainerSchemaNode.class, myContainerInGrouping).getStatus());
// This relies on schema definition order
final Iterator<ContainerEffectiveStatement> containers =
- module.streamEffectiveSubstatements(ContainerEffectiveStatement.class)
- .collect(Collectors.toList()).iterator();
+ module.streamEffectiveSubstatements(ContainerEffectiveStatement.class).toList().iterator();
final ContainerEffectiveStatement root = containers.next();
- assertThat(root, instanceOf(ContainerSchemaNode.class));
- assertEquals(Status.CURRENT, ((ContainerSchemaNode) root).getStatus());
+ assertEquals(Status.CURRENT, assertInstanceOf(ContainerSchemaNode.class, root).getStatus());
final ContainerEffectiveStatement rootMyContainer = root
.streamEffectiveSubstatements(ContainerEffectiveStatement.class)
.findAny().orElse(null);
- assertThat(rootMyContainer, instanceOf(ContainerSchemaNode.class));
- assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) rootMyContainer).getStatus());
+ assertEquals(Status.DEPRECATED, assertInstanceOf(ContainerSchemaNode.class, rootMyContainer).getStatus());
final ContainerEffectiveStatement myContainer = containers.next();
+ assertEquals(Status.DEPRECATED, assertInstanceOf(ContainerSchemaNode.class, myContainer).getStatus());
assertFalse(containers.hasNext());
- assertThat(myContainer, instanceOf(ContainerSchemaNode.class));
- assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) myContainer).getStatus());
-
}
}
*/
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.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-public class Bug5335Test extends AbstractYangTest {
+class Bug5335Test extends AbstractYangTest {
private static final String FOO = "foo";
private static final String BAR = "bar";
private static final String REV = "2016-03-04";
private static final QName MANDATORY_LEAF_B = QName.create(BAR, REV, "mandatory-leaf");
@Test
- public void incorrectTest1() {
+ void incorrectTest1() {
assertInferenceExceptionDir("/bugs/bug5335/incorrect/case-1", startsWith(
"An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
}
@Test
- public void incorrectTest2() {
+ void incorrectTest2() {
assertInferenceExceptionDir("/bugs/bug5335/incorrect/case-2", startsWith(
"An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
}
@Test
- public void incorrectTest3() {
+ void incorrectTest3() {
assertInferenceExceptionDir("/bugs/bug5335/incorrect/case-3", startsWith(
"An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
}
@Test
- public void correctTest1() {
+ void correctTest1() {
final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug5335/correct/case-1");
final DataSchemaNode mandatoryLeaf = context.findDataTreeChild(ROOT, PRESENCE_CONTAINER_B, MANDATORY_LEAF_B)
.orElse(null);
- assertThat(mandatoryLeaf, instanceOf(LeafSchemaNode.class));
+ assertInstanceOf(LeafSchemaNode.class, mandatoryLeaf);
}
@Test
- public void correctTest2() {
+ void correctTest2() {
final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug5335/correct/case-2");
final DataSchemaNode mandatoryLeaf = context.findDataTreeChild(ROOT, PRESENCE_CONTAINER_B,
NON_PRESENCE_CONTAINER_B, MANDATORY_LEAF_B).orElse(null);
- assertThat(mandatoryLeaf, instanceOf(LeafSchemaNode.class));
+ assertInstanceOf(LeafSchemaNode.class, mandatoryLeaf);
}
@Test
- public void correctTest3() {
+ void correctTest3() {
final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug5335/correct/case-3");
final DataSchemaNode mandatoryLeaf = context.findDataTreeChild(ROOT, PRESENCE_CONTAINER_B,
NON_PRESENCE_CONTAINER_B, MANDATORY_LEAF_B).orElse(null);
- assertThat(mandatoryLeaf, instanceOf(LeafSchemaNode.class));
+ assertInstanceOf(LeafSchemaNode.class, mandatoryLeaf);
}
@Test
- public void correctTest4() {
+ void correctTest4() {
final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug5335/correct/case-4");
final DataSchemaNode mandatoryLeaf = context.findDataTreeChild(ROOT, NON_PRESENCE_CONTAINER_F, MANDATORY_LEAF_F)
.orElse(null);
- assertThat(mandatoryLeaf, instanceOf(LeafSchemaNode.class));
+ assertInstanceOf(LeafSchemaNode.class, mandatoryLeaf);
}
}
* 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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-public class Bug5396Test extends AbstractYangTest {
+class Bug5396Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var context = assertEffectiveModelDir("/bugs/bug5396");
QName root = QName.create("foo", "root");
QName myLeaf2 = QName.create("foo", "my-leaf2");
SchemaNode findDataSchemaNode = context.findDataTreeChild(root, myLeaf2).get();
- assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
- LeafSchemaNode leaf2 = (LeafSchemaNode) findDataSchemaNode;
+ LeafSchemaNode leaf2 = assertInstanceOf(LeafSchemaNode.class, findDataSchemaNode);
TypeDefinition<?> type = leaf2.getType();
- assertThat(type, instanceOf(UnionTypeDefinition.class));
- UnionTypeDefinition union = (UnionTypeDefinition) type;
+ UnionTypeDefinition union = assertInstanceOf(UnionTypeDefinition.class, type);
List<TypeDefinition<?>> types = union.getTypes();
assertEquals(4, types.size());
assertNotEquals(type0, type2);
assertNotEquals(type0, type3);
- assertThat(type0, instanceOf(StringTypeDefinition.class));
- assertThat(type1, instanceOf(StringTypeDefinition.class));
- assertThat(type2, instanceOf(StringTypeDefinition.class));
- assertThat(type3, instanceOf(StringTypeDefinition.class));
-
- StringTypeDefinition stringType0 = (StringTypeDefinition) type0;
- StringTypeDefinition stringType1 = (StringTypeDefinition) type1;
- StringTypeDefinition stringType2 = (StringTypeDefinition) type2;
- StringTypeDefinition stringType3 = (StringTypeDefinition) type3;
+ StringTypeDefinition stringType0 = assertInstanceOf(StringTypeDefinition.class, type0);
+ StringTypeDefinition stringType1 = assertInstanceOf(StringTypeDefinition.class, type1);
+ StringTypeDefinition stringType2 = assertInstanceOf(StringTypeDefinition.class, type2);
+ StringTypeDefinition stringType3 = assertInstanceOf(StringTypeDefinition.class, type3);
final List<PatternConstraint> patternConstraints0 = stringType0.getPatternConstraints();
final List<PatternConstraint> patternConstraints1 = stringType1.getPatternConstraints();
assertEquals("^(?:dp[0-9]+o[0-9]+(d[0-9]+)?)$", patternConstraint0.getJavaPatternString());
assertEquals("^(?:dp[0-9]+s[0-9]+(f[0-9]+)?(d[0-9]+)?)$", patternConstraint1.getJavaPatternString());
assertEquals("^(?:dp[0-9]+(P[0-9]+)?p[0-9]{1,3}s[0-9]{1,3}(f[0-9]+)?(d[0-9]+)?)$",
- patternConstraint2.getJavaPatternString());
+ patternConstraint2.getJavaPatternString());
assertEquals("^(?:dp[0-9]+p[0-9]+p[0-9]+)$", patternConstraint3.getJavaPatternString());
}
}
*/
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.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
-public class Bug5481Test extends AbstractYangTest {
+class Bug5481Test extends AbstractYangTest {
@Test
- public void test() throws Exception {
+ void test() throws Exception {
final var context = assertEffectiveModelDir("/bugs/bug5481");
ContainerSchemaNode topContainer = verifyTopContainer(context);
verifyExtendedLeaf(topContainer);
private static ContainerSchemaNode verifyTopContainer(final EffectiveModelContext context) {
QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
DataSchemaNode dataChildByName = context.getDataChildByName(top);
- assertThat(dataChildByName, instanceOf(ContainerSchemaNode.class));
-
- ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
+ ContainerSchemaNode topContainer = assertInstanceOf(ContainerSchemaNode.class, dataChildByName);
assertFalse(topContainer.getWhenCondition().isPresent());
assertEquals(Status.CURRENT, topContainer.getStatus());
private static void verifyExtendedLeaf(final ContainerSchemaNode topContainer) {
DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
- "2016-03-09", "extended-leaf"));
- assertTrue(dataChildByName2 instanceof LeafSchemaNode);
+ "2016-03-09", "extended-leaf"));
+ LeafSchemaNode extendedLeaf = assertInstanceOf(LeafSchemaNode.class, dataChildByName2);
- LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
assertEquals(Optional.of("text"), extendedLeaf.getDescription());
assertEquals(Optional.of("ref"), extendedLeaf.getReference());
*/
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.MustDefinition;
-public class Bug5518Test extends AbstractYangTest {
+class Bug5518Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var context = assertEffectiveModelDir("/bugs/bug5518");
- final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "root"));
- assertThat(dataChildByName, instanceOf(ContainerSchemaNode.class));
- final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;
- final Collection<? extends MustDefinition> mustConstraints = root.getMustConstraints();
+ final var root = assertInstanceOf(ContainerSchemaNode.class,
+ context.getDataChildByName(QName.create("foo", "root")));
+ final var mustConstraints = root.getMustConstraints();
assertEquals(1, mustConstraints.size());
- final MustDefinition must = mustConstraints.iterator().next();
+ final var must = mustConstraints.iterator().next();
assertEquals("not(deref(.)/../same-pass)", must.getXpath().toString());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-public class Bug5550Test extends AbstractYangTest {
+class Bug5550Test extends AbstractYangTest {
private static final String NS = "foo";
private static final String REV = "2016-03-18";
@Test
- public void test() {
- final var context = assertEffectiveModelDir("/bugs/bug5550");
-
- QName root = QName.create(NS, REV, "root");
- QName containerInGrouping = QName.create(NS, REV, "container-in-grouping");
- QName leaf1 = QName.create(NS, REV, "leaf-1");
-
- SchemaNode findDataSchemaNode = context.findDataTreeChild(root, containerInGrouping, leaf1).get();
- assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
+ void test() {
+ assertInstanceOf(LeafSchemaNode.class, assertEffectiveModelDir("/bugs/bug5550")
+ .findDataTreeChild(
+ QName.create(NS, REV, "root"),
+ QName.create(NS, REV, "container-in-grouping"),
+ QName.create(NS, REV, "leaf-1"))
+ .orElseThrow());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.xml.sax.SAXException;
+import org.junit.jupiter.api.Test;
-public class Bug5693Test {
-
- private Module foo;
-
- /**
- * Use input stream to load Yin module.
- */
- @Before
- public void initTest() throws ReactorException, SAXException, IOException, URISyntaxException {
- foo = StmtTestUtils.parseYinSources("/bugs/bug5693").getModules().iterator().next();
- }
-
- /**
- * Test presence of testing feature (parsed in the last phase), if it is present then parsing was successful.
- * Meaning that stream was not closed after the first parsing phase.
- */
+class Bug5693Test {
@Test
- public void bug5693Test() {
- assertNotNull(foo.getFeatures());
- assertEquals("Module should has exactly one feature", 1, foo.getFeatures().size());
- assertEquals("Present feature should has expected local name", "test-input-stream-not-closed",
- foo.getFeatures().iterator().next().getQName().getLocalName());
+ void bug5693Test() throws Exception {
+ final var features = StmtTestUtils.parseYinSources("/bugs/bug5693").getModules().iterator().next()
+ .getFeatures();
+ assertNotNull(features);
+ assertEquals(1, features.size(), "Module should has exactly one feature");
+ assertEquals("test-input-stream-not-closed", features.iterator().next().getQName().getLocalName(),
+ "Present feature should has expected local name");
}
}
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-public class Bug5712Test extends AbstractYangTest {
+class Bug5712Test extends AbstractYangTest {
@Test
- public void testTypedefWithNewStatementParser() {
+ void testTypedefWithNewStatementParser() {
final var badModule = assertEffectiveModelDir("/bugs/bug5712").findModules("bad").iterator().next();
assertNotNull(badModule);
checkThing2TypeDef(badModule);
private static void checkThing2TypeDef(final Module badModule) {
TypeDefinition<?> thing2 = null;
- for (TypeDefinition<?> typeDef : badModule.getTypeDefinitions()) {
+ for (var typeDef : badModule.getTypeDefinitions()) {
if (typeDef.getQName().getLocalName().equals("thing2")) {
thing2 = typeDef;
break;
}
assertNotNull(thing2);
- TypeDefinition<?> baseType = thing2.getBaseType();
+ var baseType = thing2.getBaseType();
assertEquals(QName.create("urn:opendaylight:bad", "2016-04-11", "thing"), baseType.getQName());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Iterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
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.Module;
-public class Bug5884Test extends AbstractYangTest {
+class Bug5884Test extends AbstractYangTest {
private static final String NS = "urn:yang.foo";
private static final String REV = "2016-01-01";
@Test
- public void testBug5884() {
+ void testBug5884() {
final var context = assertEffectiveModelDir("/bugs/bug5884");
final QName root = QName.create(NS, REV, "main-container");
private static void testIterator(final Iterator<? extends AugmentationSchemaNode> iterator) {
while (iterator.hasNext()) {
- AugmentationSchemaNode allAugments = iterator.next();
- final DataSchemaNode currentChoice = allAugments.getChildNodes().iterator().next();
- assertThat(currentChoice, isA(CaseSchemaNode.class));
+ assertInstanceOf(CaseSchemaNode.class, iterator.next().getChildNodes().iterator().next());
}
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class Bug5899Test extends AbstractYangTest {
+class Bug5899Test extends AbstractYangTest {
@Test
- public void testBug5899() {
+ void testBug5899() {
assertEffectiveModelDir("/bugs/bug5899");
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-public class Bug5942Test extends AbstractYangTest {
+class Bug5942Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var schemaContext = assertEffectiveModelDir("/bugs/bug5942");
- final DataSchemaNode root = schemaContext.getDataChildByName(QName.create("foo", "2016-06-02", "root"));
- assertTrue(root instanceof ContainerSchemaNode);
-
- final var uses = ((ContainerSchemaNode) root).getUses();
+ final var uses = assertInstanceOf(ContainerSchemaNode.class,
+ schemaContext.getDataChildByName(QName.create("foo", "2016-06-02", "root"))).getUses();
assertEquals(1, uses.size());
- final UsesNode usesNode = uses.iterator().next();
+ final var usesNode = uses.iterator().next();
assertEquals(Optional.of("uses description"), usesNode.getDescription());
assertEquals(Optional.of("uses reference"), usesNode.getReference());
assertEquals("0!=1", usesNode.getWhenCondition().orElseThrow().toString());
- final UnrecognizedStatement unknownSchemaNode = usesNode.asEffectiveStatement().getDeclared()
+ final var unknownSchemaNode = usesNode.asEffectiveStatement().getDeclared()
.findFirstDeclaredSubstatement(UnrecognizedStatement.class).orElseThrow();
assertEquals("argument", unknownSchemaNode.argument());
package org.opendaylight.yangtools.yang.stmt;
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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.File;
import java.util.Collection;
import org.eclipse.jdt.annotation.NonNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.UniqueEffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-public class Bug5946Test {
+class Bug5946Test extends AbstractYangTest {
private static final String NS = "foo";
private static final String REV = "2016-05-26";
private static final QName L1 = QName.create(NS, REV, "l1");
private static final SchemaNodeIdentifier C_L3_ID = SchemaNodeIdentifier.Descendant.of(C, L3);
@Test
- public void test() throws Exception {
- SchemaContext context = StmtTestUtils.parseYangSources(new File(getClass()
- .getResource("/bugs/bug5946/foo.yang").toURI()));
- assertNotNull(context);
+ void test() throws Exception {
+ final var context = assertEffectiveModel("/bugs/bug5946/foo.yang");
var uniqueConstraints = getListConstraints(context, WITHOUT_UNIQUE);
assertNotNull(uniqueConstraints);
boolean l1l2 = false;
boolean l1cl3 = false;
boolean cl3l2 = false;
- for (UniqueEffectiveStatement uniqueConstraint : multipleUniqueConstraints) {
+ for (var uniqueConstraint : multipleUniqueConstraints) {
var uniqueConstraintTag = uniqueConstraint.argument();
if (uniqueConstraintTag.contains(L1_ID) && uniqueConstraintTag.contains(L2_ID)) {
l1l2 = true;
}
@Test
- public void testInvalid() throws Exception {
- final var cause = assertThrows(ReactorException.class, () -> StmtTestUtils.parseYangSources(
- new File(getClass().getResource("/bugs/bug5946/foo-invalid.yang").toURI())))
- .getCause();
- assertThat(cause.getMessage(), startsWith("Unique statement argument '/simple-unique/l1' contains schema node "
- + "identifier '/simple-unique/l1' which is not in the descendant node identifier form."));
+ void testInvalid() throws Exception {
+ assertSourceException(
+ startsWith("Unique statement argument '/simple-unique/l1' contains schema node identifier "
+ + "'/simple-unique/l1' which is not in the descendant node identifier form."),
+ "/bugs/bug5946/foo-invalid.yang");
}
- private static @NonNull Collection<? extends @NonNull UniqueEffectiveStatement> getListConstraints(
+ private static @NonNull Collection<? extends @NonNull UniqueEffectiveStatement> getListConstraints(
final SchemaContext context, final QName listQName) {
- DataSchemaNode dataChildByName = context.getDataChildByName(listQName);
- assertTrue(dataChildByName instanceof ListSchemaNode);
- return ((ListSchemaNode) dataChildByName).getUniqueConstraints();
+ return assertInstanceOf(ListSchemaNode.class, context.getDataChildByName(listQName)).getUniqueConstraints();
}
}
* 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.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class Bug6131Test extends AbstractYangTest {
+class Bug6131Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
+ // FIXME: better exception?
assertThrows(NullPointerException.class, () -> TestUtils.loadModules("/bugs/bug6131"));
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
-
-public class Bug6150Test {
+class Bug6150Test extends AbstractYangTest {
@Test
- public void effectiveAugmentFirstTest() throws Exception {
- assertNotNull(TestUtils.parseYangSource("/bugs/bug6150/target.yang", "/bugs/bug6150/aug-first.yang"));
+ void effectiveAugmentFirstTest() {
+ assertEffectiveModel("/bugs/bug6150/target.yang", "/bugs/bug6150/aug-first.yang");
}
@Test
- public void effectiveAugmentSecondTest() throws Exception {
- assertNotNull(TestUtils.parseYangSource("/bugs/bug6150/target.yang", "/bugs/bug6150/aug-second.yang"));
+ void effectiveAugmentSecondTest() {
+ assertEffectiveModel("/bugs/bug6150/target.yang", "/bugs/bug6150/aug-second.yang");
}
@Test
- public void effectiveAugmentBothTest() throws Exception {
- assertNotNull(TestUtils.parseYangSource("/bugs/bug6150/target.yang", "/bugs/bug6150/aug-first.yang",
- "/bugs/bug6150/aug-second.yang"));
+ void effectiveAugmentBothTest() {
+ assertEffectiveModel("/bugs/bug6150/target.yang", "/bugs/bug6150/aug-first.yang",
+ "/bugs/bug6150/aug-second.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.File;
-import java.util.Collection;
-import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-public class Bug6180Test {
-
+class Bug6180Test extends AbstractYangTest {
@Test
- public void stringTest() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(new File(getClass().getResource(
- "/bugs/bug6180/string-test.yang").toURI()));
- assertNotNull(schemaContext);
+ void stringTest() {
+ final var schemaContext = assertEffectiveModel("/bugs/bug6180/string-test.yang");
assertEquals(1, schemaContext.getModules().size());
- final Module module = schemaContext.getModules().iterator().next();
+ final var module = schemaContext.getModules().iterator().next();
assertEquals(Optional.of(" 1. this text contains \"string enclosed in double quotes\" and"
- + " special characters: \\,\n,\t 2. this text contains \"string enclosed in double quotes\""
- + " and special characters: \\,\n,\n, 3. this text contains \"string enclosed in"
- + " double quotes\" and special characters: \\,\n,\t "), module.getDescription());
+ + " special characters: \\,\n,\t 2. this text contains \"string enclosed in double quotes\""
+ + " and special characters: \\,\n,\n, 3. this text contains \"string enclosed in"
+ + " double quotes\" and special characters: \\,\n,\t "), module.getDescription());
}
@Test
- public void doubleQuotesTest() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(new File(getClass().getResource(
- "/bugs/bug6180/double-quotes.yang").toURI()));
- assertNotNull(schemaContext);
- verifyDoubleQuotesExpression(schemaContext);
+ void doubleQuotesTest() {
+ verifyDoubleQuotesExpression(assertEffectiveModel("/bugs/bug6180/double-quotes.yang"));
}
@Test
- public void doubleQuotesSinbleInsideTest() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(new File(getClass().getResource(
- "/bugs/bug6180/double-quotes-single-inside.yang").toURI()));
- assertNotNull(schemaContext);
- verifySingleQuotesExpression(schemaContext);
+ void doubleQuotesSinbleInsideTest() {
+ verifySingleQuotesExpression(assertEffectiveModel("/bugs/bug6180/double-quotes-single-inside.yang"));
}
@Test
- public void singleQuotesTest() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(new File(getClass().getResource(
- "/bugs/bug6180/single-quotes.yang").toURI()));
- assertNotNull(schemaContext);
- verifyDoubleQuotesExpression(schemaContext);
+ void singleQuotesTest() {
+ verifyDoubleQuotesExpression(assertEffectiveModel("/bugs/bug6180/single-quotes.yang"));
}
- private static void verifyDoubleQuotesExpression(final SchemaContext schemaContext) {
- final DataSchemaNode dataNodeBar = schemaContext.getDataChildByName(QName.create("foo", "2016-07-11", "bar"));
- assertTrue(dataNodeBar instanceof ContainerSchemaNode);
- final ContainerSchemaNode bar = (ContainerSchemaNode) dataNodeBar;
+ private static void verifyDoubleQuotesExpression(final EffectiveModelContext schemaContext) {
+ final var bar = assertInstanceOf(ContainerSchemaNode.class,
+ schemaContext.getDataChildByName(QName.create("foo", "2016-07-11", "bar")));
assertEquals("/foo != \"bar\"", bar.getWhenCondition().orElseThrow().toString());
- final Collection<? extends TypeDefinition<?>> typeDefinitions = schemaContext.getTypeDefinitions();
+ final var typeDefinitions = schemaContext.getTypeDefinitions();
assertEquals(1, typeDefinitions.size());
- final TypeDefinition<?> type = typeDefinitions.iterator().next();
- assertTrue(type instanceof StringTypeDefinition);
- final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
+ final var patternConstraints = assertInstanceOf(StringTypeDefinition.class, typeDefinitions.iterator().next())
+ .getPatternConstraints();
assertEquals(1, patternConstraints.size());
- final PatternConstraint pattern = patternConstraints.iterator().next();
+ final var pattern = patternConstraints.iterator().next();
assertEquals("^(?:\".*\")$", pattern.getJavaPatternString());
assertTrue(Pattern.compile(pattern.getJavaPatternString()).matcher("\"enclosed string in quotes\"").matches());
}
- private static void verifySingleQuotesExpression(final SchemaContext schemaContext) {
- final DataSchemaNode dataNodeBar = schemaContext.getDataChildByName(QName.create("foo", "2016-07-11", "bar"));
- assertTrue(dataNodeBar instanceof ContainerSchemaNode);
- final ContainerSchemaNode bar = (ContainerSchemaNode) dataNodeBar;
+ private static void verifySingleQuotesExpression(final EffectiveModelContext schemaContext) {
+ final var bar = assertInstanceOf(ContainerSchemaNode.class,
+ schemaContext.getDataChildByName(QName.create("foo", "2016-07-11", "bar")));
assertEquals("/foo != 'bar'", bar.getWhenCondition().orElseThrow().toString());
- final Collection<? extends TypeDefinition<?>> typeDefinitions = schemaContext.getTypeDefinitions();
+ final var typeDefinitions = schemaContext.getTypeDefinitions();
assertEquals(1, typeDefinitions.size());
- final TypeDefinition<?> type = typeDefinitions.iterator().next();
- assertTrue(type instanceof StringTypeDefinition);
- final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
+ final var patternConstraints = assertInstanceOf(StringTypeDefinition.class, typeDefinitions.iterator().next())
+ .getPatternConstraints();
assertEquals(1, patternConstraints.size());
- final PatternConstraint pattern = patternConstraints.iterator().next();
+ final var pattern = patternConstraints.iterator().next();
assertEquals("^(?:'.*')$", pattern.getJavaPatternString());
assertTrue(Pattern.compile(pattern.getJavaPatternString()).matcher("'enclosed string in quotes'").matches());
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
private static final String FOO_NS = "foo";
@Test
- public void testYang10() {
+ void testYang10() {
assertSchemaContext(assertEffectiveModelDir("/bugs/bug6183/yang10"));
}
@Test
- public void testYang11() {
+ void testYang11() {
assertSchemaContext(assertEffectiveModelDir("/bugs/bug6183/yang11"));
}
assertEquals(1, context.getModules().size());
assertEquals(4, context.getModules().iterator().next().getAugmentations().size());
- assertTrue(context.getDataChildByName(foo("before")) instanceof ContainerSchemaNode);
- assertTrue(context.getDataChildByName(foo("after")) instanceof ContainerSchemaNode);
+ assertInstanceOf(ContainerSchemaNode.class, context.getDataChildByName(foo("before")));
+ assertInstanceOf(ContainerSchemaNode.class, context.getDataChildByName(foo("after")));
final DataSchemaNode dataChildByName = context.getDataChildByName(foo("my-choice"));
- assertTrue(dataChildByName instanceof ChoiceSchemaNode);
- final ChoiceSchemaNode myChoice = (ChoiceSchemaNode) dataChildByName;
+ final ChoiceSchemaNode myChoice = assertInstanceOf(ChoiceSchemaNode.class, dataChildByName);
assertEquals(4, myChoice.getCases().size());
private static ContainerSchemaNode getContainerSchemaNode(final DataNodeContainer parent,
final String containerName) {
final DataSchemaNode dataChildByName = parent.getDataChildByName(foo(containerName));
- assertTrue(dataChildByName instanceof ContainerSchemaNode);
- return (ContainerSchemaNode) dataChildByName;
+ return assertInstanceOf(ContainerSchemaNode.class, dataChildByName);
}
private static LeafSchemaNode getLeafSchemaNode(final DataNodeContainer parent, final String leafName) {
final DataSchemaNode dataChildByName = parent.getDataChildByName(foo(leafName));
- assertTrue(dataChildByName instanceof LeafSchemaNode);
- return (LeafSchemaNode) dataChildByName;
+ return assertInstanceOf(LeafSchemaNode.class, dataChildByName);
}
private static QName foo(final String localName) {
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class Bug6240Test extends AbstractYangTest {
+class Bug6240Test extends AbstractYangTest {
private static final String NS = "bar";
private static final String REV = "2016-07-19";
@Test
- public void testModels() throws Exception {
+ void testModels() throws Exception {
final var context = assertEffectiveModelDir("/bugs/bug6240/correct");
final var modules = context.getModules();
}
assertNotNull(bar);
- assertThat(bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")), instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class, bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")));
assertThat(bar.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")),
instanceOf(ContainerSchemaNode.class));
assertEquals(1, bar.getSubmodules().size());
final DataSchemaNode dataChildByName = bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con"));
- assertThat(dataChildByName, instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class, dataChildByName);
final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;
assertThat(subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")),
}
@Test
- public void testInvalidModels() {
+ void testInvalidModels() {
assertInferenceExceptionDir("/bugs/bug6240/incorrect",
startsWith("Grouping '(bar?revision=2016-07-19)foo-imp-grp' was not resolved."));
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
-public class Bug6316Test extends AbstractYangTest {
+class Bug6316Test extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var context = assertEffectiveModelDir("/bugs/bug6316");
verifyEnumTypedefinition(context);
verifyBitsTypedefinition(context);
private static void verifyEnumTypedefinition(final SchemaContext context) {
final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "enum-leaf"));
- assertTrue(dataChildByName instanceof LeafSchemaNode);
+ assertInstanceOf(LeafSchemaNode.class, dataChildByName);
final LeafSchemaNode enumLeaf = (LeafSchemaNode) dataChildByName;
final TypeDefinition<? extends TypeDefinition<?>> type = enumLeaf.getType();
- assertTrue(type instanceof EnumTypeDefinition);
+ assertInstanceOf(EnumTypeDefinition.class, type);
final EnumTypeDefinition myEnumeration = (EnumTypeDefinition) type;
final List<EnumPair> values = myEnumeration.getValues();
for (final EnumPair enumPair : values) {
private static void verifyBitsTypedefinition(final SchemaContext context) {
final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "bits-leaf"));
- assertTrue(dataChildByName instanceof LeafSchemaNode);
- final LeafSchemaNode bitsLeaf = (LeafSchemaNode) dataChildByName;
+ final LeafSchemaNode bitsLeaf = assertInstanceOf(LeafSchemaNode.class, dataChildByName);
final TypeDefinition<? extends TypeDefinition<?>> type = bitsLeaf.getType();
- assertTrue(type instanceof BitsTypeDefinition);
- final BitsTypeDefinition myBits = (BitsTypeDefinition) type;
+ final BitsTypeDefinition myBits = assertInstanceOf(BitsTypeDefinition.class, type);
for (final Bit bit : myBits.getBits()) {
final String name = bit.getName();
switch (name) {
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.Collection;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-
-public class Bug6410Test {
+import org.junit.jupiter.api.Test;
+class Bug6410Test extends AbstractYangTest {
@Test
- public void testTypedefsInRpc() throws ReactorException {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/foo.yang"));
+ void testTypedefsInRpc() {
+ final var schemaContext = assertEffectiveModel("/bugs/bug6410/foo.yang");
- final Collection<? extends Module> modules = schemaContext.getModules();
+ final var modules = schemaContext.getModules();
assertEquals(1, modules.size());
- final Module module = modules.iterator().next();
+ final var module = modules.iterator().next();
- final Collection<? extends RpcDefinition> rpcs = module.getRpcs();
+ final var rpcs = module.getRpcs();
assertEquals(1, rpcs.size());
- final RpcDefinition rpc = rpcs.iterator().next();
+ final var rpc = rpcs.iterator().next();
- final Collection<? extends TypeDefinition<?>> typeDefs = rpc.getTypeDefinitions();
+ final var typeDefs = rpc.getTypeDefinitions();
assertEquals(2, typeDefs.size());
}
@Test
- public void shouldFailOnDuplicateTypedefs() {
- try {
- StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/bar.yang"));
- fail("A ReactorException should have been thrown.");
- } catch (ReactorException ex) {
- final Throwable cause = ex.getCause();
- assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().contains("Duplicate name for typedef"));
- }
+ void shouldFailOnDuplicateTypedefs() {
+ assertSourceException(containsString("Duplicate name for typedef"), "/bugs/bug6410/bar.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.Collection;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class Bug6491Test extends AbstractYangTest {
+class Bug6491Test extends AbstractYangTest {
private static final Revision DATE = Revision.of("2016-01-01");
@Test
- public void tetststs() {
+ void tetststs() {
testRevision("withoutRevision", null, Optional.empty());
testRevision("withRevision", DATE, Optional.of(DATE));
testRevision("importedModuleRevisionOnly", null, Optional.of(DATE));
private static void testRevision(final String path, final Revision moduleRevision,
final Optional<Revision> importedRevision) {
- final SchemaContext context = assertEffectiveModelDir("/bugs/bug6491/" + path);
- final Module module = context.findModule("bar", moduleRevision).get();
- final Collection<? extends ModuleImport> imports = module.getImports();
+ final var context = assertEffectiveModelDir("/bugs/bug6491/" + path);
+ final var module = context.findModule("bar", moduleRevision).orElseThrow();
+ final var imports = module.getImports();
assertNotNull(imports);
assertEquals(1, imports.size());
assertEquals(importedRevision, imports.iterator().next().getRevision());
*/
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.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-public class Bug6669Test extends AbstractYangTest {
+class Bug6669Test extends AbstractYangTest {
private static final String REV = "2016-09-08";
private static final String FOO_NS = "foo";
private static final String BAR_NS = "bar";
private static final QName M = QName.create(BAR_NS, REV, "m");
@Test
- public void testInvalidAugment() {
+ void testInvalidAugment() {
assertInferenceExceptionDir("/bugs/bug6669/invalid/test1", startsWith(
"An augment cannot add node 'm' because it is mandatory and in module different than target"));
}
@Test
- public void testInvalidAugment2() {
+ void testInvalidAugment2() {
assertInferenceExceptionDir("/bugs/bug6669/invalid/test2", startsWith(
"An augment cannot add node 'm' because it is mandatory and in module different than target"));
}
@Test
- public void testInvalidAugment3() {
+ void testInvalidAugment3() {
assertInferenceExceptionDir("/bugs/bug6669/invalid/test3", startsWith(
"An augment cannot add node 'l' because it is mandatory and in module different than target"));
}
@Test
- public void testValidAugment() {
+ void testValidAugment() {
final var context = assertEffectiveModelDir("/bugs/bug6669/valid/test1");
- final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, M).get();
- assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
+ assertInstanceOf(LeafSchemaNode.class, context.findDataTreeChild(ROOT, BAR, BAR_1, M).orElseThrow());
}
@Test
- public void testValidAugment2() {
+ void testValidAugment2() {
final var context = assertEffectiveModelDir("/bugs/bug6669/valid/test2");
- final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2, M).get();
- assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
+ assertInstanceOf(LeafSchemaNode.class, context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2, M).orElseThrow());
}
@Test
- public void testValidAugment3() throws Exception {
+ void testValidAugment3() throws Exception {
final var context = assertEffectiveModelDir("/bugs/bug6669/valid/test3");
- final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2,
- QName.create(BAR_NS, REV, "l")).get();
- assertThat(findDataSchemaNode, instanceOf(ListSchemaNode.class));
+ assertInstanceOf(ListSchemaNode.class,
+ context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2, QName.create(BAR_NS, REV, "l")).orElseThrow());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
-public class Bug6771Test {
+class Bug6771Test extends AbstractYangTest {
private static final QNameModule NS = QNameModule.create(XMLNamespace.of("http://www.example.com/typedef-bug"));
private static final QName ROOT = QName.create(NS, "root");
private static final QName CONT_B = QName.create(NS, "container-b");
private static final QName INNER_CONTAINER = QName.create(NS, "inner-container");
@Test
- public void augmentTest() throws Exception {
- final ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/augment.yang")
- .getModuleStatement(NS);
+ void augmentTest() {
+ final var module = assertEffectiveModel("/bugs/bug6771/augment.yang").getModuleStatement(NS);
verifyLeafType(module, ROOT, CONT_B, LEAF_CONT_B);
verifyLeafType(module, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B);
}
@Test
- public void choiceCaseTest() throws Exception {
- final ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/choice-case.yang")
- .getModuleStatement(NS);
+ void choiceCaseTest() {
+ final var module = assertEffectiveModel("/bugs/bug6771/choice-case.yang").getModuleStatement(NS);
final QName myChoice = QName.create(NS, "my-choice");
final QName caseOne = QName.create(NS, "one");
}
@Test
- public void groupingTest() throws Exception {
- verifyLeafType(TestUtils.parseYangSource("/bugs/bug6771/grouping.yang").getModuleStatement(NS),
+ void groupingTest() {
+ verifyLeafType(assertEffectiveModel("/bugs/bug6771/grouping.yang").getModuleStatement(NS),
ROOT, CONT_B, LEAF_CONT_B);
}
private static void verifyLeafType(final ModuleEffectiveStatement module, final QName... qnames) {
- final SchemaTreeEffectiveStatement<?> stmt = module.findSchemaTreeNode(qnames).orElse(null);
- assertThat(stmt, instanceOf(LeafSchemaNode.class));
- assertThat(((LeafSchemaNode) stmt).getType(), instanceOf(Uint32TypeDefinition.class));
+ assertInstanceOf(Uint32TypeDefinition.class,
+ assertInstanceOf(LeafSchemaNode.class, module.findSchemaTreeNode(qnames).orElseThrow()).getType());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UnitsEffectiveStatement;
-public class Bug6972Test extends AbstractYangTest {
+class Bug6972Test extends AbstractYangTest {
@Test
- public void allUnitsShouldBeTheSameInstance() {
+ void allUnitsShouldBeTheSameInstance() {
final var schemaContext = assertEffectiveModelDir("/bugs/bug6972");
assertEquals(3, schemaContext.getModules().size());
final Revision revision = Revision.of("2016-10-20");
- final Module foo = schemaContext.findModule("foo", revision).get();
- final Module bar = schemaContext.findModule("bar", revision).get();
- final Module baz = schemaContext.findModule("baz", revision).get();
+ final var foo = schemaContext.findModule("foo", revision).orElseThrow();
+ final var bar = schemaContext.findModule("bar", revision).orElseThrow();
+ final var baz = schemaContext.findModule("baz", revision).orElseThrow();
final QName barExportCont = QName.create("bar-ns", "bar-export", revision);
final QName barFooCont = QName.create("bar-ns", "bar-foo", revision);
final QName barFooLeaf = QName.create("bar-ns", "foo", revision);
- final UnitsEffectiveStatement unitsBar1 = getEffectiveUnits(bar, barExportCont, barFooLeaf);
+ final var unitsBar1 = getEffectiveUnits(bar, barExportCont, barFooLeaf);
assertSame(unitsBar1, getEffectiveUnits(bar, barFooCont, barFooLeaf));
final QName bazExportCont = QName.create("baz-ns", "baz-export", revision);
private static UnitsEffectiveStatement getEffectiveUnits(final Module module, final QName containerQName,
final QName leafQName) {
- UnitsEffectiveStatement units = null;
-
- final ContainerSchemaNode cont = (ContainerSchemaNode) module.getDataChildByName(containerQName);
+ final var cont = (ContainerSchemaNode) module.getDataChildByName(containerQName);
assertNotNull(cont);
- final LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName);
+ final var leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName);
assertNotNull(leaf);
- for (EffectiveStatement<?, ?> effStmt : ((LeafEffectiveStatement) leaf).effectiveSubstatements()) {
- if (effStmt instanceof UnitsEffectiveStatement) {
- units = (UnitsEffectiveStatement) effStmt;
- break;
- }
- }
-
- return units;
+ return ((LeafEffectiveStatement) leaf).streamEffectiveSubstatements(UnitsEffectiveStatement.class)
+ .findFirst()
+ .orElse(null);
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collection;
-import java.util.Iterator;
import java.util.Map;
import java.util.stream.Collectors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-public class Bug7037Test extends AbstractYangTest {
+class Bug7037Test extends AbstractYangTest {
private static final String FOO_NS = "foo";
private static final String BAR_NS = "bar";
@Test
- public void test() {
+ void test() {
final var context = assertEffectiveModelDir("/bugs/bug7037");
final var unknownSchemaNodes = context.getModuleStatement(foo("foo")) .getDeclared()
assertEquals("bar-ext-con", barExtCont.argument());
final DataSchemaNode root = context.getDataChildByName(foo("root"));
- assertTrue(root instanceof ContainerSchemaNode);
final Collection<? extends UnrecognizedStatement> rootUnknownNodes =
- ((ContainerSchemaNode) root).asEffectiveStatement().getDeclared()
- .declaredSubstatements(UnrecognizedStatement.class);
+ assertInstanceOf(ContainerSchemaNode.class, root).asEffectiveStatement().getDeclared()
+ .declaredSubstatements(UnrecognizedStatement.class);
assertEquals(2, rootUnknownNodes.size());
final Map<QName, UnrecognizedStatement> rootUnknownNodeMap = rootUnknownNodes.stream()
- .collect(Collectors.toMap(u -> u.statementDefinition().getStatementName(), u -> u));
+ .collect(Collectors.toMap(u -> u.statementDefinition().getStatementName(), u -> u));
final UnrecognizedStatement barExt = rootUnknownNodeMap.get(bar("bar-ext"));
final Collection<? extends UnrecognizedStatement> barExtUnknownNodes =
barExt.declaredSubstatements(UnrecognizedStatement.class);
assertEquals(3, barExtUnknownNodes.size());
- final Iterator<? extends UnrecognizedStatement> iterator = barExtUnknownNodes.iterator();
UnrecognizedStatement barExtCont2 = null;
- while (iterator.hasNext()) {
- final UnrecognizedStatement next = iterator.next();
+ for (UnrecognizedStatement next : barExtUnknownNodes) {
if (bar("container").equals(next.statementDefinition().getStatementName())) {
barExtCont2 = next;
break;
* 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.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-public class Bug7038Test extends AbstractYangTest {
+class Bug7038Test extends AbstractYangTest {
@Test
- public void unknownNodeTest() {
- final ModuleStatement bar = assertEffectiveModelDir("/bugs/bug7038")
+ void unknownNodeTest() {
+ final var bar = assertEffectiveModelDir("/bugs/bug7038")
.getModuleStatement(QNameModule.create(XMLNamespace.of("bar"))).getDeclared();
- final UnrecognizedStatement decimal64 = bar.findFirstDeclaredSubstatement(UnrecognizedStatement.class)
- .orElseThrow();
+ final var decimal64 = bar.findFirstDeclaredSubstatement(UnrecognizedStatement.class).orElseThrow();
assertEquals("decimal64", decimal64.argument());
assertEquals(QName.create("foo", "decimal64"), decimal64.statementDefinition().getStatementName());
}
@Test
- public void testYang11() throws Exception {
- final ContainerSchemaNode root = (ContainerSchemaNode) assertEffectiveModelDir("/bugs/bug7038/yang11")
+ void testYang11() {
+ final var root = (ContainerSchemaNode) assertEffectiveModelDir("/bugs/bug7038/yang11")
.getDataChildByName(QName.create("foo", "root"));
- final TypeDefinition<?> typedef = ((LeafSchemaNode) root.getDataChildByName(QName.create("foo", "my-leafref")))
+ final var typedef = ((LeafSchemaNode) root.getDataChildByName(QName.create("foo", "my-leafref")))
.getType();
- assertThat(typedef, instanceOf(LeafrefTypeDefinition.class));
- assertFalse(((LeafrefTypeDefinition) typedef).requireInstance());
+ assertFalse(assertInstanceOf(LeafrefTypeDefinition.class, typedef).requireInstance());
}
@Test
- public void testYang10() throws Exception {
+ void testYang10() {
assertInvalidSubstatementExceptionDir("/bugs/bug7038/yang10",
startsWith("REQUIRE_INSTANCE is not valid for TYPE"));
}
* 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.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-
-public class Bug7146Test {
+class Bug7146Test {
@Test
- public void shouldFailOnSyntaxError() throws ReactorException {
- try {
- StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug7146/foo.yang"));
- fail("RuntimeException should have been thrown because of an unknown character in yang module.");
- } catch (IllegalArgumentException ex) {
- final Throwable cause = ex.getCause();
- assertTrue(cause instanceof YangSyntaxErrorException);
- assertTrue(cause.getMessage().contains("extraneous input '#'"));
- }
+ void shouldFailOnSyntaxError() {
+ final var cause = assertThrows(IllegalArgumentException.class,
+ () -> StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug7146/foo.yang"))).getCause();
+ assertInstanceOf(YangSyntaxErrorException.class, cause);
+ assertThat(cause.getMessage(), containsString("extraneous input '#'"));
}
}
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class Bug7424Test extends AbstractYangTest {
+class Bug7424Test extends AbstractYangTest {
@Test
- public void testRpc()throws Exception {
+ void testRpc() {
assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
- + " '(foo)name' already declared"), "/bugs/bug7424/foo-rpc.yang");
+ + " '(foo)name' already declared"), "/bugs/bug7424/foo-rpc.yang");
}
@Test
- public void testNotification() {
+ void testNotification() {
assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
- + " '(foo)name' already declared"), "/bugs/bug7424/foo-notification.yang");
+ + " '(foo)name' already declared"), "/bugs/bug7424/foo-notification.yang");
}
@Test
- public void testData() {
+ void testData() {
assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
- + " '(foo)name' already declared"), "/bugs/bug7424/foo-data.yang");
+ + " '(foo)name' already declared"), "/bugs/bug7424/foo-data.yang");
}
@Test
- public void testRpcUses() {
+ void testRpcUses() {
assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
- + " '(foo)name' already declared"), "/bugs/bug7424/foo-rpc-uses.yang");
+ + " '(foo)name' already declared"), "/bugs/bug7424/foo-rpc-uses.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
-import org.opendaylight.yangtools.yang.model.api.Deviation;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-public class Bug7440Test extends AbstractYangTest {
+class Bug7440Test extends AbstractYangTest {
@Test
- public void testRestrictedTypeParentSchemaPathInDeviate() {
+ void testRestrictedTypeParentSchemaPathInDeviate() {
final var schemaContext = assertEffectiveModelDir("/bugs/bug7440");
- final Revision revision = Revision.of("2016-12-23");
- final Module foo = schemaContext.findModule("foo", revision).get();
- final Module bar = schemaContext.findModule("bar", revision).get();
+ final var revision = Revision.of("2016-12-23");
+ final var foo = schemaContext.findModule("foo", revision).get();
+ final var bar = schemaContext.findModule("bar", revision).get();
- final Collection<? extends Deviation> deviations = foo.getDeviations();
+ final var deviations = foo.getDeviations();
assertEquals(1, deviations.size());
- final Deviation deviation = deviations.iterator().next();
+ final var deviation = deviations.iterator().next();
- final Collection<? extends DeviateDefinition> deviates = deviation.getDeviates();
+ final var deviates = deviation.getDeviates();
assertEquals(1, deviates.size());
- final DeviateDefinition deviateReplace = deviates.iterator().next();
+ final var deviateReplace = deviates.iterator().next();
- final TypeDefinition<?> deviatedType = deviateReplace.getDeviatedType();
+ final var deviatedType = deviateReplace.getDeviatedType();
assertEquals(QName.create(bar.getQNameModule(), "uint32"), deviatedType.getQName());
}
}
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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.Submodule;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-public class Bug7480Test {
+class Bug7480Test {
@Test
- public void libSourcesTest() throws Exception {
- final SchemaContext context = parseYangSources("/bugs/bug7480/files", "/bugs/bug7480/lib");
+ void libSourcesTest() throws Exception {
+ final var context = parseYangSources("/bugs/bug7480/files", "/bugs/bug7480/lib");
assertNotNull(context);
- final Collection<? extends Module> modules = context.getModules();
+ final var modules = context.getModules();
assertEquals(8, modules.size());
assertNotNull(context.findModule(XMLNamespace.of("foo-imp"), Revision.of("2017-01-23")));
assertEquals(1, context.findModules(XMLNamespace.of("bar")).size());
assertEquals(1, context.findModules(XMLNamespace.of("baz")).size());
assertTrue(context.findModule(XMLNamespace.of("baz-imp"), Revision.of("2002-01-01")).isPresent());
- final Collection<? extends Module> foo = context.findModules(XMLNamespace.of("foo"));
+ final var foo = context.findModules(XMLNamespace.of("foo"));
assertEquals(1, foo.size());
- final Collection<? extends Submodule> subFoos = foo.iterator().next().getSubmodules();
+ final var subFoos = foo.iterator().next().getSubmodules();
assertEquals(1, subFoos.size());
- final Module parentMod = context.findModule(XMLNamespace.of("parent-mod-ns"), Revision.of("2017-09-07")).get();
+ final var parentMod = context.findModule(XMLNamespace.of("parent-mod-ns"), Revision.of("2017-09-07")).get();
assertEquals(1, parentMod.getSubmodules().size());
}
@Test
- public void missingRelevantImportTest() throws Exception {
+ void missingRelevantImportTest() throws Exception {
final var ex = assertThrows(SomeModifiersUnresolvedException.class,
() -> parseYangSources("/bugs/bug7480/files-2", "/bugs/bug7480/lib-2"));
final String message = ex.getSuppressed().length > 0
}
@Test
- public void testHandlingOfMainSourceConflictingWithLibSource() throws Exception {
+ void testHandlingOfMainSourceConflictingWithLibSource() throws Exception {
// parent module as main source and as lib source at the same time
// parser should remove it from the required lib sources and thus avoid module namespace collision
- final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
+ final var schemaContext = RFC7950Reactors.defaultReactor().newBuild()
.addSource(StmtTestUtils.sourceForResource(
"/bugs/bug7480/main-source-lib-source-conflict-test/parent-module.yang"))
.addLibSources(
}
@Test
- public void testHandlingOfMainSourceConflictingWithLibSource2() throws Exception {
+ void testHandlingOfMainSourceConflictingWithLibSource2() throws Exception {
// submodule as main source and as lib source at the same time
// parser should remove it from the required lib sources and thus avoid submodule name collision
- final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
+ final var schemaContext = RFC7950Reactors.defaultReactor().newBuild()
.addSource(StmtTestUtils.sourceForResource(
"/bugs/bug7480/main-source-lib-source-conflict-test/child-module.yang"))
.addLibSources(
}
private static EffectiveModelContext parseYangSources(final String yangFilesDirectoryPath,
- final String yangLibsDirectoryPath) throws Exception {
+ final String yangLibsDirectoryPath) throws Exception {
return RFC7950Reactors.defaultReactor().newBuild()
.addSources(TestUtils.loadSources(yangFilesDirectoryPath))
.addLibSources(TestUtils.loadSources(yangLibsDirectoryPath))
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-public class Bug7865Test extends AbstractYangTest {
+class Bug7865Test extends AbstractYangTest {
@Test
- public void test() throws Exception {
- final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug7865");
- final DataSchemaNode root = context.getDataChildByName(foo("root"));
- assertTrue(root instanceof ContainerSchemaNode);
- final Collection<? extends UnrecognizedStatement> unknownSchemaNodes = ((ContainerSchemaNode) root)
- .asEffectiveStatement().getDeclared().declaredSubstatements(UnrecognizedStatement.class);
+ void test() {
+ final var context = assertEffectiveModelDir("/bugs/bug7865");
+ final var unknownSchemaNodes = assertInstanceOf(ContainerSchemaNode.class,
+ context.getDataChildByName(foo("root"))).asEffectiveStatement().getDeclared()
+ .declaredSubstatements(UnrecognizedStatement.class);
assertEquals(1, unknownSchemaNodes.size());
- final UnrecognizedStatement unknownNode = unknownSchemaNodes.iterator().next();
- final Collection<? extends UnrecognizedStatement> subUnknownSchemaNodes =
- unknownNode.declaredSubstatements(UnrecognizedStatement.class);
+ final var unknownNode = unknownSchemaNodes.iterator().next();
+ final var subUnknownSchemaNodes = unknownNode.declaredSubstatements(UnrecognizedStatement.class);
assertEquals(1, subUnknownSchemaNodes.size());
- final UnrecognizedStatement subUnknownNode = subUnknownSchemaNodes.iterator().next();
- final Collection<? extends UnrecognizedStatement> subSubUnknownSchemaNodes =
- subUnknownNode.declaredSubstatements(UnrecognizedStatement.class);
+ final var subUnknownNode = subUnknownSchemaNodes.iterator().next();
+ final var subSubUnknownSchemaNodes = subUnknownNode.declaredSubstatements(UnrecognizedStatement.class);
assertEquals(1, subSubUnknownSchemaNodes.size());
assertEquals("p", subSubUnknownSchemaNodes.iterator().next().argument());
*/
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
-public class Bug7879Test extends AbstractYangTest {
+class Bug7879Test extends AbstractYangTest {
private static final XMLNamespace NS = XMLNamespace.of("my-model-ns");
@Test
- public void test() throws Exception {
- final ModuleEffectiveStatement module = assertEffectiveModelDir("/bugs/bug7879")
- .getModuleStatement(qn("my-model"));
+ void test() throws Exception {
+ final var 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);
- assertThat(container, instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class, module.findSchemaTreeNode(
+ qn("my-alarm"), qn("my-content"), qn("my-event-container")).orElseThrow());
- final SchemaTreeEffectiveStatement<?> leaf = module.findSchemaTreeNode(
- 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());
+ assertEquals(Optional.of("new description"),
+ assertInstanceOf(LeafSchemaNode.class, module.findSchemaTreeNode(
+ qn("my-alarm"), qn("my-content"), qn("my-event-value")).orElseThrow()).getDescription());
}
private static QName qn(final String localName) {
*/
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.fail;
-import java.io.File;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.junit.jupiter.api.Test;
-public class Bug7954Test {
+class Bug7954Test extends AbstractYangTest {
@Test
- public void testParsingTheSameModuleTwice() throws Exception {
- final File yang = new File(getClass().getResource("/bugs/bug7954/foo.yang").toURI());
-
- try {
- StmtTestUtils.parseYangSources(yang, yang);
- fail("An exception should have been thrown because of adding the same YANG module twice.");
- } catch (final ReactorException ex) {
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Module namespace collision: foo-ns."));
- }
+ void testParsingTheSameModuleTwice() {
+ assertSourceException(startsWith("Module namespace collision: foo-ns."),
+ "/bugs/bug7954/foo.yang", "/bugs/bug7954/foo.yang");
}
@Test
- public void testParsingTheSameSubmoduleTwice() throws Exception {
- final File yang = new File(getClass().getResource("/bugs/bug7954/bar.yang").toURI());
- final File childYang = new File(getClass().getResource("/bugs/bug7954/subbar.yang").toURI());
-
- try {
- StmtTestUtils.parseYangSources(yang, childYang, childYang);
- fail("An exception should have been thrown because of adding the same YANG submodule twice.");
- } catch (final ReactorException ex) {
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Submodule name collision: subbar."));
- }
+ void testParsingTheSameSubmoduleTwice() throws Exception {
+ assertSourceException(startsWith("Submodule name collision: subbar."), "/bugs/bug7954/bar.yang",
+ "/bugs/bug7954/subbar.yang", "/bugs/bug7954/subbar.yang");
}
}
*/
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-public class Bug8126Test extends AbstractYangTest {
+class Bug8126Test extends AbstractYangTest {
private static final XMLNamespace FOO_NS = XMLNamespace.of("foo");
private static final XMLNamespace BAR_NS = XMLNamespace.of("bar");
@Test
- public void testValidAugments() {
+ void testValidAugments() {
final var fooModule = assertEffectiveModelDir("/bugs/bug8126/valid")
.getModuleStatement(QNameModule.create(FOO_NS));
- assertThat(fooModule.findSchemaTreeNode(
+ assertInstanceOf(LeafSchemaNode.class, fooModule.findSchemaTreeNode(
foo("root"), bar("my-container"), bar("my-choice"), bar("one"), bar("one"), bar("mandatory-leaf"))
- .orElse(null), instanceOf(LeafSchemaNode.class));
- assertThat(fooModule.findSchemaTreeNode(foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2"))
- .orElse(null), instanceOf(LeafSchemaNode.class));
+ .orElseThrow());
+ assertInstanceOf(LeafSchemaNode.class, fooModule.findSchemaTreeNode(
+ foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2"))
+ .orElseThrow());
assertEquals(Optional.empty(), fooModule.findSchemaTreeNode(foo("root"), bar("mandatory-list")));
assertEquals(Optional.empty(), fooModule.findSchemaTreeNode(
foo("root"), bar("mandatory-container"), bar("mandatory-choice")));
}
@Test
- public void testAugmentMandatoryChoice() {
+ void testAugmentMandatoryChoice() {
assertInferenceExceptionDir("/bugs/bug8126/inv-choice", startsWith(
"An augment cannot add node 'mandatory-choice' because it is mandatory and in module different than "));
}
@Test
- public void testAugmentMandatoryList() {
+ void testAugmentMandatoryList() {
assertInferenceExceptionDir("/bugs/bug8126/inv-list", startsWith(
"An augment cannot add node 'mandatory-list' because it is mandatory and in module different than "));
}
@Test
- public void testAugmentMandatoryContainer() {
+ void testAugmentMandatoryContainer() {
assertInferenceExceptionDir("/bugs/bug8126/inv-cont", startsWith(
"An augment cannot add node 'mandatory-leaf-3' because it is mandatory and in module different than "));
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.SetMultimap;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
-
-public class Bug8307Test {
+class Bug8307Test {
private static final StatementStreamSource FOO_MODULE = sourceForResource("/bugs/bug8307/foo.yang");
private static final StatementStreamSource BAR_MODULE = sourceForResource("/bugs/bug8307/bar.yang");
private static final StatementStreamSource BAZ_MODULE = sourceForResource("/bugs/bug8307/baz.yang");
private static final QName MY_BAZ_CONT = QName.create(BAZ, "my-baz-cont");
@Test
- public void testDeviationsSupportedInSomeModules() throws Exception {
- final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations =
- ImmutableSetMultimap.<QNameModule, QNameModule>builder()
+ void testDeviationsSupportedInSomeModules() throws Exception {
+ final var schemaContext = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(FOO_MODULE, BAR_MODULE, BAZ_MODULE, FOOBAR_MODULE)
+ .setModulesWithSupportedDeviations(ImmutableSetMultimap.<QNameModule, QNameModule>builder()
.put(FOO, BAR)
.put(FOO, BAZ)
.put(BAR, BAZ)
- .build();
-
- final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(FOO_MODULE, BAR_MODULE, BAZ_MODULE, FOOBAR_MODULE)
- .setModulesWithSupportedDeviations(modulesWithSupportedDeviations)
- .buildEffective();
+ .build())
+ .buildEffective();
assertNotNull(schemaContext);
assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_FOO_CONT_A));
}
@Test
- public void testDeviationsSupportedInAllModules() throws Exception {
- final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(FOO_MODULE, BAR_MODULE, BAZ_MODULE, FOOBAR_MODULE)
- .buildEffective();
+ void testDeviationsSupportedInAllModules() throws Exception {
+ final var schemaContext = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(FOO_MODULE, BAR_MODULE, BAZ_MODULE, FOOBAR_MODULE)
+ .buildEffective();
assertNotNull(schemaContext);
assertEquals(Optional.empty(), schemaContext.findDataTreeChild(MY_FOO_CONT_A));
}
@Test
- public void testDeviationsSupportedInNoModule() throws Exception {
- final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(FOO_MODULE, BAR_MODULE, BAZ_MODULE, FOOBAR_MODULE)
- .setModulesWithSupportedDeviations(ImmutableSetMultimap.of())
- .buildEffective();
+ void testDeviationsSupportedInNoModule() throws Exception {
+ final var schemaContext = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(FOO_MODULE, BAR_MODULE, BAZ_MODULE, FOOBAR_MODULE)
+ .setModulesWithSupportedDeviations(ImmutableSetMultimap.of())
+ .buildEffective();
assertNotNull(schemaContext);
assertNotNull(schemaContext.findDataTreeChild(MY_FOO_CONT_A).orElse(null));
}
@Test
- public void shouldFailOnAttemptToDeviateTheSameModule() {
- final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(FOO_INVALID_MODULE);
+ void shouldFailOnAttemptToDeviateTheSameModule() {
+ final var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(FOO_INVALID_MODULE);
- try {
- reactor.buildEffective();
- fail("Deviation that targets the same module as the one it is defined is forbidden.");
- } catch (final ReactorException ex) {
- final Throwable cause = ex.getCause();
- assertTrue(cause instanceof InferenceException);
- assertTrue(cause.getMessage().startsWith(
- "Deviation must not target the same module as the one it is defined in"));
- }
+ final var cause = assertInstanceOf(InferenceException.class,
+ assertThrows(ReactorException.class, reactor::buildEffective).getCause());
+ assertThat(cause.getMessage(),
+ startsWith("Deviation must not target the same module as the one it is defined in"));
}
@Test
- public void shouldFailOnAttemptToDeviateTheSameModule2() {
- final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(BAR_INVALID_MODULE, BAZ_INVALID_MODULE);
-
- try {
- reactor.buildEffective();
- fail("Deviation that targets the same module as the one it is defined is forbidden.");
- } catch (final ReactorException ex) {
- final Throwable cause = ex.getCause();
- assertTrue(cause instanceof InferenceException);
- assertTrue(cause.getMessage().startsWith(
- "Deviation must not target the same module as the one it is defined in"));
- }
+ void shouldFailOnAttemptToDeviateTheSameModule2() {
+ final var reactor = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(BAR_INVALID_MODULE, BAZ_INVALID_MODULE);
+
+ final var cause = assertInstanceOf(InferenceException.class,
+ assertThrows(ReactorException.class, reactor::buildEffective).getCause());
+ assertThat(cause.getMessage(),
+ startsWith("Deviation must not target the same module as the one it is defined in"));
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-public class Bug8597Test extends AbstractYangTest {
+class Bug8597Test extends AbstractYangTest {
@Test
- public void test() throws Exception {
- final var foo = assertEffectiveModelDir("/bugs/bug8597").findModule("foo").orElseThrow();
- for (ModuleImport moduleImport : foo.getImports()) {
+ void test() {
+ for (var moduleImport : assertEffectiveModelDir("/bugs/bug8597").findModule("foo").orElseThrow().getImports()) {
switch (moduleImport.getModuleName().getLocalName()) {
case "bar":
assertEquals(Revision.ofNullable("1970-01-01"), moduleImport.getRevision());
import static org.hamcrest.CoreMatchers.containsString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class Bug8831Test extends AbstractYangTest {
+class Bug8831Test extends AbstractYangTest {
@Test
- public void test() throws Exception {
+ void test() {
assertEffectiveModelDir("/bugs/bug8831/valid");
}
@Test
- public void invalidModelsTest() {
+ void invalidModelsTest() {
assertSourceException(containsString("has default value 'any' marked with an if-feature statement"),
"/bugs/bug8831/invalid/inv-model.yang");
}
@Test
- public void invalidModelsTest2() {
+ void invalidModelsTest2() {
assertSourceException(containsString("has default value 'any' marked with an if-feature statement"),
"/bugs/bug8831/invalid/inv-model2.yang");
}
*/
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.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import com.google.common.collect.ImmutableSet;
import java.util.Optional;
-import org.junit.Test;
+import java.util.Set;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
-public class Bug8922Test extends AbstractYangTest {
+class Bug8922Test extends AbstractYangTest {
private static final QName MY_CON = QName.create("foo", "my-con");
private static final QName TARGET = QName.create("foo", "target");
@Test
- public void testAllFeaturesSupported() {
+ void testAllFeaturesSupported() {
final var context = assertEffectiveModel("/bugs/bug8922/foo.yang");
- final var findNode = context.findDataTreeChild(TARGET, MY_CON).get();
- assertThat(findNode, instanceOf(ContainerSchemaNode.class));
+ final var findNode = assertInstanceOf(ContainerSchemaNode.class,
+ context.findDataTreeChild(TARGET, MY_CON).orElseThrow());
assertEquals(Optional.of("New description"), findNode.getDescription());
assertEquals(1, context.findModuleStatements("foo").iterator().next()
}
@Test
- public void testNoFeatureSupported() throws Exception {
- final var context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang", ImmutableSet.of());
+ void testNoFeatureSupported() throws Exception {
+ final var context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang", Set.of());
assertNotNull(context);
assertEquals(Optional.empty(), context.findDataTreeChild(TARGET, MY_CON));
- assertTrue(context.getAvailableAugmentations().isEmpty());
+ assertEquals(Set.of(), context.getAvailableAugmentations());
assertEquals(0, context.findModuleStatements("foo").iterator().next()
.streamEffectiveSubstatements(FeatureEffectiveStatement.class).count());
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.api.Submodule;
-public class Bug9005Test extends AbstractYangTest {
+class Bug9005Test extends AbstractYangTest {
@Test
- public void test() {
- final var context = assertEffectiveModelDir("/bugs/bug9005");
+ void test() {
+ final var foo = assertEffectiveModelDir("/bugs/bug9005").findModule("foo", Revision.of("2017-07-07"))
+ .orElseThrow();
- final Module foo = context.findModule("foo", Revision.of("2017-07-07")).get();
-
- final Collection<? extends ModuleImport> imports = foo.getImports();
+ final var imports = foo.getImports();
assertEquals(1, imports.size());
- final ModuleImport imp1 = imports.iterator().next();
+ final var imp1 = imports.iterator().next();
assertEquals(Unqualified.of("bar-2"), imp1.getModuleName());
assertEquals("bar", imp1.getPrefix());
assertEquals(Revision.ofNullable("2000-01-02"), imp1.getRevision());
- final Collection<? extends Submodule> submodules = foo.getSubmodules();
+ final var submodules = foo.getSubmodules();
assertEquals(1, submodules.size());
- final Submodule submodule = submodules.iterator().next();
- final Collection<? extends ModuleImport> subImports = submodule.getImports();
+ final var submodule = submodules.iterator().next();
+ final var subImports = submodule.getImports();
assertEquals(1, subImports.size());
- final ModuleImport subImp1 = subImports.iterator().next();
+ final var subImp1 = subImports.iterator().next();
assertEquals(Unqualified.of("bar-1"), subImp1.getModuleName());
assertEquals("bar", subImp1.getPrefix());
assertEquals(Revision.ofNullable("2000-01-01"), subImp1.getRevision());
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import com.google.common.collect.Iterables;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-public class Bug9242Test extends AbstractYangTest {
+class Bug9242Test extends AbstractYangTest {
@Test
- public void testDeviateReplaceWithUserDefinedTypes() {
+ void testDeviateReplaceWithUserDefinedTypes() {
final var schemaContext = assertEffectiveModelDir("/bugs/bug9242/");
final Revision revision = Revision.of("2017-10-13");
assertNotNull(deviatedMyLeaf2Type);
final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
- impModule.getQNameModule(), "my-leaf"));
+ impModule.getQNameModule(), "my-leaf"));
assertSame(deviatedMyLeafType, myLeaf.getType());
final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
- impModule.getQNameModule(), "my-leaf-2"));
+ impModule.getQNameModule(), "my-leaf-2"));
assertSame(deviatedMyLeaf2Type, myLeaf2.getType());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class Bug9244Test extends AbstractYangTest {
+class Bug9244Test extends AbstractYangTest {
@Test
- public void testDeviateReplaceOfImplicitSubstatements() {
+ void testDeviateReplaceOfImplicitSubstatements() {
final var schemaContext = assertEffectiveModelDir("/bugs/bug9244/");
final Module barModule = schemaContext.findModule("bar", Revision.of("2017-10-13")).get();
final ContainerSchemaNode barCont = (ContainerSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "bar-cont"));
- assertNotNull(barCont);
+ QName.create(barModule.getQNameModule(), "bar-cont"));
assertEquals(Optional.of(Boolean.FALSE), barCont.effectiveConfig());
final LeafListSchemaNode barLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "bar-leaf-list"));
- assertNotNull(barLeafList);
+ QName.create(barModule.getQNameModule(), "bar-leaf-list"));
final ElementCountConstraint constraint = barLeafList.getElementCountConstraint().get();
- assertEquals((Object) 5, constraint.getMinElements());
- assertEquals((Object) 10, constraint.getMaxElements());
+ assertEquals(5, constraint.getMinElements());
+ assertEquals(10, constraint.getMaxElements());
final LeafSchemaNode barLeaf = (LeafSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "bar-leaf"));
- assertNotNull(barLeaf);
+ QName.create(barModule.getQNameModule(), "bar-leaf"));
assertTrue(barLeaf.isMandatory());
}
}
package org.opendaylight.yangtools.yang.stmt;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Optional;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class CaseStmtTest extends AbstractYangTest {
+class CaseStmtTest extends AbstractYangTest {
private static final Optional<Boolean> OPT_FALSE = Optional.of(Boolean.FALSE);
private static final Optional<Boolean> OPT_TRUE = Optional.of(Boolean.TRUE);
private DataSchemaNode tempThirdChild;
private CaseSchemaNode tempChoice;
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
schema = assertEffectiveModelDir("/case-test");
Revision rev = Revision.of("2015-09-09");
rootFoo = schema.findModule("foo", rev).get();
}
@Test
- public void caseTest() {
+ void caseTest() {
tempChild = rootFoo.getDataChildByName(QName.create(qnameFoo, "root-fff"));
assertNotNull(tempChild);
assertEquals(OPT_FALSE, tempChild.effectiveConfig());
}
@Test
- public void shortCaseTest() {
+ void shortCaseTest() {
tempChild = rootBar.getDataChildByName(QName.create(qnameBar, "sh-root-fff"));
assertNotNull(tempChild);
assertEquals(OPT_FALSE, tempChild.effectiveConfig());
}
@Test
- public void testInferenceExceptionChoice() {
+ void testInferenceExceptionChoice() {
assertInferenceExceptionDir("/case-test/case-test-exceptions/choice",
startsWith("Parent node has config=false, this node must not be specifed as config=true [at "));
}
@Test
- public void testInferenceExceptionCase() {
+ void testInferenceExceptionCase() {
assertInferenceExceptionDir("/case-test/case-test-exceptions/case",
startsWith("Parent node has config=false, this node must not be specifed as config=true [at "));
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-public class ChoiceStmtTest extends AbstractModelTest {
+class ChoiceStmtTest extends AbstractModelTest {
@Test
- public void choiceAndCaseTest() {
+ void choiceAndCaseTest() {
final ContainerSchemaNode container = (ContainerSchemaNode) FOO.getDataChildByName(fooQName("transfer"));
final ChoiceSchemaNode choice = (ChoiceSchemaNode) container.getDataChildByName(fooQName("how"));
assertEquals(5, choice.getCases().size());
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UsesEffectiveStatement;
-public class ControllerStmtParserTest extends AbstractYangTest {
+class ControllerStmtParserTest extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
final var context = assertEffectiveModelDir("/sal-broker-impl");
salDomBrokerImplModuleTest(context);
configModuleTest(context);
for (final AugmentationSchemaNode augmentationSchema : module.getAugmentations()) {
final DataSchemaNode dataNode = augmentationSchema.dataChildByName(
QName.create(module.getQNameModule(), "dom-broker-impl"));
- if (dataNode instanceof CaseSchemaNode) {
- final CaseSchemaNode caseNode = (CaseSchemaNode) dataNode;
+ if (dataNode instanceof CaseSchemaNode caseNode) {
final DataSchemaNode dataNode2 = caseNode.dataChildByName(
QName.create(module.getQNameModule(), "async-data-broker"));
- if (dataNode2 instanceof ContainerSchemaNode) {
- final ContainerSchemaNode containerNode = (ContainerSchemaNode) dataNode2;
+ if (dataNode2 instanceof ContainerSchemaNode containerNode) {
final DataSchemaNode leaf = containerNode
- .getDataChildByName(QName.create(module.getQNameModule(), "type"));
+ .getDataChildByName(QName.create(module.getQNameModule(), "type"));
assertEquals(0, leaf.getUnknownSchemaNodes().size());
final Collection<? extends UnrecognizedStatement> unknownSchemaNodes =
final DataSchemaNode dataNode = configModule.getDataChildByName(QName.create(configModule.getQNameModule(),
"modules"));
- assertTrue(dataNode instanceof ContainerSchemaNode);
+ final ContainerSchemaNode moduleContainer = assertInstanceOf(ContainerSchemaNode.class, dataNode);
- final ContainerSchemaNode moduleContainer = (ContainerSchemaNode) dataNode;
final DataSchemaNode dataChildList = moduleContainer
- .getDataChildByName(QName.create(configModule.getQNameModule(), "module"));
+ .getDataChildByName(QName.create(configModule.getQNameModule(), "module"));
+ final ListSchemaNode listModule = assertInstanceOf(ListSchemaNode.class, dataChildList);
- assertTrue(dataChildList instanceof ListSchemaNode);
-
- final ListSchemaNode listModule = (ListSchemaNode) dataChildList;
final DataSchemaNode dataChildChoice = listModule
- .getDataChildByName(QName.create(configModule.getQNameModule(), "configuration"));
-
- assertTrue(dataChildChoice instanceof ChoiceSchemaNode);
+ .getDataChildByName(QName.create(configModule.getQNameModule(), "configuration"));
+ final ChoiceSchemaNode confChoice = assertInstanceOf(ChoiceSchemaNode.class, dataChildChoice);
- final ChoiceSchemaNode confChoice = (ChoiceSchemaNode) dataChildChoice;
final CaseSchemaNode caseNodeByName = confChoice.findCaseNodes("dom-broker-impl").iterator().next();
assertNotNull(caseNodeByName);
final DataSchemaNode dataNode2 = caseNodeByName
- .getDataChildByName(QName.create(module.getQNameModule(), "async-data-broker"));
- assertTrue(dataNode2 instanceof ContainerSchemaNode);
+ .getDataChildByName(QName.create(module.getQNameModule(), "async-data-broker"));
+ final ContainerSchemaNode containerNode = assertInstanceOf(ContainerSchemaNode.class, dataNode2);
- final ContainerSchemaNode containerNode = (ContainerSchemaNode) dataNode2;
final DataSchemaNode leaf = containerNode.getDataChildByName(QName.create(module.getQNameModule(), "type"));
assertEquals(0, leaf.getUnknownSchemaNodes().size());
final CaseSchemaNode domInmemoryDataBroker = confChoice.findCaseNodes("dom-inmemory-data-broker").iterator()
- .next();
+ .next();
assertNotNull(domInmemoryDataBroker);
final DataSchemaNode schemaService = domInmemoryDataBroker
- .getDataChildByName(QName.create(module.getQNameModule(), "schema-service"));
- assertTrue(schemaService instanceof ContainerSchemaNode);
-
- final ContainerSchemaNode schemaServiceContainer = (ContainerSchemaNode) schemaService;
+ .getDataChildByName(QName.create(module.getQNameModule(), "schema-service"));
+ final ContainerSchemaNode schemaServiceContainer = assertInstanceOf(ContainerSchemaNode.class, schemaService);
assertEquals(1, schemaServiceContainer.getUses().size());
final UsesNode uses = schemaServiceContainer.getUses().iterator().next();
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-
-import java.text.ParseException;
-import java.util.Collection;
-import java.util.Set;
-import java.util.function.Predicate;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.Submodule;
import org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DefaultStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-
-public class DeclaredStatementsTest {
+class DeclaredStatementsTest extends AbstractYangTest {
@Test
- public void testDeclaredAnyXml() throws ReactorException {
- final StatementStreamSource anyxmlStmtModule =
- sourceForResource("/declared-statements-test/anyxml-declared-test.yang");
-
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(anyxmlStmtModule);
- assertNotNull(schemaContext);
+ void testDeclaredAnyXml() {
+ final var schemaContext = assertEffectiveModel("/declared-statements-test/anyxml-declared-test.yang");
final Module testModule = schemaContext.findModules("anyxml-declared-test").iterator().next();
assertNotNull(testModule);
final AnyxmlSchemaNode anyxmlSchemaNode = (AnyxmlSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "foobar"));
+ QName.create(testModule.getQNameModule(), "foobar"));
assertNotNull(anyxmlSchemaNode);
final AnyxmlStatement anyxmlStatement = ((AnyxmlEffectiveStatement) anyxmlSchemaNode).getDeclared();
final var ifFeatureStatements = anyxmlStatement.getIfFeatures();
assertNotNull(ifFeatureStatements);
assertEquals(1, ifFeatureStatements.size());
- final Predicate<Set<QName>> ifFeaturePredicate = ifFeatureStatements.iterator().next().argument();
+ final var ifFeaturePredicate = ifFeatureStatements.iterator().next().argument();
assertNotNull(ifFeaturePredicate);
final var mustStatements = anyxmlStatement.getMustStatements();
assertTrue(mustStatement.getReference().isPresent());
final ConfigStatement configStatement = anyxmlStatement.getConfig().orElseThrow();
- assertFalse(configStatement.getValue());
+ assertFalse(configStatement.argument());
final StatusStatement statusStatement = anyxmlStatement.getStatus().orElseThrow();
final Status status = statusStatement.argument();
}
@Test
- public void testDeclaredChoice() throws ReactorException {
- final StatementStreamSource choiceStmtModule =
- sourceForResource("/declared-statements-test/choice-declared-test.yang");
-
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(choiceStmtModule);
- assertNotNull(schemaContext);
+ void testDeclaredChoice() {
+ final var schemaContext = assertEffectiveModel("/declared-statements-test/choice-declared-test.yang");
final Module testModule = schemaContext.findModules("choice-declared-test").iterator().next();
assertNotNull(testModule);
final ChoiceSchemaNode choiceSchemaNode = (ChoiceSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-choice"));
+ QName.create(testModule.getQNameModule(), "test-choice"));
assertNotNull(choiceSchemaNode);
final ChoiceStatement choiceStatement = ((ChoiceEffectiveStatement) choiceSchemaNode).getDeclared();
}
@Test
- public void testDeclaredAugment() throws ReactorException {
- final StatementStreamSource augmentStmtModule =
- sourceForResource("/declared-statements-test/augment-declared-test.yang");
-
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(augmentStmtModule);
- assertNotNull(schemaContext);
+ void testDeclaredAugment() throws ReactorException {
+ final var schemaContext = assertEffectiveModel("/declared-statements-test/augment-declared-test.yang");
- final Module testModule = schemaContext.findModules("augment-declared-test").iterator().next();
+ final var testModule = schemaContext.findModules("augment-declared-test").iterator().next();
assertNotNull(testModule);
- final Collection<? extends AugmentationSchemaNode> augmentationSchemas = testModule.getAugmentations();
+ final var augmentationSchemas = testModule.getAugmentations();
assertNotNull(augmentationSchemas);
assertEquals(1, augmentationSchemas.size());
final SchemaNodeIdentifier targetNode = augmentStatement.argument();
assertNotNull(targetNode);
- final Collection<? extends DataDefinitionStatement> augmentStatementDataDefinitions =
- augmentStatement.getDataDefinitions();
+ final var augmentStatementDataDefinitions = augmentStatement.getDataDefinitions();
assertNotNull(augmentStatementDataDefinitions);
assertEquals(1, augmentStatementDataDefinitions.size());
}
@Test
- public void testDeclaredModuleAndSubmodule() throws ReactorException {
- final StatementStreamSource parentModule =
- sourceForResource("/declared-statements-test/parent-module-declared-test.yang");
-
- final StatementStreamSource childModule =
- sourceForResource("/declared-statements-test/child-module-declared-test.yang");
-
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(parentModule, childModule);
- assertNotNull(schemaContext);
+ void testDeclaredModuleAndSubmodule() throws ReactorException {
+ final var schemaContext = assertEffectiveModel("/declared-statements-test/parent-module-declared-test.yang",
+ "/declared-statements-test/child-module-declared-test.yang");
final Module testModule = schemaContext.findModules("parent-module-declared-test").iterator().next();
assertNotNull(testModule);
final IncludeStatement includeStatement = moduleStatement.getIncludes().iterator().next();
assertEquals(Unqualified.of("child-module-declared-test"), includeStatement.argument());
- final Collection<? extends Submodule> submodules = testModule.getSubmodules();
+ final var submodules = testModule.getSubmodules();
assertNotNull(submodules);
assertEquals(1, submodules.size());
}
@Test
- public void testDeclaredModule() throws ReactorException, ParseException {
- final StatementStreamSource rootModule =
- sourceForResource("/declared-statements-test/root-module-declared-test.yang");
-
- final StatementStreamSource importedModule =
- sourceForResource("/declared-statements-test/imported-module-declared-test.yang");
-
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(rootModule, importedModule);
- assertNotNull(schemaContext);
+ void testDeclaredModule() {
+ final var schemaContext = assertEffectiveModel("/declared-statements-test/root-module-declared-test.yang",
+ "/declared-statements-test/imported-module-declared-test.yang");
final Revision revision = Revision.of("2016-09-28");
final Module testModule = schemaContext.findModule("root-module-declared-test", revision).orElseThrow();
assertEquals(1, featureStatement.getIfFeatures().size());
assertEquals(2, moduleStatement.getIdentities().size());
- IdentityStatement identityStatement = null;
- for (final IdentityStatement identity : moduleStatement.getIdentities()) {
- if (identity.argument().getLocalName().equals("test-id")) {
- identityStatement = identity;
- }
- }
+ IdentityStatement identityStatement = moduleStatement.getIdentities().stream()
+ .filter(identity -> identity.argument().getLocalName().equals("test-id"))
+ .findFirst()
+ .orElseThrow();
assertEquals("test-base-id", identityStatement.getBases().iterator().next().argument().getLocalName());
assertEquals(Status.CURRENT, identityStatement.getStatus().orElseThrow().argument());
}
@Test
- public void testDeclaredContainer() throws ReactorException {
- final StatementStreamSource containerStmtModule =
- sourceForResource("/declared-statements-test/container-declared-test.yang");
-
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(containerStmtModule);
- assertNotNull(schemaContext);
+ void testDeclaredContainer() throws ReactorException {
+ final var schemaContext = assertEffectiveModel("/declared-statements-test/container-declared-test.yang");
final Module testModule = schemaContext.findModules("container-declared-test").iterator().next();
assertNotNull(testModule);
final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container"));
+ QName.create(testModule.getQNameModule(), "test-container"));
assertNotNull(containerSchemaNode);
final ContainerStatement containerStatement =
- ((ContainerEffectiveStatement) containerSchemaNode).getDeclared();
+ ((ContainerEffectiveStatement) containerSchemaNode).getDeclared();
final QName name = containerStatement.argument();
assertNotNull(name);
final WhenStatement containerStatementWhen = containerStatement.getWhenStatement().orElseThrow();
- final Collection<? extends IfFeatureStatement> containerStatementIfFeatures =
- containerStatement.getIfFeatures();
+ final var containerStatementIfFeatures = containerStatement.getIfFeatures();
assertNotNull(containerStatementIfFeatures);
assertEquals(1, containerStatementIfFeatures.size());
- final Collection<? extends MustStatement> containerStatementMusts = containerStatement.getMustStatements();
+ final var containerStatementMusts = containerStatement.getMustStatements();
assertNotNull(containerStatementMusts);
assertEquals(1, containerStatementMusts.size());
assertTrue(containerStatement.getDescription().isPresent());
assertTrue(containerStatement.getReference().isPresent());
- final Collection<? extends TypedefStatement> containerStatementTypedefs = containerStatement.getTypedefs();
+ final var containerStatementTypedefs = containerStatement.getTypedefs();
assertNotNull(containerStatementTypedefs);
assertEquals(1, containerStatementTypedefs.size());
- final Collection<? extends GroupingStatement> containerStatementGroupings = containerStatement.getGroupings();
+ final var containerStatementGroupings = containerStatement.getGroupings();
assertNotNull(containerStatementGroupings);
assertEquals(1, containerStatementGroupings.size());
- final Collection<? extends DataDefinitionStatement> containerStatementDataDefinitions =
- containerStatement.getDataDefinitions();
+ final var containerStatementDataDefinitions = containerStatement.getDataDefinitions();
assertNotNull(containerStatementDataDefinitions);
assertEquals(1, containerStatementDataDefinitions.size());
package org.opendaylight.yangtools.yang.stmt;
import static org.hamcrest.CoreMatchers.containsString;
-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.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
-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.ReactorException;
-public class DeviationResolutionTest extends AbstractYangTest {
+class DeviationResolutionTest extends AbstractYangTest {
@Test
- public void testDeviateNotSupported() throws Exception {
+ void testDeviateNotSupported() {
final var schemaContext = assertEffectiveModelDir("/deviation-resolution-test/deviation-not-supported");
assertNotNull(schemaContext);
final Module importedModule = schemaContext.findModule("imported", Revision.of("2017-01-20")).get();
final ContainerSchemaNode myContA = (ContainerSchemaNode) importedModule.getDataChildByName(
- QName.create(importedModule.getQNameModule(), "my-cont-a"));
+ QName.create(importedModule.getQNameModule(), "my-cont-a"));
assertNotNull(myContA);
assertEquals(1, myContA.getChildNodes().size());
assertNotNull(myContA.getDataChildByName(QName.create(importedModule.getQNameModule(), "my-leaf-a3")));
final ContainerSchemaNode myContB = (ContainerSchemaNode) importedModule.dataChildByName(
- QName.create(importedModule.getQNameModule(), "my-cont-b"));
+ QName.create(importedModule.getQNameModule(), "my-cont-b"));
assertNull(myContB);
final ContainerSchemaNode myContC = (ContainerSchemaNode) importedModule.getDataChildByName(
- QName.create(importedModule.getQNameModule(), "my-cont-c"));
+ QName.create(importedModule.getQNameModule(), "my-cont-c"));
assertNotNull(myContC);
assertEquals(2, myContC.getChildNodes().size());
}
@Test
- public void testDeviateAdd() throws Exception {
- final EffectiveModelContext schemaContext = TestUtils.parseYangSource(
- "/deviation-resolution-test/deviation-add/foo.yang",
- "/deviation-resolution-test/deviation-add/bar.yang");
- assertNotNull(schemaContext);
+ void testDeviateAdd() {
+ final var schemaContext = assertEffectiveModel(
+ "/deviation-resolution-test/deviation-add/foo.yang",
+ "/deviation-resolution-test/deviation-add/bar.yang");
final Module barModule = schemaContext.findModule("bar", Revision.of("2017-01-20")).get();
final LeafListSchemaNode myLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-leaf-list"));
+ QName.create(barModule.getQNameModule(), "my-leaf-list"));
assertNotNull(myLeafList);
assertEquals(Optional.of(Boolean.FALSE), myLeafList.effectiveConfig());
assertNotNull(myLeafList.getType().getUnits());
final ListSchemaNode myList = (ListSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-list"));
+ QName.create(barModule.getQNameModule(), "my-list"));
assertNotNull(myList);
assertEquals(2, myList.getUniqueConstraints().size());
final ChoiceSchemaNode myChoice = (ChoiceSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-choice"));
+ QName.create(barModule.getQNameModule(), "my-choice"));
assertNotNull(myChoice);
assertEquals("c2", myChoice.getDefaultCase().get().getQName().getLocalName());
assertEquals(2, myNotification.getMustConstraints().size());
final AnyxmlSchemaNode myAnyxml = (AnyxmlSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-anyxml"));
+ QName.create(barModule.getQNameModule(), "my-anyxml"));
assertNotNull(myAnyxml);
assertTrue(myAnyxml.isMandatory());
final AnydataSchemaNode myAnyData = (AnydataSchemaNode) barModule.findDataChildByName(
- QName.create(barModule.getQNameModule(), "my-anydata")).orElse(null);
+ QName.create(barModule.getQNameModule(), "my-anydata")).orElse(null);
assertNotNull(myAnyData);
assertTrue(myAnyData.isMandatory());
}
@Test
- public void testDeviateReplace() throws Exception {
- final EffectiveModelContext schemaContext = TestUtils.parseYangSource(
- "/deviation-resolution-test/deviation-replace/foo.yang",
- "/deviation-resolution-test/deviation-replace/bar.yang");
- assertNotNull(schemaContext);
+ void testDeviateReplace() throws Exception {
+ final var schemaContext = assertEffectiveModel(
+ "/deviation-resolution-test/deviation-replace/foo.yang",
+ "/deviation-resolution-test/deviation-replace/bar.yang");
final Module barModule = schemaContext.findModule("bar", Revision.of("2017-01-20")).get();
assertNotNull(barModule);
final LeafSchemaNode myLeaf = (LeafSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-leaf"));
+ QName.create(barModule.getQNameModule(), "my-leaf"));
assertNotNull(myLeaf);
- assertThat(myLeaf.getType(), instanceOf(Uint32TypeDefinition.class));
+ assertInstanceOf(Uint32TypeDefinition.class, myLeaf.getType());
assertEquals(Optional.of("bytes"), myLeaf.getType().getUnits());
assertEquals(Optional.of("10"), myLeaf.getType().getDefaultValue());
final LeafListSchemaNode myLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-leaf-list-test"));
+ QName.create(barModule.getQNameModule(), "my-leaf-list-test"));
assertNotNull(myLeafList);
final ElementCountConstraint constraint = myLeafList.getElementCountConstraint().get();
assertEquals(Optional.of(Boolean.TRUE), myLeafList.effectiveConfig());
final ChoiceSchemaNode myChoice = (ChoiceSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-choice"));
+ QName.create(barModule.getQNameModule(), "my-choice"));
assertNotNull(myChoice);
assertFalse(myChoice.isMandatory());
assertEquals(0, myChoice.getUnknownSchemaNodes().size());
final ContainerSchemaNode myCont = (ContainerSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-cont"));
+ QName.create(barModule.getQNameModule(), "my-cont"));
assertNotNull(myCont);
final LeafSchemaNode myAugLeaf = (LeafSchemaNode) myCont.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-aug-leaf"));
+ QName.create(barModule.getQNameModule(), "my-aug-leaf"));
assertNotNull(myAugLeaf);
- assertThat(myAugLeaf.getType(), instanceOf(Uint32TypeDefinition.class));
+ assertInstanceOf(Uint32TypeDefinition.class, myAugLeaf.getType());
assertEquals(Optional.of("seconds"), myAugLeaf.getType().getUnits());
assertEquals(Optional.of("new-def-val"), myAugLeaf.getType().getDefaultValue());
// FIXME: we need a supported extension to properly test this
assertEquals(0, myAugLeaf.getUnknownSchemaNodes().size());
final LeafSchemaNode myUsedLeaf = (LeafSchemaNode) myCont.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-used-leaf"));
+ QName.create(barModule.getQNameModule(), "my-used-leaf"));
assertNotNull(myUsedLeaf);
- assertThat(myUsedLeaf.getType(), instanceOf(Uint32TypeDefinition.class));
+ assertInstanceOf(Uint32TypeDefinition.class, myUsedLeaf.getType());
assertEquals(Optional.of("weeks"), myUsedLeaf.getType().getUnits());
assertEquals(Optional.of("new-def-val"), myUsedLeaf.getType().getDefaultValue());
// FIXME: we need a supported extension to properly test this
}
@Test
- public void testDeviateDelete() throws Exception {
- final EffectiveModelContext schemaContext = TestUtils.parseYangSource(
- "/deviation-resolution-test/deviation-delete/foo.yang",
- "/deviation-resolution-test/deviation-delete/bar.yang");
- assertNotNull(schemaContext);
+ void testDeviateDelete() throws Exception {
+ final var schemaContext = assertEffectiveModel(
+ "/deviation-resolution-test/deviation-delete/foo.yang",
+ "/deviation-resolution-test/deviation-delete/bar.yang");
final Module barModule = schemaContext.findModule("bar", Revision.of("2017-01-20")).get();
final LeafSchemaNode myLeaf = (LeafSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-leaf"));
+ QName.create(barModule.getQNameModule(), "my-leaf"));
assertNotNull(myLeaf);
assertEquals(Optional.empty(), myLeaf.getType().getDefaultValue());
assertEquals(0, myLeaf.getUnknownSchemaNodes().size());
final LeafListSchemaNode myLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-leaf-list"));
+ QName.create(barModule.getQNameModule(), "my-leaf-list"));
assertNotNull(myLeafList);
assertEquals(0, myLeafList.getDefaults().size());
assertEquals(0, myLeafList.getMustConstraints().size());
final ListSchemaNode myList = (ListSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-list"));
+ QName.create(barModule.getQNameModule(), "my-list"));
assertNotNull(myList);
assertEquals(0, myList.getUniqueConstraints().size());
assertEquals(0, myList.getUnknownSchemaNodes().size());
final ContainerSchemaNode myCont = (ContainerSchemaNode) barModule.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-cont"));
+ QName.create(barModule.getQNameModule(), "my-cont"));
assertNotNull(myCont);
final LeafSchemaNode myAugLeaf = (LeafSchemaNode) myCont.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-aug-leaf"));
+ QName.create(barModule.getQNameModule(), "my-aug-leaf"));
assertNotNull(myAugLeaf);
assertEquals(Optional.empty(), myAugLeaf.getType().getDefaultValue());
assertEquals(Optional.empty(), myAugLeaf.getType().getUnits());
assertEquals(0, myAugLeaf.getUnknownSchemaNodes().size());
final LeafSchemaNode myUsedLeaf = (LeafSchemaNode) myCont.getDataChildByName(
- QName.create(barModule.getQNameModule(), "my-used-leaf"));
+ QName.create(barModule.getQNameModule(), "my-used-leaf"));
assertNotNull(myUsedLeaf);
assertEquals(Optional.empty(), myUsedLeaf.getType().getDefaultValue());
assertEquals(Optional.empty(), myUsedLeaf.getType().getUnits());
}
@Test
- public void shouldFailOnInvalidYang10Model() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidYang10Model() {
+ assertInvalidSubstatementException(startsWith("Maximal count of DEFAULT for DEVIATE is 1, detected 2."),
"/deviation-resolution-test/deviation-add/foo10-invalid.yang",
- "/deviation-resolution-test/deviation-add/bar10-invalid.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidSubstatementException.class));
- assertThat(cause.getMessage(), startsWith("Maximal count of DEFAULT for DEVIATE is 1, detected 2."));
+ "/deviation-resolution-test/deviation-add/bar10-invalid.yang");
}
@Test
- public void shouldFailOnInvalidYang10Model2() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidYang10Model2() {
+ assertInvalidSubstatementException(startsWith("Maximal count of DEFAULT for DEVIATE is 1, detected 2."),
"/deviation-resolution-test/deviation-delete/foo10-invalid.yang",
- "/deviation-resolution-test/deviation-delete/bar10-invalid.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidSubstatementException.class));
- assertThat(cause.getMessage(), startsWith("Maximal count of DEFAULT for DEVIATE is 1, detected 2."));
+ "/deviation-resolution-test/deviation-delete/bar10-invalid.yang");
}
@Test
- public void shouldFailOnInvalidDeviationTarget() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidDeviationTarget() {
+ assertInferenceException(startsWith("(bar?revision=2017-01-20)my-cont is not a valid deviation "
+ + "target for substatement (urn:ietf:params:xml:ns:yang:yin:1)max-elements."),
"/deviation-resolution-test/foo-invalid-deviation-target.yang",
- "/deviation-resolution-test/bar.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InferenceException.class));
- assertThat(cause.getMessage(), startsWith("(bar?revision=2017-01-20)my-cont is not a valid deviation "
- + "target for substatement (urn:ietf:params:xml:ns:yang:yin:1)max-elements."));
+ "/deviation-resolution-test/bar.yang");
}
@Test
- public void shouldFailOnInvalidDeviationPath() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidDeviationPath() {
+ assertInferenceException(startsWith(
+ "Deviation target 'Absolute{qnames=[(bar?revision=2017-01-20)invalid, path]}' not found"),
"/deviation-resolution-test/foo-invalid-deviation-path.yang",
- "/deviation-resolution-test/bar.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InferenceException.class));
- assertThat(cause.getMessage(), startsWith(
- "Deviation target 'Absolute{qnames=[(bar?revision=2017-01-20)invalid, path]}' not found"));
+ "/deviation-resolution-test/bar.yang");
}
@Test
- public void shouldFailOnInvalidDeviateAdd() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidDeviateAdd() {
+ assertInferenceException(startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang"
+ + ":yin:1)config to target node (bar?revision=2017-01-20)my-leaf because it is already defined in"
+ + " target and can appear only once."),
"/deviation-resolution-test/deviation-add/foo-invalid.yang",
- "/deviation-resolution-test/deviation-add/bar-invalid.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InferenceException.class));
- assertThat(cause.getMessage(), startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang"
- + ":yin:1)config to target node (bar?revision=2017-01-20)my-leaf because it is already defined in"
- + " target and can appear only once."));
+ "/deviation-resolution-test/deviation-add/bar-invalid.yang");
}
@Test
- public void shouldFailOnInvalidDeviateAdd2() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidDeviateAdd2() {
+ assertInferenceException(startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang"
+ + ":yin:1)default to target node (bar?revision=2017-01-20)my-leaf because it is already defined in"
+ + " target and can appear only once."),
"/deviation-resolution-test/deviation-add/foo-invalid-2.yang",
- "/deviation-resolution-test/deviation-add/bar-invalid-2.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InferenceException.class));
- assertThat(cause.getMessage(), startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang"
- + ":yin:1)default to target node (bar?revision=2017-01-20)my-leaf because it is already defined in"
- + " target and can appear only once."));
+ "/deviation-resolution-test/deviation-add/bar-invalid-2.yang");
}
@Test
- public void shouldFailOnInvalidDeviateAdd3() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidDeviateAdd3() {
+ assertInferenceException(startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang"
+ + ":yin:1)default to target node (bar?revision=2017-02-01)my-used-leaf because it is already "
+ + "defined in target and can appear only once."),
"/deviation-resolution-test/deviation-add/foo-invalid-4.yang",
- "/deviation-resolution-test/deviation-add/bar-invalid-4.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InferenceException.class));
- assertThat(cause.getMessage(), startsWith("Deviation cannot add substatement (urn:ietf:params:xml:ns:yang"
- + ":yin:1)default to target node (bar?revision=2017-02-01)my-used-leaf because it is already "
- + "defined in target and can appear only once."));
+ "/deviation-resolution-test/deviation-add/bar-invalid-4.yang");
}
@Test
- public void shouldFailOnInvalidDeviateReplace() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidDeviateReplace() {
+ assertInferenceException(startsWith("Deviation cannot replace substatement "
+ + "(urn:ietf:params:xml:ns:yang:yin:1)units in target node (bar?revision=2017-01-20)my-leaf "
+ + "because it does not exist in target node."),
"/deviation-resolution-test/deviation-replace/foo-invalid.yang",
- "/deviation-resolution-test/deviation-replace/bar-invalid.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InferenceException.class));
- assertThat(cause.getMessage(), startsWith("Deviation cannot replace substatement "
- + "(urn:ietf:params:xml:ns:yang:yin:1)units in target node (bar?revision=2017-01-20)my-leaf "
- + "because it does not exist in target node."));
+ "/deviation-resolution-test/deviation-replace/bar-invalid.yang");
}
@Test
@SuppressWarnings("checkstyle:regexpSinglelineJava")
- public void shouldLogInvalidDeviateReplaceAttempt() throws Exception {
+ void shouldLogInvalidDeviateReplaceAttempt() throws Exception {
final PrintStream stdout = System.out;
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final String testLog;
System.setOut(stdout);
assertThat(testLog, containsString(
"Deviation cannot replace substatement (urn:ietf:params:xml:ns:yang:yin:1)default in target leaf-list "
- + "(bar?revision=2017-01-20)my-leaf-list because a leaf-list can have multiple "
- + "default statements."));
+ + "(bar?revision=2017-01-20)my-leaf-list because a leaf-list can have multiple "
+ + "default statements."));
}
@Test
@SuppressWarnings("checkstyle:regexpSinglelineJava")
- public void shouldLogInvalidDeviateDeleteAttempt() throws Exception {
+ void shouldLogInvalidDeviateDeleteAttempt() throws Exception {
final PrintStream stdout = System.out;
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final String testLog;
System.setOut(stdout);
assertThat(testLog, containsString(
"Deviation cannot delete substatement (urn:ietf:params:xml:ns:yang:yin:1)units with argument 'seconds' in "
- + "target node (bar?revision=2017-01-20)my-leaf because it does not exist in the target node."));
+ + "target node (bar?revision=2017-01-20)my-leaf because it does not exist in the target node."));
}
@Test
- public void shouldFailOnInvalidDeviateAddSubstatement() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidDeviateAddSubstatement() {
+ assertInvalidSubstatementException(startsWith("TYPE is not valid for DEVIATE."),
"/deviation-resolution-test/deviation-add/foo-invalid-3.yang",
- "/deviation-resolution-test/deviation-add/bar-invalid-3.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidSubstatementException.class));
- assertThat(cause.getMessage(), startsWith("TYPE is not valid for DEVIATE."));
+ "/deviation-resolution-test/deviation-add/bar-invalid-3.yang");
}
@Test
- public void shouldFailOnInvalidDeviateReplaceSubstatement() {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidDeviateReplaceSubstatement() {
+ assertInvalidSubstatementException(startsWith("MUST is not valid for DEVIATE."),
"/deviation-resolution-test/deviation-replace/foo-invalid-3.yang",
- "/deviation-resolution-test/deviation-replace/bar-invalid-3.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidSubstatementException.class));
- assertThat(cause.getMessage(), startsWith("MUST is not valid for DEVIATE."));
+ "/deviation-resolution-test/deviation-replace/bar-invalid-3.yang");
}
@Test
- public void shouldFailOnInvalidDeviateDeleteSubstatement() throws Exception {
- final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
+ void shouldFailOnInvalidDeviateDeleteSubstatement() {
+ assertInvalidSubstatementException(startsWith("CONFIG is not valid for DEVIATE."),
"/deviation-resolution-test/deviation-delete/foo-invalid-2.yang",
- "/deviation-resolution-test/deviation-delete/bar-invalid-2.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(InvalidSubstatementException.class));
- assertThat(cause.getMessage(), startsWith("CONFIG is not valid for DEVIATE."));
+ "/deviation-resolution-test/deviation-delete/bar-invalid-2.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
import com.google.common.collect.Iterables;
-import java.util.Collection;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
import org.opendaylight.yangtools.yang.model.api.DeviateKind;
import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-public class DeviationStmtTest {
+class DeviationStmtTest {
private static final StatementStreamSource FOO_MODULE = sourceForResource("/deviation-stmt-test/foo.yang");
private static final StatementStreamSource FOO_IMP_MODULE = sourceForResource("/deviation-stmt-test/foo-imp.yang");
private static final StatementStreamSource BAR_IMP_MODULE = sourceForResource("/deviation-stmt-test/bar-imp.yang");
@Test
- public void testDeviationAndDeviate() throws ReactorException {
- final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(FOO_MODULE, FOO_IMP_MODULE, BAR_MODULE, BAR_IMP_MODULE)
- .buildEffective();
+ void testDeviationAndDeviate() throws ReactorException {
+ final var schemaContext = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(FOO_MODULE, FOO_IMP_MODULE, BAR_MODULE, BAR_IMP_MODULE)
+ .buildEffective();
assertNotNull(schemaContext);
Module testModule = schemaContext.findModule("foo", Revision.of("2016-06-23")).get();
- Collection<? extends Deviation> deviations = testModule.getDeviations();
+ var deviations = testModule.getDeviations();
assertEquals(4, deviations.size());
for (Deviation deviation : deviations) {
- final Collection<? extends DeviateDefinition> deviates = deviation.getDeviates();
+ final var deviates = deviation.getDeviates();
final String targetLocalName = Iterables.getLast(deviation.getTargetPath().getNodeIdentifiers())
- .getLocalName();
+ .getLocalName();
if ("test-leaf".equals(targetLocalName)) {
assertEquals(Optional.of("test-leaf is not supported"), deviation.getDescription());
assertEquals(1, deviates.size());
assertEquals(12, deviate.getDeviatedMaxElements().intValue());
} else if (DeviateKind.REPLACE.equals(deviate.getDeviateType())) {
assertEquals(5, deviate.getDeviatedMinElements().intValue());
- assertTrue(deviate.getDeviatedType() instanceof Uint32TypeDefinition);
+ assertInstanceOf(Uint32TypeDefinition.class, deviate.getDeviatedType());
} else {
assertEquals(2, deviate.getDeviatedMusts().size());
assertEquals("minutes", deviate.getDeviatedUnits());
Deviation deviation7 = null;
for (Deviation deviation : deviations) {
- final Collection<? extends DeviateDefinition> deviates = deviation.getDeviates();
+ final var deviates = deviation.getDeviates();
final String targetLocalName = Iterables.getLast(deviation.getTargetPath().getNodeIdentifiers())
- .getLocalName();
+ .getLocalName();
if ("bar-container-1".equals(targetLocalName)) {
deviation1 = deviation;
assertEquals(1,
deviation1.asEffectiveStatement().getDeclared().declaredSubstatements(UnrecognizedStatement.class).size());
- assertTrue(deviation1.equals(deviation1));
- assertFalse(deviation1.equals(null));
- assertFalse(deviation1.equals("str"));
+ assertEquals(deviation1, deviation1);
+ assertNotEquals(null, deviation1);
+ assertNotEquals("str", deviation1);
DeviateDefinition deviate = deviation1.getDeviates().iterator().next();
- assertTrue(deviate.equals(deviate));
- assertFalse(deviate.equals(null));
- assertFalse(deviate.equals("str"));
-
- assertFalse(deviation1.equals(deviation2));
- assertFalse(deviation2.equals(deviation3));
- assertFalse(deviation4.equals(deviation5));
- assertFalse(deviation6.equals(deviation7));
+ assertEquals(deviate, deviate);
+ assertNotEquals(null, deviate);
+ assertNotEquals("str", deviate);
+
+ assertNotEquals(deviation1, deviation2);
+ assertNotEquals(deviation2, deviation3);
+ assertNotEquals(deviation4, deviation5);
+ assertNotEquals(deviation6, deviation7);
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-import java.io.FileNotFoundException;
-import java.net.URISyntaxException;
-import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
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.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-public class EffectiveBuildTest {
+class EffectiveBuildTest {
private static final StatementStreamSource SIMPLE_MODULE = sourceForResource(
- "/stmt-test/effective-build/simple-module.yang");
+ "/stmt-test/effective-build/simple-module.yang");
private static final QNameModule SIMPLE_MODULE_QNAME = QNameModule.create(XMLNamespace.of("simple.yang"));
private static final StatementStreamSource YANG_EXT = sourceForResource(
- "/stmt-test/extensions/yang-ext.yang");
+ "/stmt-test/extensions/yang-ext.yang");
@Test
- public void effectiveBuildTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSources(SIMPLE_MODULE)
- .buildEffective();
+ void effectiveBuildTest() throws ReactorException {
+ var result = RFC7950Reactors.defaultReactor().newBuild().addSources(SIMPLE_MODULE)
+ .buildEffective();
assertNotNull(result);
}
@Test
- public void extensionsTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective();
+ void extensionsTest() throws ReactorException {
+ var result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective();
assertNotNull(result);
- Collection<? extends GroupingDefinition> groupings = result.getGroupings();
+ var groupings = result.getGroupings();
assertEquals(1, groupings.size());
- GroupingDefinition grp = groupings.iterator().next();
+ var grp = groupings.iterator().next();
- Collection<? extends DataSchemaNode> childNodes = grp.getChildNodes();
+ var childNodes = grp.getChildNodes();
assertEquals(1, childNodes.size());
- DataSchemaNode child = childNodes.iterator().next();
- assertTrue(child instanceof LeafSchemaNode);
- LeafSchemaNode leaf = (LeafSchemaNode) child;
+ LeafSchemaNode leaf = assertInstanceOf(LeafSchemaNode.class, childNodes.iterator().next());
assertNotNull(leaf.getType());
}
@Test
- public void mockTest() throws ReactorException, FileNotFoundException, URISyntaxException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective();
+ void mockTest() throws Exception {
+ var result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective();
assertNotNull(result);
}
}
*/
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.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-public class EffectiveIdentityTest {
+class EffectiveIdentityTest {
private static final StatementStreamSource IDENTITY_TEST = sourceForResource(
- "/stmt-test/identity/identity-test.yang");
+ "/stmt-test/identity/identity-test.yang");
private static final StatementStreamSource CYCLIC_IDENTITY_TEST = sourceForResource(
- "/stmt-test/identity/cyclic-identity-test.yang");
+ "/stmt-test/identity/cyclic-identity-test.yang");
@Test
- public void cyclicDefineTest() {
+ void cyclicDefineTest() {
final var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(CYCLIC_IDENTITY_TEST);
final var cause = assertThrows(SomeModifiersUnresolvedException.class, reactor::buildEffective).getCause();
- assertThat(cause, instanceOf(InferenceException.class));
+ assertInstanceOf(InferenceException.class, cause);
assertThat(cause.getMessage(), startsWith("Yang model processing phase STATEMENT_DEFINITION failed [at "));
// This is a bit complicated, as the order of exceptions may differ
causes.addAll(Arrays.asList(cause.getSuppressed()));
causes.sort(Comparator.comparing(Throwable::getMessage));
assertEquals(4, causes.size());
- causes.forEach(throwable -> assertThat(throwable, instanceOf(InferenceException.class)));
+ causes.forEach(throwable -> assertInstanceOf(InferenceException.class, throwable));
assertThat(causes.get(0).getMessage(),
startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-1 and base identity "
}
@Test
- public void identityTest() throws ReactorException {
+ void identityTest() throws ReactorException {
SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSources(IDENTITY_TEST).buildEffective();
assertNotNull(result);
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.Collection;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DeviateKind;
-import org.opendaylight.yangtools.yang.model.api.Deviation;
-import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
-import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
-import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.Submodule;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-public class EffectiveModuleTest {
+class EffectiveModuleTest {
private static final QNameModule ROOT_MODULE_QNAME = QNameModule.create(XMLNamespace.of("root-ns"));
private static final QName CONT = QName.create(ROOT_MODULE_QNAME, "cont");
private static final QName FEATURE1 = QName.create(ROOT_MODULE_QNAME, "feature1");
private static final Revision REVISION = Revision.of("2000-01-01");
@Test
- public void effectiveBuildTest() throws Exception {
- final Module rootModule = TestUtils.parseYangSource(
+ void effectiveBuildTest() throws Exception {
+ final var rootModule = TestUtils.parseYangSource(
"/semantic-statement-parser/effective-module/root.yang",
"/semantic-statement-parser/effective-module/imported.yang",
"/semantic-statement-parser/effective-module/submod.yang")
assertEquals(Optional.of("cisco"), rootModule.getOrganization());
assertEquals(Optional.of("cisco email"), rootModule.getContact());
- final ContainerSchemaNode contSchemaNode = (ContainerSchemaNode) rootModule.getDataChildByName(CONT);
+ final var contSchemaNode = (ContainerSchemaNode) rootModule.getDataChildByName(CONT);
assertNotNull(contSchemaNode);
- final Collection<? extends AugmentationSchemaNode> augmentations = rootModule.getAugmentations();
+ final var augmentations = rootModule.getAugmentations();
assertEquals(1, augmentations.size());
assertEquals(Absolute.of(CONT), augmentations.iterator().next().getTargetPath());
- final Collection<? extends ModuleImport> imports = rootModule.getImports();
+ final var imports = rootModule.getImports();
assertEquals(1, imports.size());
- final ModuleImport importStmt = imports.iterator().next();
+ final var importStmt = imports.iterator().next();
assertNotNull(importStmt);
assertEquals(Unqualified.of("imported"), importStmt.getModuleName());
assertEquals(Optional.of(REVISION), importStmt.getRevision());
assertEquals("imp-pref", importStmt.getPrefix());
- final Collection<? extends Submodule> submodules = rootModule.getSubmodules();
+ final var submodules = rootModule.getSubmodules();
assertEquals(1, submodules.size());
assertEquals("submod", submodules.iterator().next().getName());
- final Collection<? extends NotificationDefinition> notifications = rootModule.getNotifications();
+ final var notifications = rootModule.getNotifications();
assertEquals(1, notifications.size());
assertEquals("notif1", notifications.iterator().next().getQName().getLocalName());
- final Collection<? extends RpcDefinition> rpcs = rootModule.getRpcs();
+ final var rpcs = rootModule.getRpcs();
assertEquals(1, rpcs.size());
assertEquals("rpc1", rpcs.iterator().next().getQName().getLocalName());
- final Collection<? extends Deviation> deviations = rootModule.getDeviations();
+ final var deviations = rootModule.getDeviations();
assertEquals(1, deviations.size());
- final Deviation deviationStmt = deviations.iterator().next();
+ final var deviationStmt = deviations.iterator().next();
assertNotNull(deviationStmt);
- final QNameModule importedModuleQName = QNameModule.create(XMLNamespace.of("imported"), REVISION);
- final QName importedContQName = QName.create(importedModuleQName, "cont");
+ final var importedContQName = QName.create(QNameModule.create(XMLNamespace.of("imported"), REVISION), "cont");
assertEquals(Absolute.of(importedContQName), deviationStmt.getTargetPath());
assertEquals(DeviateKind.ADD, deviationStmt.getDeviates().iterator().next().getDeviateType());
assertEquals(Optional.of("deviate reference"), deviationStmt.getReference());
- final Collection<? extends IdentitySchemaNode> identities = rootModule.getIdentities();
+ final var identities = rootModule.getIdentities();
assertEquals(1, identities.size());
assertEquals("identity1", identities.iterator().next().getQName().getLocalName());
- final Collection<? extends FeatureDefinition> features = rootModule.getFeatures();
+ final var features = rootModule.getFeatures();
assertEquals(1, features.size());
- final FeatureDefinition featureStmt = features.iterator().next();
+ final var featureStmt = features.iterator().next();
assertNotNull(featureStmt);
assertEquals(FEATURE1, featureStmt.getQName());
assertEquals(Optional.of("feature1 description"), featureStmt.getDescription());
assertEquals(Optional.of("feature1 reference"), featureStmt.getReference());
assertEquals(Status.CURRENT, featureStmt.getStatus());
- final Collection<? extends ExtensionDefinition> extensionSchemaNodes = rootModule.getExtensionSchemaNodes();
+ final var extensionSchemaNodes = rootModule.getExtensionSchemaNodes();
assertEquals(1, extensionSchemaNodes.size());
assertEquals("ext1", extensionSchemaNodes.iterator().next().getQName().getLocalName());
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
import java.util.Collection;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
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.ModuleLike;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.Submodule;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class EffectiveModulesAndSubmodulesTest {
+class EffectiveModulesAndSubmodulesTest {
private static final Logger LOG = LoggerFactory.getLogger(EffectiveModulesAndSubmodulesTest.class);
private static final StatementStreamSource ROOT_MODULE = sourceForResource(
- "/stmt-test/submodules/root-module.yang");
+ "/stmt-test/submodules/root-module.yang");
private static final StatementStreamSource IMPORTED_MODULE = sourceForResource(
- "/stmt-test/submodules/imported-module.yang");
+ "/stmt-test/submodules/imported-module.yang");
private static final StatementStreamSource SUBMODULE_1 = sourceForResource(
- "/stmt-test/submodules/submodule-1.yang");
+ "/stmt-test/submodules/submodule-1.yang");
private static final StatementStreamSource SUBMODULE_2 = sourceForResource(
- "/stmt-test/submodules/submodule-2.yang");
+ "/stmt-test/submodules/submodule-2.yang");
private static final StatementStreamSource SUBMODULE_TO_SUBMODULE_1 = sourceForResource(
- "/stmt-test/submodules/submodule-to-submodule-1.yang");
+ "/stmt-test/submodules/submodule-to-submodule-1.yang");
private static final QNameModule ROOT = QNameModule.create(XMLNamespace.of("root-module"));
@Test
- public void modulesAndSubmodulesSimpleReferencesTest() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(ROOT_MODULE, IMPORTED_MODULE, SUBMODULE_1, SUBMODULE_2, SUBMODULE_TO_SUBMODULE_1)
- .buildEffective();
+ void modulesAndSubmodulesSimpleReferencesTest() throws ReactorException {
+ final var result = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(ROOT_MODULE, IMPORTED_MODULE, SUBMODULE_1, SUBMODULE_2, SUBMODULE_TO_SUBMODULE_1)
+ .buildEffective();
assertNotNull(result);
- final Collection<? extends Module> modules = result.getModules();
+ final var modules = result.getModules();
assertNotNull(modules);
assertEquals(2, modules.size());
assertNotNull(root);
assertNotNull(imported);
- final Collection<? extends DataSchemaNode> rootChildNodes = root.getChildNodes();
- final Collection<? extends DataSchemaNode> importedChildNodes = imported.getChildNodes();
+ final var rootChildNodes = root.getChildNodes();
+ final var importedChildNodes = imported.getChildNodes();
assertNotNull(rootChildNodes);
assertNotNull(importedChildNodes);
assertEquals(3, rootChildNodes.size());
assertEquals(1, importedChildNodes.size());
- final Collection<? extends Submodule> rootSubmodules = root.getSubmodules();
- final Collection<? extends Submodule> importedSubmodules = imported.getSubmodules();
+ final var rootSubmodules = root.getSubmodules();
+ final var importedSubmodules = imported.getSubmodules();
assertNotNull(rootSubmodules);
assertNotNull(importedSubmodules);
Submodule sub1 = null;
Submodule sub2 = null;
- for (final Submodule rootSubmodule : rootSubmodules) {
+ for (var rootSubmodule : rootSubmodules) {
switch (rootSubmodule.getName()) {
case "submodule-1":
sub1 = rootSubmodule;
assertEquals(ROOT, sub1.getQNameModule());
assertEquals(ROOT, sub2.getQNameModule());
- final Collection<? extends DataSchemaNode> sub1ChildNodes = sub1.getChildNodes();
- final Collection<? extends DataSchemaNode> sub2ChildNodes = sub2.getChildNodes();
+ final var sub1ChildNodes = sub1.getChildNodes();
+ final var sub2ChildNodes = sub2.getChildNodes();
assertNotNull(sub1ChildNodes);
assertNotNull(sub2ChildNodes);
assertEquals(1, sub1ChildNodes.size());
assertEquals(1, sub2ChildNodes.size());
- final Collection<? extends Submodule> sub1Submodules = sub1.getSubmodules();
- final Collection<? extends Submodule> sub2Submodules = sub2.getSubmodules();
+ final var sub1Submodules = sub1.getSubmodules();
+ final var sub2Submodules = sub2.getSubmodules();
assertNotNull(sub1Submodules);
assertNotNull(sub2Submodules);
assertEquals(0, sub2Submodules.size());
Submodule sub1Submodule = null;
- for (final Submodule submodule : sub1Submodules) {
+ for (var submodule : sub1Submodules) {
switch (submodule.getName()) {
case "submodule-to-submodule-1":
sub1Submodule = submodule;
assertEquals(ROOT, sub1Submodule.getQNameModule());
- final Collection<? extends DataSchemaNode> sub1SubmoduleChildNodes = sub1Submodule.getChildNodes();
+ final var sub1SubmoduleChildNodes = sub1Submodule.getChildNodes();
assertNotNull(sub1SubmoduleChildNodes);
assertEquals(1, sub1SubmoduleChildNodes.size());
- final Collection<? extends Submodule> sub1SubmoduleSubmodules = sub1Submodule.getSubmodules();
+ final var sub1SubmoduleSubmodules = sub1Submodule.getSubmodules();
assertNotNull(sub1SubmoduleSubmodules);
assertEquals(0, sub1SubmoduleSubmodules.size());
getDataChildByNameSubTest(result, root);
}
- private static void getDataChildByNameSubTest(final SchemaContext result, final Module root) {
+ private static void getDataChildByNameSubTest(final EffectiveModelContext result, final Module root) {
final DataSchemaNode containerInRoot = result.getDataChildByName(QName
- .create(root.getQNameModule(), "container-in-root-module"));
+ .create(root.getQNameModule(), "container-in-root-module"));
assertNotNull(containerInRoot);
assertEquals(Optional.of("desc"), containerInRoot.getDescription());
}
- private static void findModulesSubTest(final SchemaContext result, final Module root, final Module imported) {
- final Module foundRoot = result.findModule("root-module").get();
- final Collection<? extends Module> foundRoots = result.findModules(XMLNamespace.of("root-module"));
- final Module foundRoot3 = result.findModule(XMLNamespace.of("root-module")).get();
+ private static void findModulesSubTest(final EffectiveModelContext result, final Module root,
+ final Module imported) {
+ final var foundRoot = result.findModule("root-module").get();
+ final var foundRoots = result.findModules(XMLNamespace.of("root-module"));
+ final var foundRoot3 = result.findModule(XMLNamespace.of("root-module")).get();
assertNotNull(foundRoot);
assertNotNull(foundRoots);
assertEquals(1, foundRoots.size());
- final Module foundRoot2 = foundRoots.iterator().next();
+ final var foundRoot2 = foundRoots.iterator().next();
assertNotNull(foundRoot2);
assertNotNull(foundRoot3);
assertEquals(root, foundRoot2);
assertEquals(root, foundRoot3);
- final Module foundImported = result.findModule("imported-module").get();
- final Collection<? extends Module> foundImporteds = result.findModules(XMLNamespace.of("imported-module"));
- final Module foundImported3 = result.findModule(XMLNamespace.of("imported-module")).get();
+ final var foundImported = result.findModule("imported-module").get();
+ final var foundImporteds = result.findModules(XMLNamespace.of("imported-module"));
+ final var foundImported3 = result.findModule(XMLNamespace.of("imported-module")).get();
assertNotNull(foundImported);
assertNotNull(foundImporteds);
assertEquals(1, foundImporteds.size());
- final Module foundImported2 = foundImporteds.iterator().next();
+ final var foundImported2 = foundImporteds.iterator().next();
assertNotNull(foundImported2);
assertNotNull(foundImported3);
assertEquals(imported, foundImported2);
assertEquals(imported, foundImported3);
- assertFalse(root.equals(imported));
+ assertNotEquals(root, imported);
}
private static void printReferences(final ModuleLike module, final boolean isSubmodule, final String indent) {
LOG.debug("{}{} {}", indent, isSubmodule ? "Submodule" : "Module", module.getName());
- for (final Submodule submodule : module.getSubmodules()) {
+ for (var submodule : module.getSubmodules()) {
printReferences(submodule, true, indent + " ");
printChilds(submodule.getChildNodes(), indent + " ");
}
}
private static void printChilds(final Collection<? extends DataSchemaNode> childNodes, final String indent) {
- for (final DataSchemaNode child : childNodes) {
+ for (var child : childNodes) {
LOG.debug("{}{} {}", indent, "Child", child.getQName().getLocalName());
- if (child instanceof DataNodeContainer) {
- printChilds(((DataNodeContainer) child).getChildNodes(), indent + " ");
+ if (child instanceof DataNodeContainer container) {
+ printChilds(container.getChildNodes(), indent + " ");
}
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.text.ParseException;
-import java.util.Collection;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveSchemaContext;
-public class EffectiveSchemaContextTest {
+class EffectiveSchemaContextTest extends AbstractYangTest {
@Test
- public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException,
- YangSyntaxErrorException {
- final EffectiveSchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/foo.yang"))
- .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/bar.yang"))
- .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/baz.yang"))
- .buildEffective();
- assertNotNull(schemaContext);
+ void testEffectiveSchemaContext() {
+ final var schemaContext = assertEffectiveModel(
+ "/effective-schema-context-test/foo.yang",
+ "/effective-schema-context-test/bar.yang",
+ "/effective-schema-context-test/baz.yang");
- final Collection<? extends DataSchemaNode> dataDefinitions = schemaContext.getDataDefinitions();
- assertEquals(3, dataDefinitions.size());
+ assertEquals(3, schemaContext.getDataDefinitions().size());
+ assertEquals(3, schemaContext.getChildNodes().size());
+ assertEquals(3, schemaContext.getNotifications().size());
+ assertEquals(3, schemaContext.getOperations().size());
+ assertEquals(3, schemaContext.getExtensions().size());
- final Collection<? extends DataSchemaNode> childNodes = schemaContext.getChildNodes();
- assertEquals(3, childNodes.size());
-
- final Collection<? extends NotificationDefinition> notifications = schemaContext.getNotifications();
- assertEquals(3, notifications.size());
-
- final Collection<? extends RpcDefinition> rpcs = schemaContext.getOperations();
- assertEquals(3, rpcs.size());
-
- final Collection<? extends ExtensionDefinition> extensions = schemaContext.getExtensions();
- assertEquals(3, extensions.size());
-
- for (ModuleEffectiveStatement module : schemaContext.getModuleStatements().values()) {
+ for (var module : schemaContext.getModuleStatements().values()) {
assertEquals(1, module.getDeclared().declaredSubstatements(UnrecognizedStatement.class).size());
}
assertTrue(schemaContext.findModule("foo", Revision.of("2016-09-21")).isPresent());
assertEquals(3, schemaContext.getModules().size());
- assertEquals(3, schemaContext.getRootDeclaredStatements().size());
+ assertEquals(3, ((EffectiveSchemaContext) schemaContext).getRootDeclaredStatements().size());
assertEquals(3, schemaContext.getModuleStatements().size());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-
-import com.google.common.collect.Range;
-import java.util.Iterator;
-import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
import java.util.Optional;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
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.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-public class EffectiveStatementTypeTest {
+class EffectiveStatementTypeTest extends AbstractYangTest {
private static SchemaContext effectiveSchemaContext;
private static Module types;
private LeafSchemaNode currentLeaf;
- @BeforeClass
- public static void setup() throws ReactorException {
- effectiveSchemaContext = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/type-tests/types.yang"))
- .buildEffective();
+ @BeforeAll
+ static void setup() {
+ effectiveSchemaContext = assertEffectiveModel("/type-tests/types.yang");
types = effectiveSchemaContext.findModules("types").iterator().next();
assertNotNull(types);
}
- @AfterClass
- public static void teardown() {
+ @AfterAll
+ static void teardown() {
effectiveSchemaContext = null;
types = null;
}
@Test
- public void testBinary() {
+ void testBinary() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-binary"));
assertNotNull(currentLeaf.getType());
final BinaryTypeDefinition binaryEff = (BinaryTypeDefinition)
- ((TypeEffectiveStatement<?>) ((LeafEffectiveStatement) currentLeaf)
+ ((TypeEffectiveStatement<?>) ((LeafEffectiveStatement) currentLeaf)
.effectiveSubstatements().iterator().next()).getTypeDefinition();
assertNull(binaryEff.getBaseType());
assertEquals(Optional.empty(), binaryEff.getUnits());
assertEquals(Optional.empty(), binaryEff.getDefaultValue());
assertEquals("binary", binaryEff.getQName().getLocalName());
- assertFalse(binaryEff.getLengthConstraint().isPresent());
+ assertEquals(Optional.empty(), binaryEff.getLengthConstraint());
assertEquals(Status.CURRENT, binaryEff.getStatus());
assertNotNull(binaryEff.getUnknownSchemaNodes());
- assertFalse(binaryEff.getDescription().isPresent());
- assertFalse(binaryEff.getReference().isPresent());
+ assertEquals(Optional.empty(), binaryEff.getDescription());
+ assertEquals(Optional.empty(), binaryEff.getReference());
}
@Test
- public void testBits() {
+ void testBits() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-bits"));
assertNotNull(currentLeaf.getType());
- final Iterator<? extends Bit> bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits().iterator();
+ final var bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits().iterator();
final Bit bitEff = bitsEffIter.next();
final Bit bitEffSecond = bitsEffIter.next();
final BitsTypeDefinition bitsEff = (BitsTypeDefinition) ((TypeDefinitionAware)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertNull(bitsEff.getBaseType());
assertNotNull(bitsEff.getQName());
assertEquals("bits", bitsEff.getQName().getLocalName());
assertNotNull(bitsEff.getUnknownSchemaNodes());
- assertFalse(bitsEff.getDescription().isPresent());
- assertFalse(bitsEff.getReference().isPresent());
+ assertEquals(Optional.empty(), bitsEff.getDescription());
+ assertEquals(Optional.empty(), bitsEff.getReference());
assertEquals(Status.CURRENT, bitsEff.getStatus());
assertEquals(Optional.empty(), bitsEff.getUnits());
assertNotNull(bitsEff.toString());
assertNotNull(bitsEff.hashCode());
- assertFalse(bitsEff.equals(null));
- assertFalse(bitsEff.equals("test"));
- assertTrue(bitsEff.equals(bitsEff));
+ assertNotEquals(null, bitsEff);
+ assertNotEquals("test", bitsEff);
+ assertEquals(bitsEff, bitsEff);
assertEquals(3, bitsEff.getBits().size());
assertEquals(Optional.empty(), bitsEff.getDefaultValue());
assertEquals(Optional.of("test bit ref"), bitEff.getReference());
assertEquals(Status.CURRENT, bitEff.getStatus());
assertNotNull(bitEff.hashCode());
- assertFalse(bitEff.equals(null));
- assertFalse(bitEff.equals("test"));
- assertFalse(bitEff.equals(bitEffSecond));
+ assertNotEquals(null, bitEff);
+ assertNotEquals("test", bitEff);
+ assertNotEquals(bitEff, bitEffSecond);
assertNotNull(bitEff.toString());
assertEquals("one", bitEff.getName());
assertEquals(Uint32.ZERO, bitEff.getPosition());
}
@Test
- public void testBoolean() {
+ void testBoolean() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-boolean"));
assertNotNull(currentLeaf.getType());
final BooleanTypeDefinition booleanEff = (BooleanTypeDefinition) ((TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertNull(booleanEff.getBaseType());
assertEquals(Optional.empty(), booleanEff.getUnits());
assertEquals(Optional.empty(), booleanEff.getDefaultValue());
assertEquals("boolean", booleanEff.getQName().getLocalName());
assertNotNull(booleanEff.getUnknownSchemaNodes());
- assertFalse(booleanEff.getDescription().isPresent());
- assertFalse(booleanEff.getReference().isPresent());
+ assertEquals(Optional.empty(), booleanEff.getDescription());
+ assertEquals(Optional.empty(), booleanEff.getReference());
assertEquals(Status.CURRENT, booleanEff.getStatus());
assertNotNull(booleanEff.toString());
}
@Test
- public void testDecimal64() {
+ void testDecimal64() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-decimal64"));
assertNotNull(currentLeaf.getType());
final DecimalTypeDefinition decimal64Eff = (DecimalTypeDefinition) ((TypeDefinitionAware)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertNull(decimal64Eff.getBaseType());
assertEquals(Optional.empty(), decimal64Eff.getUnits());
assertNotNull(decimal64Eff.getUnknownSchemaNodes());
// FIXME: The yang model api is wrong: description/reference/status are not allowed under 'type', how come we
- // parse it?
+ // parse it?
// allowed under 'type', how come we parse it?
- assertFalse(decimal64Eff.getDescription().isPresent());
- assertFalse(decimal64Eff.getReference().isPresent());
+ assertEquals(Optional.empty(), decimal64Eff.getDescription());
+ assertEquals(Optional.empty(), decimal64Eff.getReference());
assertEquals(Status.CURRENT, decimal64Eff.getStatus());
assertEquals(3, decimal64Eff.getRangeConstraint().get().getAllowedRanges().asRanges().size());
assertNotNull(decimal64Eff.toString());
assertNotNull(decimal64Eff.hashCode());
assertEquals(2, decimal64Eff.getFractionDigits());
- assertFalse(decimal64Eff.equals(null));
- assertFalse(decimal64Eff.equals("test"));
- assertTrue(decimal64Eff.equals(decimal64Eff));
+ assertNotEquals(null, decimal64Eff);
+ assertNotEquals("test", decimal64Eff);
+ assertEquals(decimal64Eff, decimal64Eff);
}
@Test
- public void testEmpty() {
+ void testEmpty() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-empty"));
assertNotNull(currentLeaf.getType());
final EmptyTypeDefinition emptyEff = (EmptyTypeDefinition) ((TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertEquals(Optional.empty(), emptyEff.getUnits());
assertEquals(Optional.empty(), emptyEff.getDefaultValue());
}
@Test
- public void testEnum() {
+ void testEnum() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-enum"));
assertNotNull(currentLeaf.getType());
- final List<EnumTypeDefinition.EnumPair> enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues();
- final EnumPair enumEff = enumEffIter.iterator().next();
+ final var enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues();
+ final var enumEff = enumEffIter.iterator().next();
- final EnumTypeDefinition enumSpecEff = (EnumTypeDefinition) ((TypeDefinitionAware)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ final var enumSpecEff = (EnumTypeDefinition) ((TypeDefinitionAware)
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertEquals("enumeration", enumSpecEff.getQName().getLocalName());
assertEquals(Optional.empty(), enumSpecEff.getDefaultValue());
assertNull(enumSpecEff.getBaseType());
assertNotNull(enumSpecEff.getUnknownSchemaNodes());
assertEquals(Status.CURRENT, enumSpecEff.getStatus());
- assertFalse(enumSpecEff.getDescription().isPresent());
- assertFalse(enumSpecEff.getReference().isPresent());
+ assertEquals(Optional.empty(), enumSpecEff.getDescription());
+ assertEquals(Optional.empty(), enumSpecEff.getReference());
assertEquals(Optional.empty(), enumSpecEff.getUnits());
assertNotNull(enumSpecEff.toString());
assertNotNull(enumSpecEff.hashCode());
- assertFalse(enumSpecEff.equals(null));
- assertFalse(enumSpecEff.equals("test"));
- assertTrue(enumSpecEff.equals(enumSpecEff));
+ assertNotEquals(null, enumSpecEff);
+ assertNotEquals("test", enumSpecEff);
+ assertEquals(enumSpecEff, enumSpecEff);
assertEquals("zero", enumEff.getName());
assertNotNull(enumEff.getUnknownSchemaNodes());
}
@Test
- public void testIdentityRef() {
+ void testIdentityRef() {
currentLeaf = (LeafSchemaNode) types
- .getDataChildByName(QName.create(types.getQNameModule(), "leaf-identityref"));
+ .getDataChildByName(QName.create(types.getQNameModule(), "leaf-identityref"));
assertNotNull(currentLeaf.getType());
final IdentityrefTypeDefinition identityRefEff = (IdentityrefTypeDefinition) ((TypeDefinitionAware)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertEquals(Optional.empty(), identityRefEff.getDefaultValue());
assertEquals("identityref", identityRefEff.getQName().getLocalName());
assertNotNull(identityRefEff.getUnknownSchemaNodes());
assertEquals(Status.CURRENT, identityRefEff.getStatus());
assertEquals("test-identity", identityRefEff.getIdentities().iterator().next().getQName().getLocalName());
- assertFalse(identityRefEff.getDescription().isPresent());
- assertFalse(identityRefEff.getReference().isPresent());
+ assertEquals(Optional.empty(), identityRefEff.getDescription());
+ assertEquals(Optional.empty(), identityRefEff.getReference());
assertNotNull(identityRefEff.toString());
// FIXME: the model is wrong, but we accept units in 'type' statement
}
@Test
- public void testInstanceIdentifier() {
+ void testInstanceIdentifier() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
- "leaf-instance-identifier"));
+ "leaf-instance-identifier"));
assertNotNull(currentLeaf.getType());
final InstanceIdentifierTypeDefinition instanceIdentEff = (InstanceIdentifierTypeDefinition)
- ((TypeEffectiveStatement<?>) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements()
- .iterator().next()).getTypeDefinition();
+ ((TypeEffectiveStatement<?>) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements()
+ .iterator().next()).getTypeDefinition();
assertNotNull(instanceIdentEff.toString());
assertFalse(instanceIdentEff.requireInstance());
assertNull(instanceIdentEff.getBaseType());
assertEquals(Optional.empty(), instanceIdentEff.getDefaultValue());
assertNotNull(instanceIdentEff.getUnknownSchemaNodes());
- assertFalse(instanceIdentEff.getDescription().isPresent());
- assertFalse(instanceIdentEff.getReference().isPresent());
+ assertEquals(Optional.empty(), instanceIdentEff.getDescription());
+ assertEquals(Optional.empty(), instanceIdentEff.getReference());
assertEquals(Optional.empty(), instanceIdentEff.getUnits());
assertEquals(Status.CURRENT, instanceIdentEff.getStatus());
assertNotNull(instanceIdentEff.hashCode());
- assertFalse(instanceIdentEff.equals(null));
- assertFalse(instanceIdentEff.equals("test"));
- assertTrue(instanceIdentEff.equals(instanceIdentEff));
+ assertNotEquals(null, instanceIdentEff);
+ assertNotEquals("test", instanceIdentEff);
+ assertEquals(instanceIdentEff, instanceIdentEff);
}
@Test
- public void testLeafref() {
+ void testLeafref() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-leafref"));
assertNotNull(currentLeaf.getType());
final LeafrefTypeDefinition leafrefEff = (LeafrefTypeDefinition) ((TypeDefinitionAware)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertEquals("/container-test/leaf-test", leafrefEff.getPathStatement().getOriginalString());
assertNull(leafrefEff.getBaseType());
assertEquals("leafref", leafrefEff.getQName().getLocalName());
assertEquals(Status.CURRENT, leafrefEff.getStatus());
assertNotNull(leafrefEff.getUnknownSchemaNodes());
- assertFalse(leafrefEff.getDescription().isPresent());
- assertFalse(leafrefEff.getReference().isPresent());
+ assertEquals(Optional.empty(), leafrefEff.getDescription());
+ assertEquals(Optional.empty(), leafrefEff.getReference());
assertNotNull(leafrefEff.hashCode());
- assertFalse(leafrefEff.equals(null));
- assertFalse(leafrefEff.equals("test"));
- assertTrue(leafrefEff.equals(leafrefEff));
+ assertNotEquals(null, leafrefEff);
+ assertNotEquals("test", leafrefEff);
+ assertEquals(leafrefEff, leafrefEff);
}
@Test
- public void testLeafrefWithDeref() {
+ void testLeafrefWithDeref() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName
- .create(types.getQNameModule(), "leaf-leafref-deref"));
+ .create(types.getQNameModule(), "leaf-leafref-deref"));
assertNotNull(currentLeaf.getType());
final LeafrefTypeDefinition leafrefEff = (LeafrefTypeDefinition) ((TypeDefinitionAware)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertEquals("deref(../container-test)/leaf-test",
- leafrefEff.getPathStatement().getOriginalString());
+ leafrefEff.getPathStatement().getOriginalString());
assertNull(leafrefEff.getBaseType());
assertEquals(Optional.empty(), leafrefEff.getUnits());
assertEquals(Optional.empty(), leafrefEff.getDefaultValue());
assertEquals("leafref", leafrefEff.getQName().getLocalName());
assertEquals(Status.CURRENT, leafrefEff.getStatus());
assertNotNull(leafrefEff.getUnknownSchemaNodes());
- assertFalse(leafrefEff.getDescription().isPresent());
- assertFalse(leafrefEff.getReference().isPresent());
+ assertEquals(Optional.empty(), leafrefEff.getDescription());
+ assertEquals(Optional.empty(), leafrefEff.getReference());
assertNotNull(leafrefEff.hashCode());
- assertFalse(leafrefEff.equals(null));
- assertFalse(leafrefEff.equals("test"));
- assertTrue(leafrefEff.equals(leafrefEff));
+ assertNotEquals(null, leafrefEff);
+ assertNotEquals("test", leafrefEff);
+ assertEquals(leafrefEff, leafrefEff);
}
@Test
- public void testIntAll() {
+ void testIntAll() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int8"));
assertNotNull(currentLeaf.getType());
final TypeEffectiveStatement<?> int8Eff = (TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
assertNotNull(int8Eff.toString());
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int16"));
assertNotNull(currentLeaf.getType());
final TypeEffectiveStatement<?> int16Eff = (TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
assertNotNull(int16Eff.toString());
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int32"));
assertNotNull(currentLeaf.getType());
final TypeEffectiveStatement<?> int32Eff = (TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
assertNotNull(int32Eff.toString());
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int64"));
assertNotNull(currentLeaf.getType());
final TypeEffectiveStatement<?> int64Eff = (TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
assertNotNull(int64Eff.toString());
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint8"));
assertNotNull(currentLeaf.getType());
final TypeEffectiveStatement<?> uint8Eff = (TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
assertNotNull(uint8Eff.toString());
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint16"));
assertNotNull(currentLeaf.getType());
final TypeEffectiveStatement<?> uint16Eff = (TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
assertNotNull(uint16Eff.toString());
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint32"));
assertNotNull(currentLeaf.getType());
final TypeEffectiveStatement<?> uint32Eff = (TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
assertNotNull(uint32Eff.toString());
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint64"));
assertNotNull(currentLeaf.getType());
final TypeEffectiveStatement<?> uint64Eff = (TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
assertNotNull(uint64Eff.toString());
}
@Test
- public void testUnion() {
+ void testUnion() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-union"));
assertNotNull(currentLeaf.getType());
final UnionTypeDefinition unionEff = (UnionTypeDefinition) ((TypeDefinitionAware)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertEquals(2, unionEff.getTypes().size());
assertEquals("union", unionEff.getQName().getLocalName());
assertNull(unionEff.getBaseType());
assertEquals(Optional.empty(), unionEff.getUnits());
assertEquals(Optional.empty(), unionEff.getDefaultValue());
- assertFalse(unionEff.getDescription().isPresent());
- assertFalse(unionEff.getReference().isPresent());
+ assertEquals(Optional.empty(), unionEff.getDescription());
+ assertEquals(Optional.empty(), unionEff.getReference());
assertNotNull(unionEff.toString());
assertNotNull(unionEff.hashCode());
- assertFalse(unionEff.equals(null));
- assertFalse(unionEff.equals("test"));
- assertTrue(unionEff.equals(unionEff));
+ assertNotEquals(null, unionEff);
+ assertNotEquals("test", unionEff);
+ assertEquals(unionEff, unionEff);
}
@Test
- public void testLengthConstraint() {
+ void testLengthConstraint() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
- "leaf-length-pattern"));
+ "leaf-length-pattern"));
- final StringTypeDefinition leafType = (StringTypeDefinition) currentLeaf.getType();
+ final var leafType = (StringTypeDefinition) currentLeaf.getType();
assertNotNull(leafType);
- final LengthConstraint lengthConstraint = leafType.getLengthConstraint().get();
+ final var lengthConstraint = leafType.getLengthConstraint().get();
- final Range<Integer> span = lengthConstraint.getAllowedRanges().span();
+ final var span = lengthConstraint.getAllowedRanges().span();
assertEquals(1, span.lowerEndpoint().intValue());
assertEquals(255, span.upperEndpoint().intValue());
- assertFalse(lengthConstraint.getReference().isPresent());
- assertFalse(lengthConstraint.getDescription().isPresent());
- assertFalse(lengthConstraint.getErrorMessage().isPresent());
- assertFalse(lengthConstraint.getErrorAppTag().isPresent());
+ assertEquals(Optional.empty(), lengthConstraint.getReference());
+ assertEquals(Optional.empty(), lengthConstraint.getDescription());
+ assertEquals(Optional.empty(), lengthConstraint.getErrorMessage());
+ assertEquals(Optional.empty(), lengthConstraint.getErrorAppTag());
assertNotNull(lengthConstraint.toString());
assertNotNull(lengthConstraint.hashCode());
- assertFalse(lengthConstraint.equals(null));
- assertFalse(lengthConstraint.equals("test"));
+ assertNotEquals(null, lengthConstraint);
+ assertNotEquals("test", lengthConstraint);
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
- "leaf-length-pattern-second"));
+ "leaf-length-pattern-second"));
assertNotNull(currentLeaf.getType());
final LengthConstraint lengthConstraintSecond = ((StringTypeDefinition) currentLeaf.getType())
- .getLengthConstraint().get();
- assertFalse(lengthConstraint.equals(lengthConstraintSecond));
+ .getLengthConstraint().get();
+ assertNotEquals(lengthConstraint, lengthConstraintSecond);
}
@Test
- public void testPatternConstraint() {
+ void testPatternConstraint() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
- "leaf-length-pattern"));
+ "leaf-length-pattern"));
assertNotNull(currentLeaf.getType());
final PatternConstraint patternConstraint = ((StringTypeDefinition) currentLeaf.getType())
- .getPatternConstraints().get(0);
+ .getPatternConstraints().get(0);
final PatternConstraint patternConstraintThird = ((StringTypeDefinition) currentLeaf.getType())
- .getPatternConstraints().get(0);
+ .getPatternConstraints().get(0);
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
- "leaf-length-pattern-second"));
+ "leaf-length-pattern-second"));
assertNotNull(currentLeaf.getType());
final PatternConstraint patternConstraintSecond = ((StringTypeDefinition) currentLeaf.getType())
- .getPatternConstraints().get(0);
+ .getPatternConstraints().get(0);
assertEquals("^(?:[0-9a-fA-F]*)$", patternConstraint.getJavaPatternString());
- assertFalse(patternConstraint.getReference().isPresent());
- assertFalse(patternConstraint.getDescription().isPresent());
+ assertEquals(Optional.empty(), patternConstraint.getReference());
+ assertEquals(Optional.empty(), patternConstraint.getDescription());
assertEquals(Optional.empty(), patternConstraint.getErrorMessage());
assertEquals(Optional.empty(), patternConstraint.getErrorAppTag());
assertNotNull(patternConstraint.toString());
assertNotNull(patternConstraint.hashCode());
- assertFalse(patternConstraint.equals(null));
- assertFalse(patternConstraint.equals("test"));
- assertFalse(patternConstraint.equals(patternConstraintSecond));
- assertTrue(patternConstraint.equals(patternConstraintThird));
+ assertNotEquals(null, patternConstraint);
+ assertNotEquals("test", patternConstraint);
+ assertNotEquals(patternConstraint, patternConstraintSecond);
+ assertEquals(patternConstraint, patternConstraintThird);
}
@Test
- public void testString() {
+ void testString() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-string"));
assertNotNull(currentLeaf.getType());
final StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement<?>)
- ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
- .getTypeDefinition();
+ ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
+ .getTypeDefinition();
assertEquals("string", stringEff.getQName().getLocalName());
assertEquals(Status.CURRENT, stringEff.getStatus());
assertEquals(Optional.empty(), stringEff.getDefaultValue());
assertNotNull(stringEff.getUnknownSchemaNodes());
assertNull(stringEff.getBaseType());
- assertFalse(stringEff.getDescription().isPresent());
- assertFalse(stringEff.getReference().isPresent());
+ assertEquals(Optional.empty(), stringEff.getDescription());
+ assertEquals(Optional.empty(), stringEff.getReference());
assertNotNull(stringEff.toString());
assertNotNull(stringEff.hashCode());
- assertFalse(stringEff.equals(null));
- assertFalse(stringEff.equals("test"));
- assertTrue(stringEff.equals(stringEff));
- assertFalse(stringEff.getLengthConstraint().isPresent());
+ assertNotEquals(null, stringEff);
+ assertNotEquals("test", stringEff);
+ assertEquals(stringEff, stringEff);
+ assertEquals(Optional.empty(), stringEff.getLengthConstraint());
assertNotNull(stringEff.getPatternConstraints());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Iterables;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-public class EffectiveUsesRefineAndConstraintsTest extends AbstractYangTest {
+class EffectiveUsesRefineAndConstraintsTest extends AbstractYangTest {
@Test
- public void refineTest() throws Exception {
- final EffectiveModelContext result = assertEffectiveModel("/stmt-test/uses/refine-test.yang");
+ void refineTest() {
+ final var result = assertEffectiveModel("/stmt-test/uses/refine-test.yang");
- final ModuleEffectiveStatement module = Iterables.getOnlyElement(result.getModuleStatements().values());
+ final var module = Iterables.getOnlyElement(result.getModuleStatements().values());
final QNameModule qnameModule = module.localQNameModule();
final QName rootContainer = QName.create(qnameModule, "root-container");
checkRefinedChoice(module, rootContainer, containerFromGrouping, choiceFromGrp);
checkRefinedContainer(module, rootContainer, containerFromGrouping2, presenceContainer);
- final GroupingEffectiveStatement grp = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class)
- .orElseThrow();
+ final var grp = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow();
assertEquals(QName.create(qnameModule, "grp-1"), grp.argument());
checkOriginalList(grp, containerFromGrouping, listInContainer);
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-public class ExtensionStmtTest {
+class ExtensionStmtTest extends AbstractYangTest {
@Test
- public void testExtensionDefinition() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/model/bar.yang"))
- .buildEffective();
- assertNotNull(result);
-
- final Module testModule = result.findModules("bar").iterator().next();
+ void testExtensionDefinition() {
+ final var result = assertEffectiveModel("/model/bar.yang");
+ final var testModule = result.findModules("bar").iterator().next();
assertNotNull(testModule);
assertEquals(1, testModule.getExtensionSchemaNodes().size());
final var extensions = testModule.getExtensionSchemaNodes();
- final ExtensionDefinition extension = extensions.iterator().next();
+ final var extension = extensions.iterator().next();
assertEquals("opendaylight", extension.getQName().getLocalName());
assertEquals("name", extension.getArgument());
assertTrue(extension.isYinElement());
}
@Test
- public void testExtensionUsage() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/semantic-statement-parser/ext-typedef.yang"))
- .addSource(sourceForResource("/semantic-statement-parser/ext-use.yang"))
- .buildEffective();
- assertNotNull(result);
+ void testExtensionUsage() {
+ final var result = assertEffectiveModel(
+ "/semantic-statement-parser/ext-typedef.yang",
+ "/semantic-statement-parser/ext-use.yang");
- final Module testModule1 = result.findModules("ext-typedef").iterator().next();
+ final var testModule1 = result.findModules("ext-typedef").iterator().next();
assertNotNull(testModule1);
assertEquals(1, testModule1.getExtensionSchemaNodes().size());
final var extensions = testModule1.getExtensionSchemaNodes();
- final ExtensionDefinition extensionDefinition = extensions.iterator().next();
+ final var extensionDefinition = extensions.iterator().next();
- final Module testModule2 = result.findModules("ext-use").iterator().next();
+ final var testModule2 = result.findModules("ext-use").iterator().next();
assertNotNull(testModule2);
- final LeafSchemaNode leaf = (LeafSchemaNode) testModule2.getDataChildByName(
+ final var leaf = (LeafSchemaNode) testModule2.getDataChildByName(
QName.create(testModule2.getQNameModule(), "value"));
assertNotNull(leaf);
final var unknownNodes = leaf.asEffectiveStatement().getDeclared()
.declaredSubstatements(UnrecognizedStatement.class);
assertEquals(1, unknownNodes.size());
- final UnrecognizedStatement extensionUse = unknownNodes.iterator().next();
+ final var extensionUse = unknownNodes.iterator().next();
assertEquals(extensionDefinition.getQName(), extensionUse.statementDefinition().getStatementName());
assertEquals(extensionDefinition.getArgument(), extensionUse.statementDefinition().getArgumentDefinition()
.orElseThrow().argumentName().getLocalName());
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import com.google.common.collect.ImmutableList;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.List;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
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.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-public class GroupingAndUsesStmtTest {
-
- private static final StatementStreamSource MODULE = sourceForResource("/model/bar.yang");
- private static final StatementStreamSource SUBMODULE = sourceForResource("/model/subfoo.yang");
- private static final StatementStreamSource GROUPING_MODULE = sourceForResource("/model/baz.yang");
- private static final StatementStreamSource USES_MODULE = sourceForResource("/model/foo.yang");
+class GroupingAndUsesStmtTest extends AbstractYangTest {
+ private static final String MODULE = "/model/bar.yang";
+ private static final String SUBMODULE = "/model/subfoo.yang";
+ private static final String GROUPING_MODULE = "/model/baz.yang";
+ private static final String USES_MODULE = "/model/foo.yang";
@Test
- public void groupingTest() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(MODULE, GROUPING_MODULE)
- .buildEffective();
- assertNotNull(result);
+ void groupingTest() {
+ final var result = assertEffectiveModel(MODULE, GROUPING_MODULE);
final Module testModule = result.findModules("baz").iterator().next();
assertNotNull(testModule);
assertEquals(1, grouping.getTypeDefinitions().size());
assertEquals("group-type", grouping.getTypeDefinitions().iterator().next().getQName().getLocalName());
- final Collection<? extends UnrecognizedStatement> unknownSchemaNodes = grouping.asEffectiveStatement()
- .getDeclared().declaredSubstatements(UnrecognizedStatement.class);
+ final var unknownSchemaNodes = grouping.asEffectiveStatement().getDeclared()
+ .declaredSubstatements(UnrecognizedStatement.class);
assertEquals(1, unknownSchemaNodes.size());
final UnrecognizedStatement extensionUse = unknownSchemaNodes.iterator().next();
assertEquals("opendaylight", extensionUse.statementDefinition().getStatementName().getLocalName());
}
@Test
- public void usesAndRefinesTest() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(MODULE, SUBMODULE, GROUPING_MODULE, USES_MODULE)
- .buildEffective();
- assertNotNull(result);
+ void usesAndRefinesTest() {
+ final var result = assertEffectiveModel(MODULE, SUBMODULE, GROUPING_MODULE, USES_MODULE);
final Module testModule = result.findModules("foo").iterator().next();
final Map<Descendant, SchemaNode> refines = usesNode.getRefines();
assertEquals(4, refines.size());
- assertEquals(ImmutableList.of(
- Descendant.of(QName.create(peer, "address")),
- Descendant.of(QName.create(peer, "port")),
- Descendant.of(QName.create(peer, "addresses")),
- Descendant.of(QName.create(peer, "addresses"), QName.create(peer, "id"))),
- new ArrayList<>(refines.keySet()));
+ assertEquals(List.of(
+ Descendant.of(QName.create(peer, "address")),
+ Descendant.of(QName.create(peer, "port")),
+ Descendant.of(QName.create(peer, "addresses")),
+ Descendant.of(QName.create(peer, "addresses"), QName.create(peer, "id"))),
+ List.copyOf(refines.keySet()));
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Iterables;
import java.util.Map;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-public class GroupingTest extends AbstractModelTest {
+class GroupingTest extends AbstractModelTest {
@Test
- public void testRefine() {
+ void testRefine() {
final ContainerSchemaNode peer = (ContainerSchemaNode) FOO.getDataChildByName(fooQName("peer"));
final ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName(fooQName("destination"));
}
@Test
- public void testGrouping() {
+ void testGrouping() {
final var groupings = BAZ.getGroupings();
assertEquals(1, groupings.size());
final GroupingDefinition grouping = groupings.iterator().next();
}
@Test
- public void testUses() {
+ void testUses() {
// suffix _u = added by uses
// suffix _g = defined in grouping
}
@Test
- public void testUsesUnderModule() {
+ void testUsesUnderModule() {
// suffix _u = added by uses
// suffix _g = defined in grouping
assertEquals(Optional.of("inner augment"), augment.getDescription());
final var children = augment.getChildNodes();
assertEquals(1, children.size());
- final DataSchemaNode leaf = children.iterator().next();
- assertTrue(leaf instanceof LeafSchemaNode);
+ final LeafSchemaNode leaf = assertInstanceOf(LeafSchemaNode.class, children.iterator().next());
assertEquals("name", leaf.getQName().getLocalName());
}
@Test
- public void testCascadeUses() throws Exception {
+ void testCascadeUses() throws Exception {
final EffectiveModelContext loadModules = TestUtils.parseYangSource("/grouping-test/cascade-uses.yang");
assertEquals(1, loadModules.getModules().size());
}
@Test
- public void testAddedByUsesLeafTypeQName() throws Exception {
+ void testAddedByUsesLeafTypeQName() throws Exception {
final EffectiveModelContext loadModules = assertEffectiveModelDir("/added-by-uses-leaf-test");
assertEquals(2, loadModules.getModules().size());
final LeafSchemaNode leaf = (LeafSchemaNode)
((ContainerSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "my-container")))
- .getDataChildByName(QName.create(foo.getQNameModule(), "my-leaf"));
+ .getDataChildByName(QName.create(foo.getQNameModule(), "my-leaf"));
TypeDefinition<?> impType = null;
for (final TypeDefinition<?> typeDefinition : imp.getTypeDefinitions()) {
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class IdentityIssueIetfRoutingTest extends AbstractYangTest {
+class IdentityIssueIetfRoutingTest extends AbstractYangTest {
@Test
- public void test() {
+ void test() {
assertEffectiveModelDir("/bugs/identity-ietf-routing-test/");
}
}
package org.opendaylight.yangtools.yang.stmt;
import static org.hamcrest.CoreMatchers.anyOf;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
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.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-public class IdentityStmtTest {
-
- private static final StatementStreamSource ILLEGAL_IDENTITY_MODULE = sourceForResource(
- "/identity/identitytest.yang");
- private static final StatementStreamSource ILLEGAL_IDENTITY_MODULE2 = sourceForResource(
- "/identity/prefixidentitytest.yang");
- private static final StatementStreamSource LEGAL_IDENTITY_MODULE = sourceForResource(
- "/identity/import/dummy.yang");
- private static final StatementStreamSource LEGAL_IDENTITY_MODULE2 = sourceForResource(
- "/identity/import/prefiximportidentitytest.yang");
- private static final StatementStreamSource ILLEGAL_IDENTITY_MODULE3 = sourceForResource(
- "/identity/illegal-chained-identity-test.yang");
- private static final StatementStreamSource LEGAL_IDENTITY_MODULE3 = sourceForResource(
- "/identity/legal-chained-identity-test.yang");
- private static final StatementStreamSource DUPLICATE_IDENTITY_MODULE = sourceForResource(
- "/identity/duplicate-identity-test.yang");
-
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void selfReferencingIdentityTest() throws ReactorException {
- RFC7950Reactors.defaultReactor().newBuild().addSource(ILLEGAL_IDENTITY_MODULE).buildEffective();
+class IdentityStmtTest extends AbstractYangTest {
+ @Test
+ void selfReferencingIdentityTest() {
+ assertInferenceException(
+ startsWith("Unable to resolve identity (urn:test.identitytest?revision=2014-09-17)test and base identity "
+ + "(urn:test.identitytest?revision=2014-09-17)test [at "),
+ "/identity/identitytest.yang");
}
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void selfReferencingIdentityWithPrefixTest() throws ReactorException {
- RFC7950Reactors.defaultReactor().newBuild().addSource(ILLEGAL_IDENTITY_MODULE2).buildEffective();
+ @Test
+ void selfReferencingIdentityWithPrefixTest() {
+ assertInferenceException(
+ startsWith("Unable to resolve identity (urn:test.prefixidentitytest?revision=2014-09-24)prefixtest and "
+ + "base identity (urn:test.prefixidentitytest?revision=2014-09-24)prefixtest [at "),
+ "/identity/prefixidentitytest.yang");
}
@Test
- public void importedIdentityTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(LEGAL_IDENTITY_MODULE, LEGAL_IDENTITY_MODULE2)
- .buildEffective();
- assertNotNull(result);
+ void importedIdentityTest() {
+ assertEffectiveModel("/identity/import/dummy.yang", "/identity/import/prefiximportidentitytest.yang");
}
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void selfReferencingIdentityThroughChaining() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(ILLEGAL_IDENTITY_MODULE3)
- .buildEffective();
- assertNotNull(result);
+ @Test
+ void selfReferencingIdentityThroughChaining() {
+ assertInferenceException(
+ startsWith("Yang model processing phase STATEMENT_DEFINITION failed [at "),
+ "/identity/illegal-chained-identity-test.yang");
}
@Test
- public void chainedIdentityTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(LEGAL_IDENTITY_MODULE3)
- .buildEffective();
- assertNotNull(result);
+ void chainedIdentityTest() {
+ final var result = assertEffectiveModel("/identity/legal-chained-identity-test.yang");
Module testModule = result.findModules("legal-chained-identity-test").iterator().next();
assertNotNull(testModule);
}
@Test
- public void duplicateIdentityTest() throws ReactorException {
- final var reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(DUPLICATE_IDENTITY_MODULE);
- final var cause = assertThrows(SomeModifiersUnresolvedException.class, reactor::buildEffective).getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Duplicate identity definition "));
+ void duplicateIdentityTest() {
+ assertSourceException(startsWith("Duplicate identity definition "), "/identity/duplicate-identity-test.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-public class IfFeatureResolutionTest {
+class IfFeatureResolutionTest extends AbstractYangTest {
@Test
- public void testSomeFeaturesSupported() throws Exception {
- final var schemaContext = StmtTestUtils.parseYangSources("/if-feature-resolution-test",
+ void testSomeFeaturesSupported() {
+ final var schemaContext = assertEffectiveModelDir("/if-feature-resolution-test",
Set.of(
QName.create("foo-namespace", "test-feature-1"),
QName.create("foo-namespace", "test-feature-2"),
QName.create("foo-namespace", "test-feature-3"),
- QName.create("bar-namespace", "imp-feature")),
- YangParserConfiguration.DEFAULT);
+ QName.create("bar-namespace", "imp-feature")));
final Module testModule = schemaContext.findModule("foo").get();
assertEquals(9, testModule.getChildNodes().size());
final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.dataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-a"));
+ QName.create(testModule.getQNameModule(), "test-container-a"));
assertNull(testContainerA);
final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-b"));
+ QName.create(testModule.getQNameModule(), "test-container-b"));
assertNotNull(testContainerB);
final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-b"));
+ QName.create(testModule.getQNameModule(), "test-leaf-b"));
assertNotNull(testLeafB);
final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-c"));
+ QName.create(testModule.getQNameModule(), "test-container-c"));
assertNotNull(testContainerC);
final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-c"));
+ QName.create(testModule.getQNameModule(), "test-leaf-c"));
assertNotNull(testLeafC);
final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.dataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-d"));
+ QName.create(testModule.getQNameModule(), "test-container-d"));
assertNull(testContainerD);
final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-e"));
+ QName.create(testModule.getQNameModule(), "test-container-e"));
assertNotNull(testContainerE);
final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
+ QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
assertNotNull(testSubContainerE);
final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.dataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-e"));
+ QName.create(testModule.getQNameModule(), "test-leaf-e"));
assertNull(testLeafE);
final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-f"));
+ QName.create(testModule.getQNameModule(), "test-container-f"));
assertNotNull(testContainerF);
final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.dataChildByName(
- QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
+ QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
assertNull(testSubContainerF);
final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-g"));
+ QName.create(testModule.getQNameModule(), "test-container-g"));
assertNotNull(testContainerG);
assertEquals(1, testContainerG.getAvailableAugmentations().size());
final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-g"));
+ QName.create(testModule.getQNameModule(), "test-leaf-g"));
assertNotNull(testLeafG);
final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.dataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
assertNull(augmentingTestLeafG);
final AnyxmlSchemaNode augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
assertNotNull(augmentingTestAnyxmlG);
final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-h"));
+ QName.create(testModule.getQNameModule(), "test-container-h"));
assertNotNull(testContainerH);
assertEquals(0, testContainerH.getChildNodes().size());
assertEquals(0, testContainerH.getUses().size());
final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-i"));
+ QName.create(testModule.getQNameModule(), "test-container-i"));
assertNotNull(testContainerI);
assertEquals(1, testContainerI.getUses().size());
ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
+ QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
final LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
+ QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNull(testGroupingLeaf);
final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-j"));
+ QName.create(testModule.getQNameModule(), "test-container-j"));
assertNotNull(testContainerJ);
final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-j"));
+ QName.create(testModule.getQNameModule(), "test-leaf-j"));
assertNotNull(testLeafJ);
final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-k"));
+ QName.create(testModule.getQNameModule(), "test-container-k"));
assertNotNull(testContainerK);
assertEquals(1, testContainerK.getUses().size());
testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
+ QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
assertNotNull(augmentingTestGroupingLeaf);
final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
assertNull(augmentingTestGroupingLeaf2);
}
@Test
- public void testAllFeaturesSupported() throws Exception {
- final var schemaContext = StmtTestUtils.parseYangSources("/if-feature-resolution-test",
- YangParserConfiguration.DEFAULT);
+ void testAllFeaturesSupported() {
+ final var schemaContext = assertEffectiveModelDir("/if-feature-resolution-test");
final Module testModule = schemaContext.findModules("foo").iterator().next();
assertNotNull(testModule);
assertEquals(11, testModule.getChildNodes().size());
final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-a"));
+ QName.create(testModule.getQNameModule(), "test-container-a"));
assertNotNull(testContainerA);
final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-a"));
+ QName.create(testModule.getQNameModule(), "test-leaf-a"));
assertNotNull(testLeafA);
final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-b"));
+ QName.create(testModule.getQNameModule(), "test-container-b"));
assertNotNull(testContainerB);
final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-b"));
+ QName.create(testModule.getQNameModule(), "test-leaf-b"));
assertNotNull(testLeafB);
final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-c"));
+ QName.create(testModule.getQNameModule(), "test-container-c"));
assertNotNull(testContainerC);
final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-c"));
+ QName.create(testModule.getQNameModule(), "test-leaf-c"));
assertNotNull(testLeafC);
final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-d"));
+ QName.create(testModule.getQNameModule(), "test-container-d"));
assertNotNull(testContainerD);
final LeafSchemaNode testLeafD = (LeafSchemaNode) testContainerD.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-d"));
+ QName.create(testModule.getQNameModule(), "test-leaf-d"));
assertNotNull(testLeafD);
final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-e"));
+ QName.create(testModule.getQNameModule(), "test-container-e"));
assertNotNull(testContainerE);
final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
+ QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
assertNotNull(testSubContainerE);
final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-e"));
+ QName.create(testModule.getQNameModule(), "test-leaf-e"));
assertNotNull(testLeafE);
final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-f"));
+ QName.create(testModule.getQNameModule(), "test-container-f"));
assertNotNull(testContainerF);
final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
+ QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
assertNotNull(testSubContainerF);
final ContainerSchemaNode testSubSubContainerF = (ContainerSchemaNode) testSubContainerF.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-subsubcontainer-f"));
+ QName.create(testModule.getQNameModule(), "test-subsubcontainer-f"));
assertNotNull(testSubSubContainerF);
final LeafSchemaNode testLeafF = (LeafSchemaNode) testSubSubContainerF.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-f"));
+ QName.create(testModule.getQNameModule(), "test-leaf-f"));
assertNotNull(testLeafF);
final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-g"));
+ QName.create(testModule.getQNameModule(), "test-container-g"));
assertNotNull(testContainerG);
assertEquals(2, testContainerG.getAvailableAugmentations().size());
final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-g"));
+ QName.create(testModule.getQNameModule(), "test-leaf-g"));
assertNotNull(testLeafG);
final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
assertNotNull(augmentingTestLeafG);
final AnyxmlSchemaNode augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
assertNotNull(augmentingTestAnyxmlG);
final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-h"));
+ QName.create(testModule.getQNameModule(), "test-container-h"));
assertNotNull(testContainerH);
assertEquals(1, testContainerH.getUses().size());
ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerH.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
+ QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
+ QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNotNull(testGroupingLeaf);
final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-i"));
+ QName.create(testModule.getQNameModule(), "test-container-i"));
assertNotNull(testContainerI);
assertEquals(1, testContainerI.getUses().size());
testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
+ QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
+ QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNotNull(testGroupingLeaf);
final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-j"));
+ QName.create(testModule.getQNameModule(), "test-container-j"));
assertNotNull(testContainerJ);
final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-j"));
+ QName.create(testModule.getQNameModule(), "test-leaf-j"));
assertNotNull(testLeafJ);
final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-k"));
+ QName.create(testModule.getQNameModule(), "test-container-k"));
assertNotNull(testContainerK);
assertEquals(1, testContainerK.getUses().size());
testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
+ QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
assertNotNull(augmentingTestGroupingLeaf);
final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
assertNotNull(augmentingTestGroupingLeaf2);
testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
+ QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNotNull(testGroupingLeaf);
}
@Test
- public void testNoFeaturesSupported() throws Exception {
- final var schemaContext = StmtTestUtils.parseYangSources("/if-feature-resolution-test",
- Set.of(), YangParserConfiguration.DEFAULT);
+ void testNoFeaturesSupported() {
+ final var schemaContext = assertEffectiveModelDir("/if-feature-resolution-test", Set.of());
final Module testModule = schemaContext.findModules("foo").iterator().next();
assertNotNull(testModule);
assertEquals(6, testModule.getChildNodes().size());
final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-e"));
+ QName.create(testModule.getQNameModule(), "test-container-e"));
assertNotNull(testContainerE);
final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
+ QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
assertNotNull(testSubContainerE);
final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.dataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-e"));
+ QName.create(testModule.getQNameModule(), "test-leaf-e"));
assertNull(testLeafE);
final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-f"));
+ QName.create(testModule.getQNameModule(), "test-container-f"));
assertNotNull(testContainerF);
final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.dataChildByName(
- QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
+ QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
assertNull(testSubContainerF);
final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-g"));
+ QName.create(testModule.getQNameModule(), "test-container-g"));
assertNotNull(testContainerG);
assertEquals(1, testContainerG.getAvailableAugmentations().size());
final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-leaf-g"));
+ QName.create(testModule.getQNameModule(), "test-leaf-g"));
assertNotNull(testLeafG);
final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.dataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
assertNull(augmentingTestLeafG);
final AnyxmlSchemaNode augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
assertNotNull(augmentingTestAnyxmlG);
final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-h"));
+ QName.create(testModule.getQNameModule(), "test-container-h"));
assertNotNull(testContainerH);
assertEquals(0, testContainerH.getChildNodes().size());
assertEquals(0, testContainerH.getUses().size());
final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-i"));
+ QName.create(testModule.getQNameModule(), "test-container-i"));
assertNotNull(testContainerI);
assertEquals(1, testContainerI.getUses().size());
ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
+ QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
+ QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNull(testGroupingLeaf);
final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-container-k"));
+ QName.create(testModule.getQNameModule(), "test-container-k"));
assertNotNull(testContainerK);
assertEquals(1, testContainerK.getUses().size());
testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
+ QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
assertNull(augmentingTestGroupingLeaf);
final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
- QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
+ QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
assertNull(augmentingTestGroupingLeaf2);
testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
- QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
+ QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNull(testGroupingLeaf);
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.hamcrest.CoreMatchers.allOf;
+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.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
-
-public class ImportResolutionBasicTest {
-
- private static final StatementStreamSource ROOT_WITHOUT_IMPORT = sourceForResource(
- "/semantic-statement-parser/import-arg-parsing/nature.yang");
- private static final StatementStreamSource IMPORT_ROOT = sourceForResource(
- "/semantic-statement-parser/import-arg-parsing/mammal.yang");
- private static final StatementStreamSource IMPORT_DERIVED = sourceForResource(
- "/semantic-statement-parser/import-arg-parsing/human.yang");
- private static final StatementStreamSource IMPORT_SELF = sourceForResource(
- "/semantic-statement-parser/import-arg-parsing/egocentric.yang");
- private static final StatementStreamSource CYCLE_YIN = sourceForResource(
- "/semantic-statement-parser/import-arg-parsing/cycle-yin.yang");
- private static final StatementStreamSource CYCLE_YANG = sourceForResource(
- "/semantic-statement-parser/import-arg-parsing/cycle-yang.yang");
- private static final StatementStreamSource FOO = sourceForResource(
- "/semantic-statement-parser/bug2649/foo.yang");
- private static final StatementStreamSource IMPORT = sourceForResource(
- "/semantic-statement-parser/bug2649/import-module.yang");
+import org.junit.jupiter.api.Test;
+class ImportResolutionBasicTest extends AbstractYangTest {
+ private static final String ROOT_WITHOUT_IMPORT = "/semantic-statement-parser/import-arg-parsing/nature.yang";
+ private static final String IMPORT_ROOT = "/semantic-statement-parser/import-arg-parsing/mammal.yang";
+ private static final String IMPORT_DERIVED = "/semantic-statement-parser/import-arg-parsing/human.yang";
@Test
- public void inImportOrderTest() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(ROOT_WITHOUT_IMPORT, IMPORT_ROOT, IMPORT_DERIVED)
- .build();
- assertNotNull(result);
+ void inImportOrderTest() {
+ assertEffectiveModel(ROOT_WITHOUT_IMPORT, IMPORT_ROOT, IMPORT_DERIVED);
}
@Test
- public void inInverseOfImportOrderTest() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT)
- .build();
- assertNotNull(result);
+ void inInverseOfImportOrderTest() {
+ assertEffectiveModel(IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
}
@Test
- public void missingImportedSourceTest() {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
- try {
- reactor.build();
- fail("reactor.process should fail due to missing imported source");
- } catch (ReactorException e) {
- assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_PRE_LINKAGE, e.getPhase());
- }
-
+ void missingImportedSourceTest() {
+ assertFailedPreLinkage("mammal", IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
}
@Test
- public void circularImportsTest() {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(CYCLE_YIN, CYCLE_YANG);
- try {
- reactor.build();
- fail("reactor.process should fail due to circular import");
- } catch (ReactorException e) {
- assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_PRE_LINKAGE, e.getPhase());
- }
+ void circularImportsTest() {
+ assertFailedPreLinkage("cycle-",
+ "/semantic-statement-parser/import-arg-parsing/cycle-yin.yang",
+ "/semantic-statement-parser/import-arg-parsing/cycle-yang.yang");
}
@Test
- public void selfImportTest() {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(IMPORT_SELF, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
- try {
- reactor.build();
- fail("reactor.process should fail due to self import");
- } catch (ReactorException e) {
- assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_PRE_LINKAGE, e.getPhase());
- }
+ void selfImportTest() {
+ assertFailedPreLinkage("egocentric",
+ "/semantic-statement-parser/import-arg-parsing/egocentric.yang", IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
}
@Test
- public void bug2649Test() throws ReactorException {
- SchemaContext buildEffective = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(FOO, IMPORT)
- .buildEffective();
- assertNotNull(buildEffective);
+ void bug2649Test() {
+ assertEffectiveModel(
+ "/semantic-statement-parser/bug2649/foo.yang",
+ "/semantic-statement-parser/bug2649/import-module.yang");
+ }
+
+ private static void assertFailedPreLinkage(final String name, final String... sources) {
+ assertInferenceException(allOf(
+ startsWith("Imported module [" + name),
+ containsString("] was not found. [at ")),
+ sources);
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
-
-public class ImportRevisionsTest {
-
- private static final StatementStreamSource ROOT_WITH_EQUAL_DATE = sourceForResource(
- "/import-revision-date-test/root-with-equal-revision-date.yang");
- private static final StatementStreamSource IMPORTED_WITH_EQUAL_DATE = sourceForResource(
- "/import-revision-date-test/imported-module-with-equal-revision-date.yang");
- private static final StatementStreamSource ROOT_WITH_UNEQUAL_DATE = sourceForResource(
- "/import-revision-date-test/root-with-unequal-revision-date.yang");
- private static final StatementStreamSource IMPORTED_WITH_UNEQUAL_DATE = sourceForResource(
- "/import-revision-date-test/imported-module-with-unequal-revision-date.yang");
- private static final StatementStreamSource ROOT_WITH_DATE = sourceForResource(
- "/import-revision-date-test/root-with-revision-date.yang");
- private static final StatementStreamSource IMPORTED_WITHOUT_DATE = sourceForResource(
- "/import-revision-date-test/imported-module-without-revision-date.yang");
- private static final StatementStreamSource ROOT_WITHOUT_DATE = sourceForResource(
- "/import-revision-date-test/root-without-revision-date.yang");
- private static final StatementStreamSource IMPORTED_WITH_DATE = sourceForResource(
- "/import-revision-date-test/imported-module-with-revision-date.yang");
- private static final StatementStreamSource ROOT_WITH_NO_DATE = sourceForResource(
- "/import-revision-date-test/root-with-no-revision-date.yang");
- private static final StatementStreamSource IMPORTED_WITH_NO_DATE = sourceForResource(
- "/import-revision-date-test/imported-module-with-no-revision-date.yang");
+import org.junit.jupiter.api.Test;
+class ImportRevisionsTest extends AbstractYangTest {
@Test
- public void equalRevisionDatesTest() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(ROOT_WITH_EQUAL_DATE, IMPORTED_WITH_EQUAL_DATE)
- .build();
- assertNotNull(result);
+ void equalRevisionDatesTest() {
+ assertEffectiveModel(
+ "/import-revision-date-test/root-with-equal-revision-date.yang",
+ "/import-revision-date-test/imported-module-with-equal-revision-date.yang");
}
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void unequalRevisionDatesTest() throws ReactorException {
- RFC7950Reactors.defaultReactor().newBuild()
- .addSources(ROOT_WITH_UNEQUAL_DATE, IMPORTED_WITH_UNEQUAL_DATE)
- .build();
+ @Test
+ void unequalRevisionDatesTest() {
+ assertInferenceException(
+ startsWith("Imported module [imported-module-with-unequal-revision-date] was not found. [at "),
+ "/import-revision-date-test/root-with-unequal-revision-date.yang",
+ "/import-revision-date-test/imported-module-with-unequal-revision-date.yang");
}
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void revisionDatesInRootOnlyTest() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(ROOT_WITH_DATE, IMPORTED_WITHOUT_DATE)
- .build();
- assertNotNull(result);
+ @Test
+ void revisionDatesInRootOnlyTest() {
+ assertInferenceException(
+ startsWith("Imported module [imported-module-without-revision-date] was not found. [at "),
+ "/import-revision-date-test/root-with-revision-date.yang",
+ "/import-revision-date-test/imported-module-without-revision-date.yang");
}
@Test
- public void revisionDatesInImportedOnlyTest() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(ROOT_WITHOUT_DATE, IMPORTED_WITH_DATE)
- .build();
- assertNotNull(result);
+ void revisionDatesInImportedOnlyTest() {
+ assertEffectiveModel(
+ "/import-revision-date-test/root-without-revision-date.yang",
+ "/import-revision-date-test/imported-module-with-revision-date.yang");
}
@Test
- public void noRevisionInRootAndImportedTest() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(ROOT_WITH_NO_DATE, IMPORTED_WITH_NO_DATE)
- .build();
- assertNotNull(result);
+ void noRevisionInRootAndImportedTest() {
+ assertEffectiveModel(
+ "/import-revision-date-test/root-with-no-revision-date.yang",
+ "/import-revision-date-test/imported-module-with-no-revision-date.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.stmt;
-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 static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-import org.junit.Test;
+import java.util.concurrent.Callable;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class IncludeResolutionTest {
-
- private static final Logger LOG = LoggerFactory.getLogger(IncludeResolutionTest.class);
+class IncludeResolutionTest {
private static final StatementStreamSource ROOT = sourceForResource(
- "/semantic-statement-parser/include-arg-parsing/root-module.yang");
+ "/semantic-statement-parser/include-arg-parsing/root-module.yang");
private static final StatementStreamSource SUBMODULE1 = sourceForResource(
- "/semantic-statement-parser/include-arg-parsing/submodule-1.yang");
+ "/semantic-statement-parser/include-arg-parsing/submodule-1.yang");
private static final StatementStreamSource SUBMODULE2 = sourceForResource(
- "/semantic-statement-parser/include-arg-parsing/submodule-2.yang");
+ "/semantic-statement-parser/include-arg-parsing/submodule-2.yang");
private static final StatementStreamSource ERROR_MODULE = sourceForResource(
- "/semantic-statement-parser/include-arg-parsing/error-module.yang");
+ "/semantic-statement-parser/include-arg-parsing/error-module.yang");
private static final StatementStreamSource ERROR_SUBMODULE = sourceForResource(
- "/semantic-statement-parser/include-arg-parsing/error-submodule.yang");
-
+ "/semantic-statement-parser/include-arg-parsing/error-submodule.yang");
+ private static final StatementStreamSource ERROR_SUBMODULE_ROOT = sourceForResource(
+ "/semantic-statement-parser/include-arg-parsing/error-submodule-root.yang");
private static final StatementStreamSource MISSING_PARENT_MODULE = sourceForResource(
- "/semantic-statement-parser/include-arg-parsing/missing-parent.yang");
+ "/semantic-statement-parser/include-arg-parsing/missing-parent.yang");
@Test
- public void includeTest() throws SourceException, ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(ROOT, SUBMODULE1, SUBMODULE2)
- .build();
+ void includeTest() throws ReactorException {
+ var result = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(ROOT, SUBMODULE1, SUBMODULE2)
+ .build();
assertNotNull(result);
}
@Test
- public void missingIncludedSourceTest() throws SourceException {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(ERROR_MODULE);
- try {
- reactor.build();
- fail("reactor.process should fail due to missing included source");
- } catch (ReactorException e) {
- assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
- LOG.info(e.getMessage());
- }
-
+ void missingIncludedSourceTest() {
+ var reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(ERROR_MODULE);
+ assertNull(assertFailedSourceLinkage(reactor::build, "Included submodule 'foo' was not found [at ").getCause());
}
@Test
- public void missingIncludedSourceTest2() throws SourceException {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(ERROR_SUBMODULE);
- try {
- reactor.build();
- fail("reactor.process should fail due to missing included source");
- } catch (ReactorException e) {
- assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
- LOG.info(e.getMessage());
- }
-
+ void missingIncludedSourceTest2() {
+ var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(ERROR_SUBMODULE, ERROR_SUBMODULE_ROOT);
+ var cause = assertFailedSourceLinkage(reactor::build, "Included submodule 'foo' was not found [at ");
+ assertNull(cause.getCause());
}
@Test
- public void missingIncludedSourceTest3() throws SourceException, ReactorException {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(MISSING_PARENT_MODULE);
- try {
- reactor.build();
- fail("reactor.process should fail due to missing belongsTo source");
- } catch (ReactorException e) {
- LOG.info(e.getMessage());
- }
+ void missingIncludedSourceTest3() throws SourceException, ReactorException {
+ var reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(MISSING_PARENT_MODULE);
+ assertNull(assertFailedSourceLinkage(reactor::build,
+ "Module 'Unqualified{localName=foo}' from belongs-to was not found [at ").getCause());
+ }
+ private static InferenceException assertFailedSourceLinkage(final Callable<?> callable, final String startStr) {
+ final var ex = assertThrows(SomeModifiersUnresolvedException.class, callable::call);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, ex.getPhase());
+ var cause = assertInstanceOf(InferenceException.class, ex.getCause());
+ assertThat(cause.getMessage(), startsWith(startStr));
+ return cause;
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
-public class IncludeRevisionsTest {
+class IncludeRevisionsTest {
private static final StatementStreamSource EQUAL_ROOT = sourceForResource("/revisions/equal-root.yang");
private static final StatementStreamSource EQUAL_REV = sourceForResource("/revisions/equal-rev.yang");
private static final StatementStreamSource NOWHERE_REV = sourceForResource("/revisions/nowhere-rev.yang");
@Test
- public void revsEqualTest() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(EQUAL_REV, EQUAL_ROOT)
- .build();
+ void revsEqualTest() throws ReactorException {
+ var result = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(EQUAL_REV, EQUAL_ROOT)
+ .build();
assertNotNull(result);
}
@Test
- public void revsUnequalTest() throws ReactorException {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(UNEQUAL_REV, UNEQUAL_ROOT);
- try {
- reactor.build();
- fail("reactor.process should fail due to unequal revisions in include and submodule");
- } catch (ReactorException e) {
- assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
- }
+ void revsUnequalTest() throws ReactorException {
+ var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(UNEQUAL_REV, UNEQUAL_ROOT);
+ var ex = assertThrows(SomeModifiersUnresolvedException.class, reactor::build);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, ex.getPhase());
}
@Test
- public void revIncludeOnly() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT)
- .build();
+ void revIncludeOnly() throws ReactorException {
+ var result = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT)
+ .build();
assertNotNull(result);
}
@Test
- public void revInModuleOnly() throws ReactorException {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(MOD_ONLY_REV, MOD_ONLY_ROOT);
- try {
- reactor.build();
- fail("reactor.process should fail due to missing revision in included submodule");
- } catch (ReactorException e) {
- assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
- }
+ void revInModuleOnly() throws ReactorException {
+ var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(MOD_ONLY_REV, MOD_ONLY_ROOT);
+ var ex = assertThrows(SomeModifiersUnresolvedException.class, reactor::build);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, ex.getPhase());
}
@Test
- public void revNowhereTest() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(NOWHERE_REV, NOWHERE_ROOT)
- .build();
+ void revNowhereTest() throws ReactorException {
+ var result = RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(NOWHERE_REV, NOWHERE_ROOT)
+ .build();
assertNotNull(result);
}
}
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collection;
import java.util.Iterator;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
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.Submodule;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-
-public class IncludedStmtsTest {
- private static SchemaContext result;
-
- @BeforeClass
- public static void setup() throws ReactorException {
- result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/included-statements-test/root-module.yang"))
- .addSource(sourceForResource("/included-statements-test/child-module.yang"))
- .buildEffective();
+
+class IncludedStmtsTest extends AbstractYangTest {
+ private static EffectiveModelContext result;
+
+ @BeforeAll
+ static void setup() {
+ result = assertEffectiveModelDir("/included-statements-test");
}
- @AfterClass
- public static void teardown() {
+ @AfterAll
+ static void teardown() {
result = null;
}
@Test
- public void includedTypedefsTest() {
+ void includedTypedefsTest() {
final Module testModule = result.findModules("root-module").iterator().next();
assertNotNull(testModule);
}
@Test
- public void includedFeaturesTest() {
+ void includedFeaturesTest() {
final Module testModule = result.findModules("root-module").iterator().next();
assertNotNull(testModule);
}
@Test
- public void includedContainersAndListsTest() {
+ void includedContainersAndListsTest() {
final Module testModule = result.findModules("root-module").iterator().next();
assertNotNull(testModule);
}
@Test
- public void submoduleNamespaceTest() {
+ void submoduleNamespaceTest() {
final Module testModule = result.findModules("root-module").iterator().next();
assertNotNull(testModule);
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
-
-public class KeyTest {
-
- private static final StatementStreamSource KEY_SIMPLE_AND_COMP = sourceForResource(
- "/semantic-statement-parser/key-arg-parsing/key-simple-and-comp.yang");
- private static final StatementStreamSource KEY_COMP_DUPLICATE = sourceForResource(
- "/semantic-statement-parser/key-arg-parsing/key-comp-duplicate.yang");
+import org.junit.jupiter.api.Test;
+class KeyTest extends AbstractYangTest {
@Test
- public void keySimpleTest() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(KEY_SIMPLE_AND_COMP)
- .build();
- assertNotNull(result);
+ void keySimpleTest() {
+ assertEffectiveModel("/semantic-statement-parser/key-arg-parsing/key-simple-and-comp.yang");
}
@Test
- public void keyCompositeInvalid() {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(KEY_COMP_DUPLICATE);
- try {
- reactor.build();
- fail("reactor.process should fail due to duplicate name in key");
- } catch (ReactorException e) {
- final Throwable cause = e.getCause();
- assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().startsWith("Key argument 'key1 key2 key2' contains duplicates"));
- }
+ void keyCompositeInvalid() {
+ assertSourceException(startsWith("Key argument 'key1 key2 key2' contains duplicates"),
+ "/semantic-statement-parser/key-arg-parsing/key-comp-duplicate.yang");
}
}
*/
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.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.junit.jupiter.api.Test;
-public class ListKeysTest {
+class ListKeysTest extends AbstractYangTest {
@Test
- public void correctListKeysTest() throws Exception {
- TestUtils.parseYangSource("/list-keys-test/correct-list-keys-test.yang");
+ void correctListKeysTest() {
+ assertEffectiveModel("/list-keys-test/correct-list-keys-test.yang");
}
@Test
- public void incorrectListKeysTest1() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> 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'"));
+ void incorrectListKeysTest1() {
+ assertInferenceException(startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"),
+ "/list-keys-test/incorrect-list-keys-test.yang");
}
@Test
- public void incorrectListKeysTest2() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> 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'"));
+ void incorrectListKeysTest2() {
+ assertInferenceException(startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"),
+ "/list-keys-test/incorrect-list-keys-test2.yang");
}
@Test
- public void incorrectListKeysTest3() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> 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'"));
+ void incorrectListKeysTest3() {
+ assertInferenceException(startsWith("Key 'grp_list' misses node 'grp_list'"),
+ "/list-keys-test/incorrect-list-keys-test3.yang");
}
@Test
- public void incorrectListKeysTest4() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> 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'"));
+ void incorrectListKeysTest4() {
+ assertInferenceException(startsWith("Key 'grp_leaf' misses node 'grp_leaf'"),
+ "/list-keys-test/incorrect-list-keys-test4.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
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.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-public class ListTest {
+class ListTest extends AbstractYangTest {
@Test
- public void listAndLeavesTest() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/list-test/list-test.yang"))
- .buildEffective();
- assertNotNull(result);
+ void listAndLeavesTest() {
+ final var result = assertEffectiveModel("/list-test/list-test.yang");
final Module testModule = result.findModules("list-test").iterator().next();
assertNotNull(testModule);
*/
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.assertTrue;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
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.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-public class MoreRevisionsTest extends AbstractYangTest {
- private static final StatementStreamSource REVFILE = sourceForResource(
- "/semantic-statement-parser/revisions/more-revisions-test.yang");
-
- private static final StatementStreamSource TED_20130712 = sourceForResource(
- "/semantic-statement-parser/two-revisions/ted@2013-07-12.yang");
-
- private static final StatementStreamSource TED_20131021 = sourceForResource(
- "/semantic-statement-parser/two-revisions/ted@2013-10-21.yang");
-
- private static final StatementStreamSource IETF_TYPES = sourceForResource(
- "/ietf/ietf-inet-types@2010-09-24.yang");
-
- private static final StatementStreamSource NETWORK_TOPOLOGY_20130712 = sourceForResource(
- "/ietf/network-topology@2013-07-12.yang");
-
- private static final StatementStreamSource NETWORK_TOPOLOGY_20131021 = sourceForResource(
- "/ietf/network-topology@2013-10-21.yang");
-
- private static final StatementStreamSource ISIS_20130712 = sourceForResource(
- "/semantic-statement-parser/two-revisions/isis-topology@2013-07-12.yang");
-
- private static final StatementStreamSource ISIS_20131021 = sourceForResource(
- "/semantic-statement-parser/two-revisions/isis-topology@2013-10-21.yang");
-
- private static final StatementStreamSource L3_20130712 = sourceForResource(
- "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-07-12.yang");
-
- private static final StatementStreamSource L3_20131021 = sourceForResource(
- "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-10-21.yang");
+class MoreRevisionsTest extends AbstractYangTest {
+ private static final String TED_20130712 = "/semantic-statement-parser/two-revisions/ted@2013-07-12.yang";
+ private static final String TED_20131021 = "/semantic-statement-parser/two-revisions/ted@2013-10-21.yang";
+ private static final String IETF_TYPES = "/ietf/ietf-inet-types@2010-09-24.yang";
+ private static final String NETWORK_TOPOLOGY_20130712 = "/ietf/network-topology@2013-07-12.yang";
+ private static final String NETWORK_TOPOLOGY_20131021 = "/ietf/network-topology@2013-10-21.yang";
+ private static final String ISIS_20130712 =
+ "/semantic-statement-parser/two-revisions/isis-topology@2013-07-12.yang";
+ private static final String ISIS_20131021 =
+ "/semantic-statement-parser/two-revisions/isis-topology@2013-10-21.yang";
+ private static final String L3_20130712 =
+ "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-07-12.yang";
+ private static final String L3_20131021 =
+ "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-10-21.yang";
@Test
- public void readAndParseYangFileTest() throws ReactorException {
- EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild().addSource(REVFILE).buildEffective();
- final Module moduleByName = result.getModules().iterator().next();
+ void readAndParseYangFileTest() {
+ final var result = assertEffectiveModel("/semantic-statement-parser/revisions/more-revisions-test.yang");
+ final var moduleByName = result.getModules().iterator().next();
assertEquals("2015-06-07", moduleByName.getQNameModule().getRevision().get().toString());
}
@Test
- public void twoRevisionsTest() throws ReactorException {
- RFC7950Reactors.defaultReactor().newBuild().addSources(TED_20130712, TED_20131021, IETF_TYPES).buildEffective();
+ void twoRevisionsTest() {
+ assertEffectiveModel(TED_20130712, TED_20131021, IETF_TYPES);
}
@Test
- public void twoRevisionsTest2() throws ReactorException {
- final var context = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021, IETF_TYPES)
- .buildEffective();
+ void twoRevisionsTest2() {
+ final var context = assertEffectiveModel(NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021, IETF_TYPES);
assertEquals(3, context.getModuleStatements().size());
assertEquals(2, context.findModules("network-topology").size());
}
@Test
- public void moreRevisionsListKeyTest() throws ReactorException {
- RFC7950Reactors.defaultReactor().newBuild()
- .addSources(TED_20130712, TED_20131021, ISIS_20130712, ISIS_20131021, L3_20130712, L3_20131021)
- .addSources(IETF_TYPES,NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021)
- .buildEffective();
+ void moreRevisionsListKeyTest() throws ReactorException {
+ assertEffectiveModel(TED_20130712, TED_20131021, ISIS_20130712, ISIS_20131021, L3_20130712, L3_20131021,
+ IETF_TYPES, NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021);
}
@Test
- public void multipleRevisionsTest() {
+ void multipleRevisionsTest() {
for (int i = 0; i < 100; i++) {
assertEffectiveModelDir("/semantic-statement-parser/multiple-revisions");
}
}
@Test
- public void multipleRevisionsFullTest() {
+ void multipleRevisionsFullTest() {
for (int i = 0; i < 100; i++) {
var context = assertEffectiveModelDir("/semantic-statement-parser/multiple-revisions/full");
assertEquals(6, context.getModules().size());
}
private static void checkInterfacesModuleFullTest(final EffectiveModelContext context, final Revision rev20100924,
- final QName dateTimeTypeDef20100924) {
+ final QName dateTimeTypeDef20100924) {
Revision rev20121115 = Revision.of("2012-11-15");
Module interfacesModule20121115 = context.findModule("ietf-interfaces", rev20121115).get();
}
private static void checkNetconfMonitoringModuleFullTest(final EffectiveModelContext context,
- final Revision rev20130715, final QName dateTimeTypeDef20130715) {
+ final Revision rev20130715, final QName dateTimeTypeDef20130715) {
Revision rev20101004 = Revision.of("2010-10-04");
Module monitoringModule20101004 = context.findModule("ietf-netconf-monitoring", rev20101004).get();
}
@Test
- public void multipleRevisionsSimpleTest() {
+ void multipleRevisionsSimpleTest() {
for (int i = 0; i < 1000; i++) {
var context = assertEffectiveModelDir("/semantic-statement-parser/multiple-revisions/simple");
assertEquals(5, context.getModules().size());
}
private static void checkInterfacesModuleSimpleTest(final EffectiveModelContext context,
- final Revision rev20100924, final QName dateTimeTypeDef20100924) {
+ final Revision rev20100924, final QName dateTimeTypeDef20100924) {
XMLNamespace interfacesNS = XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-interfaces");
Revision rev20121115 = Revision.of("2012-11-15");
final QNameModule interfacesNS20121115 = QNameModule.create(interfacesNS, rev20121115);
Module interfacesModule20121115 = context.findModule("ietf-interfaces", rev20121115).get();
DataSchemaNode leafLastChange = interfacesModule20121115.getDataChildByName(lastChange);
- assertThat(leafLastChange, instanceOf(LeafSchemaNode.class));
- QName lastChangeTypeQName = ((LeafSchemaNode) leafLastChange).getType().getQName();
+ QName lastChangeTypeQName = assertInstanceOf(LeafSchemaNode.class, leafLastChange).getType().getQName();
assertEquals(dateTimeTypeDef20100924, lastChangeTypeQName);
Collection<? extends ModuleImport> imports = interfacesModule20121115.getImports();
}
private static void checkNetconfMonitoringModuleSimpleTest(final EffectiveModelContext context,
- final Revision rev20130715, final QName dateTimeTypeDef20130715) {
+ final Revision rev20130715, final QName dateTimeTypeDef20130715) {
final XMLNamespace monitoringNS = XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring");
final QNameModule monitoring19700101 = QNameModule.create(monitoringNS);
QName lockedTime = QName.create(monitoring19700101, "locked-time");
Module monitoringModule19700101 = context.findModule("ietf-netconf-monitoring").get();
DataSchemaNode leafLockedTime = monitoringModule19700101.getDataChildByName(lockedTime);
- assertThat(leafLockedTime, instanceOf(LeafSchemaNode.class));
- QName lockedTimeTypeQName = ((LeafSchemaNode) leafLockedTime).getType().getQName();
+ QName lockedTimeTypeQName = assertInstanceOf(LeafSchemaNode.class, leafLockedTime).getType().getQName();
assertEquals(dateTimeTypeDef20130715, lockedTimeTypeQName);
Collection<? extends ModuleImport> imports = monitoringModule19700101.getImports();
}
@Test
- public void nodeTest() {
+ void nodeTest() {
final var context = assertEffectiveModelDir("/semantic-statement-parser/multiple-revisions/node-test");
QName root = QName.create("foo", "2016-04-06", "foo-root");
QName container20160404 = QName.create("foo", "2016-04-06", "con20160404");
DataSchemaNode findDataSchemaNode = context.findDataTreeChild(root, container20160404).orElse(null);
- assertThat(findDataSchemaNode, instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class, findDataSchemaNode);
QName container20160405 = QName.create("foo", "2016-04-06", "con20160405");
findDataSchemaNode = context.findDataTreeChild(root, container20160405).orElse(null);
- assertThat(findDataSchemaNode, instanceOf(ContainerSchemaNode.class));
+ assertInstanceOf(ContainerSchemaNode.class, findDataSchemaNode);
QName container20160406 = QName.create("foo", "2016-04-06", "con20160406");
assertEquals(Optional.empty(), context.findDataTreeChild(root, container20160406));
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Collection;
-import java.util.Iterator;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-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.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-public class MustAndWhenStmtTest {
+class MustAndWhenStmtTest extends AbstractYangTest {
@Test
- public void mustStmtTest() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/must-when-stmt-test/must-test.yang"))
- .buildEffective();
- assertNotNull(result);
+ void mustStmtTest() {
+ final var result = assertEffectiveModel("/must-when-stmt-test/must-test.yang");
- final Module testModule = result.findModules("must-test").iterator().next();
+ final var testModule = result.findModules("must-test").iterator().next();
assertNotNull(testModule);
- final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(
+ final var container = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "interface"));
assertNotNull(container);
assertTrue(container.isPresenceContainer());
- final Collection<? extends MustDefinition> musts = container.getMustConstraints();
+ final var musts = container.getMustConstraints();
assertEquals(2, musts.size());
- final Iterator<? extends MustDefinition> mustsIterator = musts.iterator();
+ final var mustsIterator = musts.iterator();
MustDefinition mustStmt = mustsIterator.next();
assertThat(mustStmt.getXpath().toString(), anyOf(is("ifType != 'ethernet' or (ifType = 'ethernet' and "
- + "ifMTU = 1500)"), is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
+ + "ifMTU = 1500)"), is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
assertThat(mustStmt.getErrorMessage(), anyOf(is(Optional.of("An ethernet MTU must be 1500")),
is(Optional.of("An atm MTU must be 64 .. 17966"))));
assertThat(mustStmt.getErrorAppTag(), anyOf(is(Optional.of("An ethernet error")),
}
@Test
- public void whenStmtTest() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/must-when-stmt-test/when-test.yang"))
- .buildEffective();
- assertNotNull(result);
+ void whenStmtTest() {
+ final var result = assertEffectiveModel("/must-when-stmt-test/when-test.yang");
- final Module testModule = result.findModules("when-test").iterator().next();
+ final var testModule = result.findModules("when-test").iterator().next();
assertNotNull(testModule);
- final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(
+ final var container = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container"));
assertNotNull(container);
assertEquals("conditional-leaf = 'autumn-leaf'", container.getWhenCondition().orElseThrow().toString());
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class NameCollisionWithinCaseTest extends AbstractYangTest {
+class NameCollisionWithinCaseTest extends AbstractYangTest {
@Test
- public void testChildNameCollisionOfAugmentCase() {
+ void testChildNameCollisionOfAugmentCase() {
assertSourceException(startsWith("Cannot add data tree child with name (foo?revision=2018-02-11)bar, "
- + "a conflicting child already exists [at "), "/bugs/name-collision-within-case/foo.yang");
+ + "a conflicting child already exists [at "), "/bugs/name-collision-within-case/foo.yang");
}
@Test
- public void testChildNameCollisionOfAugmentChoice() {
+ void testChildNameCollisionOfAugmentChoice() {
assertSourceException(startsWith("Cannot add data tree child with name (bar?revision=2018-02-11)bar, "
- + "a conflicting child already exists [at "), "/bugs/name-collision-within-case/bar.yang");
+ + "a conflicting child already exists [at "), "/bugs/name-collision-within-case/bar.yang");
}
@Test
- public void testChildNameCollisionNormal() {
+ void testChildNameCollisionNormal() {
assertSourceException(startsWith("Error in module 'baz': cannot add '(baz?revision=2018-02-28)bar'."
- + " Node name collision: "), "/bugs/name-collision-within-case/baz.yang");
+ + " Node name collision: "), "/bugs/name-collision-within-case/baz.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class NotificationStmtTest {
+class NotificationStmtTest extends AbstractYangTest {
@Test
- public void notificationTest() throws Exception {
- final SchemaContext result = TestUtils.parseYangSource("/model/baz.yang", "/model/bar.yang");
- assertNotNull(result);
+ void notificationTest() throws Exception {
+ final var result = assertEffectiveModel("/model/baz.yang", "/model/bar.yang");
- final Module testModule = result.findModules("baz").iterator().next();
+ final var testModule = result.findModules("baz").iterator().next();
assertNotNull(testModule);
- final Collection<? extends NotificationDefinition> notifications = testModule.getNotifications();
+ final var notifications = testModule.getNotifications();
assertEquals(1, notifications.size());
- final NotificationDefinition notification = notifications.iterator().next();
+ final var notification = notifications.iterator().next();
assertEquals("event", notification.getQName().getLocalName());
assertEquals(3, notification.getChildNodes().size());
- LeafSchemaNode leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(),
- "event-class"));
+ var leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(),
+ "event-class"));
assertNotNull(leaf);
leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "severity"));
assertNotNull(leaf);
- final AnyxmlSchemaNode anyXml = (AnyxmlSchemaNode) notification.getDataChildByName(QName.create(
+ final var anyXml = (AnyxmlSchemaNode) notification.getDataChildByName(QName.create(
testModule.getQNameModule(), "reporting-entity"));
assertNotNull(anyXml);
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
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.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-public class OrderingTest extends AbstractModelTest {
+class OrderingTest extends AbstractModelTest {
@Test
- public void testOrderingTypedef() {
+ void testOrderingTypedef() {
final var 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"
final String[] actualOrder = new String[typedefs.size()];
int offset = 0;
- for (final TypeDefinition<?> type : typedefs) {
+ for (var type : typedefs) {
actualOrder[offset] = type.getQName().getLocalName();
offset++;
}
}
@Test
- public void testOrderingChildNodes() {
+ void testOrderingChildNodes() {
AugmentationSchemaNode augment1 = null;
for (final AugmentationSchemaNode as : FOO.getAugmentations()) {
if (as.getChildNodes().size() == 5) {
}
@Test
- public void testOrderingNestedChildNodes1() {
+ void testOrderingNestedChildNodes1() {
final var 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() {
+ void testOrderingNestedChildNodes2() {
final var groupings = BAZ.getGroupings();
assertEquals(1, groupings.size());
final GroupingDefinition target = groupings.iterator().next();
final var childNodes = target.getChildNodes();
- final String[] expectedOrder = { "data", "how", "address", "port", "addresses" };
+ final String[] expectedOrder = {"data", "how", "address", "port", "addresses"};
final String[] actualOrder = new String[childNodes.size()];
int offset = 0;
}
@Test
- public void testOrderingNestedChildNodes3() {
+ void testOrderingNestedChildNodes3() {
final Module justFoo = assertEffectiveModel("/ordering/foo.yang").getModules().iterator().next();
final ContainerSchemaNode x = (ContainerSchemaNode) justFoo
- .getDataChildByName(QName.create(justFoo.getQNameModule(), "x"));
+ .getDataChildByName(QName.create(justFoo.getQNameModule(), "x"));
final var childNodes = x.getChildNodes();
final String[] expectedOrder = { "x15", "x10", "x5", "x1", "a5", "a1", "x2", "b5", "b1", "x3", "ax15", "ax5" };
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test for testing of extensions and their arguments.
*/
-public class ParsingExtensionValueTest extends AbstractYangTest {
+class ParsingExtensionValueTest extends AbstractYangTest {
@Test
- public void extensionTest() {
+ void extensionTest() {
assertSourceExceptionDir("/extensions", startsWith("ext:id is not a YANG statement or use of extension"));
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-public class RpcStmtTest extends AbstractYangTest {
+class RpcStmtTest extends AbstractYangTest {
@Test
- public void rpcTest() throws ReactorException {
- final EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/model/baz.yang"))
- .addSource(sourceForResource("/model/bar.yang"))
- .addSource(sourceForResource("/rpc-stmt-test/foo.yang"))
- .buildEffective();
- assertNotNull(result);
+ void rpcTest() {
+ final var result = assertEffectiveModel("/model/baz.yang", "/model/bar.yang", "/rpc-stmt-test/foo.yang");
final Module testModule = result.findModules("baz").iterator().next();
assertEquals(1, testModule.getRpcs().size());
}
}
- assertFalse(fooRpc1.equals(null));
- assertFalse(fooRpc1.equals("str"));
- assertFalse(fooRpc1.equals(fooRpc2));
+ assertNotEquals(null, fooRpc1);
+ assertNotEquals("str", fooRpc1);
+ assertNotEquals(fooRpc1, fooRpc2);
assertNotEquals(fooRpc1.getInput().hashCode(), fooRpc2.getInput().hashCode());
assertNotEquals(fooRpc1.getOutput().hashCode(), fooRpc2.getOutput().hashCode());
- assertTrue(fooRpc1.getInput().equals(fooRpc1.getInput()));
- assertFalse(fooRpc1.getInput().equals(null));
- assertFalse(fooRpc1.getInput().equals("str"));
- assertFalse(fooRpc1.getInput().equals(fooRpc2.getInput()));
+ assertEquals(fooRpc1.getInput(), fooRpc1.getInput());
+ assertNotEquals(null, fooRpc1.getInput());
+ assertNotEquals("str", fooRpc1.getInput());
+ assertNotEquals(fooRpc1.getInput(), fooRpc2.getInput());
- assertTrue(fooRpc1.getOutput().equals(fooRpc1.getOutput()));
- assertFalse(fooRpc1.getOutput().equals(null));
- assertFalse(fooRpc1.getOutput().equals("str"));
- assertFalse(fooRpc1.getOutput().equals(fooRpc2.getOutput()));
+ assertEquals(fooRpc1.getOutput(), fooRpc1.getOutput());
+ assertNotEquals(null, fooRpc1.getOutput());
+ assertNotEquals("str", fooRpc1.getOutput());
+ assertNotEquals(fooRpc1.getOutput(), fooRpc2.getOutput());
}
@Test
- public void testImplicitInputAndOutput() {
+ void testImplicitInputAndOutput() {
final var context = assertEffectiveModel("/rpc-stmt-test/bar.yang");
final Module barModule = context.findModule("bar", Revision.of("2016-11-25")).get();
package org.opendaylight.yangtools.yang.stmt;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException;
-public class SubstatementValidatorTest extends AbstractYangTest {
+class SubstatementValidatorTest extends AbstractYangTest {
@Test
- public void noException() throws Exception {
+ void noException() {
assertEquals(3, assertEffectiveModelDir("/augment-test/augment-in-augment").getModules().size());
}
@Test
- public void undesirableElementException() throws Exception {
+ void undesirableElementException() {
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 {
+ void maximalElementCountException() {
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() {
+ void missingElementException() {
// FIXME: should be MissingSubstatementException?
assertSourceExceptionDir("/substatement-validator/missing-element",
startsWith("Missing prefix statement [at "));
}
@Test
- public void bug6173Test() throws Exception {
+ void bug6173Test() {
assertEquals(1, assertEffectiveModelDir("/substatement-validator/empty-element").getModules().size());
}
@Test
- public void bug4310test() throws Exception {
+ void bug4310test() {
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 "));
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Revision;
-public class TwoRevisionsTest extends AbstractYangTest {
+class TwoRevisionsTest extends AbstractYangTest {
@Test
- public void testTwoRevisions() throws Exception {
+ void testTwoRevisions() {
var it = assertEffectiveModelDir("/ietf").findModuleStatements("network-topology").iterator();
assertTrue(it.hasNext());
assertEquals(Revision.ofNullable("2013-10-21"), it.next().localQNameModule().getRevision());
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import com.google.common.collect.Range;
import java.util.Collection;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.Decimal64;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
-public class TypedefConstraintsTest extends AbstractYangTest {
+class TypedefConstraintsTest extends AbstractYangTest {
@Test
- public void decimalRangeConstraintsTest() {
+ void decimalRangeConstraintsTest() {
final var context = assertEffectiveModelDir("/stmt-test/constraints");
assertNotNull(context);
final TypeDefinition<?> myDecimal = typeDefinitions.iterator().next();
- assertNotNull(myDecimal);
- assertTrue(myDecimal instanceof DecimalTypeDefinition);
-
- final Set<? extends Range<?>> rangeConstraints = ((DecimalTypeDefinition) myDecimal).getRangeConstraint()
- .get().getAllowedRanges().asRanges();
+ final Set<? extends Range<?>> rangeConstraints = assertInstanceOf(DecimalTypeDefinition.class, myDecimal)
+ .getRangeConstraint()
+ .orElseThrow().getAllowedRanges().asRanges();
assertNotNull(rangeConstraints);
assertEquals(1, rangeConstraints.size());
final DataSchemaNode dataNode = context.getDataChildByName(QName.create("urn:opendaylight.foo", "2013-10-08",
"id-decimal64"));
assertNotNull(dataNode);
- assertTrue(dataNode instanceof LeafSchemaNode);
+ final LeafSchemaNode leafDecimal = assertInstanceOf(LeafSchemaNode.class, dataNode);
- final LeafSchemaNode leafDecimal = (LeafSchemaNode) dataNode;
final TypeDefinition<?> type = leafDecimal.getType();
- assertTrue(type instanceof DecimalTypeDefinition);
- final DecimalTypeDefinition decType = (DecimalTypeDefinition) type;
+ final DecimalTypeDefinition decType = assertInstanceOf(DecimalTypeDefinition.class, type);
assertEquals(4, decType.getFractionDigits());
final Set<? extends Range<Decimal64>> decRangeConstraints = decType.getRangeConstraint().get()
- .getAllowedRanges().asRanges();
+ .getAllowedRanges().asRanges();
assertEquals(1, decRangeConstraints.size());
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.Collection;
import java.util.Optional;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-
-public class TypedefSubStmtsTest {
+import org.junit.jupiter.api.Test;
+class TypedefSubStmtsTest extends AbstractYangTest {
@Test
- public void typedefSubStmtsTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/typedef-substmts-test/typedef-substmts-test.yang"))
- .buildEffective();
- assertNotNull(result);
+ void typedefSubStmtsTest() {
+ final var result = assertEffectiveModel("/typedef-substmts-test/typedef-substmts-test.yang");
- Collection<? extends TypeDefinition<?>> typedefs = result.getTypeDefinitions();
+ final var typedefs = result.getTypeDefinitions();
assertEquals(1, typedefs.size());
- TypeDefinition<?> typedef = typedefs.iterator().next();
+ final var typedef = typedefs.iterator().next();
assertEquals("time-of-the-day", typedef.getQName().getLocalName());
assertEquals("string", typedef.getBaseType().getQName().getLocalName());
assertEquals(Optional.of("24-hour-clock"), typedef.getUnits());
- assertEquals("1am", typedef.getDefaultValue().map(Object::toString).orElse(null));
+ assertEquals("1am", typedef.getDefaultValue().map(Object::toString).orElseThrow());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Iterables;
import com.google.common.collect.Range;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
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.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.stmt.UnrecognizedStatement;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
-
-public class TypesResolutionTest {
- private static SchemaContext CONTEXT;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- CONTEXT = TestUtils.parseYangSource(
+
+class TypesResolutionTest extends AbstractYangTest {
+ private static EffectiveModelContext CONTEXT;
+
+ @BeforeAll
+ static void beforeClass() {
+ CONTEXT = assertEffectiveModel(
"/types/custom-types-test@2012-04-04.yang",
"/ietf/iana-timezones@2012-07-09.yang",
"/ietf/ietf-inet-types@2010-09-24.yang",
}
@Test
- public void testIPVersion() {
+ void testIPVersion() {
Module tested = CONTEXT.findModules("ietf-inet-types").iterator().next();
Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
assertEquals(14, typedefs.size());
}
@Test
- public void testEnumeration() {
+ void testEnumeration() {
Module tested = CONTEXT.findModules("custom-types-test").iterator().next();
Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
}
@Test
- public void testIpAddress() {
+ void testIpAddress() {
Module tested = CONTEXT.findModules("ietf-inet-types").iterator().next();
Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-address");
StringTypeDefinition ipv4 = (StringTypeDefinition) unionTypes.get(0);
assertNotNull(ipv4.getBaseType());
String expectedPattern = "^(?:(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
- + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?)$";
+ + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?)$";
assertEquals(expectedPattern, ipv4.getPatternConstraints().get(0).getJavaPatternString());
StringTypeDefinition ipv6 = (StringTypeDefinition) unionTypes.get(1);
assertNotNull(ipv6.getBaseType());
List<PatternConstraint> ipv6Patterns = ipv6.getPatternConstraints();
expectedPattern = "^(?:((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
- + "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|" + "(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
- + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?)$";
+ + "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|" + "(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
+ + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?)$";
assertEquals(expectedPattern, ipv6Patterns.get(0).getJavaPatternString());
expectedPattern = "^(?:(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)"
- + "(%.+)?)$";
+ + "(%.+)?)$";
assertEquals(expectedPattern, ipv6Patterns.get(1).getJavaPatternString());
}
@Test
- public void testDomainName() {
+ void testDomainName() {
Module tested = CONTEXT.findModules("ietf-inet-types").iterator().next();
Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
StringTypeDefinition type = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "domain-name");
List<PatternConstraint> patterns = type.getPatternConstraints();
assertEquals(1, patterns.size());
String expectedPattern = "^(?:((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
- + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.)$";
+ + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.)$";
assertEquals(expectedPattern, patterns.get(0).getJavaPatternString());
LengthConstraint lengths = type.getLengthConstraint().get();
}
@Test
- public void testInstanceIdentifier1() {
+ void testInstanceIdentifier1() {
Module tested = CONTEXT.findModules("custom-types-test").iterator().next();
LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
- QName.create(tested.getQNameModule(), "inst-id-leaf1"));
+ QName.create(tested.getQNameModule(), "inst-id-leaf1"));
InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType();
assertFalse(leafType.requireInstance());
assertEquals(1,
}
@Test
- public void testInstanceIdentifier2() {
+ void testInstanceIdentifier2() {
Module tested = CONTEXT.findModules("custom-types-test").iterator().next();
LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
- QName.create(tested.getQNameModule(), "inst-id-leaf2"));
+ QName.create(tested.getQNameModule(), "inst-id-leaf2"));
InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType();
assertFalse(leafType.requireInstance());
}
@Test
- public void testIdentity() {
+ void testIdentity() {
Module tested = CONTEXT.findModules("custom-types-test").iterator().next();
Collection<? extends IdentitySchemaNode> identities = tested.getIdentities();
assertEquals(5, identities.size());
}
@Test
- public void testBitsType1() {
+ void testBitsType1() {
Module tested = CONTEXT.findModules("custom-types-test").iterator().next();
LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
- QName.create(tested.getQNameModule(), "mybits"));
+ QName.create(tested.getQNameModule(), "mybits"));
BitsTypeDefinition leafType = (BitsTypeDefinition) leaf.getType();
Iterator<? extends Bit> bits = leafType.getBits().iterator();
}
@Test
- public void testBitsType2() {
+ void testBitsType2() {
Module tested = CONTEXT.findModules("custom-types-test").iterator().next();
Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "access-operations-type");
}
@Test
- public void testIanaTimezones() {
+ void testIanaTimezones() {
Module tested = CONTEXT.findModules("iana-timezones").iterator().next();
Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "iana-timezone");
}
@Test
- public void testObjectId128() {
+ void testObjectId128() {
Module tested = CONTEXT.findModules("ietf-yang-types").iterator().next();
Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
StringTypeDefinition testedType = (StringTypeDefinition) TestUtils.findTypedef(typedefs,
- "object-identifier-128");
+ "object-identifier-128");
List<PatternConstraint> patterns = testedType.getPatternConstraints();
assertEquals(1, patterns.size());
pattern = patterns.get(0);
assertEquals("^(?:(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*)$",
- pattern.getJavaPatternString());
+ pattern.getJavaPatternString());
QName testedTypeBaseQName = testedTypeBase.getQName();
assertEquals(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-yang-types"),
}
@Test
- public void testIdentityref() {
+ void testIdentityref() {
Module tested = CONTEXT.findModules("custom-types-test").iterator().next();
Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "service-type-ref");
}
@Test
- public void testUnionWithExt() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/types/union-with-ext/extdef.yang"))
- .addSource(sourceForResource("/types/union-with-ext/unionbug.yang"))
- .addSource(sourceForResource("/ietf/ietf-inet-types@2010-09-24.yang"))
- .buildEffective();
- assertNotNull(result);
+ void testUnionWithExt() {
+ assertEffectiveModel(
+ "/types/union-with-ext/extdef.yang",
+ "/types/union-with-ext/unionbug.yang",
+ "/ietf/ietf-inet-types@2010-09-24.yang");
}
@Test
- public void testUnionWithBits() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/types/union-with-bits/union-bits-model.yang"))
- .buildEffective();
- assertNotNull(result);
+ void testUnionWithBits() {
+ assertEffectiveModel("/types/union-with-bits/union-bits-model.yang");
}
@Test
- public void testUnionInList() {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/types/union-in-list/unioninlisttest.yang"));
-
- try {
- final SchemaContext result = reactor.buildEffective();
- fail("effective build should fail due to union in list; this is not allowed");
- } catch (ReactorException e) {
- assertEquals(SomeModifiersUnresolvedException.class, e.getClass());
- assertTrue(e.getCause() instanceof SourceException);
- assertTrue(e.getCause().getMessage().startsWith("union is not a YANG statement or use of extension"));
- }
+ void testUnionInList() {
+ assertSourceException(startsWith("union is not a YANG statement or use of extension"),
+ "/types/union-in-list/unioninlisttest.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
-public class UsesAugmentTest extends AbstractYangTest {
+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(
private static EffectiveModelContext CONTEXT;
- @BeforeClass
- public static void beforeClass() throws Exception {
+ @BeforeAll
+ static void beforeClass() throws Exception {
CONTEXT = assertEffectiveModelDir("/grouping-test");
}
* @throws Exception if exception occurs
*/
@Test
- public void testAugmentInUses() throws Exception {
+ void testAugmentInUses() throws Exception {
final Module testModule = CONTEXT.findModules("uses-grouping").iterator().next();
// * notification pcreq
assertEquals(4, childNodes.size());
// * |-- leaf version
LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
- "version"));
+ "version"));
assertNotNull(version);
assertEquals(QName.create(UG, "version"), version.getQName());
assertEquals(QName.create(UG, "version"), version.getType().getQName());
assertTrue(version.isAddedByUses());
// * |-- leaf type
LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
- "type"));
+ "type"));
assertNotNull(type);
assertTrue(type.isAddedByUses());
assertEquals(QName.create(UG, "type"), type.getQName());
assertEquals(2, union.getTypes().size());
// * |-- list requests
final ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName(QName.create(
- testModule.getQNameModule(), "requests"));
+ testModule.getQNameModule(), "requests"));
assertNotNull(requests);
assertEquals(QName.create(UG, "requests"), requests.getQName());
assertFalse(requests.isAddedByUses());
assertEquals(3, childNodes.size());
// * |-- |-- container rp
final ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
- testModule.getQNameModule(), "rp"));
+ testModule.getQNameModule(), "rp"));
assertNotNull(rp);
assertEquals(QName.create(UG, "rp"), rp.getQName());
assertFalse(rp.isAddedByUses());
assertEquals(4, childNodes.size());
// * |-- |-- |-- leaf processing-rule
LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName(QName.create(
- testModule.getQNameModule(), "processing-rule"));
+ testModule.getQNameModule(), "processing-rule"));
assertNotNull(processingRule);
assertEquals(QName.create(UG, "processing-rule"), processingRule.getQName());
assertEquals(BaseTypes.booleanType(), processingRule.getType());
assertTrue(processingRule.isAddedByUses());
// * |-- |-- |-- leaf ignore
LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(),
- "ignore"));
+ "ignore"));
assertNotNull(ignore);
assertEquals(QName.create(UG, "ignore"), ignore.getQName());
assertEquals(BaseTypes.booleanType(), ignore.getType());
assertTrue(ignore.isAddedByUses());
// * |-- |-- |-- leaf priority
final LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName(QName.create(
- testModule.getQNameModule(), "priority"));
+ testModule.getQNameModule(), "priority"));
assertNotNull(priority);
assertEquals(QName.create(UG, "priority"), priority.getQName());
// TODO
assertTrue(priority.isAddedByUses());
// * |-- |-- |-- container box
ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(),
- "box"));
+ "box"));
assertNotNull(box);
assertEquals(QName.create(UG, "box"), box.getQName());
assertTrue(box.isAddedByUses());
// * |-- |-- |-- |-- container order
final ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName(QName.create(
- testModule.getQNameModule(), "order"));
+ testModule.getQNameModule(), "order"));
assertNotNull(order);
assertEquals(QName.create(UG, "order"), order.getQName());
assertTrue(order.isAddedByUses());
assertEquals(2, order.getChildNodes().size());
// * |-- |-- |-- |-- |-- leaf delete
final LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName(QName.create(
- testModule.getQNameModule(), "delete"));
+ testModule.getQNameModule(), "delete"));
assertNotNull(delete);
assertEquals(QName.create(UG, "delete"), delete.getQName());
assertEquals(BaseTypes.uint32Type(), delete.getType());
assertTrue(delete.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf setup
final LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName(QName.create(
- testModule.getQNameModule(), "setup"));
+ testModule.getQNameModule(), "setup"));
assertNotNull(setup);
assertEquals(QName.create(UG, "setup"), setup.getQName());
assertEquals(BaseTypes.uint32Type(), setup.getType());
assertTrue(setup.isAddedByUses());
// * |-- |-- path-key-expansion
final ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
- testModule.getQNameModule(), "path-key-expansion"));
+ testModule.getQNameModule(), "path-key-expansion"));
assertNotNull(pke);
assertEquals(QName.create(UG, "path-key-expansion"), pke.getQName());
assertFalse(pke.isAddedByUses());
// * |-- |-- |-- path-key
final ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName(QName.create(
- testModule.getQNameModule(), "path-key"));
+ testModule.getQNameModule(), "path-key"));
assertNotNull(pathKey);
assertEquals(QName.create(UG, "path-key"), pathKey.getQName());
assertFalse(pathKey.isAddedByUses());
assertEquals(3, pathKey.getChildNodes().size());
// * |-- |-- |-- |-- leaf processing-rule
processingRule = (LeafSchemaNode) pathKey.getDataChildByName(QName.create(testModule.getQNameModule(),
- "processing-rule"));
+ "processing-rule"));
assertNotNull(processingRule);
assertEquals(QName.create(UG, "processing-rule"), processingRule.getQName());
assertEquals(BaseTypes.booleanType(), processingRule.getType());
assertTrue(ignore.isAddedByUses());
// * |-- |-- |-- |-- list path-keys
final ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName(QName.create(
- testModule.getQNameModule(), "path-keys"));
+ testModule.getQNameModule(), "path-keys"));
assertNotNull(pathKeys);
assertEquals(QName.create(UG, "path-keys"), pathKeys.getQName());
assertTrue(pathKeys.isAddedByUses());
version = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "version"));
assertNotNull(version);
assertEquals(QName.create(UG, "version"), version.getQName());
- assertTrue(version.getType() instanceof Uint8TypeDefinition);
+ assertInstanceOf(Uint8TypeDefinition.class, version.getType());
assertEquals(BaseTypes.uint8Type(), version.getType().getBaseType().getBaseType());
assertTrue(version.isAddedByUses());
assertTrue(version.isAugmenting());
type = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "type"));
assertNotNull(type);
assertEquals(QName.create(UG, "type"), type.getQName());
- assertTrue(type.getType() instanceof UnionTypeDefinition);
+ assertInstanceOf(UnionTypeDefinition.class, type.getType());
assertTrue(type.isAddedByUses());
assertTrue(type.isAugmenting());
// * |-- |-- container segment-computation
final ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
- testModule.getQNameModule(), "segment-computation"));
+ testModule.getQNameModule(), "segment-computation"));
assertNotNull(sc);
assertEquals(QName.create(UG, "segment-computation"), sc.getQName());
assertFalse(sc.isAddedByUses());
// * |-- |-- |-- container p2p
final ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName(QName.create(
- testModule.getQNameModule(), "p2p"));
+ testModule.getQNameModule(), "p2p"));
assertNotNull(p2p);
assertEquals(QName.create(UG, "p2p"), p2p.getQName());
assertFalse(p2p.isAddedByUses());
// * |-- |-- |-- |-- container endpoints
final ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName(QName.create(
- testModule.getQNameModule(), "endpoints"));
+ testModule.getQNameModule(), "endpoints"));
assertNotNull(endpoints);
assertEquals(QName.create(UG, "endpoints"), endpoints.getQName());
assertFalse(endpoints.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf processing-rule
processingRule = (LeafSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(),
- "processing-rule"));
+ "processing-rule"));
assertNotNull(processingRule);
assertEquals(QName.create(UG, "processing-rule"), processingRule.getQName());
assertEquals(BaseTypes.booleanType(), processingRule.getType());
assertTrue(box.isAddedByUses());
// * |-- |-- |-- |-- |-- choice address-family
final ChoiceSchemaNode af = (ChoiceSchemaNode) endpoints.getDataChildByName(QName.create(
- testModule.getQNameModule(), "address-family"));
+ testModule.getQNameModule(), "address-family"));
assertNotNull(af);
assertEquals(QName.create(UG, "address-family"), af.getQName());
assertTrue(af.isAddedByUses());
// * |-- |-- |-- |-- container reported-route
final ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName(QName.create(
- testModule.getQNameModule(), "reported-route"));
+ testModule.getQNameModule(), "reported-route"));
assertNotNull(reportedRoute);
assertEquals(QName.create(UG, "reported-route"), reportedRoute.getQName());
assertFalse(reportedRoute.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf processing-rule
processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName(QName.create(testModule.getQNameModule(),
- "processing-rule"));
+ "processing-rule"));
assertNotNull(processingRule);
assertEquals(QName.create(UG, "processing-rule"), processingRule.getQName());
assertEquals(BaseTypes.booleanType(), processingRule.getType());
assertTrue(ignore.isAddedByUses());
// * |-- |-- |-- |-- |-- list subobjects
final ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName(QName.create(
- testModule.getQNameModule(), "subobjects"));
+ testModule.getQNameModule(), "subobjects"));
assertNotNull(subobjects);
assertEquals(QName.create(UG, "subobjects"), subobjects.getQName());
assertTrue(subobjects.isAddedByUses());
// * |-- |-- |-- |-- |-- container bandwidth
ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName(QName.create(
- testModule.getQNameModule(), "bandwidth"));
+ testModule.getQNameModule(), "bandwidth"));
assertNotNull(bandwidth);
assertEquals(QName.create(UG, "bandwidth"), bandwidth.getQName());
assertFalse(bandwidth.isAddedByUses());
// * |-- |-- |-- |-- container bandwidth
bandwidth = (ContainerSchemaNode) p2p
- .getDataChildByName(QName.create(testModule.getQNameModule(), "bandwidth"));
+ .getDataChildByName(QName.create(testModule.getQNameModule(), "bandwidth"));
assertNotNull(bandwidth);
assertEquals(QName.create(UG, "bandwidth"), bandwidth.getQName());
assertTrue(bandwidth.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf processing-rule
processingRule = (LeafSchemaNode) bandwidth.getDataChildByName(QName.create(testModule.getQNameModule(),
- "processing-rule"));
+ "processing-rule"));
assertNotNull(processingRule);
assertEquals(QName.create(UG, "processing-rule"), processingRule.getQName());
assertEquals(BaseTypes.booleanType(), processingRule.getType());
assertTrue(ignore.isAddedByUses());
// * |-- |-- |-- |-- |-- container bandwidth
final ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName(QName.create(
- testModule.getQNameModule(), "bandwidth"));
+ testModule.getQNameModule(), "bandwidth"));
assertNotNull(bandwidthInner);
assertEquals(QName.create(UG, "bandwidth"), bandwidth.getQName());
assertTrue(bandwidthInner.isAddedByUses());
// * |-- list svec
final ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
- "svec"));
+ "svec"));
assertNotNull(svec);
assertEquals(QName.create(UG, "svec"), svec.getQName());
assertFalse(svec.isAddedByUses());
// * |-- |-- leaf link-diverse
final LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName(QName.create(
- testModule.getQNameModule(), "link-diverse"));
+ testModule.getQNameModule(), "link-diverse"));
assertNotNull(linkDiverse);
assertEquals(QName.create(UG, "link-diverse"), linkDiverse.getQName());
assertEquals(BaseTypes.booleanType(), linkDiverse.getType().getBaseType());
assertTrue(linkDiverse.isAddedByUses());
// * |-- |-- leaf processing-rule
processingRule = (LeafSchemaNode) svec.getDataChildByName(QName.create(testModule.getQNameModule(),
- "processing-rule"));
+ "processing-rule"));
assertNotNull(processingRule);
assertEquals(QName.create(UG, "processing-rule"), processingRule.getQName());
assertEquals(BaseTypes.booleanType(), processingRule.getType());
assertTrue(ignore.isAddedByUses());
// * |-- |-- list metric
final ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName(QName.create(
- testModule.getQNameModule(), "metric"));
+ testModule.getQNameModule(), "metric"));
assertNotNull(metric);
assertEquals(QName.create(UG, "metric"), metric.getQName());
assertFalse(metric.isAddedByUses());
// * |-- |-- |-- leaf metric-type
final LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName(QName.create(
- testModule.getQNameModule(), "metric-type"));
+ testModule.getQNameModule(), "metric-type"));
assertNotNull(metricType);
assertEquals(QName.create(UG, "metric-type"), metricType.getQName());
assertEquals(BaseTypes.uint8Type(), metricType.getType());
assertTrue(box.isAddedByUses());
// * |-- |-- |-- leaf processing-rule
processingRule = (LeafSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(),
- "processing-rule"));
+ "processing-rule"));
assertNotNull(processingRule);
assertEquals(QName.create(UG, "processing-rule"), processingRule.getQName());
assertEquals(BaseTypes.booleanType(), processingRule.getType());
}
@Test
- public void testTypedefs() throws Exception {
+ void testTypedefs() throws Exception {
final Module testModule = CONTEXT.findModules("grouping-definitions").iterator().next();
final Collection<? extends TypeDefinition<?>> types = testModule.getTypeDefinitions();
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1039Test extends AbstractYangTest {
+class YT1039Test extends AbstractYangTest {
@Test
- public void testUsesRefineAnyxml() {
+ void testUsesRefineAnyxml() {
assertEquals(2, assertEffectiveModelDir("/bugs/YT1039").getModuleStatements().size());
}
}
import static org.hamcrest.Matchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1042Test extends AbstractYangTest {
+class YT1042Test extends AbstractYangTest {
@Test
- public void testSubmoduleConflict() {
+ void testSubmoduleConflict() {
assertSourceExceptionDir("/bugs/YT1042",
startsWith("Cannot add data tree child with name (foo)foo, a conflicting child already exists"));
}
*/
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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import com.google.common.collect.Iterables;
import java.util.Iterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
-public class YT1089Test extends AbstractYangTest {
+class YT1089Test extends AbstractYangTest {
@Test
- public void testPlusLexing() {
+ void testPlusLexing() {
final EffectiveModelContext ctx = assertEffectiveModel("/bugs/YT1089/foo.yang");
assertEquals(1, ctx.getModuleStatements().size());
final Iterator<? extends EffectiveStatement<?, ?>> it =
- Iterables.getOnlyElement(ctx.getModuleStatements().values()).effectiveSubstatements().iterator();
+ Iterables.getOnlyElement(ctx.getModuleStatements().values()).effectiveSubstatements().iterator();
- assertThat(it.next(), instanceOf(NamespaceEffectiveStatement.class));
- assertThat(it.next(), instanceOf(PrefixEffectiveStatement.class));
+ assertInstanceOf(NamespaceEffectiveStatement.class, it.next());
+ assertInstanceOf(PrefixEffectiveStatement.class, it.next());
EffectiveStatement<?, ?> stmt = it.next();
- assertThat(stmt, instanceOf(DescriptionEffectiveStatement.class));
+ assertInstanceOf(DescriptionEffectiveStatement.class, stmt);
assertEquals("+something", stmt.argument());
stmt = it.next();
- assertThat(stmt, instanceOf(ContactEffectiveStatement.class));
+ assertInstanceOf(ContactEffectiveStatement.class, stmt);
assertEquals("contact++", stmt.argument());
stmt = it.next();
- assertThat(stmt, instanceOf(OrganizationEffectiveStatement.class));
+ assertInstanceOf(OrganizationEffectiveStatement.class, stmt);
assertEquals("organiza++tion", stmt.argument());
assertFoo(it.next());
}
private static void assertFoo(final EffectiveStatement<?, ?> stmt) {
- assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
+ assertInstanceOf(LeafEffectiveStatement.class, stmt);
assertEquals(QName.create("urn:foo", "foo"), stmt.argument());
final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
- assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
+ assertInstanceOf(TypeEffectiveStatement.class, it.next());
assertEquals("+", it.next().argument());
assertEquals("squotdquot", it.next().argument());
assertEquals("++", it.next().argument());
}
private static void assertBar(final EffectiveStatement<?, ?> stmt) {
- assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
+ assertInstanceOf(LeafEffectiveStatement.class, stmt);
assertEquals(QName.create("urn:foo", "bar"), stmt.argument());
final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
- assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
+ assertInstanceOf(TypeEffectiveStatement.class, it.next());
assertEquals("++", it.next().argument());
assertEquals("+ + ++", it.next().argument());
assertEquals("++ + +", it.next().argument());
}
private static void assertBaz(final EffectiveStatement<?, ?> stmt) {
- assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
+ assertInstanceOf(LeafEffectiveStatement.class, stmt);
assertEquals(QName.create("urn:foo", "baz"), stmt.argument());
final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
- assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
+ assertInstanceOf(TypeEffectiveStatement.class, it.next());
assertEquals("/", it.next().argument());
assertEquals(":", it.next().argument());
assertEquals("*", it.next().argument());
}
private static void assertXyzzy(final EffectiveStatement<?, ?> stmt) {
- assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
+ assertInstanceOf(LeafEffectiveStatement.class, stmt);
assertEquals(QName.create("urn:foo", "xyzzy"), stmt.argument());
final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
- assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
+ assertInstanceOf(TypeEffectiveStatement.class, it.next());
assertEquals("a weird concat", it.next().argument());
assertEquals("another weird concat", it.next().argument());
assertFalse(it.hasNext());
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-public class YT1133Test extends AbstractYangTest {
+class YT1133Test extends AbstractYangTest {
@Test
@SuppressWarnings("checkstyle:regexpSinglelineJava")
- public void testAugmentKeys() throws Exception {
+ void testAugmentKeys() throws Exception {
final PrintStream stdout = System.out;
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final EffectiveModelContext ctx;
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1189Test extends AbstractYangTest {
+class YT1189Test extends AbstractYangTest {
@Test
- public void testDescendantAugment() {
+ void testDescendantAugment() {
assertSourceException(startsWith("Descendant schema node identifier is not allowed when used outside"
- + " of a uses statement [at "), "/bugs/YT1189/foo.yang");
+ + " of a uses statement [at "), "/bugs/YT1189/foo.yang");
}
@Test
- public void testAbsoluteUsesAugment() {
+ void testAbsoluteUsesAugment() {
assertSourceException(startsWith("Absolute schema node identifier is not allowed when used within a"
- + " uses statement [at "), "/bugs/YT1189/bar.yang");
+ + " uses statement [at "), "/bugs/YT1189/bar.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-public class YT1195Test extends AbstractYangTest {
+class YT1195Test extends AbstractYangTest {
@Test
- public void testKeyStatementReuse() {
+ void testKeyStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1195/key.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
*/
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-public class YT1200Test extends AbstractYangTest {
+class YT1200Test extends AbstractYangTest {
private static final QName FOO = QName.create("urn:foo", "foo");
@Test
- public void testKeyParsing() {
+ 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());
+ assertInstanceOf(ListSchemaNode.class, foo).getKeyDefinition());
}
}
*/
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Relative;
import org.opendaylight.yangtools.yang.xpath.api.YangXPathAxis;
-public class YT1201Test extends AbstractYangTest {
+class YT1201Test extends AbstractYangTest {
private static final QName FOO = QName.create("foo", "foo");
private static final QName BAR = QName.create("foo", "bar");
@Test
- public void testWhenPrefixes() {
+ void testWhenPrefixes() {
final DataSchemaNode bar = assertEffectiveModelDir("/bugs/YT1201/").getDataChildByName(BAR);
- assertThat(bar, instanceOf(ContainerSchemaNode.class));
- final YangExpr when = ((ContainerSchemaNode) bar).getWhenCondition().get().getRootExpr();
- assertThat(when, instanceOf(Relative.class));
- assertEquals(List.of(YangXPathAxis.CHILD.asStep(FOO)), ((Relative) when).getSteps());
+ final YangExpr when = assertInstanceOf(ContainerSchemaNode.class, bar).getWhenCondition().orElseThrow()
+ .getRootExpr();
+ assertEquals(List.of(YangXPathAxis.CHILD.asStep(FOO)), assertInstanceOf(Relative.class, when).getSteps());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
import java.util.List;
import java.util.stream.Collectors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.stmt.AugmentEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UsesEffectiveStatement;
-public class YT1208Test extends AbstractYangTest {
+class YT1208Test extends AbstractYangTest {
@Test
- public void testAugmentStatementReuse() {
+ void testAugmentStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/augment.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
}
@Test
- public void testCaseStatementReuse() {
+ void testCaseStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/case.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
}
@Test
- public void testChoiceStatementReuse() {
+ void testChoiceStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/choice.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
}
@Test
- public void testGroupingStatementReuse() {
+ void testGroupingStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/grouping.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
}
@Test
- public void testLeafStatementReuse() {
+ void testLeafStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/leaf.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
assertNotNull(module);
}
@Test
- public void testLeafListStatementReuse() {
+ void testLeafListStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/leaflist.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
}
@Test
- public void testListStatementReuse() {
+ void testListStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/list.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
}
@Test
- public void testTypedefStatementReuse() {
+ void testTypedefStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/typedef.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
}
@Test
- public void testUsesStatementReuse() {
+ void testUsesStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/uses.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
assertNotNull(module);
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.WhenEffectiveStatement;
-public class YT1209Test extends AbstractYangTest {
+class YT1209Test extends AbstractYangTest {
@Test
- public void testWhenStatementReuse() {
+ void testWhenStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1209/when.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
import java.util.List;
import java.util.stream.Collectors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
-public class YT1212Test extends AbstractYangTest {
+class YT1212Test extends AbstractYangTest {
@Test
- public void testActiontatementReuse() {
+ void testActiontatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1212/anyxml.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
}
@Test
- public void testLeafStatementReuse() {
+ void testLeafStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1212/leaf.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
}
@Test
- public void testContainerStatementReuse() {
+ void testContainerStatementReuse() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1212/container.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefAwareEffectiveStatement;
-public class YT1262Test extends AbstractYangTest {
+class YT1262Test extends AbstractYangTest {
@Test
- public void testTypedefNamespaces() {
+ void testTypedefNamespaces() {
final var modelContext = assertEffectiveModelDir("/bugs/YT1262");
final var module = modelContext.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
assertTypedef(module, "fdef");
}
private static void assertTypedef(final EffectiveStatement<?, ?> parent, final String typedefName) {
- assertThat(parent, instanceOf(TypedefAwareEffectiveStatement.class));
- assertTrue(((TypedefAwareEffectiveStatement<?, ?>) parent).findTypedef(QName.create("foo", typedefName))
- .isPresent());
+ assertTrue(assertInstanceOf(TypedefAwareEffectiveStatement.class, parent)
+ .findTypedef(QName.create("foo", typedefName)).isPresent());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.stmt.DefaultEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-public class YT1312Test extends AbstractYangTest {
+class YT1312Test extends AbstractYangTest {
@Test
- public void testRefineDefault() {
+ void testRefineDefault() {
final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1312/foo.yang")
.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.parser.spi.source.YangVersionLinkageException;
* Tests for {@code MUST NOT} statements around include/import interop of RFC6020 and RFC7950, as per
* <a href="https://datatracker.ietf.org/doc/html/rfc7950#section-12">RFC7950 section 12</a>.
*/
-public class YT1339Test extends AbstractYangTest {
+class YT1339Test extends AbstractYangTest {
@Test
- public void testInclude() {
+ void testInclude() {
// A YANG version 1.1 module MUST NOT include a YANG version 1 submodule,
assertFailedInclude("old-sub", YangVersion.VERSION_1, YangVersion.VERSION_1_1);
// ... and a YANG version 1 module MUST NOT include a YANG version 1.1 submodule
}
@Test
- public void testImportNewByRev() {
+ void testImportNewByRev() {
// A YANG version 1 module or submodule MUST NOT import a YANG version 1.1 module by revision.
assertFailedImport("import-rev");
assertFailedImport("import-rev-sub");
}
@Test
- public void testImportOldByRev() {
+ void testImportOldByRev() {
// A YANG version 1.1 module or submodule MAY import a YANG version 1 module by revision.
assertEffectiveModelDir("/bugs/YT1339/import");
}
@Test
- public void testImportNoRev() {
+ void testImportNoRev() {
// no language forbidding imports without revision
assertEffectiveModelDir("/bugs/YT1339/import-norev");
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1346Test extends AbstractYangTest {
+class YT1346Test extends AbstractYangTest {
@Test
- public void testUsesAugmentUsesException() {
+ void testUsesAugmentUsesException() {
assertEffectiveModel("/bugs/YT1346/foo.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-public class YT1370Test {
+class YT1370Test {
@Test
- public void testAugmentUnsupportedByFeatures() throws Exception {
+ void testAugmentUnsupportedByFeatures() throws Exception {
assertNotNull(StmtTestUtils.parseYangSources("/bugs/YT1370", Set.of(), YangParserConfiguration.DEFAULT));
}
}
*/
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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement;
-public class YT1383Test extends AbstractYangTest {
+class YT1383Test extends AbstractYangTest {
@Test
- public void testDeclaredImplicitCase() {
+ void testDeclaredImplicitCase() {
final var foo = assertEffectiveModel("/bugs/YT1383/foo.yang").getModuleStatements().values().iterator()
.next().findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow();
final var effStatements = foo.effectiveSubstatements();
assertEquals(2, effStatements.size());
final var bar = effStatements.get(0);
- assertThat(bar, instanceOf(CaseEffectiveStatement.class));
+ assertInstanceOf(CaseEffectiveStatement.class, bar);
assertNotNull(bar.getDeclared());
final var baz = effStatements.get(1);
- assertThat(baz, instanceOf(CaseEffectiveStatement.class));
+ assertInstanceOf(CaseEffectiveStatement.class, baz);
assertNull(baz.getDeclared());
// Declared view of things
final var declStatements = fooDecl.declaredSubstatements();
assertEquals(2, declStatements.size());
final var barDecl = declStatements.get(0);
- assertThat(barDecl, instanceOf(CaseStatement.class));
+ assertInstanceOf(CaseStatement.class, barDecl);
final var bazDecl = declStatements.get(1);
- assertThat(bazDecl, instanceOf(ContainerStatement.class));
+ assertInstanceOf(ContainerStatement.class, bazDecl);
}
}
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1385Test extends AbstractYangTest {
+class YT1385Test extends AbstractYangTest {
@Test
- public void testSameModuleWrongUnique() {
+ void testSameModuleWrongUnique() {
assertSourceException(allOf(
startsWith("Following components of unique statement argument refer to non-existent nodes: "
+ "[Descendant{qnames=[(foo)bar]}] [at "),
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
-public class YT1393Test {
+class YT1393Test {
@Test
- public void testUsesAugmentUnsupportedByFeatures() throws Exception {
+ void testUsesAugmentUnsupportedByFeatures() throws Exception {
final var module = StmtTestUtils.parseYangSource("/bugs/YT1393/foo.yang", Set.of())
.findModuleStatement(QName.create("foo", "foo"))
.orElseThrow();
}
@Test
- public void testUsesRefineUnsupportedByFeatures() throws Exception {
+ void testUsesRefineUnsupportedByFeatures() throws Exception {
final var module = StmtTestUtils.parseYangSource("/bugs/YT1393/bar.yang", Set.of())
.findModuleStatement(QName.create("bar", "bar"))
.orElseThrow();
}
@Test
- public void testAugmentAugmentUnsupportedByFeatures() throws Exception {
+ void testAugmentAugmentUnsupportedByFeatures() throws Exception {
final var module = StmtTestUtils.parseYangSource("/bugs/YT1393/baz.yang", Set.of())
.findModuleStatement(QName.create("baz", "baz"))
.orElseThrow();
}
@Test
- public void testUsesAugmentInUnsupportedByFeatures() throws Exception {
+ void testUsesAugmentInUnsupportedByFeatures() throws Exception {
final var module = StmtTestUtils.parseYangSource("/bugs/YT1393/xyzzy.yang", Set.of())
.findModuleStatement(QName.create("xyzzy", "xyzzy"))
.orElseThrow();
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1407Test extends AbstractYangTest {
+class YT1407Test extends AbstractYangTest {
@Test
- public void testUsedUndeclaredCase() {
+ void testUsedUndeclaredCase() {
assertEffectiveModelDir("/bugs/YT1407");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1408Test extends AbstractYangTest {
+class YT1408Test extends AbstractYangTest {
@Test
- public void testChoiceCaseDeviateCase() {
+ void testChoiceCaseDeviateCase() {
assertEffectiveModelDir("/bugs/YT1408/choice-case-deviate-case");
}
@Test
- public void testChoiceDeviateCase() {
+ void testChoiceDeviateCase() {
assertEffectiveModelDir("/bugs/YT1408/choice-deviate-case");
}
@Test
- public void testAugmentChoiceCaseDeviateCase() {
+ void testAugmentChoiceCaseDeviateCase() {
assertEffectiveModelDir("/bugs/YT1408/aug-choice-case-deviate-case");
}
@Test
- public void testAugmentChoiceDeviateCase() {
+ void testAugmentChoiceDeviateCase() {
assertEffectiveModelDir("/bugs/YT1408/aug-choice-deviate-case");
}
}
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
-public class YT1410Test extends AbstractYangTest {
+class YT1410Test extends AbstractYangTest {
@Test
- public void testRFC6020() {
+ void testRFC6020() {
assertInvalidSubstatementException(
startsWith("CHOICE is not valid for CHOICE. Error in module foo (QNameModule{ns=foo}) [at "),
"/bugs/YT1410/foo.yang");
}
@Test
- public void testRFC7950() {
+ void testRFC7950() {
final var module = assertEffectiveModel("/bugs/YT1410/bar.yang").getModuleStatement(QName.create("bar", "bar"));
final var one = module.findSchemaTreeNode(QName.create("bar", "one")).orElseThrow();
- assertThat(one, instanceOf(ChoiceEffectiveStatement.class));
+ assertInstanceOf(ChoiceEffectiveStatement.class, one);
final var two = ((ChoiceEffectiveStatement) one).findSchemaTreeNode(QName.create("bar", "two")).orElseThrow();
- assertThat(two, instanceOf(CaseEffectiveStatement.class));
+ assertInstanceOf(CaseEffectiveStatement.class, two);
assertThat(((CaseEffectiveStatement) two).findSchemaTreeNode(QName.create("bar", "two")).orElseThrow(),
instanceOf(ChoiceEffectiveStatement.class));
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
-public class YT1431Test {
+class YT1431Test {
@Test
- public void testUnsupportedChoiceLeaf() throws Exception {
+ void testUnsupportedChoiceLeaf() throws Exception {
final var module = StmtTestUtils.parseYangSource("/bugs/YT1431/foo.yang", Set.of())
.findModuleStatement(QName.create("foo", "foo"))
.orElseThrow();
}
@Test
- public void testUnsupportedChoiceLeafAugment() throws Exception {
+ void testUnsupportedChoiceLeafAugment() throws Exception {
final var module = StmtTestUtils.parseYangSource("/bugs/YT1431/bar.yang", Set.of())
.findModuleStatement(QName.create("bar", "bar"))
.orElseThrow();
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1434Test extends AbstractYangTest {
+class YT1434Test extends AbstractYangTest {
@Test
- public void testUniqueViaAugment() {
+ void testUniqueViaAugment() {
assertEffectiveModel("/bugs/YT1434/foo.yang");
}
@Test
- public void testUniqueViaUses() {
+ void testUniqueViaUses() {
assertEffectiveModel("/bugs/YT1434/bar.yang");
}
@Test
- public void testUniqueViaSubmoduleUses() {
+ void testUniqueViaSubmoduleUses() {
assertEffectiveModel("/bugs/YT1434/main-module.yang", "/bugs/YT1434/submodule.yang",
- "/bugs/YT1434/test-bug.yang");
+ "/bugs/YT1434/test-bug.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1436Test extends AbstractYangTest {
+class YT1436Test extends AbstractYangTest {
@Test
- public void testUniqueLeafFromOtherSubmodule() {
+ void testUniqueLeafFromOtherSubmodule() {
assertEffectiveModelDir("/bugs/YT1436/unique");
}
@Test
- public void testAugmentGroupingFromOtherSubmodule() {
+ void testAugmentGroupingFromOtherSubmodule() {
assertEffectiveModelDir("/bugs/YT1436/augment");
}
}
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1441Test extends AbstractYangTest {
+class YT1441Test extends AbstractYangTest {
@Test
- public void testInvalidRange() {
+ void testInvalidRange() {
assertSourceException(startsWith(
"Range constraint does not match fraction-digits: Decreasing scale of 2.345 to 2 requires rounding [at "),
"/bugs/YT1441/foo.yang");
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1445Test extends AbstractYangTest {
+class YT1445Test extends AbstractYangTest {
@Test
- public void testUniqueTopLevelGrouping() {
+ void testUniqueTopLevelGrouping() {
assertEffectiveModel("/bugs/YT1445/top-level-grouping/foo.yang");
}
@Test
- public void testUniqueInListGrouping() {
+ void testUniqueInListGrouping() {
assertEffectiveModel("/bugs/YT1445/list-grouping/foo.yang");
}
@Test
- public void testUniqueInGroupingUsedByGrouping() {
+ void testUniqueInGroupingUsedByGrouping() {
assertEffectiveModel("/bugs/YT1445/nested-grouping/foo.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.stmt;
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
-
-public class YT1448Test extends AbstractYangTest {
+import org.junit.jupiter.api.Test;
+class YT1448Test extends AbstractYangTest {
@Test
- public void deviationFromSubmodule() {
+ void deviationFromSubmodule() {
assertEffectiveModelDir("/bugs/YT1448/valid");
}
@Test
- public void deviationFromSubmoduleTargetedOwnModule() {
+ void deviationFromSubmoduleTargetedOwnModule() {
assertInferenceExceptionDir("/bugs/YT1448/invalid",
- startsWith("Deviation must not target the same module as the one it is defined in"));
+ startsWith("Deviation must not target the same module as the one it is defined in"));
}
}
*/
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
-public class YT1465Test extends AbstractYangTest {
+class YT1465Test extends AbstractYangTest {
@Test
- public void supportedLeafInChoiceAugment() throws Exception {
+ void supportedLeafInChoiceAugment() throws Exception {
final var baz = assertBaz(StmtTestUtils.parseYangSource("/bugs/YT1465/foo.yang", null));
final var schemas = baz.schemaTreeNodes();
assertEquals(2, schemas.size());
final var it = schemas.iterator();
- final var first = it.next();
- assertThat(first, instanceOf(CaseEffectiveStatement.class));
+ final var first = assertInstanceOf(CaseEffectiveStatement.class, it.next());
assertEquals(QName.create("foo", "one"), first.argument());
- final var second = it.next();
- assertThat(second, instanceOf(CaseEffectiveStatement.class));
+ final var second = assertInstanceOf(CaseEffectiveStatement.class, it.next());
assertEquals(QName.create("foo", "two"), second.argument());
}
@Test
- public void unsupportedLeafInChoiceAugment() throws Exception {
+ void unsupportedLeafInChoiceAugment() throws Exception {
final var baz = assertBaz(StmtTestUtils.parseYangSource("/bugs/YT1465/foo.yang", Set.of()));
final var schemas = baz.schemaTreeNodes();
assertEquals(1, schemas.size());
- final var first = schemas.iterator().next();
- assertThat(first, instanceOf(CaseEffectiveStatement.class));
+ final var first = assertInstanceOf(CaseEffectiveStatement.class, schemas.iterator().next());
assertEquals(QName.create("foo", "one"), first.argument());
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT1470Test extends AbstractYangTest {
+class YT1470Test extends AbstractYangTest {
@Test
- public void testUniqueInAugmentedList() {
+ void testUniqueInAugmentedList() {
assertEffectiveModelDir("/bugs/YT1470");
}
}
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UsesEffectiveStatement;
-public class YT1471Test extends AbstractYangTest {
+class YT1471Test extends AbstractYangTest {
private static final QName FOO = QName.create("urn:foo", "foo");
private static final QName BAR = QName.create("urn:foo", "bar");
private static final QName BAZ = QName.create("urn:foo", "baz");
private static final QName BAZ_LEAF = QName.create("urn:foo", "baz-leaf");
@Test
- public void testAugmentSingleGroupingWithFeatureSupported() {
+ void testAugmentSingleGroupingWithFeatureSupported() {
assertSupportedFoo("single");
}
@Test
- public void testAugmentSingleGroupingWithFeatureNotSupported() {
+ void testAugmentSingleGroupingWithFeatureNotSupported() {
assertEquals(List.of(), assertFoo("single", Set.of()).effectiveSubstatements());
}
@Test
- public void testAugmentNestedGroupingWithFeatureSupported() {
+ void testAugmentNestedGroupingWithFeatureSupported() {
assertSupportedFoo("nested");
}
@Test
- public void testAugmentNestedGroupingWithFeatureNotSupported() {
+ void testAugmentNestedGroupingWithFeatureNotSupported() {
assertThat(assertFoo("nested", Set.of()).effectiveSubstatements(),
contains(instanceOf(UsesEffectiveStatement.class)));
}
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT838Test extends AbstractYangTest {
+class YT838Test extends AbstractYangTest {
@Test
- public void testGroupingShadowing() {
+ void testGroupingShadowing() {
testGrouping("grouping.yang");
}
@Test
- public void testGroupingPostShadowing() {
+ void testGroupingPostShadowing() {
testGrouping("grouping-post.yang");
}
@Test
- public void testTypedefShadowing() {
+ void testTypedefShadowing() {
testTypedef("typedef.yang");
}
@Test
- public void testTypedefPostShadowing() {
+ void testTypedefPostShadowing() {
testTypedef("typedef-post.yang");
}
private static void testGrouping(final String model) {
assertSourceException(startsWith("Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "),
- "/bugs/YT838/" + model);
+ "/bugs/YT838/" + model);
}
private static void testTypedef(final String model) {
assertSourceException(startsWith("Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "),
- "/bugs/YT838/" + model);
+ "/bugs/YT838/" + model);
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
-public class YT841Test extends AbstractYangTest {
+class YT841Test extends AbstractYangTest {
private static final QName FOO = QName.create("foo", "2018-01-02", "foo");
@Test
- public void testFindDataSchemaNode() throws Exception {
+ void testFindDataSchemaNode() throws Exception {
final SchemaTreeEffectiveStatement<?> input = assertEffectiveModelDir("/bugs/YT841/")
.getModuleStatement(FOO)
.findSchemaTreeNode(FOO, FOO, FOO, QName.create(FOO, "input"))
.orElse(null);
- assertThat(input, instanceOf(InputEffectiveStatement.class));
+ assertInstanceOf(InputEffectiveStatement.class, input);
}
}
import static org.hamcrest.Matchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT857Test extends AbstractYangTest {
+class YT857Test extends AbstractYangTest {
@Test
- public void testConflictDetection() {
+ void testConflictDetection() {
assertSourceException(startsWith("Cannot add data tree child with name (foo)one, a conflicting"
- + " child already exists"), "/bugs/YT857/foo.yang");
+ + " child already exists"), "/bugs/YT857/foo.yang");
}
}
*/
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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
import com.google.common.collect.Iterables;
-import java.util.Optional;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-public class YT859Test {
+class YT859Test {
@Test
- public void testAugmentUnsupported() throws Exception {
+ void testAugmentUnsupported() throws Exception {
final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/YT859/", Set.of(),
YangParserConfiguration.DEFAULT);
assertEquals(4, context.getModules().size());
final DataSchemaNode named = Iterables.getOnlyElement(context.findModules("xyzzy"))
.findDataChildByName(QName.create("xyzzy", "xyzzy"), QName.create("xyzzy", "named")).orElseThrow();
- assertThat(named, instanceOf(ListSchemaNode.class));
- assertEquals(Optional.empty(), ((ListSchemaNode) named).findDataChildByName(QName.create("foo", "foo")));
+ assertNull(assertInstanceOf(ListSchemaNode.class, named).dataChildByName(QName.create("foo", "foo")));
}
}
import static org.hamcrest.CoreMatchers.startsWith;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class YT893Test extends AbstractYangTest {
+class YT893Test extends AbstractYangTest {
@Test
- public void testCR() {
+ void testCR() {
assertSourceException(startsWith("Failed to parse node"), "/bugs/YT893/cr.yang");
}
@Test
- public void testCRLF() {
+ void testCRLF() {
assertEffectiveModel("/bugs/YT893/crlf.yang");
}
@Test
- public void testHTAB() {
+ void testHTAB() {
assertEffectiveModel("/bugs/YT893/ht.yang");
}
@Test
- public void testLF() {
+ void testLF() {
assertEffectiveModel("/bugs/YT893/lf.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-public class YT911Test extends AbstractYangTest {
+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() {
+ void testAugmentationConfig() {
final var context = assertEffectiveModel("/bugs/YT911/foo.yang");
- final DataSchemaNode foo = context.findDataChildByName(FOO).get();
+ final var foo = assertInstanceOf(ContainerSchemaNode.class, context.dataChildByName(FOO));
assertEquals(Optional.of(Boolean.FALSE), foo.effectiveConfig());
- assertTrue(foo instanceof ContainerSchemaNode);
// Instantiated node
- final DataSchemaNode bar = ((ContainerSchemaNode) foo).findDataTreeChild(BAR).get();
+ final DataSchemaNode bar = foo.findDataTreeChild(BAR).orElseThrow();
assertEquals(Optional.of(Boolean.FALSE), bar.effectiveConfig());
- assertTrue(foo instanceof ContainerSchemaNode);
// Original augmentation node
- final AugmentationSchemaNode aug = ((ContainerSchemaNode) foo).getAvailableAugmentations().iterator().next();
- final DataSchemaNode augBar = aug.findDataTreeChild(BAR).get();
+ final AugmentationSchemaNode aug = foo.getAvailableAugmentations().iterator().next();
+ final DataSchemaNode augBar = aug.findDataTreeChild(BAR).orElseThrow();
assertEquals(Optional.empty(), augBar.effectiveConfig());
- assertTrue(foo instanceof ContainerSchemaNode);
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-public class YT956Test extends AbstractYangTest {
+class YT956Test extends AbstractYangTest {
private static final QName ANOTHER_CONTAINER = QName.create("http://www.example.com/anothermodule",
"another-container");
private static final QName FIRST_AUGMENT = QName.create("http://www.example.com/mainmodule", "first-augment");
@Test
- public void testAugmentationConditional() {
- final DataSchemaNode another = assertEffectiveModelDir("/bugs/YT956/")
- .getDataChildByName(ANOTHER_CONTAINER);
- assertThat(another, isA(ContainerSchemaNode.class));
- final ContainerSchemaNode anotherContainer = (ContainerSchemaNode) another;
+ void testAugmentationConditional() {
+ final var another = assertEffectiveModelDir("/bugs/YT956/").getDataChildByName(ANOTHER_CONTAINER);
+ final var anotherContainer = assertInstanceOf(ContainerSchemaNode.class, another);
- final DataSchemaNode first = anotherContainer.findDataChildByName(FIRST_AUGMENT).get();
- assertThat(first, isA(ContainerSchemaNode.class));
- final ContainerSchemaNode firstAugment = (ContainerSchemaNode) first;
+ final var first = anotherContainer.findDataChildByName(FIRST_AUGMENT).get();
+ final var firstAugment = assertInstanceOf(ContainerSchemaNode.class, first);
// Augmentation needs to be added
assertEquals(3, firstAugment.getChildNodes().size());
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
-public class YT971Test extends AbstractYangTest {
+class YT971Test extends AbstractYangTest {
private static final QNameModule NAMESPACE = QNameModule.create(XMLNamespace.of("test"), Revision.of("2019-03-25"));
@Test
- public void testEscapeLexer() {
+ void testEscapeLexer() {
final var context = assertEffectiveModel("/bugs/YT971/test.yang");
final DataSchemaNode someContainer = context.getDataChildByName(
QName.create(NAMESPACE, "some-container"));
- assertThat(someContainer, instanceOf(ContainerSchemaNode.class));
- final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) someContainer;
-
+ final ContainerSchemaNode containerSchemaNode = assertInstanceOf(ContainerSchemaNode.class, someContainer);
final DataSchemaNode someLeaf = containerSchemaNode.getDataChildByName(QName.create(NAMESPACE, "some-leaf"));
- assertThat(someLeaf, instanceOf(LeafSchemaNode.class));
- final LeafSchemaNode leafSchemaNode = (LeafSchemaNode) someLeaf;
+ final LeafSchemaNode leafSchemaNode = assertInstanceOf(LeafSchemaNode.class, someLeaf);
assertEquals(Optional.of("Some string that ends with a backslash (with escape backslash too) \\"),
- leafSchemaNode.getDescription());
- assertThat(leafSchemaNode.getType(), instanceOf(Int16TypeDefinition.class));
+ leafSchemaNode.getDescription());
+ assertInstanceOf(Int16TypeDefinition.class, leafSchemaNode.getType());
final DataSchemaNode someOtherLeaf = containerSchemaNode.getDataChildByName(
QName.create(NAMESPACE, "some-other-leaf"));
- assertThat(someOtherLeaf, instanceOf(LeafSchemaNode.class));
- final LeafSchemaNode otherLeafSchemaNode = (LeafSchemaNode) someOtherLeaf;
+ final LeafSchemaNode otherLeafSchemaNode = assertInstanceOf(LeafSchemaNode.class, someOtherLeaf);
assertEquals(Optional.of("Some string after the double backslash"), otherLeafSchemaNode.getDescription());
- assertThat(otherLeafSchemaNode.getType(), instanceOf(Int32TypeDefinition.class));
+ assertInstanceOf(Int32TypeDefinition.class, otherLeafSchemaNode.getType());
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-public class YT983Test extends AbstractYangTest {
+class YT983Test extends AbstractYangTest {
private static final QName FOO = QName.create("foo", "2019-04-30", "foo");
@Test
- public void testAugmentationConfig() {
+ void testAugmentationConfig() {
final var context = assertEffectiveModel("/bugs/YT983/foo.yang");
- final DataSchemaNode foo = context.findDataChildByName(FOO).get();
- assertTrue(foo instanceof LeafSchemaNode);
+ assertInstanceOf(LeafSchemaNode.class, context.getDataChildByName(FOO));
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
-
-public class YangFileStmtTest {
- //basic statements to parse and write
- private static final StatementStreamSource YANGFILE = sourceForResource("/semantic-statement-parser/test.yang");
- private static final StatementStreamSource IMPORTEDYANGFILE = sourceForResource(
- "/semantic-statement-parser/importedtest.yang");
- private static final StatementStreamSource SIMPLENODES = sourceForResource(
- "/semantic-statement-parser/simple-nodes-semantic.yang");
- private static final StatementStreamSource FOOBAR = sourceForResource("/semantic-statement-parser/foobar.yang");
- //extension statement to parse and write
- private static final StatementStreamSource EXTFILE = sourceForResource(
- "/semantic-statement-parser/ext-typedef.yang");
- private static final StatementStreamSource EXTUSE = sourceForResource("/semantic-statement-parser/ext-use.yang");
-
+class YangFileStmtTest extends AbstractYangTest {
private static final StatementStreamSource BAR = sourceForResource("/model-new/bar.yang");
private static final StatementStreamSource BAZ = sourceForResource("/model-new/baz.yang");
private static final StatementStreamSource FOO = sourceForResource("/model-new/foo.yang");
private static final StatementStreamSource SUBFOO2 = sourceForResource("/model/subfoo.yang");
@Test
- public void readAndParseYangFileTestModel() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(BAZ, FOO, BAR, SUBFOO)
- .build();
- assertNotNull(result);
+ void readAndParseYangFileTestModel() throws ReactorException {
+ assertNotNull(RFC7950Reactors.defaultReactor().newBuild().addSources(BAZ, FOO, BAR, SUBFOO).build());
}
@Test
- public void readAndParseYangFileTestModel2() throws ReactorException {
- ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(BAZ2, FOO2, BAR2, SUBFOO2)
- .build();
- assertNotNull(result);
+ void readAndParseYangFileTestModel2() throws ReactorException {
+ assertNotNull(RFC7950Reactors.defaultReactor().newBuild().addSources(BAZ2, FOO2, BAR2, SUBFOO2).build());
}
@Test
- public void readAndParseYangFileTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(YANGFILE, SIMPLENODES, IMPORTEDYANGFILE, FOOBAR, EXTFILE, EXTUSE)
- .buildEffective();
- assertNotNull(result);
+ void readAndParseYangFileTest() {
+ assertEffectiveModel(
+ //basic statements to parse and write
+ "/semantic-statement-parser/test.yang",
+ "/semantic-statement-parser/simple-nodes-semantic.yang",
+ "/semantic-statement-parser/importedtest.yang",
+ "/semantic-statement-parser/foobar.yang",
+ //extension statement to parse and write
+ "/semantic-statement-parser/ext-typedef.yang",
+ "/semantic-statement-parser/ext-use.yang");
}
}
\ No newline at end of file
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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-public class YangParserIdentityTest extends AbstractYangTest {
+class YangParserIdentityTest extends AbstractYangTest {
// base identity name equals identity name
@Test
- public void testParsingIdentityTestModule() {
+ void testParsingIdentityTestModule() {
assertInferenceException(startsWith("Unable to resolve identity (urn:test.identitytest?revision="
- + "2014-09-17)test and base identity"), "/identity/identitytest.yang");
+ + "2014-09-17)test and base identity"), "/identity/identitytest.yang");
}
// same module prefixed base identity name equals identity name
@Test
- public void testParsingPrefixIdentityTestModule() {
+ void testParsingPrefixIdentityTestModule() {
assertInferenceException(startsWith("Unable to resolve identity (urn:test.prefixidentitytest?revision="
- + "2014-09-24)prefixtest and base identity"), "/identity/prefixidentitytest.yang");
+ + "2014-09-24)prefixtest and base identity"), "/identity/prefixidentitytest.yang");
}
// imported module prefixed base identity name equals identity name, but
// prefix differs
@Test
- public void testParsingImportPrefixIdentityTestModule() {
+ void testParsingImportPrefixIdentityTestModule() {
final var module = assertEffectiveModelDir("/identity/import").findModules("prefiximportidentitytest")
.iterator().next();
final var imports = module.getImports();
- assertEquals(imports.size(), 1);
+ assertEquals(1, imports.size());
ModuleImport dummy = TestUtils.findImport(imports, "dummy");
assertNotEquals(dummy.getPrefix(), module.getPrefix());
}
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertThrows;
-import com.google.common.base.Throwables;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.junit.jupiter.api.Test;
-public class YangParserNegativeTest {
+class YangParserNegativeTest extends AbstractYangTest {
@Test
- public void testInvalidImport() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource("/negative-scenario/testfile1.yang"));
-
- final Throwable rootCause = Throwables.getRootCause(ex);
- assertThat(rootCause, isA(InferenceException.class));
- assertThat(rootCause.getMessage(), startsWith("Imported module"));
- assertThat(rootCause.getMessage(), containsString("was not found."));
+ void testInvalidImport() {
+ assertInferenceException(allOf(startsWith("Imported module"), containsString("was not found.")),
+ "/negative-scenario/testfile1.yang");
}
@Test
- public void testTypeNotFound() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource("/negative-scenario/testfile2.yang"));
- final Throwable rootCause = Throwables.getRootCause(ex);
- assertThat(rootCause, isA(InferenceException.class));
- assertThat(rootCause.getMessage(),
- startsWith("Type [(urn:simple.types.data.demo?revision=2013-02-27)int-ext] was not found."));
+ void testTypeNotFound() {
+ assertInferenceException(
+ startsWith("Type [(urn:simple.types.data.demo?revision=2013-02-27)int-ext] was not found."),
+ "/negative-scenario/testfile2.yang");
}
@Test
- public void testInvalidAugmentTarget() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource(
- "/negative-scenario/testfile0.yang", "/negative-scenario/testfile3.yang"));
- final Throwable rootCause = Throwables.getRootCause(ex);
- assertThat(rootCause, isA(InferenceException.class));
- assertThat(rootCause.getMessage(), startsWith(
- "Augment target 'Absolute{qnames=[(urn:simple.container.demo)unknown]}' not found"));
+ void testInvalidAugmentTarget() {
+ assertInferenceException(
+ startsWith("Augment target 'Absolute{qnames=[(urn:simple.container.demo)unknown]}' not found"),
+ "/negative-scenario/testfile0.yang", "/negative-scenario/testfile3.yang");
}
@Test
- public void testInvalidRefine() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> 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 "
+ void testInvalidRefine() {
+ assertSourceException(
+ containsString("Error in module 'test4' in the refine of uses "
+ "'Descendant{qnames=[(urn:simple.container.demo)node]}': can not perform refine of 'PRESENCE' for"
- + " the target 'LEAF_LIST'."));
+ + " the target 'LEAF_LIST'."),
+ "/negative-scenario/testfile4.yang");
}
@Test
- public void testInvalidLength() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> 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]"));
+ void testInvalidLength() {
+ assertSourceException(startsWith("Invalid length constraint [4..10]"),
+ "/negative-scenario/testfile5.yang");
}
@Test
- public void testInvalidRange() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource("/negative-scenario/testfile6.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, isA(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Invalid range constraint: [[5..20]]"));
+ void testInvalidRange() {
+ assertSourceException(startsWith("Invalid range constraint: [[5..20]]"),
+ "/negative-scenario/testfile6.yang");
}
@Test
- public void testDuplicateContainer() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource("/negative-scenario/duplicity/container.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, isA(SourceException.class));
- assertThat(cause.getMessage(), containsString("Error in module 'container': cannot add "
+ void testDuplicateContainer() {
+ assertSourceException(startsWith("Error in module 'container': cannot add "
+ "'(urn:simple.container.demo)foo'. Node name collision: '(urn:simple.container.demo)foo' already "
- + "declared"));
+ + "declared"),
+ "/negative-scenario/duplicity/container.yang");
}
@Test
- public void testDuplicateContainerList() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource("/negative-scenario/duplicity/container-list.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, isA(SourceException.class));
- assertThat(cause.getMessage(), containsString("Error in module 'container-list': cannot add "
+ void testDuplicateContainerList() {
+ assertSourceException(startsWith("Error in module 'container-list': cannot add "
+ "'(urn:simple.container.demo)foo'. Node name collision: '(urn:simple.container.demo)foo' already "
- + "declared"));
+ + "declared"),
+ "/negative-scenario/duplicity/container-list.yang");
}
@Test
- public void testDuplicateContainerLeaf() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource("/negative-scenario/duplicity/container-leaf.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, isA(SourceException.class));
- assertThat(cause.getMessage(), containsString("Error in module 'container-leaf': cannot add "
+ void testDuplicateContainerLeaf() {
+ assertSourceException(startsWith("Error in module 'container-leaf': cannot add "
+ "'(urn:simple.container.demo)foo'. Node name collision: '(urn:simple.container.demo)foo' already "
- + "declared"));
+ + "declared"),
+ "/negative-scenario/duplicity/container-leaf.yang");
}
@Test
- public void testDuplicateTypedef() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource("/negative-scenario/duplicity/typedef.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, isA(SourceException.class));
- assertThat(cause.getMessage(), startsWith(
- "Duplicate name for typedef (urn:simple.container.demo)int-ext [at"));
+ void testDuplicateTypedef() {
+ assertSourceException(
+ startsWith("Duplicate name for typedef (urn:simple.container.demo)int-ext [at"),
+ "/negative-scenario/duplicity/typedef.yang");
}
@Test
- public void testDuplicityInAugmentTarget1() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource(
- "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment1.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, isA(InferenceException.class));
- assertThat(cause.getMessage(), startsWith(
- "An augment cannot add node named 'id' because this name is already used in target"));
+ void testDuplicityInAugmentTarget1() {
+ assertInferenceException(
+ startsWith("An augment cannot add node named 'id' because this name is already used in target"),
+ "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment1.yang");
}
@Test
- public void testDuplicityInAugmentTarget2() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource(
- "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment2.yang"));
- final Throwable rootCause = Throwables.getRootCause(ex);
- assertThat(rootCause, isA(SourceException.class));
- assertThat(rootCause.getMessage(), allOf(
+ void testDuplicityInAugmentTarget2() {
+ assertSourceException(allOf(
startsWith("Error in module 'augment0': cannot add "
+ "'(urn:simple.augment2.demo?revision=2014-06-02)delta'. Node name collision: "
+ "'(urn:simple.augment2.demo?revision=2014-06-02)delta' already declared at "),
- endsWith("duplicity/augment2.yang:17:9]")));
+ endsWith("duplicity/augment2.yang:17:9]")),
+ "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment2.yang");
}
@Test
- public void testMandatoryInAugment() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource(
- "/negative-scenario/testfile8.yang", "/negative-scenario/testfile7.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, isA(InferenceException.class));
- assertThat(cause.getMessage(), startsWith(
- "An augment cannot add node 'linkleaf' because it is mandatory and in module different than target"));
+ void testMandatoryInAugment() {
+ assertInferenceException(startsWith(
+ "An augment cannot add node 'linkleaf' because it is mandatory and in module different than target"),
+ "/negative-scenario/testfile8.yang", "/negative-scenario/testfile7.yang");
}
@Test
- public void testInvalidListKeyDefinition() {
- final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource("/negative-scenario/invalid-list-key-def.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, isA(InferenceException.class));
- assertThat(cause.getMessage(), startsWith(
- "Key 'rib-id' misses node 'rib-id' in list '(invalid:list:key:def)application-map'"));
+ void testInvalidListKeyDefinition() {
+ assertInferenceException(startsWith(
+ "Key 'rib-id' misses node 'rib-id' in list '(invalid:list:key:def)application-map'"),
+ "/negative-scenario/invalid-list-key-def.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
import java.util.Optional;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
-public class YangParserSimpleTest extends AbstractYangTest {
+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 Module MODULE;
- @BeforeClass
- public static void beforeClass() throws Exception {
+ @BeforeAll
+ static void beforeClass() throws Exception {
MODULE = assertEffectiveModelDir("/simple-test").findModules("simple-nodes").iterator().next();
}
@Test
- public void testParseAnyXml() {
+ void testParseAnyXml() {
final AnyxmlSchemaNode data = (AnyxmlSchemaNode) MODULE.getDataChildByName(
QName.create(MODULE.getQNameModule(), "data"));
- assertFalse(data.equals(null));
+ assertNotEquals(null, data);
assertEquals(
"RegularAnyxmlEffectiveStatement{argument=(urn:opendaylight:simple-nodes?revision=2013-07-30)data}",
data.toString());
}
@Test
- public void testParseAnyData() {
+ void testParseAnyData() {
final AnydataSchemaNode anydata = (AnydataSchemaNode) MODULE.findDataChildByName(
- QName.create(MODULE.getQNameModule(), "data2")).orElse(null);
+ QName.create(MODULE.getQNameModule(), "data2")).orElse(null);
- assertNotNull("'anydata data not found'", anydata);
+ assertNotNull(anydata, "'anydata data not found'");
assertEquals(
"RegularAnydataEffectiveStatement{argument=(urn:opendaylight:simple-nodes?revision=2013-07-30)data2}",
anydata.toString());
}
@Test
- public void testParseContainer() {
+ void testParseContainer() {
final ContainerSchemaNode nodes = (ContainerSchemaNode) MODULE
- .getDataChildByName(QName.create(MODULE.getQNameModule(), "nodes"));
+ .getDataChildByName(QName.create(MODULE.getQNameModule(), "nodes"));
// test SchemaNode args
assertEquals(SN_NODES, nodes.getQName());
assertEquals(Optional.of("nodes collection"), nodes.getDescription());
// child nodes
// total size = 8: defined 6, inserted by uses 2
assertEquals(8, nodes.getChildNodes().size());
- final LeafListSchemaNode added = (LeafListSchemaNode)nodes.getDataChildByName(QName.create(
+ final LeafListSchemaNode added = (LeafListSchemaNode) nodes.getDataChildByName(QName.create(
MODULE.getQNameModule(), "added"));
assertEquals(QName.create(SN, "added"), added.getQName());
assertEquals(QName.create(SN, "mytype"), added.getType().getQName());
*/
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.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Range;
import com.google.common.collect.RangeSet;
-import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class YangParserTest extends AbstractModelTest {
+class YangParserTest extends AbstractModelTest {
@Test
- public void testHeaders() throws ParseException {
+ void testHeaders() {
assertEquals("foo", FOO.getName());
assertEquals(YangVersion.VERSION_1, FOO.getYangVersion());
assertEquals(XMLNamespace.of("urn:opendaylight.foo"), FOO.getNamespace());
}
@Test
- public void testParseList() {
+ void testParseList() {
final ContainerSchemaNode interfaces = (ContainerSchemaNode) BAR.getDataChildByName(barQName("interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(barQName("ifEntry"));
// test SchemaNode args
final LeafSchemaNode ifIndex = (LeafSchemaNode) ifEntry.getDataChildByName(barQName("ifIndex"));
assertEquals(ifEntry.getKeyDefinition().get(0), ifIndex.getQName());
- assertTrue(ifIndex.getType() instanceof Uint32TypeDefinition);
+ assertInstanceOf(Uint32TypeDefinition.class, ifIndex.getType());
assertEquals(Optional.of("minutes"), ifIndex.getType().getUnits());
final LeafSchemaNode ifMtu = (LeafSchemaNode) ifEntry.getDataChildByName(barQName("ifMtu"));
assertEquals(BaseTypes.int32Type(), ifMtu.getType());
}
@Test
- public void testTypedefRangesResolving() throws ParseException {
+ void testTypedefRangesResolving() {
final LeafSchemaNode int32Leaf = (LeafSchemaNode) FOO.getDataChildByName(fooQName("int32-leaf"));
final Int32TypeDefinition leafType = (Int32TypeDefinition) int32Leaf.getType();
}
@Test
- public void testTypedefPatternsResolving() {
+ void testTypedefPatternsResolving() {
final LeafSchemaNode stringleaf = (LeafSchemaNode) FOO.getDataChildByName(fooQName("string-leaf"));
- assertTrue(stringleaf.getType() instanceof StringTypeDefinition);
+ assertInstanceOf(StringTypeDefinition.class, stringleaf.getType());
final StringTypeDefinition type = (StringTypeDefinition) stringleaf.getType();
assertEquals(barQName("string-ext4"), type.getQName());
assertEquals(Optional.empty(), type.getUnits());
}
@Test
- public void testTypedefInvalidPatternsResolving() {
+ void testTypedefInvalidPatternsResolving() {
final LeafSchemaNode multiplePatternStringLeaf = (LeafSchemaNode) FOO.getDataChildByName(
fooQName("multiple-pattern-string-leaf"));
StringTypeDefinition type = (StringTypeDefinition) multiplePatternStringLeaf.getType();
}
@Test
- public void testTypedefLengthsResolving() {
+ void testTypedefLengthsResolving() {
final LeafSchemaNode lengthLeaf = (LeafSchemaNode) FOO.getDataChildByName(fooQName("length-leaf"));
final StringTypeDefinition type = (StringTypeDefinition) lengthLeaf.getType();
}
@Test
- public void testTypedefDecimal1() {
+ void testTypedefDecimal1() {
final LeafSchemaNode testleaf = (LeafSchemaNode) FOO.getDataChildByName(fooQName("decimal-leaf"));
- assertTrue(testleaf.getType() instanceof DecimalTypeDefinition);
+ assertInstanceOf(DecimalTypeDefinition.class, testleaf.getType());
final DecimalTypeDefinition type = (DecimalTypeDefinition) testleaf.getType();
assertEquals(barQName("my-decimal-type"), type.getQName());
assertEquals(Optional.empty(), type.getUnits());
}
@Test
- public void testTypedefDecimal2() {
+ void testTypedefDecimal2() {
final LeafSchemaNode testleaf = (LeafSchemaNode) FOO.getDataChildByName(fooQName("decimal-leaf2"));
- assertTrue(testleaf.getType() instanceof DecimalTypeDefinition);
+ assertInstanceOf(DecimalTypeDefinition.class, testleaf.getType());
final DecimalTypeDefinition type = (DecimalTypeDefinition) testleaf.getType();
assertEquals(barQName("my-decimal-type"), type.getQName());
assertEquals(Optional.empty(), type.getUnits());
}
@Test
- public void testTypedefUnion() {
+ void testTypedefUnion() {
final LeafSchemaNode unionleaf = (LeafSchemaNode) FOO.getDataChildByName(fooQName("union-leaf"));
- assertTrue(unionleaf.getType() instanceof UnionTypeDefinition);
+ assertInstanceOf(UnionTypeDefinition.class, unionleaf.getType());
final UnionTypeDefinition type = (UnionTypeDefinition) unionleaf.getType();
assertEquals(barQName("my-union-ext"), type.getQName());
assertEquals(Optional.empty(), type.getUnits());
}
@Test
- public void testNestedUnionResolving() {
+ void testNestedUnionResolving() {
final LeafSchemaNode testleaf = (LeafSchemaNode) FOO.getDataChildByName(fooQName("custom-union-leaf"));
- assertTrue(testleaf.getType() instanceof UnionTypeDefinition);
+ assertInstanceOf(UnionTypeDefinition.class, testleaf.getType());
final UnionTypeDefinition type = (UnionTypeDefinition) testleaf.getType();
assertEquals(bazQName("union1"), type.getQName());
assertEquals(Optional.empty(), type.getUnits());
final List<TypeDefinition<?>> unionTypes = union.getTypes();
assertEquals(2, unionTypes.size());
assertEquals(BaseTypes.int32Type(), unionTypes.get(0));
- assertTrue(unionTypes.get(1) instanceof UnionTypeDefinition);
+ assertInstanceOf(UnionTypeDefinition.class, unionTypes.get(1));
final UnionTypeDefinition unionType1 = (UnionTypeDefinition) unionTypes.get(1);
assertEquals(barQName("nested-union2"), unionType1.getQName());
final UnionTypeDefinition nestedUnion = unionType1.getBaseType();
final List<TypeDefinition<?>> nestedUnion2Types = nestedUnion.getTypes();
assertEquals(2, nestedUnion2Types.size());
- assertTrue(nestedUnion2Types.get(1) instanceof StringTypeDefinition);
- assertTrue(nestedUnion2Types.get(0) instanceof UnionTypeDefinition);
+ assertInstanceOf(StringTypeDefinition.class, nestedUnion2Types.get(1));
+ assertInstanceOf(UnionTypeDefinition.class, nestedUnion2Types.get(0));
final UnionTypeDefinition myUnionExt = (UnionTypeDefinition) nestedUnion2Types.get(0);
assertEquals(barQName("my-union-ext"), myUnionExt.getQName());
final UnionTypeDefinition myUnionBase = myUnion.getBaseType();
final List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
assertEquals(2, myUnionBaseTypes.size());
- assertTrue(myUnionBaseTypes.get(0) instanceof Int16TypeDefinition);
+ assertInstanceOf(Int16TypeDefinition.class, myUnionBaseTypes.get(0));
assertEquals(BaseTypes.int32Type(), myUnionBaseTypes.get(1));
final Int16TypeDefinition int16Ext = (Int16TypeDefinition) myUnionBaseTypes.get(0);
}
@Test
- public void testChoice() {
+ void testChoice() {
final ContainerSchemaNode transfer = (ContainerSchemaNode) FOO.getDataChildByName(fooQName("transfer"));
final ChoiceSchemaNode how = (ChoiceSchemaNode) transfer.getDataChildByName(fooQName("how"));
final var cases = how.getCases();
}
@Test
- public void testDeviation() {
+ void testDeviation() {
final var deviations = FOO.getDeviations();
assertEquals(1, deviations.size());
final Deviation dev = deviations.iterator().next();
}
@Test
- public void testUnknownNode() {
+ void testUnknownNode() {
final ContainerSchemaNode network = (ContainerSchemaNode) BAZ.getDataChildByName(bazQName("network"));
final var unknownNodes = network.asEffectiveStatement().getDeclared()
.declaredSubstatements(UnrecognizedStatement.class);
}
@Test
- public void testFeature() {
+ void testFeature() {
final var features = BAZ.getFeatures();
assertEquals(3, features.size());
}
@Test
- public void testExtension() {
+ void testExtension() {
final var extensions = BAZ.getExtensionSchemaNodes();
assertEquals(1, extensions.size());
final ExtensionDefinition extension = extensions.iterator().next();
assertEquals("name", extension.getArgument());
assertEquals(
Optional.of("Takes as argument a name string. Makes the code generator use the given name in the #define."),
- extension.getDescription());
+ extension.getDescription());
assertTrue(extension.isYinElement());
}
@Test
- public void testNotification() {
+ void testNotification() {
final var notifications = BAZ.getNotifications();
assertEquals(1, notifications.size());
assertEquals(0, notification.getUses().size());
final LeafSchemaNode eventClass = (LeafSchemaNode) notification.getDataChildByName(bazQName("event-class"));
- assertTrue(eventClass.getType() instanceof StringTypeDefinition);
+ assertInstanceOf(StringTypeDefinition.class, eventClass.getType());
final LeafSchemaNode severity = (LeafSchemaNode) notification.getDataChildByName(bazQName("severity"));
- assertTrue(severity.getType() instanceof StringTypeDefinition);
+ assertInstanceOf(StringTypeDefinition.class, severity.getType());
}
@Test
- public void testRpc() {
+ void testRpc() {
final var rpcs = BAZ.getRpcs();
assertEquals(1, rpcs.size());
}
@Test
- public void testTypePath() throws ParseException {
+ void testTypePath() {
final Collection<? extends TypeDefinition<?>> types = BAR.getTypeDefinitions();
// int32-ext1
}
@Test
- public void testTypePath2() throws ParseException {
+ void testTypePath2() {
final var types = BAR.getTypeDefinitions();
// my-decimal-type
}
@Test
- public void testSubmodules() {
+ void testSubmodules() {
final DataSchemaNode id = FOO.getDataChildByName(fooQName("id"));
assertNotNull(id);
final DataSchemaNode subExt = FOO.getDataChildByName(fooQName("sub-ext"));
}
@Test
- public void unknownStatementInSubmoduleHeaderTest() throws Exception {
- TestUtils.parseYangSource(
+ void unknownStatementInSubmoduleHeaderTest() {
+ assertEffectiveModel(
"/yang-grammar-test/revisions-extension.yang",
"/yang-grammar-test/submodule-header-extension.yang");
}
@Test
- public void unknownStatementBetweenRevisionsTest() throws Exception {
- TestUtils.parseYangSource(
+ void unknownStatementBetweenRevisionsTest() {
+ assertEffectiveModel(
"/yang-grammar-test/revisions-extension.yang",
"/yang-grammar-test/submodule-header-extension.yang");
}
@Test
- public void unknownStatementsInStatementsTest() {
- final var ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> TestUtils.parseYangSource(
- "/yang-grammar-test/stmtsep-in-statements.yang",
- "/yang-grammar-test/stmtsep-in-statements2.yang",
- "/yang-grammar-test/stmtsep-in-statements-sub.yang"));
- final var cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("aaa is not a YANG statement or use of extension"));
+ void unknownStatementsInStatementsTest() {
+ assertSourceException(startsWith("aaa is not a YANG statement or use of extension"),
+ "/yang-grammar-test/stmtsep-in-statements.yang",
+ "/yang-grammar-test/stmtsep-in-statements2.yang",
+ "/yang-grammar-test/stmtsep-in-statements-sub.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
import com.google.common.collect.Iterables;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-public class YangParserWithContextTest {
+class YangParserWithContextTest {
private static final XMLNamespace T1_NS = XMLNamespace.of("urn:simple.demo.test1");
private static final XMLNamespace T2_NS = XMLNamespace.of("urn:simple.demo.test2");
private static final XMLNamespace T3_NS = XMLNamespace.of("urn:simple.demo.test3");
private static final StatementStreamSource FOO = sourceForResource("/model/foo.yang");
private static final StatementStreamSource SUBFOO = sourceForResource("/model/subfoo.yang");
- private static final StatementStreamSource[] IETF = new StatementStreamSource[] {
- sourceForResource("/ietf/iana-afn-safi@2012-06-04.yang"),
- sourceForResource("/ietf/iana-if-type@2012-06-05.yang"),
- sourceForResource("/ietf/iana-timezones@2012-07-09.yang"),
- sourceForResource("/ietf/ietf-inet-types@2010-09-24.yang"),
- sourceForResource("/ietf/ietf-yang-types@2010-09-24.yang"),
- sourceForResource("/ietf/network-topology@2013-07-12.yang"),
- sourceForResource("/ietf/network-topology@2013-10-21.yang") };
+ private static final StatementStreamSource[] IETF = new StatementStreamSource[]{
+ sourceForResource("/ietf/iana-afn-safi@2012-06-04.yang"),
+ sourceForResource("/ietf/iana-if-type@2012-06-05.yang"),
+ sourceForResource("/ietf/iana-timezones@2012-07-09.yang"),
+ sourceForResource("/ietf/ietf-inet-types@2010-09-24.yang"),
+ sourceForResource("/ietf/ietf-yang-types@2010-09-24.yang"),
+ sourceForResource("/ietf/network-topology@2013-07-12.yang"),
+ sourceForResource("/ietf/network-topology@2013-10-21.yang")};
@Test
- public void testTypeFromContext() throws ReactorException {
+ void testTypeFromContext() throws ReactorException {
final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(IETF)
- .addSource(sourceForResource("/types/custom-types-test@2012-04-04.yang"))
- .addSource(sourceForResource("/context-test/test1.yang"))
- .buildEffective();
+ .addSources(IETF)
+ .addSource(sourceForResource("/types/custom-types-test@2012-04-04.yang"))
+ .addSource(sourceForResource("/context-test/test1.yang"))
+ .buildEffective();
final Module module = context.findModule("test1", Revision.of("2013-06-18")).get();
final LeafSchemaNode leaf = (LeafSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(),
- "id"));
+ "id"));
- assertTrue(leaf.getType() instanceof Uint16TypeDefinition);
- final Uint16TypeDefinition leafType = (Uint16TypeDefinition) leaf.getType();
+ final Uint16TypeDefinition leafType = assertInstanceOf(Uint16TypeDefinition.class, leaf.getType());
QName qname = leafType.getQName();
assertEquals(XMLNamespace.of("urn:simple.demo.test1"), qname.getNamespace());
assertEquals(Revision.ofNullable("2013-06-18"), qname.getRevision());
}
@Test
- public void testUsesFromContext() throws ReactorException {
+ void testUsesFromContext() throws ReactorException {
final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(BAZ, FOO, BAR, SUBFOO, sourceForResource("/context-test/test2.yang"))
- .buildEffective();
+ .addSources(BAZ, FOO, BAR, SUBFOO, sourceForResource("/context-test/test2.yang"))
+ .buildEffective();
final Module testModule = context.findModule("test2", Revision.of("2013-06-18")).get();
final Module contextModule = context.findModules(XMLNamespace.of("urn:opendaylight.baz")).iterator().next();
// get node containing uses
final ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
- testModule.getQNameModule(), "peer"));
+ testModule.getQNameModule(), "peer"));
final ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName(QName.create(
- testModule.getQNameModule(), "destination"));
+ testModule.getQNameModule(), "destination"));
// check uses
final var uses = destination.getUses();
// check uses process
final AnyxmlSchemaNode data_u = (AnyxmlSchemaNode) destination.getDataChildByName(QName.create(
- testModule.getQNameModule(), "data"));
+ testModule.getQNameModule(), "data"));
assertNotNull(data_u);
assertTrue(data_u.isAddedByUses());
final AnyxmlSchemaNode data_g = (AnyxmlSchemaNode) grouping.getDataChildByName(QName.create(
- contextModule.getQNameModule(), "data"));
+ contextModule.getQNameModule(), "data"));
assertNotNull(data_g);
assertFalse(data_g.isAddedByUses());
- assertFalse(data_u.equals(data_g));
+ assertNotEquals(data_u, data_g);
final ChoiceSchemaNode how_u = (ChoiceSchemaNode) destination.getDataChildByName(QName.create(
- testModule.getQNameModule(), "how"));
+ testModule.getQNameModule(), "how"));
assertNotNull(how_u);
assertTrue(how_u.isAddedByUses());
final ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName(QName.create(
- contextModule.getQNameModule(), "how"));
+ contextModule.getQNameModule(), "how"));
assertNotNull(how_g);
assertFalse(how_g.isAddedByUses());
- assertFalse(how_u.equals(how_g));
+ assertNotEquals(how_u, how_g);
final LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName(QName.create(
- testModule.getQNameModule(), "address"));
+ testModule.getQNameModule(), "address"));
assertNotNull(address_u);
assertTrue(address_u.isAddedByUses());
final LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
- contextModule.getQNameModule(), "address"));
+ contextModule.getQNameModule(), "address"));
assertNotNull(address_g);
assertFalse(address_g.isAddedByUses());
- assertFalse(address_u.equals(address_g));
+ assertNotEquals(address_u, address_g);
final ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName(QName.create(
- testModule.getQNameModule(), "port"));
+ testModule.getQNameModule(), "port"));
assertNotNull(port_u);
assertTrue(port_u.isAddedByUses());
final ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName(QName.create(
- contextModule.getQNameModule(), "port"));
+ contextModule.getQNameModule(), "port"));
assertNotNull(port_g);
assertFalse(port_g.isAddedByUses());
- assertFalse(port_u.equals(port_g));
+ assertNotEquals(port_u, port_g);
final ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName(QName.create(
- testModule.getQNameModule(), "addresses"));
+ testModule.getQNameModule(), "addresses"));
assertNotNull(addresses_u);
assertTrue(addresses_u.isAddedByUses());
final ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName(QName.create(
- contextModule.getQNameModule(), "addresses"));
+ contextModule.getQNameModule(), "addresses"));
assertNotNull(addresses_g);
assertFalse(addresses_g.isAddedByUses());
- assertFalse(addresses_u.equals(addresses_g));
+ assertNotEquals(addresses_u, addresses_g);
// grouping defined by 'uses'
final var groupings_u = destination.getGroupings();
}
@Test
- public void testUsesRefineFromContext() throws ReactorException {
+ void testUsesRefineFromContext() throws ReactorException {
final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(BAZ, FOO, BAR, SUBFOO, sourceForResource("/context-test/test2.yang"))
- .buildEffective();
+ .addSources(BAZ, FOO, BAR, SUBFOO, sourceForResource("/context-test/test2.yang"))
+ .buildEffective();
final Module module = context.findModule("test2", Revision.of("2013-06-18")).get();
final ContainerSchemaNode peer = (ContainerSchemaNode) module.getDataChildByName(QName.create(
- module.getQNameModule(), "peer"));
+ module.getQNameModule(), "peer"));
final ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName(QName.create(
- module.getQNameModule(), "destination"));
+ module.getQNameModule(), "destination"));
final var usesNodes = destination.getUses();
assertEquals(1, usesNodes.size());
final UsesNode usesNode = usesNodes.iterator().next();
}
@Test
- public void testIdentity() throws ReactorException {
+ void testIdentity() throws ReactorException {
final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(IETF)
- .addSource(sourceForResource("/types/custom-types-test@2012-04-04.yang"))
- .addSource(sourceForResource("/context-test/test3.yang"))
- .buildEffective();
+ .addSources(IETF)
+ .addSource(sourceForResource("/types/custom-types-test@2012-04-04.yang"))
+ .addSource(sourceForResource("/context-test/test3.yang"))
+ .buildEffective();
final Module module = context.findModule("test3", Revision.of("2013-06-18")).get();
final var identities = module.getIdentities();
}
@Test
- public void testUnknownNodes() throws ReactorException {
+ void testUnknownNodes() throws ReactorException {
final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(IETF)
- .addSource(sourceForResource("/types/custom-types-test@2012-04-04.yang"))
- .addSource(sourceForResource("/context-test/test3.yang"))
- .buildEffective();
+ .addSources(IETF)
+ .addSource(sourceForResource("/types/custom-types-test@2012-04-04.yang"))
+ .addSource(sourceForResource("/context-test/test3.yang"))
+ .buildEffective();
final Module module = context.findModule("test3", Revision.of("2013-06-18")).get();
final ContainerStatement network = ((ContainerSchemaNode) module.getDataChildByName(
}
@Test
- public void testAugment() throws Exception {
+ void testAugment() throws Exception {
final Module t4 = TestUtils.parseYangSource(
"/context-augment-test/test1.yang", "/context-augment-test/test2.yang",
"/context-augment-test/test3.yang", "/context-augment-test/test4.yang")
.findModules("test4").iterator().next();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) t4.getDataChildByName(QName.create(
- t4.getQNameModule(), "interfaces"));
+ t4.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(t4.getQNameModule(),
- "ifEntry"));
+ "ifEntry"));
// test augmentation process
final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(T3_NS,
- REV, "augment-holder"));
+ REV, "augment-holder"));
assertNotNull(augmentHolder);
final DataSchemaNode ds0 = augmentHolder.getDataChildByName(QName.create(T2_NS, REV, "ds0ChannelNumber"));
assertNotNull(ds0);
final DataSchemaNode interfaceId = augmentHolder.getDataChildByName(QName.create(T2_NS, REV, "interface-id"));
assertNotNull(interfaceId);
final DataSchemaNode higherLayerIf = augmentHolder.getDataChildByName(QName.create(T2_NS, REV,
- "higher-layer-if"));
+ "higher-layer-if"));
assertNotNull(higherLayerIf);
final ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName(QName.create(T2_NS,
- REV, "schemas"));
+ REV, "schemas"));
assertNotNull(schemas);
assertNotNull(schemas.getDataChildByName(QName.create(T1_NS, REV, "id")));
// test augment target after augmentation: check if it is same instance
final ListSchemaNode ifEntryAfterAugment = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
- t4.getQNameModule(), "ifEntry"));
+ t4.getQNameModule(), "ifEntry"));
assertTrue(ifEntry == ifEntryAfterAugment);
}
@Test
- public void testDeviation() throws ReactorException {
+ void testDeviation() throws ReactorException {
final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(sourceForResource("/model/bar.yang"))
- .addSource(sourceForResource("/context-test/deviation-test.yang"))
- .buildEffective();
+ .addSource(sourceForResource("/model/bar.yang"))
+ .addSource(sourceForResource("/context-test/deviation-test.yang"))
+ .buildEffective();
final Module testModule = context.findModule("deviation-test", Revision.of("2013-02-27")).get();
final var deviations = testModule.getDeviations();
final Revision expectedRev = Revision.of("2013-07-03");
assertEquals(Absolute.of(
- QName.create(expectedNS, expectedRev, "interfaces"), QName.create(expectedNS, expectedRev, "ifEntry")),
+ QName.create(expectedNS, expectedRev, "interfaces"), QName.create(expectedNS, expectedRev, "ifEntry")),
dev.getTargetPath());
assertEquals(DeviateKind.ADD, dev.getDeviates().iterator().next().getDeviateType());
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-
-public class YangTypes2StmtTest {
-
- private static final StatementStreamSource TYPEFILE1 = sourceForResource("/semantic-statement-parser/types2.yang");
- private static final StatementStreamSource TYPEFILE2 = sourceForResource("/semantic-statement-parser/types.yang");
- private static final StatementStreamSource TYPEFILE3 = sourceForResource(
- "/semantic-statement-parser/simple-types.yang");
- private static final StatementStreamSource TYPEFILE4 = sourceForResource(
- "/semantic-statement-parser/identityreftest.yang");
+class YangTypes2StmtTest extends AbstractYangTest {
private static final QNameModule TYPES2_MODULE = QNameModule.create(XMLNamespace.of("types2"));
private static final QName LF_DECIMAL = QName.create(TYPES2_MODULE, "lf-decimal");
private static final QName LF_BOOL = QName.create(TYPES2_MODULE, "lf-bool");
@Test
- public void readAndParseYangFileTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(TYPEFILE1, TYPEFILE2, TYPEFILE3, TYPEFILE4)
- .buildEffective();
- assertNotNull(result);
+ void readAndParseYangFileTest() {
+ final var result = assertEffectiveModel(
+ "/semantic-statement-parser/types2.yang", "/semantic-statement-parser/types.yang",
+ "/semantic-statement-parser/simple-types.yang", "/semantic-statement-parser/identityreftest.yang");
final LeafSchemaNode lfDecimalNode = (LeafSchemaNode) result.getDataChildByName(LF_DECIMAL);
assertNotNull(lfDecimalNode);
- assertTrue(lfDecimalNode.getType() instanceof DecimalTypeDefinition);
- final DecimalTypeDefinition lfDecimalNodeType = (DecimalTypeDefinition) lfDecimalNode.getType();
+ final DecimalTypeDefinition lfDecimalNodeType =
+ assertInstanceOf(DecimalTypeDefinition.class, lfDecimalNode.getType());
assertEquals(2, lfDecimalNodeType.getFractionDigits());
final LeafSchemaNode lfInt8Node = (LeafSchemaNode) result.getDataChildByName(LF_INT8);
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-
-public class YangTypesStmtTest {
-
- private static final StatementStreamSource TYPEFILE1 = sourceForResource("/semantic-statement-parser/types.yang");
- private static final StatementStreamSource TYPEFILE2 = sourceForResource(
- "/semantic-statement-parser/simple-types.yang");
- private static final StatementStreamSource TYPEFILE3 = sourceForResource(
- "/semantic-statement-parser/identityreftest.yang");
-
- private static final StatementStreamSource FILE1 = sourceForResource("/semantic-statement-parser/model/bar.yang");
- private static final StatementStreamSource FILE2 = sourceForResource("/semantic-statement-parser/model/baz.yang");
- private static final StatementStreamSource FILE3 = sourceForResource(
- "/semantic-statement-parser/model/subfoo.yang");
- private static final StatementStreamSource FILE4 = sourceForResource("/semantic-statement-parser/model/foo.yang");
+import org.junit.jupiter.api.Test;
+class YangTypesStmtTest extends AbstractYangTest {
@Test
- public void readAndParseYangFileTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(TYPEFILE1, TYPEFILE2, TYPEFILE3, FILE1, FILE2, FILE3, FILE4)
- .buildEffective();
- assertNotNull(result);
+ void readAndParseYangFileTest() {
+ assertEffectiveModel(
+ "/semantic-statement-parser/types.yang",
+ "/semantic-statement-parser/simple-types.yang",
+ "/semantic-statement-parser/identityreftest.yang",
+ "/semantic-statement-parser/model/bar.yang",
+ "/semantic-statement-parser/model/baz.yang",
+ "/semantic-statement-parser/model/subfoo.yang",
+ "/semantic-statement-parser/model/foo.yang");
}
}
*/
package org.opendaylight.yangtools.yang.stmt.test;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import java.util.List;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug5200Test extends AbstractYangTest {
+class Bug5200Test extends AbstractYangTest {
private static final String NS = "foo";
private static final String REV = "2016-05-05";
@Test
- public void test() {
+ void test() {
final var context = assertEffectiveModelDir("/bugs/bug5200");
QName root = QName.create(NS, REV, "root");
QName myLeaf = QName.create(NS, REV, "my-leaf");
QName myLeaf2 = QName.create(NS, REV, "my-leaf-2");
- SchemaNode myLeafNode = context.findDataTreeChild(root, myLeaf).get();
- SchemaNode myLeaf2Node = context.findDataTreeChild(root, myLeaf2).get();
+ SchemaNode myLeafNode = context.findDataTreeChild(root, myLeaf).orElseThrow();
+ SchemaNode myLeaf2Node = context.findDataTreeChild(root, myLeaf2).orElseThrow();
- assertThat(myLeafNode, instanceOf(LeafSchemaNode.class));
- assertThat(myLeaf2Node, instanceOf(LeafSchemaNode.class));
+ final var myLeafType = assertInstanceOf(StringTypeDefinition.class,
+ assertInstanceOf(LeafSchemaNode.class, myLeafNode).getType());
+ final var myLeaf2Type = assertInstanceOf(Int32TypeDefinition.class,
+ assertInstanceOf(LeafSchemaNode.class, myLeaf2Node).getType());
- TypeDefinition<?> myLeafType = ((LeafSchemaNode) myLeafNode).getType();
- TypeDefinition<?> myLeaf2Type = ((LeafSchemaNode) myLeaf2Node).getType();
-
- assertThat(myLeafType, instanceOf(StringTypeDefinition.class));
- assertThat(myLeaf2Type, instanceOf(Int32TypeDefinition.class));
-
- final LengthConstraint lengthConstraint =
- ((StringTypeDefinition) myLeafType).getLengthConstraint().get();
- final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) myLeafType).getPatternConstraints();
+ final LengthConstraint lengthConstraint = myLeafType.getLengthConstraint().orElseThrow();
+ final List<PatternConstraint> patternConstraints = myLeafType.getPatternConstraints();
assertEquals(1, lengthConstraint.getAllowedRanges().asRanges().size());
assertEquals(1, patternConstraints.size());
assertEquals(Optional.of("pattern constraint error-app-tag"), patternConstraint.getErrorAppTag());
assertEquals(Optional.of("pattern constraint error-app-message"), patternConstraint.getErrorMessage());
- RangeConstraint<?> rangeConstraint = ((Int32TypeDefinition) myLeaf2Type).getRangeConstraint().get();
+ RangeConstraint<?> rangeConstraint = myLeaf2Type.getRangeConstraint().orElseThrow();
assertEquals(1, rangeConstraint.getAllowedRanges().asRanges().size());
assertEquals(Optional.of("range constraint error-app-tag"), rangeConstraint.getErrorAppTag());
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
-import org.xml.sax.SAXException;
public abstract class AbstractYinModulesTest {
- static SchemaContext context;
+ static EffectiveModelContext context;
- @BeforeClass
- public static void beforeClass() throws ReactorException, SAXException, IOException, URISyntaxException {
+ @BeforeAll
+ static void beforeClass() throws Exception {
context = TestUtils.loadYinModules(
AbstractYinModulesTest.class.getResource("/semantic-statement-parser/yin/modules").toURI());
assertEquals(9, context.getModules().size());
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static void afterClass() {
context = null;
}
}
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collection;
import java.util.Iterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class YinFileAugmentStmtTest extends AbstractYinModulesTest {
+class YinFileAugmentStmtTest extends AbstractYinModulesTest {
@Test
- public void testAugment() {
+ void testAugment() {
final Module testModule = context.findModules("main-impl").iterator().next();
assertNotNull(testModule);
assertNotNull(augment);
assertThat(augment.getTargetPath().toString(), containsString(
"(urn:opendaylight:params:xml:ns:yang:controller:config?revision=2013-04-05)modules, module, "
- + "configuration"));
+ + "configuration"));
assertEquals(1, augment.getChildNodes().size());
final DataSchemaNode caseNode = augment.findDataChildByName(
QName.create(testModule.getQNameModule(), "main-impl")).get();
- assertThat(caseNode, isA(CaseSchemaNode.class));
+ assertInstanceOf(CaseSchemaNode.class, caseNode);
}
}
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class YinFileChoiceStmtTest extends AbstractYinModulesTest {
+class YinFileChoiceStmtTest extends AbstractYinModulesTest {
@Test
- public void testChoiceAndCases() {
+ void testChoiceAndCases() {
final Module testModule = context.findModules("config").iterator().next();
assertNotNull(testModule);
QName.create(testModule.getQNameModule(), "module")).get();
ChoiceSchemaNode choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(),
- "configuration")).get();
+ "configuration")).get();
assertEquals("configuration", choice.getQName().getLocalName());
assertTrue(choice.isMandatory());
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.Iterator;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class YinFileExtensionStmtTest extends AbstractYinModulesTest {
+class YinFileExtensionStmtTest extends AbstractYinModulesTest {
@Test
- public void testExtensions() {
+ void testExtensions() {
Module testModule = context.findModules("config").iterator().next();
assertNotNull(testModule);
assertEquals("name", extension.getArgument());
assertEquals("java-class", extension.getQName().getLocalName());
assertEquals(Optional.of("YANG language extension carrying the fully-qualified name of\n"
- + "a Java class. Code generation tools use the provided reference\n"
- + "to tie a specific construct to its Java representation."), extension.getDescription());
+ + "a Java class. Code generation tools use the provided reference\n"
+ + "to tie a specific construct to its Java representation."), extension.getDescription());
extension = extIterator.next();
assertEquals("name", extension.getArgument());
assertEquals("required-identity", extension.getQName().getLocalName());
assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
- + "leafref, which points to a identityref, should additionally\n"
- + "require the target node is actually set to a descendant to\n"
- + "of a particular identity.\n"
- + "\n"
- + "This is a workaround to two YANG deficiencies:\n"
- + "1) not being able to leafref instances of identityref\n"
- + "2) not being able to refine an identityref\n"
- + "\n"
- + "This extension takes one argument, name, which MUST be the name\n"
- + "of an identity. Furthermore, that identity MUST be based,\n"
- + "directly or indirectly, on the identity, which is referenced by\n"
- + "the leaf reference, which is annotated with this extension."), extension.getDescription());
+ + "leafref, which points to a identityref, should additionally\n"
+ + "require the target node is actually set to a descendant to\n"
+ + "of a particular identity.\n"
+ + "\n"
+ + "This is a workaround to two YANG deficiencies:\n"
+ + "1) not being able to leafref instances of identityref\n"
+ + "2) not being able to refine an identityref\n"
+ + "\n"
+ + "This extension takes one argument, name, which MUST be the name\n"
+ + "of an identity. Furthermore, that identity MUST be based,\n"
+ + "directly or indirectly, on the identity, which is referenced by\n"
+ + "the leaf reference, which is annotated with this extension."), extension.getDescription());
extension = extIterator.next();
assertNull(extension.getArgument());
assertEquals("inner-state-bean", extension.getQName().getLocalName());
assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
- + "list located under module's state should be treated as a list\n"
- + "of child state beans instead of just an ordinary list attribute"), extension.getDescription());
+ + "list located under module's state should be treated as a list\n"
+ + "of child state beans instead of just an ordinary list attribute"), extension.getDescription());
extension = extIterator.next();
assertEquals("name", extension.getArgument());
assertEquals("provided-service", extension.getQName().getLocalName());
assertEquals(Optional.of("YANG language extension which indicates that a particular\n"
- + "module provides certain service. This extension can be placed\n"
- + "on identities that are based on module-type. Zero or more services\n"
- + "can be provided.\n"
- + "This extension takes one argument - name - which MUST be the name\n"
- + "of an identity. Furthermore, this identity MUST be based on\n"
- + "service-type."), extension.getDescription());
+ + "module provides certain service. This extension can be placed\n"
+ + "on identities that are based on module-type. Zero or more services\n"
+ + "can be provided.\n"
+ + "This extension takes one argument - name - which MUST be the name\n"
+ + "of an identity. Furthermore, this identity MUST be based on\n"
+ + "service-type."), extension.getDescription());
extension = extIterator.next();
assertEquals("java-prefix", extension.getArgument());
assertEquals("java-name-prefix", extension.getQName().getLocalName());
assertEquals(Optional.of("YANG language extension carrying java simple class name prefix\n"
- + "that will be taken into account when generating java code from\n"
- + "identities that are based on module-type."), extension.getDescription());
+ + "that will be taken into account when generating java code from\n"
+ + "identities that are based on module-type."), extension.getDescription());
}
}
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collection;
import java.util.Iterator;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
-public class YinFileFeatureStmtTest {
- private SchemaContext context;
+class YinFileFeatureStmtTest {
+ private EffectiveModelContext context;
- @Before
- public void init() throws Exception {
+ @BeforeEach
+ void init() throws Exception {
context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/feature-test/")
.toURI());
assertEquals(1, context.getModules().size());
}
@Test
- public void testFeature() {
+ void testFeature() {
Module testModule = context.findModules("yang-with-features").iterator().next();
assertNotNull(testModule);
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
import java.util.Iterator;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class YinFileGroupingStmtTest extends AbstractYinModulesTest {
+class YinFileGroupingStmtTest extends AbstractYinModulesTest {
@Test
- public void testGrouping() {
+ void testGrouping() {
final Module testModule = context.findModules("config").iterator().next();
assertNotNull(testModule);
final GroupingDefinition grouping = groupingsIterator.next();
assertEquals("service-ref", grouping.getQName().getLocalName());
assertEquals(Optional.of("Type of references to a particular service instance. This type\n"
- + "can be used when defining module configuration to refer to a\n"
- + "particular service instance. Containers using this grouping\n"
- + "should not define anything else. The run-time implementation\n"
- + "is expected to inject a reference to the service as the value\n"
- + "of the container."), grouping.getDescription());
+ + "can be used when defining module configuration to refer to a\n"
+ + "particular service instance. Containers using this grouping\n"
+ + "should not define anything else. The run-time implementation\n"
+ + "is expected to inject a reference to the service as the value\n"
+ + "of the container."), grouping.getDescription());
final Collection<? extends DataSchemaNode> children = grouping.getChildNodes();
assertEquals(2, children.size());
final LeafSchemaNode leaf1 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
- testModule.getQNameModule(), "type")).get();
+ testModule.getQNameModule(), "type")).get();
assertTrue(leaf1.isMandatory());
final LeafSchemaNode leaf2 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
- testModule.getQNameModule(), "name")).get();
+ testModule.getQNameModule(), "name")).get();
assertTrue(leaf2.isMandatory());
}
}
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class YinFileHeaderStmtsTest extends AbstractYinModulesTest {
+class YinFileHeaderStmtsTest extends AbstractYinModulesTest {
@Test
- public void testYinFileHeader() {
+ void testYinFileHeader() {
Module testModule = context.findModules("config").iterator().next();
assertEquals(YangVersion.VERSION_1, testModule.getYangVersion());
assertEquals(XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:controller:config"),
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
import java.util.Iterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class YinFileIdentityStmtTest extends AbstractYinModulesTest {
+class YinFileIdentityStmtTest extends AbstractYinModulesTest {
@Test
- public void testIdentity() {
+ void testIdentity() {
Module testModule = context.findModules("config").iterator().next();
assertNotNull(testModule);
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collection;
import java.util.Iterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-public class YinFileImportStmtTest extends AbstractYinModulesTest {
-
+class YinFileImportStmtTest extends AbstractYinModulesTest {
@Test
- public void testImport() {
+ void testImport() {
Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
assertNotNull(testModule);
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.Submodule;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
-public class YinFileIncludeStmtTest {
+class YinFileIncludeStmtTest {
@Test
- public void testInclude() throws Exception {
+ void testInclude() throws Exception {
Collection<? extends Submodule> submodules = TestUtils.loadYinModules(getClass().getResource(
"/semantic-statement-parser/yin/include-belongs-to-test").toURI()).findModules("parent").iterator().next()
.getSubmodules();
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class YinFileLeafListStmtTest extends AbstractYinModulesTest {
+class YinFileLeafListStmtTest extends AbstractYinModulesTest {
@Test
- public void testLeafList() {
+ void testLeafList() {
final Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
final LeafListSchemaNode leafList = (LeafListSchemaNode) testModule.findDataChildByName(
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
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.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
-public class YinFileListStmtTest extends AbstractYinModulesTest {
+class YinFileListStmtTest extends AbstractYinModulesTest {
@Test
- public void testListAndLeaves() {
+ void testListAndLeaves() {
final Module testModule = context.findModules("config").iterator().next();
assertNotNull(testModule);
final ListSchemaNode list = (ListSchemaNode) testModule.findDataChildByName(QName.create(
- testModule.getQNameModule(), "modules"), QName.create(testModule.getQNameModule(), "module")).get();
+ testModule.getQNameModule(), "modules"), QName.create(testModule.getQNameModule(), "module")).get();
final List<QName> keys = list.getKeyDefinition();
assertEquals(1, keys.size());
assertEquals("name", keys.get(0).getLocalName());
leaf = (LeafSchemaNode) childrenIterator.next();
assertEquals("type", leaf.getQName().getLocalName());
- final TypeDefinition<?> leafType = leaf.getType();
- assertThat(leafType, isA(IdentityrefTypeDefinition.class));
- assertEquals("module-type", ((IdentityrefTypeDefinition)leafType).getIdentities().iterator().next().getQName()
- .getLocalName());
+ final IdentityrefTypeDefinition leafType = assertInstanceOf(IdentityrefTypeDefinition.class, leaf.getType());
+ assertEquals("module-type", leafType.getIdentities().iterator().next().getQName().getLocalName());
assertTrue(leaf.isMandatory());
}
}
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
-public class YinFileMetaStmtsTest extends AbstractYinModulesTest {
+class YinFileMetaStmtsTest extends AbstractYinModulesTest {
@Test
- public void testMetaStatements() {
+ void testMetaStatements() {
Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
assertNotNull(testModule);
assertEquals(Optional.of("IETF NETCONF (Network Configuration) Working Group"), testModule.getOrganization());
assertEquals(Optional.of("WG Web: <http://tools.ietf.org/wg/netconf/>\n"
- + "WG List: <mailto:netconf@ietf.org>\n"
- + "\n"
- + "WG Chair: Mehmet Ersue\n"
- + " <mailto:mehmet.ersue@nsn.com>\n"
- + "\n"
- + "WG Chair: Bert Wijnen\n"
- + " <mailto:bertietf@bwijnen.net>\n"
- + "\n"
- + "Editor: Mark Scott\n"
- + " <mailto:mark.scott@ericsson.com>\n"
- + "\n"
- + "Editor: Martin Bjorklund\n"
- + " <mailto:mbj@tail-f.com>"), testModule.getContact());
+ + "WG List: <mailto:netconf@ietf.org>\n"
+ + "\n"
+ + "WG Chair: Mehmet Ersue\n"
+ + " <mailto:mehmet.ersue@nsn.com>\n"
+ + "\n"
+ + "WG Chair: Bert Wijnen\n"
+ + " <mailto:bertietf@bwijnen.net>\n"
+ + "\n"
+ + "Editor: Mark Scott\n"
+ + " <mailto:mark.scott@ericsson.com>\n"
+ + "\n"
+ + "Editor: Martin Bjorklund\n"
+ + " <mailto:mbj@tail-f.com>"), testModule.getContact());
assertEquals(Optional.of("NETCONF Monitoring Module.\n" + "All elements in this module are read-only.\n" + "\n"
+ "Copyright (c) 2010 IETF Trust and the persons identified as\n" + "authors of the code. All rights "
+ "reserved.\n" + "\n" + "Redistribution and use in source and binary forms, with or\n" + "without "
+ "Simplified BSD\n" + "License set forth in Section 4.c of the IETF Trust's\n" + "Legal Provisions "
+ "Relating to IETF Documents\n" + "(http://trustee.ietf.org/license-info).\n" + "\n" + "This version "
+ "of this YANG module is part of RFC 6022; see\n" + "the RFC itself for full legal notices."),
- testModule.getDescription());
+ testModule.getDescription());
}
}
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collection;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-public class YinFileRpcStmtTest extends AbstractYinModulesTest {
+class YinFileRpcStmtTest extends AbstractYinModulesTest {
@Test
- public void testRpc() {
+ void testRpc() {
Module testModule = context.findModules("ietf-netconf-monitoring").iterator().next();
Collection<? extends RpcDefinition> rpcs = testModule.getRpcs();
RpcDefinition rpc = rpcs.iterator().next();
assertEquals("get-schema", rpc.getQName().getLocalName());
assertEquals(Optional.of("This operation is used to retrieve a schema from the\n"
- + "NETCONF server.\n"
- + "\n"
- + "Positive Response:\n"
- + "The NETCONF server returns the requested schema.\n"
- + "\n"
- + "Negative Response:\n"
- + "If requested schema does not exist, the <error-tag> is\n"
- + "'invalid-value'.\n"
- + "\n"
- + "If more than one schema matches the requested parameters, the\n"
- + "<error-tag> is 'operation-failed', and <error-app-tag> is\n"
- + "'data-not-unique'."), rpc.getDescription());
+ + "NETCONF server.\n"
+ + "\n"
+ + "Positive Response:\n"
+ + "The NETCONF server returns the requested schema.\n"
+ + "\n"
+ + "Negative Response:\n"
+ + "If requested schema does not exist, the <error-tag> is\n"
+ + "'invalid-value'.\n"
+ + "\n"
+ + "If more than one schema matches the requested parameters, the\n"
+ + "<error-tag> is 'operation-failed', and <error-app-tag> is\n"
+ + "'data-not-unique'."), rpc.getDescription());
InputSchemaNode input = rpc.getInput();
assertNotNull(input);
*/
package org.opendaylight.yangtools.yang.stmt.yin;
+import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YinStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
import org.xml.sax.SAXException;
-public class YinFileStmtTest {
+class YinFileStmtTest {
private static final StatementStreamSource YIN_FILE = createSource("test.yin");
private static final StatementStreamSource EXT_FILE = createSource("extension.yin");
}
@Test
- public void readAndParseYinFileTestModel() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(YIN_FILE, EXT_FILE, EXT_USE_FILE)
- .buildEffective();
- assertNotNull(result);
+ void readAndParseYinFileTestModel() throws ReactorException {
+ assertNotNull(RFC7950Reactors.defaultReactor().newBuild()
+ .addSources(YIN_FILE, EXT_FILE, EXT_USE_FILE)
+ .buildEffective());
}
// parsing yin file whose import statement references a module which does not exist
- @Test(expected = SomeModifiersUnresolvedException.class)
- public void readAndParseInvalidYinFileTest() throws ReactorException {
- SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(INVALID_YIN_FILE)
- .buildEffective();
- assertNotNull(result);
+ @Test
+ void readAndParseInvalidYinFileTest() {
+ var reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(INVALID_YIN_FILE);
+ assertThrows(SomeModifiersUnresolvedException.class, reactor::buildEffective);
}
// parsing yin file with duplicate key name in a list statement
@Test
- public void readAndParseInvalidYinFileTest2() {
- BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(INVALID_YIN_FILE_2);
-
- try {
- reactor.buildEffective();
- fail("Reactor exception should have been thrown");
- } catch (ReactorException e) {
- final Throwable cause = e.getCause();
- assertThat(cause, isA(SourceException.class));
- assertTrue(cause.getMessage().startsWith(
- "Key argument 'testing-string testing-string' contains duplicates"));
- }
+ void readAndParseInvalidYinFileTest2() {
+ var reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(INVALID_YIN_FILE_2);
+ final var cause = assertThrows(SomeModifiersUnresolvedException.class, reactor::buildEffective).getCause();
+ assertInstanceOf(SourceException.class, cause);
+ assertThat(cause.getMessage(), startsWith("Key argument 'testing-string testing-string' contains duplicates"));
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collection;
import java.util.Iterator;
import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-public class YinFileTypeDefStmtTest extends AbstractYinModulesTest {
+class YinFileTypeDefStmtTest extends AbstractYinModulesTest {
@Test
- public void testTypedef() {
+ void testTypedef() {
Module testModule = context.findModules("config").iterator().next();
assertNotNull(testModule);
*/
package org.opendaylight.yangtools.yang.stmt.yin;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collection;
import java.util.Iterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
-public class YinFileUsesStmtTest extends AbstractYinModulesTest {
+class YinFileUsesStmtTest extends AbstractYinModulesTest {
@Test
- public void testUses() {
+ void testUses() {
final Module testModule = context.findModules("main-impl").iterator().next();
final Collection<? extends AugmentationSchemaNode> augmentations = testModule.getAugmentations();
*/
package org.opendaylight.yangtools.yang.thirdparty.plugin;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import java.io.IOException;
-import java.net.URISyntaxException;
import java.util.Collection;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-public class ThirdPartyExtensionPluginTest {
+class ThirdPartyExtensionPluginTest {
private static final String NS = "urn:opendaylight:yang:extension:third-party";
private static final String REV = "2016-06-09";
@Test
- public void test() throws URISyntaxException, ReactorException, IOException, YangSyntaxErrorException {
+ void test() throws Exception {
final BuildAction reactor = RFC7950Reactors.defaultReactorBuilder()
.addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
new ThirdPartyExtensionSupport(YangParserConfiguration.DEFAULT))
.newBuild();
reactor.addSource(StmtTestUtils.sourceForResource("/plugin-test/foo.yang"));
- final SchemaContext schema = reactor.buildEffective();
+ final EffectiveModelContext schema = reactor.buildEffective();
final DataSchemaNode dataChildByName = schema.getDataChildByName(QName.create(NS, REV, "root"));
- assertThat(dataChildByName, isA(ContainerSchemaNode.class));
- final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;
+ final ContainerSchemaNode root = assertInstanceOf(ContainerSchemaNode.class, dataChildByName);
final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = root.getUnknownSchemaNodes();
assertEquals(1, unknownSchemaNodes.size());
final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.iterator().next();
- assertThat(unknownSchemaNode, isA(ThirdPartyExtensionEffectiveStatement.class));
final ThirdPartyExtensionEffectiveStatement thirdPartyExtensionStmt =
- (ThirdPartyExtensionEffectiveStatement) unknownSchemaNode;
+ assertInstanceOf(ThirdPartyExtensionEffectiveStatement.class, unknownSchemaNode);
assertEquals("Third-party namespace test.", thirdPartyExtensionStmt.getValueFromNamespace());
assertEquals("plugin test", thirdPartyExtensionStmt.argument());
}
--- /dev/null
+module root-module {
+ namespace root-module;
+ prefix rm;
+}
}
include foo;
-}
\ No newline at end of file
+}
module key-comp-duplicate {
- namespace root;
- prefix root;
+ namespace root;
+ prefix root;
- list comp {
- key "key1 key2 key2";
- container key1 {
- }
- container key2 {
- }
- container key3 {
- }
- }
-}
\ No newline at end of file
+ list comp {
+ key "key1 key2 key2";
+ container key1;
+ container key2;
+ }
+}
module key-simple-and-comp {
- namespace root;
- prefix root;
+ namespace root;
+ prefix root;
- list simple {
- key "key1";
- container key1 {
- }
- }
+ list simple {
+ key "key1";
+ leaf key1 {
+ type string;
+ }
+ }
- list comp {
- key "key1 key2 key3";
- container key1 {
+ list comp {
+ key "key1 key2 key3";
+ leaf key1 {
+ type string;
}
- container key2 {
+ leaf key2 {
+ type string;
}
- container key3 {
+ leaf key3 {
+ type string;
}
- }
-}
\ No newline at end of file
+ }
+}