View Javadoc

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.ComponentAbstractSmokeTestBase;
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(ComponentAbstractSmokeTestBase.CREATE_NEW_DOCUMENT_NOT_SUBMITTED_SUCCESSFULLY_MESSAGE_TEXT + ComponentAbstractSmokeTestBase.FOR_TEST_MESSAGE,
52                  KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
53  
54          jiraMatches.put("//*[@id='u229']", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
55  
56          jiraMatches.put("//a[contains(text(),'Travel Account Lookup')])[3]", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
57  
58          jiraMatches.put("By.linkText: Travel Account Lookup", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
59  
60          jiraMatches.put("//a[contains(text(),'Validation - Regex')", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
61  
62          //        jiraMatches.put("",
63          //                "");
64      }
65  
66      /**
67       * If the contents contents the jiraMatches key, call fail on failable passing in the jiraMatches value for the matched key.
68       * @param contents to check for containing of the jiraMatches keys.
69       * @param failable to fail with the jiraMatches value if the jiraMatches key is contained in the contents
70       */
71      public static void failOnMatchedJira(String contents, Failable failable) {
72          Iterator<String> iter = jiraMatches.keySet().iterator();
73          String key = null;
74  
75          while (iter.hasNext()) {
76              key = iter.next();
77              if (contents.contains(key)) {
78                  failable.fail(JIRA_BROWSE_URL + jiraMatches.get(key));
79              }
80          }
81      }
82  
83      /**
84       * Calls failOnMatchedJira with the contents and if no match is detected then the message.
85       * @param contents to check for containing of the jiraMatches keys.
86       * @param message to check for containing of the jiraMatches keys if contents doesn't
87       * @param failable to fail with the jiraMatches value if the contents or message is detected
88       */
89      public static void failOnMatchedJira(String contents, String message, Failable failable) {
90          failOnMatchedJira(contents, failable);
91          failOnMatchedJira(message, failable);
92      }
93  }