blob: 6c0930a882e9efd6ab2331cdeed8ccb3ef871fd4 [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;
Gaurav Agrawal72cd1b72016-06-30 13:28:14 +053028import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
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
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
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}