|
27 | 27 |
|
28 | 28 | import com.google.common.base.Optional; |
29 | 29 | import com.offbytwo.jenkins.client.JenkinsHttpClient; |
| 30 | +import com.offbytwo.jenkins.model.BuildWithDetails; |
30 | 31 | import com.offbytwo.jenkins.model.FolderJob; |
31 | 32 | import com.offbytwo.jenkins.model.Job; |
32 | 33 | import com.offbytwo.jenkins.model.JobWithDetails; |
33 | 34 | import com.offbytwo.jenkins.model.MainView; |
34 | 35 | import com.offbytwo.jenkins.model.View; |
| 36 | +import org.apache.http.HttpStatus; |
| 37 | +import org.apache.http.client.HttpResponseException; |
| 38 | +import static org.junit.Assert.assertNull; |
35 | 39 |
|
36 | 40 | import static org.mockito.Mockito.mock; |
37 | 41 | import static org.mockito.Mockito.times; |
@@ -328,6 +332,57 @@ public void getVersionShouldNotFailWithNPE() |
328 | 332 |
|
329 | 333 | } |
330 | 334 |
|
| 335 | + |
| 336 | + @Test |
| 337 | + public void testGetBuildDetails_NotFound() throws IOException { |
| 338 | + final HttpResponseException ex = new HttpResponseException(HttpStatus.SC_NOT_FOUND,""); |
| 339 | + given(client.get(anyString(), eq(BuildWithDetails.class))).willThrow(ex); |
| 340 | + assertNull(server.getBuildDetails("someJob", 1)); |
| 341 | + } |
| 342 | + |
| 343 | + @Test(expected=HttpResponseException.class) |
| 344 | + public void testGetBuildDetails_ResponseException() throws IOException { |
| 345 | + final HttpResponseException ex = new HttpResponseException(HttpStatus.SC_BAD_REQUEST,""); |
| 346 | + given(client.get(anyString(), eq(BuildWithDetails.class))).willThrow(ex); |
| 347 | + server.getBuildDetails("someJob", 1); |
| 348 | + } |
| 349 | + |
| 350 | + |
| 351 | + @Test |
| 352 | + public void testGetBuildDetails_WithFolderJob() throws Exception { |
| 353 | + final String expectedPath = "http://localhost/jobs/someFolder/job/someJob/1"; |
| 354 | + final FolderJob folderJob = new FolderJob("someFolder", "http://localhost/jobs/someFolder/"); |
| 355 | + final BuildWithDetails expected = new BuildWithDetails(); |
| 356 | + given(client.get(eq(expectedPath), eq(BuildWithDetails.class))).willReturn(expected); |
| 357 | + final BuildWithDetails details = server.getBuildDetails(folderJob, "someJob", 1); |
| 358 | + assertTrue(details == expected); |
| 359 | + } |
| 360 | + |
| 361 | + |
| 362 | + |
| 363 | + |
| 364 | + @Test |
| 365 | + public void testGetBuildDetails_WithOutFolderJob() throws Exception { |
| 366 | + final String expectedPath = "/job/someJob/1"; |
| 367 | + final BuildWithDetails expected = new BuildWithDetails(); |
| 368 | + given(client.get(eq(expectedPath), eq(BuildWithDetails.class))).willReturn(expected); |
| 369 | + final BuildWithDetails details = server.getBuildDetails("someJob", 1); |
| 370 | + assertTrue(details == expected); |
| 371 | + } |
| 372 | + |
| 373 | + @Test |
| 374 | + public void testGetBuildDetails_WithTreeProperties() throws Exception { |
| 375 | + final String expectedPath = "/job/someJob/1?tree=building%2Cculprits%5BfullName%5D"; |
| 376 | + final BuildWithDetails expected = new BuildWithDetails(); |
| 377 | + given(client.get(eq(expectedPath), eq(BuildWithDetails.class))).willReturn(expected); |
| 378 | + final String[] treeProps = {"building", "culprits[fullName]"}; |
| 379 | + final BuildWithDetails details = server.getBuildDetails("someJob", 1, treeProps); |
| 380 | + assertTrue(details == expected); |
| 381 | + } |
| 382 | + |
| 383 | + |
| 384 | + |
| 385 | + |
331 | 386 | private void shouldGetFolderJobs(String... jobNames) throws IOException { |
332 | 387 | // given |
333 | 388 | String path = "http://localhost/jobs/someFolder/"; |
|
0 commit comments