Best Cerberus-source code snippet using org.cerberus.servlet.crud.test.UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter
Source:UpdateTestCaseWithDependencies.java
...152 * Get steps, actions and controls from page by:153 * - generating a new stepId, action or controlId number,154 * - setting the correct related stepId and action for action or controlId155 */156 List<TestCaseStep> stepsFromRequest = getTestCaseStepsFromParameter(request, appContext, testId, testCaseId, steps);157 List<TestCaseStepAction> actionsFromRequest = new ArrayList<>();158 List<TestCaseStepActionControl> controlsFromRequest = new ArrayList<>();159 int maxStepId = stepService.getMaxStepId(stepsFromRequest);160 for (TestCaseStep step : stepsFromRequest) {161 if (step.getStepId() == -1) {162 step.setStepId(++maxStepId);163 }164 if (step.getActions() != null) {165 int maxActionId = actionService.getMaxActionId(step.getActions());166 for (TestCaseStepAction action : step.getActions()) {167 if (action.getActionId() == -1) {168 action.setActionId(++maxActionId);169 }170 action.setStepId(step.getStepId());171 if (action.getControls() != null) {172 int maxControlId = controlService.getMaxControlId(action.getControls());173 for (TestCaseStepActionControl control : action.getControls()) {174 if (control.getControlId() == -1) {175 control.setControlId(++maxControlId);176 }177 control.setStepId(step.getStepId());178 control.setActionId(action.getActionId());179 }180 controlsFromRequest.addAll(action.getControls());181 }182 }183 actionsFromRequest.addAll(step.getActions());184 }185 }186 /*187 * Create, update or delete stepId, action and controlId according to the needs188 */189 List<TestCaseStep> stepsFromDatabase = stepService.getListOfSteps(initialTest, initialTestCase);190 stepService.compareListAndUpdateInsertDeleteElements(stepsFromRequest, stepsFromDatabase, false);191 List<TestCaseStepAction> actionsFromDatabase = actionService.readByTestTestCase(initialTest, initialTestCase).getDataList();192 actionService.compareListAndUpdateInsertDeleteElements(actionsFromRequest, actionsFromDatabase, false);193 List<TestCaseStepActionControl> controlsFromDatabase = new ArrayList<>(controlService.findControlByTestTestCase(initialTest, initialTestCase));194 controlService.compareListAndUpdateInsertDeleteElements(controlsFromRequest, controlsFromDatabase, false);195 testcase.setUsrModif(request.getUserPrincipal().getName());196 testcase.setVersion(testcase.getVersion() + 1);197 testCaseService.update(testcase.getTest(), testcase.getTestcase(), testcase);198 /**199 * Adding Log entry.200 */201 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {202 /**203 * Update was successful. Adding Log entry.204 */205 ILogEventService logEventService = appContext.getBean(LogEventService.class);206 logEventService.createForPrivateCalls("/UpdateTestCaseWithDependencies", "UPDATE", "Update TestCase Script : ['" + testcase.getTest() + "'|'" + testcase.getTestcase() + "'] version : " + testcase.getVersion(), request);207 }208 }209 }210 /**211 * Formating and returning the json result.212 */213 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());214 jsonResponse.put("message", ans.getResultMessage().getDescription());215 response.getWriter().print(jsonResponse);216 response.getWriter().flush();217 }218 private List<TestCaseCountryProperties> getTestCaseCountryPropertiesFromParameter(TestCase testcase, JSONArray properties) throws JSONException {219 List<TestCaseCountryProperties> testCaseCountryProp = new ArrayList<>();220 for (int i = 0; i < properties.length(); i++) {221 JSONObject propJson = properties.getJSONObject(i);222 boolean delete = propJson.getBoolean("toDelete");223 String property = propJson.getString("property");224 String description = propJson.getString("description");225 int cacheExpire = propJson.getInt("cacheExpire");226 String type = propJson.getString("type");227 String value = propJson.getString("value1");228 String value2 = propJson.getString("value2");229 String length = propJson.getString("length");230 int rowLimit = propJson.getInt("rowLimit");231 int retryNb = propJson.optInt("retryNb");232 int retryPeriod = propJson.optInt("retryPeriod");233 int rank = propJson.optInt("rank");234 String nature = propJson.getString("nature");235 String database = propJson.getString("database");236 JSONArray countries = propJson.getJSONArray("countries");237 if (!delete && !property.isEmpty()) {238 for (int j = 0; j < countries.length(); j++) {239 String country = countries.getJSONObject(j).getString("value");240 testCaseCountryProp.add(TestCaseCountryProperties.builder()241 .test(testcase.getTest())242 .testcase(testcase.getTestcase())243 .country(country)244 .property(property)245 .description(description)246 .type(type)247 .database(database)248 .value1(value)249 .value2(value2)250 .length(length)251 .rowLimit(rowLimit)252 .cacheExpire(cacheExpire)253 .nature(nature)254 .retryNb(retryNb)255 .retryPeriod(retryPeriod)256 .rank(rank)257 .build());258 }259 }260 }261 return testCaseCountryProp;262 }263 private List<TestCaseStep> getTestCaseStepsFromParameter(HttpServletRequest request, ApplicationContext appContext, String test, String testCase, JSONArray stepArray) throws JSONException {264 List<TestCaseStep> testCaseStep = new ArrayList<>();265 ITestCaseStepService tcsService = appContext.getBean(ITestCaseStepService.class);266 IFactoryTestCaseStep testCaseStepFactory = appContext.getBean(IFactoryTestCaseStep.class);267 for (int i = 0; i < stepArray.length(); i++) {268 JSONObject step = stepArray.getJSONObject(i);269 boolean delete = step.getBoolean("toDelete");270 int stepId = step.isNull("stepId") ? -1 : step.getInt("stepId");271 int sort = step.isNull("sort") ? -1 : step.getInt("sort");272 String loop = step.getString("loop");273 String conditionOperator = step.getString("conditionOperator");274 String conditionValue1 = step.getString("conditionValue1");275 String conditionValue2 = step.getString("conditionValue2");276 String conditionValue3 = step.getString("conditionValue3");277 JSONArray conditionOptions = ParameterParserUtil.parseJSONArrayParamAndDecode(step.getString("conditionOptions"), new JSONArray(), "UTF8");...
getTestCaseStepsFromParameter
Using AI Code Generation
1var test = request.getParameter("test");2var testcase = request.getParameter("testcase");3var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);4var test = request.getParameter("test");5var testcase = request.getParameter("testcase");6var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);7var test = request.getParameter("test");8var testcase = request.getParameter("testcase");9var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);10var test = request.getParameter("test");11var testcase = request.getParameter("testcase");12var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);13var test = request.getParameter("test");14var testcase = request.getParameter("testcase");15var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);16var test = request.getParameter("test");17var testcase = request.getParameter("testcase");18var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);19var test = request.getParameter("test");20var testcase = request.getParameter("testcase");21var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);22var test = request.getParameter("test");23var testcase = request.getParameter("testcase");24var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);25var test = request.getParameter("test");26var testcase = request.getParameter("testcase");27var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);28var test = request.getParameter("test");29var testcase = request.getParameter("testcase");30var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);31var test = request.getParameter("test");32var testcase = request.getParameter("testcase");33var tcs = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(test, testcase);34var test = request.getParameter("test");35var testcase = request.getParameter("testcase");
getTestCaseStepsFromParameter
Using AI Code Generation
1import org.cerberus.servlet.crud.test.UpdateTestCaseWithDependencies;2import org.cerberus.servlet.crud.test.UpdateTestCaseWithDependencies;3import java.util.List;4import java.util.ArrayList;5import java.util.Map;6List<Map<String, String>> steps = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter(request.getParameter("steps"));7TestCase testCase = testCaseService.findTestCaseByKey(request.getParameter("test"), request.getParameter("testcase"));8UpdateTestCaseWithDependencies.updateTestCaseSteps(testCase, steps);9testCase = testCaseService.findTestCaseByKey(request.getParameter("test"), request.getParameter("testcase"));
getTestCaseStepsFromParameter
Using AI Code Generation
1List testCaseStepList = new ArrayList();2testCaseStepList = UpdateTestCaseWithDependencies.getTestCaseStepsFromParameter("myParameterName");3UpdateTestCaseWithDependencies.updateTestCaseSteps(testCaseStepList);4UpdateTestCaseWithDependencies.updateTestCase(testCase);5UpdateTestCaseWithDependencies.createTestCase(testCase);6UpdateTestCaseWithDependencies.createTestCaseSteps(testCaseStepList);7UpdateTestCaseWithDependencies.deleteTestCaseSteps(testCaseStepList);8UpdateTestCaseWithDependencies.deleteTestCase(testCase);9UpdateTestCaseWithDependencies.createTestCaseSteps(testCaseStepList);10UpdateTestCaseWithDependencies.updateTestCaseSteps(testCaseStepList);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!