Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.TestCaseStepDAO.loadFromResultSet
Source:TestCaseStepDAO.java
...82 preStat.setString(2, testcase);83 list = new ArrayList<>();84 try (ResultSet resultSet = preStat.executeQuery();) {85 while (resultSet.next()) {86 list.add(loadFromResultSet(resultSet));87 }88 } catch (SQLException exception) {89 LOG.error("Unable to execute query : " + exception.toString());90 }91 } catch (SQLException exception) {92 LOG.error("Unable to execute query : " + exception.toString());93 }94 return list;95 }96 @Override97 public List<TestCaseStep> findAllTestcaseSteps() {98 final String query = "SELECT * FROM testcasestep";99 List<TestCaseStep> steps = new ArrayList<>();100 if (LOG.isDebugEnabled()) {101 LOG.debug("SQL : " + query);102 }103 try (Connection connection = this.databaseSpring.connect();104 PreparedStatement preStat = connection.prepareStatement(query);) {105 try (ResultSet resultSet = preStat.executeQuery();) {106 while (resultSet.next()) {107 steps.add(loadFromResultSet(resultSet));108 }109 } catch (SQLException exception) {110 LOG.error("Unable to execute query : " + exception.toString());111 }112 } catch (SQLException exception) {113 LOG.error("Unable to execute query : " + exception.toString());114 }115 return steps;116 }117 @Override118 public List<TestCaseStep> findAllLibrarySteps() {119 final String query = "SELECT * FROM testcasestep WHERE IsLibraryStep = true";120 List<TestCaseStep> steps = new ArrayList<>();121 if (LOG.isDebugEnabled()) {122 LOG.debug("SQL : " + query);123 }124 try (Connection connection = this.databaseSpring.connect();125 PreparedStatement preStat = connection.prepareStatement(query);) {126 try (ResultSet resultSet = preStat.executeQuery();) {127 while (resultSet.next()) {128 steps.add(loadFromResultSet(resultSet));129 }130 } catch (SQLException exception) {131 LOG.error("Unable to execute query : " + exception.toString());132 }133 } catch (SQLException exception) {134 LOG.error("Unable to execute query : " + exception.toString());135 }136 return steps;137 }138 @Override139 public List<TestCaseStep> findTestcaseStepsByTestFolderId(String testFolderId) {140 final String query = "SELECT * FROM testcasestep WHERE Test = ?";141 List<TestCaseStep> steps = new ArrayList<>();142 if (LOG.isDebugEnabled()) {143 LOG.debug("SQL : " + query);144 }145 try (Connection connection = this.databaseSpring.connect();146 PreparedStatement preStat = connection.prepareStatement(query);) {147 preStat.setString(1, testFolderId);148 try (ResultSet resultSet = preStat.executeQuery();) {149 while (resultSet.next()) {150 steps.add(loadFromResultSet(resultSet));151 }152 } catch (SQLException exception) {153 LOG.error("Unable to execute query : " + exception.toString());154 }155 } catch (SQLException exception) {156 LOG.error("Unable to execute query : " + exception.toString());157 }158 return steps;159 }160 @Override161 public TestCaseStep findTestCaseStep(String test, String testcase, Integer stepId) {162 TestCaseStep result = null;163 final String query = "SELECT * FROM testcasestep WHERE test = ? AND testcase = ? AND stepId = ?";164 if (LOG.isDebugEnabled()) {165 LOG.debug("SQL : " + query);166 }167 try (Connection connection = this.databaseSpring.connect();168 PreparedStatement preStat = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);) {169 preStat.setString(1, test);170 preStat.setString(2, testcase);171 preStat.setInt(3, stepId);172 try (ResultSet resultSet = preStat.executeQuery();) {173 if (resultSet.first()) {174 result = loadFromResultSet(resultSet);175 }176 } catch (SQLException exception) {177 LOG.error("Unable to execute query : " + exception.toString());178 }179 } catch (SQLException exception) {180 LOG.error("Unable to execute query : " + exception.toString());181 }182 return result;183 }184 @Override185 public void deleteTestCaseStep(TestCaseStep tcs) throws CerberusException {186 final String query = "DELETE FROM testcasestep WHERE test = ? and testcase = ? and stepId = ?";187 if (LOG.isDebugEnabled()) {188 LOG.debug("SQL : " + query);189 }190 try (Connection connection = this.databaseSpring.connect();191 PreparedStatement preStat = connection.prepareStatement(query);) {192 preStat.setString(1, tcs.getTest());193 preStat.setString(2, tcs.getTestcase());194 preStat.setInt(3, tcs.getStepId());195 if (preStat.executeUpdate() == 0) {196 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));197 }198 } catch (SQLException exception) {199 LOG.error("Unable to execute query : " + exception.toString());200 }201 }202 @Override203 public void updateTestCaseStep(TestCaseStep tcs) throws CerberusException {204 StringBuilder query = new StringBuilder();205 query.append("UPDATE testcasestep SET ");206 query.append(" `Description` = ?, `isUsingLibraryStep`=? ");207 if (!StringUtil.isNullOrEmpty(tcs.getLibraryStepTest())) {208 query.append(",`libraryStepTest`=? ");209 }210 if (!StringUtil.isNullOrEmpty(tcs.getLibraryStepTestcase())) {211 query.append(",`libraryStepTestcase`=? ");212 }213 if (tcs.getLibraryStepStepId() >= 0) {214 query.append(",`libraryStepStepId`=? ");215 }216 query.append(",`isLibraryStep` = ?, `Sort` = ?, `loop` = ?, `conditionOperator` = ?, `conditionOptions` = ?, `conditionValue1` = ?, `conditionValue2` = ?, `conditionValue3` = ?, `isExecutionForced` = ?, DateModif = CURRENT_TIMESTAMP, UsrModif = ? WHERE Test = ? AND testcase = ? AND stepId = ?");217 if (LOG.isDebugEnabled()) {218 LOG.debug("SQL : " + query.toString());219 }220 try (Connection connection = this.databaseSpring.connect();221 PreparedStatement preStat = connection.prepareStatement(query.toString());) {222 int i = 1;223 preStat.setString(i++, tcs.getDescription());224 preStat.setBoolean(i++, tcs.isUsingLibraryStep());225 if (!StringUtil.isNullOrEmpty(tcs.getLibraryStepTest())) {226 preStat.setString(i++, tcs.getLibraryStepTest());227 }228 if (!StringUtil.isNullOrEmpty(tcs.getLibraryStepTestcase())) {229 preStat.setString(i++, tcs.getLibraryStepTestcase());230 }231 if (tcs.getLibraryStepStepId() >= 0) {232 preStat.setInt(i++, tcs.getLibraryStepStepId());233 }234 preStat.setBoolean(i++, tcs.isLibraryStep());235 preStat.setInt(i++, tcs.getSort());236 preStat.setString(i++, tcs.getLoop() == null ? "" : tcs.getLoop());237 preStat.setString(i++, tcs.getConditionOperator() == null ? "" : tcs.getConditionOperator());238 preStat.setString(i++, tcs.getConditionOptions() == null ? "[]" : tcs.getConditionOptions().toString());239 preStat.setString(i++, tcs.getConditionValue1() == null ? "" : tcs.getConditionValue1());240 preStat.setString(i++, tcs.getConditionValue2() == null ? "" : tcs.getConditionValue2());241 preStat.setString(i++, tcs.getConditionValue3() == null ? "" : tcs.getConditionValue3());242 preStat.setBoolean(i++, tcs.isExecutionForced());243 preStat.setString(i++, tcs.getUsrModif() == null ? "" : tcs.getUsrModif());244 preStat.setString(i++, tcs.getTest());245 preStat.setString(i++, tcs.getTestcase());246 preStat.setInt(i++, tcs.getStepId());247 if (preStat.executeUpdate() == 0) {248 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));249 }250 } catch (SQLException exception) {251 LOG.error("Unable to execute query : " + exception.toString());252 }253 }254 @Override255 public List<TestCaseStep> getTestCaseStepUsingStepInParamter(String test, String testcase,256 int stepId) throws CerberusException {257 List<TestCaseStep> list = new ArrayList<>();258 final String query = "SELECT * FROM testcasestep WHERE isUsingLibraryStep IS true AND libraryStepTest = ? AND libraryStepTestcase = ? AND libraryStepStepId = ?";259 if (LOG.isDebugEnabled()) {260 LOG.debug("SQL : " + query);261 }262 try (Connection connection = this.databaseSpring.connect();263 PreparedStatement preStat = connection.prepareStatement(query);) {264 preStat.setString(1, test);265 preStat.setString(2, testcase);266 preStat.setInt(3, stepId);267 try (ResultSet resultSet = preStat.executeQuery();) {268 while (resultSet.next()) {269 list.add(loadFromResultSet(resultSet));270 }271 } catch (SQLException exception) {272 LOG.error("Unable to execute query : " + exception.toString());273 }274 } catch (SQLException exception) {275 LOG.error("Unable to execute query : " + exception.toString());276 }277 return list;278 }279 @Override280 public List<TestCaseStep> getTestCaseStepUsingTestCaseInParamter(String test, String testcase) throws CerberusException {281 List<TestCaseStep> list = null;282 final String query = "SELECT * FROM testcasestep WHERE isUsingLibraryStep IS true AND libraryStepTest = ? AND libraryStepTestcase = ?";283 if (LOG.isDebugEnabled()) {284 LOG.debug("SQL : " + query);285 }286 try (Connection connection = this.databaseSpring.connect();287 PreparedStatement preStat = connection.prepareStatement(query);) {288 preStat.setString(1, test);289 preStat.setString(2, testcase);290 list = new ArrayList<>();291 try (ResultSet resultSet = preStat.executeQuery();) {292 while (resultSet.next()) {293 list.add(loadFromResultSet(resultSet));294 }295 } catch (SQLException exception) {296 LOG.error("Unable to execute query : " + exception.toString());297 }298 } catch (SQLException exception) {299 LOG.error("Unable to execute query : " + exception.toString());300 }301 return list;302 }303 @Override304 public List<TestCaseStep> getTestCaseStepsUsingTestInParameter(final String test) throws CerberusException {305 final String query = "SELECT * FROM testcasestep WHERE isUsingLibraryStep IS true AND libraryStepTest = ?";306 List<TestCaseStep> steps = new ArrayList<>();307 try (final Connection connection = databaseSpring.connect();308 final PreparedStatement preStat = connection.prepareStatement(query)) {309 preStat.setString(1, test);310 try (ResultSet resultSet = preStat.executeQuery();) {311 while (resultSet.next()) {312 steps.add(loadFromResultSet(resultSet));313 }314 } catch (SQLException exception) {315 LOG.error("Unable to execute query : " + exception.toString());316 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));317 }318 } catch (SQLException exception) {319 LOG.error("Unable to execute query : " + exception.toString());320 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));321 }322 return steps;323 }324 @Override325 public List<TestCaseStep> getStepLibraryBySystem(String system) throws CerberusException {326 List<TestCaseStep> list = null;327 StringBuilder query = new StringBuilder();328 query.append("SELECT tcs.test, tcs.testcase, tcs.stepId, tcs.sort, tcs.description, tc.description as tcdesc FROM testcasestep tcs ");329 query.append("join testcase tc on tc.test=tcs.test and tc.testcase=tcs.testcase ");330 query.append("join application app on tc.application=app.application ");331 query.append("where tcs.islibrarystep IS true and app.system = ? ");332 query.append("order by tcs.test, tcs.testcase, tcs.sort");333 // Debug message on SQL.334 if (LOG.isDebugEnabled()) {335 LOG.debug("SQL : " + query);336 }337 try (Connection connection = this.databaseSpring.connect();338 PreparedStatement preStat = connection.prepareStatement(query.toString());) {339 preStat.setString(1, system);340 list = new ArrayList<>();341 try (ResultSet resultSet = preStat.executeQuery();) {342 while (resultSet.next()) {343 String test = resultSet.getString("test");344 String testcase = resultSet.getString("testcase");345 String tcdesc = resultSet.getString("tcdesc");346 int s = resultSet.getInt("stepId");347 int sort = resultSet.getInt("sort");348 String description = resultSet.getString("description");349 TestCaseStep tcs = factoryTestCaseStep.create(test, testcase, s, sort, null, null, null, null, null, null, description, false, null, null, 0, false, false, null, null, null, null);350 TestCase tcObj = factoryTestCase.create(test, testcase, tcdesc);351 tcs.setTestcaseObj(tcObj);352 list.add(tcs);353 }354 } catch (SQLException exception) {355 LOG.error("Unable to execute query : " + exception.toString());356 }357 } catch (SQLException exception) {358 LOG.error("Unable to execute query : " + exception.toString());359 }360 return list;361 }362 @Override363 public List<TestCaseStep> getStepLibraryBySystemTest(String system, String test) throws CerberusException {364 List<TestCaseStep> list = null;365 StringBuilder query = new StringBuilder();366 query.append("SELECT tcs.test, tcs.testcase,tcs.stepId, tcs.sort, tcs.description, tc.description as tcdesc, tc.application as tcapp FROM testcasestep tcs ");367 query.append("join testcase tc on tc.test=tcs.test and tc.testcase=tcs.testcase ");368 query.append("join application app on tc.application=app.application ");369 query.append("where tcs.islibrarystep IS true ");370 if (system != null) {371 query.append("and app.system = ? ");372 }373 if (test != null) {374 query.append("and tcs.test = ? ");375 }376 query.append("order by tcs.test, tcs.testcase, tcs.sort");377 if (LOG.isDebugEnabled()) {378 LOG.debug("SQL : " + query.toString());379 LOG.debug("SQL.param.system : " + system);380 LOG.debug("SQL.param.test : " + test);381 }382 try (Connection connection = this.databaseSpring.connect();383 PreparedStatement preStat = connection.prepareStatement(query.toString());) {384 int i = 1;385 if (system != null) {386 preStat.setString(i++, system);387 }388 if (test != null) {389 preStat.setString(i++, test);390 }391 list = new ArrayList<>();392 try (ResultSet resultSet = preStat.executeQuery();) {393 while (resultSet.next()) {394 String t = resultSet.getString("test");395 String tc = resultSet.getString("testcase");396 int s = resultSet.getInt("stepId");397 int sort = resultSet.getInt("sort");398 String description = resultSet.getString("description");399 String tcdesc = resultSet.getString("tcdesc");400 TestCase tcToAdd = factoryTestCase.create(t, tc, tcdesc);401 tcToAdd.setApplication(resultSet.getString("tcapp"));402 TestCaseStep tcsToAdd = factoryTestCaseStep.create(t, tc, s, sort, null, null, null, null, null, null, description, false, null, null, 0, false, false, null, null, null, null);403 tcsToAdd.setTestcaseObj(tcToAdd);404 list.add(tcsToAdd);405 }406 } catch (SQLException exception) {407 LOG.error("Unable to execute query : " + exception.toString());408 }409 } catch (SQLException exception) {410 LOG.error("Unable to execute query : " + exception.toString());411 }412 return list;413 }414 @Override415 public List<TestCaseStep> getStepLibraryBySystemTestTestCase(String system, String test,416 String testcase) throws CerberusException {417 List<TestCaseStep> list = null;418 StringBuilder query = new StringBuilder();419 query.append("SELECT tcs.test, tcs.testcase,tcs.stepId, tcs.sort, tcs.description FROM testcasestep tcs ");420 query.append("join testcase tc on tc.test=tcs.test and tc.testcase=tcs.testcase ");421 query.append("join application app on tc.application=app.application ");422 query.append("where tcs.islibrarystep IS true ");423 if (system != null) {424 query.append("and app.system = ? ");425 }426 if (test != null) {427 query.append("and tcs.test = ? ");428 }429 if (testcase != null) {430 query.append("and tcs.testcase = ? ");431 }432 query.append("order by tcs.test, tcs.testcase, tcs.sort");433 if (LOG.isDebugEnabled()) {434 LOG.debug("SQL : " + query.toString());435 LOG.debug("SQL.param.system : " + system);436 LOG.debug("SQL.param.test : " + test);437 LOG.debug("SQL.param.testcase : " + testcase);438 }439 try (Connection connection = this.databaseSpring.connect();440 PreparedStatement preStat = connection.prepareStatement(query.toString());) {441 int i = 1;442 if (system != null) {443 preStat.setString(i++, system);444 }445 if (test != null) {446 preStat.setString(i++, test);447 }448 if (testcase != null) {449 preStat.setString(i++, testcase);450 }451 list = new ArrayList<>();452 try (ResultSet resultSet = preStat.executeQuery();) {453 while (resultSet.next()) {454 String t = resultSet.getString("test");455 String tc = resultSet.getString("testcase");456 int s = resultSet.getInt("stepId");457 int sort = resultSet.getInt("sort");458 String description = resultSet.getString("description");459 list.add(factoryTestCaseStep.create(t, tc, s, sort, null, null, null, null, null, null, description, false, null, null, 0, false, false, null, null, null, null));460 }461 } catch (SQLException exception) {462 LOG.error("Unable to execute query : " + exception.toString());463 }464 } catch (SQLException exception) {465 LOG.error("Unable to execute query : " + exception.toString());466 }467 return list;468 }469 @Override470 public AnswerList<TestCaseStep> readByTestTestCase(String test, String testcase) {471 AnswerList<TestCaseStep> response = new AnswerList<>();472 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);473 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));474 List<TestCaseStep> stepList = new ArrayList<>();475 StringBuilder query = new StringBuilder();476 query.append("SELECT tcs.*, tcs2.sort as libraryStepSort, ");477 query.append("MAX(IF(tcs1.test IS NULL, 0, 1)) AS isStepInUseByOtherTestCase ");478 query.append("FROM testcasestep tcs ");479 query.append("LEFT JOIN testcasestep tcs1 ");480 query.append("ON tcs1.isUsingLibraryStep = true AND tcs1.libraryStepTest = ? AND tcs1.libraryStepTestcase = ? AND tcs1.libraryStepStepId = tcs.stepId ");481 query.append("LEFT OUTER JOIN testcasestep tcs2 ");482 query.append("ON tcs2.Test = tcs.libraryStepTest AND tcs2.Testcase = tcs.libraryStepTestcase AND tcs2.stepId = tcs.libraryStepStepId ");483 query.append("WHERE tcs.test = ? AND tcs.testcase = ? ");484 query.append("GROUP BY tcs.test, tcs.testcase, tcs.stepId ORDER BY tcs.sort");485 if (LOG.isDebugEnabled()) {486 LOG.debug("SQL : " + query.toString());487 LOG.debug("SQL.param.test : " + test);488 LOG.debug("SQL.param.testcase : " + testcase);489 }490 try (Connection connection = this.databaseSpring.connect();491 PreparedStatement preStat = connection.prepareStatement(query.toString());) {492 preStat.setString(1, test);493 preStat.setString(2, testcase);494 preStat.setString(3, test);495 preStat.setString(4, testcase);496 try (ResultSet resultSet = preStat.executeQuery();) {497 //gets the data498 while (resultSet.next()) {499 stepList.add(this.loadFromResultSet(resultSet));500 }501 if (stepList.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.502 LOG.error("Partial Result in the query.");503 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);504 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));505 response = new AnswerList<>(stepList, stepList.size());506 } else if (stepList.size() <= 0) {507 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);508 response = new AnswerList<>(stepList, stepList.size());509 } else {510 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);511 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));512 response = new AnswerList<>(stepList, stepList.size());513 }514 } catch (SQLException exception) {515 LOG.error("Unable to execute query : " + exception.toString());516 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);517 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));518 }519 } catch (SQLException exception) {520 LOG.error("Unable to execute query : " + exception.toString());521 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);522 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));523 }524 response.setResultMessage(msg);525 return response;526 }527 @Override528 public AnswerList<TestCaseStep> readByLibraryUsed(String test, String testcase,529 int stepId530 ) {531 AnswerList<TestCaseStep> response = new AnswerList<>();532 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);533 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));534 List<TestCaseStep> stepList = new ArrayList<>();535 StringBuilder query = new StringBuilder();536 query.append("SELECT * FROM testcasestep tcs WHERE tcs.isUsingLibraryStep = true ");537 query.append("AND tcs.libraryStepTest = ? AND tcs.libraryStepTestcase = ? AND tcs.libraryStepStepId = ?");538 try (Connection connection = this.databaseSpring.connect();539 PreparedStatement preStat = connection.prepareStatement(query.toString());) {540 preStat.setString(1, test);541 preStat.setString(2, testcase);542 preStat.setInt(3, stepId);543 try (ResultSet resultSet = preStat.executeQuery();) {544 while (resultSet.next()) {545 stepList.add(this.loadFromResultSet(resultSet));546 }547 if (stepList.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.548 LOG.error("Partial Result in the query.");549 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);550 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));551 response = new AnswerList<>(stepList, stepList.size());552 } else if (stepList.size() <= 0) {553 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);554 response = new AnswerList<>(stepList, stepList.size());555 } else {556 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);557 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));558 response = new AnswerList<>(stepList, stepList.size());559 }560 } catch (SQLException exception) {561 LOG.error("Unable to execute query : " + exception.toString());562 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);563 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));564 }565 } catch (SQLException exception) {566 LOG.error("Unable to execute query : " + exception.toString());567 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);568 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));569 }570 response.setResultMessage(msg);571 return response;572 }573 @Override574 public Answer create(TestCaseStep testCaseStep575 ) {576 Answer ans = new Answer();577 MessageEvent msg = null;578 StringBuilder query = new StringBuilder();579 query.append("INSERT INTO `testcasestep` (`Test`,`TestCase`,`StepId`,`Sort`,`Description`,`isUsingLibraryStep` ");580 if (!StringUtil.isNullOrEmpty(testCaseStep.getLibraryStepTest())) {581 query.append(",`libraryStepTest` ");582 }583 if (!StringUtil.isNullOrEmpty(testCaseStep.getLibraryStepTestcase())) {584 query.append(",`libraryStepTestcase` ");585 }586 if (testCaseStep.getLibraryStepStepId() >= 0) {587 query.append(",`libraryStepStepId` ");588 }589 query.append(", `isLibraryStep`, `loop`, `conditionOperator`, `conditionOptions`, `conditionValue1`, `conditionValue2`, `conditionValue3`, `isExecutionForced`, `usrCreated`) ");590 query.append("VALUES (?,?,?,?,?,?,?,?");591 if (!StringUtil.isNullOrEmpty(testCaseStep.getLibraryStepTest())) {592 query.append(",?");593 }594 if (!StringUtil.isNullOrEmpty(testCaseStep.getLibraryStepTestcase())) {595 query.append(",?");596 }597 if (testCaseStep.getLibraryStepStepId() >= 0) {598 query.append(",?");599 }600 query.append(",?,?,?,?,?,?,?)");601 if (LOG.isDebugEnabled()) {602 LOG.debug("SQL : " + query.toString());603 LOG.debug("SQL.param.libraryStepTest : " + testCaseStep.getLibraryStepTest());604 LOG.debug("SQL.param.libraryStepTestcase : " + testCaseStep.getLibraryStepTestcase());605 LOG.debug("SQL.param.libraryStepStepId : " + testCaseStep.getLibraryStepStepId());606 }607 try (Connection connection = databaseSpring.connect();608 PreparedStatement preStat = connection.prepareStatement(query.toString())) {609 // Prepare and execute query610 int i = 1;611 preStat.setString(i++, testCaseStep.getTest());612 preStat.setString(i++, testCaseStep.getTestcase());613 preStat.setInt(i++, testCaseStep.getStepId());614 preStat.setInt(i++, testCaseStep.getSort());615 preStat.setString(i++, testCaseStep.getDescription());616 preStat.setBoolean(i++, testCaseStep.isUsingLibraryStep());617 if (!StringUtil.isNullOrEmpty(testCaseStep.getLibraryStepTest())) {618 preStat.setString(i++, testCaseStep.getLibraryStepTest());619 }620 if (!StringUtil.isNullOrEmpty(testCaseStep.getLibraryStepTestcase())) {621 preStat.setString(i++, testCaseStep.getLibraryStepTestcase());622 }623 if (testCaseStep.getLibraryStepStepId() >= 0) {624 preStat.setInt(i++, testCaseStep.getLibraryStepStepId());625 }626 preStat.setBoolean(i++, testCaseStep.isLibraryStep());627 preStat.setString(i++, testCaseStep.getLoop() == null ? "" : testCaseStep.getLoop());628 preStat.setString(i++, testCaseStep.getConditionOperator() == null ? "" : testCaseStep.getConditionOperator());629 preStat.setString(i++, testCaseStep.getConditionOptions() == null ? "[]" : testCaseStep.getConditionOptions().toString());630 preStat.setString(i++, testCaseStep.getConditionValue1() == null ? "" : testCaseStep.getConditionValue1());631 preStat.setString(i++, testCaseStep.getConditionValue2() == null ? "" : testCaseStep.getConditionValue2());632 preStat.setString(i++, testCaseStep.getConditionValue3() == null ? "" : testCaseStep.getConditionValue3());633 preStat.setBoolean(i++, testCaseStep.isExecutionForced());634 preStat.setString(i++, testCaseStep.getUsrCreated() == null ? "" : testCaseStep.getUsrCreated());635 preStat.executeUpdate();636 // Set the final message637 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME)638 .resolveDescription("OPERATION", "CREATE");639 } catch (SQLException exception) {640 LOG.error("Unable to execute query : " + exception.toString());641 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);642 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));643 } catch (Exception e) {644 LOG.warn("Unable to create TestCaseStep: " + e.getMessage(), e);645 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",646 e.toString());647 } finally {648 ans.setResultMessage(msg);649 }650 return ans;651 }652 private TestCaseStep loadFromResultSet(ResultSet resultSet) throws SQLException {653 if (resultSet == null) {654 return null;655 }656 String test = resultSet.getString("test") == null ? "" : resultSet.getString("test");657 String testcase = resultSet.getString("testcase") == null ? "" : resultSet.getString("testcase");658 int stepId = resultSet.getInt("stepId") == 0 ? 0 : resultSet.getInt("stepId");659 int sort = resultSet.getInt("sort");660 String loop = resultSet.getString("loop") == null ? "" : resultSet.getString("loop");661 String conditionOperator = resultSet.getString("conditionOperator") == null ? "" : resultSet.getString("conditionOperator");662 String conditionValue1 = resultSet.getString("conditionValue1") == null ? "" : resultSet.getString("conditionValue1");663 String conditionValue2 = resultSet.getString("conditionValue2") == null ? "" : resultSet.getString("conditionValue2");664 String conditionValue3 = resultSet.getString("conditionValue3") == null ? "" : resultSet.getString("conditionValue3");665 JSONArray conditionOptions = SqlUtil.getJSONArrayFromColumn(resultSet, "conditionOptions");666 String description = resultSet.getString("description") == null ? "" : resultSet.getString("description");...
loadFromResultSet
Using AI Code Generation
1public class TestCaseStepDAO {2 private static final Logger LOG = LogManager.getLogger(TestCaseStepDAO.class);3 private final String OBJECT_NAME = "TestCaseStep";4 private final String SQL_DUPLICATED_CODE = "23000";5 private final int MAX_ROW_SELECTED = 100000;6 public void loadFromResultSet(ResultSet resultSet, TestCaseStep testCaseStep) throws SQLException {7 testCaseStep.setTest(resultSet.getString("Test"));8 testCaseStep.setTestCase(resultSet.getString("TestCase"));9 testCaseStep.setStep(resultSet.getInt("Step"));10 testCaseStep.setLoop(resultSet.getInt("Loop"));11 testCaseStep.setLoopTo(resultSet.getInt("LoopTo"));12 testCaseStep.setSort(resultSet.getInt("sort"));13 testCaseStep.setConditionOperator(resultSet.getString("ConditionOperator"));14 testCaseStep.setConditionVal1(resultSet.getString("ConditionVal1"));15 testCaseStep.setConditionVal2(resultSet.getString("ConditionVal2"));16 testCaseStep.setConditionVal3(resultSet.getString("ConditionVal3"));17 testCaseStep.setUseStep(resultSet.getString("UseStep"));18 testCaseStep.setUseStepTest(resultSet.getString("UseStepTest"));19 testCaseStep.setUseStepTestCase(resultSet.getString("UseStepTestCase"));20 testCaseStep.setUseStepStep(resultSet.getInt("UseStepStep"));21 testCaseStep.setUseStepLoop(resultSet.getInt("UseStepLoop"));22 testCaseStep.setUseStepLoopTo(resultSet.getInt("UseStepLoopTo"));23 testCaseStep.setInLibrary(resultSet.getString("InLibrary"));24 testCaseStep.setLibraryStep(resultSet.getString("LibraryStep"));25 testCaseStep.setDescription(resultSet.getString("Description"));26 testCaseStep.setUsrCreated(resultSet.getString("UsrCreated"));27 testCaseStep.setDateCreated(resultSet.getTimestamp("DateCreated"));28 testCaseStep.setUsrModif(resultSet.getString("UsrModif"));29 testCaseStep.setDateModif(resultSet.getTimestamp("DateModif"));30 testCaseStep.setScreenshotFilename(resultSet.getString("screenshotFilename"));31 testCaseStep.setPageSourceFilename(resultSet.getString("pageSourceFilename"));32 testCaseStep.setSeleniumLogFilename(resultSet.getString("seleniumLogFilename"));33 testCaseStep.setVerbose(resultSet.getInt("Verbose"));34 testCaseStep.setsSLCertificate(resultSet.getString("SSLCertificate"));35 testCaseStep.setsSLCertificateKey(resultSet.getString("SSLCertificateKey"));36 testCaseStep.setsSLCertificatePassword(resultSet.getString("SSLCertificatePassword"));37 testCaseStep.setsSLCertificateKeyPassword(resultSet.getString("SSLCertificateKeyPassword"));38 testCaseStep.setsSLKeyStore(resultSet.getString("SSLKeyStore"));
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!!