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