2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.export.test;
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;
15 import java.io.BufferedOutputStream;
16 import java.io.ByteArrayOutputStream;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class Bug5531Test {
25 public void test() throws Exception {
26 SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug5531");
28 assertNotNull(schema);
29 assertNotNull(schema.getModules());
30 assertEquals(1, schema.getModules().size());
32 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
33 BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
35 // write small module of size less than 8kB
36 for (Module module : schema.getModules()) {
37 YinExportUtils.writeModuleToOutputStream(schema, module, bufferedOutputStream);
40 String output = byteArrayOutputStream.toString();
42 // if all changes were flushed then following conditions are satisfied
43 assertNotEquals("Output should not be empty", 0, output.length());
44 assertTrue("Output should contains start of the module", output.contains("<module"));
45 assertTrue("Output should contains end of the module", output.contains("</module>"));