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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations