c00cb6a4c95657934b036907e4b2970769196bae
[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.net.URISyntaxException;
14 import java.util.Set;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.stmt.TestUtils;
22
23 public class YinFileRpcStmtTest {
24
25     private Set<Module> modules;
26
27     @Before
28     public void init() throws URISyntaxException, ReactorException {
29         modules = TestUtils.loadYinModules(getClass().getResource
30                 ("/semantic-statement-parser/yin/modules").toURI());
31         assertEquals(9, modules.size());
32     }
33
34     @Test
35     public void testRpc() {
36         Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring");
37         assertNotNull(testModule);
38
39         Set<RpcDefinition> rpcs = testModule.getRpcs();
40         assertEquals(1, rpcs.size());
41
42         RpcDefinition rpc = rpcs.iterator().next();
43         assertEquals("get-schema", rpc.getQName().getLocalName());
44         assertEquals("This operation is used to retrieve a schema from the\n" +
45                 "NETCONF server.\n" +
46                 "\n" +
47                 "Positive Response:\n" +
48                 "The NETCONF server returns the requested schema.\n" +
49                 "\n" +
50                 "Negative Response:\n" +
51                 "If requested schema does not exist, the <error-tag> is\n" +
52                 "'invalid-value'.\n" +
53                 "\n" +
54                 "If more than one schema matches the requested parameters, the\n" +
55                 "<error-tag> is 'operation-failed', and <error-app-tag> is\n" +
56                 "'data-not-unique'.", rpc.getDescription());
57
58         ContainerSchemaNode input = rpc.getInput();
59         assertNotNull(input);
60         assertEquals(3, input.getChildNodes().size());
61
62         ContainerSchemaNode output = rpc.getOutput();
63         assertNotNull(output);
64         assertEquals(1, output.getChildNodes().size());
65     }
66 }