1 6 package fr.jayasoft.ivy.xml; 7 8 import java.io.BufferedReader ; 9 import java.io.File ; 10 import java.io.FileReader ; 11 import java.io.IOException ; 12 import java.io.InputStreamReader ; 13 import java.util.GregorianCalendar ; 14 15 import junit.framework.TestCase; 16 import fr.jayasoft.ivy.DefaultModuleDescriptor; 17 import fr.jayasoft.ivy.Ivy; 18 import fr.jayasoft.ivy.ModuleDescriptor; 19 import fr.jayasoft.ivy.util.FileUtil; 20 21 public class XmlModuleDescriptorWriterTest extends TestCase { 22 private File _dest = new File ("build/test/test-write.xml"); 23 24 public void testSimple() throws Exception { 25 DefaultModuleDescriptor md = (DefaultModuleDescriptor)XmlModuleDescriptorParser.getInstance().parseDescriptor(new Ivy(), XmlModuleDescriptorWriterTest.class.getResource("test-simple.xml"), true); 26 md.setResolvedPublicationDate(new GregorianCalendar (2005, 4, 1, 11, 0, 0).getTime()); 27 XmlModuleDescriptorWriter.write(md, _dest); 28 29 assertTrue(_dest.exists()); 30 String wrote = FileUtil.readEntirely(new BufferedReader (new FileReader (_dest))).replaceAll("\r\n", "\n").replace('\r', '\n'); 31 String expected = readEntirely("test-write-simple.xml").replaceAll("\r\n", "\n").replace('\r', '\n'); 32 assertEquals(expected, wrote); 33 } 34 35 public void testDependencies() throws Exception { 36 ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(new Ivy(), XmlModuleDescriptorWriterTest.class.getResource("test-dependencies.xml"), true); 37 XmlModuleDescriptorWriter.write(md, _dest); 38 39 assertTrue(_dest.exists()); 40 String wrote = FileUtil.readEntirely(new BufferedReader (new FileReader (_dest))).replaceAll("\r\n", "\n").replace('\r', '\n'); 41 String expected = readEntirely("test-write-dependencies.xml").replaceAll("\r\n", "\n").replace('\r', '\n'); 42 assertEquals(expected, wrote); 43 } 44 45 46 public void testFull() throws Exception { 47 ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(new Ivy(), XmlModuleDescriptorWriterTest.class.getResource("test.xml"), true); 48 XmlModuleDescriptorWriter.write(md, _dest); 49 50 assertTrue(_dest.exists()); 51 String wrote = FileUtil.readEntirely(new BufferedReader (new FileReader (_dest))).replaceAll("\r\n", "\n").replace('\r', '\n'); 52 String expected = readEntirely("test-write-full.xml").replaceAll("\r\n", "\n").replace('\r', '\n'); 53 assertEquals(expected, wrote); 54 } 55 56 57 58 private String readEntirely(String resource) throws IOException { 59 return FileUtil.readEntirely(new BufferedReader (new InputStreamReader (XmlModuleDescriptorWriterTest.class.getResource(resource).openStream()))); 60 } 61 62 public void setUp() { 63 if (_dest.exists()) { 64 _dest.delete(); 65 } 66 if (!_dest.getParentFile().exists()) { 67 _dest.getParentFile().mkdirs(); 68 } 69 } 70 71 protected void tearDown() throws Exception { 72 if (_dest.exists()) { 73 _dest.delete(); 74 } 75 } 76 } 77 | Popular Tags |