How to use loadFromResultSet method of org.cerberus.crud.dao.impl.TestCaseStepActionDAO class

Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.TestCaseStepActionDAO.loadFromResultSet

Source:TestCaseStepActionDAO.java Github

copy

Full Screen

...70 preStat.setInt(4, sequence);71 ResultSet resultSet = preStat.executeQuery();72 try {73 if (resultSet.first()) {74 testCaseStepAction = this.loadFromResultSet(resultSet);75 }76 } catch (SQLException exception) {77 LOG.warn("Unable to execute query : " + exception.toString());78 } finally {79 if (resultSet != null) {80 resultSet.close();81 }82 }83 } catch (SQLException exception) {84 LOG.warn("Unable to execute query : " + exception.toString());85 } finally {86 if (preStat != null) {87 preStat.close();88 }89 }90 } catch (SQLException exception) {91 LOG.warn("Unable to execute query : " + exception.toString());92 } finally {93 try {94 if (connection != null) {95 connection.close();96 }97 } catch (SQLException e) {98 LOG.warn(e.toString());99 }100 }101 return testCaseStepAction;102 }103 @Override104 public List<TestCaseStepAction> findTestCaseStepActionbyTestTestCase(String test, String testCase) throws CerberusException {105 List<TestCaseStepAction> list = null;106 final StringBuilder query = new StringBuilder();107 query.append("SELECT tca.* ");108 query.append("FROM testcasestepaction AS tca ");109 query.append("RIGHT JOIN testcasestep AS tcs ON tca.Test = tcs.Test AND tca.TestCase = tcs.TestCase AND tca.Step = tcs.Step ");110 query.append("WHERE tca.Test = ? AND tca.TestCase = ? ");111 query.append("GROUP BY tca.Test, tca.TestCase, tca.Step, tca.Sequence ");112 query.append("ORDER BY tcs.Sort, tca.Sort ");113 Connection connection = this.databaseSpring.connect();114 try {115 PreparedStatement preStat = connection.prepareStatement(query.toString());116 try {117 preStat.setString(1, test);118 preStat.setString(2, testCase);119 ResultSet resultSet = preStat.executeQuery();120 try {121 list = new ArrayList<TestCaseStepAction>();122 while (resultSet.next()) {123 list.add(this.loadFromResultSet(resultSet));124 }125 } catch (SQLException exception) {126 LOG.warn("Unable to execute query : " + exception.toString());127 } finally {128 if (resultSet != null) {129 resultSet.close();130 }131 }132 } catch (SQLException exception) {133 LOG.warn("Unable to execute query : " + exception.toString());134 } finally {135 if (preStat != null) {136 preStat.close();137 }138 }139 } catch (SQLException exception) {140 LOG.warn("Unable to execute query : " + exception.toString());141 } finally {142 try {143 if (connection != null) {144 connection.close();145 }146 } catch (SQLException e) {147 LOG.warn(e.toString());148 }149 }150 return list;151 }152 @Override153 public List<TestCaseStepAction> findActionByTestTestCaseStep(String test, String testcase, int stepNumber) {154 List<TestCaseStepAction> list = null;155 final String query = "SELECT * FROM testcasestepaction tca WHERE tca.test = ? AND tca.testcase = ? AND tca.step = ? ORDER BY tca.sort";156 Connection connection = this.databaseSpring.connect();157 try {158 PreparedStatement preStat = connection.prepareStatement(query);159 try {160 preStat.setString(1, test);161 preStat.setString(2, testcase);162 preStat.setInt(3, stepNumber);163 ResultSet resultSet = preStat.executeQuery();164 try {165 list = new ArrayList<TestCaseStepAction>();166 while (resultSet.next()) {167 list.add(this.loadFromResultSet(resultSet));168 }169 } catch (SQLException exception) {170 LOG.warn("Unable to execute query : " + exception.toString());171 } finally {172 if (resultSet != null) {173 resultSet.close();174 }175 }176 } catch (SQLException exception) {177 LOG.warn("Unable to execute query : " + exception.toString());178 } finally {179 if (preStat != null) {180 preStat.close();181 }182 }183 } catch (SQLException exception) {184 LOG.warn("Unable to execute query : " + exception.toString());185 } finally {186 try {187 if (connection != null) {188 connection.close();189 }190 } catch (SQLException e) {191 LOG.warn(e.toString());192 }193 }194 return list;195 }196 @Override197 public AnswerList readByTestTestCase(String test, String testcase) {198 AnswerList response = new AnswerList();199 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);200 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));201 List<TestCaseStepAction> actionList = new ArrayList<TestCaseStepAction>();202 StringBuilder query = new StringBuilder();203 query.append("SELECT * FROM testcasestepaction tca WHERE tca.test = ? AND tca.testcase = ?");204 Connection connection = this.databaseSpring.connect();205 try {206 PreparedStatement preStat = connection.prepareStatement(query.toString());207 try {208 preStat.setString(1, test);209 preStat.setString(2, testcase);210 ResultSet resultSet = preStat.executeQuery();211 try {212 //gets the data213 while (resultSet.next()) {214 actionList.add(this.loadFromResultSet(resultSet));215 }216 //get the total number of rows217 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");218 int nrTotalRows = 0;219 if (resultSet != null && resultSet.next()) {220 nrTotalRows = resultSet.getInt(1);221 }222 if (actionList.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.223 LOG.error("Partial Result in the query.");224 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);225 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));226 response = new AnswerList(actionList, actionList.size());227 } else if (actionList.size() <= 0) {228 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);229 response = new AnswerList(actionList, actionList.size());230 } else {231 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);232 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));233 response = new AnswerList(actionList, actionList.size());234 }235 } catch (SQLException exception) {236 LOG.error("Unable to execute query : " + exception.toString());237 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);238 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));239 } finally {240 if (resultSet != null) {241 resultSet.close();242 }243 }244 } catch (SQLException exception) {245 LOG.error("Unable to execute query : " + exception.toString());246 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);247 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));248 } finally {249 if (preStat != null) {250 preStat.close();251 }252 }253 } catch (SQLException exception) {254 LOG.error("Unable to execute query : " + exception.toString());255 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);256 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));257 } finally {258 try {259 if (!this.databaseSpring.isOnTransaction()) {260 if (connection != null) {261 connection.close();262 }263 }264 } catch (SQLException exception) {265 LOG.warn("Unable to close connection : " + exception.toString());266 }267 }268 response.setResultMessage(msg);269 return response;270 }271 @Override272 public AnswerList readByVarious1(String test, String testcase, int step) {273 AnswerList response = new AnswerList();274 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);275 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));276 List<TestCaseStepAction> actionList = new ArrayList<TestCaseStepAction>();277 StringBuilder query = new StringBuilder();278 query.append("SELECT * FROM testcasestepaction tca WHERE tca.test = ? AND tca.testcase = ? AND tca.step = ?");279 Connection connection = this.databaseSpring.connect();280 try {281 PreparedStatement preStat = connection.prepareStatement(query.toString());282 try {283 preStat.setString(1, test);284 preStat.setString(2, testcase);285 preStat.setInt(3, step);286 ResultSet resultSet = preStat.executeQuery();287 try {288 //gets the data289 while (resultSet.next()) {290 actionList.add(this.loadFromResultSet(resultSet));291 }292 //get the total number of rows293 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");294 int nrTotalRows = 0;295 if (resultSet != null && resultSet.next()) {296 nrTotalRows = resultSet.getInt(1);297 }298 if (actionList.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.299 LOG.error("Partial Result in the query.");300 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);301 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));302 response = new AnswerList(actionList, actionList.size());303 } else if (actionList.size() <= 0) {304 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);305 response = new AnswerList(actionList, actionList.size());306 } else {307 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);308 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));309 response = new AnswerList(actionList, actionList.size());310 }311 } catch (SQLException exception) {312 LOG.error("Unable to execute query : " + exception.toString());313 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);314 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));315 } finally {316 if (resultSet != null) {317 resultSet.close();318 }319 }320 } catch (SQLException exception) {321 LOG.error("Unable to execute query : " + exception.toString());322 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);323 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));324 } finally {325 if (preStat != null) {326 preStat.close();327 }328 }329 } catch (SQLException exception) {330 LOG.error("Unable to execute query : " + exception.toString());331 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);332 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));333 } finally {334 try {335 if (!this.databaseSpring.isOnTransaction()) {336 if (connection != null) {337 connection.close();338 }339 }340 } catch (SQLException exception) {341 LOG.warn("Unable to close connection : " + exception.toString());342 }343 }344 response.setResultMessage(msg);345 return response;346 }347 @Override348 public void createTestCaseStepAction(TestCaseStepAction testCaseStepAction) throws CerberusException {349 boolean throwExcep = false;350 StringBuilder query = new StringBuilder();351 query.append("INSERT INTO testcasestepaction (`test`, `testCase`, `step`, `sequence`, `sort`, `conditionOper`, `conditionVal1`, `conditionVal2`, `action`, `value1`, `value2`, `ForceExeStatus`, `description`, `screenshotfilename`) ");352 query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");353 Connection connection = this.databaseSpring.connect();354 try {355 PreparedStatement preStat = connection.prepareStatement(query.toString());356 try {357 preStat.setString(1, testCaseStepAction.getTest());358 preStat.setString(2, testCaseStepAction.getTestCase());359 preStat.setInt(3, testCaseStepAction.getStep());360 preStat.setInt(4, testCaseStepAction.getSequence());361 preStat.setInt(5, testCaseStepAction.getSort());362 preStat.setString(6, testCaseStepAction.getConditionOper());363 preStat.setString(7, testCaseStepAction.getConditionVal1());364 preStat.setString(8, testCaseStepAction.getConditionVal2());365 preStat.setString(9, testCaseStepAction.getAction());366 preStat.setString(10, testCaseStepAction.getValue1());367 preStat.setString(11, testCaseStepAction.getValue2());368 preStat.setString(12, testCaseStepAction.getForceExeStatus());369 preStat.setString(13, testCaseStepAction.getDescription());370 preStat.setString(14, testCaseStepAction.getScreenshotFilename());371 preStat.executeUpdate();372 throwExcep = false;373 } catch (SQLException exception) {374 LOG.warn("Unable to execute query : " + exception.toString());375 } finally {376 if (preStat != null) {377 preStat.close();378 }379 }380 } catch (SQLException exception) {381 LOG.warn("Unable to execute query : " + exception.toString());382 } finally {383 try {384 if (connection != null) {385 connection.close();386 }387 } catch (SQLException e) {388 LOG.warn(e.toString());389 }390 }391 if (throwExcep) {392 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));393 }394 }395 @Override396 public void update(TestCaseStepAction testCaseStepAction) throws CerberusException {397 boolean throwExcep = false;398 final String query = new StringBuilder("UPDATE `testcasestepaction` ")399 .append("SET ")400 .append("`Test` = ?, ")401 .append("`TestCase` = ?, ")402 .append("`Step` = ?, ")403 .append("`Sequence` = ?, ")404 .append("`Sort` = ?, ")405 .append("`ConditionOper` = ?, ")406 .append("`ConditionVal1` = ?, ")407 .append("`ConditionVal2` = ?, ")408 .append("`Action` = ?, ")409 .append("`Value1` = ?, ")410 .append("`Value2` = ?, ")411 .append("`ForceExeStatus` = ?, ")412 .append("`Description` = ?, ")413 .append("`ScreenshotFilename` = ? ")414 .append("WHERE `Test` = ? AND `TestCase` = ? AND `Step` = ? AND `Sequence` = ? ")415 .toString();416 417 LOG.debug("SQL " + query);418 LOG.debug("SQL.param.conditionOper " + testCaseStepAction.getConditionOper());419 LOG.debug("SQL.param.conditionVal1 " + testCaseStepAction.getConditionVal1());420 LOG.debug("SQL.param.conditionVal2 " + testCaseStepAction.getConditionVal2());421 Connection connection = this.databaseSpring.connect();422 try {423 PreparedStatement preStat = connection.prepareStatement(query);424 try {425 int i=1;426 preStat.setString(i++, testCaseStepAction.getTest());427 preStat.setString(i++, testCaseStepAction.getTestCase());428 preStat.setInt(i++, testCaseStepAction.getStep());429 preStat.setInt(i++, testCaseStepAction.getSequence());430 preStat.setInt(i++, testCaseStepAction.getSort());431 preStat.setString(i++, testCaseStepAction.getConditionOper());432 preStat.setString(i++, testCaseStepAction.getConditionVal1());433 preStat.setString(i++, testCaseStepAction.getConditionVal2());434 preStat.setString(i++, testCaseStepAction.getAction());435 preStat.setString(i++, testCaseStepAction.getValue1());436 preStat.setString(i++, testCaseStepAction.getValue2());437 preStat.setString(i++, testCaseStepAction.getForceExeStatus());438 preStat.setString(i++, testCaseStepAction.getDescription());439 preStat.setString(i++, testCaseStepAction.getScreenshotFilename());440 preStat.setString(i++, testCaseStepAction.getTest());441 preStat.setString(i++, testCaseStepAction.getTestCase());442 preStat.setInt(i++, testCaseStepAction.getStep());443 preStat.setInt(i++, testCaseStepAction.getSequence());444 preStat.executeUpdate();445 throwExcep = false;446 } catch (SQLException exception) {447 LOG.warn("Unable to execute query : " + exception.toString());448 } finally {449 if (preStat != null) {450 preStat.close();451 }452 }453 } catch (SQLException exception) {454 LOG.warn("Unable to execute query : " + exception.toString());455 } finally {456 try {457 if (connection != null) {458 connection.close();459 }460 } catch (SQLException e) {461 LOG.warn(e.toString());462 }463 }464 if (throwExcep) {465 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));466 }467 }468 @Override469 public void delete(TestCaseStepAction tcsa) throws CerberusException {470 boolean throwExcep = false;471 final String query = "DELETE FROM testcasestepaction WHERE test = ? and testcase = ? and step = ? and `sequence` = ?";472 Connection connection = this.databaseSpring.connect();473 try {474 PreparedStatement preStat = connection.prepareStatement(query);475 try {476 preStat.setString(1, tcsa.getTest());477 preStat.setString(2, tcsa.getTestCase());478 preStat.setInt(3, tcsa.getStep());479 preStat.setInt(4, tcsa.getSequence());480 throwExcep = preStat.executeUpdate() == 0;481 } catch (SQLException exception) {482 LOG.warn("Unable to execute query : " + exception.toString());483 } finally {484 if (preStat != null) {485 preStat.close();486 }487 }488 } catch (SQLException exception) {489 LOG.warn("Unable to execute query : " + exception.toString());490 } finally {491 try {492 if (connection != null) {493 connection.close();494 }495 } catch (SQLException e) {496 LOG.warn(e.toString());497 }498 }499 if (throwExcep) {500 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));501 }502 }503 @Override504 public boolean changeTestCaseStepActionSequence(String test, String testCase, int step, int oldSequence, int newSequence) {505 TestCaseStepAction testCaseStepAction = null;506 final String query = "update testcasestepaction set sequence = ? WHERE test = ? AND testcase = ? AND step = ? AND sequence = ?";507 Connection connection = this.databaseSpring.connect();508 try {509 PreparedStatement preStat = connection.prepareStatement(query);510 try {511 preStat.setInt(1, newSequence);512 preStat.setString(2, test);513 preStat.setString(3, testCase);514 preStat.setInt(4, step);515 preStat.setInt(5, oldSequence);516 int lines = preStat.executeUpdate();517 return (lines > 0);518 } catch (SQLException exception) {519 LOG.warn("Unable to execute query : " + exception.toString());520 } finally {521 if (preStat != null) {522 preStat.close();523 }524 }525 } catch (SQLException exception) {526 LOG.warn("Unable to execute query : " + exception.toString());527 } finally {528 try {529 if (connection != null) {530 connection.close();531 }532 } catch (SQLException e) {533 LOG.warn(e.toString());534 }535 }536 return false;537 }538 @Override539 public Answer create(TestCaseStepAction testCaseStepAction) {540 Answer ans = new Answer();541 MessageEvent msg = null;542 StringBuilder query = new StringBuilder();543 query.append("INSERT INTO testcasestepaction (`test`, `testCase`, `step`, `sequence`, `sort`, `conditionOper`, `conditionVal1`, `conditionVal2`, `action`, `Value1`, `Value2`, `ForceExeStatus`, `description`, `screenshotfilename`) ");544 query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");545 try (Connection connection = databaseSpring.connect();546 PreparedStatement preStat = connection.prepareStatement(query.toString())) {547 // Prepare and execute query548 preStat.setString(1, testCaseStepAction.getTest());549 preStat.setString(2, testCaseStepAction.getTestCase());550 preStat.setInt(3, testCaseStepAction.getStep());551 preStat.setInt(4, testCaseStepAction.getSequence());552 preStat.setInt(5, testCaseStepAction.getSort());553 preStat.setString(6, testCaseStepAction.getConditionOper());554 preStat.setString(7, testCaseStepAction.getConditionVal1());555 preStat.setString(8, testCaseStepAction.getConditionVal2());556 preStat.setString(9, testCaseStepAction.getAction());557 preStat.setString(10, testCaseStepAction.getValue1());558 preStat.setString(11, testCaseStepAction.getValue2());559 preStat.setString(12, testCaseStepAction.getForceExeStatus());560 preStat.setString(13, testCaseStepAction.getDescription());561 preStat.setString(14, testCaseStepAction.getScreenshotFilename());562 preStat.executeUpdate();563 // Set the final message564 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME)565 .resolveDescription("OPERATION", "CREATE");566 } catch (Exception e) {567 LOG.warn("Unable to create TestCaseStepAction: " + e.getMessage());568 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",569 e.toString());570 } finally {571 ans.setResultMessage(msg);572 }573 return ans;574 }575 private TestCaseStepAction loadFromResultSet(ResultSet resultSet) throws SQLException {576 String test = resultSet.getString("tca.Test");577 String testCase = resultSet.getString("tca.TestCase");578 Integer step = resultSet.getInt("tca.Step");579 Integer sequence = resultSet.getInt("tca.Sequence");580 Integer sort = resultSet.getInt("tca.Sort");581 String conditionOper = resultSet.getString("tca.ConditionOper");582 String conditionVal1 = resultSet.getString("tca.ConditionVal1");583 String conditionVal2 = resultSet.getString("tca.ConditionVal2");584 String action = resultSet.getString("tca.Action");585 String value1 = resultSet.getString("tca.Value1");586 String value2 = resultSet.getString("tca.Value2");587 String description = resultSet.getString("tca.description");588 String screenshotFilename = resultSet.getString("tca.screenshotFilename");589 String forceExeStatus = resultSet.getString("tca.forceExeStatus");...

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