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;
037:
038: import java.io.File;
039: import java.io.Serializable;
040:
041: import junit.framework.TestCase;
042: import net.sourceforge.cruisecontrol.testutil.TestUtil.FilesToDelete;
043: import net.sourceforge.cruisecontrol.util.IO;
044:
045: /**
046: * @author <a href="mailto:hak@2mba.dk">Hack Kampbjorn</a>
047: */
048: public class LogFileTest extends TestCase {
049: private final FilesToDelete filesToDelete = new FilesToDelete();
050: private File logDir;
051: private File log1;
052: private File log2;
053: private File log3;
054:
055: public void setUp() {
056: logDir = new File("testresults/");
057: if (!logDir.exists()) {
058: assertTrue("Failed to create test result dir", logDir
059: .mkdir());
060: }
061: log1 = new File(logDir, "log20040903010203.xml");
062: log2 = new File(logDir,
063: "log20040905010203Lsuccessful-build-file.1.xml");
064: log3 = new File(logDir, "log20051021103500.xml.gz");
065:
066: filesToDelete.add(log1);
067: filesToDelete.add(log2);
068: filesToDelete.add(log3);
069: filesToDelete.add(logDir);
070: }
071:
072: public void tearDown() {
073: filesToDelete.delete();
074:
075: log1 = null;
076: log2 = null;
077: log3 = null;
078: logDir = null;
079: }
080:
081: public void testGetLatestLog() throws Exception {
082: IO.write(log1, "");
083: IO.write(log2, "");
084: IO.write(log3, "");
085:
086: File result = LogFile.getLatestLogFile(logDir).getFile();
087: assertEquals(log3.getName(), result.getName());
088: }
089:
090: public void testIsCompressed() throws Exception {
091: IO.write(log1, "");
092: IO.write(log2, "");
093: IO.write(log3, "");
094:
095: assertFalse(new LogFile(log1).isCompressed());
096: assertFalse(new LogFile(log2).isCompressed());
097: assertTrue(new LogFile(log3).isCompressed());
098: }
099:
100: public void testGetLatestSuccessfulLog() throws Exception {
101: IO.write(log1, "");
102: IO.write(log2, "");
103: IO.write(log3, "");
104:
105: File result = LogFile.getLatestSuccessfulLogFile(logDir)
106: .getFile();
107: assertEquals(log2, result);
108: }
109:
110: public void testSerializable() throws Exception {
111: IO.write(log1, "");
112:
113: assertTrue(
114: "LogFile class must be serializable for Metrics Tab (charting) to work",
115: Serializable.class.isAssignableFrom(LogFile.class));
116: }
117: }
|