001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2004, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol;
037:
038: import java.text.ParseException;
039: import java.util.Calendar;
040: import java.util.Date;
041: import java.util.GregorianCalendar;
042:
043: import junit.framework.Test;
044: import junit.framework.TestCase;
045: import junit.framework.TestSuite;
046:
047: /**
048: * Test that we can determine build information correctly.
049: * @author <a href="mailto:robertdw@users.sourceforge.net">Robert Watkins</a>
050: * @author <a href="mailto:hak@2mba.dk">Hack Kampbjorn</a>
051: */
052: public class BuildInfoTest extends TestCase {
053: public static Test suite() {
054: return new LogFileSetupDecorator(new TestSuite(
055: BuildInfoTest.class));
056: }
057:
058: public void testCreationFailedBuild() throws ParseException {
059: Date buildDate = new GregorianCalendar(2002, Calendar.FEBRUARY,
060: 22, 12, 15, 30).getTime();
061: BuildInfo buildInfo = new BuildInfo("log20020222121530.xml");
062: assertEquals(buildDate, buildInfo.getBuildDate());
063: assertFalse(buildInfo.isSuccessful());
064: assertNull(buildInfo.getLabel());
065: }
066:
067: public void testCreationCompressedFailedBuild()
068: throws ParseException {
069: Date buildDate = new GregorianCalendar(2004, Calendar.OCTOBER,
070: 28, 15, 24, 19).getTime();
071: BuildInfo buildInfo = new BuildInfo("log20041028152419.xml.gz");
072: assertEquals(buildDate, buildInfo.getBuildDate());
073: assertFalse(buildInfo.isSuccessful());
074: assertNull(buildInfo.getLabel());
075: }
076:
077: public void testCreationGoodBuild() throws ParseException {
078: Date buildDate = new GregorianCalendar(2002, Calendar.FEBRUARY,
079: 23, 12, 0, 0).getTime();
080: BuildInfo buildInfo = new BuildInfo(
081: "log20020223120000LBuild.1.xml");
082: assertEquals(buildDate, buildInfo.getBuildDate());
083: assertTrue(buildInfo.isSuccessful());
084: assertEquals("Build.1", buildInfo.getLabel());
085: }
086:
087: public void testCreationCompressedGoodBuild() throws ParseException {
088: Date buildDate = new GregorianCalendar(2004, Calendar.OCTOBER,
089: 28, 15, 56, 4).getTime();
090: BuildInfo buildInfo = new BuildInfo(
091: "log20041028155604LBuild.2.xml.gz");
092: assertEquals(buildDate, buildInfo.getBuildDate());
093: assertTrue(buildInfo.isSuccessful());
094: assertEquals("Build.2", buildInfo.getLabel());
095: }
096:
097: public void testCreationGoodBuildWithEmptyLabel()
098: throws ParseException {
099: Date buildDate = new GregorianCalendar(2002, Calendar.FEBRUARY,
100: 23, 12, 0, 0).getTime();
101: BuildInfo buildInfo = new BuildInfo("log20020223120000L.xml");
102: assertEquals(buildDate, buildInfo.getBuildDate());
103: assertTrue(buildInfo.isSuccessful());
104: assertEquals("", buildInfo.getLabel());
105: }
106:
107: public void testLoadBuildInfo() throws ParseException {
108: // use the BuildInfoHelper to load up the list of BuildInfo objects
109: // verify the build date for each.
110: // verify the build successful state for each
111: // verify the label for each (if any)
112: BuildInfo[] expected = {
113: new BuildInfo("log20020222120000.xml"),
114: new BuildInfo("log20020223120000LBuild.1.xml"),
115: new BuildInfo("log20020224120000.xml"),
116: new BuildInfo("log20020225120000LBuild.2.xml"),
117: new BuildInfo("log20041018160000.xml.gz"),
118: new BuildInfo("log20041018170000LBuild.3.xml.gz") };
119:
120: BuildInfoSummary results = BuildInfo
121: .loadFromDir(LogFileSetupDecorator.LOG_DIR);
122: assertEquals(3, results.getNumBrokenBuilds());
123: assertEquals(3, results.getNumSuccessfulBuilds());
124: BuildInfo[] resultsArray = results.asArray();
125: for (int i = 0; i < expected.length; i++) {
126: BuildInfo expectedResult = expected[i];
127: BuildInfo actualResult = resultsArray[i];
128: validateBuildInfo(expectedResult, actualResult);
129: }
130: }
131:
132: private void validateBuildInfo(BuildInfo expected, BuildInfo actual) {
133: assertEquals(expected.getBuildDate(), actual.getBuildDate());
134: assertEquals(expected.getLabel(), actual.getLabel());
135: assertEquals(expected.isSuccessful(), actual.isSuccessful());
136:
137: }
138: }
|