*/
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.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
public class Bug6669Test {
private static final String REV = "2016-09-08";
private static final QName BAR_1 = QName.create(BAR_NS, REV, "bar1");
private static final QName BAR_2 = QName.create(BAR_NS, REV, "bar2");
private static final QName M = QName.create(BAR_NS, REV, "m");
- private static final QName L = QName.create(BAR_NS, REV, "l");
@Test
- public void testInvalidAugment() throws Exception {
- final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test1");
- assertNotNull(context);
-
- final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
- SchemaPath.create(true, ROOT, BAR, BAR_1, M));
- assertNull(findDataSchemaNode);
+ public void testInvalidAugment() {
+ final ReactorException ex = assertThrows(ReactorException.class,
+ () -> StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test1"));
+ final Throwable cause = ex.getCause();
+ assertThat(cause, instanceOf(InferenceException.class));
+ assertThat(cause.getMessage(), startsWith(
+ "An augment cannot add node 'm' because it is mandatory and in module different than target"));
}
@Test
- public void testInvalidAugment2() throws Exception {
- final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test2");
- assertNotNull(context);
-
- final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
- SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, M));
- assertNull(findDataSchemaNode);
+ public void testInvalidAugment2() {
+ final ReactorException ex = assertThrows(ReactorException.class,
+ () -> StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test2"));
+ final Throwable cause = ex.getCause();
+ assertThat(cause, instanceOf(InferenceException.class));
+ assertThat(cause.getMessage(), startsWith(
+ "An augment cannot add node 'm' because it is mandatory and in module different than target"));
}
@Test
- public void testInvalidAugment3() throws Exception {
- final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test3");
- assertNotNull(context);
-
- final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
- SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, L));
- assertNull(findDataSchemaNode);
+ public void testInvalidAugment3() {
+ final ReactorException ex = assertThrows(ReactorException.class,
+ () -> StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test3"));
+ final Throwable cause = ex.getCause();
+ assertThat(cause, instanceOf(InferenceException.class));
+ assertThat(cause.getMessage(), startsWith(
+ "An augment cannot add node 'l' because it is mandatory and in module different than target"));
}
@Test
assertNotNull(context);
final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
- SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, L));
+ SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, QName.create(BAR_NS, REV, "l")));
assertTrue(findDataSchemaNode instanceof ListSchemaNode);
}
}