blob: 1688d2d8f2482b51a6e3a5fa57ecf6838c2ad2fb [file] [log] [blame]
Vidyashree Ramab6248172016-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-Huaweid81eccb2016-06-01 14:30:22 +053035
Vidyashree Ramab6248172016-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 {
Bharat saraswale304c252016-08-16 20:56:20 +053041 // Now no exception should be thrown. logs should come.
Vidyashree Ramab6248172016-05-17 16:16:15 +053042 manager.getDataModel("src/test/resources/OrderedByStatement.yang");
43 }
44
45 /**
46 * Checks whether exception is thrown for anyxml statement.
47 */
48 @Test
49 public void processAnyXmlStatement() throws IOException, ParserException {
Bharat saraswale304c252016-08-16 20:56:20 +053050 // Now no exception should be thrown. logs should come.
Vidyashree Ramab6248172016-05-17 16:16:15 +053051 manager.getDataModel("src/test/resources/AnyxmlStatement.yang");
52 }
janani b3e357f62016-05-19 17:39:50 +053053
54 /**
55 * Checks whether exception is thrown when extra brace is added in the EOF.
56 */
57 @Test
58 public void processFileWithExtraBrace() throws IOException, ParserException {
59 thrown.expect(ParserException.class);
60 thrown.expectMessage("mismatched input '}' expecting <EOF>");
61 manager.getDataModel("src/test/resources/ProcessFileWithExtraBrace.yang");
62 }
63
64 /**
65 * Checks whether exception is thrown when leaf is given after module ends.
66 */
67 @Test
68 public void processFileWithExtraLeaf() throws IOException, ParserException {
69 thrown.expect(ParserException.class);
70 thrown.expectMessage("mismatched input 'leaf' expecting <EOF>");
71 manager.getDataModel("src/test/resources/ProcessFileWithExtraLeaf.yang");
72 }
73
74 /**
75 * Checks whether exception is thrown when extra brace is added in between the EOF.
76 */
77 @Test
78 public void processFileWithExtraBraceInBetween() throws IOException, ParserException {
79 thrown.expect(ParserException.class);
80 thrown.expectMessage("mismatched input 'container' expecting <EOF>");
81 manager.getDataModel("src/test/resources/ProcessFileWithExtraBraceInBetween.yang");
82 }
Vidyashree Ramab6248172016-05-17 16:16:15 +053083}