Enable test for invalid leafrefs 46/87646/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 12 Feb 2020 17:53:24 +0000 (18:53 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 12 Feb 2020 19:58:06 +0000 (20:58 +0100)
This refactors the ignored test to correctly assert what we are
doing and enables it.

Change-Id: I9be5ff3a7b419596ed3bc11dd4d05885c0927192
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java

index 1ca9962e5896ec62207d3de38dc0c7e31e882337..f8be448b1d590a40b60527fe796a5272c3344d6e 100644 (file)
@@ -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"));
     }
 }