Search in sources :

Example 11 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class TestCaseExecutionDAO method findExecutionbyCriteria1.

@Override
public List<TestCaseExecution> findExecutionbyCriteria1(String dateLimit, String test, String testCase, String application, String country, String environment, String controlStatus, String status) throws CerberusException {
    List<TestCaseExecution> myTestCaseExecutions = null;
    TestCaseExecution Execution;
    boolean throwException = false;
    final String query = new StringBuffer("SELECT exe.*, tec.*, app.* FROM testcaseexecution exe ").append("LEFT JOIN testcase tec ON exe.test = tec.test AND exe.testcase = tec.testcase ").append("LEFT JOIN application app ON exe.application = app.application ").append("WHERE exe.start > ? AND exe.test LIKE ? AND exe.testcase LIKE ? AND exe.environment LIKE ? ").append("AND exe.country LIKE ? AND exe.application LIKE ? AND exe.controlstatus LIKE ? ").append("AND exe.status LIKE ?").toString();
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, dateLimit);
        preStat.setString(2, test);
        preStat.setString(3, testCase);
        preStat.setString(4, environment);
        preStat.setString(5, country);
        preStat.setString(6, application);
        preStat.setString(7, controlStatus);
        preStat.setString(8, status);
        try (ResultSet resultSet = preStat.executeQuery()) {
            if (!(resultSet.first())) {
                throwException = true;
            } else {
                myTestCaseExecutions = new ArrayList<TestCaseExecution>();
                do {
                    Execution = this.loadWithDependenciesFromResultSet(resultSet);
                    myTestCaseExecutions.add(Execution);
                } while (resultSet.next());
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        }
    } catch (Exception exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    }
    if (throwException) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));
    }
    return myTestCaseExecutions;
}
Also used : IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) CerberusException(org.cerberus.exception.CerberusException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) ResultSet(java.sql.ResultSet)

Example 12 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class TestCaseExecutionDAO method readDistinctEnvCoutnryBrowserByTag.

@Override
public AnswerList readDistinctEnvCoutnryBrowserByTag(String tag) {
    AnswerList answer = new AnswerList();
    StringBuilder query = new StringBuilder();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    query.append("SELECT exe.* FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY exe.Environment, exe.Country, exe.Browser, exe.ControlStatus");
    Connection connection = this.databaseSpring.connect();
    List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setString(1, tag);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    testCaseExecutionList.add(this.loadFromResultSet(resultSet));
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
                answer = new AnswerList(testCaseExecutionList, testCaseExecutionList.size());
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
                testCaseExecutionList = null;
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
            testCaseExecutionList = null;
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException ex) {
        LOG.warn(ex.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
        }
    }
    answer.setResultMessage(msg);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 13 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class ExportServiceFactory method createRow.

