Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.TestCaseStepActionExecutionDAO.loadFromResultset
Source:TestCaseStepActionExecutionDAO.java
...69 ResultSet resultSet = preStat.executeQuery();70 try {71 result = new ArrayList<TestCaseStepActionExecution>();72 while (resultSet.next()) {73 result.add(this.loadFromResultset(resultSet));74 }75 } catch (SQLException exception) {76 LOG.warn("Unable to execute query : " + exception.toString());77 } finally {78 resultSet.close();79 }80 } catch (SQLException exception) {81 LOG.warn("Unable to execute query : " + exception.toString());82 } finally {83 preStat.close();84 }85 } catch (SQLException exception) {86 LOG.warn("Unable to execute query : " + exception.toString());87 } finally {88 try {89 if (connection != null) {90 connection.close();91 }92 } catch (SQLException e) {93 LOG.warn(e.toString());94 }95 }96 return result;97 }98 @Override99 public AnswerList readByVarious1(long executionId, String test, String testCase, int step, int index) {100 MessageEvent msg;101 AnswerList answer = new AnswerList();102 List<TestCaseStepActionExecution> list = new ArrayList<TestCaseStepActionExecution>();103 StringBuilder query = new StringBuilder();104 query.append("SELECT * FROM testcasestepactionexecution exa ");105 query.append("where exa.id = ? and exa.test = ? and exa.testcase = ? and exa.step = ? and exa.index = ? ");106 // Debug message on SQL.107 if (LOG.isDebugEnabled()) {108 LOG.debug("SQL : " + query.toString());109 }110 Connection connection = this.databaseSpring.connect();111 try {112 PreparedStatement preStat = connection.prepareStatement(query.toString());113 try {114 preStat.setLong(1, executionId);115 preStat.setString(2, test);116 preStat.setString(3, testCase);117 preStat.setInt(4, step);118 preStat.setInt(5, index);119 ResultSet resultSet = preStat.executeQuery();120 try {121 while (resultSet.next()) {122 list.add(this.loadFromResultset(resultSet));123 }124 if (list.isEmpty()) {125 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);126 } else {127 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);128 }129 } catch (SQLException exception) {130 LOG.error("Unable to execute query : " + exception.toString());131 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);132 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));133 list.clear();134 } finally {135 if (resultSet != null) {136 resultSet.close();137 }138 }139 } catch (SQLException exception) {140 LOG.error("Unable to execute query : " + exception.toString());141 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);142 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));143 } finally {144 if (preStat != null) {145 preStat.close();146 }147 }148 } catch (SQLException exception) {149 LOG.error("Unable to execute query : " + exception.toString());150 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);151 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));152 } finally {153 try {154 if (connection != null) {155 connection.close();156 }157 } catch (SQLException exception) {158 LOG.warn("Unable to close connection : " + exception.toString());159 }160 }161 answer.setTotalRows(list.size());162 answer.setDataList(list);163 answer.setResultMessage(msg);164 return answer;165 }166 @Override167 public AnswerItem readByKey(long executionId, String test, String testCase, int step, int index, int sequence) {168 MessageEvent msg;169 AnswerItem answer = new AnswerItem();170 TestCaseStepActionExecution tcsa = null;171 StringBuilder query = new StringBuilder();172 query.append("SELECT * FROM testcasestepactionexecution exa ");173 query.append("where exa.id = ? and exa.test = ? and exa.testcase = ? and exa.step = ? and exa.index = ? and exa.sequence = .");174 // Debug message on SQL.175 if (LOG.isDebugEnabled()) {176 LOG.debug("SQL : " + query.toString());177 }178 Connection connection = this.databaseSpring.connect();179 try {180 PreparedStatement preStat = connection.prepareStatement(query.toString());181 try {182 preStat.setLong(1, executionId);183 preStat.setString(2, test);184 preStat.setString(3, testCase);185 preStat.setInt(4, step);186 preStat.setInt(5, index);187 preStat.setInt(6, sequence);188 ResultSet resultSet = preStat.executeQuery();189 try {190 while (resultSet.next()) {191 tcsa = this.loadFromResultset(resultSet);192 }193 if (tcsa == null) {194 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);195 } else {196 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);197 }198 } catch (SQLException exception) {199 LOG.error("Unable to execute query : " + exception.toString());200 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);201 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));202 } finally {203 if (resultSet != null) {204 resultSet.close();205 }206 }207 } catch (SQLException exception) {208 LOG.error("Unable to execute query : " + exception.toString());209 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);210 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));211 } finally {212 if (preStat != null) {213 preStat.close();214 }215 }216 } catch (SQLException exception) {217 LOG.error("Unable to execute query : " + exception.toString());218 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);219 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));220 } finally {221 try {222 if (connection != null) {223 connection.close();224 }225 } catch (SQLException exception) {226 LOG.warn("Unable to close connection : " + exception.toString());227 }228 }229 answer.setItem(tcsa);230 answer.setResultMessage(msg);231 return answer;232 }233 @Override234 @Deprecated235 public List<List<String>> getListOfSequenceDuration(String idList) {236 List<List<String>> list = null;237 StringBuilder query = new StringBuilder();238 query.append("select a.ID, Step, Sequence, 'Action' as type, b.Start,");239 query.append("concat(substr(EndLong,1,4),'-',");240 query.append("substr(EndLong,5,2),'-',substr(EndLong,7,2),' ',substr(EndLong,9,2),");241 query.append("':',substr(EndLong,11,2),':',substr(EndLong,13,2),'.',");242 query.append("substr(EndLong,15,3)) as testEnd, concat(substr(StartLong,1,4),'-',");243 query.append("substr(StartLong,5,2),'-',substr(StartLong,7,2),' ',");244 query.append("substr(StartLong,9,2),':',substr(StartLong,11,2),':',");245 query.append("substr(StartLong,13,2),'.',substr(StartLong,15,3)) as testStart, a.`action` as ctrl ");246 query.append(" from testcasestepactionexecution a join testcaseexecution b on a.id=b.id where step != '0' and a.test!='Pre Testing' and a.id in (?)");247 query.append(" union select c.ID, c.Step, c.Sequence, 'Control', d.Start,");248 query.append("concat(substr(EndLong,1,4),'-',");249 query.append("substr(EndLong,5,2),'-',substr(EndLong,7,2),' ',substr(EndLong,9,2),");250 query.append("':',substr(EndLong,11,2),':',substr(EndLong,13,2),'.',");251 query.append("substr(EndLong,15,3)) as testEnd, concat(substr(StartLong,1,4),'-',");252 query.append("substr(StartLong,5,2),'-',substr(StartLong,7,2),' ',");253 query.append("substr(StartLong,9,2),':',substr(StartLong,11,2),':',");254 query.append("substr(StartLong,13,2),'.',substr(StartLong,15,3)) as testStart, c.`control` as ctrl ");255 query.append(" from testcasestepactioncontrolexecution c join testcaseexecution d on c.id=d.id where step != '0' and c.test!='Pre Testing' and c.id in (?)");256 query.append(" order by step, sequence,ctrl, type, ID");257 Connection connection = this.databaseSpring.connect();258 try {259 PreparedStatement preStat = connection.prepareStatement(query.toString());260 preStat.setString(1, idList);261 preStat.setString(2, idList);262 LOG.warn(query.toString());263 try {264 ResultSet resultSet = preStat.executeQuery();265 list = new ArrayList<List<String>>();266 try {267 while (resultSet.next()) {268 List<String> array = new ArrayList<String>();269 array.add(resultSet.getString(1));270 array.add(resultSet.getString(2));271 array.add(resultSet.getString(3));272 array.add(resultSet.getString(4));273 array.add(resultSet.getString(5));274 array.add(resultSet.getString(6));275 array.add(resultSet.getString(7));276 array.add(resultSet.getString(8));277 list.add(array);278 }279 } catch (SQLException exception) {280 LOG.warn("Unable to execute query : " + exception.toString());281 } finally {282 resultSet.close();283 }284 } catch (SQLException exception) {285 LOG.warn("Unable to execute query : " + exception.toString());286 } finally {287 preStat.close();288 }289 } catch (SQLException exception) {290 LOG.warn("Unable to execute query : " + exception.toString());291 } finally {292 try {293 if (connection != null) {294 connection.close();295 }296 } catch (SQLException e) {297 LOG.warn(e.toString());298 }299 }300 return list;301 }302 @Override303 public void insertTestCaseStepActionExecution(TestCaseStepActionExecution testCaseStepActionExecution) {304 final String query = "INSERT INTO testcasestepactionexecution(id, step, `index`, sequence, sort, "305 + "conditionOper, conditionVal1Init, conditionVal2Init, conditionVal1, conditionVal2, ACTION, value1Init, value2Init, value1, value2, forceExeStatus, "306 + "start, END, startlong, endlong, returnCode, returnMessage, test, testcase, description) "307 + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";308 // Debug message on SQL.309 if (LOG.isDebugEnabled()) {310 LOG.debug("SQL : " + query);311 LOG.debug("SQL.param.id : " + testCaseStepActionExecution.getId());312 LOG.debug("SQL.param.test : " + testCaseStepActionExecution.getTest());313 LOG.debug("SQL.param.testcase : " + testCaseStepActionExecution.getTestCase());314 LOG.debug("SQL.param.step : " + testCaseStepActionExecution.getStep());315 LOG.debug("SQL.param.index : " + testCaseStepActionExecution.getIndex());316 LOG.debug("SQL.param.sequence : " + testCaseStepActionExecution.getSequence());317 }318 Connection connection = this.databaseSpring.connect();319 try {320 PreparedStatement preStat = connection.prepareStatement(query);321 try {322 int i = 1;323 preStat.setLong(i++, testCaseStepActionExecution.getId());324 preStat.setInt(i++, testCaseStepActionExecution.getStep());325 preStat.setInt(i++, testCaseStepActionExecution.getIndex());326 preStat.setInt(i++, testCaseStepActionExecution.getSequence());327 preStat.setInt(i++, testCaseStepActionExecution.getSort());328 preStat.setString(i++, testCaseStepActionExecution.getConditionOper());329 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getConditionVal1Init(), 65000));330 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getConditionVal2Init(), 65000));331 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getConditionVal1(), 65000));332 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getConditionVal2(), 65000));333 preStat.setString(i++, testCaseStepActionExecution.getAction());334 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getValue1Init(), 65000));335 preStat.setString(i++, StringUtil.getLeftString(ParameterParserUtil.securePassword(testCaseStepActionExecution.getValue2Init(), testCaseStepActionExecution.getPropertyName()), 65000));336 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getValue1(), 65000));337 preStat.setString(i++, StringUtil.getLeftString(ParameterParserUtil.securePassword(testCaseStepActionExecution.getValue2(), testCaseStepActionExecution.getPropertyName()), 65000));338 preStat.setString(i++, testCaseStepActionExecution.getForceExeStatus());339 if (testCaseStepActionExecution.getStart() != 0) {340 preStat.setTimestamp(i++, new Timestamp(testCaseStepActionExecution.getStart()));341 } else {342 preStat.setString(i++, "1970-01-01 01:01:01");343 }344 if (testCaseStepActionExecution.getEnd() != 0) {345 preStat.setTimestamp(i++, new Timestamp(testCaseStepActionExecution.getEnd()));346 } else {347 preStat.setString(i++, "1970-01-01 01:01:01");348 }349 DateFormat df = new SimpleDateFormat(DateUtil.DATE_FORMAT_TIMESTAMP);350 preStat.setString(i++, df.format(testCaseStepActionExecution.getStart()));351 preStat.setString(i++, df.format(testCaseStepActionExecution.getEnd()));352 preStat.setString(i++, testCaseStepActionExecution.getReturnCode());353 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getReturnMessage(), 65000));354 preStat.setString(i++, testCaseStepActionExecution.getTest());355 preStat.setString(i++, testCaseStepActionExecution.getTestCase());356 preStat.setString(i++, testCaseStepActionExecution.getDescription());357 preStat.executeUpdate();358 } catch (SQLException exception) {359 LOG.error("Unable to execute query : " + exception.toString());360 } finally {361 preStat.close();362 }363 } catch (SQLException exception) {364 LOG.error("Unable to execute query : " + exception.toString());365 } finally {366 try {367 if (connection != null) {368 connection.close();369 }370 } catch (SQLException e) {371 LOG.warn(e.toString());372 }373 }374 }375 @Override376 public void updateTestCaseStepActionExecution(TestCaseStepActionExecution testCaseStepActionExecution) {377 final String query = "UPDATE testcasestepactionexecution SET ACTION = ?, value1 = ?, value2 = ?, forceExeStatus = ?, start = ?, END = ?"378 + ", startlong = ?, endlong = ?, returnCode = ?, returnMessage = ?, description = ?, sort = ?"379 + ", value1Init = ?, Value2Init = ?, conditionOper = ?, conditionVal1 = ?, conditionVal2 = ?, conditionVal1Init = ?, conditionVal2Init = ?"380 + " WHERE id = ? AND test = ? AND testcase = ? AND step = ? AND `index` = ? AND sequence = ? ;";381 // Debug message on SQL.382 if (LOG.isDebugEnabled()) {383 LOG.debug("SQL : " + query);384 LOG.debug("SQL.param.id : " + testCaseStepActionExecution.getId());385 LOG.debug("SQL.param.test : " + testCaseStepActionExecution.getTest());386 LOG.debug("SQL.param.testcase : " + testCaseStepActionExecution.getTestCase());387 LOG.debug("SQL.param.step : " + testCaseStepActionExecution.getStep());388 LOG.debug("SQL.param.index : " + testCaseStepActionExecution.getIndex());389 LOG.debug("SQL.param.sequence : " + testCaseStepActionExecution.getSequence());390 }391 Connection connection = this.databaseSpring.connect();392 try {393 PreparedStatement preStat = connection.prepareStatement(query);394 try {395 int i = 1;396 preStat.setString(i++, testCaseStepActionExecution.getAction());397 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getValue1(), 65000));398 preStat.setString(i++, StringUtil.getLeftString(ParameterParserUtil.securePassword(testCaseStepActionExecution.getValue2(), testCaseStepActionExecution.getPropertyName()), 65000));399 preStat.setString(i++, testCaseStepActionExecution.getForceExeStatus());400 if (testCaseStepActionExecution.getStart() != 0) {401 preStat.setTimestamp(i++, new Timestamp(testCaseStepActionExecution.getStart()));402 } else {403 preStat.setString(i++, "1970-01-01 01:01:01");404 }405 if (testCaseStepActionExecution.getEnd() != 0) {406 preStat.setTimestamp(i++, new Timestamp(testCaseStepActionExecution.getEnd()));407 } else {408 preStat.setString(i++, "1970-01-01 01:01:01");409 }410 DateFormat df = new SimpleDateFormat(DateUtil.DATE_FORMAT_TIMESTAMP);411 preStat.setString(i++, df.format(testCaseStepActionExecution.getStart()));412 preStat.setString(i++, df.format(testCaseStepActionExecution.getEnd()));413 preStat.setString(i++, testCaseStepActionExecution.getReturnCode());414 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getReturnMessage(), 65000));415 preStat.setString(i++, testCaseStepActionExecution.getDescription());416 preStat.setInt(i++, testCaseStepActionExecution.getSort());417 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getValue1Init(), 65000));418 preStat.setString(i++, StringUtil.getLeftString(ParameterParserUtil.securePassword(testCaseStepActionExecution.getValue2Init(), testCaseStepActionExecution.getPropertyName()), 65000));419 preStat.setString(i++, testCaseStepActionExecution.getConditionOper());420 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getConditionVal1(), 65000));421 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getConditionVal2(), 65000));422 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getConditionVal1Init(), 65000));423 preStat.setString(i++, StringUtil.getLeftString(testCaseStepActionExecution.getConditionVal2Init(), 65000));424 preStat.setLong(i++, testCaseStepActionExecution.getId());425 preStat.setString(i++, testCaseStepActionExecution.getTest());426 preStat.setString(i++, testCaseStepActionExecution.getTestCase());427 preStat.setInt(i++, testCaseStepActionExecution.getStep());428 preStat.setInt(i++, testCaseStepActionExecution.getIndex());429 preStat.setInt(i++, testCaseStepActionExecution.getSequence());430 preStat.executeUpdate();431 } catch (SQLException exception) {432 LOG.error("Unable to execute query : " + exception.toString());433 } finally {434 preStat.close();435 }436 } catch (SQLException exception) {437 LOG.error("Unable to execute query : " + exception.toString());438 } finally {439 try {440 if (connection != null) {441 connection.close();442 }443 } catch (SQLException e) {444 LOG.warn(e.toString());445 }446 }447 }448 @Override449 public TestCaseStepActionExecution loadFromResultset(ResultSet resultSet) throws SQLException {450 long id = resultSet.getInt("exa.id");451 String test = resultSet.getString("exa.test");452 String testCase = resultSet.getString("exa.testcase");453 int step = resultSet.getInt("exa.step");454 int index = resultSet.getInt("exa.index");455 int seq = resultSet.getInt("exa.sequence");456 int sort = resultSet.getInt("exa.sort");457 String returnCode = resultSet.getString("exa.returncode");458 String returnMessage = resultSet.getString("exa.returnmessage");459 String conditionOper = resultSet.getString("exa.ConditionOper");460 String conditionVal1Init = resultSet.getString("exa.ConditionVal1Init");461 String conditionVal2Init = resultSet.getString("exa.ConditionVal2Init");462 String conditionVal1 = resultSet.getString("exa.ConditionVal1");463 String conditionVal2 = resultSet.getString("exa.ConditionVal2");...
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!!