001package edu.pdx.cs.joy.family; 002 003import java.io.PrintWriter; 004import java.io.StringReader; 005import java.io.StringWriter; 006 007 008/** 009 * This class tests the functionality of the <code>XmlDumper</code> 010 * and <code>XmlParser</code> classes. 011 */ 012public class XmlTest extends FamilyTreeConversionTestCase { 013 014 /** 015 * Converts a FamilyTree to XML and returns the XML as a String. 016 */ 017 protected String getStringFor(FamilyTree tree) { 018 // Write the XML to a String 019 StringWriter sw = new StringWriter(); 020 PrintWriter pw = new PrintWriter(sw, true); 021 XmlDumper dumper = new XmlDumper(pw); 022 dumper.dump(tree); 023 String xml = sw.toString(); 024 return xml; 025 } 026 027 /** 028 * Parsers a FamilyTree from a String containing XML 029 */ 030 protected FamilyTree getFamilyTreeFor(String xml) 031 throws FamilyTreeException { 032 033 // Parse the XML from the String 034 StringReader sr = new StringReader(xml); 035 XmlParser parser = new XmlParser(sr); 036 return parser.parse(); 037 } 038 039 040}