blob: fcba7c0b06447b5848fe20f1abcd08ada5366193 [file] [log] [blame]
Vidyashree Ramadeac28b2016-06-20 15:12:43 +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 org.junit.Test;
20import org.onosproject.yangutils.datamodel.YangContainer;
21import org.onosproject.yangutils.datamodel.YangLeaf;
22import org.onosproject.yangutils.datamodel.YangList;
23import org.onosproject.yangutils.datamodel.YangModule;
24import org.onosproject.yangutils.datamodel.YangNode;
25import org.onosproject.yangutils.parser.exceptions.ParserException;
26import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
27
28import java.io.IOException;
29import java.util.ListIterator;
30
31import static org.hamcrest.core.Is.is;
32import static org.junit.Assert.assertThat;
33
34/**
35 * Test cases for testing when listener functionality.
36 */
37public class WhenListenerTest {
38
39 private final YangUtilsParserManager manager = new YangUtilsParserManager();
40
41 /**
42 * Checks if when listener updates the data model.
43 */
44 @Test
45 public void processContainerSubStatementWhen() throws IOException, ParserException {
46 YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementWhen.yang");
47
48 YangModule yangNode = (YangModule) node;
49 assertThat(yangNode.getName(), is("Test"));
50
51 YangList yangList = (YangList) yangNode.getChild();
52 assertThat(yangList.getName(), is("interface-switching-capability"));
53
54 YangContainer container = (YangContainer) yangList.getNextSibling();
55 assertThat(container.getName(), is("time-division-multiplex-capable"));
56
57 String expectedConstraint = "../switching-capability = 'TDM'";
58 assertThat(container.getWhen().getCondition(), is(expectedConstraint));
59 }
60
61 /**
62 * Checks if when listener updates the data model.
63 */
64 @Test
65 public void processLeafSubStatementWhen() throws IOException, ParserException {
66 YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementWhen.yang");
67
68 YangModule yangNode = (YangModule) node;
69 assertThat(yangNode.getName(), is("Test"));
70
71 ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
72 YangLeaf leafInfo = leafIterator.next();
73
74 assertThat(leafInfo.getWhen().getCondition(), is("ifType != 'ethernet'"));
75 }
76}