2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertThrows;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 public class Bug6669Test {
26 private static final String REV = "2016-09-08";
27 private static final String FOO_NS = "foo";
28 private static final String BAR_NS = "bar";
29 private static final QName ROOT = QName.create(FOO_NS, REV, "root");
30 private static final QName BAR = QName.create(BAR_NS, REV, "bar");
31 private static final QName BAR_1 = QName.create(BAR_NS, REV, "bar1");
32 private static final QName BAR_2 = QName.create(BAR_NS, REV, "bar2");
33 private static final QName M = QName.create(BAR_NS, REV, "m");
36 public void testInvalidAugment() {
37 final ReactorException ex = assertThrows(ReactorException.class,
38 () -> StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test1"));
39 final Throwable cause = ex.getCause();
40 assertThat(cause, instanceOf(InferenceException.class));
41 assertThat(cause.getMessage(), startsWith(
42 "An augment cannot add node 'm' because it is mandatory and in module different than target"));
46 public void testInvalidAugment2() {
47 final ReactorException ex = assertThrows(ReactorException.class,
48 () -> StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test2"));
49 final Throwable cause = ex.getCause();
50 assertThat(cause, instanceOf(InferenceException.class));
51 assertThat(cause.getMessage(), startsWith(
52 "An augment cannot add node 'm' because it is mandatory and in module different than target"));
56 public void testInvalidAugment3() {
57 final ReactorException ex = assertThrows(ReactorException.class,
58 () -> StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test3"));
59 final Throwable cause = ex.getCause();
60 assertThat(cause, instanceOf(InferenceException.class));
61 assertThat(cause.getMessage(), startsWith(
62 "An augment cannot add node 'l' because it is mandatory and in module different than target"));
66 public void testValidAugment() throws Exception {
67 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test1");
68 assertNotNull(context);
70 final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, M).get();
71 assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
75 public void testValidAugment2() throws Exception {
76 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test2");
77 assertNotNull(context);
79 final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2, M).get();
80 assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
84 public void testValidAugment3() throws Exception {
85 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test3");
86 assertNotNull(context);
88 final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2,
89 QName.create(BAR_NS, REV, "l")).get();
90 assertThat(findDataSchemaNode, instanceOf(ListSchemaNode.class));