Search in sources :

Example 36 with TestCaseExecution

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

the class TestCaseExecutionService method readByKeyWithDependency.

@Override
public AnswerItem readByKeyWithDependency(long executionId) {
    AnswerItem tce = this.readByKey(executionId);
    TestCaseExecution testCaseExecution = (TestCaseExecution) tce.getItem();
    AnswerItem<TestCase> ai = testCaseService.readByKeyWithDependency(testCaseExecution.getTest(), testCaseExecution.getTestCase());
    testCaseExecution.setTestCaseObj(ai.getItem());
    AnswerList a = testCaseExecutionDataService.readByIdWithDependency(executionId);
    for (Object object : a.getDataList()) {
        TestCaseExecutionData tced = (TestCaseExecutionData) object;
        if (tced.getIndex() == 1) {
            testCaseExecution.getTestCaseExecutionDataMap().put(tced.getProperty(), tced);
        }
    }
    // We frist add the 'Pres Testing' testcase execution steps.
    AnswerList preTestCaseSteps = testCaseStepExecutionService.readByVarious1WithDependency(executionId, "Pre Testing", null);
    testCaseExecution.setTestCaseStepExecutionList(preTestCaseSteps.getDataList());
    // Then we add the steps from the main testcase.
    AnswerList steps = testCaseStepExecutionService.readByVarious1WithDependency(executionId, testCaseExecution.getTest(), testCaseExecution.getTestCase());
    testCaseExecution.addTestCaseStepExecutionList(steps.getDataList());
    AnswerList files = testCaseExecutionFileService.readByVarious(executionId, "");
    testCaseExecution.setFileList((List<TestCaseExecutionFile>) files.getDataList());
    AnswerItem response = new AnswerItem(testCaseExecution, tce.getResultMessage());
    return response;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) AnswerList(org.cerberus.util.answer.AnswerList) TestCase(org.cerberus.crud.entity.TestCase) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 37 with TestCaseExecution

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

the class EmailGenerationService method generateNotifyEndTagExecution.

