How to use CreateRobot class of org.cerberus.servlet.crud.testexecution package

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

copy

Full Screen

...53/​**54 *55 * @author bcivel56 */​57@WebServlet(name = "CreateRobot", urlPatterns = {"/​CreateRobot"})58public class CreateRobot extends HttpServlet {59 private static final Logger LOG = LogManager.getLogger(CreateRobot.class);60 /​**61 * Processes requests for both HTTP <code>GET</​code> and <code>POST</​code>62 * methods.63 *64 * @param request servlet request65 * @param response servlet response66 * @throws ServletException if a servlet-specific error occurs67 * @throws IOException if an I/​O error occurs68 * @throws org.cerberus.exception.CerberusException69 * @throws org.json.JSONException70 */​71 protected void processRequest(HttpServletRequest request, HttpServletResponse response)72 throws ServletException, IOException, CerberusException, JSONException {73 JSONObject jsonResponse = new JSONObject();74 Answer ans = new Answer();75 Gson gson = new Gson();76 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);77 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));78 ans.setResultMessage(msg);79 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);80 response.setContentType("application/​json");81 String charset = request.getCharacterEncoding();82 /​**83 * Parsing and securing all required parameters.84 */​85 /​/​ Parameter that are already controled by GUI (no need to decode) --> We SECURE them86 /​/​ Parameter that needs to be secured --> We SECURE+DECODE them87 String robot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robot"), null, charset);88 String port = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("port"), null, charset);89 String platform = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("platform"), null, charset);90 String browser = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("browser"), null, charset);91 String version = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("version"), "", charset);92 String active = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("active"), "Y", charset);93 String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);94 String userAgent = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("useragent"), "", charset);95 String screenSize = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("screensize"), "", charset);96 String robotDecli = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robotDecli"), "", charset);97 String hostUser = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("hostUsername"), null, charset);98 String hostPassword = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("hostPassword"), null, charset);99 List<RobotCapability> capabilities = (List<RobotCapability>) (request.getParameter("capabilities") == null ? Collections.emptyList() : gson.fromJson(request.getParameter("capabilities"), new TypeToken<List<RobotCapability>>() {100 }.getType()));101 /​/​ Parameter that we cannot secure as we need the html --> We DECODE them102 String host = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("host"), null, charset);103 /​/​ Securing capabilities by setting them the associated robot name104 /​/​ Check also if there is no duplicated capability105 Map<String, Object> capabilityMap = new HashMap<String, Object>();106 for (RobotCapability capability : capabilities) {107 capabilityMap.put(capability.getCapability(), null);108 capability.setRobot(robot);109 }110 Integer robotid = 0;111 boolean robotid_error = false;112 try {113 if (request.getParameter("robotid") != null && !request.getParameter("robotid").equals("")) {114 robotid = Integer.valueOf(policy.sanitize(request.getParameter("robotid")));115 }116 } catch (Exception ex) {117 robotid_error = true;118 }119 /​**120 * Checking all constrains before calling the services.121 */​122 if (StringUtil.isNullOrEmpty(robot)) {123 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);124 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")125 .replace("%OPERATION%", "Create")126 .replace("%REASON%", "Robot name is missing."));127 ans.setResultMessage(msg);128 } else if (StringUtil.isNullOrEmpty(host)) {129 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);130 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")131 .replace("%OPERATION%", "Create")132 .replace("%REASON%", "Robot host is missing."));133 ans.setResultMessage(msg);134 } else if (StringUtil.isNullOrEmpty(platform)) {135 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);136 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")137 .replace("%OPERATION%", "Create")138 .replace("%REASON%", "Robot platform is missing."));139 ans.setResultMessage(msg);140 } else if (robotid_error) {141 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);142 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")143 .replace("%OPERATION%", "Create")144 .replace("%REASON%", "Could not manage to convert robotid to an integer value or robotid is missing."));145 ans.setResultMessage(msg);146 } else if (capabilityMap.size() != capabilities.size()) {147 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);148 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")149 .replace("%OPERATION%", "Create")150 .replace("%REASON%", "There is at least one duplicated capability. Please edit or remove it to continue."));151 ans.setResultMessage(msg);152 } else {153 /​**154 * All data seems cleans so we can call the services.155 */​156 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());157 IRobotService robotService = appContext.getBean(IRobotService.class);158 IFactoryRobot robotFactory = appContext.getBean(IFactoryRobot.class);159 Robot robotData = robotFactory.create(robotid, robot, host, port, platform, browser, version, active, description, userAgent, screenSize, hostUser, hostPassword, capabilities, robotDecli);160 ans = robotService.create(robotData);161 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {162 /​**163 * Object created. Adding Log entry.164 */​165 ILogEventService logEventService = appContext.getBean(LogEventService.class);166 logEventService.createForPrivateCalls("/​CreateRobot", "CREATE", "Create Robot : ['" + robot + "']", request);167 }168 }169 /​**170 * Formating and returning the json result.171 */​172 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());173 jsonResponse.put("message", ans.getResultMessage().getDescription());174 response.getWriter().print(jsonResponse);175 response.getWriter().flush();176 }177 /​/​ <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">178 /​**179 * Handles the HTTP <code>GET</​code> method.180 *...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Different Ways To Style CSS Box Shadow Effects

Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.

Webinar: Move Forward With An Effective Test Automation Strategy [Voices of Community]

The key to successful test automation is to focus on tasks that maximize the return on investment (ROI), ensuring that you are automating the right tests and automating them in the right way. This is where test automation strategies come into play.

Keeping Quality Transparency Throughout the organization

In general, software testers have a challenging job. Software testing is frequently the final significant activity undertaken prior to actually delivering a product. Since the terms “software” and “late” are nearly synonymous, it is the testers that frequently catch the ire of the whole business as they try to test the software at the end. It is the testers who are under pressure to finish faster and deem the product “release candidate” before they have had enough opportunity to be comfortable. To make matters worse, if bugs are discovered in the product after it has been released, everyone looks to the testers and says, “Why didn’t you spot those bugs?” The testers did not cause the bugs, but they must bear some of the guilt for the bugs that were disclosed.

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful