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.allOf;
11 import static org.hamcrest.CoreMatchers.containsString;
12 import static org.hamcrest.CoreMatchers.endsWith;
13 import static org.hamcrest.CoreMatchers.startsWith;
15 import org.junit.jupiter.api.Test;
17 class YangParserNegativeTest extends AbstractYangTest {
19 void testInvalidImport() {
20 assertInferenceException(allOf(startsWith("Imported module"), containsString("was not found.")),
21 "/negative-scenario/testfile1.yang");
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");
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");
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");
48 void testInvalidLength() {
49 assertSourceException(startsWith("Invalid length constraint [4..10]"),
50 "/negative-scenario/testfile5.yang");
54 void testInvalidRange() {
55 assertSourceException(startsWith("Invalid range constraint: [[5..20]]"),
56 "/negative-scenario/testfile6.yang");
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 "
64 "/negative-scenario/duplicity/container.yang");
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 "
72 "/negative-scenario/duplicity/container-list.yang");
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 "
80 "/negative-scenario/duplicity/container-leaf.yang");
84 void testDuplicateTypedef() {
85 assertSourceException(
86 startsWith("Duplicate name for typedef (urn:simple.container.demo)int-ext [at"),
87 "/negative-scenario/duplicity/typedef.yang");
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");
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");
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");
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");