1 17 package org.apache.tools.ant.taskdefs.optional; 18 19 import org.apache.tools.ant.BuildFileTest; 20 import org.apache.tools.ant.util.FileUtils; 21 22 import java.util.Properties ; 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.IOException ; 26 27 31 public class ReplaceRegExpTest extends BuildFileTest { 32 private static final String PROJECT_PATH = "src/etc/testcases/taskdefs/optional"; 33 public ReplaceRegExpTest(String name) { 34 super(name); 35 } 36 37 public void setUp() { 38 configureProject(PROJECT_PATH + "/replaceregexp.xml"); 39 } 40 41 public void tearDown() { 42 executeTarget("cleanup"); 43 } 44 45 public void testReplace() throws IOException { 46 Properties original = new Properties (); 47 FileInputStream propsFile = null; 48 try { 49 propsFile = new FileInputStream (PROJECT_PATH + "/replaceregexp.properties"); 50 original.load(propsFile); 51 } finally { 52 if (propsFile != null) { 53 propsFile.close(); 54 propsFile = null; 55 } 56 } 57 58 assertEquals("Def", original.get("OldAbc")); 59 60 executeTarget("testReplace"); 61 62 Properties after = new Properties (); 63 try { 64 propsFile = new FileInputStream (PROJECT_PATH + "/test.properties"); 65 after.load(propsFile); 66 } finally { 67 if (propsFile != null) { 68 propsFile.close(); 69 propsFile = null; 70 } 71 } 72 73 assertNull(after.get("OldAbc")); 74 assertEquals("AbcDef", after.get("NewProp")); 75 } 76 public void testDirectoryDateDoesNotChange() { 78 executeTarget("touchDirectory"); 79 File myFile = new File (PROJECT_PATH + "/" + getProject().getProperty("tmpregexp")); 80 long timeStampBefore = myFile.lastModified(); 81 executeTarget("testDirectoryDateDoesNotChange"); 82 long timeStampAfter = myFile.lastModified(); 83 assertEquals("directory date should not change", 84 timeStampBefore, timeStampAfter); 85 } 86 public void testDontAddNewline1() throws IOException { 87 executeTarget("testDontAddNewline1"); 88 assertTrue("Files match", 89 FileUtils.newFileUtils() 90 .contentEquals(new File (PROJECT_PATH + "/test.properties"), 91 new File (PROJECT_PATH + "/replaceregexp2.result.properties"))); 92 } 93 94 public void testDontAddNewline2() throws IOException { 95 executeTarget("testDontAddNewline2"); 96 assertTrue("Files match", 97 FileUtils.newFileUtils() 98 .contentEquals(new File (PROJECT_PATH + "/test.properties"), 99 new File (PROJECT_PATH + "/replaceregexp2.result.properties"))); 100 } 101 102 } | Popular Tags |