@Override
public Email generateNotifyEndTagExecution(String tag, String campaign, String to, String ciResult, double ciScore) throws Exception {
    Email email = new Email();
    String system = "";
    String from = parameterService.getParameterStringByKey("cerberus_notification_tagexecutionend_from", system, "Cerberus <no.reply@cerberus-testing.org>");
    String host = parameterService.findParameterByKey("cerberus_smtp_host", system).getValue();
    int port = Integer.valueOf(parameterService.findParameterByKey("cerberus_smtp_port", system).getValue());
    String userName = parameterService.findParameterByKey("cerberus_smtp_username", system).getValue();
    String password = parameterService.findParameterByKey("cerberus_smtp_password", system).getValue();
    String subject = parameterService.getParameterStringByKey("cerberus_notification_tagexecutionend_subject", system, "Empty Subject. Please define parameter 'cerberus_notification_tagexecutionend_subject'.");
    String body = parameterService.getParameterStringByKey("cerberus_notification_tagexecutionend_body", system, "Empty Body. Please define parameter 'cerberus_notification_tagexecutionend_body'.");
    String cerberusUrl = parameterService.findParameterByKey("cerberus_url", system).getValue();
    StringBuilder urlreporttag = new StringBuilder();
    urlreporttag.append(cerberusUrl);
    urlreporttag.append("/ReportingExecutionByTag.jsp?Tag=");
    urlreporttag.append(tag);
    // Body replace.
    body = body.replace("%TAG%", tag);
    body = body.replace("%URLTAGREPORT%", urlreporttag.toString());
    body = body.replace("%CAMPAIGN%", campaign);
    body = body.replace("%CIRESULT%", ciResult);
    body = body.replace("%CISCORE%", String.format("%.2f", ciScore));
    Tag mytag = tagService.convert(tagService.readByKey(tag));
    long tagDur = (mytag.getDateEndQueue().getTime() - mytag.getDateCreated().getTime()) / 60000;
    body = body.replace("%TAGDURATION%", String.valueOf(tagDur));
    body = body.replace("%TAGSTART%", String.valueOf(mytag.getDateCreated()));
    body = body.replace("%TAGEND%", String.valueOf(mytag.getDateEndQueue()));
    // Get TestcaseExecutionDetail in order to replace %TAGGLOBALSTATUS% or %TAGTCDETAIL%.
    List<TestCaseExecution> testCaseExecutions = testCaseExecutionService.readLastExecutionAndExecutionInQueueByTag(tag);
    StringBuilder globalStatus = new StringBuilder();
    globalStatus.append("<table><thead><tr style=\"background-color:#cad3f1; font-style:bold\"><td>Status</td><td>Number</td><td>%</td></tr></thead><tbody>");
    Map<String, Integer> axisMap = new HashMap<String, Integer>();
    Integer total;
    total = testCaseExecutions.size();
    for (TestCaseExecution execution : testCaseExecutions) {
        if (axisMap.containsKey(execution.getControlStatus())) {
            axisMap.put(execution.getControlStatus(), axisMap.get(execution.getControlStatus()) + 1);
        } else {
            axisMap.put(execution.getControlStatus(), 1);
        }
    }
    float per = 0;
    DecimalFormat df = new DecimalFormat("#.##");
    for (Map.Entry<String, Integer> entry : axisMap.entrySet()) {
        globalStatus.append("<tr>");
        globalStatus.append("<td>").append(entry.getKey()).append("</td>");
        globalStatus.append("<td>").append(entry.getValue()).append("</td>");
        per = (float) entry.getValue() / (float) total;
        per = per * 100;
        globalStatus.append("<td>").append(String.format("%.2f", per)).append("</td>");
        globalStatus.append("</tr>");
    }
    globalStatus.append("<tr style=\"background-color:#cad3f1; font-style:bold\"><td>TOTAL</td>");
    globalStatus.append("<td>").append(total).append("</td>");
    globalStatus.append("<td></td></tr>");
    globalStatus.append("</tbody></table>");
    body = body.replace("%TAGGLOBALSTATUS%", globalStatus.toString());
    Integer totalTC = 0;
    StringBuilder detailStatus = new StringBuilder();
    detailStatus.append("<table><thead><tr style=\"background-color:#cad3f1; font-style:bold\"><td>Test</td><td>Test Case</td><td>Description</td><td>Environment</td><td>Country</td><td>Status</td></tr></thead><tbody>");
    for (TestCaseExecution execution : testCaseExecutions) {
        if (!TestCaseExecution.CONTROLSTATUS_OK.equals(execution.getControlStatus())) {
            detailStatus.append("<tr>");
            detailStatus.append("<td>").append(execution.getTest()).append("</td>");
            detailStatus.append("<td>").append(execution.getTestCase()).append("</td>");
            detailStatus.append("<td>").append(execution.getDescription()).append("</td>");
            detailStatus.append("<td>").append(execution.getEnvironment()).append("</td>");
            detailStatus.append("<td>").append(execution.getCountry()).append("</td>");
            detailStatus.append("<td>").append(execution.getControlStatus()).append("</td>");
            detailStatus.append("</tr>");
            totalTC++;
        }
    }
    detailStatus.append("<tr style=\"background-color:#cad3f1; font-style:bold\">");
    detailStatus.append("<td>TOTAL</td>");
    detailStatus.append("<td colspan=\"5\">").append(totalTC).append("</td>");
    detailStatus.append("</tr>");
    detailStatus.append("</tbody></table>");
    body = body.replace("%TAGTCDETAIL%", detailStatus.toString());
    // Subject replace.
    subject = subject.replace("%TAG%", tag);
    subject = subject.replace("%CAMPAIGN%", campaign);
    email = emailFactory.create(host, port, userName, password, true, subject, body, from, to, null);
    return email;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) Email(org.cerberus.service.email.entity.Email) HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) Tag(org.cerberus.crud.entity.Tag) HashMap(java.util.HashMap) Map(java.util.Map)

Example 38 with TestCaseExecution

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

the class ReadTestCaseExecution method findExecutionColumns.

