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 / Bug6867BasicTest.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
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 Bug6867BasicTest {
21
22     @Test
23     public void valid10Test() throws Exception {
24         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/valid-10.yang");
25         assertNotNull(schemaContext);
26     }
27
28     @Test
29     public void valid11Test() throws Exception {
30         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/valid-11.yang");
31         assertNotNull(schemaContext);
32     }
33
34     @Test
35     public void invalid10Test() throws Exception {
36         try {
37             StmtTestUtils.parseYangSource("/rfc7950/basic-test/invalid-10.yang");
38             fail("Test should fail due to invalid Yang 1.0");
39         } catch (final SomeModifiersUnresolvedException e) {
40             assertTrue(e.getCause().getMessage().startsWith("NOTIFICATION is not valid for CONTAINER"));
41         }
42     }
43
44     @Test
45     public void invalid11Test() throws Exception {
46         try {
47             StmtTestUtils.parseYangSource("/rfc7950/basic-test/invalid-11.yang");
48             fail("Test should fail due to invalid Yang 1.1");
49         } catch (final SomeModifiersUnresolvedException e) {
50             assertTrue(e.getCause().getMessage().startsWith("RPC is not valid for CONTAINER"));
51         }
52     }
53
54     @Test
55     public void anyData11Test() throws Exception {
56         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/anydata-11.yang");
57         assertNotNull(schemaContext);
58     }
59
60     @Test
61     public void anyData10Test() throws Exception {
62         try {
63             StmtTestUtils.parseYangSource("/rfc7950/basic-test/anydata-10.yang");
64             fail("Test should fail due to invalid Yang 1.0");
65         } catch (final SomeModifiersUnresolvedException e) {
66             assertTrue(e.getCause().getMessage().startsWith("anydata is not a YANG statement or use of extension"));
67         }
68     }
69
70     @Test
71     public void yangModelTest() throws Exception {
72         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/model");
73         assertNotNull(schemaContext);
74     }
75
76     @Test
77     public void unsupportedVersionTest() throws Exception {
78         try {
79             StmtTestUtils.parseYangSource("/rfc7950/basic-test/unsupported-version.yang");
80             fail("Test should fail due to unsupported Yang version");
81         } catch (final SomeModifiersUnresolvedException e) {
82             final Throwable cause = e.getCause();
83             assertNotNull(cause);
84             assertTrue(cause.getMessage().startsWith("Unsupported YANG version 2.3"));
85         }
86     }
87 }