use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class UpdateTestCaseMass 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_ERROR_UNEXPECTED);
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);
ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
/**
* 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
String function = request.getParameter("massFunction");
String status = request.getParameter("massStatus");
String application = request.getParameter("massApplication");
// Parameter that we cannot secure as we need the html --> We DECODE them
String[] myTest = request.getParameterValues("test");
String[] myTestCase = request.getParameterValues("testcase");
StringBuilder output_message = new StringBuilder();
int massErrorCounter = 0;
int tcCounter = 0;
for (String myTest1 : myTest) {
String cur_test = myTest1;
String cur_testcase = myTestCase[tcCounter];
/**
* All data seems cleans so we can call the services.
*/
AnswerItem resp = testCaseService.readByKey(cur_test, cur_testcase);
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%", "Update").replace("%REASON%", "TestCase does not exist."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(msg.getDescription());
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
TestCase tcData = (TestCase) resp.getItem();
/**
* Before updating, we check that the old entry can be modified.
* If old entry point to a build/revision that already been
* deployed, we cannot update it.
*/
if (!testCaseService.hasPermissionsUpdate(tcData, request)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).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."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(msg.getDescription());
} else // We test that at least a data to update has been defined.
if ((function != null) || (status != null) || (application != null)) {
tcData.setUsrModif(request.getRemoteUser());
tcData.setFunction(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(function, tcData.getFunction(), charset));
tcData.setStatus(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(status, tcData.getStatus(), charset));
tcData.setApplication(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(application, tcData.getApplication(), charset));
ans = testCaseService.update(tcData.getTest(), tcData.getTestCase(), tcData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
logEventService.createForPrivateCalls("/UpdateTestCaseMass", "UPDATE", "Updated TestCase : ['" + tcData.getTest() + "'|'" + tcData.getTestCase() + "']", request);
} else {
massErrorCounter++;
output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(ans.getResultMessage().getDescription());
}
}
}
tcCounter++;
}
if (myTest.length > 1) {
if (massErrorCounter == myTest.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 + " objects(s) out of " + myTest.length + " failed to update 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 + " objects(s) out of " + myTest.length + " failed to update 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 " + myTest.length + " object(s) updated successfuly.");
ans.setResultMessage(msg);
}
logEventService.createForPrivateCalls("/UpdateTestCaseMass", "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.TestCase in project cerberus-source by cerberustesting.
the class GetTestCaseForTest method doGet.
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
String testName = policy.sanitize(httpServletRequest.getParameter("test"));
String system = policy.sanitize(httpServletRequest.getParameter("system"));
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseService testService = appContext.getBean(ITestCaseService.class);
JSONArray array = new JSONArray();
JSONObject jsonObject = new JSONObject();
try {
List<TestCase> tcaseList;
if (system == null) {
tcaseList = testService.findTestCaseByTest(testName);
} else {
tcaseList = testService.findTestCaseActiveAutomatedBySystem(testName, system);
}
for (TestCase list : tcaseList) {
JSONObject testCase = new JSONObject();
testCase.put("testCase", list.getTestCase());
testCase.put("description", list.getTestCase().concat(" [").concat(list.getApplication()).concat("] : ").concat(list.getDescription()));
testCase.put("application", list.getApplication());
array.put(testCase);
}
jsonObject.put("testCaseList", array);
httpServletResponse.setContentType("application/json");
httpServletResponse.getWriter().print(jsonObject.toString());
} catch (JSONException exception) {
LOG.warn(exception.toString());
}
}
use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class ReadTestCase method findTestCaseByTestTestCase.
private AnswerItem findTestCaseByTestTestCase(String test, String testCase, ApplicationContext appContext, HttpServletRequest request) throws JSONException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
testCaseService = appContext.getBean(ITestCaseService.class);
testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
// finds the project
AnswerItem answerTestCase = testCaseService.readByKey(test, testCase);
if (answerTestCase.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerTestCase.getItem() != null) {
// if the service returns an OK message then we can get the item and convert it to JSONformat
TestCase tc = (TestCase) answerTestCase.getItem();
JSONObject response = convertToJSONObject(tc);
// Country List feed.
JSONArray countryArray = new JSONArray();
AnswerList answerTestCaseCountryList = testCaseCountryService.readByTestTestCase(null, test, testCase);
for (TestCaseCountry country : (List<TestCaseCountry>) answerTestCaseCountryList.getDataList()) {
countryArray.put(convertToJSONObject(country));
}
response.put("countryList", countryArray);
// Label List feed.
JSONArray labelArray = new JSONArray();
AnswerList answerTestCaseLabelList = testCaseLabelService.readByTestTestCase(test, testCase);
for (TestCaseLabel label : (List<TestCaseLabel>) answerTestCaseLabelList.getDataList()) {
labelArray.put(convertToJSONObject(label));
}
response.put("labelList", labelArray);
object.put("contentTable", response);
object.put("hasPermissionsUpdate", testCaseService.hasPermissionsUpdate(tc, request));
}
item.setItem(object);
item.setResultMessage(answerTestCase.getResultMessage());
return item;
}
use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class ReadTestCase method findTestCaseByVarious.
private AnswerItem findTestCaseByVarious(ApplicationContext appContext, HttpServletRequest request) throws JSONException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
JSONArray dataArray = new JSONArray();
String[] test = request.getParameterValues("test");
String[] idProject = request.getParameterValues("project");
String[] app = request.getParameterValues("application");
String[] creator = request.getParameterValues("creator");
String[] implementer = request.getParameterValues("implementer");
String[] system = request.getParameterValues("system");
String[] testBattery = request.getParameterValues("testBattery");
String[] campaign = request.getParameterValues("campaign");
String[] priority = request.getParameterValues("priority");
String[] group = request.getParameterValues("group");
String[] status = request.getParameterValues("status");
String[] labelid = request.getParameterValues("labelid");
int length = ParameterParserUtil.parseIntegerParam(request.getParameter("length"), -1);
testCaseService = appContext.getBean(ITestCaseService.class);
AnswerList answer = testCaseService.readByVarious(test, idProject, app, creator, implementer, system, campaign, labelid, priority, group, status, length);
if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
for (TestCase tc : (List<TestCase>) answer.getDataList()) {
dataArray.put(convertToJSONObject(tc));
}
}
object.put("contentTable", dataArray);
item.setItem(object);
item.setResultMessage(answer.getResultMessage());
return item;
}
use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class ReadTestCase method findTestCaseByCampaign.
private AnswerItem findTestCaseByCampaign(ApplicationContext appContext, String campaign) throws JSONException {
AnswerItem answer = new AnswerItem();
JSONObject jsonResponse = new JSONObject();
JSONArray dataArray = new JSONArray();
String[] campaignList = new String[1];
campaignList[0] = campaign;
testCaseService = appContext.getBean(ITestCaseService.class);
final AnswerItem<Map<String, List<String>>> parsedCampaignParameters = campaignParameterService.parseParametersByCampaign(campaign);
List<String> countries = parsedCampaignParameters.getItem().get(CampaignParameter.COUNTRY_PARAMETER);
AnswerItem<List<TestCase>> resp = null;
if (countries != null && !countries.isEmpty()) {
resp = testCaseService.findTestCaseByCampaignNameAndCountries(campaign, countries.toArray(new String[countries.size()]));
} else {
resp = testCaseService.findTestCaseByCampaignNameAndCountries(campaign, null);
}
if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
for (Object c : resp.getItem()) {
TestCase cc = (TestCase) c;
dataArray.put(convertToJSONObject(cc));
}
}
jsonResponse.put("contentTable", dataArray);
answer.setItem(jsonResponse);
answer.setResultMessage(resp.getResultMessage());
return answer;
}
Aggregations