private int createRow(String test, HashMap<String, List<TestCaseExecution>> executionsPerTestCase, Sheet sheet, int currentIndex, List<String> mapCountries) {
    int lastRow = currentIndex + executionsPerTestCase.size();
    int current = currentIndex;
    TreeMap<String, List<TestCaseExecution>> sortedKeys = new TreeMap<String, List<TestCaseExecution>>(executionsPerTestCase);
    // Create new style
    CellStyle wrapStyle = sheet.getColumnStyle(0);
    // Set wordwrap
    wrapStyle.setWrapText(true);
    for (String testCaseKey : sortedKeys.keySet()) {
        List<String> browserEnvironment = new LinkedList<String>();
        String application;
        String description;
        Row r = sheet.createRow(current);
        List<TestCaseExecution> executionList = executionsPerTestCase.get(testCaseKey);
        Cell testCell = r.createCell(0);
        testCell.setCellValue(test);
        testCell.setCellStyle(wrapStyle);
        r.createCell(1).setCellValue(testCaseKey);
        // gets the first object to retrieve the application - at least exists one test case execution
        if (executionList.isEmpty()) {
            application = "N/D";
            description = "N/D";
        } else {
            application = executionList.get(0).getApplication();
            description = executionList.get(0).getTestCaseObj().getBehaviorOrValueExpected();
        }
        // Sets the application and description
        r.createCell(2).setCellValue(application);
        r.createCell(3).setCellValue(description);
        int rowStartedTestCaseInfo = current;
        for (TestCaseExecution exec : executionList) {
            if (browserEnvironment.isEmpty()) {
                browserEnvironment.add(exec.getEnvironment() + "_" + exec.getBrowser());
                r.createCell(4).setCellValue(exec.getEnvironment());
                r.createCell(5).setCellValue(exec.getBrowser());
            } else {
                int index = browserEnvironment.indexOf(exec.getEnvironment() + "_" + exec.getBrowser());
                // Does not exist any information about browser and environment
                if (browserEnvironment.indexOf(exec.getEnvironment() + "_" + exec.getBrowser()) == -1) {
                    // need to add another row with the same characteristics
                    r = sheet.createRow(++current);
                    r.createCell(0).setCellValue(test);
                    r.createCell(1).setCellValue(testCaseKey);
                    r.createCell(2).setCellValue(application);
                    r.createCell(3).setCellValue(description);
                    r.createCell(4).setCellValue(exec.getEnvironment());
                    r.createCell(5).setCellValue(exec.getBrowser());
                    browserEnvironment.add(exec.getEnvironment() + "_" + exec.getBrowser());
                } else {
                    // there is information about the browser and environment
                    Row rowExisting = sheet.getRow(rowStartedTestCaseInfo + index);
                    r = rowExisting;
                }
            }
            // TODO:FN tirar daqui estes valores
            int indexOfCountry = mapCountries.indexOf(exec.getCountry()) + 6;
            Cell executionResult = r.createCell(indexOfCountry);
            executionResult.setCellValue(exec.getControlStatus());
            // Create hyperling
            CreationHelper createHelper = sheet.getWorkbook().getCreationHelper();
            CellStyle hlinkstyle = sheet.getWorkbook().createCellStyle();
            Font hlinkfont = sheet.getWorkbook().createFont();
            hlinkfont.setUnderline(XSSFFont.U_SINGLE);
            hlinkfont.setColor(HSSFColor.BLUE.index);
            hlinkstyle.setFont(hlinkfont);
            Hyperlink link = (Hyperlink) createHelper.createHyperlink(Hyperlink.LINK_URL);
            link.setAddress("http://www.tutorialspoint.com/");
            executionResult.setHyperlink((Hyperlink) link);
            executionResult.setCellStyle(hlinkstyle);
        }
        current++;
    }
    /*CellRangeAddress range = new CellRangeAddress(currentIndex, lastRow, 0, 0);
         sheet.addMergedRegion(range);*/
    return lastRow;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) Font(org.apache.poi.ss.usermodel.Font) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell) Hyperlink(org.apache.poi.ss.usermodel.Hyperlink)

Example 14 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class ExportServiceFactory method createReportByTagExport.

