Bug 7159: Add yang-test-util artifact
[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 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
19
20 public class Bug4504Test {
21     @Test
22     public void test() throws Exception {
23         SchemaContext schema = YangParserTestUtils.parseYangSources("/bugs/bug4504");
24         assertNotNull(schema);
25         final File outDir = new File("target/bug4504-export");
26         outDir.mkdirs();
27         for (final Module module : schema.getModules()) {
28             exportModule(schema, module, outDir);
29         }
30     }
31
32     private static File exportModule(final SchemaContext schemaContext, final Module module, final File outDir)
33             throws Exception {
34         final File outFile = new File(outDir, YinExportUtils.wellFormedYinName(module.getName(), module.getRevision()));
35         try (OutputStream output = new FileOutputStream(outFile)) {
36             YinExportUtils.writeModuleToOutputStream(schemaContext, module, output);
37         }
38         return outFile;
39     }
40 }