a3d5a6c34b7da59b598103ac426126b101f4623b
[yangtools.git] / yang / yang-model-export / src / test / java / org / opendaylight / yangtools / yang / model / export / test / Bug4504Test.java
1 /*
2  * Copyright (c) 2015 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.test;
9
10 import static org.junit.Assert.assertNotNull;
11 import java.io.File;
12 import java.io.FileOutputStream;
13 import java.io.OutputStream;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.model.api.Module;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
18
19 public class Bug4504Test {
20     @Test
21     public void test() throws Exception {
22         SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug4504");
23         assertNotNull(schema);
24         final File outDir = new File("target/bug4504-export");
25         outDir.mkdirs();
26         for (final Module module : schema.getModules()) {
27             exportModule(schema, module, outDir);
28         }
29     }
30
31     private static File exportModule(final SchemaContext schemaContext, final Module module, final File outDir)
32             throws Exception {
33         final File outFile = new File(outDir, YinExportUtils.wellFormedYinName(module.getName(), module.getRevision()));
34         try (OutputStream output = new FileOutputStream(outFile)) {
35             YinExportUtils.writeModuleToOutputStream(schemaContext, module, output);
36         }
37         return outFile;
38     }
39 }