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.XMLLogHelper; 42 import org.jdom.Element; 43 44 58 public class LinkJabberPublisherTest extends TestCase { 59 60 private LinkJabberPublisher publisher; 61 62 private XMLLogHelper successLogHelper; 63 64 private String baseURLString = 65 "http://mybuildserver.com:8080/buildservlet/BuildServlet"; 66 67 protected void setUp() throws Exception { 68 successLogHelper = createLogHelper(true, true); 69 publisher = new LinkJabberPublisher(); 70 } 71 72 protected XMLLogHelper createLogHelper(boolean success, boolean lastBuildSuccess) { 73 Element cruisecontrolElement = new Element("cruisecontrol"); 74 Element infoElement = new Element("info"); 75 76 Element logFileElement = new Element("property"); 77 logFileElement.setAttribute("name", "logfile"); 78 logFileElement.setAttribute("value", "log20020206120000.xml"); 79 infoElement.addContent(logFileElement); 80 cruisecontrolElement.addContent(infoElement); 81 82 Element projectNameElement = new Element("property"); 83 projectNameElement.setAttribute("name", "projectname"); 84 projectNameElement.setAttribute("value", "Jabbertest"); 85 infoElement.addContent(projectNameElement); 86 87 Element buildElement = new Element("build"); 88 if (!success) { 89 buildElement.setAttribute("error", "Something went wrong"); 90 } 91 cruisecontrolElement.addContent(buildElement); 92 93 return new XMLLogHelper(cruisecontrolElement); 94 } 95 96 101 public void testCreateMessage() throws CruiseControlException { 102 publisher.setBuildResultsURL(baseURLString); 103 assertEquals( 104 "Build results for successful build of project Jabbertest: " + baseURLString + "?log=log20020206120000", 105 publisher.createMessage(successLogHelper)); 106 } 107 108 114 public void testQuestionMarkInBuildResultsURL() throws CruiseControlException { 115 publisher.setBuildResultsURL(baseURLString + "?key=value"); 116 117 assertEquals( 118 "Build results for successful build of project Jabbertest: " 119 + baseURLString 120 + "?key=value&log=log20020206120000", 121 publisher.createMessage(successLogHelper)); 122 } 123 124 137 public void testValidate() { 138 publisher.setPassword("asdfdsaf"); 140 publisher.setRecipient("recipient"); 141 publisher.setBuildResultsURL("http://foo.com"); 142 try { 143 publisher.validate(); 144 fail("should throw exception if host not set"); 145 } catch (CruiseControlException e) { 146 } 147 publisher.setHost("host"); 149 publisher.setUsername(null); 150 try { 151 publisher.validate(); 152 fail("should throw exception if username not set"); 153 } catch (CruiseControlException e) { 154 } 155 publisher.setUsername("username@adsfdsaf.com"); 157 try { 158 publisher.validate(); 159 fail("should throw exception if username is of the wrong form"); 160 } catch (CruiseControlException e) { 161 } 162 publisher.setUsername("username"); 164 publisher.setPassword(null); 165 try { 166 publisher.validate(); 167 fail("should throw exception if password not set"); 168 } catch (CruiseControlException e) { 169 } 170 publisher.setPassword("adsfadsf"); 172 publisher.setRecipient(null); 173 try { 174 publisher.validate(); 175 fail("should throw exception if recipient not set"); 176 } catch (CruiseControlException e) { 177 } 178 publisher.setRecipient("recipient"); 180 try { 181 publisher.validate(); 182 fail("should throw exception if recipient is of the wrong form"); 183 } catch (CruiseControlException e) { 184 } 185 publisher.setRecipient("recipient@foo.com"); 187 publisher.setBuildResultsURL(null); 188 try { 189 publisher.validate(); 190 fail("should throw exception if BuildResultURL not set"); 191 } catch (CruiseControlException e) { 192 } 193 } 194 195 } | Popular Tags |