blob: fbe961b66de9b46c9b9e259e5bee219ad7527582 [file] [log] [blame]
Gaurav Agrawal2737d2a2016-02-13 14:23:40 +05301/*
Brian O'Connor0f7908b2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawal2737d2a2016-02-13 14:23:40 +05303 *
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.listeners;
18
19import org.junit.Rule;
20import org.junit.Test;
21import org.junit.rules.ExpectedException;
22import org.onosproject.yangutils.datamodel.YangModule;
VinodKumarS-Huawei0ab06da2016-08-20 22:04:59 +053023import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaModule;
Gaurav Agrawal2737d2a2016-02-13 14:23:40 +053024import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
25import org.onosproject.yangutils.parser.exceptions.ParserException;
26import org.onosproject.yangutils.parser.impl.TreeWalkListener;
27
28/**
29 * Test cases for testing base rule listener functionality.
30 */
31public 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-Huawei0ab06da2016-08-20 22:04:59 +053045 YangModule tmpModule = new YangJavaModule();
Gaurav Agrawal2737d2a2016-02-13 14:23:40 +053046 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-Huawei0ab06da2016-08-20 22:04:59 +053099 YangModule tmpModule = new YangJavaModule();
100 YangModule tmpModule2 = new YangJavaModule();
Gaurav Agrawal2737d2a2016-02-13 14:23:40 +0530101 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-Huawei0ab06da2016-08-20 22:04:59 +0530107}