Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.parser.impl.listeners; |
| 18 | |
| 19 | import org.junit.Rule; |
| 20 | import org.junit.Test; |
| 21 | import org.junit.rules.ExpectedException; |
| 22 | import org.onosproject.yangutils.datamodel.YangModule; |
| 23 | import org.onosproject.yangutils.datamodel.YangNode; |
| 24 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 25 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 26 | |
| 27 | import java.io.IOException; |
| 28 | |
| 29 | import static org.hamcrest.core.Is.is; |
| 30 | import static org.junit.Assert.assertThat; |
| 31 | |
| 32 | /** |
| 33 | * Test cases for testing contact listener functionality. |
| 34 | */ |
| 35 | public 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 Agrawal | 0520c7c | 2016-02-21 02:56:46 +0530 | [diff] [blame] | 50 | // Checks for the contact value in data model tree. |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 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 | /** |
Gaurav Agrawal | 0520c7c | 2016-02-21 02:56:46 +0530 | [diff] [blame] | 66 | * 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 Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 78 | * 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 | } |