How to use convertTestCaseExecutionInQueueToJSONObject method of org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionQueue class

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

Source:ReadTestCaseExecutionQueue.java Github

copy

Full Screen

...174 AnswerItem answer = queueService.readByKey(queueid);175 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {176 //if the service returns an OK message then we can get the item and convert it to JSONformat177 TestCaseExecutionQueue lib = (TestCaseExecutionQueue) answer.getItem();178 JSONObject response = convertTestCaseExecutionInQueueToJSONObject(lib);179 int nb = 0;180 nb = queueService.getNbEntryToGo(lib.getId(), lib.getPriority());181 response.put("nbEntryInQueueToGo", nb);182 object.put("contentTable", response);183 }184 object.put("hasPermissions", userHasPermissions);185 item.setItem(object);186 item.setResultMessage(answer.getResultMessage());187 return item;188 }189 private AnswerItem findExecutionInQueueList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {190 AnswerItem item = new AnswerItem();191 JSONObject object = new JSONObject();192 executionService = appContext.getBean(ITestCaseExecutionQueueService.class);193 int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));194 int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));195 /*int sEcho = Integer.valueOf(request.getParameter("sEcho"));*/196 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");197 int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "2"));198 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "id,test,testcase,country,environment,browser,tag");199 String columnToSort[] = sColumns.split(",");200 String columnName = columnToSort[columnToSortParameter];201 String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "desc");202 List<String> individualLike = new ArrayList(Arrays.asList(request.getParameter("sLike").split(",")));203 Map<String, List<String>> individualSearch = new HashMap<>();204 for (int a = 0; a < columnToSort.length; a++) {205 if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {206 List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));207 if(individualLike.contains(columnToSort[a])) {208 individualSearch.put(columnToSort[a]+":like", search);209 }else {210 individualSearch.put(columnToSort[a], search);211 }212 }213 }214 AnswerList resp = executionService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);215 JSONArray jsonArray = new JSONArray();216 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values217 for (TestCaseExecutionQueue exec : (List<TestCaseExecutionQueue>) resp.getDataList()) {218 jsonArray.put(convertTestCaseExecutionInQueueToJSONObject(exec));219 }220 }221 object.put("hasPermissions", userHasPermissions);222 object.put("contentTable", jsonArray);223 object.put("iTotalRecords", resp.getTotalRows());224 object.put("iTotalDisplayRecords", resp.getTotalRows());225 item.setItem(object);226 item.setResultMessage(resp.getResultMessage());227 return item;228 }229 private AnswerItem findExecutionInQueueStatus(ApplicationContext appContext, HttpServletRequest request) throws JSONException {230 AnswerItem item = new AnswerItem();231 JSONObject object = new JSONObject();232 executionThreadPoolService = appContext.getBean(IExecutionThreadPoolService.class);233 parameterService = appContext.getBean(IParameterService.class);234 invariantService = appContext.getBean(IInvariantService.class);235 JSONArray jsonArray = new JSONArray();236 try {237 HashMap<String, Integer> mapRunning = executionThreadPoolService.getCurrentlyRunning();238 HashMap<String, Integer> mapInQueue = executionThreadPoolService.getCurrentlyToTreat();239 HashMap<String, Integer> mapPoolSize = executionThreadPoolService.getCurrentlyPoolSizes();240 for (Map.Entry<String, Integer> entry : mapRunning.entrySet()) {241 String column = entry.getKey();242 Integer name = entry.getValue();243 if (!("".equals(column))) {244 String[] data = column.split("\\/\\/");245 JSONObject jsonObject = new JSONObject();246 switch (data[0]) {247 case TestCaseExecutionQueueToTreat.CONSTRAIN1_GLOBAL:248 jsonObject.put("contrainId", data[0]);249 jsonObject.put("system", "");250 jsonObject.put("environment", "");251 jsonObject.put("country", "");252 jsonObject.put("application", "");253 jsonObject.put("robot", "");254 jsonObject.put("nbInQueue", ParameterParserUtil.parseIntegerParam(mapInQueue.get(column), 0));255 jsonObject.put("nbPoolSize", ParameterParserUtil.parseIntegerParam(mapPoolSize.get(column), 0));256 jsonObject.put("nbRunning", ParameterParserUtil.parseIntegerParam(name, 0));257 jsonObject.put("hasPermissionsUpdate", parameterService.hasPermissionsUpdate("cerberus_queueexecution_global_threadpoolsize", request));258 break;259 case TestCaseExecutionQueueToTreat.CONSTRAIN2_APPLICATION:260 jsonObject.put("contrainId", data[0]);261 jsonObject.put("system", data[1]);262 jsonObject.put("environment", data[2]);263 jsonObject.put("country", data[3]);264 jsonObject.put("application", data[4]);265 jsonObject.put("robot", "");266 jsonObject.put("nbInQueue", ParameterParserUtil.parseIntegerParam(mapInQueue.get(column), 0));267 jsonObject.put("nbPoolSize", ParameterParserUtil.parseIntegerParam(mapPoolSize.get(column), 0));268 jsonObject.put("nbRunning", ParameterParserUtil.parseIntegerParam(name, 0));269 jsonObject.put("hasPermissionsUpdate", parameterService.hasPermissionsUpdate("cerberus_queueexecution_global_threadpoolsize", request));270 break;271 case TestCaseExecutionQueueToTreat.CONSTRAIN3_ROBOT:272 jsonObject.put("contrainId", data[0]);273 jsonObject.put("system", "");274 jsonObject.put("environment", "");275 jsonObject.put("country", "");276 jsonObject.put("application", "");277 if (data.length > 1) {278 jsonObject.put("robot", data[1]);279 if ((data[1] == null) || (data[1].equalsIgnoreCase("null"))) {280 jsonObject.put("invariantExist", false);281 } else {282 jsonObject.put("invariantExist", invariantService.isInvariantExist("ROBOTHOST", data[1]));283 }284 } else {285 jsonObject.put("robot", "");286 jsonObject.put("invariantExist", false);287 }288 jsonObject.put("nbInQueue", ParameterParserUtil.parseIntegerParam(mapInQueue.get(column), 0));289 jsonObject.put("nbPoolSize", ParameterParserUtil.parseIntegerParam(mapPoolSize.get(column), 0));290 jsonObject.put("nbRunning", ParameterParserUtil.parseIntegerParam(name, 0));291 jsonObject.put("hasPermissionsUpdate", parameterService.hasPermissionsUpdate("cerberus_queueexecution_global_threadpoolsize", request));292 break;293 }294 jsonArray.put(jsonObject);295 }296 }297 object.put("contentTable", jsonArray);298 } catch (CerberusException ex) {299 LOG.warn(ex);300 }301 object.put("messageType", "");302 object.put("message", "");303 item.setResultMessage(new MessageEvent(MessageEventEnum.GENERIC_OK));304 item.setItem(object);305 return item;306 }307 private AnswerItem findDistinctValuesOfColumn(ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {308 AnswerItem answer = new AnswerItem();309 JSONObject object = new JSONObject();310 AnswerList values = new AnswerList();311 executionService = appContext.getBean(ITestCaseExecutionQueueService.class);312 String column = ParameterParserUtil.parseStringParam(request.getParameter("columnName"), "");313 String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");314 LOG.debug(columnName);315 switch (columnName) {316 /**317 * Columns from Status318 */319 case "state":320 List<String> dataList = new ArrayList<>();321 dataList.add(TestCaseExecutionQueue.State.QUEUED.name());322 dataList.add(TestCaseExecutionQueue.State.WAITING.name());323 dataList.add(TestCaseExecutionQueue.State.STARTING.name());324 dataList.add(TestCaseExecutionQueue.State.EXECUTING.name());325 dataList.add(TestCaseExecutionQueue.State.ERROR.name());326 dataList.add(TestCaseExecutionQueue.State.DONE.name());327 dataList.add(TestCaseExecutionQueue.State.CANCELLED.name());328 values.setDataList(dataList);329 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);330 msg.setDescription(msg.getDescription().replace("%ITEM%", "execution").replace("%OPERATION%", "SELECT"));331 values.setResultMessage(msg);332 break;333 /**334 * For all other columns, get distinct values from testcaseexecution335 */336 default:337 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");338 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "id,test,testcase,country,environment,browser,tag");339 String columnToSort[] = sColumns.split(",");340 List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));341 Map<String, List<String>> individualSearch = new HashMap<>();342 for (int a = 0; a < columnToSort.length; a++) {343 if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {344 List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));345 if(individualLike.contains(columnToSort[a])) {346 individualSearch.put(columnToSort[a]+":like", search);347 }else {348 individualSearch.put(columnToSort[a], search);349 } 350 }351 }352 values = executionService.readDistinctValuesByCriteria(columnName, sort, searchParameter, individualSearch, column);353 }354 object.put("distinctValues", values.getDataList());355 answer.setItem(object);356 answer.setResultMessage(values.getResultMessage());357 return answer;358 }359 private JSONObject convertTestCaseExecutionInQueueToJSONObject(TestCaseExecutionQueue exec) throws JSONException {360 Gson gson = new Gson();361 JSONObject result = new JSONObject(gson.toJson(exec));362 return result;363 }364}...

Full Screen

Full Screen

convertTestCaseExecutionInQueueToJSONObject

Using AI Code Generation

copy

Full Screen

1import java.io.IOException;2import java.io.PrintWriter;3import java.util.List;4import javax.servlet.ServletException;5import javax.servlet.http.HttpServlet;6import javax.servlet.http.HttpServletRequest;7import javax.servlet.http.HttpServletResponse;8import org.cerberus.crud.entity.TestCaseExecutionQueue;9import org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue;10import org.cerberus.crud.service.ITestCaseExecutionQueueService;11import org.cerberus.crud.service.impl.TestCaseExecutionQueueService;12import org.cerberus.engine.entity.MessageEvent;13import org.cerberus.engine.entity.MessageGeneral;14import org.cerberus.engine.execution.IExecutionQueueService;15import org.cerberus.engine.execution.impl.ExecutionQueueService;16import org.cerberus.engine.threadpool.IExecutionThreadPoolService;17import org.cerberus.engine.threadpool.impl.ExecutionThreadPoolService;18import org.cerberus.engine.threadpool.impl.ThreadPoolService;19import org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionQueue;20import org.cerberus.util.answer.AnswerList;21import org.json.JSONArray;22import org.json.JSONException;23import org.json.JSONObject;24import org.springframework.context.ApplicationContext;25import org.springframework.web.context.support.WebApplicationContextUtils;26public class ReadTestCaseExecutionQueue extends HttpServlet {27 private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(ReadTestCaseExecutionQueue.class);28 private ITestCaseExecutionQueueService testCaseExecutionQueueService;29 private IExecutionThreadPoolService executionThreadPoolService;30 private IExecutionQueueService executionQueueService;31 private IFactoryTestCaseExecutionQueue factoryTestCaseExecutionQueue;32 public void init() throws ServletException {33 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());34 testCaseExecutionQueueService = appContext.getBean(TestCaseExecutionQueueService.class);35 executionThreadPoolService = appContext.getBean(ExecutionThreadPoolService.class);36 executionQueueService = appContext.getBean(ExecutionQueueService.class);37 factoryTestCaseExecutionQueue = appContext.getBean(IFactoryTestCaseExecutionQueue.class);38 }39 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {40 response.setContentType("application/json");41 response.setCharacterEncoding("utf-8");42 PrintWriter out = response.getWriter();43 try {44 JSONObject jsonResponse = new JSONObject();45 JSONArray jsonArray = new JSONArray();46 AnswerList answer = testCaseExecutionQueueService.readAllByCriteria(0

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