use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class DeleteTestCaseLabel 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, JSONException {
JSONObject jsonResponse = new JSONObject();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ILogEventService logEventService = appContext.getBean(LogEventService.class);
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
String charset = request.getCharacterEncoding();
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
// Parameter that needs to be secured --> We SECURE+DECODE them
// Parameter that we cannot secure as we need the html --> We DECODE them
Integer myIdInt = 0;
String[] myLabelIdList = request.getParameterValues("labelid");
String[] myTestList = request.getParameterValues("test");
String[] myTestCaseList = request.getParameterValues("testcase");
if ((myTestList.length == 0) || (myTestCaseList.length == 0) || (myLabelIdList.length == 0)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Create").replace("%REASON%", "Missing Parameter (either test, testcase or labelid)."));
ans.setResultMessage(msg);
} else if (myTestList.length != myTestCaseList.length) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Create").replace("%REASON%", "Number of Test does not match number of testcase."));
ans.setResultMessage(msg);
}
StringBuilder output_message = new StringBuilder();
int massErrorCounter = 0;
for (int i = 0; i < myLabelIdList.length; i++) {
String myLabelId = myLabelIdList[i];
myIdInt = 0;
boolean label_error = true;
try {
if (myLabelId != null && !myLabelId.equals("")) {
myIdInt = Integer.valueOf(policy.sanitize(myLabelId));
label_error = false;
}
} catch (Exception ex) {
label_error = true;
}
/**
* Checking all constrains before calling the services.
*/
if (label_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "Could not manage to convert labelid to an integer value or labelid is missing."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(myLabelId).append(" - ").append(msg.getDescription());
} else {
/**
* All data seems cleans so we can call the services.
*/
ILabelService labelService = appContext.getBean(ILabelService.class);
IFactoryTestCaseLabel factoryTestCaseLabel = appContext.getBean(IFactoryTestCaseLabel.class);
ITestCaseLabelService testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
AnswerItem resp = labelService.readByKey(myIdInt);
if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
/**
* Object could not be found. We stop here and report the
* error.
*/
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Delete").replace("%REASON%", "Label does not exist."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>labelid : ").append(myLabelId).append(" - ").append(msg.getDescription());
} else {
for (int j = 0; j < myTestList.length; j++) {
/**
* The service was able to perform the query and confirm
* the object exist, then we can create it.
*/
resp = testCaseLabelService.readByKey(myTestList[j], myTestCaseList[j], myIdInt);
if ((resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
TestCaseLabel tcLabel = (TestCaseLabel) resp.getItem();
ans = testCaseLabelService.delete(tcLabel);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
logEventService.createForPrivateCalls("/DeleteTestCaseLabel", "DELETE", "Deleted TestCaseLabel : ['" + myIdInt + "'|'" + myTestList[j] + "'|'" + myTestCaseList[j] + "']", request);
} else {
massErrorCounter++;
output_message.append("<br>Label : ").append(myLabelId).append(" Test : '").append(myTestList[j]).append("' TestCase : '").append(myTestCaseList[j]).append("' - ").append(ans.getResultMessage().getDescription());
}
}
}
}
}
}
if (myTestList.length > 1) {
if (massErrorCounter == myTestList.length) {
// All updates are in ERROR.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " label links(s) out of " + (myTestList.length * myLabelIdList.length) + " failed to be deleted due to an issue.<br>") + output_message.toString());
ans.setResultMessage(msg);
} else if (massErrorCounter > 0) {
// At least 1 update in error
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " label links(s) out of " + (myTestList.length * myLabelIdList.length) + " failed to be deleted due to an issue.<br>") + output_message.toString());
ans.setResultMessage(msg);
} else {
// No error detected.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update") + "\n\nAll " + (myTestList.length * myLabelIdList.length) + " label links(s) deleted successfuly.");
ans.setResultMessage(msg);
}
logEventService.createForPrivateCalls("/DeleteTestCaseLabel", "MASSUPDATE", msg.getDescription(), request);
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", ans.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class DuplicateTestCase method processRequest.
// </editor-fold>
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException, CerberusException {
JSONObject jsonResponse = new JSONObject();
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");
String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("testCase"), "");
String originalTest = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTest"), "");
String originalTestCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTestCase"), null);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(test) || StringUtil.isNullOrEmpty(testCase) || StringUtil.isNullOrEmpty(originalTest) || originalTestCase != null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case").replace("%OPERATION%", "Duplicate").replace("%REASON%", "mandatory fields are missing."));
ans.setResultMessage(msg);
} else {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
ITestCaseCountryService testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);
ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);
ITestCaseStepActionService testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
ITestCaseStepActionControlService testCaseStepActionControlService = appContext.getBean(ITestCaseStepActionControlService.class);
ITestCaseLabelService testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
AnswerItem originalTestAI = testCaseService.readByKey(originalTest, originalTestCase);
AnswerItem targetTestAI = testCaseService.readByKey(test, testCase);
TestCase originalTC = (TestCase) originalTestAI.getItem();
TestCase targetTC = (TestCase) targetTestAI.getItem();
if (!(originalTestAI.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && originalTestAI.getItem() != null)) {
/**
* Object could not be found. We stop here and report the error.
*/
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "TestCase does not exist."));
ans.setResultMessage(msg);
} else /**
* The service was able to perform the query and confirm the object
* exist, then we can update it.
*/
if (!request.isUserInRole("Test")) {
// We cannot update the testcase if the user is not at least in Test role.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "Not enought privilege to duplicate the testcase. You must belong to Test Privilege."));
ans.setResultMessage(msg);
} else if (targetTC != null) {
// If target Test Case already exists.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "The test case you try to create already exists. Please define a test/testcase that is not already existing."));
ans.setResultMessage(msg);
} else {
getInfo(request, originalTC);
// Update object with new testcase id and insert it in db
originalTC.setTest(test);
originalTC.setTestCase(testCase);
ans = testCaseService.create(originalTC);
List<TestCaseCountry> countryList = new ArrayList();
countryList = testCaseCountryService.findTestCaseCountryByTestTestCase(originalTest, originalTestCase);
boolean success = true;
if (!countryList.isEmpty()) {
ans = testCaseCountryService.duplicateList(countryList, test, testCase);
}
// List<TestCaseCountry> countryList = getCountryList(test, testCase, request);
// boolean success = false;
// if (countryList.isEmpty()) {
// success = true;
// } else {
// success = testCaseCountryService.insertListTestCaseCountry(countryList);
// }
List<TestCaseCountryProperties> tccpList = new ArrayList();
if (!countryList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
tccpList = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCase(originalTest, originalTestCase);
if (!tccpList.isEmpty()) {
ans = testCaseCountryPropertiesService.duplicateList(tccpList, test, testCase);
}
}
List<TestCaseStep> tcsList = new ArrayList();
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
tcsList = testCaseStepService.getListOfSteps(originalTest, originalTestCase);
if (!tcsList.isEmpty()) {
ans = testCaseStepService.duplicateList(tcsList, test, testCase);
}
}
List<TestCaseStepAction> tcsaList = new ArrayList();
if (!tcsList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
tcsaList = testCaseStepActionService.findTestCaseStepActionbyTestTestCase(originalTest, originalTestCase);
if (!tcsaList.isEmpty()) {
ans = testCaseStepActionService.duplicateList(tcsaList, test, testCase);
}
}
if (!tcsList.isEmpty() && !tcsaList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
List<TestCaseStepActionControl> tcsacList = testCaseStepActionControlService.findControlByTestTestCase(originalTest, originalTestCase);
if (!tcsacList.isEmpty()) {
ans = testCaseStepActionControlService.duplicateList(tcsacList, test, testCase);
}
}
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
List<TestCaseLabel> tclList = testCaseLabelService.readByTestTestCase(originalTest, originalTestCase).getDataList();
if (!tclList.isEmpty()) {
ans = testCaseLabelService.duplicateList(tclList, test, testCase);
}
}
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate"));
ans.setResultMessage(msg);
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/DuplicateTestCase", "CREATE", "Create testcase : ['" + test + "'|'" + testCase + "']", request);
}
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", ans.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.entity.TestCaseLabel 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;
}
use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class UpdateTestCase method getLabelListFromRequest.
private List<TestCaseLabel> getLabelListFromRequest(HttpServletRequest request, ApplicationContext appContext, String test, String testCase, JSONArray json) throws CerberusException, JSONException, UnsupportedEncodingException {
List<TestCaseLabel> labelList = new ArrayList();
for (int i = 0; i < json.length(); i++) {
JSONObject objectJson = json.getJSONObject(i);
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
boolean delete = objectJson.getBoolean("toDelete");
Integer labelId = objectJson.getInt("labelId");
Timestamp creationDate = new Timestamp(new Date().getTime());
if (!delete) {
labelList.add(testCaseLabelFactory.create(0, test, testCase, labelId, request.getRemoteUser(), creationDate, request.getRemoteUser(), creationDate, null));
}
}
return labelList;
}
use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class UpdateTestCase 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
* @throws org.json.JSONException
* @throws org.cerberus.exception.CerberusException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException, CerberusException {
JSONObject jsonResponse = new JSONObject();
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");
String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("testCase"), null);
String keyTest = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTest"), "");
String keyTestCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTestCase"), null);
// Prepare the final answer.
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
/**
* Checking all constrains before calling the services.
*/
if ((StringUtil.isNullOrEmpty(test)) || (StringUtil.isNullOrEmpty(testCase)) || (StringUtil.isNullOrEmpty(keyTest)) || (StringUtil.isNullOrEmpty(keyTestCase))) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case").replace("%OPERATION%", "Update").replace("%REASON%", "mandatory fields (test, testcase) are missing."));
finalAnswer.setResultMessage(msg);
} else {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
testCaseService = appContext.getBean(ITestCaseService.class);
testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
testCaseLabelFactory = appContext.getBean(IFactoryTestCaseLabel.class);
testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
testCaseCountryFactory = appContext.getBean(IFactoryTestCaseCountry.class);
AnswerItem resp = testCaseService.readByKey(keyTest, keyTestCase);
TestCase tc = (TestCase) resp.getItem();
if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
/**
* Object could not be found. We stop here and report the error.
*/
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Update").replace("%REASON%", "TestCase does not exist."));
finalAnswer.setResultMessage(msg);
} else /**
* The service was able to perform the query and confirm the object
* exist, then we can update it.
*/
{
if (!testCaseService.hasPermissionsUpdate(tc, request)) {
// We cannot update the testcase if the user is not at least in Test role.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Update").replace("%REASON%", "Not enought privilege to update the testcase. You must belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));
finalAnswer.setResultMessage(msg);
} else {
tc = getTestCaseFromRequest(request, tc);
tc.setTestCaseVersion(tc.getTestCaseVersion() + 1);
// Update testcase
ans = testCaseService.update(keyTest, keyTestCase, tc);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateTestCase", "UPDATE", "Update testcase : ['" + keyTest + "'|'" + keyTestCase + "'] " + "version : " + tc.getTestCaseVersion(), request);
// Update labels
if (request.getParameter("labelList") != null) {
JSONArray objLabelArray = new JSONArray(request.getParameter("labelList"));
List<TestCaseLabel> labelList = new ArrayList();
labelList = getLabelListFromRequest(request, appContext, test, testCase, objLabelArray);
// Update the Database with the new list.
ans = testCaseLabelService.compareListAndUpdateInsertDeleteElements(tc.getTest(), tc.getTestCase(), labelList);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
// Update Countries
if (request.getParameter("countryList") != null) {
JSONArray objCountryArray = new JSONArray(request.getParameter("countryList"));
List<TestCaseCountry> tccList = new ArrayList();
tccList = getCountryListFromRequest(request, appContext, test, testCase, objCountryArray);
// Update the Database with the new list.
ans = testCaseCountryService.compareListAndUpdateInsertDeleteElements(tc.getTest(), tc.getTestCase(), tccList);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
}
}
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
Aggregations