blob: bb59e65f8ef39753d6e4cf624e8ab43af90f34bd [file] [log] [blame]
Vidyashree Rama25bf4d02016-03-29 14:37:02 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vidyashree Rama25bf4d02016-03-29 14:37:02 +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 java.util.ListIterator;
21
22import org.junit.Test;
23import org.onosproject.yangutils.datamodel.YangNode;
24import org.onosproject.yangutils.datamodel.YangModule;
25import org.onosproject.yangutils.datamodel.YangAugment;
26import org.onosproject.yangutils.datamodel.YangLeaf;
27import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
28import org.onosproject.yangutils.datamodel.YangDataTypes;
29import org.onosproject.yangutils.datamodel.YangNodeType;
30import org.onosproject.yangutils.parser.exceptions.ParserException;
31import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
32
33import static org.hamcrest.core.Is.is;
34import static org.junit.Assert.assertThat;
35
36/**
37 * Test cases for testing augment listener functionality.
38 */
39public class AugmentListenerTest {
40
41 private final YangUtilsParserManager manager = new YangUtilsParserManager();
42
43 /**
44 * Checks valid augment statement.
45 */
46 @Test
47 public void processValidAugmentStatement() throws IOException, ParserException {
48
49 YangNode node = manager.getDataModel("src/test/resources/ValidAugmentStatement.yang");
50
51 assertThat((node instanceof YangModule), is(true));
52 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
53 YangModule yangNode = (YangModule) node;
54 assertThat(yangNode.getName(), is("Test"));
55
56 YangAugment yangAugment = (YangAugment) yangNode.getChild();
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053057 ListIterator<YangNodeIdentifier> nodeIdentifierIterator = yangAugment.getTargetNode().listIterator();
58 YangNodeIdentifier yangNodeIdentifier = nodeIdentifierIterator.next();
59 assertThat(yangNodeIdentifier.getPrefix(), is("if"));
60 assertThat(yangNodeIdentifier.getName(), is("interfaces"));
61
62 ListIterator<YangLeaf> leafIterator = yangAugment.getListOfLeaf().listIterator();
63 YangLeaf leafInfo = leafIterator.next();
64
65 assertThat(leafInfo.getLeafName(), is("ds0ChannelNumber"));
66 assertThat(leafInfo.getDataType().getDataTypeName(), is("ChannelNumber"));
67 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
68 }
69}