How to use processRequest method of org.cerberus.servlet.crud.testexecution.ReadExecutionStat class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.ReadExecutionStat.processRequest

Source:ReadExecutionStat.java Github

copy

Full Screen

...83 * @throws ServletException if a servlet-specific error occurs84 * @throws IOException if an I/O error occurs85 * @throws org.cerberus.exception.CerberusException86 */87 protected void processRequest(HttpServletRequest request, HttpServletResponse response)88 throws ServletException, IOException, CerberusException {89 String echo = request.getParameter("sEcho");90 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());91 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);92 response.setContentType("application/json");93 response.setCharacterEncoding("utf8");94 // Calling Servlet Transversal Util.95 ServletUtil.servletStart(request);96 // Default message to unexpected error.97 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);98 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));99 /**100 * Parsing and securing all required parameters.101 */102 factoryTestCase = appContext.getBean(IFactoryTestCase.class);103 List<String> system = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("system"), new ArrayList<String>(), "UTF8");104 String from = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("from"), null, "UTF8");105 String to = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("to"), null, "UTF8");106 LOG.debug("from : " + from);107 LOG.debug("to : " + to);108 Date fromD;109 try {110 TimeZone tz = TimeZone.getTimeZone("UTC");111 DateFormat df = new SimpleDateFormat(DATE_FORMAT);112 df.setTimeZone(tz);113 fromD = df.parse(from);114 } catch (ParseException ex) {115 fromD = Date.from(ZonedDateTime.now().minusMonths(1).toInstant());116 LOG.debug("Exception when parsing date", ex);117 }118 Date toD;119 try {120 TimeZone tz = TimeZone.getTimeZone("UTC");121 DateFormat df = new SimpleDateFormat(DATE_FORMAT);122 df.setTimeZone(tz);123 toD = df.parse(to);124 } catch (ParseException ex) {125 toD = Date.from(ZonedDateTime.now().toInstant());126 LOG.debug("Exception when parsing date", ex);127 }128 LOG.debug("from : " + fromD);129 LOG.debug("to : " + toD);130 List<TestCase> ltc = new ArrayList<>();131 List<String> test = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tests"), new ArrayList<String>(), "UTF8");132 List<String> testCase = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("testcases"), new ArrayList<String>(), "UTF8");133 int i = 0;134 for (String string : test) {135 ltc.add(factoryTestCase.create(string, testCase.get(i++)));136 }137 if (ltc.size() <= 0) {138 ltc.add(factoryTestCase.create("", ""));139 }140 List<String> parties = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("parties"), Arrays.asList("total"), "UTF8");141 List<String> types = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("types"), Arrays.asList("total"), "UTF8");142 List<String> units = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("units"), Arrays.asList("request", "totalsize"), "UTF8");143 List<String> countries = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("countries"), new ArrayList<String>(), "UTF8");144 Boolean countriesDefined = (request.getParameterValues("countries") != null);145 List<String> environments = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("environments"), new ArrayList<String>(), "UTF8");146 Boolean environmentsDefined = (request.getParameterValues("environments") != null);147 List<String> robotDeclis = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("robotDeclis"), new ArrayList<String>(), "UTF8");148 Boolean robotDeclisDefined = (request.getParameterValues("robotDeclis") != null);149 // Init Answer with potencial error from Parsing parameter.150 AnswerItem<JSONObject> answer = new AnswerItem<>(msg);151 // Map of countries, Environments and RobotDeclis (Boolean contains true if requested to be displayed).152 HashMap<String, Boolean> countryMap = new HashMap<>();153 HashMap<String, Boolean> environmentMap = new HashMap<>();154 HashMap<String, Boolean> robotDecliMap = new HashMap<>();155 HashMap<String, Boolean> systemMap = new HashMap<>();156 HashMap<String, TestCase> testCaseMap = new HashMap<>();157 HashMap<String, Boolean> applicationMap = new HashMap<>();158 testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);159 List<TestCaseExecution> exeL = testCaseExecutionService.readByCriteria(null, null, null, null, ltc, fromD, toD);160 for (TestCaseExecution exe : exeL) {161 countryMap.put(exe.getCountry(), countries.contains(exe.getCountry()));162 environmentMap.put(exe.getEnvironment(), environments.contains(exe.getEnvironment()));163 robotDecliMap.put(exe.getRobotDecli(), robotDeclis.contains(exe.getRobotDecli()));164 testCaseMap.put(exe.getTest() + "/\\" + exe.getTestCase(), factoryTestCase.create(exe.getTest(), exe.getTestCase()));165 systemMap.put(exe.getSystem(), true);166 applicationMap.put(exe.getApplication(), true);167 }168 LOG.debug(countryMap);169 LOG.debug(environmentMap);170 LOG.debug(robotDecliMap);171 try {172 JSONObject jsonResponse = new JSONObject();173 testCaseExecutionHttpStatService = appContext.getBean(ITestCaseExecutionHttpStatService.class);174 answer = testCaseExecutionHttpStatService.readByCriteria("OK", ltc, fromD, toD, system, countries, environments, robotDeclis, parties, types, units);175 jsonResponse = (JSONObject) answer.getItem();176 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());177 jsonResponse.put("message", answer.getResultMessage().getDescription());178 jsonResponse.put("sEcho", echo);179 JSONObject jsonResponse1 = new JSONObject();180 answer = findExeStatList(appContext, request, exeL, countries, environments, robotDeclis);181 jsonResponse1 = (JSONObject) answer.getItem();182 jsonResponse.put("datasetExeTime", jsonResponse1.getJSONArray("curvesTime"));183 jsonResponse.put("datasetExeStatusNb", jsonResponse1.getJSONArray("curvesNb"));184 jsonResponse.put("datasetExeStatusNbDates", jsonResponse1.getJSONArray("curvesDatesNb"));185 JSONObject objectdist = getAllDistinct(countryMap, systemMap, testCaseMap, applicationMap, environmentMap, robotDecliMap, countriesDefined, environmentsDefined, robotDeclisDefined);186 objectdist.put("units", jsonResponse.getJSONArray("distinctUnits"));187 objectdist.put("types", jsonResponse.getJSONArray("distinctTypes"));188 objectdist.put("parties", jsonResponse.getJSONArray("distinctParties"));189 jsonResponse.remove("distinctUnits");190 jsonResponse.remove("distinctTypes");191 jsonResponse.remove("distinctParties");192 jsonResponse.put("distinct", objectdist);193 response.getWriter().print(jsonResponse.toString());194 } catch (JSONException e) {195 LOG.warn(e, e);196 //returns a default error message with the json format that is able to be parsed by the client-side197 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());198 }199 }200 private AnswerItem<JSONObject> findExeStatList(ApplicationContext appContext, HttpServletRequest request,201 List<TestCaseExecution> exeList,202 List<String> countries, List<String> environments, List<String> robotDeclis) throws JSONException {203 AnswerItem<JSONObject> item = new AnswerItem<>();204 JSONObject object = new JSONObject();205 testCaseExecutionHttpStatService = appContext.getBean(ITestCaseExecutionHttpStatService.class);206 applicationService = appContext.getBean(IApplicationService.class);207 testCaseService = appContext.getBean(ITestCaseService.class);208 factoryTestCase = appContext.getBean(IFactoryTestCase.class);209 HashMap<String, JSONArray> curveMap = new HashMap<>();210 HashMap<String, JSONObject> curveObjMap = new HashMap<>();211 String curveKey = "";212 JSONArray curArray = new JSONArray();213 JSONObject curveObj = new JSONObject();214 JSONObject pointObj = new JSONObject();215 HashMap<String, JSONObject> curveStatusObjMap = new HashMap<>();216 HashMap<String, Boolean> curveDateMap = new HashMap<>();217 HashMap<String, Integer> curveDateStatusMap = new HashMap<>();218 String curveKeyStatus = "";219 JSONObject curveStatObj = new JSONObject();220 for (TestCaseExecution exeCur : exeList) {221 if ((countries.isEmpty() || countries.contains(exeCur.getCountry()))222 && (environments.isEmpty() || environments.contains(exeCur.getEnvironment()))223 && (robotDeclis.isEmpty() || robotDeclis.contains(exeCur.getRobotDecli()))) {224 /**225 * Curves of testcase response time.226 */227 curveKey = exeCur.getTest() + "|" + exeCur.getTestCase() + "|" + exeCur.getCountry() + "|" + exeCur.getEnvironment() + "|" + exeCur.getRobotDecli() + "|";228 long y = 0;229 if (!exeCur.getControlStatus().equalsIgnoreCase("PE")) {230 y = exeCur.getEnd() - exeCur.getStart();231 pointObj = new JSONObject();232 Date d = new Date(exeCur.getStart());233 TimeZone tz = TimeZone.getTimeZone("UTC");234 DateFormat df = new SimpleDateFormat(DATE_FORMAT);235 df.setTimeZone(tz);236 pointObj.put("x", df.format(d));237 pointObj.put("y", y);238 pointObj.put("exe", exeCur.getId());239 pointObj.put("exeControlStatus", exeCur.getControlStatus());240 if (curveMap.containsKey(curveKey)) {241 curArray = curveMap.get(curveKey);242 } else {243 curArray = new JSONArray();244 curveObj = new JSONObject();245 curveObj.put("key", curveKey);246 TestCase a = factoryTestCase.create(exeCur.getTest(), exeCur.getTestCase());247 try {248 a = testCaseService.convert(testCaseService.readByKey(exeCur.getTest(), exeCur.getTestCase()));249 curveObj.put("testcase", a.toJson());250 } catch (CerberusException ex) {251 LOG.error("Exception when getting TestCase details", ex);252 }253 curveObj.put("country", exeCur.getCountry());254 curveObj.put("environment", exeCur.getEnvironment());255 curveObj.put("robotdecli", exeCur.getRobotDecli());256 curveObj.put("system", exeCur.getSystem());257 curveObj.put("application", exeCur.getApplication());258 curveObj.put("unit", "testduration");259 curveObjMap.put(curveKey, curveObj);260 }261 curArray.put(pointObj);262 curveMap.put(curveKey, curArray);263 }264 /**265 * Bar Charts per control status.266 */267 curveKeyStatus = exeCur.getControlStatus();268 Date d = new Date(exeCur.getStart());269 TimeZone tz = TimeZone.getTimeZone("UTC");270 DateFormat df = new SimpleDateFormat(DATE_FORMAT_DAY);271 df.setTimeZone(tz);272 String dday = df.format(d);273 curveDateMap.put(dday, false);274 String keyDateStatus = curveKeyStatus + "-" + dday;275 if (curveDateStatusMap.containsKey(keyDateStatus)) {276 curveDateStatusMap.put(keyDateStatus, curveDateStatusMap.get(keyDateStatus) + 1);277 } else {278 curveDateStatusMap.put(keyDateStatus, 1);279 }280 if (!curveStatusObjMap.containsKey(curveKeyStatus)) {281 curveStatObj = new JSONObject();282 curveStatObj.put("key", curveKeyStatus);283 curveStatObj.put("unit", "nbExe");284 curveStatusObjMap.put(curveKeyStatus, curveStatObj);285 }286 }287 }288 /**289 * Feed Curves of testcase response time to JSON.290 */291 JSONArray curvesArray = new JSONArray();292 for (Map.Entry<String, JSONObject> entry : curveObjMap.entrySet()) {293 String key = entry.getKey();294 JSONObject val = entry.getValue();295 JSONObject localcur = new JSONObject();296 localcur.put("key", val);297 localcur.put("points", curveMap.get(key));298 curvesArray.put(localcur);299 }300 object.put("curvesTime", curvesArray);301 /**302 * Bar Charts per control status to JSON.303 */304 curvesArray = new JSONArray();305 for (Map.Entry<String, Boolean> entry : curveDateMap.entrySet()) {306 curvesArray.put(entry.getKey());307 }308 object.put("curvesDatesNb", curvesArray);309 curvesArray = new JSONArray();310 for (Map.Entry<String, JSONObject> entry : curveStatusObjMap.entrySet()) {311 String key = entry.getKey();312 JSONObject val = entry.getValue();313 JSONArray valArray = new JSONArray();314 for (Map.Entry<String, Boolean> entry1 : curveDateMap.entrySet()) {315 String key1 = entry1.getKey(); // Date316 if (curveDateStatusMap.containsKey(key + "-" + key1)) {317 valArray.put(curveDateStatusMap.get(key + "-" + key1));318 } else {319 valArray.put(0);320 }321 }322 JSONObject localcur = new JSONObject();323 localcur.put("key", val);324 localcur.put("points", valArray);325 curvesArray.put(localcur);326 }327 object.put("curvesNb", curvesArray);328 item.setItem(object);329 return item;330 }331 private JSONObject getAllDistinct(332 HashMap<String, Boolean> countryMap,333 HashMap<String, Boolean> systemMap,334 HashMap<String, TestCase> testCaseMap,335 HashMap<String, Boolean> applicationMap,336 HashMap<String, Boolean> environmentMap,337 HashMap<String, Boolean> robotDecliMap,338 Boolean countriesDefined,339 Boolean environmentsDefined,340 Boolean robotDeclisDefined) throws JSONException {341 JSONObject objectdist = new JSONObject();342 JSONArray objectSdinst = new JSONArray();343 for (Map.Entry<String, Boolean> sys : systemMap.entrySet()) {344 String key = sys.getKey();345 JSONObject objectcount = new JSONObject();346 objectcount.put("name", key);347 objectcount.put("hasData", systemMap.containsKey(key));348 objectSdinst.put(objectcount);349 }350 objectdist.put("systems", objectSdinst);351 JSONArray objectTCdinst = new JSONArray();352 for (Map.Entry<String, TestCase> env : testCaseMap.entrySet()) {353 try {354 String key = env.getKey();355 TestCase tc = env.getValue();356 TestCase a = testCaseService.convert(testCaseService.readByKey(tc.getTest(), tc.getTestCase()));357 objectTCdinst.put(a.toJson());358 } catch (CerberusException ex) {359 LOG.error("Exception when getting TestCase.", ex);360 }361 }362 objectdist.put("testCases", objectTCdinst);363 JSONArray objectAdinst = new JSONArray();364 for (Map.Entry<String, Boolean> app : applicationMap.entrySet()) {365 try {366 String key = app.getKey();367 Application a = applicationService.convert(applicationService.readByKey(key));368 objectAdinst.put(convertApplicationToJSONObject(a));369 } catch (CerberusException ex) {370 LOG.error("Exception when getting Application.", ex);371 }372 }373 objectdist.put("applications", objectAdinst);374 JSONArray objectCdinst = new JSONArray();375 for (Map.Entry<String, Boolean> country : countryMap.entrySet()) {376 String key = country.getKey();377 JSONObject objectcount = new JSONObject();378 objectcount.put("name", key);379 objectcount.put("hasData", countryMap.containsKey(key));380 if (countriesDefined) {381 objectcount.put("isRequested", countryMap.get(key));382 } else {383 objectcount.put("isRequested", true);384 }385 objectCdinst.put(objectcount);386 }387 objectdist.put("countries", objectCdinst);388 JSONArray objectdinst = new JSONArray();389 for (Map.Entry<String, Boolean> env : environmentMap.entrySet()) {390 String key = env.getKey();391 JSONObject objectcount = new JSONObject();392 objectcount.put("name", key);393 objectcount.put("hasData", environmentMap.containsKey(key));394 if (environmentsDefined) {395 objectcount.put("isRequested", environmentMap.get(key));396 } else {397 objectcount.put("isRequested", true);398 }399 objectdinst.put(objectcount);400 }401 objectdist.put("environments", objectdinst);402 objectdinst = new JSONArray();403 for (Map.Entry<String, Boolean> env : robotDecliMap.entrySet()) {404 String key = env.getKey();405 JSONObject objectcount = new JSONObject();406 objectcount.put("name", key);407 objectcount.put("hasData", robotDecliMap.containsKey(key));408 if (robotDeclisDefined) {409 objectcount.put("isRequested", robotDecliMap.get(key));410 } else {411 objectcount.put("isRequested", true);412 }413 objectdinst.put(objectcount);414 }415 objectdist.put("robotDeclis", objectdinst);416 return objectdist;417 }418 private JSONObject convertApplicationToJSONObject(Application app) throws JSONException {419 Gson gson = new Gson();420 JSONObject result = new JSONObject(gson.toJson(app));421 return result;422 }423 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">424 /**425 * Handles the HTTP <code>GET</code> method.426 *427 * @param request servlet request428 * @param response servlet response429 * @throws ServletException if a servlet-specific error occurs430 * @throws IOException if an I/O error occurs431 */432 @Override433 protected void doGet(HttpServletRequest request, HttpServletResponse response)434 throws ServletException, IOException {435 try {436 processRequest(request, response);437 } catch (CerberusException ex) {438 LOG.warn(ex);439 }440 }441 /**442 * Handles the HTTP <code>POST</code> method.443 *444 * @param request servlet request445 * @param response servlet response446 * @throws ServletException if a servlet-specific error occurs447 * @throws IOException if an I/O error occurs448 */449 @Override450 protected void doPost(HttpServletRequest request, HttpServletResponse response)451 throws ServletException, IOException {452 try {453 processRequest(request, response);454 } catch (CerberusException ex) {455 LOG.warn(ex);456 }457 }458 /**459 * Returns a short description of the servlet.460 *461 * @return a String containing servlet description462 */463 @Override464 public String getServletInfo() {465 return "Short description";466 }// </editor-fold>467}...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.testexecution.ReadExecutionStat;2import org.cerberus.servlet.crud.testexecution.ReadExecutionStatTest;3def processRequest = new ReadExecutionStatTest().processRequest4def result = processRequest("TEST", "TEST", "TEST", "TEST", "TEST", "TEST")5def processRequest = new ReadExecutionStatTest().processRequest6def result = processRequest("TEST", "TEST", "TEST", "TEST", "TEST", "TEST")

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.testexecution.ReadExecutionStat;2import org.cerberus.servlet.crud.testexecution.ReadExecutionStat;3import java.util.List;4import java.util.List;5import java.util.Map;6import java.util.Map;7ReadExecutionStat readExecutionStat = new ReadExecutionStat();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful