| 1 | // Jomic - a viewer for comic book archives. |
| 2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | package net.sf.jomic.tools; |
| 17 | |
| 18 | import java.io.File; |
| 19 | import java.io.FileWriter; |
| 20 | import java.io.IOException; |
| 21 | import java.io.Writer; |
| 22 | |
| 23 | import junit.framework.TestCase; |
| 24 | |
| 25 | import org.w3c.dom.Document; |
| 26 | |
| 27 | /** |
| 28 | * TestCase for XmlTools. |
| 29 | * |
| 30 | * @author Thomas Aglassinger |
| 31 | */ |
| 32 | public class XmlToolsTest extends TestCase |
| 33 | { |
| 34 | private TestTools testTools; |
| 35 | private XmlTools xmlTools; |
| 36 | |
| 37 | protected void setUp() |
| 38 | throws Exception { |
| 39 | super.setUp(); |
| 40 | testTools = TestTools.instance(); |
| 41 | xmlTools = XmlTools.instance(); |
| 42 | } |
| 43 | |
| 44 | public void testCreateDocument() { |
| 45 | Document document = xmlTools.createEmptyDocument(null); |
| 46 | |
| 47 | assertNotNull(document); |
| 48 | assertEquals(null, document.getFirstChild()); |
| 49 | |
| 50 | document = xmlTools.createEmptyDocument("hugo"); |
| 51 | assertNotNull(document); |
| 52 | assertNotNull(document.getFirstChild()); |
| 53 | } |
| 54 | |
| 55 | public void testWrite() |
| 56 | throws IOException { |
| 57 | Document document = xmlTools.createEmptyDocument("some"); |
| 58 | String outFileName = testTools.getTestFileName(XmlToolsTest.class, "testWrite", null, "xml"); |
| 59 | File outFile = testTools.getTestOutputFile(outFileName); |
| 60 | Writer writer = new FileWriter(outFile); |
| 61 | |
| 62 | try { |
| 63 | xmlTools.write(document, writer); |
| 64 | } finally { |
| 65 | writer.close(); |
| 66 | } |
| 67 | testTools.assertFilesEqual(outFileName); |
| 68 | } |
| 69 | |
| 70 | protected void tearDown() |
| 71 | throws Exception { |
| 72 | xmlTools = null; |
| 73 | testTools = null; |
| 74 | super.tearDown(); |
| 75 | } |
| 76 | } |