Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.parser.impl.listeners; |
| 18 | |
| 19 | import org.junit.Rule; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import org.junit.rules.ExpectedException; |
| 23 | import org.onosproject.yangutils.datamodel.YangModule; |
| 24 | import org.onosproject.yangutils.datamodel.YangNode; |
| 25 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| 26 | import org.onosproject.yangutils.datamodel.YangContainer; |
| 27 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 28 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 29 | |
| 30 | import java.io.IOException; |
| 31 | |
| 32 | import static org.hamcrest.MatcherAssert.assertThat; |
| 33 | import static org.hamcrest.Matchers.is; |
| 34 | import static org.hamcrest.Matchers.nullValue; |
| 35 | |
| 36 | /** |
| 37 | * Test cases for presence listener. |
| 38 | */ |
| 39 | public class PresenceListenerTest { |
| 40 | |
| 41 | @Rule |
| 42 | public ExpectedException thrown = ExpectedException.none(); |
| 43 | |
| 44 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 45 | |
| 46 | /** |
| 47 | * Checks presence statement as sub-statement of container. |
| 48 | */ |
| 49 | @Test |
| 50 | public void processContainerSubStatementPresence() throws IOException, ParserException { |
| 51 | |
| 52 | YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementPresence.yang"); |
| 53 | |
| 54 | assertThat((node instanceof YangModule), is(true)); |
| 55 | |
| 56 | // Check whether the node type is set properly to module. |
| 57 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 58 | |
| 59 | // Check whether the module name is set correctly. |
| 60 | YangModule yangNode = (YangModule) node; |
| 61 | assertThat(yangNode.getName(), is("Test")); |
| 62 | |
| 63 | // Check whether the list is child of module |
| 64 | YangContainer yangContainer = (YangContainer) yangNode.getChild(); |
| 65 | assertThat(yangContainer.getName(), is("valid")); |
| 66 | assertThat(yangContainer.getPresence(), is("\"invalid\"")); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * checks default value of presence statement. |
| 71 | */ |
| 72 | @Test |
| 73 | public void processPresenceDefaultValue() throws IOException, ParserException { |
| 74 | |
| 75 | YangNode node = manager.getDataModel("src/test/resources/PresenceDefaultValue.yang"); |
| 76 | |
| 77 | assertThat((node instanceof YangModule), is(true)); |
| 78 | |
| 79 | // Check whether the node type is set properly to module. |
| 80 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 81 | |
| 82 | // Check whether the module name is set correctly. |
| 83 | YangModule yangNode = (YangModule) node; |
| 84 | assertThat(yangNode.getName(), is("Test")); |
| 85 | |
| 86 | // Check whether the list is child of module |
| 87 | YangContainer yangContainer = (YangContainer) yangNode.getChild(); |
| 88 | assertThat(yangContainer.getName(), is("valid")); |
| 89 | assertThat(yangContainer.getPresence(), is(nullValue())); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Checks presence statement without statement end. |
| 94 | */ |
| 95 | @Test |
| 96 | public void processPresenceWithoutStatementEnd() throws IOException, ParserException { |
| 97 | thrown.expect(ParserException.class); |
| 98 | thrown.expectMessage("mismatched input 'leaf' expecting {';', '+'}"); |
| 99 | YangNode node = manager.getDataModel("src/test/resources/PresenceWithoutStatementEnd.yang"); |
| 100 | } |
| 101 | } |