Removes code duplicity in parser unit tests.
JIRA: YANGTOOLS-1345
Change-Id: I0d20bf4d023a07e87d3d8228e29aa26a6bdb2348
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
16 files changed:
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import java.io.IOException;
-import java.net.URISyntaxException;
import org.junit.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.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.junit.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.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class ElementCountConstraintsTest {
+public class ElementCountConstraintsTest extends AbstractYangTest {
- public void testElementCountConstraints()
- throws YangSyntaxErrorException, ReactorException, URISyntaxException, IOException {
- final var schemaContext = StmtTestUtils.parseYangSource("/constraint-definitions-test/foo.yang");
- assertNotNull(schemaContext);
+ public void testElementCountConstraints() {
+ final var context = assertEffectiveModel("/constraint-definitions-test/foo.yang");
- final Module testModule = schemaContext.findModule("foo", Revision.of("2016-09-20")).get();
+ 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"));
ElementCountConstraint constraints1 = constrainedLeafList1.getElementCountConstraint().get();
final LeafListSchemaNode constrainedLeafList1 = (LeafListSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "constrained-leaf-list-1"));
ElementCountConstraint constraints1 = constrainedLeafList1.getElementCountConstraint().get();
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
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.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Collection;
import java.util.HashSet;
import java.util.Collection;
import java.util.HashSet;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class ActionStatementTest {
+public 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 {
private static final String FOO_NS = "foo-namespace";
private static final String FOO_REV = "2016-12-13";
@Test
public void testActionStatementInDataContainers() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foo.yang");
- assertNotNull(schemaContext);
+ final var context = assertEffectiveModel("/rfc7950/action-stmt/foo.yang");
- assertContainsActions(schemaContext, "root", "grp-action", "aug-action");
- assertContainsActions(schemaContext, "top-list", "top-list-action");
- assertContainsActions(schemaContext, "top", "top-action");
+ assertContainsActions(context, "root", "grp-action", "aug-action");
+ assertContainsActions(context, "top-list", "top-list-action");
+ assertContainsActions(context, "top", "top-action");
- final Collection<? extends GroupingDefinition> groupings = schemaContext.getGroupings();
+ final Collection<? extends GroupingDefinition> groupings = context.getGroupings();
assertEquals(1, groupings.size());
assertContainsActions(groupings.iterator().next(), "grp-action");
assertEquals(1, groupings.size());
assertContainsActions(groupings.iterator().next(), "grp-action");
- final Collection<? extends Module> modules = schemaContext.getModules();
+ final Collection<? extends Module> modules = context.getModules();
assertEquals(1, modules.size());
final Module foo = modules.iterator().next();
final Collection<? extends AugmentationSchemaNode> augmentations = foo.getAugmentations();
assertEquals(1, modules.size());
final Module foo = modules.iterator().next();
final Collection<? extends AugmentationSchemaNode> augmentations = foo.getAugmentations();
- public void testActionUnsupportedInYang10() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foo10.yang");
- fail("Test should fail due to invalid Yang 1.0");
- } catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith("action is not a YANG statement or use of extension"));
- }
+ public void testActionUnsupportedInYang10() {
+ assertSourceException(startsWith("action is not a YANG statement or use of extension"),
+ "/rfc7950/action-stmt/foo10.yang");
- public void testActionWithinIllegalAncestor() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foo-invalid.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith("Action (foo-namespace?revision=2016-12-13)"
- + "action-in-grouping is defined within a notification, rpc or another action"));
- }
+ public 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");
- public void testActionWithinListWithoutKey() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/action-stmt/bar-invalid.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Action (bar-namespace?revision=2016-12-13)my-action is defined within a list"
- + " that has no key statement"));
- }
+ public 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");
- public void testActionInUsedGroupingWithinCase() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/action-stmt/baz-invalid.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Action (baz-namespace?revision=2016-12-13)action-in-grouping is defined within a "
- + "case statement"));
- }
+ public 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");
- public void testActionInUsedGroupingAtTopLevelOfModule() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foobar-invalid.yang");
- fail("Test should fail due to invalid Yang 1.1");
- } catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Action (foobar-namespace?revision=2016-12-13)my-action is defined at the top level of a module"));
- }
+ public 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");
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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 com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
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.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-public class Bug6868Test {
+public 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 String FOO_NS = "foo";
private static final String IMP_NS = "imp";
private static final String IMP_REV = "2017-01-09";
@Test
public void invalidYang10Test() {
@Test
public void invalidYang10Test() {
- SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6868/invalid10.yang"));
- assertThat(ex.getCause().getMessage(), startsWith("Invalid identifier '(not foo) or (bar and baz)' [at "));
+ assertSourceException(startsWith("Invalid identifier '(not foo) or (bar and baz)' [at "),
+ "/rfc7950/bug6868/invalid10.yang");
}
}
\ No newline at end of file
}
}
\ No newline at end of file
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import org.junit.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.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug6880Test {
+public class Bug6880Test extends AbstractYangTest {
- public void valid10Test() throws Exception {
- final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6880/foo.yang");
- assertNotNull(schemaContext);
+ public void valid10Test() {
+ final var context = assertEffectiveModel("/rfc7950/bug6880/foo.yang");
- final DataSchemaNode findDataSchemaNode = schemaContext.findDataTreeChild(QName.create("foo", "my-leaf-list"))
+ final DataSchemaNode findDataSchemaNode = context.findDataTreeChild(QName.create("foo", "my-leaf-list"))
.orElse(null);
assertThat(findDataSchemaNode, instanceOf(LeafListSchemaNode.class));
final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
.orElse(null);
assertThat(findDataSchemaNode, instanceOf(LeafListSchemaNode.class));
final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
@Test
public void invalid10Test() {
@Test
public void invalid10Test() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/rfc7950/bug6880/invalid10.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("DEFAULT is not valid for LEAF_LIST"));
+ assertInvalidSubstatementException(startsWith("DEFAULT is not valid for LEAF_LIST"),
+ "/rfc7950/bug6880/invalid10.yang");
}
}
\ No newline at end of file
}
}
\ No newline at end of file
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.InputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class Bug9241Test {
+public class Bug9241Test extends AbstractYangTest {
- public void testImplicitInputAndOutputInAction() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug9241/foo.yang");
- assertNotNull(schemaContext);
+ public void testImplicitInputAndOutputInAction() {
+ final var context = assertEffectiveModel("/rfc7950/bug9241/foo.yang");
- final Module fooModule = schemaContext.findModule("foo", Revision.of("2017-10-13")).get();
+ final Module fooModule = context.findModule("foo", Revision.of("2017-10-13")).get();
final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(
fooModule.getQNameModule(), "action-cont"));
final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(
fooModule.getQNameModule(), "action-cont"));
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
*/
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.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Collection;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import java.util.Collection;
import org.junit.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.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class IdentityStatementTest {
+public class IdentityStatementTest extends AbstractYangTest {
- public void testMultipleBaseIdentities() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identity-stmt/foo.yang");
- assertNotNull(schemaContext);
+ public void testMultipleBaseIdentities() {
+ final var context = assertEffectiveModel("/rfc7950/identity-stmt/foo.yang");
- final Module foo = schemaContext.findModule("foo", Revision.of("2016-12-21")).get();
+ final Module foo = context.findModule("foo", Revision.of("2016-12-21")).get();
for (final IdentitySchemaNode identity : foo.getIdentities()) {
if ("derived-id".equals(identity.getQName().getLocalName())) {
final Collection<? extends IdentitySchemaNode> baseIdentities = identity.getBaseIdentities();
for (final IdentitySchemaNode identity : foo.getIdentities()) {
if ("derived-id".equals(identity.getQName().getLocalName())) {
final Collection<? extends IdentitySchemaNode> baseIdentities = identity.getBaseIdentities();
- public void testInvalidYang10() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/identity-stmt/foo10.yang");
- fail("Test should fail due to invalid Yang 1.0");
- } catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith("Maximal count of BASE for IDENTITY is 1, detected 3."));
- }
+ public void testInvalidYang10() {
+ assertInvalidSubstatementException(startsWith("Maximal count of BASE for IDENTITY is 1, detected 3."),
+ "/rfc7950/identity-stmt/foo10.yang");
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
+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.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Collection;
import java.util.Set;
import java.util.Collection;
import java.util.Set;
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.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.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class IdentityrefStatementTest {
+public class IdentityrefStatementTest extends AbstractYangTest {
- public void testIdentityrefWithMultipleBaseIdentities() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo.yang");
- assertNotNull(schemaContext);
+ public void testIdentityrefWithMultipleBaseIdentities() {
+ final var context = assertEffectiveModel("/rfc7950/identityref-stmt/foo.yang");
- final Module foo = schemaContext.findModule("foo", Revision.of("2017-01-11")).get();
+ final Module foo = context.findModule("foo", Revision.of("2017-01-11")).get();
final Collection<? extends IdentitySchemaNode> identities = foo.getIdentities();
assertEquals(3, identities.size());
final Collection<? extends IdentitySchemaNode> identities = foo.getIdentities();
assertEquals(3, identities.size());
- public void testInvalidYang10() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo10.yang");
- fail("Test should fail due to invalid Yang 1.0");
- } catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith("Maximal count of BASE for TYPE is 1, detected 3."));
- }
+ public void testInvalidYang10() {
+ assertInvalidSubstatementException(startsWith("Maximal count of BASE for TYPE is 1, detected 3."),
+ "/rfc7950/identityref-stmt/foo10.yang");
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
*/
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.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Collection;
import org.junit.Test;
import java.util.Collection;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.common.Revision;
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.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
-public class LeafrefStatementTest {
+public class LeafrefStatementTest extends AbstractYangTest {
- public void testRequireInstanceInLeafrefs() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/leafref-stmt/foo.yang");
- assertNotNull(schemaContext);
+ public void testRequireInstanceInLeafrefs() {
+ final var context = assertEffectiveModel("/rfc7950/leafref-stmt/foo.yang");
- final Module foo = schemaContext.findModule("foo", Revision.of("2016-12-20")).get();
+ final Module foo = context.findModule("foo", Revision.of("2016-12-20")).get();
final Collection<? extends TypeDefinition<?>> typeDefinitions = foo.getTypeDefinitions();
assertEquals(1, typeDefinitions.size());
final Collection<? extends TypeDefinition<?>> typeDefinitions = foo.getTypeDefinitions();
assertEquals(1, typeDefinitions.size());
- public void testInvalidYang10() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/rfc7950/leafref-stmt/foo10.yang");
- fail("Test should fail due to invalid Yang 1.0");
- } catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith("REQUIRE_INSTANCE is not valid for TYPE"));
- }
+ public void testInvalidYang10() {
+ assertInvalidSubstatementException(startsWith("REQUIRE_INSTANCE is not valid for TYPE"),
+ "/rfc7950/leafref-stmt/foo10.yang");
*/
package org.opendaylight.yangtools.yang.stmt;
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.startsWith;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-public class Bug7424Test {
+public class Bug7424Test extends AbstractYangTest {
- public void testRpc() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc.yang");
- fail("Test should fail due to invalid yang model.");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
- }
+ public void testRpc()throws Exception {
+ assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
+ + " '(foo)name' already declared"), "/bugs/bug7424/foo-rpc.yang");
- public void testNotification() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/bugs/bug7424/foo-notification.yang");
- fail("Test should fail due to invalid yang model.");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
- }
+ public void testNotification() {
+ assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
+ + " '(foo)name' already declared"), "/bugs/bug7424/foo-notification.yang");
- public void testData() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/bugs/bug7424/foo-data.yang");
- fail("Test should fail due to invalid yang model.");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
- }
+ public void testData() {
+ assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
+ + " '(foo)name' already declared"), "/bugs/bug7424/foo-data.yang");
- public void testRpcUses() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc-uses.yang");
- fail("Test should fail due to invalid yang model.");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getMessage().startsWith(
- "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
- }
+ public 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");
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
-public class Bug8922Test {
+public 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
private static final QName MY_CON = QName.create("foo", "my-con");
private static final QName TARGET = QName.create("foo", "target");
@Test
- public void testAllFeaturesSupported() throws Exception {
- final var context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang");
- assertNotNull(context);
+ public void testAllFeaturesSupported() {
+ final var context = assertEffectiveModel("/bugs/bug8922/foo.yang");
final var findNode = context.findDataTreeChild(TARGET, MY_CON).get();
assertThat(findNode, instanceOf(ContainerSchemaNode.class));
assertEquals(Optional.of("New description"), findNode.getDescription());
final var findNode = context.findDataTreeChild(TARGET, MY_CON).get();
assertThat(findNode, instanceOf(ContainerSchemaNode.class));
assertEquals(Optional.of("New description"), findNode.getDescription());
*/
package org.opendaylight.yangtools.yang.stmt;
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertThrows;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class NameCollisionWithinCaseTest {
+public class NameCollisionWithinCaseTest extends AbstractYangTest {
@Test
public void testChildNameCollisionOfAugmentCase() {
@Test
public void testChildNameCollisionOfAugmentCase() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/foo.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Cannot add data tree child with name (foo?revision=2018-02-11)bar, "
- + "a conflicting child already exists [at "));
+ 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");
}
@Test
public void testChildNameCollisionOfAugmentChoice() {
}
@Test
public void testChildNameCollisionOfAugmentChoice() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/bar.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Cannot add data tree child with name (bar?revision=2018-02-11)bar, "
- + "a conflicting child already exists [at "));
+ 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");
- public void testChildNameCollisionNormal() throws Exception {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/baz.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith(
- "Error in module 'baz': cannot add '(baz?revision=2018-02-28)bar'. Node name collision: "));
+ public 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");
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.Module;
import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.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;
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 {
+public class RpcStmtTest extends AbstractYangTest {
@Test
public void rpcTest() throws ReactorException {
final EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild()
@Test
public void rpcTest() throws ReactorException {
final EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild()
- public void testImplicitInputAndOutput() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rpc-stmt-test/bar.yang");
- assertNotNull(schemaContext);
+ public void testImplicitInputAndOutput() {
+ final var context = assertEffectiveModel("/rpc-stmt-test/bar.yang");
- final Module barModule = schemaContext.findModule("bar", Revision.of("2016-11-25")).get();
+ final Module barModule = context.findModule("bar", Revision.of("2016-11-25")).get();
final Collection<? extends RpcDefinition> rpcs = barModule.getRpcs();
assertEquals(1, rpcs.size());
final Collection<? extends RpcDefinition> rpcs = barModule.getRpcs();
assertEquals(1, rpcs.size());
*/
package org.opendaylight.yangtools.yang.stmt;
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertThrows;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class YT1189Test {
+public class YT1189Test extends AbstractYangTest {
@Test
public void testDescendantAugment() {
@Test
public void testDescendantAugment() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/bugs/YT1189/foo.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(),
- startsWith("Descendant schema node identifier is not allowed when used outside of a uses statement [at "));
+ assertSourceException(startsWith("Descendant schema node identifier is not allowed when used outside"
+ + " of a uses statement [at "), "/bugs/YT1189/foo.yang");
}
@Test
public void testAbsoluteUsesAugment() {
}
@Test
public void testAbsoluteUsesAugment() {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/bugs/YT1189/bar.yang"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(),
- startsWith("Absolute schema node identifier is not allowed when used within a uses statement [at "));
+ assertSourceException(startsWith("Absolute schema node identifier is not allowed when used within a"
+ + " uses statement [at "), "/bugs/YT1189/bar.yang");
*/
package org.opendaylight.yangtools.yang.stmt;
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class YT838Test {
+public class YT838Test extends AbstractYangTest {
@Test
public void testGroupingShadowing() {
testGrouping("grouping.yang");
@Test
public void testGroupingShadowing() {
testGrouping("grouping.yang");
}
private static void testGrouping(final String model) {
}
private static void testGrouping(final String model) {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
-
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(),
- startsWith("Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "));
+ assertSourceException(startsWith("Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "),
+ "/bugs/YT838/" + model);
}
private static void testTypedef(final String model) {
}
private static void testTypedef(final String model) {
- final ReactorException ex = assertThrows(ReactorException.class,
- () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
- final Throwable cause = ex.getCause();
- assertTrue(cause instanceof SourceException);
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(), startsWith("Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "));
+ assertSourceException(startsWith("Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "),
+ "/bugs/YT838/" + model);
*/
package org.opendaylight.yangtools.yang.stmt;
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.fail;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class YT857Test {
+public class YT857Test extends AbstractYangTest {
- public void testConflictDetection() throws Exception {
- try {
- StmtTestUtils.parseYangSource("/bugs/YT857/foo.yang");
- fail("Conflict on models should have been detected");
- } catch (ReactorException e) {
- final Throwable cause = e.getCause();
- assertThat(cause, instanceOf(SourceException.class));
- assertThat(cause.getMessage(),
- startsWith("Cannot add data tree child with name (foo)one, a conflicting child already exists"));
- }
+ public void testConflictDetection() {
+ assertSourceException(startsWith("Cannot add data tree child with name (foo)one, a conflicting"
+ + " child already exists"), "/bugs/YT857/foo.yang");
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import java.util.Optional;
import org.junit.Test;
import java.util.Optional;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
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.type.Int16TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
-public class YT971Test {
+public class YT971Test extends AbstractYangTest {
private static final QNameModule NAMESPACE = QNameModule.create(XMLNamespace.of("test"), Revision.of("2019-03-25"));
@Test
private static final QNameModule NAMESPACE = QNameModule.create(XMLNamespace.of("test"), Revision.of("2019-03-25"));
@Test
- public void testEscapeLexer() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/bugs/YT971/test.yang");
- assertNotNull(schemaContext);
+ public void testEscapeLexer() {
+ final var context = assertEffectiveModel("/bugs/YT971/test.yang");
- final DataSchemaNode someContainer = schemaContext.getDataChildByName(
+ final DataSchemaNode someContainer = context.getDataChildByName(
QName.create(NAMESPACE, "some-container"));
assertThat(someContainer, instanceOf(ContainerSchemaNode.class));
final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) someContainer;
QName.create(NAMESPACE, "some-container"));
assertThat(someContainer, instanceOf(ContainerSchemaNode.class));
final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) someContainer;