blob: 9791ba3d6b27831e9442aa8d7984ccf7a62bd855 [file] [log] [blame]
Gaurav Agrawala04483c2016-02-13 14:23:40 +05301/*
2 * Copyright 2016 Open Networking Laboratory
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
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
50 // Checks for the version value in data model tree.
51 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 /**
66 * Checks if contact is not empty.
67 */
68 @Test(expected = ParserException.class)
69 public void processContactWithEmptyString() throws IOException, ParserException {
70
71 YangNode node = manager.getDataModel("src/test/resources/ContactWithEmptyString.yang");
72 }
73
74 /**
75 * Checks that contact must be present after namespace.
76 */
77 @Test(expected = ParserException.class)
78 public void processContactIncorrectOrder() throws IOException, ParserException {
79
80 YangNode node = manager.getDataModel("src/test/resources/ContactIncorrectOrder.yang");
81 }
82}