blob: a20c43e097c622b5e619210c63dd21925aa73a58 [file] [log] [blame]
Gaurav Agrawalbd804472016-03-25 11:25:36 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawalbd804472016-03-25 11:25:36 +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 java.io.IOException;
20import org.junit.Test;
21import org.onosproject.yangutils.datamodel.YangContainer;
janani b4e53f9b2016-04-26 18:49:20 +053022import org.onosproject.yangutils.datamodel.YangGrouping;
Gaurav Agrawalbd804472016-03-25 11:25:36 +053023import org.onosproject.yangutils.datamodel.YangList;
24import org.onosproject.yangutils.datamodel.YangModule;
25import org.onosproject.yangutils.datamodel.YangNode;
26import org.onosproject.yangutils.datamodel.YangNodeType;
27import org.onosproject.yangutils.datamodel.YangStatusType;
28import org.onosproject.yangutils.datamodel.YangUses;
29import org.onosproject.yangutils.parser.exceptions.ParserException;
30import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31
32import static org.hamcrest.MatcherAssert.assertThat;
33import static org.hamcrest.core.Is.is;
34
35/**
36 * Test cases for testing uses listener.
37 */
38public class UsesListenerTest {
39
40 private final YangUtilsParserManager manager = new YangUtilsParserManager();
41
42 /**
43 * Checks uses statement inside module.
44 */
45 @Test
46 public void processUsesInModule() throws IOException, ParserException {
47
48 YangNode node = manager.getDataModel("src/test/resources/UsesInModule.yang");
49
50 // Check whether the data model tree returned is of type module.
51 assertThat((node instanceof YangModule), is(true));
52
53 // Check whether the node type is set properly to module.
54 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
55
56 // Check whether the module name is set correctly.
57 YangModule yangNode = (YangModule) node;
58 assertThat(yangNode.getName(), is("Test"));
59
janani b4e53f9b2016-04-26 18:49:20 +053060 YangGrouping yangGrouping = (YangGrouping) yangNode.getChild();
61 assertThat(yangGrouping.getName(), is("endpoint"));
62
63 YangUses yangUses = (YangUses) yangGrouping.getNextSibling();
Gaurav Agrawalbd804472016-03-25 11:25:36 +053064 assertThat(yangUses.getName(), is("endpoint"));
65 }
66
67 /**
68 * Checks uses statement inside container.
69 */
70 @Test
71 public void processUsesInContainer() throws IOException, ParserException {
72
73 YangNode node = manager.getDataModel("src/test/resources/UsesInContainer.yang");
74
75 // Check whether the data model tree returned is of type module.
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
janani b4e53f9b2016-04-26 18:49:20 +053085 YangGrouping yangGrouping = (YangGrouping) yangNode.getChild();
86 assertThat(yangGrouping.getName(), is("endpoint"));
87
88 YangContainer yangContainer = (YangContainer) yangGrouping.getNextSibling();
Gaurav Agrawalbd804472016-03-25 11:25:36 +053089 assertThat(yangContainer.getName(), is("valid"));
90
91 YangUses yangUses = (YangUses) yangContainer.getChild();
92 assertThat(yangUses.getName(), is("endpoint"));
93
94 // Check attributes associated with uses.
95 assertThat(yangUses.getStatus(), is(YangStatusType.CURRENT));
96 assertThat(yangUses.getReference(), is("\"RFC 6020\""));
97 assertThat(yangUses.getDescription(), is("\"grouping under test\""));
98 }
99
100 /**
101 * Checks uses statement inside list.
102 */
103 @Test
104 public void processUsesInList() throws IOException, ParserException {
105
106 YangNode node = manager.getDataModel("src/test/resources/UsesInList.yang");
107
108 // Check whether the data model tree returned is of type module.
109 assertThat((node instanceof YangModule), is(true));
110
111 // Check whether the node type is set properly to module.
112 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
113
114 // Check whether the module name is set correctly.
115 YangModule yangNode = (YangModule) node;
116 assertThat(yangNode.getName(), is("Test"));
117
janani b4e53f9b2016-04-26 18:49:20 +0530118 YangGrouping yangGrouping = (YangGrouping) yangNode.getChild();
119 assertThat(yangGrouping.getName(), is("endpoint"));
120
121 YangList yangList = (YangList) yangGrouping.getNextSibling();
Gaurav Agrawalbd804472016-03-25 11:25:36 +0530122 assertThat(yangList.getName(), is("valid"));
123
124 YangUses yangUses = (YangUses) yangList.getChild();
125 assertThat(yangUses.getName(), is("endpoint"));
126
127 // Check attributes associated with uses.
128 assertThat(yangUses.getStatus(), is(YangStatusType.CURRENT));
129 assertThat(yangUses.getReference(), is("\"RFC 6020\""));
130 assertThat(yangUses.getDescription(), is("\"grouping under test\""));
131 }
132}