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 | |
Gaurav Agrawal | be2b331 | 2016-08-17 18:58:17 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.onosproject.yangutils.datamodel.YangModule; |
| 22 | import org.onosproject.yangutils.datamodel.YangNode; |
| 23 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 24 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 25 | |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 26 | import static org.hamcrest.core.Is.is; |
| 27 | import static org.junit.Assert.assertThat; |
| 28 | |
| 29 | /** |
| 30 | * Test cases for testing namespace listener functionality. |
| 31 | */ |
| 32 | public class NamespaceListenerTest { |
| 33 | |
| 34 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 35 | |
| 36 | /** |
| 37 | * Checks that value of namespace shouldn't have invalid spaces. |
| 38 | */ |
| 39 | @Test(expected = ParserException.class) |
| 40 | public void processNamespaceWithInvalidSpaces() throws IOException, ParserException { |
| 41 | |
| 42 | YangNode node = manager.getDataModel("src/test/resources/NamespaceWithInvalidSpaces.yang"); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Checks if namespace with double quotes is allowed. |
| 47 | */ |
| 48 | @Test() |
| 49 | public void processNamespaceInDoubleQuotes() throws IOException, ParserException { |
| 50 | |
| 51 | YangNode node = manager.getDataModel("src/test/resources/NamespaceInDoubleQuotes.yang"); |
| 52 | |
| 53 | // Checks for the version value in data model tree. |
Gaurav Agrawal | e5057f0 | 2016-08-22 17:14:33 +0530 | [diff] [blame] | 54 | assertThat(((YangModule) node).getNameSpace(), is("urn:ietf:params:xml:ns:yang:ietf-ospf")); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Checks if namespace without double quotes is allowed. |
| 59 | */ |
| 60 | @Test() |
| 61 | public void processNamespaceWithoutQuotes() throws IOException, ParserException { |
| 62 | |
| 63 | YangNode node = manager.getDataModel("src/test/resources/NamespaceWithoutQuotes.yang"); |
| 64 | |
| 65 | // Checks for the version value in data model tree. |
Gaurav Agrawal | e5057f0 | 2016-08-22 17:14:33 +0530 | [diff] [blame] | 66 | assertThat(((YangModule) node).getNameSpace(), is("urn:ietf:params:xml:ns:yang:ietf-ospf")); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Checks if namespace is present only once. |
| 71 | */ |
| 72 | @Test(expected = ParserException.class) |
| 73 | public void processNamespaceDualEntry() throws IOException, ParserException { |
| 74 | |
| 75 | YangNode node = manager.getDataModel("src/test/resources/NamespaceDualEntry.yang"); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Checks if mandatory parameter namespace is present. |
| 80 | */ |
| 81 | @Test(expected = ParserException.class) |
| 82 | public void processNamespaceNoEntryTest() throws IOException, ParserException { |
| 83 | |
| 84 | YangNode node = manager.getDataModel("src/test/resources/NamespaceNoEntryTest.yang"); |
| 85 | } |
Gaurav Agrawal | be2b331 | 2016-08-17 18:58:17 +0530 | [diff] [blame] | 86 | } |