Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 17 | package org.onosproject.yangutils.parser.impl.listeners; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.yangutils.datamodel.YangModule; |
| 21 | import org.onosproject.yangutils.datamodel.YangNode; |
| 22 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 23 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 24 | |
| 25 | import java.io.IOException; |
| 26 | |
| 27 | import static org.hamcrest.core.Is.is; |
| 28 | import static org.junit.Assert.assertThat; |
| 29 | |
| 30 | /** |
| 31 | * Test cases for testing include listener functionality. |
| 32 | */ |
| 33 | public class IncludeListenerTest { |
| 34 | |
| 35 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 36 | |
| 37 | /** |
| 38 | * Checks if include listener with ; is valid and updates the data |
| 39 | * model tree. |
| 40 | */ |
| 41 | @Test |
| 42 | public void processIncludeWithStmtend() throws IOException, ParserException { |
| 43 | |
| 44 | YangNode node = manager.getDataModel("src/test/resources/IncludeWithStmtend.yang"); |
| 45 | |
| 46 | // Checks for the sub module name in data model tree. |
| 47 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Checks if include listener with braces and without revision date is valid |
| 52 | * and updates the data model tree. |
| 53 | */ |
| 54 | @Test |
| 55 | public void processIncludeWithEmptyBody() throws IOException, ParserException { |
| 56 | |
| 57 | YangNode node = manager.getDataModel("src/test/resources/IncludeWithEmptyBody.yang"); |
| 58 | |
| 59 | // Checks for the sub module name in data model tree. |
| 60 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Checks if include listener with braces and with revision date is valid |
| 65 | * and updates the data model tree. |
| 66 | */ |
| 67 | @Test |
| 68 | public void processIncludeWithDate() throws IOException, ParserException { |
| 69 | |
| 70 | YangNode node = manager.getDataModel("src/test/resources/IncludeWithDate.yang"); |
| 71 | |
| 72 | // Checks for the sub module name in data model tree. |
| 73 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); |
| 74 | assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Checks if include has more than one occurrence. |
| 79 | */ |
| 80 | @Test |
| 81 | public void processIncludeMultiInstance() throws IOException, ParserException { |
| 82 | |
| 83 | YangNode node = manager.getDataModel("src/test/resources/IncludeMultiInstance.yang"); |
| 84 | |
| 85 | // Checks for the sub module name in data model tree. |
| 86 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); |
| 87 | assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); |
| 88 | assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn")); |
| 89 | assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Checks if include and import can come in any order. |
| 94 | */ |
| 95 | @Test |
| 96 | public void processIncludeImportAnyOrder() throws IOException, ParserException { |
| 97 | |
| 98 | YangNode node = manager.getDataModel("src/test/resources/IncludeImportAnyOrder.yang"); |
| 99 | |
| 100 | // Checks for the sub module name in data model tree. |
| 101 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); |
| 102 | assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); |
| 103 | assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn")); |
| 104 | assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Checks if syntax of Include is not correct. |
| 109 | */ |
| 110 | @Test(expected = ParserException.class) |
| 111 | public void processIncludeInvalidSyntax() throws IOException, ParserException { |
| 112 | |
| 113 | YangNode node = manager.getDataModel("src/test/resources/IncludeInvalidSyntax.yang"); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Checks if syntax of revision date in Include is not correct. |
| 118 | */ |
| 119 | @Test(expected = ParserException.class) |
| 120 | public void processIncludeInvalidDateSyntax() throws IOException, ParserException { |
| 121 | |
| 122 | YangNode node = manager.getDataModel("src/test/resources/IncludeInvalidDateSyntax.yang"); |
| 123 | } |
| 124 | } |