BUG-4688: Rework SchemaContext module lookups
[yangtools.git] / yang / yang-model-export / src / test / java / org / opendaylight / yangtools / yang / model / export / test / 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.test;
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.QName;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
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 SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class,
30             "/bugs/bug6856/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", QName.parseRevision("2017-02-28")).get();
37         YinExportUtils.writeModuleToOutputStream(schemaContext, fooModule, 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/bug6856/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", QName.parseRevision("2017-02-28")).get();
57         YinExportUtils.writeModuleToOutputStream(schemaContext, barModule, 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 }