1 37 package net.sourceforge.cruisecontrol.bootstrappers; 38 39 import junit.framework.TestCase; 40 import net.sourceforge.cruisecontrol.CruiseControlException; 41 42 import java.io.File ; 43 import java.io.IOException ; 44 45 49 public class SVNBootstrapperTest extends TestCase { 50 51 private SVNBootstrapper bootStrapper; 52 53 protected void setUp() { 54 bootStrapper = new SVNBootstrapper(); 55 } 56 57 public void testValidate() throws IOException { 58 try { 59 bootStrapper.validate(); 60 fail("should throw an exception when no attributes are set"); 61 } catch (CruiseControlException e) { 62 } 63 64 bootStrapper = new SVNBootstrapper(); 65 bootStrapper.setFile("some filename"); 66 try { 67 bootStrapper.validate(); 68 } catch (CruiseControlException e) { 69 fail("should not throw an exception when at least the 'filename' attribute is set"); 70 } 71 72 bootStrapper = new SVNBootstrapper(); 73 bootStrapper.setLocalWorkingCopy("invalid directory"); 74 try { 75 bootStrapper.validate(); 76 fail("should throw an exception when an invalid 'localWorkingCopy' attribute is set"); 77 } catch (CruiseControlException e) { 78 } 80 81 File tempFile = File.createTempFile("temp", "txt"); 82 tempFile.deleteOnExit(); 83 84 bootStrapper = new SVNBootstrapper(); 85 bootStrapper.setLocalWorkingCopy(tempFile.getParent()); 86 try { 87 bootStrapper.validate(); 88 } catch (CruiseControlException e) { 89 fail( 90 "should not throw an exception when at least a valid 'localWorkingCopy' " 91 + "attribute is set"); 92 } 93 94 bootStrapper = new SVNBootstrapper(); 95 bootStrapper.setLocalWorkingCopy(tempFile.getAbsolutePath()); 96 try { 97 bootStrapper.validate(); 98 fail( 99 "should throw an exception when 'localWorkingCopy' is a file instead of a " 100 + "directory."); 101 } catch (CruiseControlException e) { 102 } 104 } 105 106 public void testBuildUpdateCommand() throws CruiseControlException { 107 String tempDir = System.getProperty("java.io.tmpdir"); 108 109 bootStrapper.setLocalWorkingCopy(tempDir); 110 String command = bootStrapper.buildUpdateCommand().toString(); 111 assertEquals("svn update --non-interactive", command); 112 113 bootStrapper.setFile("foo.txt"); 114 command = bootStrapper.buildUpdateCommand().toString(); 115 assertEquals("svn update --non-interactive foo.txt", command); 116 117 bootStrapper.setUsername("lee"); 118 command = bootStrapper.buildUpdateCommand().toString(); 119 assertEquals("svn update --non-interactive --username lee foo.txt", command); 120 121 bootStrapper.setPassword("secret"); 122 command = bootStrapper.buildUpdateCommand().toString(); 123 assertEquals( 124 "svn update --non-interactive --username lee --password secret foo.txt", 125 command); 126 } 127 } 128 | Popular Tags |