Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YangParserNegativeTest.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.allOf;
11 import static org.hamcrest.CoreMatchers.containsString;
12 import static org.hamcrest.CoreMatchers.endsWith;
13 import static org.hamcrest.CoreMatchers.startsWith;
14
15 import org.junit.jupiter.api.Test;
16
17 class YangParserNegativeTest extends AbstractYangTest {
18     @Test
19     void testInvalidImport() {
20         assertInferenceException(allOf(startsWith("Imported module"), containsString("was not found.")),
21             "/negative-scenario/testfile1.yang");
22     }
23
24     @Test
25     void testTypeNotFound() {
26         assertInferenceException(
27             startsWith("Type [(urn:simple.types.data.demo?revision=2013-02-27)int-ext] was not found."),
28             "/negative-scenario/testfile2.yang");
29     }
30
31     @Test
32     void testInvalidAugmentTarget() {
33         assertInferenceException(
34             startsWith("Augment target 'Absolute{qnames=[(urn:simple.container.demo)unknown]}' not found"),
35             "/negative-scenario/testfile0.yang", "/negative-scenario/testfile3.yang");
36     }
37
38     @Test
39     void testInvalidRefine() {
40         assertSourceException(
41             containsString("Error in module 'test4' in the refine of uses "
42             + "'Descendant{qnames=[(urn:simple.container.demo)node]}': can not perform refine of 'PRESENCE' for"
43             + " the target 'LEAF_LIST'."),
44             "/negative-scenario/testfile4.yang");
45     }
46
47     @Test
48     void testInvalidLength() {
49         assertSourceException(startsWith("Invalid length constraint [4..10]"),
50             "/negative-scenario/testfile5.yang");
51     }
52
53     @Test
54     void testInvalidRange() {
55         assertSourceException(startsWith("Invalid range constraint: [[5..20]]"),
56             "/negative-scenario/testfile6.yang");
57     }
58
59     @Test
60     void testDuplicateContainer() {
61         assertSourceException(startsWith("Error in module 'container': cannot add "
62             + "'(urn:simple.container.demo)foo'. Node name collision: '(urn:simple.container.demo)foo' already "
63             + "declared"),
64             "/negative-scenario/duplicity/container.yang");
65     }
66
67     @Test
68     void testDuplicateContainerList() {
69         assertSourceException(startsWith("Error in module 'container-list': cannot add "
70             + "'(urn:simple.container.demo)foo'. Node name collision: '(urn:simple.container.demo)foo' already "
71             + "declared"),
72             "/negative-scenario/duplicity/container-list.yang");
73     }
74
75     @Test
76     void testDuplicateContainerLeaf() {
77         assertSourceException(startsWith("Error in module 'container-leaf': cannot add "
78             + "'(urn:simple.container.demo)foo'. Node name collision: '(urn:simple.container.demo)foo' already "
79             + "declared"),
80             "/negative-scenario/duplicity/container-leaf.yang");
81     }
82
83     @Test
84     void testDuplicateTypedef() {
85         assertSourceException(
86             startsWith("Duplicate name for typedef (urn:simple.container.demo)int-ext [at"),
87             "/negative-scenario/duplicity/typedef.yang");
88     }
89
90     @Test
91     void testDuplicityInAugmentTarget1() {
92         assertInferenceException(
93             startsWith("An augment cannot add node named 'id' because this name is already used in target"),
94             "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment1.yang");
95     }
96
97     @Test
98     void testDuplicityInAugmentTarget2() {
99         assertSourceException(allOf(
100             startsWith("Error in module 'augment0': cannot add "
101                 + "'(urn:simple.augment2.demo?revision=2014-06-02)delta'. Node name collision: "
102                 + "'(urn:simple.augment2.demo?revision=2014-06-02)delta' already declared at "),
103             endsWith("duplicity/augment2.yang:17:9]")),
104             "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment2.yang");
105     }
106
107     @Test
108     void testMandatoryInAugment() {
109         assertInferenceException(startsWith(
110             "An augment cannot add node 'linkleaf' because it is mandatory and in module different than target"),
111             "/negative-scenario/testfile8.yang", "/negative-scenario/testfile7.yang");
112     }
113
114     @Test
115     void testInvalidListKeyDefinition() {
116         assertInferenceException(startsWith(
117             "Key 'rib-id' misses node 'rib-id' in list '(invalid:list:key:def)application-map'"),
118             "/negative-scenario/invalid-list-key-def.yang");
119     }
120 }