Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.yangutils.parser.impl.listeners; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.yangutils.datamodel.YangModule; |
| 21 | import org.onosproject.yangutils.datamodel.YangNode; |
| 22 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 23 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 24 | |
| 25 | import java.io.IOException; |
| 26 | |
| 27 | import static org.hamcrest.core.Is.is; |
| 28 | import static org.junit.Assert.assertThat; |
| 29 | |
| 30 | /** |
| 31 | * Test cases for testing organization listener functionality. |
| 32 | */ |
| 33 | public class OrganizationListenerTest { |
| 34 | |
| 35 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 36 | |
| 37 | /** |
| 38 | * Checks if organization listener updates the data model tree. |
| 39 | */ |
| 40 | @Test |
| 41 | public void processOrganizationValidEntry() throws IOException, ParserException { |
| 42 | |
| 43 | YangNode node = manager.getDataModel("src/test/resources/OrganizationValidEntry.yang"); |
| 44 | |
| 45 | // Checks for the version value in data model tree. |
| 46 | assertThat(((YangModule) node).getOrganization(), is("\"IETF SPRING Working Group\"")); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Checks that organization must be present only once. |
| 51 | */ |
| 52 | @Test(expected = ParserException.class) |
| 53 | public void processOrganizationDualEntry() throws IOException, ParserException { |
| 54 | |
| 55 | YangNode node = manager.getDataModel("src/test/resources/OrganizationDualEntry.yang"); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Checks if organization entry syntax is correct. |
| 60 | */ |
| 61 | @Test(expected = ParserException.class) |
| 62 | public void processOrganizationMissingValue() throws IOException, ParserException { |
| 63 | |
| 64 | YangNode node = manager.getDataModel("src/test/resources/OrganizationMissingValue.yang"); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Checks if organization and namespace is present in correct order. |
| 69 | */ |
| 70 | @Test(expected = ParserException.class) |
| 71 | public void processOrganizationInvalidOrder() throws IOException, ParserException { |
| 72 | |
| 73 | YangNode node = manager.getDataModel("src/test/resources/OrganizationInvalidOrder.yang"); |
| 74 | } |
| 75 | } |