blob: fbeacc824bafaa3ad525756d200b2ff0bf9829ae [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;
janani bcc9ac302016-03-24 12:43:48 +053029import static org.hamcrest.core.IsNull.notNullValue;
Gaurav Agrawala04483c2016-02-13 14:23:40 +053030import static org.junit.Assert.assertThat;
31
32/**
33 * Test cases for testing revision listener functionality.
34 */
35public class RevisionListenerTest {
36
37 private final YangUtilsParserManager manager = new YangUtilsParserManager();
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053038 private static final String DATE_FORMAT = "yyyy-MM-dd";
39 private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
Gaurav Agrawala04483c2016-02-13 14:23:40 +053040
41 /**
42 * Checks if revision doesn't have optional parameters "revision and
43 * description".
44 */
45 @Test
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053046 public void processRevisionNoOptionalParameter() throws IOException, ParserException, ParseException {
Gaurav Agrawala04483c2016-02-13 14:23:40 +053047
48 YangNode node = manager.getDataModel("src/test/resources/RevisionNoOptionalParameter.yang");
Gaurav Agrawala04483c2016-02-13 14:23:40 +053049 // Checks for the version value in data model tree.
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053050 assertThat(((YangModule) node).getRevision().getRevDate(), is(simpleDateFormat.parse("2016-02-03")));
Gaurav Agrawala04483c2016-02-13 14:23:40 +053051 }
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 bcc9ac302016-03-24 12:43:48 +053070
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 bde4ffab2016-04-15 16:18:30 +053078 assertThat(((YangModule) node).getRevision().getRevDate(), notNullValue());
janani bcc9ac302016-03-24 12:43:48 +053079 }
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053080
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 Agrawala04483c2016-02-13 14:23:40 +053090}