blob: 7c8c5e934f5f461b8c9261450a4ff8d2f6f8df3b [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.Rule;
20import org.junit.Test;
21import org.junit.rules.ExpectedException;
22import org.onosproject.yangutils.datamodel.YangModule;
23import org.onosproject.yangutils.datamodel.YangNode;
24import org.onosproject.yangutils.parser.exceptions.ParserException;
25import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
26
27import java.io.IOException;
28
29import static org.hamcrest.core.Is.is;
30import static org.junit.Assert.assertThat;
31
32/**
33 * Test cases for testing contact listener functionality.
34 */
35public class ContactListenerTest {
36
37 @Rule
38 public ExpectedException thrown = ExpectedException.none();
39
40 private final YangUtilsParserManager manager = new YangUtilsParserManager();
41
42 /**
43 * Checks if contact listener updates the data model tree.
44 */
45 @Test
46 public void processContactValidEntry() throws IOException, ParserException {
47
48 YangNode node = manager.getDataModel("src/test/resources/ContactValidEntry.yang");
49
Gaurav Agrawalb5a1c132016-02-21 02:56:46 +053050 // Checks for the contact value in data model tree.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053051 assertThat(((YangModule) node).getContact(), is("\"WG List: <mailto:spring@ietf.org>\nEditor: "
52 + "Stephane Litkowski\n " + "<mailto:stephane.litkowski@orange.com>\""));
53 }
54
55 /**
56 * Checks that contact must be present only once.
57 */
58 @Test(expected = ParserException.class)
59 public void processContactDualEntryTest() throws IOException, ParserException {
60
61 YangNode node = manager.getDataModel("src/test/resources/ContactDualEntryTest.yang");
62
63 }
64
65 /**
Gaurav Agrawalb5a1c132016-02-21 02:56:46 +053066 * Checks that contact can have a string value without double quotes.
67 */
68 @Test
69 public void processContactWithoutQuotes() throws IOException, ParserException {
70
71 YangNode node = manager.getDataModel("src/test/resources/ContactWithoutQuotes.yang");
72
73 // Checks for the contact value in data model tree.
74 assertThat(((YangModule) node).getContact(), is("WG"));
75 }
76
77 /**
Gaurav Agrawala04483c2016-02-13 14:23:40 +053078 * Checks if contact is not empty.
79 */
80 @Test(expected = ParserException.class)
81 public void processContactWithEmptyString() throws IOException, ParserException {
82
83 YangNode node = manager.getDataModel("src/test/resources/ContactWithEmptyString.yang");
84 }
85
86 /**
87 * Checks that contact must be present after namespace.
88 */
89 @Test(expected = ParserException.class)
90 public void processContactIncorrectOrder() throws IOException, ParserException {
91
92 YangNode node = manager.getDataModel("src/test/resources/ContactIncorrectOrder.yang");
93 }
94}