1 package net.sourceforge.cruisecontrol.publishers.sfee; 2 3 import com.vasoftware.sf.soap42.webservices.ClientSoapStubFactory; 4 import com.vasoftware.sf.soap42.webservices.sfmain.ISourceForgeSoap; 5 import com.vasoftware.sf.soap42.webservices.sfmain.ProjectSoapList; 6 import com.vasoftware.sf.soap42.webservices.sfmain.ProjectSoapRow; 7 import com.vasoftware.sf.soap42.webservices.tracker.ArtifactSoapList; 8 import com.vasoftware.sf.soap42.webservices.tracker.ArtifactSoapRow; 9 import com.vasoftware.sf.soap42.webservices.tracker.ITrackerAppSoap; 10 import com.vasoftware.sf.soap42.webservices.tracker.TrackerSoapList; 11 import com.vasoftware.sf.soap42.webservices.tracker.TrackerSoapRow; 12 import junit.framework.TestCase; 13 import net.sourceforge.cruisecontrol.CruiseControlException; 14 import net.sourceforge.cruisecontrol.util.XPathAwareChild; 15 import net.sourceforge.cruisecontrol.util.NamedXPathAwareChild; 16 import net.sourceforge.cruisecontrol.testutil.TestUtil; 17 18 import java.rmi.RemoteException ; 19 20 public class SfeeTrackerPublisherTest extends TestCase { 21 22 private static final String SERVER_URL = "http://tapestry.sourceforge.vasoftware.com"; 23 private static final String USERNAME = "foo"; 24 private static final String PASSWORD = "bar"; 25 private static final String PROJECT_NAME = "CC Integration"; 26 27 public void setUp() { 28 SfeeTestUtils util = new SfeeTestUtils(); 29 util.loadSfeeInMemory(SERVER_URL, USERNAME, PASSWORD); 30 util.addProject(PROJECT_NAME); 31 util.addTracker("UnitTestStatistics", PROJECT_NAME); 32 } 33 34 public void testCanPublishStaticValuesToTracker() throws CruiseControlException, RemoteException { 35 SfeeTrackerPublisher publisher = new SfeeTrackerPublisher(); 36 publisher.setTrackerName("UnitTestStatistics"); 37 publisher.setServerURL(SERVER_URL); 38 publisher.setUsername(USERNAME); 39 publisher.setPassword(PASSWORD); 40 publisher.setProjectName(PROJECT_NAME); 41 42 XPathAwareChild title = publisher.createTitle(); 43 assertNotNull("createTitle should never return null.", title); 44 title.setValue("Testing"); 45 46 XPathAwareChild description = publisher.createDescription(); 47 assertNotNull("createDescription should never return null.", title); 48 String descriptionValue = "Testing @ " + System.currentTimeMillis(); 49 description.setValue(descriptionValue); 50 51 XPathAwareChild status = publisher.createStatus(); 52 status.setValue("Open"); 53 54 NamedXPathAwareChild field = publisher.createField(); 55 field.setName("BrokenUnitTests"); 56 field.setValue("0"); 57 58 field = publisher.createField(); 59 field.setName("SuccessfulUnitTests"); 60 field.setValue("0"); 61 62 field = publisher.createField(); 63 field.setName("TotalNumberOfUnitTests"); 64 field.setValue("0"); 65 66 publisher.validate(); 67 publisher.publish(null); 68 69 assertTrackerArtifactCreated(descriptionValue); 70 } 71 72 public void testValidate() throws Exception { 73 SfeeTrackerPublisher publisher = new SfeeTrackerPublisher(); 74 assertNotValidatable(publisher); 75 publisher.setTrackerName("UnitTestStatistics"); 76 assertNotValidatable(publisher); 77 publisher.setServerURL(SERVER_URL); 78 assertNotValidatable(publisher); 79 publisher.setUsername(USERNAME); 80 assertNotValidatable(publisher); 81 publisher.setPassword(PASSWORD); 82 assertNotValidatable(publisher); 83 publisher.setProjectName(PROJECT_NAME); 84 85 assertNotValidatable(publisher); 86 87 XPathAwareChild title = publisher.createTitle(); 88 assertNotNull("createTitle should never return null.", title); 89 title.setValue("Testing"); 90 assertNotValidatable(publisher); 91 92 XPathAwareChild description = publisher.createDescription(); 93 assertNotNull("createDescription should never return null.", title); 94 String descriptionValue = "Testing @ " + System.currentTimeMillis(); 95 description.setValue(descriptionValue); 96 assertNotValidatable(publisher); 97 98 XPathAwareChild status = publisher.createStatus(); 99 status.setValue("Open"); 100 101 publisher.validate(); 102 } 103 104 public void testProjectNameNotFound() throws CruiseControlException { 105 SfeeTrackerPublisher publisher = new SfeeTrackerPublisher(); 106 publisher.setTrackerName("UnitTestStatistics"); 107 publisher.setServerURL(SERVER_URL); 108 publisher.setUsername(USERNAME); 109 publisher.setPassword(PASSWORD); 110 String projectName = "NON-EXISTENT PROJECT " + System.currentTimeMillis(); 111 publisher.setProjectName(projectName); 112 113 XPathAwareChild title = publisher.createTitle(); 114 title.setValue("Testing"); 115 116 XPathAwareChild description = publisher.createDescription(); 117 String descriptionValue = "Testing @ " + System.currentTimeMillis(); 118 description.setValue(descriptionValue); 119 120 XPathAwareChild status = publisher.createStatus(); 121 status.setValue("Open"); 122 123 publisher.validate(); 124 try { 125 publisher.publish(null); 126 fail("Expected an exception for a non-existent project name"); 127 } catch (CruiseControlException expected) { 128 assertTrue(expected.getMessage().indexOf("projectName [" + projectName + "] not found") >= 0); 129 } 130 } 131 132 public void testTrackerNameNotFound() throws CruiseControlException { 133 SfeeTrackerPublisher publisher = new SfeeTrackerPublisher(); 134 String trackerName = "Non-Existent Tracker Name" + System.currentTimeMillis(); 135 publisher.setTrackerName(trackerName); 136 publisher.setServerURL(SERVER_URL); 137 publisher.setUsername(USERNAME); 138 publisher.setPassword(PASSWORD); 139 publisher.setProjectName(PROJECT_NAME); 140 141 XPathAwareChild title = publisher.createTitle(); 142 title.setValue("Testing"); 143 144 XPathAwareChild description = publisher.createDescription(); 145 String descriptionValue = "Testing @ " + System.currentTimeMillis(); 146 description.setValue(descriptionValue); 147 148 XPathAwareChild status = publisher.createStatus(); 149 status.setValue("Open"); 150 151 publisher.validate(); 152 try { 153 publisher.publish(null); 154 fail("Expected an exception for a non-existent tracker name"); 155 } catch (CruiseControlException expected) { 156 assertTrue(expected.getMessage().indexOf("trackerName [" + trackerName + "] not found") >= 0); 157 } 158 } 159 160 public void testPublishWithXPath() throws CruiseControlException, RemoteException { 161 SfeeTrackerPublisher publisher = new SfeeTrackerPublisher(); 162 publisher.setTrackerName("UnitTestStatistics"); 163 publisher.setServerURL(SERVER_URL); 164 publisher.setUsername(USERNAME); 165 publisher.setPassword(PASSWORD); 166 publisher.setProjectName(PROJECT_NAME); 167 168 XPathAwareChild title = publisher.createTitle(); 169 assertNotNull("createTitle should never return null.", title); 170 title.setValue("Testing"); 171 172 XPathAwareChild description = publisher.createDescription(); 173 assertNotNull("createDescription should never return null.", title); 174 String descriptionValue = "Testing @ " + System.currentTimeMillis(); 175 description.setValue(descriptionValue); 176 177 XPathAwareChild status = publisher.createStatus(); 178 status.setValue("Open"); 179 180 NamedXPathAwareChild field = publisher.createField(); 181 field.setName("BrokenUnitTests"); 182 field.setValue("0"); 183 184 field = publisher.createField(); 185 field.setName("SuccessfulUnitTests"); 186 field.setValue("0"); 187 188 field = publisher.createField(); 189 field.setName("TotalNumberOfUnitTests"); 190 field.setXPathExpression("1+2"); 191 192 publisher.validate(); 193 publisher.publish(TestUtil.createElement(true, true)); 194 195 assertTrackerArtifactCreated(descriptionValue); 196 } 197 198 private void assertNotValidatable(SfeeTrackerPublisher publisher) { 199 try { 200 publisher.validate(); 201 fail("Publisher should not be valid."); 202 } catch (CruiseControlException expected) { 203 204 } 205 } 206 207 private void assertTrackerArtifactCreated(String uniqueDescription) throws RemoteException { 208 ISourceForgeSoap soap = (ISourceForgeSoap) ClientSoapStubFactory 209 .getSoapStub(ISourceForgeSoap.class, SERVER_URL); 210 String sessionID = soap.login(USERNAME, PASSWORD); 211 ProjectSoapList projectList = soap.getProjectList(sessionID); 212 ProjectSoapRow[] rows = projectList.getDataRows(); 213 String projectID = null; 214 for (int i = 0; i < rows.length; i++) { 215 ProjectSoapRow nextProjectRow = rows[i]; 216 if (nextProjectRow.getTitle().equals(PROJECT_NAME)) { 217 projectID = nextProjectRow.getId(); 218 } 219 } 220 assertNotNull(projectID); 221 222 ITrackerAppSoap tracker = (ITrackerAppSoap) ClientSoapStubFactory 223 .getSoapStub(ITrackerAppSoap.class, SERVER_URL); 224 TrackerSoapList trackerList = tracker.getTrackerList(sessionID, projectID); 225 TrackerSoapRow[] trackerListRows = trackerList.getDataRows(); 226 String trackerID = null; 227 for (int i = 0; i < trackerListRows.length; i++) { 228 TrackerSoapRow trackerListRow = trackerListRows[i]; 229 if (trackerListRow.getTitle().equals("UnitTestStatistics")) { 230 trackerID = trackerListRow.getId(); 231 } 232 } 233 assertNotNull(trackerID); 234 235 ArtifactSoapList artifactList = tracker.getArtifactList(sessionID, trackerID, null); 236 ArtifactSoapRow[] artifactDataRows = artifactList.getDataRows(); 237 boolean found = false; 238 for (int i = 0; i < artifactDataRows.length; i++) { 239 ArtifactSoapRow nextRow = artifactDataRows[i]; 240 if (nextRow.getDescription().equals(uniqueDescription)) { 241 found = true; 242 } 243 } 244 assertTrue("Didn't find the tracker artifact with description [" + uniqueDescription + "]", found); 245 } 246 247 } 248 | Popular Tags |