blob: cbc4009c0a769e37ea725a3629dcd50c3fd857a6 [file] [log] [blame]
Vidyashree Rama918f1622016-07-28 17:33:15 +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.YangAppDataStructure;
22import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
23import org.onosproject.yangutils.datamodel.YangDataStructure;
24import org.onosproject.yangutils.datamodel.YangModule;
25import org.onosproject.yangutils.datamodel.YangNode;
26import org.onosproject.yangutils.datamodel.YangNodeType;
27import org.onosproject.yangutils.parser.exceptions.ParserException;
28import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
29
30import static org.hamcrest.MatcherAssert.assertThat;
31import static org.hamcrest.core.Is.is;
32
33/**
34 * Test cases for compiler annotation listener.
35 */
36public class CompilerAnnotationListenerTest {
37
38 private final YangUtilsParserManager manager = new YangUtilsParserManager();
39
40 /**
41 * Checks valid compiler annotation statements.
42 */
43 @Test
44 public void processValidCompilerAnnotation() throws IOException, ParserException {
45
46 YangNode node = manager.getDataModel("src/test/resources/ValidCompilerAnnotation.yang");
47
48 // Check whether the data model tree returned is of type module.
49 assertThat((node instanceof YangModule), is(true));
50
51 // Check whether the node type is set properly to module.
52 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
53
54 // Check whether the module name is set correctly.
55 YangModule yangNode = (YangModule) node;
56 assertThat(yangNode.getName(), is("event"));
57
58 YangCompilerAnnotation compilerAnnotation = yangNode.getCompilerAnnotationList()
59 .iterator().next();
60 assertThat(compilerAnnotation.getPrefix(), is("ca"));
61 assertThat(compilerAnnotation.getPath(), is("/candidate-servers/server"));
62
63 YangAppDataStructure appDataStructure = compilerAnnotation.getYangAppDataStructure();
64 assertThat(appDataStructure.getPrefix(), is("abc"));
65 assertThat(appDataStructure.getDataStructure(), is(YangDataStructure.MAP));
66
67 assertThat(appDataStructure.getKeyList().iterator().next(), is("name"));
68 }
69}