Update DataObjectStep class hierarchy
[yangtools.git] / model / yang-model-export / src / test / java / org / opendaylight / yangtools / yang / model / export / Bug6856Test.java
1 /*
2  * Copyright (c) 2017 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.model.export;
9
10 import static org.junit.jupiter.api.Assertions.assertFalse;
11 import static org.junit.jupiter.api.Assertions.assertNotNull;
12 import static org.junit.jupiter.api.Assertions.assertTrue;
13
14 import java.io.BufferedOutputStream;
15 import java.io.ByteArrayOutputStream;
16 import org.junit.jupiter.api.Test;
17 import org.opendaylight.yangtools.yang.common.Revision;
18 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
19
20 public class Bug6856Test {
21     @Test
22     public void testImplicitInputAndOutputInRpc() throws Exception {
23         final var schemaContext = YangParserTestUtils.parseYang("""
24             module foo {
25               namespace foo;
26               prefix foo;
27               revision 2017-02-28;
28
29               rpc foo-rpc {}
30             }""");
31         assertNotNull(schemaContext);
32
33         final var byteArrayOutputStream = new ByteArrayOutputStream();
34         final var bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
35
36         final var fooModule = schemaContext.findModule("foo", Revision.of("2017-02-28")).orElseThrow();
37         YinExportUtils.writeModuleAsYinText(fooModule.asEffectiveStatement(), bufferedOutputStream);
38
39         final var output = byteArrayOutputStream.toString();
40         assertNotNull(output);
41         assertFalse(output.isEmpty());
42
43         assertFalse(output.contains("<input>"));
44         assertFalse(output.contains("<output>"));
45     }
46
47     @Test
48     public void testExplicitInputAndOutputInRpc() throws Exception {
49         final var schemaContext = YangParserTestUtils.parseYang("""
50             module bar {
51               namespace bar;
52               prefix bar;
53               revision 2017-02-28;
54
55               rpc bar-rpc {
56                 input {
57                   leaf input-leaf {
58                     type string;
59                   }
60                 }
61                 output {
62                   leaf output-leaf {
63                     type string;
64                   }
65                 }
66               }
67             }""");
68         assertNotNull(schemaContext);
69
70         final var byteArrayOutputStream = new ByteArrayOutputStream();
71         final var bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
72
73         final var barModule = schemaContext.findModule("bar", Revision.of("2017-02-28")).orElseThrow();
74         YinExportUtils.writeModuleAsYinText(barModule.asEffectiveStatement(), bufferedOutputStream);
75
76         final var output = byteArrayOutputStream.toString();
77         assertNotNull(output);
78         assertFalse(output.isEmpty());
79
80         assertTrue(output.contains("<input>"));
81         assertTrue(output.contains("<output>"));
82     }
83 }