3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 require_once(dirname(__FILE__).'/../include/HudsonJob.class.php');
22 Mock::generatePartial(
24 'HudsonJobTestVersion',
25 array('_getXMLObject', 'getIconsPath', 'getHudsonControler')
27 Mock::generatePartial(
29 'HudsonJobTestColorVersion',
33 require_once(dirname(__FILE__).'/../include/hudson.class.php');
34 Mock::generate('hudson');
36 require_once 'common/language/BaseLanguage.class.php';
37 Mock::generate('BaseLanguage');
39 class HudsonJobTest extends UnitTestCase {
41 * Constructor of the test. Can be ommitted.
42 * Usefull to set the name of the test
44 function HudsonJobTest($name = 'HudsonJob test') {
45 $this->UnitTestCase($name);
49 $GLOBALS['Language'] = new MockBaseLanguage($this);
52 function testMalformedURL() {
53 $this->expectException('HudsonJobURLMalformedException');
55 $j = new HudsonJob("toto");
57 function testMissingSchemeURL() {
58 $this->expectException('HudsonJobURLMalformedException');
60 $j = new HudsonJob("code4:8080/hudson/jobs/Codendi");
62 function testMissingHostURL() {
63 $this->expectException('HudsonJobURLMalformedException');
65 $j = new HudsonJob("http://");
68 function testWrongXMLFile() {
70 <?xml version='1.0' standalone='yes'?>
76 $xmldom = new SimpleXMLElement($xmlstr);
78 $j = new HudsonJobTestVersion($this);
79 $j->setReturnValue('_getXMLObject', $xmldom);
80 $j->setReturnValue('getIconsPath', '');
86 function testSimpleJob() {
88 <?xml version='1.0' standalone='yes'?>
93 <description></description>
94 <displayName>Codendi</displayName>
96 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/Codendi/</url>
97 <buildable>true</buildable>
101 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/Codendi/1/</url>
104 <description>Build stability: 1 des 5 derniers builds ont échoué.</description>
108 <description>Résultats des tests: 5 tests failing out of a total of 403 tests.</description>
111 <inQueue>false</inQueue>
112 <keepDependencies>false</keepDependencies>
115 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/Codendi/60/</url>
119 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/Codendi/60/</url>
120 </lastCompletedBuild>
123 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/Codendi/30/</url>
125 <lastSuccessfulBuild>
127 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/Codendi/60/</url>
128 </lastSuccessfulBuild>
129 <nextBuildNumber>61</nextBuildNumber>
133 $xmldom = new SimpleXMLElement($xmlstr);
136 $j = new HudsonJobTestVersion($this);
137 $j->setReturnValue('_getXMLObject', $xmldom);
138 $mh = new Mockhudson($this);
139 $mh->setReturnValue('getIconsPath', '');
140 $j->setReturnValue('getHudsonControler', $mh);
141 $j->setReturnValue('getIconsPath', '');
143 $j->HudsonJob("http://myCIserver/jobs/myCIjob");
145 $this->assertEqual($j->getProjectStyle(), "freeStyleProject");
146 $this->assertEqual($j->getName(), "Codendi");
147 $this->assertEqual($j->getUrl(), "http://code4.grenoble.xrce.xerox.com:8080/hudson/job/Codendi/");
148 $this->assertEqual($j->getColor(), "yellow");
149 $this->assertEqual($j->getStatusIcon(), "status_yellow.png");
151 $this->assertEqual($j->getLastBuildNumber(), "60");
152 $this->assertEqual($j->getLastSuccessfulBuildNumber(), "60");
153 $this->assertEqual($j->getLastFailedBuildNumber(), "30");
154 $this->assertEqual($j->getNextBuildNumber(), "61");
155 $this->assertTrue($j->hasBuilds());
156 $this->assertTrue($j->isBuildable());
158 $this->assertEqual($j->getHealthScores(), array('79', '98'));
159 $this->assertEqual($j->getHealthAverageScore(), '88');
160 $this->assertEqual($j->getWeatherReportIcon(), "health_80_plus.gif");
164 function testJobFromAnotherJob() {
166 <?xml version='1.0' standalone='yes'?>
170 <description></description>
171 <displayName>TestProjectExistingJob</displayName>
172 <name>TestProjectExistingJob</name>
173 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectExistingJob/</url>
174 <buildable>true</buildable>
178 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectExistingJob/1/</url>
181 <description>Build stability: Tous les builds récents ont échoué.</description>
184 <inQueue>false</inQueue>
185 <keepDependencies>false</keepDependencies>
188 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectExistingJob/1/</url>
192 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectExistingJob/1/</url>
193 </lastCompletedBuild>
196 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectExistingJob/1/</url>
198 <nextBuildNumber>2</nextBuildNumber>
202 $xmldom = new SimpleXMLElement($xmlstr);
204 $j = new HudsonJobTestVersion($this);
205 $j->setReturnValue('_getXMLObject', $xmldom);
206 $mh = new Mockhudson($this);
207 $mh->setReturnValue('getIconsPath', '');
208 $j->setReturnValue('getHudsonControler', $mh);
209 $j->setReturnValue('getIconsPath', '');
211 $j->HudsonJob("http://myCIserver/jobs/myCIjob");
213 $this->assertEqual($j->getProjectStyle(), "freeStyleProject");
214 $this->assertEqual($j->getName(), "TestProjectExistingJob");
215 $this->assertEqual($j->getUrl(), "http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectExistingJob/");
216 $this->assertEqual($j->getColor(), "red");
217 $this->assertEqual($j->getStatusIcon(), "status_red.png");
219 $this->assertEqual($j->getLastBuildNumber(), "1");
220 $this->assertNull($j->getLastSuccessfulBuildNumber());
221 $this->assertEqual($j->getLastFailedBuildNumber(), "1");
222 $this->assertEqual($j->getNextBuildNumber(), "2");
223 $this->assertTrue($j->hasBuilds());
224 $this->assertTrue($j->isBuildable());
226 $this->assertEqual($j->getHealthScores(), array('0'));
227 $this->assertEqual($j->getHealthAverageScore(), '0');
228 $this->assertEqual($j->getWeatherReportIcon(), "health_00_to_19.gif");
232 function testJobFromExternalJob() {
234 <?xml version='1.0' standalone='yes'?>
236 <displayName>TestProjectExternalJob</displayName>
237 <name>TestProjectExternalJob</name>
238 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectExternalJob/</url>
239 <buildable>false</buildable>
241 <inQueue>false</inQueue>
242 <keepDependencies>false</keepDependencies>
243 <nextBuildNumber>1</nextBuildNumber>
247 $xmldom = new SimpleXMLElement($xmlstr);
249 $j = new HudsonJobTestVersion($this);
250 $j->setReturnValue('_getXMLObject', $xmldom);
251 $mh = new Mockhudson($this);
252 $mh->setReturnValue('getIconsPath', '');
253 $j->setReturnValue('getHudsonControler', $mh);
254 $j->setReturnValue('getIconsPath', '');
256 $j->HudsonJob("http://myCIserver/jobs/myCIjob");
258 $this->assertEqual($j->getProjectStyle(), "externalJob");
259 $this->assertEqual($j->getName(), "TestProjectExternalJob");
260 $this->assertEqual($j->getUrl(), "http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectExternalJob/");
261 $this->assertEqual($j->getColor(), "grey");
262 $this->assertEqual($j->getStatusIcon(), "status_grey.png");
264 $this->assertNull($j->getLastBuildNumber());
265 $this->assertNull($j->getLastSuccessfulBuildNumber());
266 $this->assertNull($j->getLastFailedBuildNumber());
267 $this->assertEqual($j->getNextBuildNumber(), "1");
268 $this->assertFalse($j->hasBuilds());
269 $this->assertFalse($j->isBuildable());
271 $this->assertEqual($j->getHealthScores(), array());
272 $this->assertEqual($j->getHealthAverageScore(), '0');
276 function testJobFromMaven2Job() {
278 <?xml version='1.0' standalone='yes'?>
280 <displayName>TestProjectMaven2</displayName>
281 <name>TestProjectMaven2</name>
282 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectMaven2/</url>
283 <buildable>true</buildable>
285 <inQueue>false</inQueue>
286 <keepDependencies>false</keepDependencies>
287 <nextBuildNumber>1</nextBuildNumber>
291 $xmldom = new SimpleXMLElement($xmlstr);
293 $j = new HudsonJobTestVersion($this);
294 $j->setReturnValue('_getXMLObject', $xmldom);
295 $mh = new Mockhudson($this);
296 $mh->setReturnValue('getIconsPath', '');
297 $j->setReturnValue('getHudsonControler', $mh);
298 $j->setReturnValue('getIconsPath', '');
300 $j->HudsonJob("http://myCIserver/jobs/myCIjob");
302 $this->assertEqual($j->getProjectStyle(), "mavenModuleSet");
303 $this->assertEqual($j->getName(), "TestProjectMaven2");
304 $this->assertEqual($j->getUrl(), "http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectMaven2/");
305 $this->assertEqual($j->getColor(), "grey");
306 $this->assertEqual($j->getStatusIcon(), "status_grey.png");
308 $this->assertNull($j->getLastBuildNumber());
309 $this->assertNull($j->getLastSuccessfulBuildNumber());
310 $this->assertNull($j->getLastFailedBuildNumber());
311 $this->assertEqual($j->getNextBuildNumber(), "1");
312 $this->assertFalse($j->hasBuilds());
313 $this->assertTrue($j->isBuildable());
315 $this->assertEqual($j->getHealthScores(), array());
316 $this->assertEqual($j->getHealthAverageScore(), '0');
320 function testJobFromMultiConfiguration() {
322 <?xml version='1.0' standalone='yes'?>
324 <displayName>TestProjectMultiConfiguration</displayName>
325 <name>TestProjectMultiConfiguration</name>
326 <url>http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectMultiConfiguration/</url>
327 <buildable>true</buildable>
329 <inQueue>false</inQueue>
330 <keepDependencies>false</keepDependencies>
331 <nextBuildNumber>1</nextBuildNumber>
335 $xmldom = new SimpleXMLElement($xmlstr);
337 $j = new HudsonJobTestVersion($this);
338 $j->setReturnValue('_getXMLObject', $xmldom);
339 $mh = new Mockhudson($this);
340 $mh->setReturnValue('getIconsPath', '');
341 $j->setReturnValue('getHudsonControler', $mh);
342 $j->setReturnValue('getIconsPath', '');
344 $j->HudsonJob("http://myCIserver/jobs/myCIjob");
346 $this->assertEqual($j->getProjectStyle(), "matrixProject");
347 $this->assertEqual($j->getName(), "TestProjectMultiConfiguration");
348 $this->assertEqual($j->getUrl(), "http://code4.grenoble.xrce.xerox.com:8080/hudson/job/TestProjectMultiConfiguration/");
349 $this->assertEqual($j->getColor(), "grey");
350 $this->assertEqual($j->getStatusIcon(), "status_grey.png");
352 $this->assertNull($j->getLastBuildNumber());
353 $this->assertNull($j->getLastSuccessfulBuildNumber());
354 $this->assertNull($j->getLastFailedBuildNumber());
355 $this->assertEqual($j->getNextBuildNumber(), "1");
356 $this->assertFalse($j->hasBuilds());
357 $this->assertTrue($j->isBuildable());
359 $this->assertEqual($j->getHealthScores(), array());
360 $this->assertEqual($j->getHealthAverageScore(), '0');
364 function testColorNoAnime1() {
365 $j = new HudsonJobTestColorVersion($this);
366 $j->setReturnValue('getColor', "blue");
367 $this->assertEqual($j->getColorNoAnime(), "blue");
369 function testColorNoAnime2() {
370 $j = new HudsonJobTestColorVersion($this);
371 $j->setReturnValue('getColor', "blue_anime");
372 $this->assertEqual($j->getColorNoAnime(), "blue");
374 function testColorNoAnime3() {
375 $j = new HudsonJobTestColorVersion($this);
376 $j->setReturnValue('getColor', "grey");
377 $this->assertEqual($j->getColorNoAnime(), "grey");
379 function testColorNoAnime4() {
380 $j = new HudsonJobTestColorVersion($this);
381 $j->setReturnValue('getColor', "grey_anime");
382 $this->assertEqual($j->getColorNoAnime(), "grey");