1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.PrintStream ; 25 import junit.framework.*; 26 import org.netbeans.junit.*; 27 28 32 public class ConvertImportTest extends NbTestCase { 33 private File testFile; 34 public ConvertImportTest(java.lang.String testName) { 35 super(testName); 36 } 37 38 39 public void testConvertImport() throws IOException { 40 String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 41 "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" + 42 "<import file=\"../../../nbbuild/templates/xtest-unit.xml\"/>\n" + 43 "</project>"; 44 String xmlOut = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 45 "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" + 46 "<import file=\"../templates/xtest-unit.xml\"/>\n" + 47 "</project>"; 48 49 String xmlOutPrefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 50 "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" + 51 "<import file=\"${test.dist.dir}/templates/xtest-unit.xml\"/>\n" + 52 "</project>"; 53 54 createFile(xml); 55 56 ConvertImport convert = new ConvertImport(); 57 convert.setFile(testFile); 58 convert.setOldName("templates/xtest-unit.xml"); 59 convert.setNewPath("../templates/xtest-unit.xml"); 60 convert.execute(); 61 assertNewXml(xmlOut); 62 63 createFile(xml); 64 convert.setPropertyPrefixName("test.dist.dir"); 65 convert.setNewPath("templates/xtest-unit.xml"); 66 convert.execute(); 67 assertNewXml(xmlOutPrefix); 68 69 xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 70 "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" + 71 "<!-- <import file=\"../../../nbbuild/templates/xtest-unit.xml\"/>\n-->" + 72 "</project>"; 73 createFile(xml); 74 convert.execute(); 75 assertNewXml(xml); 76 77 xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 78 "<!-- file -->" + 79 "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" + 80 "<import file=\"../../../nbbuild/templates/xtest-unit.xml\"/>\n" + 81 "</project>"; 82 xmlOut = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 83 "<!-- file -->" + 84 "<project name=\"ant/freeform/test-unit\" basedir=\".\" default=\"all\">\n" + 85 "<import file=\"${test.dist.dir}/xx\"/>\n" + 86 "</project>"; 87 createFile(xml); 88 convert.setNewPath("xx"); 89 convert.execute(); 90 assertNewXml(xmlOut); 91 92 } 93 94 private File createFile(String xml) throws IOException { 95 testFile = new File (getWorkDir(),"testFile.xml"); 96 PrintStream ps = new PrintStream (testFile); 97 ps.print(xml); 98 ps.close(); 99 return testFile; 100 } 101 102 private void assertNewXml(String xmlOut) throws IOException { 103 File file = new File (getWorkDir(),"ref.xml"); 104 PrintStream ps = new PrintStream (file); 105 ps.print(xmlOut); 106 assertFile(testFile,file); 107 } 108 } 109 | Popular Tags |