blob: c12b377902131396d7d5ec7ec12bed24e3bc1407 [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
19import org.junit.Test;
20import org.onosproject.yangutils.datamodel.YangModule;
21import org.onosproject.yangutils.datamodel.YangNode;
22import org.onosproject.yangutils.parser.exceptions.ParserException;
23import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
24
25import java.io.IOException;
26
27import static org.hamcrest.core.Is.is;
28import static org.junit.Assert.assertThat;
29
30/**
31 * Test cases for testing revision date listener functionality.
32 */
33public 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 /**
Vidyashree Rama468f8282016-03-04 19:08:35 +053056 * Checks revision date in quotes inside include.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053057 */
Vidyashree Rama468f8282016-03-04 19:08:35 +053058 @Test
Gaurav Agrawala04483c2016-02-13 14:23:40 +053059 public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException {
60
61 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang");
Vidyashree Rama468f8282016-03-04 19:08:35 +053062 // Checks for the version value in data model tree.
63 assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
64 assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
65 assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
Gaurav Agrawala04483c2016-02-13 14:23:40 +053066 }
67
68 /**
Vidyashree Rama468f8282016-03-04 19:08:35 +053069 * Checks revision date in quotes inside import.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053070 */
Vidyashree Rama468f8282016-03-04 19:08:35 +053071 @Test
Gaurav Agrawala04483c2016-02-13 14:23:40 +053072 public void processRevisionDateInQuotesAtImport() throws IOException, ParserException {
73
74 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang");
Vidyashree Rama468f8282016-03-04 19:08:35 +053075 // Checks for the version value in data model tree.
76 assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
77 assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
78 assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
Gaurav Agrawala04483c2016-02-13 14:23:40 +053079 }
80
81 /**
82 * Checks if revision date follows YYYY-MM-DD format.
83 */
84 @Test(expected = ParserException.class)
85 public void processRevisionDateInvalidFormat() throws IOException, ParserException {
86
87 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidFormat.yang");
88 }
89
90 /**
Gaurav Agrawalb5a1c132016-02-21 02:56:46 +053091 * Checks if revision date is correct.
92 */
93 @Test(expected = ParserException.class)
94 public void processRevisionDateInvalid() throws IOException, ParserException {
95
96 YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalid.yang");
97 }
98
99 /**
Gaurav Agrawala04483c2016-02-13 14:23:40 +0530100 * Checks if revision date listener updates the data model tree.
101 */
102 @Test
103 public void processRevisionDateValidEntry() throws IOException, ParserException {
104
105 YangNode node = manager.getDataModel("src/test/resources/RevisionDateValidEntry.yang");
106
107 // Checks for the version value in data model tree.
108 assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
109 assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
110 assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
111 }
112}