Fix yang-export warnings
[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
9 package org.opendaylight.yangtools.yang.model.export;
10
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import java.io.BufferedOutputStream;
16 import java.io.ByteArrayOutputStream;
17 import java.io.OutputStream;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.Revision;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24
25 public class Bug6856Test {
26
27     @Test
28     public void testImplicitInputAndOutputInRpc() throws Exception {
29         final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class,
30             "/bugs/bug-6856/foo.yang");
31         assertNotNull(schemaContext);
32
33         final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
34         final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
35
36         final Module fooModule = schemaContext.findModule("foo", Revision.of("2017-02-28")).get();
37         YinExportUtils.writeModuleAsYinText(fooModule.asEffectiveStatement(), bufferedOutputStream);
38
39         final String 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 SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class,
50             "/bugs/bug-6856/bar.yang");
51         assertNotNull(schemaContext);
52
53         final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
54         final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
55
56         final Module barModule = schemaContext.findModule("bar", Revision.of("2017-02-28")).get();
57         YinExportUtils.writeModuleAsYinText(barModule.asEffectiveStatement(), bufferedOutputStream);
58
59         final String output = byteArrayOutputStream.toString();
60         assertNotNull(output);
61         assertFalse(output.isEmpty());
62
63         assertTrue(output.contains("<input>"));
64         assertTrue(output.contains("<output>"));
65     }
66 }