How to use loadTestCaseExecutionAndApplicationFromResultSet method of org.cerberus.crud.dao.impl.TestCaseExecutionDAO class

Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.TestCaseExecutionDAO.loadTestCaseExecutionAndApplicationFromResultSet

Source:TestCaseExecutionDAO.java Github

copy

Full Screen

...476 PreparedStatement preStat = connection.prepareStatement(query);) {477 preStat.setLong(1, id);478 try (ResultSet resultSet = preStat.executeQuery();) {479 if (resultSet.first()) {480 result = this.loadTestCaseExecutionAndApplicationFromResultSet(resultSet);481 }482 } catch (SQLException exception) {483 LOG.error("Unable to execute query : " + exception.toString());484 }485 } catch (SQLException exception) {486 LOG.error("Unable to execute query : " + exception.toString());487 }488 return result;489 }490 @Override491 public TestCaseExecution findLastTestCaseExecutionNotPE(String test, String testCase) throws CerberusException {492 TestCaseExecution result = null;493 StringBuilder query = new StringBuilder();494 query.append("SELECT exe.* FROM `testcaseexecution` exe ");495 query.append(" WHERE Test = ? and TestCase= ? and ID = ");496 query.append(" (SELECT MAX(ID) from `testcaseexecution` ");497 query.append("WHERE Test= ? and TestCase= ? and ControlStatus!='PE')");498 try (Connection connection = this.databaseSpring.connect();499 PreparedStatement preStat = connection.prepareStatement(query.toString());) {500 preStat.setString(1, test);501 preStat.setString(2, testCase);502 preStat.setString(3, test);503 preStat.setString(4, testCase);504 try (ResultSet resultSet = preStat.executeQuery();) {505 if (resultSet.first()) {506 result = loadFromResultSet(resultSet);507 }508 } catch (SQLException exception) {509 LOG.error("Unable to execute query : " + exception.toString());510 }511 } catch (SQLException exception) {512 LOG.error("Unable to execute query : " + exception.toString());513 }514 return result;515 }516 @Override517 public TestCaseExecution findLastTCExecutionInGroup(String test, String testCase, String environment, String country,518 String build, String revision, String browser, String browserVersion,519 String ip, String port, String tag) {520 TestCaseExecution result = null;521 StringBuilder query = new StringBuilder();522 query.append("SELECT exe.* FROM testcaseexecution exe ")523 .append("WHERE exe.test = ? AND exe.testcase = ? AND exe.country = ? AND exe.browser = ? ");524 if (!StringUtil.isNull(environment)) {525 query.append("AND exe.environment IN (");526 query.append(environment);527 query.append(") ");528 }529 if (!StringUtil.isNull(build)) {530 query.append("AND exe.build IN (");531 query.append(build);532 query.append(") ");533 }534 if (!StringUtil.isNull(revision)) {535 query.append("AND exe.revision IN (");536 query.append(revision);537 query.append(") ");538 }539 if (!StringUtil.isNull(browserVersion)) {540 query.append("AND exe.browserfullversion LIKE ? ");541 }542 if (!StringUtil.isNull(ip)) {543 query.append("AND exe.ip LIKE ? ");544 }545 if (!StringUtil.isNull(port)) {546 query.append("AND exe.port LIKE ? ");547 }548 if (!StringUtil.isNull(tag)) {549 query.append("AND exe.tag LIKE ? ");550 }551 query.append("ORDER BY exe.id DESC");552 try (Connection connection = this.databaseSpring.connect();553 PreparedStatement preStat = connection.prepareStatement(query.toString());) {554 preStat.setString(1, test);555 preStat.setString(2, testCase);556 preStat.setString(3, country);557 preStat.setString(4, browser);558 int i = 5;559 if (!StringUtil.isNull(browserVersion)) {560 preStat.setString(i, browserVersion);561 i++;562 }563 if (!StringUtil.isNull(ip)) {564 preStat.setString(i, ip);565 i++;566 }567 if (!StringUtil.isNull(port)) {568 preStat.setString(i, port);569 i++;570 }571 if (!StringUtil.isNull(tag)) {572 preStat.setString(i, tag);573 }574 try (ResultSet resultSet = preStat.executeQuery();) {575 if (resultSet.first()) {576 result = this.loadFromResultSet(resultSet);577 }578 } catch (SQLException exception) {579 LOG.error("Unable to execute query : " + exception.toString());580 }581 } catch (SQLException exception) {582 LOG.error("Unable to execute query : " + exception.toString());583 }584 return result;585 }586 @Override587 public List<String> findDistinctTag(boolean withUUIDTag) throws CerberusException {588 List<String> list = null;589 StringBuilder query = new StringBuilder();590 query.append("select distinct tag from testcaseexecution exe ")591 .append("where tag != '' ");592 if (!withUUIDTag) {593 query.append(" and length(tag) != length('c3888898-c65a-11e3-9b3e-0000004047e0')");594 }595 query.append(" UNION select distinct tag from testcaseexecutionqueue where tag !='' ");596 Connection connection = this.databaseSpring.connect();597 try {598 PreparedStatement preStat = connection.prepareStatement(query.toString());599 try {600 ResultSet resultSet = preStat.executeQuery();601 try {602 list = new ArrayList<String>();603 while (resultSet.next()) {604 list.add(resultSet.getString("tag"));605 }606 } catch (SQLException exception) {607 LOG.error("Unable to execute query : " + exception.toString());608 } finally {609 resultSet.close();610 }611 } catch (SQLException exception) {612 LOG.error("Unable to execute query : " + exception.toString());613 } finally {614 preStat.close();615 }616 } catch (SQLException exception) {617 LOG.error("Unable to execute query : " + exception.toString());618 } finally {619 try {620 if (connection != null) {621 connection.close();622 }623 } catch (SQLException e) {624 LOG.warn(e.toString());625 }626 }627 return list;628 }629 @Override630 public void setTagToExecution(long id, String tag) throws CerberusException {631 boolean throwEx = false;632 final String query = "UPDATE testcaseexecution exe SET exe.tag = ? WHERE exe.id = ?";633 Connection connection = this.databaseSpring.connect();634 try {635 PreparedStatement preStat = connection.prepareStatement(query);636 try {637 preStat.setString(1, tag);638 preStat.setLong(2, id);639 preStat.executeUpdate();640 } catch (SQLException exception) {641 LOG.error("Unable to execute query : " + exception.toString());642 throwEx = true;643 } finally {644 preStat.close();645 }646 } catch (SQLException exception) {647 LOG.error("Unable to execute query : " + exception.toString());648 } finally {649 try {650 if (connection != null) {651 connection.close();652 }653 } catch (SQLException e) {654 LOG.warn(e.toString());655 }656 }657 if (throwEx) {658 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));659 }660 }661 @Override662 public List<TestCaseExecution> readByTagByCriteria(String tag, int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch) throws CerberusException {663 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);664 List<String> individalColumnSearchValues = new ArrayList<>();665 final StringBuffer query = new StringBuffer();666 query.append("SELECT * FROM testcaseexecution exe ");667 query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase ");668 query.append("left join application app on tec.application = app.application ");669 query.append("where exe.ID IN ");670 query.append("(select MAX(exe.ID) from testcaseexecution exe ");671 query.append("where 1=1 ");672 if (!StringUtil.isNullOrEmpty(tag)) {673 query.append("and exe.tag = ? ");674 }675 query.append("group by exe.test, exe.testcase, exe.Environment, exe.Browser, exe.Country) ");676 if (!StringUtil.isNullOrEmpty(searchTerm)) {677 query.append("and (exe.`test` like ? ");678 query.append(" or exe.`testCase` like ? ");679 query.append(" or exe.`application` like ? ");680 query.append(" or tec.`bugid` like ? ");681 query.append(" or tec.`priority` like ? ");682 query.append(" or tec.`description` like ? )");683 }684 if (individualSearch != null && !individualSearch.isEmpty()) {685 query.append(" and ( 1=1 ");686 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {687 query.append(" and ");688 query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));689 individalColumnSearchValues.addAll(entry.getValue());690 }691 query.append(" ) ");692 }693 if (!StringUtil.isNullOrEmpty(sort)) {694 query.append(" order by ").append(sort);695 }696 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {697 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);698 } else {699 query.append(" limit ").append(start).append(" , ").append(amount);700 }701 // Debug message on SQL.702 if (LOG.isDebugEnabled()) {703 LOG.debug("SQL : " + query.toString());704 LOG.debug("SQL.param.tag : " + tag);705 }706 return RequestDbUtils.executeQueryList(databaseSpring, query.toString(),707 preStat -> {708 int i = 1;709 if (!StringUtil.isNullOrEmpty(tag)) {710 preStat.setString(i++, tag);711 }712 if (!Strings.isNullOrEmpty(searchTerm)) {713 preStat.setString(i++, "%" + searchTerm + "%");714 preStat.setString(i++, "%" + searchTerm + "%");715 preStat.setString(i++, "%" + searchTerm + "%");716 preStat.setString(i++, "%" + searchTerm + "%");717 preStat.setString(i++, "%" + searchTerm + "%");718 preStat.setString(i++, "%" + searchTerm + "%");719 }720 for (String individualColumnSearchValue : individalColumnSearchValues) {721 preStat.setString(i++, individualColumnSearchValue);722 }723 },724 rs -> loadWithDependenciesFromResultSet(rs)725 );726 }727 @Override728 public AnswerList<TestCaseExecution> readByTag(String tag) throws CerberusException {729 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);730 AnswerList<TestCaseExecution> answer = new AnswerList<>();731 final StringBuffer query = new StringBuffer();732 query.append("SELECT * FROM testcaseexecution exe ");733 query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase ");734 query.append("left join application as app on tec.application = app.application ");735 query.append("where 1=1 and exe.tag = ? ");736 // Debug message on SQL.737 if (LOG.isDebugEnabled()) {738 LOG.debug("SQL : " + query.toString());739 LOG.debug("SQL.param.tag : " + tag);740 }741 List<TestCaseExecution> testCaseExecutionList = new ArrayList<>();742 Connection connection = this.databaseSpring.connect();743 try {744 PreparedStatement preStat = connection.prepareStatement(query.toString());745 preStat.setString(1, tag);746 try {747 ResultSet resultSet = preStat.executeQuery();748 try {749 while (resultSet.next()) {750 testCaseExecutionList.add(this.loadWithDependenciesFromResultSet(resultSet));751 }752 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));753 answer.setTotalRows(testCaseExecutionList.size());754 } catch (SQLException exception) {755 LOG.warn("Unable to execute query : " + exception.toString());756 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);757 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));758 testCaseExecutionList = null;759 } finally {760 resultSet.close();761 }762 } catch (SQLException exception) {763 LOG.warn("Unable to execute query : " + exception.toString());764 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);765 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));766 testCaseExecutionList = null;767 } finally {768 preStat.close();769 }770 } catch (SQLException exception) {771 LOG.warn("Unable to execute query : " + exception.toString());772 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);773 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));774 testCaseExecutionList = null;775 } finally {776 try {777 if (connection != null) {778 connection.close();779 }780 } catch (SQLException e) {781 LOG.warn(e.toString());782 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);783 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));784 }785 }786 answer.setResultMessage(msg);787 answer.setDataList(testCaseExecutionList);788 return answer;789 }790 @Override791 public Integer readNbByTag(String tag) throws CerberusException {792 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);793 Integer result = 0;794 final StringBuffer query = new StringBuffer();795 query.append("SELECT count(*) FROM testcaseexecution exe ");796 query.append("where 1=1 and exe.tag = ? ");797 // Debug message on SQL.798 if (LOG.isDebugEnabled()) {799 LOG.debug("SQL : " + query.toString());800 LOG.debug("SQL.param.tag : " + tag);801 }802 Connection connection = this.databaseSpring.connect();803 try {804 PreparedStatement preStat = connection.prepareStatement(query.toString());805 preStat.setString(1, tag);806 try {807 ResultSet resultSet = preStat.executeQuery();808 try {809 while (resultSet.next()) {810 result = resultSet.getInt(1);811 }812 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));813 } catch (SQLException exception) {814 LOG.warn("Unable to execute query : " + exception.toString());815 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);816 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));817 } finally {818 resultSet.close();819 }820 } catch (SQLException exception) {821 LOG.warn("Unable to execute query : " + exception.toString());822 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);823 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));824 } finally {825 preStat.close();826 }827 } catch (SQLException exception) {828 LOG.warn("Unable to execute query : " + exception.toString());829 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);830 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));831 } finally {832 try {833 if (connection != null) {834 connection.close();835 }836 } catch (SQLException e) {837 LOG.warn(e.toString());838 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);839 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));840 }841 }842 return result;843 }844 @Override845 public AnswerList<TestCaseExecution> readByCriteria(int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch, List<String> individualLike, List<String> system) throws CerberusException {846 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);847 AnswerList<TestCaseExecution> response = new AnswerList<>();848 List<String> individalColumnSearchValues = new ArrayList<>();849 List<TestCaseExecution> objectList = new ArrayList<>();850 final StringBuffer query = new StringBuffer();851 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testcaseexecution exe ");852 query.append("where 1=1 ");853 if (!StringUtil.isNullOrEmpty(searchTerm)) {854 query.append("and (exe.`id` like ? ");855 query.append(" or exe.`test` like ? ");856 query.append(" or exe.`testCase` like ? ");857 query.append(" or exe.`build` like ? ");858 query.append(" or exe.`revision` like ? ");859 query.append(" or exe.`environment` like ? ");860 query.append(" or exe.`country` like ? ");861 query.append(" or exe.`browser` like ? ");862 query.append(" or exe.`version` like ? ");863 query.append(" or exe.`platform` like ? ");864 query.append(" or exe.`browserfullversion` like ? ");865 query.append(" or exe.`start` like ? ");866 query.append(" or exe.`end` like ? ");867 query.append(" or exe.`controlstatus` like ? ");868 query.append(" or exe.`controlmessage` like ? ");869 query.append(" or exe.`application` like ? ");870 query.append(" or exe.`url` like ? ");871 query.append(" or exe.`robot` like ? ");872 query.append(" or exe.`robotexecutor` like ? ");873 query.append(" or exe.`robothost` like ? ");874 query.append(" or exe.`robotport` like ? ");875 query.append(" or exe.`tag` like ? ");876 query.append(" or exe.`end` like ? ");877 query.append(" or exe.`status` like ? ");878 query.append(" or exe.`crbversion` like ? ");879 query.append(" or exe.`executor` like ? ");880 query.append(" or exe.`screensize` like ? ");881 query.append(" or exe.`userAgent` like ? )");882 }883 if (individualSearch != null && !individualSearch.isEmpty()) {884 query.append(" and ( 1=1 ");885 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {886 query.append(" and ");887 query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));888 individalColumnSearchValues.addAll(entry.getValue());889 }890 query.append(" ) ");891 }892 if (system != null && !system.isEmpty()) {893 query.append(" and " + SqlUtil.generateInClause("exe.system", system) + " ");894 }895 query.append(" AND " + UserSecurity.getSystemAllowForSQL("exe.system"));896 if (!StringUtil.isNullOrEmpty(sort)) {897 query.append(" order by ").append(sort);898 }899 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {900 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);901 } else {902 query.append(" limit ").append(start).append(" , ").append(amount);903 }904 // Debug message on SQL.905 if (LOG.isDebugEnabled()) {906 LOG.debug("SQL : " + query.toString());907 }908 Connection connection = this.databaseSpring.connect();909 try {910 PreparedStatement preStat = connection.prepareStatement(query.toString());911 try {912 int i = 1;913 if (!Strings.isNullOrEmpty(searchTerm)) {914 preStat.setString(i++, "%" + searchTerm + "%");915 preStat.setString(i++, "%" + searchTerm + "%");916 preStat.setString(i++, "%" + searchTerm + "%");917 preStat.setString(i++, "%" + searchTerm + "%");918 preStat.setString(i++, "%" + searchTerm + "%");919 preStat.setString(i++, "%" + searchTerm + "%");920 preStat.setString(i++, "%" + searchTerm + "%");921 preStat.setString(i++, "%" + searchTerm + "%");922 preStat.setString(i++, "%" + searchTerm + "%");923 preStat.setString(i++, "%" + searchTerm + "%");924 preStat.setString(i++, "%" + searchTerm + "%");925 preStat.setString(i++, "%" + searchTerm + "%");926 preStat.setString(i++, "%" + searchTerm + "%");927 preStat.setString(i++, "%" + searchTerm + "%");928 preStat.setString(i++, "%" + searchTerm + "%");929 preStat.setString(i++, "%" + searchTerm + "%");930 preStat.setString(i++, "%" + searchTerm + "%");931 preStat.setString(i++, "%" + searchTerm + "%");932 preStat.setString(i++, "%" + searchTerm + "%");933 preStat.setString(i++, "%" + searchTerm + "%");934 preStat.setString(i++, "%" + searchTerm + "%");935 preStat.setString(i++, "%" + searchTerm + "%");936 preStat.setString(i++, "%" + searchTerm + "%");937 preStat.setString(i++, "%" + searchTerm + "%");938 preStat.setString(i++, "%" + searchTerm + "%");939 preStat.setString(i++, "%" + searchTerm + "%");940 preStat.setString(i++, "%" + searchTerm + "%");941 preStat.setString(i++, "%" + searchTerm + "%");942 }943 for (String individualColumnSearchValue : individalColumnSearchValues) {944 preStat.setString(i++, individualColumnSearchValue);945 }946 if (system != null && !system.isEmpty()) {947 for (String sys : system) {948 preStat.setString(i++, sys);949 }950 }951 ResultSet resultSet = preStat.executeQuery();952 try {953 //gets the data954 while (resultSet.next()) {955 objectList.add(this.loadFromResultSet(resultSet));956 }957 //get the total number of rows958 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");959 int nrTotalRows = 0;960 if (resultSet != null && resultSet.next()) {961 nrTotalRows = resultSet.getInt(1);962 }963 if (objectList.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.964 LOG.error("Partial Result in the query.");965 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);966 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));967 response = new AnswerList<>(objectList, nrTotalRows);968 } else if (objectList.size() <= 0) {969 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);970 response = new AnswerList<>(objectList, nrTotalRows);971 } else {972 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);973 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));974 response = new AnswerList<>(objectList, nrTotalRows);975 }976 } catch (SQLException exception) {977 LOG.error("Unable to execute query : " + exception.toString(), exception);978 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);979 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));980 } finally {981 if (resultSet != null) {982 resultSet.close();983 }984 }985 } catch (SQLException exception) {986 LOG.error("Unable to execute query : " + exception.toString(), exception);987 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);988 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));989 } finally {990 if (preStat != null) {991 preStat.close();992 }993 }994 } catch (SQLException exception) {995 LOG.error("Unable to execute query : " + exception.toString(), exception);996 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);997 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));998 } finally {999 try {1000 if (!this.databaseSpring.isOnTransaction()) {1001 if (connection != null) {1002 connection.close();1003 }1004 }1005 } catch (SQLException exception) {1006 LOG.warn("Unable to close connection : " + exception.toString());1007 }1008 }1009 response.setResultMessage(msg);1010 response.setDataList(objectList);1011 return response;1012 }1013 @Override1014 public AnswerList<TestCaseExecution> readDistinctEnvCoutnryBrowserByTag(String tag) {1015 AnswerList<TestCaseExecution> answer = new AnswerList<>();1016 StringBuilder query = new StringBuilder();1017 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1018 query.append("SELECT exe.* FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY exe.Environment, exe.Country, exe.Browser, exe.ControlStatus");1019 Connection connection = this.databaseSpring.connect();1020 List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();1021 try {1022 PreparedStatement preStat = connection.prepareStatement(query.toString());1023 preStat.setString(1, tag);1024 try {1025 ResultSet resultSet = preStat.executeQuery();1026 try {1027 while (resultSet.next()) {1028 testCaseExecutionList.add(this.loadFromResultSet(resultSet));1029 }1030 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));1031 answer = new AnswerList<>(testCaseExecutionList, testCaseExecutionList.size());1032 } catch (SQLException exception) {1033 LOG.warn("Unable to execute query : " + exception.toString());1034 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1035 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1036 testCaseExecutionList = null;1037 } finally {1038 if (resultSet != null) {1039 resultSet.close();1040 }1041 }1042 } catch (SQLException ex) {1043 LOG.warn("Unable to execute query : " + ex.toString());1044 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1045 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1046 testCaseExecutionList = null;1047 } finally {1048 if (preStat != null) {1049 preStat.close();1050 }1051 }1052 } catch (SQLException ex) {1053 LOG.warn(ex.toString());1054 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1055 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1056 } finally {1057 try {1058 if (connection != null) {1059 connection.close();1060 }1061 } catch (SQLException ex) {1062 LOG.warn("Unable to execute query : " + ex.toString());1063 }1064 }1065 answer.setResultMessage(msg);1066 return answer;1067 }1068 @Override1069 public AnswerList<TestCaseExecution> readDistinctColumnByTag(String tag, boolean env, boolean country, boolean browser, boolean app) {1070 AnswerList<TestCaseExecution> answer = new AnswerList<>();1071 StringBuilder query = new StringBuilder();1072 StringBuilder distinct = new StringBuilder();1073 int prev = 0;1074 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1075 if (!(!env && !country && !app && !browser)) {1076 if (env) {1077 distinct.append("Environment");1078 prev++;1079 }1080 if (country) {1081 if (prev != 0) {1082 prev = 0;1083 distinct.append(",");1084 }1085 distinct.append("Country");1086 prev++;1087 }1088 if (browser) {1089 if (prev != 0) {1090 prev = 0;1091 distinct.append(",");1092 }1093 distinct.append("Browser");1094 prev++;1095 }1096 if (app) {1097 if (prev != 0) {1098 prev = 0;1099 distinct.append(",");1100 }1101 distinct.append("Application");1102 }1103 query.append("SELECT ");1104 query.append(distinct.toString());1105 query.append(" FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY ");1106 query.append(distinct.toString());1107 } else {1108 //If there is no distinct, select nothing1109 query.append("SELECT * FROM testcaseexecution exe WHERE 1 = 0 AND exe.tag = ?");1110 }1111 Connection connection = this.databaseSpring.connect();1112 List<TestCaseExecution> column = new ArrayList<TestCaseExecution>();1113 try {1114 PreparedStatement preStat = connection.prepareStatement(query.toString());1115 preStat.setString(1, tag);1116 try {1117 ResultSet resultSet = preStat.executeQuery();1118 try {1119 while (resultSet.next()) {1120 TestCaseExecution tmp = new TestCaseExecution();1121 if (env) {1122 tmp.setEnvironment(resultSet.getString("Environment"));1123 } else {1124 tmp.setEnvironment("");1125 }1126 if (country) {1127 tmp.setCountry(resultSet.getString("Country"));1128 } else {1129 tmp.setCountry("");1130 }1131 if (browser) {1132 tmp.setBrowser(resultSet.getString("Browser"));1133 } else {1134 tmp.setBrowser("");1135 }1136 if (app) {1137 tmp.setApplication(resultSet.getString("Application"));1138 } else {1139 tmp.setApplication("");1140 }1141 column.add(tmp);1142 }1143 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));1144 answer = new AnswerList<>(column, column.size());1145 } catch (SQLException exception) {1146 LOG.warn("Unable to execute query : " + exception.toString());1147 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1148 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1149 column = null;1150 } finally {1151 if (resultSet != null) {1152 resultSet.close();1153 }1154 }1155 } catch (SQLException ex) {1156 LOG.warn("Unable to execute query : " + ex.toString());1157 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1158 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1159 column = null;1160 } finally {1161 if (preStat != null) {1162 preStat.close();1163 }1164 }1165 } catch (SQLException ex) {1166 LOG.warn(ex.toString());1167 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1168 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1169 } finally {1170 try {1171 if (connection != null) {1172 connection.close();1173 }1174 } catch (SQLException ex) {1175 LOG.warn("Unable to execute query : " + ex.toString());1176 }1177 }1178 answer.setResultMessage(msg);1179 return answer;1180 }1181 @Override1182 public AnswerItem<TestCaseExecution> readByKey(long executionId) {1183 AnswerItem<TestCaseExecution> ans = new AnswerItem<>();1184 TestCaseExecution result = null;1185 final String query = "SELECT * FROM `testcaseexecution` exe WHERE exe.`id` = ?";1186 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1187 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1188 Connection connection = this.databaseSpring.connect();1189 try {1190 PreparedStatement preStat = connection.prepareStatement(query);1191 try {1192 preStat.setLong(1, executionId);1193 ResultSet resultSet = preStat.executeQuery();1194 try {1195 if (resultSet.first()) {1196 result = loadFromResultSet(resultSet);1197 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1198 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));1199 ans.setItem(result);1200 } else {1201 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);1202 }1203 } catch (SQLException exception) {1204 LOG.error("Unable to execute query : " + exception.toString());1205 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1206 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1207 } finally {1208 resultSet.close();1209 }1210 } catch (SQLException exception) {1211 LOG.error("Unable to execute query : " + exception.toString());1212 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1213 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1214 } finally {1215 preStat.close();1216 }1217 } catch (SQLException exception) {1218 LOG.error("Unable to execute query : " + exception.toString());1219 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1220 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1221 } finally {1222 try {1223 if (connection != null) {1224 connection.close();1225 }1226 } catch (SQLException exception) {1227 LOG.warn("Unable to close connection : " + exception.toString());1228 }1229 }1230 //sets the message1231 ans.setResultMessage(msg);1232 return ans;1233 }1234 @Override1235 public TestCaseExecution loadFromResultSet(ResultSet resultSet) throws SQLException {1236 long id = ParameterParserUtil.parseLongParam(resultSet.getString("exe.ID"), 0);1237 String test = ParameterParserUtil.parseStringParam(resultSet.getString("exe.test"), "");1238 String testcase = ParameterParserUtil.parseStringParam(resultSet.getString("exe.testcase"), "");1239 String description = ParameterParserUtil.parseStringParam(resultSet.getString("exe.description"), "");1240 String build = ParameterParserUtil.parseStringParam(resultSet.getString("exe.build"), "");1241 String revision = ParameterParserUtil.parseStringParam(resultSet.getString("exe.revision"), "");1242 String environment = ParameterParserUtil.parseStringParam(resultSet.getString("exe.environment"), "");1243 String environmentData = ParameterParserUtil.parseStringParam(resultSet.getString("exe.environmentData"), "");1244 String country = ParameterParserUtil.parseStringParam(resultSet.getString("exe.country"), "");1245 String robot = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robot"), ""); // Host the Selenium IP1246 String robotExecutor = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotExecutor"), ""); // Host the Selenium IP1247 String robotHost = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotHost"), ""); // Host the Selenium IP1248 String robotPort = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotPort"), ""); // host the Selenium Port1249 String robotDecli = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotdecli"), "");1250 String browser = ParameterParserUtil.parseStringParam(resultSet.getString("exe.browser"), "");1251 String version = ParameterParserUtil.parseStringParam(resultSet.getString("exe.version"), "");1252 String platform = ParameterParserUtil.parseStringParam(resultSet.getString("exe.platform"), "");1253 long start = ParameterParserUtil.parseLongParam(String.valueOf(resultSet.getTimestamp("exe.start").getTime()), 0);1254 long end = ParameterParserUtil.parseLongParam(String.valueOf(resultSet.getTimestamp("exe.end").getTime()), 0);1255 String controlStatus = ParameterParserUtil.parseStringParam(resultSet.getString("exe.controlStatus"), "");1256 String controlMessage = ParameterParserUtil.parseStringParam(resultSet.getString("exe.controlMessage"), "");1257 String application = ParameterParserUtil.parseStringParam(resultSet.getString("exe.application"), "");1258 String url = ParameterParserUtil.parseStringParam(resultSet.getString("exe.url"), "");1259 String tag = ParameterParserUtil.parseStringParam(resultSet.getString("exe.tag"), "");1260 String status = ParameterParserUtil.parseStringParam(resultSet.getString("exe.status"), "");1261 String crbVersion = ParameterParserUtil.parseStringParam(resultSet.getString("exe.crbVersion"), "");1262 String executor = ParameterParserUtil.parseStringParam(resultSet.getString("exe.executor"), "");1263 String screenSize = ParameterParserUtil.parseStringParam(resultSet.getString("exe.screensize"), "");1264 String conditionOper = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionOper"), "");1265 String conditionVal1 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal1"), "");1266 String conditionVal1Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal1Init"), "");1267 String conditionVal2 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal2"), "");1268 String conditionVal2Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal2Init"), "");1269 String conditionVal3 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal3"), "");1270 String conditionVal3Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal3Init"), "");1271 String manualExecution = ParameterParserUtil.parseStringParam(resultSet.getString("exe.manualExecution"), "N");1272 String userAgent = ParameterParserUtil.parseStringParam(resultSet.getString("exe.userAgent"), "");1273 String system = ParameterParserUtil.parseStringParam(resultSet.getString("exe.system"), "");1274 long queueId = ParameterParserUtil.parseLongParam(resultSet.getString("exe.queueId"), 0);1275 int testCaseVersion = ParameterParserUtil.parseIntegerParam(resultSet.getInt("exe.testCaseVersion"), 0);1276 int testCasePriority = ParameterParserUtil.parseIntegerParam(resultSet.getInt("exe.testCasePriority"), 0);1277 String robotProvider = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotProvider"), "");1278 String robotSessionId = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotSessionId"), "");1279 String usrModif = ParameterParserUtil.parseStringParam(resultSet.getString("exe.UsrModif"), "");1280 String usrCreated = ParameterParserUtil.parseStringParam(resultSet.getString("exe.UsrCreated"), "");1281 Timestamp dateCreated = resultSet.getTimestamp("exe.DateCreated");1282 Timestamp dateModif = resultSet.getTimestamp("exe.DateModif");1283 TestCaseExecution result = factoryTCExecution.create(id, test, testcase, description, build, revision, environment,1284 country, robot, robotExecutor, robotHost, robotPort, robotDecli, browser, version, platform, start, end, controlStatus, controlMessage, application, null, url,1285 tag, 0, 0, 0, 0, true, "", "", status, crbVersion, null, null, null,1286 false, null, null, null, environmentData, null, null, null, null, executor, 0, screenSize, null, robotProvider, robotSessionId,1287 conditionOper, conditionVal1Init, conditionVal2Init, conditionVal3Init, conditionVal1, conditionVal2, conditionVal3, manualExecution, userAgent, testCaseVersion, testCasePriority, system,1288 usrCreated, dateCreated, usrModif, dateModif);1289 result.setQueueID(queueId);1290 return result;1291 }1292 private TestCaseExecution loadWithDependenciesFromResultSet(ResultSet resultSet) throws SQLException {1293 TestCaseExecution testCaseExecution = new TestCaseExecution();1294 testCaseExecution = this.loadFromResultSet(resultSet);1295 testCaseExecution.setTestCaseObj(testCaseDAO.loadFromResultSet(resultSet));1296 testCaseExecution.setApplicationObj(applicationDAO.loadFromResultSet(resultSet));1297 return testCaseExecution;1298 }1299 private TestCaseExecution loadWithTestCaseFromResultSet(ResultSet resultSet) throws SQLException {1300 TestCaseExecution testCaseExecution = new TestCaseExecution();1301 testCaseExecution = this.loadFromResultSet(resultSet);1302 testCaseExecution.setTestCaseObj(testCaseDAO.loadFromResultSet(resultSet));1303 return testCaseExecution;1304 }1305 private TestCaseExecution loadTestCaseExecutionAndApplicationFromResultSet(ResultSet resultSet) throws SQLException {1306 TestCaseExecution testCaseExecution = new TestCaseExecution();1307 testCaseExecution = this.loadFromResultSet(resultSet);1308 testCaseExecution.setApplicationObj(applicationDAO.loadFromResultSet(resultSet));1309 return testCaseExecution;1310 }1311 @Override1312 public AnswerList<String> readDistinctValuesByCriteria(List<String> system, String test, String searchParameter, Map<String, List<String>> individualSearch, String columnName) {1313 AnswerList<String> answer = new AnswerList<>();1314 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1315 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1316 List<String> distinctValues = new ArrayList<>();1317 List<String> individalColumnSearchValues = new ArrayList<>();1318 final StringBuffer query = new StringBuffer();1319 query.append("SELECT distinct ");...

