1 37 package net.sourceforge.cruisecontrol; 38 39 import java.text.ParseException ; 40 import java.util.Calendar ; 41 import java.util.Date ; 42 import java.util.GregorianCalendar ; 43 44 import junit.framework.Test; 45 import junit.framework.TestCase; 46 import junit.framework.TestSuite; 47 48 53 public class BuildInfoTest extends TestCase { 54 public static Test suite() { 55 return new LogFileSetupDecorator(new TestSuite(BuildInfoTest.class)); 56 } 57 58 public void testCreationFailedBuild() throws ParseException { 59 Date buildDate = new GregorianCalendar (2002, Calendar.FEBRUARY, 22, 12, 15, 30).getTime(); 60 BuildInfo buildInfo = new BuildInfo("log20020222121530.xml"); 61 assertEquals(buildDate, buildInfo.getBuildDate()); 62 assertFalse(buildInfo.isSuccessful()); 63 assertNull(buildInfo.getLabel()); 64 } 65 66 public void testCreationCompressedFailedBuild() throws ParseException { 67 Date buildDate = new GregorianCalendar (2004, Calendar.OCTOBER, 28, 15, 24, 19).getTime(); 68 BuildInfo buildInfo = new BuildInfo("log20041028152419.xml.gz"); 69 assertEquals(buildDate, buildInfo.getBuildDate()); 70 assertFalse(buildInfo.isSuccessful()); 71 assertNull(buildInfo.getLabel()); 72 } 73 74 public void testCreationGoodBuild() throws ParseException { 75 Date buildDate = new GregorianCalendar (2002, Calendar.FEBRUARY, 23, 12, 0, 0).getTime(); 76 BuildInfo buildInfo = new BuildInfo("log20020223120000LBuild.1.xml"); 77 assertEquals(buildDate, buildInfo.getBuildDate()); 78 assertTrue(buildInfo.isSuccessful()); 79 assertEquals("Build.1", buildInfo.getLabel()); 80 } 81 82 public void testCreationCompressedGoodBuild() throws ParseException { 83 Date buildDate = new GregorianCalendar (2004, Calendar.OCTOBER, 28, 15, 56, 4).getTime(); 84 BuildInfo buildInfo = new BuildInfo("log20041028155604LBuild.2.xml.gz"); 85 assertEquals(buildDate, buildInfo.getBuildDate()); 86 assertTrue(buildInfo.isSuccessful()); 87 assertEquals("Build.2", buildInfo.getLabel()); 88 } 89 90 public void testCreationGoodBuildWithEmptyLabel() throws ParseException { 91 Date buildDate = new GregorianCalendar (2002, Calendar.FEBRUARY, 23, 12, 0, 0).getTime(); 92 BuildInfo buildInfo = new BuildInfo("log20020223120000L.xml"); 93 assertEquals(buildDate, buildInfo.getBuildDate()); 94 assertTrue(buildInfo.isSuccessful()); 95 assertEquals("", buildInfo.getLabel()); 96 } 97 98 public void testLoadBuildInfo() throws ParseException { 99 BuildInfo[] expected = { new BuildInfo("log20020222120000.xml"), 104 new BuildInfo("log20020223120000LBuild.1.xml"), 105 new BuildInfo("log20020224120000.xml"), 106 new BuildInfo("log20020225120000LBuild.2.xml"), 107 new BuildInfo("log20041018160000.xml.gz"), 108 new BuildInfo("log20041018170000LBuild.3.xml.gz")}; 109 110 BuildInfoSummary results = BuildInfo.loadFromDir(LogFileSetupDecorator.LOG_DIR); 111 assertEquals(3, results.getNumBrokenBuilds()); 112 assertEquals(3, results.getNumSuccessfulBuilds()); 113 BuildInfo[] resultsArray = results.asArray(); 114 for (int i = 0; i < expected.length; i++) { 115 BuildInfo expectedResult = expected[i]; 116 BuildInfo actualResult = resultsArray[i]; 117 validateBuildInfo(expectedResult, actualResult); 118 } 119 } 120 121 private void validateBuildInfo(BuildInfo expected, BuildInfo actual) { 122 assertEquals(expected.getBuildDate(), actual.getBuildDate()); 123 assertEquals(expected.getLabel(), actual.getLabel()); 124 assertEquals(expected.isSuccessful(), actual.isSuccessful()); 125 126 } 127 } 128 | Popular Tags |