Source Code Cross Referenced for BuildStatusTest.java in  » Build » cruisecontrol » net » sourceforge » cruisecontrol » sourcecontrols » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Build » cruisecontrol » net.sourceforge.cruisecontrol.sourcecontrols 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /********************************************************************************
002:         * CruiseControl, a Continuous Integration Toolkit
003:         * Copyright (c) 2001, 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.sourcecontrols;
037:
038:        import java.io.File;
039:        import java.util.Calendar;
040:        import java.util.Date;
041:        import java.util.List;
042:        import java.util.Map;
043:
044:        import junit.framework.TestCase;
045:        import net.sourceforge.cruisecontrol.CruiseControlException;
046:        import net.sourceforge.cruisecontrol.Log;
047:        import net.sourceforge.cruisecontrol.testutil.TestUtil.FilesToDelete;
048:        import net.sourceforge.cruisecontrol.util.DateUtil;
049:
050:        /**
051:         * Unit tests for BuildStatus.java.
052:         *
053:         *@author Garrick Olson
054:         */
055:        public class BuildStatusTest extends TestCase {
056:            private BuildStatus buildStatus;
057:            private final FilesToDelete filesToDelete = new FilesToDelete();
058:
059:            protected void setUp() throws Exception {
060:                buildStatus = new BuildStatus();
061:            }
062:
063:            protected void tearDown() throws Exception {
064:                buildStatus = null;
065:                filesToDelete.delete();
066:            }
067:
068:            /**
069:             * Make sure the validate() method works properly.
070:             */
071:            public void testValidate() throws Exception {
072:                // Verify log directory is mandatory
073:                try {
074:                    buildStatus.validate();
075:                    fail("Should have thrown exception indicating log directory is mandatory");
076:                } catch (CruiseControlException e) {
077:                    assertEquals("Wrong exception",
078:                            "'logdir' is required for BuildStatus", e
079:                                    .getMessage());
080:                }
081:
082:                // Verify log directory must exist
083:                buildStatus.setLogDir("does not exist");
084:
085:                try {
086:                    buildStatus.validate();
087:                    fail("Should have thrown exception indicating log directory must exist");
088:                } catch (CruiseControlException e) {
089:                    assertTrue("Wrong exception", e.getMessage().startsWith(
090:                            "Log directory does not exist"));
091:                }
092:
093:                // Verify log directory must be a directory
094:                File tempFile = File.createTempFile("temp", "txt");
095:                tempFile.deleteOnExit();
096:                filesToDelete.add(tempFile);
097:                buildStatus.setLogDir(tempFile.getAbsolutePath());
098:
099:                try {
100:                    buildStatus.validate();
101:                    fail("Should have thrown exception indicating log directory must be a directory");
102:                } catch (CruiseControlException e) {
103:                    assertTrue("Wrong exception", e.getMessage().startsWith(
104:                            "Log directory is not a directory"));
105:                }
106:
107:                // Set it to a directory and everything should be okay
108:                buildStatus.setLogDir(tempFile.getParentFile()
109:                        .getAbsolutePath());
110:                buildStatus.validate();
111:            }
112:
113:            /**
114:             * Verify the getModifications() method works properly.
115:             */
116:            public void testGetModifications() throws Exception {
117:                File tempDir = new File(System.getProperty("java.io.tmpdir"));
118:
119:                buildStatus.setLogDir(tempDir.getAbsolutePath());
120:                buildStatus.validate();
121:
122:                Calendar calendar = Calendar.getInstance();
123:                Date today = calendar.getTime();
124:                calendar.add(Calendar.DATE, -1);
125:                Date yesterday = calendar.getTime();
126:                calendar.add(Calendar.DATE, -1);
127:                Date twoDaysAgo = calendar.getTime();
128:
129:                // Should be no modifications at this point
130:                List modifications = buildStatus.getModifications(twoDaysAgo,
131:                        null);
132:                assertEquals("Wrong number of modifications", 0, modifications
133:                        .size());
134:
135:                // Verify an unsuccessful build does not show up
136:                File yesterdayLog = new File(tempDir, Log
137:                        .formatLogFileName(yesterday));
138:                yesterdayLog.createNewFile();
139:                filesToDelete.add(yesterdayLog);
140:                modifications = buildStatus.getModifications(twoDaysAgo, null);
141:                assertEquals("Wrong number of modifications", 0, modifications
142:                        .size());
143:
144:                // Verify a successful build shows up
145:                File yesterdayLog2 = new File(tempDir, Log.formatLogFileName(
146:                        yesterday, "good.1"));
147:                yesterdayLog2.createNewFile();
148:                filesToDelete.add(yesterdayLog2);
149:
150:                modifications = buildStatus.getModifications(twoDaysAgo, null);
151:                assertEquals("Wrong number of modifications", 1, modifications
152:                        .size());
153:
154:                Map properties = buildStatus.getProperties();
155:                // Verify properties were set correctly
156:                assertEquals("Property was not set correctly", tempDir
157:                        .getAbsolutePath(), properties
158:                        .get(BuildStatus.MOST_RECENT_LOGDIR_KEY));
159:                assertEquals("Property was not set correctly", yesterdayLog2
160:                        .getName(), properties
161:                        .get(BuildStatus.MOST_RECENT_LOGFILE_KEY));
162:                assertEquals("Property was not set correctly", DateUtil
163:                        .getFormattedTime(yesterday), properties
164:                        .get(BuildStatus.MOST_RECENT_LOGTIME_KEY));
165:                assertEquals("Property was not set correctly", "good.1",
166:                        properties.get(BuildStatus.MOST_RECENT_LOGLABEL_KEY));
167:                assertEquals(4, properties.size());
168:
169:                // Verify date range works
170:                modifications = buildStatus.getModifications(today, null);
171:                assertEquals("Wrong number of modifications", 0, modifications
172:                        .size());
173:
174:                // Verify properties are set correctly when there are multiple modifications
175:                File todayLog = new File(tempDir, Log.formatLogFileName(today,
176:                        "good.2"));
177:                todayLog.createNewFile();
178:                filesToDelete.add(todayLog);
179:
180:                buildStatus.setProperty("property");
181:                modifications = buildStatus.getModifications(twoDaysAgo, null);
182:                assertEquals("Wrong number of modifications", 2, modifications
183:                        .size());
184:
185:                properties = buildStatus.getProperties();
186:                // Verify properties were set correctly
187:                assertEquals("Property was not set correctly", tempDir
188:                        .getAbsolutePath(), properties
189:                        .get(BuildStatus.MOST_RECENT_LOGDIR_KEY));
190:                assertEquals("Property was not set correctly", todayLog
191:                        .getName(), properties
192:                        .get(BuildStatus.MOST_RECENT_LOGFILE_KEY));
193:                assertEquals("Property was not set correctly", DateUtil
194:                        .getFormattedTime(today), properties
195:                        .get(BuildStatus.MOST_RECENT_LOGTIME_KEY));
196:                assertEquals("Property was not set correctly", "good.2",
197:                        properties.get(BuildStatus.MOST_RECENT_LOGLABEL_KEY));
198:                assertEquals("true", properties.get("property"));
199:                assertEquals(5, properties.size());
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.