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

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

Source:ReadExecutionTagHistory.java Github

copy

Full Screen

...86 * @throws ServletException if a servlet-specific error occurs87 * @throws IOException if an I/O error occurs88 * @throws org.cerberus.exception.CerberusException89 */90 protected void processRequest(HttpServletRequest request, HttpServletResponse response)91 throws ServletException, IOException, CerberusException {92 String echo = request.getParameter("sEcho");93 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());94 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);95 response.setContentType("application/json");96 response.setCharacterEncoding("utf8");97 // Calling Servlet Transversal Util.98 ServletUtil.servletStart(request);99 // Default message to unexpected error.100 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);101 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));102 /**103 * Parsing and securing all required parameters.104 */105 factoryTestCase = appContext.getBean(IFactoryTestCase.class);106 List<String> systems = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("system"), new ArrayList<String>(), "UTF8");107 String from = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("from"), null, "UTF8");108 String to = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("to"), null, "UTF8");109 LOG.debug("from : " + from);110 LOG.debug("to : " + to);111 Date fromD;112 try {113 TimeZone tz = TimeZone.getTimeZone("UTC");114 DateFormat df = new SimpleDateFormat(DATE_FORMAT);115 df.setTimeZone(tz);116 fromD = df.parse(from);117 } catch (ParseException ex) {118 fromD = Date.from(ZonedDateTime.now().minusMonths(1).toInstant());119 LOG.debug("Exception when parsing date", ex);120 }121 Date toD;122 try {123 TimeZone tz = TimeZone.getTimeZone("UTC");124 DateFormat df = new SimpleDateFormat(DATE_FORMAT);125 df.setTimeZone(tz);126 toD = df.parse(to);127 } catch (ParseException ex) {128 toD = Date.from(ZonedDateTime.now().toInstant());129 LOG.debug("Exception when parsing date", ex);130 }131 LOG.debug("from : " + fromD);132 LOG.debug("to : " + toD);133 // Init Answer with potencial error from Parsing parameter.134 AnswerItem<JSONObject> answer = new AnswerItem<>(msg);135 try {136 JSONObject jsonResponse = new JSONObject();137 answer = findTagHistoData(appContext, request, systems, fromD, toD);138 jsonResponse = (JSONObject) answer.getItem();139 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());140 jsonResponse.put("message", answer.getResultMessage().getDescription());141 jsonResponse.put("sEcho", echo);142 response.getWriter().print(jsonResponse.toString());143 } catch (JSONException e) {144 LOG.warn(e);145 //returns a default error message with the json format that is able to be parsed by the client-side146 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());147 }148 }149 private AnswerItem<JSONObject> findTagHistoData(ApplicationContext appContext, HttpServletRequest request,150 List<String> system, Date from, Date to) throws JSONException {151 AnswerItem<JSONObject> item = new AnswerItem<>();152 JSONObject object = new JSONObject();153 testCaseExecutionHttpStatService = appContext.getBean(ITestCaseExecutionHttpStatService.class);154 applicationService = appContext.getBean(IApplicationService.class);155 testCaseService = appContext.getBean(ITestCaseService.class);156 factoryTestCase = appContext.getBean(IFactoryTestCase.class);157 tagService = appContext.getBean(ITagService.class);158 HashMap<String, JSONObject> curveStatusObjMap = new HashMap<>();159 TreeMap<String, Boolean> curveDateMap = new TreeMap<>();160 TreeMap<String, Integer> curveDateStatusMap = new TreeMap<>();161 TreeMap<String, Integer> curveStatusMap = new TreeMap<>();162 String curveKeyStatus;163 JSONArray curArray = new JSONArray();164 JSONObject curveStatObj = new JSONObject();165 JSONObject pointObj = new JSONObject();166 // get all TestCase Execution Data.167 AnswerList<Tag> resp = tagService.readByVarious(system, from, to);168 // Building the list of status to load adding the extra RETRY.169 List<String> statList = new ArrayList<>();170 for (ControlStatus v : TestCaseExecution.ControlStatus.values()) {171 statList.add(v.name().toUpperCase());172 }173 statList.add("RETRY");174 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values175 List<Tag> tcList = (List<Tag>) resp.getDataList();176 for (Tag tagCur : tcList) {177 /**178 * Bar Charts per control status.179 */180 for (String v : statList) {181 182 curveKeyStatus = v.toUpperCase();183 int x = getValue(tagCur, curveKeyStatus);184 Date d = new Date(tagCur.getDateCreated().getTime());185 TimeZone tz = TimeZone.getTimeZone("UTC");186 DateFormat df = new SimpleDateFormat(DATE_FORMAT_DAY);187 df.setTimeZone(tz);188 String dday = df.format(d);189 curveDateMap.put(dday, false);190 String keyDateStatus = curveKeyStatus + "-" + dday;191 if (curveDateStatusMap.containsKey(keyDateStatus)) {192 curveDateStatusMap.put(keyDateStatus, curveDateStatusMap.get(keyDateStatus) + x);193 } else {194 curveDateStatusMap.put(keyDateStatus, x);195 }196 if (curveStatusMap.containsKey(curveKeyStatus)) {197 curveStatusMap.put(curveKeyStatus, curveStatusMap.get(curveKeyStatus) + x);198 } else {199 curveStatusMap.put(curveKeyStatus, x);200 }201 if (!curveStatusObjMap.containsKey(curveKeyStatus)) {202 curveStatObj = new JSONObject();203 curveStatObj.put("key", curveKeyStatus);204 curveStatObj.put("unit", "nbExe");205 curveStatusObjMap.put(curveKeyStatus, curveStatObj);206 }207 }208 }209 object.put("hasHistodata", (tcList.size() > 0));210 }211 /**212 * Bar Charts per control status to JSON.213 */214 JSONArray curvesArray = new JSONArray();215 for (Map.Entry<String, Boolean> entry : curveDateMap.entrySet()) {216 curvesArray.put(entry.getKey());217 }218 object.put("curvesDatesNb", curvesArray);219 curvesArray = new JSONArray();220 for (Map.Entry<String, JSONObject> entry : curveStatusObjMap.entrySet()) {221 String key = entry.getKey();222 if (curveStatusMap.get(key) > 0) {223 JSONObject val = entry.getValue();224 val.put("nbExe", curveStatusMap.get(key));225 JSONArray valArray = new JSONArray();226 for (Map.Entry<String, Boolean> entry1 : curveDateMap.entrySet()) {227 String key1 = entry1.getKey(); // Date228 if (curveDateStatusMap.containsKey(key + "-" + key1)) {229 valArray.put(curveDateStatusMap.get(key + "-" + key1));230 } else {231 valArray.put(0);232 }233 }234 JSONObject localcur = new JSONObject();235 localcur.put("key", val);236 localcur.put("points", valArray);237 curvesArray.put(localcur);238 }239 }240 object.put("curvesNb", curvesArray);241 object.put("iTotalRecords", resp.getTotalRows());242 object.put("iTotalDisplayRecords", resp.getTotalRows());243 item.setItem(object);244 item.setResultMessage(resp.getResultMessage());245 return item;246 }247 private int getValue(Tag tagCur, String status) {248 switch (status) {249 case "OK":250 return tagCur.getNbOK();251 case "KO":252 return tagCur.getNbKO();253 case "FA":254 return tagCur.getNbFA();255 case "NA":256 return tagCur.getNbNA();257 case "NE":258 return tagCur.getNbNE();259 case "WE":260 return tagCur.getNbWE();261 case "PE":262 return tagCur.getNbPE();263 case "QU":264 return tagCur.getNbQU();265 case "QE":266 return tagCur.getNbQE();267 case "CA":268 return tagCur.getNbCA();269 case "RETRY":270 return tagCur.getNbExe() - tagCur.getNbExeUsefull();271 }272 return 0;273 }274 private JSONObject convertApplicationToJSONObject(Application app) throws JSONException {275 Gson gson = new Gson();276 JSONObject result = new JSONObject(gson.toJson(app));277 return result;278 }279 private String getKeyCurve(TestCaseExecutionHttpStat stat, String party, String type, String unit) {280 return type + "/" + party + "/" + unit + "/" + stat.getTest() + "/" + stat.getTestCase() + "/" + stat.getCountry() + "/" + stat.getEnvironment() + "/" + stat.getRobotDecli() + "/" + stat.getSystem() + "/" + stat.getApplication();281 }282 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">283 /**284 * Handles the HTTP <code>GET</code> method.285 *286 * @param request servlet request287 * @param response servlet response288 * @throws ServletException if a servlet-specific error occurs289 * @throws IOException if an I/O error occurs290 */291 @Override292 protected void doGet(HttpServletRequest request, HttpServletResponse response)293 throws ServletException, IOException {294 try {295 processRequest(request, response);296 } catch (CerberusException ex) {297 LOG.warn(ex);298 }299 }300 /**301 * Handles the HTTP <code>POST</code> method.302 *303 * @param request servlet request304 * @param response servlet response305 * @throws ServletException if a servlet-specific error occurs306 * @throws IOException if an I/O error occurs307 */308 @Override309 protected void doPost(HttpServletRequest request, HttpServletResponse response)310 throws ServletException, IOException {311 try {312 processRequest(request, response);313 } catch (CerberusException ex) {314 LOG.warn(ex);315 }316 }317 /**318 * Returns a short description of the servlet.319 *320 * @return a String containing servlet description321 */322 @Override323 public String getServletInfo() {324 return "Short description";325 }// </editor-fold>326}...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1String response = processRequest(url);2log(response);3URL obj = new URL(url);4HttpURLConnection con = (HttpURLConnection) obj.openConnection();5con.setRequestMethod("GET");6int responseCode = con.getResponseCode();7BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));8String inputLine;9StringBuffer response = new StringBuffer();10while ((inputLine = in.readLine()) != null) {11 response.append(inputLine);12}13in.close();14log(response.toString());15HttpClient client = HttpClientBuilder.create().build();16HttpGet request = new HttpGet(url);17HttpResponse response = client.execute(request);18log(EntityUtils.toString(response.getEntity()));19OkHttpClient client = new OkHttpClient();20Request request = new Request.Builder()21 .url(url)22 .build();23Response response = client.newCall(request).execute();24log(response.body().string());25RestTemplate restTemplate = new RestTemplate();26String response = restTemplate.getForObject(url, String.class);27log(response);28RequestSpecification request = RestAssured.given();

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.testexecution.ReadExecutionTagHistory2def tags = ReadExecutionTagHistory.processRequest(id)3import org.cerberus.servlet.crud.testexecution.ReadExecutionTagHistory;4public class Main {5 public static void main(String[] args) {6 int id = 1;7 String[] tags = ReadExecutionTagHistory.processRequest(id);8 for (String tag : tags) {9 System.out.println(tag);10 }11 }12}13import org.cerberus.servlet.crud.testexecution.ReadExecutionTagHistory14tags = ReadExecutionTagHistory.processRequest(id)15print(tags)16tags = ReadExecutionTagHistory.processRequest(id)

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