1 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 ; 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 { 52 publisher = new SCPPublisher(); 53 } 54 55 protected void tearDown() throws Exception { 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 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 |