KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > BuildInfoTest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2004, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol;
38
39 import java.text.ParseException JavaDoc;
40 import java.util.Calendar JavaDoc;
41 import java.util.Date JavaDoc;
42 import java.util.GregorianCalendar JavaDoc;
43
44 import junit.framework.Test;
45 import junit.framework.TestCase;
46 import junit.framework.TestSuite;
47
48 /**
49  * Test that we can determine build information correctly.
50  * @author <a HREF="mailto:robertdw@users.sourceforge.net">Robert Watkins</a>
51  * @author <a HREF="mailto:hak@2mba.dk">Hack Kampbjorn</a>
52  */

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 JavaDoc {
59         Date JavaDoc buildDate = new GregorianCalendar JavaDoc(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 JavaDoc {
67         Date JavaDoc buildDate = new GregorianCalendar JavaDoc(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 JavaDoc {
75         Date JavaDoc buildDate = new GregorianCalendar JavaDoc(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 JavaDoc {
83         Date JavaDoc buildDate = new GregorianCalendar JavaDoc(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 JavaDoc {
91         Date JavaDoc buildDate = new GregorianCalendar JavaDoc(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 JavaDoc {
99         // use the BuildInfoHelper to load up the list of BuildInfo objects
100
// verify the build date for each.
101
// verify the build successful state for each
102
// verify the label for each (if any)
103
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