blob: 0ced4d2a1d0a3809a2dacd21eeaa53aac80cbaee [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;
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.datamodel.YangStatusType;
27import org.onosproject.yangutils.datamodel.YangUses;
28import org.onosproject.yangutils.parser.exceptions.ParserException;
29import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
30
31import static org.hamcrest.MatcherAssert.assertThat;
32import static org.hamcrest.core.Is.is;
33
34/**
35 * Test cases for testing uses listener.
36 */
37public class UsesListenerTest {
38
39 private final YangUtilsParserManager manager = new YangUtilsParserManager();
40
41 /**
42 * Checks uses statement inside module.
43 */
44 @Test
45 public void processUsesInModule() throws IOException, ParserException {
46
47 YangNode node = manager.getDataModel("src/test/resources/UsesInModule.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 YangUses yangUses = (YangUses) yangNode.getChild();
60 assertThat(yangUses.getName(), is("endpoint"));
61 }
62
63 /**
64 * Checks uses statement inside container.
65 */
66 @Test
67 public void processUsesInContainer() throws IOException, ParserException {
68
69 YangNode node = manager.getDataModel("src/test/resources/UsesInContainer.yang");
70
71 // Check whether the data model tree returned is of type module.
72 assertThat((node instanceof YangModule), is(true));
73
74 // Check whether the node type is set properly to module.
75 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
76
77 // Check whether the module name is set correctly.
78 YangModule yangNode = (YangModule) node;
79 assertThat(yangNode.getName(), is("Test"));
80
81 YangContainer yangContainer = (YangContainer) yangNode.getChild();
82 assertThat(yangContainer.getName(), is("valid"));
83
84 YangUses yangUses = (YangUses) yangContainer.getChild();
85 assertThat(yangUses.getName(), is("endpoint"));
86
87 // Check attributes associated with uses.
88 assertThat(yangUses.getStatus(), is(YangStatusType.CURRENT));
89 assertThat(yangUses.getReference(), is("\"RFC 6020\""));
90 assertThat(yangUses.getDescription(), is("\"grouping under test\""));
91 }
92
93 /**
94 * Checks uses statement inside list.
95 */
96 @Test
97 public void processUsesInList() throws IOException, ParserException {
98
99 YangNode node = manager.getDataModel("src/test/resources/UsesInList.yang");
100
101 // Check whether the data model tree returned is of type module.
102 assertThat((node instanceof YangModule), is(true));
103
104 // Check whether the node type is set properly to module.
105 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
106
107 // Check whether the module name is set correctly.
108 YangModule yangNode = (YangModule) node;
109 assertThat(yangNode.getName(), is("Test"));
110
111 YangList yangList = (YangList) yangNode.getChild();
112 assertThat(yangList.getName(), is("valid"));
113
114 YangUses yangUses = (YangUses) yangList.getChild();
115 assertThat(yangUses.getName(), is("endpoint"));
116
117 // Check attributes associated with uses.
118 assertThat(yangUses.getStatus(), is(YangStatusType.CURRENT));
119 assertThat(yangUses.getReference(), is("\"RFC 6020\""));
120 assertThat(yangUses.getDescription(), is("\"grouping under test\""));
121 }
122}