Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 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.listeners; |
| 18 | |
| 19 | import org.junit.Rule; |
| 20 | import org.junit.Test; |
| 21 | import org.junit.rules.ExpectedException; |
| 22 | import org.onosproject.yangutils.datamodel.YangModule; |
VinodKumarS-Huawei | 0ab06da | 2016-08-20 22:04:59 +0530 | [diff] [blame^] | 23 | import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaModule; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
| 25 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 26 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
| 27 | |
| 28 | /** |
| 29 | * Test cases for testing base rule listener functionality. |
| 30 | */ |
| 31 | public class BaseFileListenerTest { |
| 32 | |
| 33 | @Rule |
| 34 | public ExpectedException thrown = ExpectedException.none(); |
| 35 | |
| 36 | /** |
| 37 | * Checks for exception if stack of parsable data is not empty at the entry |
| 38 | * of yang base rule. |
| 39 | */ |
| 40 | @Test |
| 41 | public void processYangFileEntryNonEmptyStack() { |
| 42 | thrown.expect(ParserException.class); |
| 43 | thrown.expectMessage("Internal parser error detected: Invalid holder for yangbase before processing."); |
| 44 | |
VinodKumarS-Huawei | 0ab06da | 2016-08-20 22:04:59 +0530 | [diff] [blame^] | 45 | YangModule tmpModule = new YangJavaModule(); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 46 | TreeWalkListener listener = new TreeWalkListener(); |
| 47 | listener.getParsedDataStack().push(tmpModule); |
| 48 | GeneratedYangParser.YangfileContext ctx = null; |
| 49 | BaseFileListener.processYangFileEntry(listener, ctx); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Checks that exception shouldn't be generated if stack of parsable data is |
| 54 | * empty at the entry of yang base rule. |
| 55 | */ |
| 56 | @Test |
| 57 | public void processYangFileEntryEmptyStack() { |
| 58 | |
| 59 | TreeWalkListener listener = new TreeWalkListener(); |
| 60 | GeneratedYangParser.YangfileContext ctx = null; |
| 61 | BaseFileListener.processYangFileEntry(listener, ctx); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Checks that exception should be generated if stack of parsable data is |
| 66 | * not empty at the exit of yang base rule. |
| 67 | */ |
| 68 | @Test |
| 69 | public void processYangFileExitEmptyStack() { |
| 70 | thrown.expect(ParserException.class); |
| 71 | thrown.expectMessage("Internal parser error detected: Missing holder at yangbase after processing."); |
| 72 | |
| 73 | TreeWalkListener listener = new TreeWalkListener(); |
| 74 | GeneratedYangParser.YangfileContext ctx = null; |
| 75 | BaseFileListener.processYangFileExit(listener, ctx); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Checks that exception shouldn't be generated if stack of parsable data is |
| 80 | * empty at the exit of yang base rule. |
| 81 | */ |
| 82 | @Test |
| 83 | public void processYangFileExitNonEmptyStack() { |
| 84 | |
| 85 | TreeWalkListener listener = new TreeWalkListener(); |
| 86 | GeneratedYangParser.YangfileContext ctx = null; |
| 87 | BaseFileListener.processYangFileEntry(listener, ctx); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Checks that after popping out the parsable node from stack it should be |
| 92 | * empty. |
| 93 | */ |
| 94 | @Test |
| 95 | public void processYangFileExitStackErrorExtraEntryTest() { |
| 96 | thrown.expect(ParserException.class); |
| 97 | thrown.expectMessage("Internal parser error detected: Invalid holder for yangbase after processing."); |
| 98 | |
VinodKumarS-Huawei | 0ab06da | 2016-08-20 22:04:59 +0530 | [diff] [blame^] | 99 | YangModule tmpModule = new YangJavaModule(); |
| 100 | YangModule tmpModule2 = new YangJavaModule(); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 101 | TreeWalkListener listener = new TreeWalkListener(); |
| 102 | listener.getParsedDataStack().push(tmpModule); |
| 103 | listener.getParsedDataStack().push(tmpModule2); |
| 104 | GeneratedYangParser.YangfileContext ctx = null; |
| 105 | BaseFileListener.processYangFileExit(listener, ctx); |
| 106 | } |
VinodKumarS-Huawei | 0ab06da | 2016-08-20 22:04:59 +0530 | [diff] [blame^] | 107 | } |