Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.yangutils.parser.impl; |
| 18 | |
| 19 | import java.io.IOException; |
| 20 | |
| 21 | import org.junit.Rule; |
| 22 | import org.junit.Test; |
| 23 | import org.junit.rules.ExpectedException; |
| 24 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 25 | |
| 26 | /** |
| 27 | * Test cases for testing tree walk listener functionality. |
| 28 | */ |
| 29 | public class TreeWalkListenerTest { |
| 30 | |
| 31 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 32 | |
| 33 | @Rule |
| 34 | public ExpectedException thrown = ExpectedException.none(); |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 35 | |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 36 | /** |
| 37 | * Checks whether exception is thrown for ordered statement. |
| 38 | */ |
| 39 | @Test |
| 40 | public void processOrderedByStatement() throws IOException, ParserException { |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 41 | // Now no exception should be thrown. logs should come. |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 42 | 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 saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 50 | // Now no exception should be thrown. logs should come. |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 51 | manager.getDataModel("src/test/resources/AnyxmlStatement.yang"); |
| 52 | } |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 53 | |
| 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 Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 83 | } |