private void createReportByTagExport(Workbook workbook) {
    // handles the export of the execution by tag data
    HashMap<String, SummaryStatisticsDTO> summaryMap = new HashMap<String, SummaryStatisticsDTO>();
    HashMap<String, HashMap<String, List<TestCaseExecution>>> mapList = new HashMap<String, HashMap<String, List<TestCaseExecution>>>();
    List<String> mapCountries = new ArrayList<String>();
    List<CellStyle> stylesList = new LinkedList<CellStyle>();
    if (exportOptions.contains("chart") || exportOptions.contains("list")) {
        // then we need to create the default colors for each cell
        try (HSSFWorkbook hwb = new HSSFWorkbook()) {
            HSSFPalette palette = hwb.getCustomPalette();
            CellStyle okStyle = workbook.createCellStyle();
            // get the color which most closely matches the color you want to use
            // code to get the style for the cell goes here
            okStyle.setFillForegroundColor(palette.findSimilarColor(92, 184, 0).getIndex());
            okStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
            // okStyle.setFont();
            stylesList.add(okStyle);
        } catch (IOException e) {
            LOG.warn(e.toString());
        }
    }
    for (TestCaseExecution execution : (List<TestCaseExecution>) list) {
        if (exportOptions.contains("chart") || exportOptions.contains("summary")) {
            String keySummaryTable = execution.getApplication() + " " + execution.getCountry() + " " + execution.getEnvironment();
            SummaryStatisticsDTO stats;
            String status = execution.getControlStatus();
            if (summaryMap.containsKey(keySummaryTable)) {
                stats = summaryMap.get(keySummaryTable);
            } else {
                stats = new SummaryStatisticsDTO();
                stats.setApplication(execution.getApplication());
                stats.setCountry(execution.getCountry());
                stats.setEnvironment(execution.getEnvironment());
            }
            stats.updateStatisticByStatus(status);
            // updates the map
            summaryMap.put(keySummaryTable, stats);
        }
        if (exportOptions.contains("list")) {
            if (exportOptions.contains("filter")) {
            // filter active
            } else {
            // all data is saved
            }
            HashMap<String, List<TestCaseExecution>> listExecution;
            List<TestCaseExecution> testCaseList;
            String testKey = execution.getTest();
            String testCaseKey = execution.getTestCase();
            if (mapList.containsKey(testKey)) {
                listExecution = mapList.get(testKey);
            } else {
                listExecution = new HashMap<String, List<TestCaseExecution>>();
            }
            if (listExecution.containsKey(testCaseKey)) {
                testCaseList = listExecution.get(testCaseKey);
            } else {
                testCaseList = new ArrayList<TestCaseExecution>();
            }
            testCaseList.add(execution);
            listExecution.put(testCaseKey, testCaseList);
            mapList.put(testKey, listExecution);
            if (mapCountries.indexOf(execution.getCountry()) == -1) {
                mapCountries.add(execution.getCountry());
            }
        }
    }
    int rowCount = -1;
    // Create a blank sheet
    Sheet sheet = workbook.createSheet("Report by Tag");
    sheet.getPrintSetup().setLandscape(true);
    PrintSetup ps = sheet.getPrintSetup();
    sheet.setAutobreaks(true);
    // ps.setFitHeight((short) 1);
    ps.setFitWidth((short) 1);
    sheet.setFitToPage(true);
    sheet.setColumnWidth(0, 9000);
    if (exportOptions.contains("chart")) {
        SummaryStatisticsDTO sumsTotal = calculateTotalValues(summaryMap);
        Row row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("Report By Status");
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("Status");
        row.createCell(1).setCellValue("Total");
        row.createCell(2).setCellValue("Percentage");
        row = sheet.createRow(++rowCount);
        CellStyle okStyle = stylesList.get(0);
        Cell cellOk = row.createCell(0);
        cellOk.setCellValue("OK");
        cellOk.setCellStyle(okStyle);
        row.createCell(1).setCellValue(sumsTotal.getOK());
        row.createCell(2).setCellValue(sumsTotal.getPercOK());
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("KO");
        row.createCell(1).setCellValue(sumsTotal.getKO());
        row.createCell(2).setCellValue(sumsTotal.getPercKO());
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("FA");
        row.createCell(1).setCellValue(sumsTotal.getFA());
        row.createCell(2).setCellValue(sumsTotal.getPercFA());
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("NA");
        row.createCell(1).setCellValue(sumsTotal.getNA());
        row.createCell(2).setCellValue(sumsTotal.getPercNA());
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("NE");
        row.createCell(1).setCellValue(sumsTotal.getNE());
        row.createCell(2).setCellValue(sumsTotal.getPercNE());
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("QU");
        row.createCell(1).setCellValue(sumsTotal.getQU());
        row.createCell(2).setCellValue(sumsTotal.getPercQU());
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("PE");
        row.createCell(1).setCellValue(sumsTotal.getPE());
        row.createCell(2).setCellValue(sumsTotal.getPercPE());
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("CA");
        row.createCell(1).setCellValue(sumsTotal.getCA());
        row.createCell(2).setCellValue(sumsTotal.getPercCA());
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("Total");
        row.createCell(1).setCellValue(sumsTotal.getTotal());
        sheet.createRow(++rowCount).createCell(0).setCellValue("");
        sheet.createRow(++rowCount).createCell(0).setCellValue("");
        sheet.createRow(++rowCount).createCell(0).setCellValue("");
        sheet.createRow(++rowCount).createCell(0).setCellValue("");
    }
    if (exportOptions.contains("summary")) {
        // draw the table with data
        Row row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("Summary Table");
        // start creating data
        row = sheet.createRow(++rowCount);
        row.createCell(0).setCellValue("Application");
        row.createCell(1).setCellValue("Country");
        row.createCell(2).setCellValue("Environment");
        row.createCell(3).setCellValue("OK");
        row.createCell(4).setCellValue("KO");
        row.createCell(5).setCellValue("FA");
        row.createCell(6).setCellValue("NA");
        row.createCell(7).setCellValue("NE");
        row.createCell(8).setCellValue("PE");
        row.createCell(8).setCellValue("QU");
        row.createCell(9).setCellValue("CA");
        row.createCell(10).setCellValue("NOT OK");
        row.createCell(11).setCellValue("Total");
        /*temporary styles*/
        CellStyle styleBlue = workbook.createCellStyle();
        CellStyle styleGreen = workbook.createCellStyle();
        try (HSSFWorkbook hwb = new HSSFWorkbook()) {
            HSSFPalette palette = hwb.getCustomPalette();
            // get the color which most closely matches the color you want to use
            HSSFColor myColor = palette.findSimilarColor(66, 139, 202);
            // get the palette index of that color
            short palIndex = myColor.getIndex();
            // code to get the style for the cell goes here
            styleBlue.setFillForegroundColor(palIndex);
            styleBlue.setFillPattern(CellStyle.SPARSE_DOTS);
            HSSFColor myColorGreen = palette.findSimilarColor(92, 184, 0);
            styleGreen.setFillForegroundColor(myColorGreen.getIndex());
            styleGreen.setFillPattern(CellStyle.SPARSE_DOTS);
            int startRow = (rowCount + 2);
            TreeMap<String, SummaryStatisticsDTO> sortedSummaryMap = new TreeMap<String, SummaryStatisticsDTO>(summaryMap);
            for (String key : sortedSummaryMap.keySet()) {
                row = sheet.createRow(++rowCount);
                SummaryStatisticsDTO sumStats = summaryMap.get(key);
                // application
                row.createCell(0).setCellValue((String) sumStats.getApplication());
                // country
                row.createCell(1).setCellValue((String) sumStats.getCountry());
                // environment
                row.createCell(2).setCellValue((String) sumStats.getEnvironment());
                // OK
                row.createCell(3).setCellValue(sumStats.getOK());
                // KO
                row.createCell(4).setCellValue(sumStats.getKO());
                // FA
                row.createCell(5).setCellValue(sumStats.getFA());
                // NA
                row.createCell(6).setCellValue(sumStats.getNA());
                // NE
                row.createCell(7).setCellValue(sumStats.getNE());
                // PE
                row.createCell(8).setCellValue(sumStats.getPE());
                // QU
                row.createCell(9).setCellValue(sumStats.getQU());
                // CA
                row.createCell(10).setCellValue(sumStats.getCA());
                int rowNumber = row.getRowNum() + 1;
                // NOT OK
                // row.createCell(11).setCellValue(sumStats.getNotOkTotal());
                row.createCell(11).setCellFormula("SUM(E" + rowNumber + ":J" + rowNumber + ")");
                // Total
                row.createCell(12).setCellFormula("SUM(D" + rowNumber + ",K" + rowNumber + ")");
                if (sumStats.getOK() == sumStats.getTotal()) {
                    for (int i = 0; i < 13; i++) {
                        row.getCell(i).setCellStyle(styleGreen);
                    }
                }
            }
            // TODO:FN percentages missing
            // Total row
            row = sheet.createRow(++rowCount);
            row.createCell(0).setCellValue("Total");
            row.createCell(1).setCellValue("");
            row.createCell(2).setCellValue("");
            // OK
            row.createCell(3).setCellFormula("SUM(D" + startRow + ":D" + rowCount + ")");
            // KO
            row.createCell(4).setCellFormula("SUM(E" + startRow + ":E" + rowCount + ")");
            // FA
            row.createCell(5).setCellFormula("SUM(F" + startRow + ":F" + rowCount + ")");
            // NA
            row.createCell(6).setCellFormula("SUM(G" + startRow + ":G" + rowCount + ")");
            // NE
            row.createCell(7).setCellFormula("SUM(H" + startRow + ":H" + rowCount + ")");
            // PE
            row.createCell(8).setCellFormula("SUM(I" + startRow + ":I" + rowCount + ")");
            // QU
            row.createCell(9).setCellFormula("SUM(J" + startRow + ":I" + rowCount + ")");
            // CA
            row.createCell(10).setCellFormula("SUM(K" + startRow + ":J" + rowCount + ")");
            int rowNumberTotal = row.getRowNum() + 1;
            // NOT OK
            row.createCell(11).setCellFormula("SUM(E" + rowNumberTotal + ":J" + rowNumberTotal + ")");
            // Total
            row.createCell(12).setCellFormula("SUM(D" + rowNumberTotal + ",K" + rowNumberTotal + ")");
            for (int i = 0; i < 13; i++) {
                row.getCell(i).setCellStyle(styleBlue);
            }
            // add some empty rows
            sheet.createRow(++rowCount).createCell(0).setCellValue("");
            sheet.createRow(++rowCount).createCell(0).setCellValue("");
            sheet.createRow(++rowCount).createCell(0).setCellValue("");
            sheet.createRow(++rowCount).createCell(0).setCellValue("");
        } catch (IOException e) {
            LOG.warn(e.toString());
        }
    }
    if (exportOptions.contains("list")) {
        // exports the data from test cases' executions
        Row r = sheet.createRow(++rowCount);
        r.createCell(0).setCellValue("Test");
        r.createCell(1).setCellValue("Test Case");
        r.createCell(2).setCellValue("Description");
        r.createCell(3).setCellValue("Application");
        r.createCell(4).setCellValue("Environment");
        r.createCell(5).setCellValue("Browser");
        // creates the country list
        // sorts the list of countries
        Collections.sort(mapCountries);
        int startIndexForCountries = 6;
        for (String country : mapCountries) {
            r.createCell(startIndexForCountries).setCellValue(country);
            startIndexForCountries++;
        }
        TreeMap<String, HashMap<String, List<TestCaseExecution>>> sortedKeys = new TreeMap<String, HashMap<String, List<TestCaseExecution>>>(mapList);
        rowCount++;
        for (String keyMapList : sortedKeys.keySet()) {
            rowCount = createRow(keyMapList, mapList.get(keyMapList), sheet, rowCount, mapCountries);
        }
    }
}
Also used : HSSFPalette(org.apache.poi.hssf.usermodel.HSSFPalette) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HSSFColor(org.apache.poi.hssf.util.HSSFColor) PrintSetup(org.apache.poi.ss.usermodel.PrintSetup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Cell(org.apache.poi.ss.usermodel.Cell) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) IOException(java.io.IOException) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) SummaryStatisticsDTO(org.cerberus.dto.SummaryStatisticsDTO) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 15 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class GetReportData method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, ParseException, JSONException {
    response.setContentType("text/html;charset=UTF-8");
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);
    testCaseExecutionInQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);
    response.setContentType("application/json");
    response.setCharacterEncoding("utf8");
    JSONObject jsonResult = new JSONObject();
    String tag = request.getParameter("Tag");
    boolean split = ParameterParserUtil.parseBooleanParam(request.getParameter("split"), false);
    /**
     * Get list of execution by tag, env, country, browser
     */
    AnswerList<TestCaseExecution> listOfExecution = testCaseExecutionService.readByTagByCriteria(tag, 0, 0, null, null, null);
    List<TestCaseExecution> testCaseExecutions = listOfExecution.getDataList();
    /**
     * Get list of Execution in Queue by Tag
     */
    List<TestCaseExecutionQueue> testCaseExecutionsInQueue = testCaseExecutionInQueueService.findTestCaseExecutionInQueuebyTag(tag);
    /**
     * Feed hash map with execution from the two list (to get only one by
     * test,testcase,country,env,browser)
     */
    testCaseExecutions = hashExecution(testCaseExecutions, testCaseExecutionsInQueue);
    /**
     * Geting the global start and end of the execution tag.
     */
    long startMin = 0;
    long endMax = 0;
    for (TestCaseExecution testCaseExecution : testCaseExecutions) {
        if ((startMin == 0) || (testCaseExecution.getStart() < startMin)) {
            startMin = testCaseExecution.getStart();
        }
        if ((endMax == 0) || (testCaseExecution.getEnd() > endMax)) {
            endMax = testCaseExecution.getEnd();
        }
    }
    if (!split) {
        Map<String, JSONObject> axisMap = new HashMap<String, JSONObject>();
        for (TestCaseExecution testCaseWithExecution : testCaseExecutions) {
            String key;
            String controlStatus;
            JSONObject control = new JSONObject();
            JSONObject function = new JSONObject();
            if (testCaseWithExecution.getTestCaseObj().getFunction() != null && !"".equals(testCaseWithExecution.getTestCaseObj().getFunction())) {
                key = testCaseWithExecution.getTestCaseObj().getFunction();
            } else {
                key = testCaseWithExecution.getTest();
            }
            controlStatus = testCaseWithExecution.getControlStatus();
            control.put("value", 1);
            control.put("color", getColor(controlStatus));
            control.put("label", controlStatus);
            function.put("name", key);
            if (axisMap.containsKey(key)) {
                function = axisMap.get(key);
                if (function.has(controlStatus)) {
                    int prec = function.getJSONObject(controlStatus).getInt("value");
                    control.put("value", prec + 1);
                }
            }
            function.put(controlStatus, control);
            axisMap.put(key, function);
        }
        jsonResult.put("axis", axisMap.values());
        jsonResult.put("tag", tag);
        jsonResult.put("start", new Date(startMin));
        jsonResult.put("end", new Date(endMax));
    } else if (split) {
        boolean env = ParameterParserUtil.parseBooleanParam(request.getParameter("env"), false);
        boolean country = ParameterParserUtil.parseBooleanParam(request.getParameter("country"), false);
        boolean browser = ParameterParserUtil.parseBooleanParam(request.getParameter("browser"), false);
        boolean app = ParameterParserUtil.parseBooleanParam(request.getParameter("app"), false);
        AnswerList columnExec = testCaseExecutionService.readDistinctColumnByTag(tag, env, country, browser, app);
        List<TestCaseExecution> columnTcExec = columnExec.getDataList();
        AnswerList columnQueue = testCaseExecutionInQueueService.readDistinctColumnByTag(tag, env, country, browser, app);
        List<TestCaseExecutionQueue> columnInQueue = columnQueue.getDataList();
        Map<String, TestCaseExecution> testCaseExecutionsList = new LinkedHashMap();
        for (TestCaseExecution column : columnTcExec) {
            String key = column.getBrowser() + column.getCountry() + column.getEnvironment() + column.getApplication();
            testCaseExecutionsList.put(key, column);
        }
        for (TestCaseExecutionQueue column : columnInQueue) {
            TestCaseExecution testCaseExecution = testCaseExecutionInQueueService.convertToTestCaseExecution(column);
            String key = testCaseExecution.getBrowser() + testCaseExecution.getCountry() + testCaseExecution.getEnvironment() + testCaseExecution.getApplicationObj().getApplication();
            testCaseExecutionsList.put(key, testCaseExecution);
        }
        List<TestCaseExecution> res = new ArrayList<TestCaseExecution>(testCaseExecutionsList.values());
        HashMap<String, SummaryStatisticsDTO> statMap = new HashMap<String, SummaryStatisticsDTO>();
        for (TestCaseExecution column : res) {
            SummaryStatisticsDTO stat = new SummaryStatisticsDTO();
            stat.setEnvironment(column.getEnvironment());
            stat.setCountry(column.getCountry());
            stat.setRobotDecli(column.getBrowser());
            stat.setApplication(column.getApplication());
            statMap.put(column.getEnvironment() + "_" + column.getCountry() + "_" + column.getBrowser() + "_" + column.getApplication(), stat);
        }
        jsonResult.put("contentTable", getStatByEnvCountryBrowser(testCaseExecutions, statMap, env, country, browser, app));
    }
    response.getWriter().print(jsonResult);
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) SummaryStatisticsDTO(org.cerberus.dto.SummaryStatisticsDTO) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ITestCaseExecutionQueueService(org.cerberus.crud.service.ITestCaseExecutionQueueService)

Aggregations

TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)55 ArrayList (java.util.ArrayList)24 IFactoryTestCaseExecution (org.cerberus.crud.factory.IFactoryTestCaseExecution)20 MessageEvent (org.cerberus.engine.entity.MessageEvent)19 JSONObject (org.json.JSONObject)17 AnswerItem (org.cerberus.util.answer.AnswerItem)15 AnswerList (org.cerberus.util.answer.AnswerList)14 Connection (java.sql.Connection)13 PreparedStatement (java.sql.PreparedStatement)13 ResultSet (java.sql.ResultSet)13 SQLException (java.sql.SQLException)13 LinkedHashMap (java.util.LinkedHashMap)13 ITestCaseExecutionService (org.cerberus.crud.service.ITestCaseExecutionService)12 CerberusException (org.cerberus.exception.CerberusException)11 List (java.util.List)10 HashMap (java.util.HashMap)9 TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)9 JSONArray (org.json.JSONArray)9 JSONException (org.json.JSONException)9 ApplicationContext (org.springframework.context.ApplicationContext)9