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.util.ArrayList;
039: import java.util.Date;
040: import java.util.List;
041: import java.util.Map;
042:
043: import junit.framework.TestCase;
044: import net.sourceforge.cruisecontrol.CruiseControlException;
045:
046: public class CompoundTest extends TestCase {
047:
048: public void testGetModifications() {
049: List modList = null;
050:
051: Compound compound = new Compound();
052: Triggers trigger = (Triggers) compound.createTriggers();
053: Targets target = (Targets) compound.createTargets();
054:
055: MockSourceControl msc1 = new MockSourceControl();
056: msc1.setType(1);
057: trigger.add(msc1);
058:
059: MockSourceControl msc2 = new MockSourceControl();
060: msc2.setType(2);
061: target.add(msc2);
062:
063: List triggerModsList = msc1.getModifications(new Date(0),
064: new Date());
065: List targetModsList = msc2.getModifications(new Date(0),
066: new Date());
067: List allModsList = new ArrayList();
068: allModsList.addAll(targetModsList);
069: allModsList.addAll(triggerModsList);
070:
071: // test retrieving mods without including trigger changes
072: compound.setIncludeTriggerChanges("false");
073:
074: modList = compound.getModifications(new Date(0), new Date());
075: assertEquals("modification lists should match", modList,
076: targetModsList);
077: assertEquals(0, compound.getProperties().size());
078:
079: // test retrieving mods without including trigger changes
080: compound.setIncludeTriggerChanges("true");
081: compound.setProperty("property");
082:
083: modList = compound.getModifications(new Date(0), new Date());
084: assertEquals("modification lists should match", modList,
085: allModsList);
086: Map properties = compound.getProperties();
087: assertEquals(1, properties.size());
088: assertTrue(properties.containsKey("property"));
089: }
090:
091: public void testValidate() {
092: Compound compound = null;
093:
094: // test compound with no triggers
095: compound = new Compound();
096: compound.createTargets();
097:
098: try {
099: compound.validate();
100: fail("Compound should throw exceptions when required attributes are not set.");
101: } catch (CruiseControlException e) {
102: assertEquals(
103: "Error: there must be exactly one \"triggers\" block in a compound block.",
104: e.getMessage());
105: }
106:
107: // test compound with no targets
108: compound = new Compound();
109: compound.createTriggers();
110:
111: try {
112: compound.validate();
113: fail("Compound should throw exceptions when required attributes are not set.");
114: } catch (CruiseControlException e) {
115: assertEquals(
116: "Error: there must be exactly one \"targets\" block in a compound block.",
117: e.getMessage());
118: }
119:
120: // test compound with all attributes properly set
121: compound.createTargets();
122:
123: try {
124: compound.validate();
125: } catch (CruiseControlException e) {
126: fail("Compound should not throw exceptions when required attributes are set.");
127: }
128: }
129: }
|