From: Robert Varga Date: Wed, 12 Feb 2020 17:53:24 +0000 (+0100) Subject: Enable test for invalid leafrefs X-Git-Tag: v4.0.8~36 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=37b509c25252593e4a695219f3e54ce4da03ab6d;p=yangtools.git Enable test for invalid leafrefs This refactors the ignored test to correctly assert what we are doing and enables it. Change-Id: I9be5ff3a7b419596ed3bc11dd4d05885c0927192 Signed-off-by: Robert Varga --- diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java index 1ca9962e58..f8be448b1d 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java @@ -7,17 +7,20 @@ */ package org.opendaylight.yangtools.yang.data.impl.leafref.context; +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 java.util.List; import java.util.Set; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; @@ -26,6 +29,9 @@ import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils; 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.parser.api.YangParserException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -216,10 +222,16 @@ public class LeafRefContextTreeBuilderTest { assertTrue(allChildsReferencedByLeafRef.isEmpty()); } - @Test(expected = IllegalArgumentException.class) - @Ignore + @Test public void incorrectLeafRefPathTest() { - LeafRefContext.create( - YangParserTestUtils.parseYangResourceDirectory("/leafref-context-test/incorrect-modules")); + final IllegalStateException ise = assertThrows(IllegalStateException.class, + () -> YangParserTestUtils.parseYangResourceDirectory("/leafref-context-test/incorrect-modules")); + final Throwable ype = ise.getCause(); + assertThat(ype, instanceOf(YangParserException.class)); + final Throwable reactor = ype.getCause(); + assertThat(reactor, instanceOf(ReactorException.class)); + final Throwable source = reactor.getCause(); + assertThat(source, instanceOf(SourceException.class)); + assertThat(source.getMessage(), startsWith("token recognition error at: './' at 1:2")); } }