Define a feature-parent
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug6669Test.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.hamcrest.CoreMatchers.startsWith;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12
13 import org.junit.jupiter.api.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
17
18 class Bug6669Test extends AbstractYangTest {
19     private static final String REV = "2016-09-08";
20     private static final String FOO_NS = "foo";
21     private static final String BAR_NS = "bar";
22     private static final QName ROOT = QName.create(FOO_NS, REV, "root");
23     private static final QName BAR = QName.create(BAR_NS, REV, "bar");
24     private static final QName BAR_1 = QName.create(BAR_NS, REV, "bar1");
25     private static final QName BAR_2 = QName.create(BAR_NS, REV, "bar2");
26     private static final QName M = QName.create(BAR_NS, REV, "m");
27
28     @Test
29     void testInvalidAugment() {
30         assertInferenceExceptionDir("/bugs/bug6669/invalid/test1", startsWith(
31             "An augment cannot add node 'm' because it is mandatory and in module different than target"));
32     }
33
34     @Test
35     void testInvalidAugment2() {
36         assertInferenceExceptionDir("/bugs/bug6669/invalid/test2", startsWith(
37             "An augment cannot add node 'm' because it is mandatory and in module different than target"));
38     }
39
40     @Test
41     void testInvalidAugment3() {
42         assertInferenceExceptionDir("/bugs/bug6669/invalid/test3", startsWith(
43             "An augment cannot add node 'l' because it is mandatory and in module different than target"));
44     }
45
46     @Test
47     void testValidAugment() {
48         final var context = assertEffectiveModelDir("/bugs/bug6669/valid/test1");
49         assertInstanceOf(LeafSchemaNode.class, context.findDataTreeChild(ROOT, BAR, BAR_1, M).orElseThrow());
50     }
51
52     @Test
53     void testValidAugment2() {
54         final var context = assertEffectiveModelDir("/bugs/bug6669/valid/test2");
55         assertInstanceOf(LeafSchemaNode.class, context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2, M).orElseThrow());
56     }
57
58     @Test
59     void testValidAugment3() throws Exception {
60         final var context = assertEffectiveModelDir("/bugs/bug6669/valid/test3");
61         assertInstanceOf(ListSchemaNode.class,
62             context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2, QName.create(BAR_NS, REV, "l")).orElseThrow());
63     }
64 }