KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > publishers > SCPPublisherTest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2001-2003, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.publishers;
38
39 import junit.framework.TestCase;
40 import net.sourceforge.cruisecontrol.CruiseControlException;
41 import net.sourceforge.cruisecontrol.util.Commandline;
42
43 import java.io.File JavaDoc;
44
45 import org.jdom.Element;
46
47 public class SCPPublisherTest extends TestCase {
48
49     private SCPPublisher publisher;
50
51     protected void setUp() throws Exception JavaDoc {
52         publisher = new SCPPublisher();
53     }
54
55     protected void tearDown() throws Exception JavaDoc {
56         publisher = null;
57     }
58
59     public void testIfFileNotSetShouldGetLatestLogNameEachTime() throws CruiseControlException {
60         TestSCPPublisher testpublisher = new TestSCPPublisher();
61         assertFalse(testpublisher.getLogFileNameWasCalled);
62         testpublisher.publish(null);
63         assertTrue(testpublisher.getLogFileNameWasCalled);
64
65         testpublisher.getLogFileNameWasCalled = false;
66         assertFalse(testpublisher.getLogFileNameWasCalled);
67         testpublisher.publish(null);
68         assertTrue(testpublisher.getLogFileNameWasCalled);
69     }
70     
71     public void testValidate() {
72         publisher.setSourceUser("user1");
73         try {
74             publisher.validate();
75             fail("SCPPublisher should throw exceptions when only user is set.");
76         } catch (CruiseControlException e) {
77         }
78         publisher.setSourceUser(null);
79         publisher.setSourceHost("host1");
80
81         try {
82             publisher.validate();
83             fail("SCPPublisher should throw exceptions when only host is set.");
84         } catch (CruiseControlException e) {
85         }
86         publisher.setSourceUser("user1");
87         publisher.setSourceHost("host1");
88         publisher.setSourceUser(null);
89         publisher.setSourceHost("host1");
90         try {
91             publisher.validate();
92             fail("SCPPublisher should throw exceptions when only user is set.");
93         } catch (CruiseControlException e) {
94         }
95     }
96
97     public void testCreateCommandline() {
98         publisher.setSourceUser("user1");
99         publisher.setSourceHost("host1");
100         publisher.setTargetUser("user2");
101         publisher.setTargetHost("host2");
102         assertEquals(
103             "scp -S ssh user1@host1:."
104                 + File.separator
105                 + "filename "
106                 + "user2@host2:."
107                 + File.separator,
108             publisher.createCommandline("filename").toString());
109         publisher.setOptions("-P 1000");
110         assertEquals(
111             "scp -P 1000 -S ssh user1@host1:."
112                 + File.separator
113                 + "filename "
114                 + "user2@host2:."
115                 + File.separator,
116             publisher.createCommandline("filename").toString());
117         publisher.setSSH("plink");
118         assertEquals(
119             "scp -P 1000 -S plink user1@host1:."
120                 + File.separator
121                 + "filename "
122                 + "user2@host2:."
123                 + File.separator,
124             publisher.createCommandline("filename").toString());
125         publisher.setTargetDir(File.separator + "home" + File.separator + "httpd");
126         assertEquals(
127             "scp -P 1000 -S plink user1@host1:."
128                 + File.separator
129                 + "filename "
130                 + "user2@host2:"
131                 + File.separator
132                 + "home"
133                 + File.separator
134                 + "httpd"
135                 + File.separator,
136             publisher.createCommandline("filename").toString());
137     }
138     
139     private class TestSCPPublisher extends SCPPublisher {
140         private boolean getLogFileNameWasCalled = false;
141
142         protected String JavaDoc getLogFileName(Element cruisecontrolLog) throws CruiseControlException {
143             getLogFileNameWasCalled = true;
144             return "fileName";
145         }
146         
147         protected void executeCommand(Commandline command) throws CruiseControlException {
148         }
149     };
150 }
151
Popular Tags