1 37 package net.sourceforge.cruisecontrol; 38 39 import java.text.SimpleDateFormat ; 40 import java.util.Date ; 41 42 import junit.framework.TestCase; 43 44 public class ModificationTest extends TestCase { 45 46 public void testToXml() { 47 Date modifiedTime = new Date (); 48 SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy"); 49 Modification mod = new Modification(); 50 51 Modification.ModifiedFile modfile = mod.createModifiedFile("File\"Name&", "Folder'Name"); 52 modfile.action = "checkin"; 53 54 mod.modifiedTime = modifiedTime; 55 mod.userName = "User<>Name"; 56 mod.comment = "Comment"; 57 58 String base = 59 "<modification type=\"unknown\">" 60 + "<file action=\"checkin\"><filename>File\"Name&</filename>" 61 + "<project>Folder'Name</project></file>" 62 + "<date>" + formatter.format(modifiedTime) + "</date>" 63 + "<user>User<>Name</user>" 64 + "<comment><![CDATA[Comment]]></comment>"; 65 String closingTag = "</modification>"; 66 String expected = base + closingTag; 67 68 assertEquals(expected, mod.toXml(formatter)); 69 70 String expectedWithEmail = 71 base + "<email>foo.bar@quuuux.quuux.quux.qux</email>" + closingTag; 72 mod.emailAddress = "foo.bar@quuuux.quuux.quux.qux"; 73 74 assertEquals(expectedWithEmail, mod.toXml(formatter)); 75 } 76 77 public void testBadComment() { 78 Date modifiedTime = new Date (); 79 SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy"); 80 Modification mod = new Modification(); 81 82 Modification.ModifiedFile modfile = mod.createModifiedFile("File\"Name&", "Folder'Name"); 83 modfile.action = "checkin"; 84 85 mod.modifiedTime = modifiedTime; 86 mod.userName = "User<>Name"; 87 mod.comment = "Attempting to heal the wounded build.\0x18"; 88 89 String base = 90 "<modification type=\"unknown\">" 91 + "<file action=\"checkin\"><filename>File\"Name&</filename>" 92 + "<project>Folder'Name</project></file>" 93 + "<date>" + formatter.format(modifiedTime) + "</date>" 94 + "<user>User<>Name</user>" 95 + "<comment><![CDATA[Unable to parse comment. It contains illegal data.]]></comment>"; 96 String closingTag = "</modification>"; 97 String expected = base + closingTag; 98 99 assertEquals(expected, mod.toXml(formatter)); 100 } 101 102 public void testToElementAndBack() throws Exception { 103 Date modifiedTime = new Date (); 104 SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy"); 105 Modification mod = new Modification(); 106 107 Modification.ModifiedFile modfile = mod.createModifiedFile("File\"Name&", "Folder'Name"); 108 modfile.action = "checkin"; 109 110 mod.modifiedTime = modifiedTime; 111 mod.userName = "User<>Name"; 112 mod.comment = "Attempting to heal the wounded build.\0x18"; 113 114 Modification modification = new Modification(); 115 modification.fromElement(mod.toElement(formatter), formatter); 116 mod.equals(modification); 117 118 assertEquals("Folder'Name/File\"Name&", modification.getFullPath()); 120 } 121 } | Popular Tags |