1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.testtools.common;
17
18 import java.io.BufferedReader;
19 import java.io.InputStreamReader;
20 import java.net.HttpURLConnection;
21 import java.net.URL;
22 import java.util.Iterator;
23
24
25
26
27
28
29
30 public class JiraAwareStatusCheck {
31
32 public static void main(String[] args ) {
33 String baseUrl = "https://jira.kuali.org/browse/";
34 String jira = "";
35 String statusSpan = "<span id=\"status-val\" class=\"value\">";
36
37 checkJiraMatchesContains(baseUrl, jira, statusSpan);
38 checkJiraMatchesRegex(baseUrl, jira, statusSpan);
39 }
40
41 private static void checkJiraMatchesContains(String baseUrl, String jira, String statusSpan) {
42 String key;
43 String status;
44 Iterator iter = JiraAwareFailureUtils.jiraMatches.keySet().iterator();
45 while (iter.hasNext()) {
46 key = (String)iter.next();
47 jira = JiraAwareFailureUtils.jiraMatches.getProperty(key);
48 jira = jira.substring(0, jira.indexOf(" "));
49 try {
50 status = getStatus(baseUrl, jira, statusSpan);
51 System.out.println(jira + " Status: " + status + " for key: " + key);
52 } catch (Exception e) {
53 System.out.println("Exception reading " + baseUrl + jira + " " + e.getMessage());
54 e.printStackTrace();
55 }
56 }
57 }
58
59 private static void checkJiraMatchesRegex(String baseUrl, String jira, String statusSpan) {
60 String key;
61 String status;
62 Iterator iter = JiraAwareFailureUtils.regexJiraMatches.keySet().iterator();
63 while (iter.hasNext()) {
64 key = (String)iter.next();
65 jira = JiraAwareFailureUtils.regexJiraMatches.getProperty(key);
66 jira = jira.substring(0, jira.indexOf(" "));
67 try {
68 status = getStatus(baseUrl, jira, statusSpan);
69 System.out.println(jira + " Status: " + status + " for key: " + key);
70 } catch (Exception e) {
71 System.out.println("Exception reading " + baseUrl + jira + " " + e.getMessage());
72 e.printStackTrace();
73 }
74 }
75 }
76
77 private static String getStatus(String baseUrl, String jira, String statusSpan) throws Exception {
78 String contents = JiraAwareStatusCheck.getText(baseUrl + jira);
79
80 contents = contents.substring(contents.indexOf(statusSpan) + statusSpan.length(), contents.length());
81 contents = contents.substring(0, contents.indexOf("</span>"));
82 String status = contents.substring(contents.indexOf("alt=\"") + 5, contents.length());
83 status = status.substring(0, status.indexOf("\""));
84 return status;
85 }
86
87 public static String getText(String url) throws Exception {
88 URL website = new URL(url);
89 HttpURLConnection connection = (HttpURLConnection)website.openConnection();
90 connection.setInstanceFollowRedirects(true);
91 BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
92
93 StringBuilder response = new StringBuilder();
94 String inputLine;
95
96 while ((inputLine = in.readLine()) != null) {
97 response.append(inputLine);
98 }
99
100 in.close();
101
102 return response.toString();
103 }
104 }