If we end up with a single exception, do not wrap it in
InferenceException, as we want to correctly identify whether it is a
problem with the source or inference.
Change-Id: I9963ec5067145b5886a2bf20cba4bd8104794afe
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
- if (exceptions.isEmpty()) {
- return Optional.empty();
+ switch (exceptions.size()) {
+ case 0:
+ return Optional.empty();
+ case 1:
+ return Optional.of(exceptions.get(0));
+ default:
+ final String message = String.format("Yang model processing phase %s failed", identifier);
+ final InferenceException ex = new InferenceException(message, root, exceptions.get(0));
+ exceptions.listIterator(1).forEachRemaining(ex::addSuppressed);
+ return Optional.of(ex);
-
- final String message = String.format("Yang model processing phase %s failed", identifier);
- final InferenceException e = new InferenceException(message, root, exceptions.get(0));
- exceptions.listIterator(1).forEachRemaining(e::addSuppressed);
-
- return Optional.of(e);
}
void loadStatements() {
}
void loadStatements() {
*/
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.assertTrue;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
public class AugmentToExtensionTest extends AbstractYangTest {
@Test
public void testIncorrectPath() throws Exception {
public class AugmentToExtensionTest extends AbstractYangTest {
@Test
public void testIncorrectPath() throws Exception {
- // FIXME: this should not be here, or why do we need encapsulation? Add asserts for that
- final var cause = assertInferenceExceptionDir("/augment-to-extension-test/incorrect-path",
- startsWith("Yang model processing phase EFFECTIVE_MODEL failed [at "));
-
- final var firstCause = cause.getCause();
- assertThat(firstCause, instanceOf(InferenceException.class));
- assertThat(firstCause.getMessage(), startsWith("Augment target "
+ 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 "));
}
*/
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.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThrows;
-import java.util.Collection;
import org.junit.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.junit.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.parser.spi.meta.SomeModifiersUnresolvedException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class Bug6240Test {
+public class Bug6240Test extends AbstractYangTest {
private static final String NS = "bar";
private static final String REV = "2016-07-19";
@Test
public void testModels() throws Exception {
private static final String NS = "bar";
private static final String REV = "2016-07-19";
@Test
public void testModels() throws Exception {
- final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6240/correct");
- assertNotNull(context);
+ final var context = assertEffectiveModelDir("/bugs/bug6240/correct");
- final Collection<? extends Module> modules = context.getModules();
+ final var modules = context.getModules();
assertEquals(2, modules.size());
Module bar = null;
assertEquals(2, modules.size());
Module bar = null;
- assertTrue(bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")) instanceof ContainerSchemaNode);
- assertTrue(bar.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")) instanceof ContainerSchemaNode);
+ assertThat(bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")), instanceOf(ContainerSchemaNode.class));
+ 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"));
assertEquals(1, bar.getSubmodules().size());
final DataSchemaNode dataChildByName = bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con"));
- assertTrue(dataChildByName instanceof ContainerSchemaNode);
+ assertThat(dataChildByName, instanceOf(ContainerSchemaNode.class));
final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;
final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;
- assertTrue(subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")) instanceof ContainerSchemaNode);
- assertTrue(subBarCon.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con"))
- instanceof ContainerSchemaNode);
+ assertThat(subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")),
+ instanceOf(ContainerSchemaNode.class));
+ assertThat(subBarCon.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")),
+ instanceOf(ContainerSchemaNode.class));
- public void testInvalidModels() throws Exception {
- try {
- StmtTestUtils.parseYangSources("/bugs/bug6240/incorrect");
- } catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e.getCause().getCause().getMessage().startsWith(
- "Grouping '(bar?revision=2016-07-19)foo-imp-grp' was not resolved."));
- }
+ public void testInvalidModels() {
+ final var ex = assertThrows(SomeModifiersUnresolvedException.class,
+ () -> StmtTestUtils.parseYangSources("/bugs/bug6240/incorrect"));
+ final var cause = ex.getCause();
+ assertThat(cause, instanceOf(SourceException.class));
+ assertThat(cause.getMessage(), startsWith("Grouping '(bar?revision=2016-07-19)foo-imp-grp' was not resolved."));
final var ex = assertThrows(SomeModifiersUnresolvedException.class,
() -> parseYangSources("/bugs/bug7480/files-2", "/bugs/bug7480/lib-2"));
final String message = ex.getSuppressed().length > 0
final var ex = assertThrows(SomeModifiersUnresolvedException.class,
() -> parseYangSources("/bugs/bug7480/files-2", "/bugs/bug7480/lib-2"));
final String message = ex.getSuppressed().length > 0
- ? ex.getSuppressed()[0].getCause().getMessage() : ex.getCause().getCause().getMessage();
+ ? ex.getSuppressed()[0].getMessage() : ex.getCause().getMessage();
assertThat(message, startsWith("Imported module [missing-lib] was not found."));
}
assertThat(message, startsWith("Imported module [missing-lib] was not found."));
}
final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
"/deviation-resolution-test/foo-invalid-deviation-path.yang",
"/deviation-resolution-test/bar.yang"));
final ReactorException ex = assertThrows(ReactorException.class, () -> TestUtils.parseYangSource(
"/deviation-resolution-test/foo-invalid-deviation-path.yang",
"/deviation-resolution-test/bar.yang"));
- final Throwable cause = ex.getCause().getCause();
+ 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"));
assertThat(cause, instanceOf(InferenceException.class));
assertThat(cause.getMessage(), startsWith(
"Deviation target 'Absolute{qnames=[(bar?revision=2017-01-20)invalid, path]}' not found"));
public void borderCaseInvalidMajorTest() throws Exception {
final ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-major", SEMVER));
public void borderCaseInvalidMajorTest() throws Exception {
final ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-major", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(),
+ assertThat(ex.getCause().getMessage(),
startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
}
startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
}
public void borderCaseInvalidMinorTest() {
final ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-minor", SEMVER));
public void borderCaseInvalidMinorTest() {
final ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-minor", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(),
+ assertThat(ex.getCause().getMessage(),
startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
}
startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
}
public void borderCaseInvalidPatchTest() throws Exception {
final ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-patch", SEMVER));
public void borderCaseInvalidPatchTest() throws Exception {
final ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/border-case/border-case-invalid-patch", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(),
+ assertThat(ex.getCause().getMessage(),
startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
}
}
startsWith("Unable to find module compatible with requested import [bar(5.5.5)]."));
}
}
*/
package org.opendaylight.yangtools.yang.stmt.openconfigver;
*/
package org.opendaylight.yangtools.yang.stmt.openconfigver;
+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.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import java.util.Optional;
import org.junit.Test;
import org.opendaylight.yangtools.concepts.SemVer;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.Module;
import java.util.Optional;
import org.junit.Test;
import org.opendaylight.yangtools.concepts.SemVer;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.api.ImportResolutionMode;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.api.ImportResolutionMode;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
@Test
public void defaultsTest() throws Exception {
@Test
public void defaultsTest() throws Exception {
- SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/defaults", SEMVER);
+ final var context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/defaults", SEMVER);
assertNotNull(context);
Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
assertNotNull(context);
Module foo = context.findModules(XMLNamespace.of("foo")).iterator().next();
@Test
public void defaultMajorValidTest() throws Exception {
@Test
public void defaultMajorValidTest() throws Exception {
- SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-valid",
+ final var context = StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-valid",
SEMVER);
assertNotNull(context);
SEMVER);
assertNotNull(context);
@Test
public void defaultMajorInvalidTest() throws Exception {
@Test
public void defaultMajorInvalidTest() throws Exception {
- try {
- StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-invalid", SEMVER);
- fail("Test should fail due to invalid openconfig version");
- } catch (ReactorException e) {
- assertTrue(e.getCause().getCause().getMessage()
- .startsWith("Unable to find module compatible with requested import [bar(0.0.1)]."));
- }
+ final var ex = assertThrows(ReactorException.class,
+ () -> StmtTestUtils.parseYangSources("/openconfig-version/defaults/default-major-invalid", SEMVER));
+ assertThat(ex.getCause().getMessage(),
+ startsWith("Unable to find module compatible with requested import [bar(0.0.1)]."));
public void importInvalidDeprecatedTest1() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-1", SEMVER));
public void importInvalidDeprecatedTest1() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-1", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(), startsWith(
+ assertThat(ex.getCause().getMessage(), startsWith(
"Unable to find module compatible with requested import [openconfig-extensions(1.0.0)]."));
}
"Unable to find module compatible with requested import [openconfig-extensions(1.0.0)]."));
}
public void importInvalidDeprecatedTest2() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-2", SEMVER));
public void importInvalidDeprecatedTest2() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-deprecated-2", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(), startsWith(
+ assertThat(ex.getCause().getMessage(), startsWith(
"Unable to find module compatible with requested import [openconfig-extensions(0.9.9)]."));
}
"Unable to find module compatible with requested import [openconfig-extensions(0.9.9)]."));
}
public void importInvalidNotsufficientTest1() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-1", SEMVER));
public void importInvalidNotsufficientTest1() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-1", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(), startsWith(
+ assertThat(ex.getCause().getMessage(), startsWith(
"Unable to find module compatible with requested import [openconfig-extensions(2.0.0)]."));
}
"Unable to find module compatible with requested import [openconfig-extensions(2.0.0)]."));
}
public void importInvalidNotsufficientTest2() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-2", SEMVER));
public void importInvalidNotsufficientTest2() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/import/import-invalid-notsufficient-2", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(), startsWith(
+ assertThat(ex.getCause().getMessage(), startsWith(
"Unable to find module compatible with requested import [openconfig-extensions(2.0.5)]."));
}
}
"Unable to find module compatible with requested import [openconfig-extensions(2.0.5)]."));
}
}
- public void multipleInvalidDeprecatedTest() throws Exception {
+ public void multipleInvalidDeprecatedTest() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/multiple/multiple-invalid-deprecated", SEMVER));
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/multiple/multiple-invalid-deprecated", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(),
+ assertThat(ex.getCause().getMessage(),
startsWith("Unable to find module compatible with requested import [bar(1.0.0)]."));
}
@Test
startsWith("Unable to find module compatible with requested import [bar(1.0.0)]."));
}
@Test
- public void multipleInvalidNosufficientTest() throws Exception {
+ public void multipleInvalidNosufficientTest() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/multiple/multiple-invalid-nosufficient", SEMVER));
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/multiple/multiple-invalid-nosufficient", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(),
+ assertThat(ex.getCause().getMessage(),
startsWith("Unable to find module compatible with requested import [bar(2.5.5)]."));
}
startsWith("Unable to find module compatible with requested import [bar(2.5.5)]."));
}
- public void basicImportErrTest1() throws Exception {
+ public void basicImportErrTest1() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/basic-import-invalid-1", SEMVER));
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/basic-import-invalid-1", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(),
+ assertThat(ex.getCause().getMessage(),
startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));
}
@Test
startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));
}
@Test
- public void basicImportErrTest2() throws Exception {
+ public void basicImportErrTest2() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/basic-import-invalid-2", SEMVER));
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYangSources("/openconfig-version/basic-import-invalid-2", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(),
+ assertThat(ex.getCause().getMessage(),
startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));
}
startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));
}
- public void basicImportErrTest1() throws URISyntaxException, SAXException, IOException {
+ public void basicImportErrTest1() {
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import-invalid", SEMVER));
ReactorException ex = assertThrows(ReactorException.class,
() -> StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import-invalid", SEMVER));
- assertThat(ex.getCause().getCause().getMessage(),
+ assertThat(ex.getCause().getMessage(),
startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));
}
}
startsWith("Unable to find module compatible with requested import [bar(0.1.2)]."));
}
}