1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.testtools.selenium;
17
18 import org.apache.commons.io.FileUtils;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Test;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.net.MalformedURLException;
26
27
28
29
30 public class JenkinsJsonAllJobsResults extends JenkinsJsonJobResultsBase {
31
32 @Before
33 public void setUp() throws MalformedURLException, InterruptedException {
34 super.setUp();
35 }
36
37 @After
38 public void tearDown() {
39 closeAndQuitWebDriver();
40 }
41
42 @Test
43 public void testGetAllJobResults() throws Exception {
44 for (int i = 0, s = jobs.length; i < s; i++) {
45 getResults(jobs[i]);
46 }
47 }
48
49 private void getResults(String job) throws Exception {
50 String url = null;
51 String jobJson;
52 String json;
53 String outputFile;
54
55 url = jenkinsBase + "/job/" + job + "/api/json";
56
57 jobJson = retrieveJson(url);
58
59 String jsonJobNumber;
60 while (jobJson.contains(("{\"number\":"))) {
61 jsonJobNumber = jobJson.substring(jobJson.indexOf("{\"number\":") + 10, jobJson.length());
62 jsonJobNumber = jsonJobNumber.substring(0, jsonJobNumber.indexOf(","));
63
64 jobJson = jobJson.substring(jobJson.indexOf("{\"number\":") + 9, jobJson.length());
65
66 try {
67 writeJobResults(job, jsonJobNumber);
68 } catch (Exception e) {
69 passed = false;
70 System.out.println("job: " + job + " url: " + url + " " + e.getMessage());
71 e.printStackTrace();
72 }
73 }
74
75 }
76
77 private void writeJobResults(String job, String jobNumber) throws InterruptedException, IOException {
78 String url;
79 String json;
80 String outputFile;
81 url = jenkinsBase + "/job/" + job + "/" + jobNumber + "/testReport/api/json";
82 json = retrieveJson(url);
83
84 outputFile = job + "-" + jobNumber + ".json";
85 if (outputDirectory != null) {
86 outputFile = outputDirectory + File.separatorChar + outputFile;
87 }
88
89 json = json.replaceAll("}],", "}],\n");
90 FileUtils.writeStringToFile(new File(outputFile), json);
91 }
92 }