blob: 95ee043fc70094b59cf64301a992aee69b2df7e2 [file] [log] [blame]
janani b23ccc312016-07-14 19:35:22 +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.listeners;
18
19import org.junit.Rule;
20import org.junit.Test;
21import org.junit.rules.ExpectedException;
22import org.onosproject.yangutils.datamodel.YangList;
23import org.onosproject.yangutils.datamodel.YangModule;
24import org.onosproject.yangutils.datamodel.YangNode;
25import org.onosproject.yangutils.datamodel.YangNodeType;
26import org.onosproject.yangutils.parser.exceptions.ParserException;
27import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
28
29import java.io.IOException;
30import java.util.ListIterator;
31
32import static org.hamcrest.MatcherAssert.assertThat;
33import static org.hamcrest.core.Is.is;
34
35/**
36 * Test cases for unique listener.
37 */
38public class UniqueListenerTest {
39
40 @Rule
41 public ExpectedException thrown = ExpectedException.none();
42
43 private final YangUtilsParserManager manager = new YangUtilsParserManager();
44
45 /**
46 * Checks unique statement as sub-statement of list.
47 */
48 @Test
49 public void processListSubStatementUnique() throws IOException, ParserException {
50
51 YangNode node = manager.getDataModel("src/test/resources/ListSubStatementUnique.yang");
52
53 assertThat((node instanceof YangModule), is(true));
54
55 // Check whether the node type is set properly to module.
56 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
57
58 // Check whether the module name is set correctly.
59 YangModule yangNode = (YangModule) node;
60 assertThat(yangNode.getName(), is("Test"));
61
62 // Check whether the list is child of module
63 YangList yangList = (YangList) yangNode.getChild();
64 assertThat(yangList.getName(), is("valid"));
65 assertThat(yangList.getUniqueList().listIterator().next(), is("invalid-interval"));
66 }
67
68 /**
69 * Check multiple unique values.
70 */
71 @Test
72 public void processMultipleUniqueValues() throws IOException, ParserException {
73
74 YangNode node = manager.getDataModel("src/test/resources/MultipleUniqueValues.yang");
75
76 assertThat((node instanceof YangModule), is(true));
77
78 // Check whether the node type is set properly to module.
79 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
80
81 // Check whether the module name is set correctly.
82 YangModule yangNode = (YangModule) node;
83 assertThat(yangNode.getName(), is("Test"));
84
85 // Check whether the list is child of module
86 YangList yangList = (YangList) yangNode.getChild();
87 assertThat(yangList.getName(), is("valid"));
88 ListIterator<String> listIterator;
89 String list;
90 listIterator = yangList.getUniqueList().listIterator();
91 list = listIterator.next();
92 assertThat(list, is("ospf"));
93 list = listIterator.next();
94 assertThat(list, is("isis"));
95 }
96}