rama-huawei | e37efa4 | 2016-07-11 14:48:12 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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.YangMust; |
| 21 | import org.onosproject.yangutils.datamodel.YangModule; |
| 22 | import org.onosproject.yangutils.datamodel.YangNode; |
| 23 | import org.onosproject.yangutils.datamodel.YangContainer; |
| 24 | import org.onosproject.yangutils.datamodel.YangAppErrorInfo; |
| 25 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 26 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 27 | |
| 28 | import java.io.IOException; |
| 29 | import java.util.List; |
| 30 | |
| 31 | import static org.hamcrest.core.Is.is; |
| 32 | import static org.junit.Assert.assertThat; |
| 33 | |
| 34 | /** |
| 35 | * Test-cases for testing error app tag message listener functionality. |
| 36 | */ |
| 37 | public class ErrorAppTagListenerTest { |
| 38 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 39 | |
| 40 | /** |
| 41 | * Checks if error app tag message is default updated in the data model. |
| 42 | */ |
| 43 | @Test |
| 44 | public void processContainerSubStatementErrorDefaultAppTag() throws IOException, ParserException { |
| 45 | YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorDefaultAppTag.yang"); |
| 46 | |
| 47 | YangModule yangNode = (YangModule) node; |
| 48 | assertThat(yangNode.getName(), is("ErrorAppTag")); |
| 49 | |
| 50 | YangContainer yangContainer = (YangContainer) yangNode.getChild(); |
| 51 | assertThat(yangContainer.getName(), is("interface")); |
| 52 | |
| 53 | String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)"; |
| 54 | List<YangMust> mustConstraintList = yangContainer.getListOfMust(); |
| 55 | assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint)); |
| 56 | |
| 57 | YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo(); |
| 58 | assertThat(yangAppErrorInfo.getGetErrorAppTag(), is("must-violation")); |
| 59 | assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed")); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Checks if error app tag message listener updates the data model. |
| 64 | */ |
| 65 | @Test |
| 66 | public void processContainerSubStatementErrorAppTag() throws IOException, ParserException { |
| 67 | YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorAppTag.yang"); |
| 68 | |
| 69 | YangModule yangNode = (YangModule) node; |
| 70 | assertThat(yangNode.getName(), is("ErrorAppTag")); |
| 71 | |
| 72 | YangContainer yangContainer = (YangContainer) yangNode.getChild(); |
| 73 | assertThat(yangContainer.getName(), is("interface")); |
| 74 | |
| 75 | String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)"; |
| 76 | List<YangMust> mustConstraintList = yangContainer.getListOfMust(); |
| 77 | assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint)); |
| 78 | |
| 79 | YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo(); |
| 80 | assertThat(yangAppErrorInfo.getGetErrorAppTag(), is("An ethernet MTU must be 1500")); |
| 81 | assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed")); |
| 82 | } |
| 83 | } |