blob: adb88dcb9ac95fb733adc5c99f01fca2da4f8d9a [file] [log] [blame]
Vidyashree Rama6a72b792016-03-29 12:00:42 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vidyashree Rama6a72b792016-03-29 12:00:42 +05303 *
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
17package org.onosproject.yangutils.parser.impl.listeners;
18
19import java.io.IOException;
20
21import org.junit.Test;
22import org.onosproject.yangutils.datamodel.YangNode;
23import org.onosproject.yangutils.datamodel.YangModule;
24import org.onosproject.yangutils.datamodel.YangRpc;
25import org.onosproject.yangutils.datamodel.YangTypeDef;
26import org.onosproject.yangutils.datamodel.YangStatusType;
27import org.onosproject.yangutils.datamodel.YangNodeType;
28import org.onosproject.yangutils.datamodel.YangDataTypes;
29import org.onosproject.yangutils.parser.exceptions.ParserException;
30import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31
32import static org.hamcrest.core.Is.is;
33import static org.junit.Assert.assertThat;
34
35/**
36 * Test cases for testing Rpc listener functionality.
37 */
38public 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));
64 assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
65 }
66}