Vidyashree Rama | 09e1ca5 | 2016-03-29 12:00:42 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vidyashree Rama | 09e1ca5 | 2016-03-29 12:00:42 +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 java.io.IOException; |
| 20 | |
| 21 | import org.junit.Test; |
| 22 | import org.onosproject.yangutils.datamodel.YangNode; |
| 23 | import org.onosproject.yangutils.datamodel.YangModule; |
| 24 | import org.onosproject.yangutils.datamodel.YangRpc; |
| 25 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
| 26 | import org.onosproject.yangutils.datamodel.YangStatusType; |
| 27 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| 28 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
| 29 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 30 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 31 | |
| 32 | import static org.hamcrest.core.Is.is; |
| 33 | import static org.junit.Assert.assertThat; |
| 34 | |
| 35 | /** |
| 36 | * Test cases for testing Rpc listener functionality. |
| 37 | */ |
| 38 | public class RpcListenerTest { |
| 39 | |
| 40 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 41 | |
| 42 | /** |
| 43 | * Checks valid rpc statements. |
| 44 | */ |
| 45 | @Test |
| 46 | public void processValidRpcStatement() throws IOException, ParserException { |
| 47 | |
| 48 | YangNode node = manager.getDataModel("src/test/resources/ValidRpcStatement.yang"); |
| 49 | |
| 50 | assertThat((node instanceof YangModule), is(true)); |
| 51 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 52 | YangModule yangNode = (YangModule) node; |
| 53 | assertThat(yangNode.getName(), is("rock")); |
| 54 | |
| 55 | YangRpc yangRpc = (YangRpc) yangNode.getChild(); |
| 56 | assertThat(yangRpc.getName(), is("rock-the-house")); |
| 57 | assertThat(yangRpc.getDescription(), is("\"description\"")); |
| 58 | assertThat(yangRpc.getReference(), is("\"reference\"")); |
| 59 | assertThat(yangRpc.getStatus(), is(YangStatusType.CURRENT)); |
| 60 | |
| 61 | YangTypeDef typeDef = (YangTypeDef) yangRpc.getChild(); |
| 62 | assertThat(typeDef.getName(), is("my-type")); |
| 63 | assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED)); |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 64 | assertThat(typeDef.getTypeDefBaseType().getDataType(), is(YangDataTypes.INT32)); |
Vidyashree Rama | 09e1ca5 | 2016-03-29 12:00:42 +0530 | [diff] [blame] | 65 | } |
| 66 | } |