// </editor-fold>
private AnswerItem findExecutionColumns(ApplicationContext appContext, HttpServletRequest request, String Tag) throws CerberusException, ParseException, JSONException {
    AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
    JSONObject jsonResponse = new JSONObject();
    AnswerList testCaseExecutionList = new AnswerList();
    AnswerList testCaseExecutionListInQueue = new AnswerList();
    testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);
    testCaseExecutionInQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);
    /**
     * Get list of execution by tag, env, country, browser
     */
    testCaseExecutionList = testCaseExecutionService.readDistinctEnvCoutnryBrowserByTag(Tag);
    List<TestCaseExecution> testCaseExecutions = testCaseExecutionList.getDataList();
    /**
     * Get list of Execution in Queue by Tag
     */
    testCaseExecutionListInQueue = testCaseExecutionInQueueService.readDistinctEnvCountryBrowserByTag(Tag);
    List<TestCaseExecutionQueue> testCaseExecutionsInQueue = testCaseExecutionListInQueue.getDataList();
    /**
     * Feed hash map with execution from the two list (to get only one by
     * test,testcase,country,env,browser)
     */
    LinkedHashMap<String, TestCaseExecution> testCaseExecutionsList = new LinkedHashMap();
    for (TestCaseExecution testCaseWithExecution : testCaseExecutions) {
        String key = testCaseWithExecution.getBrowser() + "_" + testCaseWithExecution.getCountry() + "_" + testCaseWithExecution.getEnvironment() + " " + testCaseWithExecution.getControlStatus();
        testCaseExecutionsList.put(key, testCaseWithExecution);
    }
    for (TestCaseExecutionQueue testCaseWithExecutionInQueue : testCaseExecutionsInQueue) {
        TestCaseExecution testCaseExecution = testCaseExecutionInQueueService.convertToTestCaseExecution(testCaseWithExecutionInQueue);
        String key = testCaseExecution.getBrowser() + "_" + testCaseExecution.getCountry() + "_" + testCaseExecution.getEnvironment() + "_" + testCaseExecution.getControlStatus();
        testCaseExecutionsList.put(key, testCaseExecution);
    }
    testCaseExecutions = new ArrayList<TestCaseExecution>(testCaseExecutionsList.values());
    JSONObject statusFilter = getStatusList(request);
    JSONObject countryFilter = getCountryList(request, appContext);
    LinkedHashMap<String, JSONObject> columnMap = new LinkedHashMap<String, JSONObject>();
    for (TestCaseExecution testCaseWithExecution : testCaseExecutions) {
        String controlStatus = testCaseWithExecution.getControlStatus();
        if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseWithExecution.getCountry()).equals("on")) {
            JSONObject column = new JSONObject();
            column.put("country", testCaseWithExecution.getCountry());
            column.put("environment", testCaseWithExecution.getEnvironment());
            column.put("browser", testCaseWithExecution.getBrowser());
            columnMap.put(testCaseWithExecution.getBrowser() + "_" + testCaseWithExecution.getCountry() + "_" + testCaseWithExecution.getEnvironment(), column);
        }
    }
    jsonResponse.put("Columns", columnMap.values());
    answer.setItem(jsonResponse);
    answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.JSONObject) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) ITestCaseExecutionQueueService(org.cerberus.crud.service.ITestCaseExecutionQueueService)

Example 39 with TestCaseExecution

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

the class ReadTestCaseExecution method hashExecution.

private List<TestCaseExecution> hashExecution(List<TestCaseExecution> testCaseExecutions, List<TestCaseExecutionQueue> testCaseExecutionsInQueue) throws ParseException {
    LinkedHashMap<String, TestCaseExecution> testCaseExecutionsList = new LinkedHashMap();
    SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    for (TestCaseExecution testCaseExecution : testCaseExecutions) {
        String key = testCaseExecution.getBrowser() + "_" + testCaseExecution.getCountry() + "_" + testCaseExecution.getEnvironment() + "_" + testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();
        testCaseExecutionsList.put(key, testCaseExecution);
    }
    for (TestCaseExecutionQueue testCaseExecutionInQueue : testCaseExecutionsInQueue) {
        TestCaseExecution testCaseExecution = testCaseExecutionInQueueService.convertToTestCaseExecution(testCaseExecutionInQueue);
        String key = testCaseExecution.getBrowser() + "_" + testCaseExecution.getCountry() + "_" + testCaseExecution.getEnvironment() + "_" + testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();
        if ((testCaseExecutionsList.containsKey(key) && testCaseExecutionsList.get(key).getStart() < testCaseExecutionInQueue.getRequestDate().getTime()) || !testCaseExecutionsList.containsKey(key)) {
            testCaseExecutionsList.put(key, testCaseExecution);
        }
    }
    List<TestCaseExecution> result = new ArrayList<TestCaseExecution>(testCaseExecutionsList.values());
    return result;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) ArrayList(java.util.ArrayList) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) SimpleDateFormat(java.text.SimpleDateFormat) LinkedHashMap(java.util.LinkedHashMap)

Example 40 with TestCaseExecution

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

the class ReadTestCaseExecutionByTag method generateTestCaseExecutionTable.

