Remove deprecated Yin/YangStatementSourceImpl
[yangtools.git] / yang / yang-model-export / src / test / java / org / opendaylight / yangtools / yang / model / export / test / SchemaContextEmitterTest.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
9 package org.opendaylight.yangtools.yang.model.export.test;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
13 import static org.junit.Assert.assertNotNull;
14
15 import java.io.BufferedOutputStream;
16 import java.io.ByteArrayOutputStream;
17 import java.io.IOException;
18 import java.io.OutputStream;
19 import java.net.URISyntaxException;
20 import javax.xml.stream.XMLStreamException;
21 import org.custommonkey.xmlunit.Diff;
22 import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier;
23 import org.custommonkey.xmlunit.XMLAssert;
24 import org.custommonkey.xmlunit.XMLUnit;
25 import org.junit.Test;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
30 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
31 import org.w3c.dom.Document;
32 import org.xml.sax.SAXException;
33
34 public class SchemaContextEmitterTest {
35
36     @Test
37     public void testSchemaContextEmitter() throws ReactorException, IOException, URISyntaxException,
38             XMLStreamException, SAXException {
39         final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory(
40             "/schema-context-emitter-test");
41         assertNotNull(schemaContext);
42         assertEquals(1, schemaContext.getModules().size());
43
44         final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
45         final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
46
47         for (final Module module : schemaContext.getModules()) {
48             YinExportUtils.writeModuleToOutputStream(schemaContext, module, bufferedOutputStream);
49         }
50
51         final String output = byteArrayOutputStream.toString();
52         assertNotNull(output);
53         assertNotEquals(0, output.length());
54
55         final Document doc = YinExportTestUtils.loadDocument("/schema-context-emitter-test/foo.yin");
56         final String expected = YinExportTestUtils.toString(doc.getDocumentElement());
57
58         XMLUnit.setIgnoreWhitespace(true);
59         XMLUnit.setNormalize(true);
60
61         final Diff diff = new Diff(expected, output);
62         diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
63         XMLAssert.assertXMLEqual(diff, true);
64     }
65 }