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.ComponentSmokeTest;
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(
052                    ComponentSmokeTest.CREATE_NEW_DOCUMENT_NOT_SUBMITTED_SUCCESSFULLY_MESSAGE_TEXT + ComponentSmokeTest.FOR_TEST_MESSAGE,
053                    KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
054    
055            jiraMatches.put("//*[@id='u229']", KULRICE_8823_FIX_BROKEN_SMOKE_TESTS_IN_CI);
056    
057            jiraMatches.put("after clicking Expand All", "KULRICE-3833 KRAD Sampleapp (Travel) Account Inquiry Collapse all toggles all and Expand all does nothing");
058            //        jiraMatches.put("",
059            //                "");
060        }
061    
062        /**
063         * If the contents contents the jiraMatches key, call fail on failable passing in the jiraMatches value for the matched key.
064         * @param contents to check for containing of the jiraMatches keys.
065         * @param failable to fail with the jiraMatches value if the jiraMatches key is contained in the contents
066         */
067        public static void failOnMatchedJira(String contents, Failable failable) {
068            Iterator<String> iter = jiraMatches.keySet().iterator();
069            String key = null;
070    
071            while (iter.hasNext()) {
072                key = iter.next();
073                if (contents.contains(key)) {
074                    failable.fail(JIRA_BROWSE_URL + jiraMatches.get(key));
075                }
076            }
077        }
078    
079        /**
080         * Calls failOnMatchedJira with the contents and if no match is detected then the message.
081         * @param contents to check for containing of the jiraMatches keys.
082         * @param message to check for containing of the jiraMatches keys if contents doesn't
083         * @param failable to fail with the jiraMatches value if the contents or message is detected
084         */
085        public static void failOnMatchedJira(String contents, String message, Failable failable) {
086            failOnMatchedJira(contents, failable);
087            failOnMatchedJira(message, failable);
088        }
089    }