blob: 146f4109c9d0e66cba061b849cfb0fb97b4b2d38 [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;
Bharat saraswalb1170bd2016-07-14 13:26:18 +053023import org.onosproject.yangutils.datamodel.YangAtomicPath;
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053024import org.onosproject.yangutils.datamodel.YangAugment;
Gaurav Agrawal72cd1b72016-06-30 13:28:14 +053025import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
Bharat saraswalb1170bd2016-07-14 13:26:18 +053026import org.onosproject.yangutils.datamodel.YangLeaf;
27import org.onosproject.yangutils.datamodel.YangModule;
28import org.onosproject.yangutils.datamodel.YangNode;
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053029import 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
Bharat saraswalb1170bd2016-07-14 13:26:18 +053051 assertThat(node instanceof YangModule, is(true));
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053052 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();
Bharat saraswalb1170bd2016-07-14 13:26:18 +053057 ListIterator<YangAtomicPath> absPathIterator = yangAugment.getTargetNode().listIterator();
58 YangAtomicPath absPathIdentifier = absPathIterator.next();
59 assertThat(absPathIdentifier.getNodeIdentifier().getPrefix(), is("if"));
60 assertThat(absPathIdentifier.getNodeIdentifier().getName(), is("interfaces"));
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053061
62 ListIterator<YangLeaf> leafIterator = yangAugment.getListOfLeaf().listIterator();
63 YangLeaf leafInfo = leafIterator.next();
64
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053065 assertThat(leafInfo.getName(), is("ds0ChannelNumber"));
Vidyashree Rama25bf4d02016-03-29 14:37:02 +053066 assertThat(leafInfo.getDataType().getDataTypeName(), is("ChannelNumber"));
67 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
68 }
69}