Fix yang-export warnings
[yangtools.git] / model / yang-model-export / src / test / java / org / opendaylight / yangtools / yang / model / export / Bug5531Test.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.model.export;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
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 org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
20 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
21
22 public class Bug5531Test {
23     @Test
24     public void test() throws Exception {
25         EffectiveModelContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug5531");
26
27         assertNotNull(schema);
28         assertNotNull(schema.getModules());
29         assertEquals(1, schema.getModules().size());
30
31         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
32         BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
33
34         // write small module of size less than 8kB
35         for (ModuleEffectiveStatement module : schema.getModuleStatements().values()) {
36             YinExportUtils.writeModuleAsYinText(module, bufferedOutputStream);
37         }
38
39         String output = byteArrayOutputStream.toString();
40
41         // if all changes were flushed then following conditions are satisfied
42         assertNotEquals("Output should not be empty", 0, output.length());
43         assertTrue("Output should contains start of the module", output.contains("<module"));
44         assertTrue("Output should contains end of the module", output.contains("</module>"));
45     }
46 }