001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2007, 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.dashboard.seleniumtests;
037:
038: import java.io.File;
039:
040: import net.sourceforge.cruisecontrol.dashboard.testhelpers.DataUtils;
041: import net.sourceforge.cruisecontrol.dashboard.utils.CCDateFormatter;
042:
043: import org.apache.commons.io.FileUtils;
044: import org.joda.time.DateTime;
045:
046: public class FailedBuildMoreThan24HourTest extends SeleniumTestCase {
047:
048: private File failedLevel8;
049:
050: private File failedLevel7;
051:
052: private File failedLevel6;
053:
054: private File failedLevel5;
055:
056: private File failedLevel4;
057:
058: private File failedLevel3;
059:
060: private File failedLevel2;
061:
062: private File failedLevel1;
063:
064: private File failedLevel0;
065:
066: private File justSucceeded;
067:
068: private File justFailed;
069:
070: protected void doSetUp() throws Exception {
071: File projectWithoutPublishers = new File(DataUtils
072: .getLogRootOfWebapp(), "projectWithoutPublishers");
073: DateTime now = new DateTime();
074: failedLevel8 = new File(projectWithoutPublishers, "log"
075: + CCDateFormatter.yyyyMMddHHmmss(now.minusDays(2))
076: + ".xml");
077: failedLevel7 = new File(projectWithoutPublishers, "log"
078: + CCDateFormatter.yyyyMMddHHmmss(now
079: .minusMinutes(7 * 180 + 12)) + ".xml");
080: failedLevel6 = new File(projectWithoutPublishers, "log"
081: + CCDateFormatter.yyyyMMddHHmmss(now
082: .minusMinutes(6 * 180 + 12)) + ".xml");
083: failedLevel5 = new File(projectWithoutPublishers, "log"
084: + CCDateFormatter.yyyyMMddHHmmss(now
085: .minusMinutes(5 * 180 + 12)) + ".xml");
086: failedLevel4 = new File(projectWithoutPublishers, "log"
087: + CCDateFormatter.yyyyMMddHHmmss(now
088: .minusMinutes(4 * 180 + 12)) + ".xml");
089: failedLevel3 = new File(projectWithoutPublishers, "log"
090: + CCDateFormatter.yyyyMMddHHmmss(now
091: .minusMinutes(3 * 180 + 12)) + ".xml");
092: failedLevel2 = new File(projectWithoutPublishers, "log"
093: + CCDateFormatter.yyyyMMddHHmmss(now
094: .minusMinutes(2 * 180 + 12)) + ".xml");
095: failedLevel1 = new File(projectWithoutPublishers, "log"
096: + CCDateFormatter.yyyyMMddHHmmss(now
097: .minusMinutes(1 * 180 + 12)) + ".xml");
098: failedLevel0 = new File(projectWithoutPublishers, "log"
099: + CCDateFormatter.yyyyMMddHHmmss(now
100: .minusMinutes(0 * 180 + 12)) + ".xml");
101: justSucceeded = new File(projectWithoutPublishers, "log"
102: + CCDateFormatter.yyyyMMddHHmmss(now
103: .minusMinutes(0 * 180 + 8)) + "Lbuild.123.xml");
104: justFailed = new File(projectWithoutPublishers, "log"
105: + CCDateFormatter.yyyyMMddHHmmss(now
106: .minusMinutes(0 * 180 + 5)) + ".xml");
107: }
108:
109: protected void doTearDown() throws Exception {
110: File[] files = new File[] { failedLevel8, failedLevel7,
111: failedLevel6, failedLevel5, failedLevel4, failedLevel3,
112: failedLevel2, failedLevel1, failedLevel0,
113: justSucceeded, justFailed };
114: for (int i = 0; i < files.length; i++) {
115: try {
116: FileUtils.forceDelete(files[i]);
117: } catch (Exception e) {
118: continue;
119: }
120: }
121: }
122:
123: public void testChangeColorWhenFailedDateChanges() throws Exception {
124: openDashboardPage();
125: assertClassName(failedLevel0, "level_0");
126: assertClassName(failedLevel1, "level_1");
127: assertClassName(failedLevel2, "level_2");
128: assertClassName(failedLevel3, "level_3");
129: assertClassName(failedLevel4, "level_4");
130: assertClassName(failedLevel5, "level_5");
131: assertClassName(failedLevel6, "level_6");
132: assertClassName(failedLevel7, "level_7");
133: assertClassName(failedLevel8, "level_8");
134: assertClassName(justSucceeded, "level_0");
135: assertClassName(justFailed, "level_0");
136: }
137:
138: private void assertClassName(File file, String className)
139: throws Exception {
140: file.createNewFile();
141: String textPresent = "selenium.browserbot.getCurrentWindow().document.getElementById('projectWithoutPublishers_level').className.indexOf('"
142: + className + "') >= 0";
143: user.waitForCondition(textPresent, "20000");
144: }
145: }
|