001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package edu.samplu.common;
017
018 import edu.samplu.admin.test.ComponentAbstractSmokeTestBase;
019
020 import java.util.HashMap;
021 import java.util.Iterator;
022 import java.util.Map;
023
024 /**
025 * Created as a way to link Rice Smoke Test failures to existing Jiras as a html link in Jenkins. The more failures
026 * the more useful it is to not have to keep tracking down the same Jiras. Having this feature for Integration Tests
027 * as well would be a huge help for the QA team.
028 * TODO:
029 * <ol>
030 * <li>Integration Test integration. ITs often fail by the 10s tracking down existing Jiras is a huge time sink.</li>
031 * <li>Possible Extraction of jiraMatches data to property file.</li>
032 * </ol>
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 */
035 public class JiraAwareFailureUtil {
036 /**
037 * KULRICE-8823 Fix broken smoke tests in CI
038 */
039 public static final String KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI = "KULRICE-8823 Fix broken smoke tests in CI";
040
041 /**
042 * https://jira.kuali.org/browse/
043 */
044 public static final String JIRA_BROWSE_URL = "https://jira.kuali.org/browse/";
045
046 static Map<String, String> jiraMatches;
047
048 static {
049 jiraMatches = new HashMap<String, String>();
050
051 jiraMatches.put(ComponentAbstractSmokeTestBase.CREATE_NEW_DOCUMENT_NOT_SUBMITTED_SUCCESSFULLY_MESSAGE_TEXT + ComponentAbstractSmokeTestBase.FOR_TEST_MESSAGE,
052 KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
053
054 jiraMatches.put("//*[@id='u229']", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
055
056 jiraMatches.put("//a[contains(text(),'Travel Account Lookup')])[3]", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
057
058 jiraMatches.put("By.linkText: Travel Account Lookup", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
059
060 jiraMatches.put("//a[contains(text(),'Validation - Regex')", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
061
062 // jiraMatches.put("",
063 // "");
064 }
065
066 /**
067 * If the contents contents the jiraMatches key, call fail on failable passing in the jiraMatches value for the matched key.
068 * @param contents to check for containing of the jiraMatches keys.
069 * @param failable to fail with the jiraMatches value if the jiraMatches key is contained in the contents
070 */
071 public static void failOnMatchedJira(String contents, Failable failable) {
072 Iterator<String> iter = jiraMatches.keySet().iterator();
073 String key = null;
074
075 while (iter.hasNext()) {
076 key = iter.next();
077 if (contents.contains(key)) {
078 failable.fail(JIRA_BROWSE_URL + jiraMatches.get(key));
079 }
080 }
081 }
082
083 /**
084 * Calls failOnMatchedJira with the contents and if no match is detected then the message.
085 * @param contents to check for containing of the jiraMatches keys.
086 * @param message to check for containing of the jiraMatches keys if contents doesn't
087 * @param failable to fail with the jiraMatches value if the contents or message is detected
088 */
089 public static void failOnMatchedJira(String contents, String message, Failable failable) {
090 failOnMatchedJira(contents, failable);
091 failOnMatchedJira(message, failable);
092 }
093 }