1 /**
2 * Copyright 2005-2013 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package edu.samplu.common;
17
18 import edu.samplu.admin.test.ComponentSmokeTest;
19
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.Map;
23
24 /**
25 * Created as a way to link Rice Smoke Test failures to existing Jiras as a html link in Jenkins. The more failures
26 * the more useful it is to not have to keep tracking down the same Jiras. Having this feature for Integration Tests
27 * as well would be a huge help for the QA team.
28 * TODO:
29 * <ol>
30 * <li>Integration Test integration. ITs often fail by the 10s tracking down existing Jiras is a huge time sink.</li>
31 * <li>Possible Extraction of jiraMatches data to property file.</li>
32 * </ol>
33 * @author Kuali Rice Team (rice.collab@kuali.org)
34 */
35 public class JiraAwareFailureUtil {
36 /**
37 * KULRICE-8823 Fix broken smoke tests in CI
38 */
39 public static final String KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI = "KULRICE-8823 Fix broken smoke tests in CI";
40
41 /**
42 * https://jira.kuali.org/browse/
43 */
44 public static final String JIRA_BROWSE_URL = "https://jira.kuali.org/browse/";
45
46 static Map<String, String> jiraMatches;
47
48 static {
49 jiraMatches = new HashMap<String, String>();
50
51 jiraMatches.put(
52 ComponentSmokeTest.CREATE_NEW_DOCUMENT_NOT_SUBMITTED_SUCCESSFULLY_MESSAGE_TEXT + ComponentSmokeTest.FOR_TEST_MESSAGE,
53 KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
54
55 jiraMatches.put("//*[@id='u229']", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
56
57 jiraMatches.put("after clicking Expand All", "KULRICE-3833 KRAD Sampleapp (Travel) Account Inquiry Collapse all toggles all and Expand all does nothing");
58 // jiraMatches.put("",
59 // "");
60 }
61
62 /**
63 * If the contents contents the jiraMatches key, call fail on failable passing in the jiraMatches value for the matched key.
64 * @param contents to check for containing of the jiraMatches keys.
65 * @param failable to fail with the jiraMatches value if the jiraMatches key is contained in the contents
66 */
67 public static void failOnMatchedJira(String contents, Failable failable) {
68 Iterator<String> iter = jiraMatches.keySet().iterator();
69 String key = null;
70
71 while (iter.hasNext()) {
72 key = iter.next();
73 if (contents.contains(key)) {
74 failable.fail(JIRA_BROWSE_URL + jiraMatches.get(key));
75 }
76 }
77 }
78
79 /**
80 * Calls failOnMatchedJira with the contents and if no match is detected then the message.
81 * @param contents to check for containing of the jiraMatches keys.
82 * @param message to check for containing of the jiraMatches keys if contents doesn't
83 * @param failable to fail with the jiraMatches value if the contents or message is detected
84 */
85 public static void failOnMatchedJira(String contents, String message, Failable failable) {
86 failOnMatchedJira(contents, failable);
87 failOnMatchedJira(message, failable);
88 }
89 }