blob: ab7242a9925bb6470c7e3835f7916fb028e03708 [file] [log] [blame]
Gaurav Agrawala04483c2016-02-13 14:23:40 +05301/*
2 * Copyright 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 org.junit.Test;
20import org.onosproject.yangutils.datamodel.YangModule;
21import org.onosproject.yangutils.datamodel.YangNode;
22import org.onosproject.yangutils.datamodel.YangNodeType;
23import org.onosproject.yangutils.parser.exceptions.ParserException;
24import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
25
26import java.io.IOException;
27
28import static org.hamcrest.core.Is.is;
29import static org.junit.Assert.assertThat;
30
31/**
32 * Test cases for testing module listener functionality.
33 */
34public class ModuleListenerTest {
35
36 private final YangUtilsParserManager manager = new YangUtilsParserManager();
37
38 /**
39 * Checks if module listener updates the data model root node.
40 */
41 @Test
42 public void processModuleValidEntry() throws IOException, ParserException {
43
44 YangNode node = manager.getDataModel("src/test/resources/ModuleValidEntry.yang");
45
46 // Check whether the data model tree returned is of type module.
47 assertThat((node instanceof YangModule), is(true));
48
49 // Check whether the node type is set properly to module.
50 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
51
52 // Check whether the module name is set correctly.
53 YangModule yangNode = (YangModule) node;
54 assertThat(yangNode.getName(), is("Test"));
55 }
56
57 /**
58 * Checks if module name is set correctly.
59 */
60 @Test(expected = ParserException.class)
61 public void processModuleInvalidEntryTest() throws IOException, ParserException {
62
63 YangNode node = manager.getDataModel("src/test/resources/ModuleWithInvalidIdentifier.yang");
64 }
65}