Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +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 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
| 20 | |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 21 | import org.junit.Test; |
| 22 | import org.onosproject.yangutils.datamodel.YangModule; |
| 23 | import org.onosproject.yangutils.datamodel.YangNode; |
| 24 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 25 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 26 | |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 27 | import static org.hamcrest.core.Is.is; |
| 28 | import static org.junit.Assert.assertThat; |
| 29 | |
| 30 | /** |
| 31 | * Test cases for testing version listener functionality. |
| 32 | */ |
| 33 | public class VersionListenerTest { |
| 34 | |
| 35 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 36 | |
| 37 | /** |
| 38 | * Checks if value of version is correct. |
| 39 | */ |
| 40 | @Test(expected = ParserException.class) |
| 41 | public void processVersionInvalidValue() throws IOException, ParserException { |
| 42 | |
| 43 | YangNode node = manager.getDataModel("src/test/resources/VersionInvalidValue.yang"); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Checks if version listener updates the data model tree. |
| 48 | */ |
| 49 | @Test |
| 50 | public void processVersionValidEntry() throws IOException, ParserException { |
| 51 | |
| 52 | YangNode node = manager.getDataModel("src/test/resources/VersionValidEntry.yang"); |
| 53 | |
| 54 | // Checks for the version value in data model tree. |
| 55 | assertThat(((YangModule) node).getVersion(), is((byte) 1)); |
| 56 | } |
| 57 | |
| 58 | /** |
Vidyashree Rama | d322132 | 2016-03-04 19:08:35 +0530 | [diff] [blame] | 59 | * Checks version in double quotes. |
| 60 | */ |
| 61 | @Test |
| 62 | public void processValidVersionWithDoubleQuotes() throws IOException, ParserException { |
| 63 | |
| 64 | YangNode node = manager.getDataModel("src/test/resources/ValidVersionWithDoubleQuotes.yang"); |
| 65 | |
| 66 | // Checks for the version value in data model tree. |
| 67 | assertThat(((YangModule) node).getVersion(), is((byte) 1)); |
| 68 | } |
| 69 | |
| 70 | /** |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 71 | * Checks if version which is optional paramater is not present. |
| 72 | */ |
| 73 | @Test |
| 74 | public void processVersionNotPresent() throws IOException, ParserException { |
| 75 | |
| 76 | YangNode node = manager.getDataModel("src/test/resources/VersionNotPresent.yang"); |
| 77 | |
| 78 | // Checks for the version value in data model tree. |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 79 | assertThat(((YangModule) node).getVersion(), is((byte) 1)); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Checks that version should be present only once. |
| 84 | */ |
| 85 | @Test(expected = ParserException.class) |
| 86 | public void processVersionDualEntry() throws IOException, ParserException { |
| 87 | |
| 88 | YangNode node = manager.getDataModel("src/test/resources/VersionDualEntry.yang"); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Checks if version can appear in any order in module header. |
| 93 | */ |
| 94 | @Test |
| 95 | public void processVersionOrder() throws IOException, ParserException { |
| 96 | |
| 97 | YangNode node = manager.getDataModel("src/test/resources/VersionOrder.yang"); |
| 98 | |
| 99 | // Checks for the version value in data model tree. |
| 100 | assertThat(((YangModule) node).getVersion(), is((byte) 1)); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Checks if sytax of version entry is not correct. |
| 105 | */ |
| 106 | @Test(expected = ParserException.class) |
| 107 | public void processVersionInvalidSyntax() throws IOException, ParserException { |
| 108 | |
| 109 | YangNode node = manager.getDataModel("src/test/resources/VersionInvalidSyntax.yang"); |
| 110 | } |
| 111 | } |