Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug6901Test.java
1 /*
2  * Copyright (c) 2017 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
18 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
19
20 public class Bug6901Test {
21
22     @Test
23     public void ifFeature11EnumBitTest() throws Exception {
24         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6901/foo.yang");
25         assertNotNull(schemaContext);
26     }
27
28     @Test
29     public void ifFeatureOnDefaultValueEnumTest() throws Exception {
30         try {
31             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum.yang");
32             fail("Test should fail due to invalid Yang 1.1");
33         } catch (final SomeModifiersUnresolvedException e) {
34             assertTrue(e.getCause().getMessage().startsWith(
35                     "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
36         }
37     }
38
39     @Test
40     public void ifFeatureOnDefaultValueEnumTest2() throws Exception {
41         try {
42             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum-2.yang");
43             fail("Test should fail due to invalid Yang 1.1");
44         } catch (final SomeModifiersUnresolvedException e) {
45             assertTrue(e.getCause().getMessage().startsWith(
46                     "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
47         }
48     }
49
50     @Test
51     public void ifFeatureOnDefaultValueEnumTest3() throws Exception {
52         try {
53             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum-3.yang");
54             fail("Test should fail due to invalid Yang 1.1");
55         } catch (final SomeModifiersUnresolvedException e) {
56             assertTrue(e.getCause().getMessage().startsWith(
57                     "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
58         }
59     }
60
61     @Test
62     public void ifFeatureOnDefaultValueBitTest() throws Exception {
63         try {
64             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-bit.yang");
65             fail("Test should fail due to invalid Yang 1.1");
66         } catch (final SomeModifiersUnresolvedException e) {
67             assertTrue(e.getCause().getMessage().startsWith(
68                     "Typedef '(foo)bits-typedef-2' has default value 'two' marked with an if-feature statement."));
69         }
70     }
71
72     @Test
73     public void ifFeatureOnDefaultValueUnionTest() throws Exception {
74         try {
75             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-union.yang");
76             fail("Test should fail due to invalid Yang 1.1");
77         } catch (final SomeModifiersUnresolvedException e) {
78             assertTrue(e.getCause().getMessage().startsWith(
79                     "Leaf '(foo)union-leaf' has default value 'two' marked with an if-feature statement."));
80         }
81     }
82
83     @Test
84     public void unsupportedFeatureTest() throws Exception {
85         try {
86             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum.yang");
87             fail("Test should fail due to invalid Yang 1.1");
88         } catch (final SomeModifiersUnresolvedException e) {
89             assertTrue(
90                     e.getCause().getMessage().contains("has default value 'two' marked with an if-feature statement"));
91         }
92     }
93
94     @Test
95     public void ifFeature10EnumTest() throws Exception {
96         try {
97             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-10-enum.yang");
98             fail("Test should fail due to invalid Yang 1.0");
99         } catch (final SomeModifiersUnresolvedException e) {
100             assertTrue(e.getCause().getMessage().startsWith("IF_FEATURE is not valid for ENUM"));
101         }
102     }
103
104     @Test
105     public void ifFeature10BitTest() throws Exception {
106         try {
107             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-10-bit.yang");
108             fail("Test should fail due to invalid Yang 1.0");
109         } catch (final SomeModifiersUnresolvedException e) {
110             assertTrue(e.getCause().getMessage().startsWith("IF_FEATURE is not valid for BIT"));
111         }
112     }
113 }