blob: 6057a7fbeafd9353b62250584237bf5aaf057f80 [file] [log] [blame]
Gaurav Agrawalbd804472016-03-25 11:25:36 +05301/*
2 * Copyright 2014-2016 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 static org.hamcrest.MatcherAssert.assertThat;
20import static org.hamcrest.core.Is.is;
21import org.junit.Test;
22import org.onosproject.yangutils.datamodel.YangCase;
23import org.onosproject.yangutils.datamodel.YangChoice;
24import org.onosproject.yangutils.datamodel.YangContainer;
25import org.onosproject.yangutils.datamodel.YangList;
26import org.onosproject.yangutils.datamodel.YangModule;
27import org.onosproject.yangutils.datamodel.YangNode;
28import org.onosproject.yangutils.datamodel.YangNodeType;
29import org.onosproject.yangutils.parser.exceptions.ParserException;
30import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31
32import java.io.IOException;
33
34/**
35 * Test cases for short case listener.
36 */
37public class ShortCaseListenerTest {
38
39 private final YangUtilsParserManager manager = new YangUtilsParserManager();
40
41 /**
42 * Checks short case listener with container.
43 */
44 @Test
45 public void processShortCaseListenerWithContainer() throws IOException, ParserException {
46
47 YangNode node = manager.getDataModel("src/test/resources/ShortCaseListenerWithContainer.yang");
48
49 // Check whether the data model tree returned is of type module.
50 assertThat((node instanceof YangModule), is(true));
51
52 // Check whether the node type is set properly to module.
53 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
54
55 // Check whether the module name is set correctly.
56 YangModule yangNode = (YangModule) node;
57 assertThat(yangNode.getName(), is("Test"));
58
59 YangContainer yangContainer = (YangContainer) yangNode.getChild();
60 assertThat(yangContainer.getName(), is("food"));
61
62 YangChoice yangChoice = (YangChoice) yangContainer.getChild();
63 assertThat(yangChoice.getName(), is("snack"));
64
65 YangCase yangCase = (YangCase) yangChoice.getChild();
66 assertThat(yangCase.getName(), is("sports-arena"));
67
68 YangContainer yangContainer1 = (YangContainer) yangCase.getChild();
69 assertThat(yangContainer1.getName(), is("sports-arena"));
70 }
71
72 /**
73 * Checks short case listener with list.
74 */
75 @Test
76 public void processShortCaseListenerWithList() throws IOException, ParserException {
77
78 YangNode node = manager.getDataModel("src/test/resources/ShortCaseListenerWithList.yang");
79
80 // Check whether the data model tree returned is of type module.
81 assertThat((node instanceof YangModule), is(true));
82
83 // Check whether the node type is set properly to module.
84 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
85
86 // Check whether the module name is set correctly.
87 YangModule yangNode = (YangModule) node;
88 assertThat(yangNode.getName(), is("Test"));
89
90 YangContainer yangContainer = (YangContainer) yangNode.getChild();
91 assertThat(yangContainer.getName(), is("food"));
92
93 YangChoice yangChoice = (YangChoice) yangContainer.getChild();
94 assertThat(yangChoice.getName(), is("snack"));
95
96 YangCase yangCase = (YangCase) yangChoice.getChild();
97 assertThat(yangCase.getName(), is("sports-arena"));
98
99 YangList yangList = (YangList) yangCase.getChild();
100 assertThat(yangList.getName(), is("sports-arena"));
101 }
102}