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;
037:
038: import java.io.IOException;
039:
040: import org.jdom.Document;
041: import org.jdom.Element;
042: import org.jdom.output.XMLOutputter;
043:
044: import junit.framework.TestCase;
045:
046: public class LogFileReaderTest extends TestCase {
047:
048: private LogFileReader reader;
049:
050: protected void setUp() throws Exception {
051: super .setUp();
052: Document document = createValidDocument();
053: reader = new LogFileReader(document);
054:
055: }
056:
057: protected void tearDown() throws Exception {
058: super .tearDown();
059: }
060:
061: public void testLogFileReader() {
062: assertNotNull("reader should have been constructed", reader);
063: }
064:
065: /**
066: * test that we successufully get the build interval
067: */
068: public void testGetBuildInterval() {
069: assertEquals("Build interval", 100, reader.getBuildInterval());
070: }
071:
072: /**
073: * test that we get an interval of 0 if the property is not found
074: * @throws IOException
075: */
076: public void testGetBuildIntervalInvalid() throws IOException {
077: LogFileReader logFileReader = new LogFileReader(
078: createInvalidDocument());
079: assertEquals("Build interval", 0, logFileReader
080: .getBuildInterval());
081: }
082:
083: private Document createValidDocument() throws IOException {
084: Element root = new Element("cruisecontrol");
085: Element info = new Element("info");
086: root.addContent(info);
087: Element property = new Element("property");
088: property.setAttribute("name", "anotherproperty");
089: property.setAttribute("value", "astring");
090: info.addContent(property);
091:
092: Element property2 = new Element("property");
093: property2.setAttribute("name", "interval");
094: property2.setAttribute("value", "100");
095: info.addContent(property2);
096:
097: Document document = new Document(root);
098: XMLOutputter outputter = new XMLOutputter();
099: outputter.output(document, System.out);
100: return document;
101: }
102:
103: private Document createInvalidDocument() throws IOException {
104: Element root = new Element("cruisecontrol");
105: Element info = new Element("info");
106: root.addContent(info);
107: Element property = new Element("property");
108: property.setAttribute("name", "notinterval");
109: property.setAttribute("value", "100");
110: info.addContent(property);
111:
112: Document document = new Document(root);
113: XMLOutputter outputter = new XMLOutputter();
114: outputter.output(document, System.out);
115: return document;
116: }
117:
118: }
|