blob: 8a00480188d90eaa9a46e65845bb68dba2bfa4d1 [file] [log] [blame]
Gaurav Agrawala04483c2016-02-13 14:23:40 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawala04483c2016-02-13 14:23:40 +05303 *
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
17package org.onosproject.yangutils.parser.impl.listeners;
18
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053019import java.io.IOException;
20import java.text.ParseException;
21import java.text.SimpleDateFormat;
Gaurav Agrawala04483c2016-02-13 14:23:40 +053022import org.junit.Test;
23import org.onosproject.yangutils.datamodel.YangModule;
24import org.onosproject.yangutils.datamodel.YangNode;
25import org.onosproject.yangutils.parser.exceptions.ParserException;
26import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
27
Gaurav Agrawala04483c2016-02-13 14:23:40 +053028import static org.hamcrest.core.Is.is;
29import static org.junit.Assert.assertThat;
30
31/**
32 * Test cases for testing revision date listener functionality.
33 */
34public class RevisionDateListenerTest {
35
36 private final YangUtilsParserManager manager = new YangUtilsParserManager();
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053037 private static final String DATE_FORMAT = "yyyy-MM-dd";
38 private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
Gaurav Agrawala04483c2016-02-13 14:23:40 +053039
40 /**
41 * Checks if revision date syntax is correct in include.
42 */
43 @Test(expected = ParserException.class)
44 public void processRevisionDateInvalidSyntaxAtInclude() throws IOException, ParserException {
45
46 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidSyntaxAtInclude.yang");
47 }
48
49 /**
50 * Checks if revision date syntax is correct in import.
51 */
52 @Test(expected = ParserException.class)
53 public void processRevisionDateInvalidSyntaxAtImport() throws IOException, ParserException {
54
55 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidSyntaxAtImport.yang");
56 }
57
58 /**
Vidyashree Rama468f8282016-03-04 19:08:35 +053059 * Checks revision date in quotes inside include.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053060 */
Vidyashree Rama468f8282016-03-04 19:08:35 +053061 @Test
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053062 public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException, ParseException {
Gaurav Agrawala04483c2016-02-13 14:23:40 +053063
64 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang");
Vidyashree Rama468f8282016-03-04 19:08:35 +053065 // Checks for the version value in data model tree.
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053066 assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
67 assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
68 assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
Gaurav Agrawala04483c2016-02-13 14:23:40 +053069 }
70
71 /**
Vidyashree Rama468f8282016-03-04 19:08:35 +053072 * Checks revision date in quotes inside import.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053073 */
Vidyashree Rama468f8282016-03-04 19:08:35 +053074 @Test
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053075 public void processRevisionDateInQuotesAtImport() throws IOException, ParserException, ParseException {
Gaurav Agrawala04483c2016-02-13 14:23:40 +053076
77 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang");
Vidyashree Rama468f8282016-03-04 19:08:35 +053078 // Checks for the version value in data model tree.
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053079 assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
80 assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
81 assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
Gaurav Agrawala04483c2016-02-13 14:23:40 +053082 }
83
84 /**
85 * Checks if revision date follows YYYY-MM-DD format.
86 */
87 @Test(expected = ParserException.class)
88 public void processRevisionDateInvalidFormat() throws IOException, ParserException {
89
90 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidFormat.yang");
91 }
92
93 /**
Gaurav Agrawalb5a1c132016-02-21 02:56:46 +053094 * Checks if revision date is correct.
95 */
96 @Test(expected = ParserException.class)
97 public void processRevisionDateInvalid() throws IOException, ParserException {
98
99 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalid.yang");
100 }
101
102 /**
Gaurav Agrawala04483c2016-02-13 14:23:40 +0530103 * Checks if revision date listener updates the data model tree.
104 */
105 @Test
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530106 public void processRevisionDateValidEntry() throws IOException, ParserException, ParseException {
Gaurav Agrawala04483c2016-02-13 14:23:40 +0530107
108 YangNode node = manager.getDataModel("src/test/resources/RevisionDateValidEntry.yang");
109
110 // Checks for the version value in data model tree.
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530111 assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
112 assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
113 assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
Gaurav Agrawala04483c2016-02-13 14:23:40 +0530114 }
115}