Further yang-parser-impl checkstyle fixes
[yangtools.git] / yang / yang-parser-impl / 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?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature "
36                             + "statement."));
37         }
38     }
39
40     @Test
41     public void ifFeatureOnDefaultValueEnumTest2() throws Exception {
42         try {
43             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum-2.yang");
44             fail("Test should fail due to invalid Yang 1.1");
45         } catch (final SomeModifiersUnresolvedException e) {
46             assertTrue(e.getCause().getMessage().startsWith(
47                     "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature "
48                             + "statement."));
49         }
50     }
51
52     @Test
53     public void ifFeatureOnDefaultValueEnumTest3() throws Exception {
54         try {
55             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum-3.yang");
56             fail("Test should fail due to invalid Yang 1.1");
57         } catch (final SomeModifiersUnresolvedException e) {
58             assertTrue(e.getCause().getMessage().startsWith(
59                     "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature "
60                             + "statement."));
61         }
62     }
63
64     @Test
65     public void ifFeatureOnDefaultValueBitTest() throws Exception {
66         try {
67             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-bit.yang");
68             fail("Test should fail due to invalid Yang 1.1");
69         } catch (final SomeModifiersUnresolvedException e) {
70             assertTrue(e.getCause().getMessage().startsWith(
71                     "Typedef '(foo?revision=1970-01-01)bits-typedef-2' has default value 'two' marked with an "
72                             + "if-feature statement."));
73         }
74     }
75
76     @Test
77     public void ifFeatureOnDefaultValueUnionTest() throws Exception {
78         try {
79             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-union.yang");
80             fail("Test should fail due to invalid Yang 1.1");
81         } catch (final SomeModifiersUnresolvedException e) {
82             assertTrue(e.getCause().getMessage().startsWith(
83                     "Leaf '(foo?revision=1970-01-01)union-leaf' has default value 'two' marked with an if-feature "
84                             + "statement."));
85         }
86     }
87
88     @Test
89     public void unsupportedFeatureTest() throws Exception {
90         try {
91             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum.yang");
92             fail("Test should fail due to invalid Yang 1.1");
93         } catch (final SomeModifiersUnresolvedException e) {
94             assertTrue(
95                     e.getCause().getMessage().contains("has default value 'two' marked with an if-feature statement"));
96         }
97     }
98
99     @Test
100     public void ifFeature10EnumTest() throws Exception {
101         try {
102             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-10-enum.yang");
103             fail("Test should fail due to invalid Yang 1.0");
104         } catch (final SomeModifiersUnresolvedException e) {
105             assertTrue(e.getCause().getMessage().startsWith("IF_FEATURE is not valid for ENUM"));
106         }
107     }
108
109     @Test
110     public void ifFeature10BitTest() throws Exception {
111         try {
112             StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-10-bit.yang");
113             fail("Test should fail due to invalid Yang 1.0");
114         } catch (final SomeModifiersUnresolvedException e) {
115             assertTrue(e.getCause().getMessage().startsWith("IF_FEATURE is not valid for BIT"));
116         }
117     }
118 }