97248a8dc371553c9b4fa7a32da7e95e3ae40ed1
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / yin / YinFileRpcStmtTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.stmt.yin;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.io.IOException;
14 import java.net.URISyntaxException;
15 import java.util.Optional;
16 import java.util.Set;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.stmt.TestUtils;
25 import org.xml.sax.SAXException;
26
27 public class YinFileRpcStmtTest {
28
29     private SchemaContext context;
30
31     @Before
32     public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
33         context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
34         assertEquals(9, context.getModules().size());
35     }
36
37     @Test
38     public void testRpc() {
39         Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
40
41         Set<RpcDefinition> rpcs = testModule.getRpcs();
42         assertEquals(1, rpcs.size());
43
44         RpcDefinition rpc = rpcs.iterator().next();
45         assertEquals("get-schema", rpc.getQName().getLocalName());
46         assertEquals(Optional.of("This operation is used to retrieve a schema from the\n"
47                 + "NETCONF server.\n"
48                 + "\n"
49                 + "Positive Response:\n"
50                 + "The NETCONF server returns the requested schema.\n"
51                 + "\n"
52                 + "Negative Response:\n"
53                 + "If requested schema does not exist, the <error-tag> is\n"
54                 + "'invalid-value'.\n"
55                 + "\n"
56                 + "If more than one schema matches the requested parameters, the\n"
57                 + "<error-tag> is 'operation-failed', and <error-app-tag> is\n"
58                 + "'data-not-unique'."), rpc.getDescription());
59
60         ContainerSchemaNode input = rpc.getInput();
61         assertNotNull(input);
62         assertEquals(3, input.getChildNodes().size());
63
64         ContainerSchemaNode output = rpc.getOutput();
65         assertNotNull(output);
66         assertEquals(1, output.getChildNodes().size());
67     }
68 }