Gaurav Agrawal | a04483c | 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 revision date listener functionality. |
| 32 | */ |
| 33 | public class RevisionDateListenerTest { |
| 34 | |
| 35 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 36 | |
| 37 | /** |
| 38 | * Checks if revision date syntax is correct in include. |
| 39 | */ |
| 40 | @Test(expected = ParserException.class) |
| 41 | public void processRevisionDateInvalidSyntaxAtInclude() throws IOException, ParserException { |
| 42 | |
| 43 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidSyntaxAtInclude.yang"); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Checks if revision date syntax is correct in import. |
| 48 | */ |
| 49 | @Test(expected = ParserException.class) |
| 50 | public void processRevisionDateInvalidSyntaxAtImport() throws IOException, ParserException { |
| 51 | |
| 52 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidSyntaxAtImport.yang"); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Checks revision date should not be in quotes inside include. |
| 57 | */ |
| 58 | @Test(expected = ParserException.class) |
| 59 | public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException { |
| 60 | |
| 61 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang"); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Checks revision date should not be in quotes inside import. |
| 66 | */ |
| 67 | @Test(expected = ParserException.class) |
| 68 | public void processRevisionDateInQuotesAtImport() throws IOException, ParserException { |
| 69 | |
| 70 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang"); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Checks if revision date follows YYYY-MM-DD format. |
| 75 | */ |
| 76 | @Test(expected = ParserException.class) |
| 77 | public void processRevisionDateInvalidFormat() throws IOException, ParserException { |
| 78 | |
| 79 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidFormat.yang"); |
| 80 | } |
| 81 | |
| 82 | /** |
Gaurav Agrawal | b5a1c13 | 2016-02-21 02:56:46 +0530 | [diff] [blame^] | 83 | * Checks if revision date is correct. |
| 84 | */ |
| 85 | @Test(expected = ParserException.class) |
| 86 | public void processRevisionDateInvalid() throws IOException, ParserException { |
| 87 | |
| 88 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalid.yang"); |
| 89 | } |
| 90 | |
| 91 | /** |
Gaurav Agrawal | a04483c | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 92 | * Checks if revision date listener updates the data model tree. |
| 93 | */ |
| 94 | @Test |
| 95 | public void processRevisionDateValidEntry() throws IOException, ParserException { |
| 96 | |
| 97 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateValidEntry.yang"); |
| 98 | |
| 99 | // Checks for the version value in data model tree. |
| 100 | assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03")); |
| 101 | assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); |
| 102 | assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); |
| 103 | } |
| 104 | } |