blob: d5c3c837bb1e30f588beca90f01371c89269bab4 [file] [log] [blame]
Vidyashree Rama36f2fab2016-07-15 14:06:56 +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 java.io.IOException;
20import org.junit.Test;
21import org.onosproject.yangutils.datamodel.YangExtension;
22import org.onosproject.yangutils.datamodel.YangModule;
23import org.onosproject.yangutils.datamodel.YangNode;
24import org.onosproject.yangutils.datamodel.YangNodeType;
25import org.onosproject.yangutils.parser.exceptions.ParserException;
26import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
27
28import static org.hamcrest.MatcherAssert.assertThat;
29import static org.hamcrest.core.Is.is;
30
31/**
32 * Test cases for testing extension listener.
33 */
34public class ExtensionListenerTest {
35
36 private final YangUtilsParserManager manager = new YangUtilsParserManager();
37
38 /**
39 * Checks extension statement as sub-statement of module.
40 */
41 @Test
42 public void processValidExtensionStatement() throws IOException, ParserException {
43
44 YangNode node = manager.getDataModel("src/test/resources/ValidExtensionStatement.yang");
45
46 assertThat((node instanceof YangModule), is(true));
47
48 // Check whether the node type is set properly to module.
49 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
50
51 YangModule yangNode = (YangModule) node;
52 assertThat(yangNode.getName(), is("ietf-yang-compiler-annotation"));
53
54 YangExtension extension = yangNode.getExtensionList().iterator().next();
55 assertThat(extension.getName(), is("compiler-annotation"));
56 assertThat(extension.getArgumentName(), is("target"));
57 assertThat(extension.getDescription(), is("\"This extension allows for defining compiler annotations\""));
58 }
59}
60