blob: 874f8ed46602fc7da25dbeabf2a9ccb347df3fb4 [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();
35 /**
36 * Checks whether exception is thrown for ordered statement.
37 */
38 @Test
39 public void processOrderedByStatement() throws IOException, ParserException {
40 thrown.expect(ParserException.class);
41 thrown.expectMessage("YANG file error : \"ordered-by\" is not supported in current version, please check wiki" +
42 " for YANG utils road map.");
43 manager.getDataModel("src/test/resources/OrderedByStatement.yang");
44 }
45
46 /**
47 * Checks whether exception is thrown for anyxml statement.
48 */
49 @Test
50 public void processAnyXmlStatement() throws IOException, ParserException {
51 thrown.expect(ParserException.class);
52 thrown.expectMessage("YANG file error : \"anyxml\" is not supported.");
53 manager.getDataModel("src/test/resources/AnyxmlStatement.yang");
54 }
janani bdd1314f2016-05-19 17:39:50 +053055
56 /**
57 * Checks whether exception is thrown when extra brace is added in the EOF.
58 */
59 @Test
60 public void processFileWithExtraBrace() throws IOException, ParserException {
61 thrown.expect(ParserException.class);
62 thrown.expectMessage("mismatched input '}' expecting <EOF>");
63 manager.getDataModel("src/test/resources/ProcessFileWithExtraBrace.yang");
64 }
65
66 /**
67 * Checks whether exception is thrown when leaf is given after module ends.
68 */
69 @Test
70 public void processFileWithExtraLeaf() throws IOException, ParserException {
71 thrown.expect(ParserException.class);
72 thrown.expectMessage("mismatched input 'leaf' expecting <EOF>");
73 manager.getDataModel("src/test/resources/ProcessFileWithExtraLeaf.yang");
74 }
75
76 /**
77 * Checks whether exception is thrown when extra brace is added in between the EOF.
78 */
79 @Test
80 public void processFileWithExtraBraceInBetween() throws IOException, ParserException {
81 thrown.expect(ParserException.class);
82 thrown.expectMessage("mismatched input 'container' expecting <EOF>");
83 manager.getDataModel("src/test/resources/ProcessFileWithExtraBraceInBetween.yang");
84 }
Vidyashree Rama1db15562016-05-17 16:16:15 +053085}