private JSONObject generateTestCaseExecutionTable(ApplicationContext appContext, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) {
    JSONObject testCaseExecutionTable = new JSONObject();
    LinkedHashMap<String, JSONObject> ttc = new LinkedHashMap<String, JSONObject>();
    LinkedHashMap<String, JSONObject> columnMap = new LinkedHashMap<String, JSONObject>();
    testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
    AnswerList testCaseLabelList = testCaseLabelService.readByTestTestCase(null, null);
    for (TestCaseExecution testCaseExecution : testCaseExecutions) {
        try {
            String controlStatus = testCaseExecution.getControlStatus();
            // We check is Country and status is inside the fitered values.
            if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {
                JSONObject executionJSON = testCaseExecutionToJSONObject(testCaseExecution);
                String execKey = testCaseExecution.getEnvironment() + " " + testCaseExecution.getCountry() + " " + testCaseExecution.getRobotDecli();
                String testCaseKey = testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();
                JSONObject execTab = new JSONObject();
                JSONObject ttcObject = new JSONObject();
                if (ttc.containsKey(testCaseKey)) {
                    // We add an execution entry into the testcase line.
                    ttcObject = ttc.get(testCaseKey);
                    execTab = ttcObject.getJSONObject("execTab");
                    execTab.put(execKey, executionJSON);
                    ttcObject.put("execTab", execTab);
                    Integer toto = (Integer) ttcObject.get("NbExecutionsTotal");
                    toto += testCaseExecution.getNbExecutions() - 1;
                    ttcObject.put("NbExecutionsTotal", toto);
                } else {
                    // We add a new testcase entry (with The current execution).
                    ttcObject.put("test", testCaseExecution.getTest());
                    ttcObject.put("testCase", testCaseExecution.getTestCase());
                    ttcObject.put("shortDesc", testCaseExecution.getDescription());
                    ttcObject.put("status", testCaseExecution.getStatus());
                    ttcObject.put("application", testCaseExecution.getApplication());
                    boolean testExist = ((testCaseExecution.getTestCaseObj() != null) && (testCaseExecution.getTestCaseObj().getTest() != null));
                    if (testExist) {
                        ttcObject.put("function", testCaseExecution.getTestCaseObj().getFunction());
                        ttcObject.put("priority", testCaseExecution.getTestCaseObj().getPriority());
                        ttcObject.put("comment", testCaseExecution.getTestCaseObj().getComment());
                        if ((testCaseExecution.getApplicationObj() != null) && (testCaseExecution.getApplicationObj().getBugTrackerUrl() != null) && (testCaseExecution.getTestCaseObj().getBugID() != null)) {
                            ttcObject.put("bugId", new JSONObject("{\"bugId\":\"" + testCaseExecution.getTestCaseObj().getBugID() + "\",\"bugTrackerUrl\":\"" + testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", testCaseExecution.getTestCaseObj().getBugID()) + "\"}"));
                        } else {
                            ttcObject.put("bugId", new JSONObject("{\"bugId\":\"\",\"bugTrackerUrl\":\"\"}"));
                        }
                    } else {
                        ttcObject.put("function", "");
                        ttcObject.put("priority", 0);
                        ttcObject.put("comment", "");
                        ttcObject.put("bugId", new JSONObject("{\"bugId\":\"\",\"bugTrackerUrl\":\"\"}"));
                    }
                    // Flag that report if test case still exist.
                    ttcObject.put("testExist", testExist);
                    // Adding nb of execution on retry.
                    ttcObject.put("NbExecutionsTotal", (testCaseExecution.getNbExecutions() - 1));
                    execTab.put(execKey, executionJSON);
                    ttcObject.put("execTab", execTab);
                    /**
                     * Iterate on the label retrieved and generate HashMap
                     * based on the key Test_TestCase
                     */
                    LinkedHashMap<String, JSONArray> testCaseWithLabel = new LinkedHashMap();
                    for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList.getDataList()) {
                        if (Label.TYPE_STICKER.equals(label.getLabel().getType())) {
                            // We only display STICKER Type Label in Reporting By Tag Page..
                            String key = label.getTest() + "_" + label.getTestcase();
                            JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());
                            if (testCaseWithLabel.containsKey(key)) {
                                testCaseWithLabel.get(key).put(jo);
                            } else {
                                testCaseWithLabel.put(key, new JSONArray().put(jo));
                            }
                        }
                    }
                    ttcObject.put("labels", testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase()));
                }
                ttc.put(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase(), ttcObject);
                JSONObject column = new JSONObject();
                column.put("country", testCaseExecution.getCountry());
                column.put("environment", testCaseExecution.getEnvironment());
                column.put("robotDecli", testCaseExecution.getRobotDecli());
                columnMap.put(testCaseExecution.getRobotDecli() + "_" + testCaseExecution.getCountry() + "_" + testCaseExecution.getEnvironment(), column);
            }
            Map<String, JSONObject> treeMap = new TreeMap<String, JSONObject>(columnMap);
            testCaseExecutionTable.put("tableContent", ttc.values());
            testCaseExecutionTable.put("iTotalRecords", ttc.size());
            testCaseExecutionTable.put("iTotalDisplayRecords", ttc.size());
            testCaseExecutionTable.put("tableColumns", treeMap.values());
        } catch (JSONException ex) {
            LOG.error("Error on generateTestCaseExecutionTable : " + ex);
        } catch (Exception ex) {
            LOG.error("Error on generateTestCaseExecutionTable : " + ex);
        }
    }
    return testCaseExecutionTable;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) TreeMap(java.util.TreeMap) ServletException(javax.servlet.ServletException) JSONException(org.json.JSONException) ParseException(java.text.ParseException) IOException(java.io.IOException) CerberusException(org.cerberus.exception.CerberusException) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) ITestCaseLabelService(org.cerberus.crud.service.ITestCaseLabelService)

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