1 37 package net.sourceforge.cruisecontrol.bootstrappers; 38 39 import junit.framework.TestCase; 40 import net.sourceforge.cruisecontrol.CruiseControlException; 41 42 48 public class P4BootstrapperTest extends TestCase { 49 private P4Bootstrapper p4Bootstrapper; 50 51 public void setUp() throws Exception { 52 p4Bootstrapper = new P4Bootstrapper(); 53 } 54 55 public void testViewNotSet() { 56 try { 57 p4Bootstrapper.validate(); 58 fail("Should be Exception if view is not set."); 59 } catch (CruiseControlException expected) { 60 } 61 } 62 63 public void testInvalidView() { 64 p4Bootstrapper.setView(""); 65 try { 66 p4Bootstrapper.validate(); 67 fail("Empty path not allowed"); 68 } catch (CruiseControlException expected) { 69 } 70 } 71 72 public void testInvalidPort() { 73 p4Bootstrapper.setView("foo"); 74 p4Bootstrapper.setPort(""); 75 try { 76 p4Bootstrapper.validate(); 77 fail("Empty port not allowed"); 78 } catch (CruiseControlException expected) { 79 } 80 } 81 82 public void testInvalidClient() { 83 p4Bootstrapper.setView("foo"); 84 p4Bootstrapper.setClient(""); 85 try { 86 p4Bootstrapper.validate(); 87 fail("Empty client not allowed"); 88 } catch (CruiseControlException expected) { 89 } 90 } 91 92 public void testInvalidUser() { 93 p4Bootstrapper.setView("foo"); 94 p4Bootstrapper.setUser(""); 95 try { 96 p4Bootstrapper.validate(); 97 fail("Empty user not allowed"); 98 } catch (CruiseControlException expected) { 99 } 100 } 101 102 public void testCreateCommandlineWithViewSet() throws CruiseControlException { 103 p4Bootstrapper.setView("foo"); 104 assertEquals("p4 -s sync foo", p4Bootstrapper.createCommandline().toString()); 105 106 p4Bootstrapper.setView("foo bar"); 107 assertEquals("p4 -s sync \"foo bar\"", p4Bootstrapper.createCommandline().toString()); 108 } 109 110 public void testCreateCommandlineWithP4PortSet() throws CruiseControlException { 111 p4Bootstrapper.setView("foo"); 112 p4Bootstrapper.setPort("testhost:1666"); 113 checkEnvironmentSpecification(" -p testhost:1666 "); 114 } 115 116 public void testCreateCommandlineWithP4ClientSet() throws CruiseControlException { 117 p4Bootstrapper.setView("foo"); 118 p4Bootstrapper.setClient("testclient"); 119 checkEnvironmentSpecification(" -c testclient "); 120 } 121 122 public void testCreateCommandlineWithP4UserSet() throws CruiseControlException { 123 p4Bootstrapper.setView("foo"); 124 p4Bootstrapper.setUser("testuser"); 125 p4Bootstrapper.setPasswd("password"); 126 checkEnvironmentSpecification(" -u testuser -P password "); 127 } 128 129 132 private void checkEnvironmentSpecification(String expectedSetting) 133 throws CruiseControlException { 134 String commandline = p4Bootstrapper.createCommandline().toString(); 135 int specicationPosition = commandline.indexOf(expectedSetting); 136 int syncPosition = commandline.indexOf(" sync "); 137 assertTrue(specicationPosition != -1); 138 assertTrue(syncPosition != -1); 139 assertTrue(specicationPosition < syncPosition); 140 } 141 } 142 | Popular Tags |