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 | |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
| 20 | import java.text.ParseException; |
| 21 | import java.text.SimpleDateFormat; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 22 | import org.junit.Test; |
| 23 | import org.onosproject.yangutils.datamodel.YangModule; |
| 24 | import org.onosproject.yangutils.datamodel.YangNode; |
| 25 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 26 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 27 | |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 28 | import static org.hamcrest.core.Is.is; |
janani b | a302749 | 2016-03-24 12:43:48 +0530 | [diff] [blame] | 29 | import static org.hamcrest.core.IsNull.notNullValue; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 30 | import static org.junit.Assert.assertThat; |
| 31 | |
| 32 | /** |
| 33 | * Test cases for testing revision listener functionality. |
| 34 | */ |
| 35 | public class RevisionListenerTest { |
| 36 | |
| 37 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 38 | private static final String DATE_FORMAT = "yyyy-MM-dd"; |
| 39 | private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Checks if revision doesn't have optional parameters "revision and |
| 43 | * description". |
| 44 | */ |
| 45 | @Test |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 46 | public void processRevisionNoOptionalParameter() throws IOException, ParserException, ParseException { |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 47 | |
| 48 | YangNode node = manager.getDataModel("src/test/resources/RevisionNoOptionalParameter.yang"); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 49 | // Checks for the version value in data model tree. |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 50 | assertThat(((YangModule) node).getRevision().getRevDate(), is(simpleDateFormat.parse("2016-02-03"))); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Checks if the syntax of revision is correct. |
| 55 | */ |
| 56 | @Test(expected = ParserException.class) |
| 57 | public void processRevisionInValidSyntax() throws IOException, ParserException { |
| 58 | |
| 59 | YangNode node = manager.getDataModel("src/test/resources/RevisionInValidSyntax.yang"); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Checks if the correct order is followed. |
| 64 | */ |
| 65 | @Test(expected = ParserException.class) |
| 66 | public void processRevisionInValidOrder() throws IOException, ParserException { |
| 67 | |
| 68 | YangNode node = manager.getDataModel("src/test/resources/RevisionInValidOrder.yang"); |
| 69 | } |
janani b | a302749 | 2016-03-24 12:43:48 +0530 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Checks the revision with current date is created for empty revision statement. |
| 73 | */ |
| 74 | @Test |
| 75 | public void processWithoutRevision() throws IOException, ParserException { |
| 76 | |
| 77 | YangNode node = manager.getDataModel("src/test/resources/RevisionAbsence.yang"); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 78 | assertThat(((YangModule) node).getRevision().getRevDate(), notNullValue()); |
janani b | a302749 | 2016-03-24 12:43:48 +0530 | [diff] [blame] | 79 | } |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * Checks latest date is stored when there are multiple revisions. |
| 83 | */ |
| 84 | @Test |
| 85 | public void processWithMultipleRevision() throws IOException, ParserException, ParseException { |
| 86 | |
| 87 | YangNode node = manager.getDataModel("src/test/resources/MultipleRevision.yang"); |
| 88 | assertThat(((YangModule) node).getRevision().getRevDate(), is(simpleDateFormat.parse("2013-07-15"))); |
| 89 | } |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 90 | } |