Full Screen

Full Screen

loadTestCaseExecutionAndApplicationFromResultSet

Using AI Code Generation

copy

Full Screen

1public static TestCaseExecution loadTestCaseExecutionAndApplicationFromResultSet(ResultSet resultSet) throws SQLException {2 TestCaseExecution tCExecution = new TestCaseExecution();3 tCExecution.setId(resultSet.getLong("id"));4 tCExecution.setTest(resultSet.getString("test"));5 tCExecution.setTestCase(resultSet.getString("testCase"));6 tCExecution.setCountry(resultSet.getString("country"));7 tCExecution.setEnvironment(resultSet.getString("environment"));8 tCExecution.setBuild(resultSet.getString("build"));9 tCExecution.setRevision(resultSet.getString("revision"));10 tCExecution.setRobot(resultSet.getString("robot"));11 tCExecution.setRobotDecli(resultSet.getString("robotDecli"));12 tCExecution.setRobotExecutor(resultSet.getString("robotExecutor"));13 tCExecution.setRobotHost(resultSet.getString("robotHost"));14 tCExecution.setRobotPort(resultSet.getString("robotPort"));15 tCExecution.setRobotProvider(resultSet.getString("robotProvider"));16 tCExecution.setBrowser(resultSet.getString("browser"));17 tCExecution.setBrowserFullVersion(resultSet.getString("browserFullVersion"));18 tCExecution.setBrowserVersion(resultSet.getString("browserVersion"));19 tCExecution.setPlatform(resultSet.getString("platform"));20 tCExecution.setVersion(resultSet.getString("version"));21 tCExecution.setStart(resultSet.getTimestamp("start"));22 tCExecution.setEnd(resultSet.getTimestamp("end"));23 tCExecution.setControlStatus(resultSet.getString("controlStatus"));24 tCExecution.setControlMessage(resultSet.getString("controlMessage"));25 tCExecution.setControlProperty(resultSet.getString("controlProperty"));26 tCExecution.setApplicationObj(new Application(resultSet.getString("application")));27 tCExecution.setIp(resultSet.getString("ip"));28 tCExecution.setUrl(resultSet.getString("url"));29 tCExecution.setTag(resultSet.getString("tag"));30 tCExecution.setVerbose(resultSet.getInt("verbose"));31 tCExecution.setScreenshot(resultSet.getInt("screenshot"));32 tCExecution.setPageSource(resultSet.getInt("pageSource"));33 tCExecution.setSeleniumLog(resultSet.getInt("seleniumLog"));34 tCExecution.setManualURL(resultSet.getString("manualURL"));35 tCExecution.setManualHost(resultSet.getString("manualHost"));36 tCExecution.setManualContextRoot(resultSet.getString("manualContextRoot"));37 tCExecution.setManualLoginRelativeURL(resultSet.getString("manualLoginRelativeURL"));38 tCExecution.setManualEnvData(resultSet.getString("manualEnvData"));39 tCExecution.setManualExecution(resultSet.getInt("manualExecution"));40 tCExecution.setRobotIP(resultSet

Full Screen

Full Screen

loadTestCaseExecutionAndApplicationFromResultSet

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.dao.ITestCaseExecutionDAO;2import org.cerberus.crud.entity.Application;3import org.cerberus.crud.entity.TestCaseExecution;4import org.cerberus.crud.factory.IFactoryApplication;5import org.cerberus.crud.factory.IFactoryTestCaseExecution;6import org.cerberus.crud.service.ITestCaseExecutionService;7import org.cerberus.crud.service.ITestCaseService;8import org.cerberus.engine.entity.MessageEvent;9import org.cerberus.engine.entity.MessageGeneral;10import org.cerberus.engine.execution.IExecutionThreadPoolService;11import org.cerberus.engine.execution.impl.ExecutionThreadPoolService;12import org.cerberus.engine.threadpool.IExecutionThreadPoolService;13import org.cerberus.engine.threadpool.imp

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful