Bug 6867: Extend yang statement parser to support different yang versions
[yangtools.git] / yang / yang-parser-impl / 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 java.io.FileNotFoundException;
16 import java.net.URISyntaxException;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
21 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
23
24 public class Bug6867BasicTest {
25
26     @Test
27     public void valid10Test() throws ReactorException, SourceException, FileNotFoundException, URISyntaxException {
28         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/valid-10.yang");
29         assertNotNull(schemaContext);
30     }
31
32     @Test
33     public void valid11Test() throws ReactorException, SourceException, FileNotFoundException, URISyntaxException {
34         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/valid-11.yang");
35         assertNotNull(schemaContext);
36     }
37
38     @Test
39     public void invalid10Test() throws ReactorException, SourceException, FileNotFoundException, URISyntaxException {
40         try {
41             StmtTestUtils.parseYangSource("/rfc7950/basic-test/invalid-10.yang");
42             fail("Test should fail due to invalid Yang 1.0");
43         } catch (final SomeModifiersUnresolvedException e) {
44             assertTrue(e.getCause().getMessage().startsWith("NOTIFICATION is not valid for CONTAINER"));
45         }
46     }
47
48     @Test
49     public void invalid11Test() throws ReactorException, SourceException, FileNotFoundException, URISyntaxException {
50         try {
51             StmtTestUtils.parseYangSource("/rfc7950/basic-test/invalid-11.yang");
52             fail("Test should fail due to invalid Yang 1.1");
53         } catch (final SomeModifiersUnresolvedException e) {
54             assertTrue(e.getCause().getMessage().startsWith("RPC is not valid for CONTAINER"));
55         }
56     }
57
58     @Test
59     public void anyData11Test() throws ReactorException, SourceException, FileNotFoundException, URISyntaxException {
60         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/anydata-11.yang");
61         assertNotNull(schemaContext);
62     }
63
64     @Test
65     public void anyData10Test() throws ReactorException, SourceException, FileNotFoundException, URISyntaxException {
66         try {
67             StmtTestUtils.parseYangSource("/rfc7950/basic-test/anydata-10.yang");
68             fail("Test should fail due to invalid Yang 1.0");
69         } catch (final SomeModifiersUnresolvedException e) {
70             assertTrue(e.getCause().getMessage().startsWith("anydata is not a YANG statement or use of extension"));
71         }
72     }
73
74     @Test
75     public void yangModelTest() throws ReactorException, SourceException, FileNotFoundException, URISyntaxException {
76         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/model");
77         assertNotNull(schemaContext);
78     }
79
80     @Test
81     public void unsupportedVersionTest() throws ReactorException, SourceException, FileNotFoundException,
82             URISyntaxException {
83         try {
84             StmtTestUtils.parseYangSource("/rfc7950/basic-test/unsupported-version.yang");
85             fail("Test should fail due to unsupported Yang version");
86         } catch (final SomeModifiersUnresolvedException e) {
87             final Throwable cause = e.getCause();
88             assertNotNull(cause);
89             assertTrue(cause.getMessage().startsWith("Unsupported YANG version 2.3"));
90         }
91     }
92 }