blob: 1056d98fef346a57d4c28080831037f4a973540c [file] [log] [blame]
Vidyashree Rama1db15562016-05-17 16:16:15 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yangutils.parser.impl;
18
19import java.io.IOException;
20
21import org.junit.Rule;
22import org.junit.Test;
23import org.junit.rules.ExpectedException;
24import org.onosproject.yangutils.parser.exceptions.ParserException;
25
26/**
27 * Test cases for testing tree walk listener functionality.
28 */
29public class TreeWalkListenerTest {
30
31 private final YangUtilsParserManager manager = new YangUtilsParserManager();
32
33 @Rule
34 public ExpectedException thrown = ExpectedException.none();
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053035
Vidyashree Rama1db15562016-05-17 16:16:15 +053036 /**
37 * Checks whether exception is thrown for ordered statement.
38 */
39 @Test
40 public void processOrderedByStatement() throws IOException, ParserException {
41 thrown.expect(ParserException.class);
42 thrown.expectMessage("YANG file error : \"ordered-by\" is not supported in current version, please check wiki" +
43 " for YANG utils road map.");
44 manager.getDataModel("src/test/resources/OrderedByStatement.yang");
45 }
46
47 /**
48 * Checks whether exception is thrown for anyxml statement.
49 */
50 @Test
51 public void processAnyXmlStatement() throws IOException, ParserException {
52 thrown.expect(ParserException.class);
53 thrown.expectMessage("YANG file error : \"anyxml\" is not supported.");
54 manager.getDataModel("src/test/resources/AnyxmlStatement.yang");
55 }
janani bdd1314f2016-05-19 17:39:50 +053056
57 /**
58 * Checks whether exception is thrown when extra brace is added in the EOF.
59 */
60 @Test
61 public void processFileWithExtraBrace() throws IOException, ParserException {
62 thrown.expect(ParserException.class);
63 thrown.expectMessage("mismatched input '}' expecting <EOF>");
64 manager.getDataModel("src/test/resources/ProcessFileWithExtraBrace.yang");
65 }
66
67 /**
68 * Checks whether exception is thrown when leaf is given after module ends.
69 */
70 @Test
71 public void processFileWithExtraLeaf() throws IOException, ParserException {
72 thrown.expect(ParserException.class);
73 thrown.expectMessage("mismatched input 'leaf' expecting <EOF>");
74 manager.getDataModel("src/test/resources/ProcessFileWithExtraLeaf.yang");
75 }
76
77 /**
78 * Checks whether exception is thrown when extra brace is added in between the EOF.
79 */
80 @Test
81 public void processFileWithExtraBraceInBetween() throws IOException, ParserException {
82 thrown.expect(ParserException.class);
83 thrown.expectMessage("mismatched input 'container' expecting <EOF>");
84 manager.getDataModel("src/test/resources/ProcessFileWithExtraBraceInBetween.yang");
85 }
Vidyashree Rama1db15562016-05-17 16:16:15 +053086}