blob: ef89a78367b426c6c38e8d71a1fff9e0c3c33812 [file] [log] [blame]
Gaurav Agrawala04483c2016-02-13 14:23:40 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawala04483c2016-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.Test;
20import org.onosproject.yangutils.datamodel.YangModule;
21import org.onosproject.yangutils.datamodel.YangNode;
22import org.onosproject.yangutils.parser.exceptions.ParserException;
23import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
24
25import java.io.IOException;
26
27import static org.hamcrest.core.Is.is;
28import static org.junit.Assert.assertThat;
29
30/**
31 * Test cases for testing prefix listener functionality.
32 */
33public class PrefixListenerTest {
34
35 private final YangUtilsParserManager manager = new YangUtilsParserManager();
36
37 /**
38 * Checks if value of prefix is correct.
39 */
40 @Test(expected = ParserException.class)
41 public void processPrefixInvalidValue() throws IOException, ParserException {
42
43 YangNode node = manager.getDataModel("src/test/resources/PrefixInvalidValue.yang");
44 }
45
46 /**
47 * Checks if prefix listener updates the data model tree.
48 */
49 @Test
50 public void processPrefixValidEntry() throws IOException, ParserException {
51
52 YangNode node = manager.getDataModel("src/test/resources/PrefixValidEntry.yang");
53
54 // Checks for the version value in data model tree.
55 assertThat(((YangModule) node).getPrefix(), is("On"));
56 }
57
58 /**
Vidyashree Rama468f8282016-03-04 19:08:35 +053059 * Checks prefix value with double quotes.
60 */
61 @Test
62 public void processPrefixWithDoubleQuotes() throws IOException, ParserException {
63
64 YangNode node = manager.getDataModel("src/test/resources/PrefixWithDoubleQuotes.yang");
65 assertThat(((YangModule) node).getPrefix(), is("On"));
66 }
67
68 /**
Gaurav Agrawala04483c2016-02-13 14:23:40 +053069 * Checks that prefix should be present just once.
70 */
71 @Test(expected = ParserException.class)
72 public void processPrefixDualEntry() throws IOException, ParserException {
73
74 YangNode node = manager.getDataModel("src/test/resources/PrefixDualEntry.yang");
75 }
76
77 /**
78 * Checks if prefix syntax is followed.
79 */
80 @Test(expected = ParserException.class)
81 public void processPrefixMissingValue() throws IOException, ParserException {
82
83 YangNode node = manager.getDataModel("src/test/resources/PrefixMissingValue.yang");
84 }
85
86 /**
87 * Checks that exception should be reported if prefix is missing.
88 */
89 @Test(expected = ParserException.class)
90 public void processPrefixOrder() throws IOException, ParserException {
91
92 YangNode node = manager.getDataModel("src/test/resources/PrefixOrder.yang");
93 }
94}