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 | |
| 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; |
janani b | a302749 | 2016-03-24 12:43:48 +0530 | [diff] [blame] | 28 | import static org.hamcrest.core.IsNull.notNullValue; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 29 | import static org.junit.Assert.assertThat; |
| 30 | |
| 31 | /** |
| 32 | * Test cases for testing revision listener functionality. |
| 33 | */ |
| 34 | public class RevisionListenerTest { |
| 35 | |
| 36 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 37 | |
| 38 | /** |
| 39 | * Checks if revision doesn't have optional parameters "revision and |
| 40 | * description". |
| 41 | */ |
| 42 | @Test |
| 43 | public void processRevisionNoOptionalParameter() throws IOException, ParserException { |
| 44 | |
| 45 | YangNode node = manager.getDataModel("src/test/resources/RevisionNoOptionalParameter.yang"); |
| 46 | |
| 47 | // Checks for the version value in data model tree. |
| 48 | assertThat(((YangModule) node).getRevision().getRevDate(), is("2016-02-03")); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Checks if the syntax of revision is correct. |
| 53 | */ |
| 54 | @Test(expected = ParserException.class) |
| 55 | public void processRevisionInValidSyntax() throws IOException, ParserException { |
| 56 | |
| 57 | YangNode node = manager.getDataModel("src/test/resources/RevisionInValidSyntax.yang"); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Checks if the correct order is followed. |
| 62 | */ |
| 63 | @Test(expected = ParserException.class) |
| 64 | public void processRevisionInValidOrder() throws IOException, ParserException { |
| 65 | |
| 66 | YangNode node = manager.getDataModel("src/test/resources/RevisionInValidOrder.yang"); |
| 67 | } |
janani b | a302749 | 2016-03-24 12:43:48 +0530 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Checks the revision with current date is created for empty revision statement. |
| 71 | */ |
| 72 | @Test |
| 73 | public void processWithoutRevision() throws IOException, ParserException { |
| 74 | |
| 75 | YangNode node = manager.getDataModel("src/test/resources/RevisionAbsence.yang"); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 76 | assertThat(((YangModule) node).getRevision().getRevDate(), notNullValue()); |
janani b | a302749 | 2016-03-24 12:43:48 +0530 | [diff] [blame] | 77 | } |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 78 | } |