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.HashMap;
039: import java.util.Map;
040:
041: import junit.framework.TestCase;
042: import net.sourceforge.cruisecontrol.CruiseControlException;
043: import net.sourceforge.cruisecontrol.util.OSEnvironment;
044:
045: /**
046: * @author <a href="mailto:j.c.yip@computer.org">Jason Che-han Yip</a>
047: */
048: public class ConcurrentVersionsSystemValidationTest extends TestCase {
049:
050: private ConcurrentVersionsSystem cvs;
051:
052: protected void setUp() throws Exception {
053: super .setUp();
054:
055: cvs = new ConcurrentVersionsSystem();
056: }
057:
058: public void testPassesValidationIfCvsrootAndModuleSet()
059: throws Exception {
060: cvs.setCvsRoot("cvsroot");
061: cvs.setModule("module");
062:
063: try {
064: cvs.validate();
065: } catch (CruiseControlException e) {
066: fail("Should not have failed validation");
067: }
068:
069: }
070:
071: public void testFailsValidationIfNeitherLocalWorkingCopyNorBothCvsrootAndModuleSet()
072: throws Exception {
073: final MockOSEnvironment env = new MockOSEnvironment();
074: ConcurrentVersionsSystem mockEnvCvs = new ConcurrentVersionsSystem() {
075: protected OSEnvironment getOSEnvironment() {
076: return env;
077: }
078: };
079:
080: // set only module
081: mockEnvCvs.setModule("module");
082:
083: assertFailsValidation(mockEnvCvs);
084:
085: // set only cvsroot as parameter
086: mockEnvCvs.setModule(null);
087: mockEnvCvs.setCvsRoot("cvsroot");
088:
089: assertFailsValidation(mockEnvCvs);
090:
091: // set only CVSROOT as environment variable
092: mockEnvCvs.setCvsRoot(null);
093: env.add("CVSROOT", "cvsroot");
094: assertFailsValidation(mockEnvCvs);
095: }
096:
097: public void testLocalWorkingCopyAndCvsrootModuleAreMutuallyExclusive()
098: throws Exception {
099: cvs.setLocalWorkingCopy("localWorkingCopy");
100: cvs.setModule("module");
101: cvs.setCvsRoot("cvsroot");
102:
103: assertFailsValidation(cvs);
104: }
105:
106: public void testFailsValidationIfLocalWorkingCopyDoesNotExist() {
107: cvs.setLocalWorkingCopy("localWorkingCopy");
108:
109: assertFailsValidation(cvs);
110: }
111:
112: private void assertFailsValidation(ConcurrentVersionsSystem cvs) {
113: try {
114: cvs.validate();
115: fail("Should fail validation");
116: } catch (CruiseControlException e) {
117: // expected
118: }
119: }
120:
121: private static class MockOSEnvironment extends OSEnvironment {
122: private Map myVariables = new HashMap();
123:
124: public void add(String variable, String value) {
125: myVariables.put(variable, value);
126: }
127:
128: public String getVariable(String variable) {
129: return (String) myVariables.get(variable);
130: }
131: }
132:
133: }
|