How to use toString method of org.cerberus.crud.entity.TestCaseExecutionData class

Best Cerberus-source code snippet using org.cerberus.crud.entity.TestCaseExecutionData.toString

Source:PropertyService.java Github

copy

Full Screen

...497 // Checking recursive decode.498 if ((tCExecution.getRecursiveAlreadyCalculatedPropertiesList() != null) && (tCExecution.getRecursiveAlreadyCalculatedPropertiesList().contains(testCaseCountryProperty.getProperty()))) {499 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_RECURSIVE);500 res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseCountryProperty.getProperty())501 .replace("%HISTO%", tCExecution.getRecursiveAlreadyCalculatedPropertiesList().toString()));502 testCaseExecutionData.setPropertyResultMessage(res);503 testCaseExecutionData.setEnd(new Date().getTime());504 LOG.debug("Finished to calculate Property (interupted) : '" + testCaseCountryProperty.getProperty() + "' : " + testCaseExecutionData.getPropertyResultMessage().getDescription());505 return;506 }507 if (tCExecution.getRecursiveAlreadyCalculatedPropertiesList() != null) {508 tCExecution.getRecursiveAlreadyCalculatedPropertiesList().add(testCaseCountryProperty.getProperty());509 }510 try {511 // Check if cache activated and cache entry exist.512 int cacheValue = testCaseCountryProperty.getCacheExpire();513 boolean useCache = false;514 AnswerItem<TestCaseExecutionData> answerData = null;515 if (cacheValue > 0) {516 answerData = testCaseExecutionDataService.readLastCacheEntry(tCExecution.getApplicationObj().getSystem(), tCExecution.getEnvironment(), tCExecution.getCountry(), testCaseCountryProperty.getProperty(), cacheValue);517 if (answerData.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getItem() != null) {518 useCache = true;519 }520 }521 if (!useCache) {522 /**523 * Decode Property replacing properties encapsulated with %524 */525 if (testCaseCountryProperty.getValue1().contains("%")) {526 answerDecode = variableService.decodeStringCompletly(testCaseCountryProperty.getValue1(), tCExecution, null, false);527 testCaseExecutionData.setValue1((String) answerDecode.getItem());528 if (!(answerDecode.isCodeStringEquals("OK"))) {529 // If anything wrong with the decode --> we stop here with decode message in the property result.530 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Property Value1"));531 testCaseExecutionData.setEnd(new Date().getTime());532 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());533 LOG.debug("Finished to calculate Property (interupted) : '" + testCaseCountryProperty.getProperty() + "' : " + testCaseExecutionData.getPropertyResultMessage().getDescription());534 return;535 }536 }537 if (testCaseCountryProperty.getValue2() != null && testCaseCountryProperty.getValue2().contains("%")) {538 answerDecode = variableService.decodeStringCompletly(testCaseCountryProperty.getValue2(), tCExecution, null, false);539 testCaseExecutionData.setValue2((String) answerDecode.getItem());540 if (!(answerDecode.isCodeStringEquals("OK"))) {541 // If anything wrong with the decode --> we stop here with decode message in the property result.542 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Property Value2"));543 testCaseExecutionData.setEnd(new Date().getTime());544 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());545 LOG.debug("Finished to calculate Property (interupted) : '" + testCaseCountryProperty.getProperty() + "' : " + testCaseExecutionData.getPropertyResultMessage().getDescription());546 return;547 }548 }549 // cache not activated or no entry exist.550 int execution_count = 0;551 int retries = testCaseCountryProperty.getRetryNb();552 int periodms = testCaseCountryProperty.getRetryPeriod();553 LOG.debug("Init Retries : " + retries + " Period : " + periodms);554 /**555 * Controling that retrynb and retryperiod are correctly feeded.556 * <br>557 * This is to avoid that <br>558 * 1/ retry is greater than cerberus_property_maxretry <br>559 * 2/ total duration of property calculation is longuer than560 * cerberus_property_maxretrytotalduration561 */562 boolean forced_retry = false;563 String forced_retry_message = "";564 if (!(retries == 0)) {565 int maxretry = parameterService.getParameterIntegerByKey("cerberus_property_maxretry", "", 50);566 if (retries > maxretry) {567 retries = maxretry;568 forced_retry = true;569 }570 int maxtotalduration = parameterService.getParameterIntegerByKey("cerberus_property_maxretrytotalduration", "", 1800000);571 if (periodms > maxtotalduration) {572 periodms = maxtotalduration;573 forced_retry = true;574 }575 if (retries * periodms > maxtotalduration) {576 retries = (int) maxtotalduration / periodms;577 forced_retry = true;578 }579 if (forced_retry) {580 forced_retry_message = "WARNING : Forced Retries : " + testCaseCountryProperty.getRetryNb() + "-->" + retries + " and Period : " + testCaseCountryProperty.getRetryPeriod() + "-->" + periodms + " (in order to respect the constrains cerberus_property_maxretry " + maxretry + " & cerberus_property_maxtotalduration " + maxtotalduration + ")";581 LOG.debug("Forced Retries : " + retries + " Period : " + periodms + " in order to respect the constrains cerberus_property_maxretry " + maxretry + " & cerberus_property_maxtotalduration " + maxtotalduration);582 }583 }584 /**585 * Looping on calculating the action until result is OK or reach586 * the max retry.587 */588 while (execution_count <= retries && !(testCaseExecutionData.getPropertyResultMessage().getCodeString().equals("OK"))) {589 LOG.debug("Attempt #" + execution_count + " " + testCaseCountryProperty.getProperty() + " " + testCaseCountryProperty.getValue1());590 if (execution_count >= 1) { // We only wait the period if not on the very first calculation.591 try {592 Thread.sleep(periodms);593 LOG.debug("Attempt #" + execution_count + " " + testCaseCountryProperty.getProperty() + " " + testCaseCountryProperty.getValue1() + " Waiting " + periodms + " ms");594 } catch (InterruptedException ex) {595 LOG.error(ex.toString());596 }597 }598 /**599 * Calculate Property regarding the type600 */601 switch (testCaseCountryProperty.getType()) {602 case TestCaseCountryProperties.TYPE_TEXT:603 testCaseExecutionData = this.property_calculateText(testCaseExecutionData, testCaseCountryProperty, forceRecalculation);604 break;605 case TestCaseCountryProperties.TYPE_GETFROMDATALIB:606 testCaseExecutionData = this.property_getFromDataLib(testCaseExecutionData, tCExecution, testCaseStepActionExecution, testCaseCountryProperty, forceRecalculation);607 break;608 case TestCaseCountryProperties.TYPE_GETFROMSQL:609 testCaseExecutionData = this.property_getFromSql(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);610 break;611 case TestCaseCountryProperties.TYPE_GETFROMHTML:612 testCaseExecutionData = this.property_getFromHtml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);613 break;614 case TestCaseCountryProperties.TYPE_GETFROMHTMLVISIBLE:615 testCaseExecutionData = this.property_getFromHtmlVisible(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);616 break;617 case TestCaseCountryProperties.TYPE_GETFROMJS:618 testCaseExecutionData = this.property_getFromJS(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);619 break;620 case TestCaseCountryProperties.TYPE_GETATTRIBUTEFROMHTML:621 testCaseExecutionData = this.property_getAttributeFromHtml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);622 break;623 case TestCaseCountryProperties.TYPE_GETFROMCOOKIE:624 testCaseExecutionData = this.property_getFromCookie(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);625 break;626 case TestCaseCountryProperties.TYPE_GETFROMXML:627 testCaseExecutionData = this.property_getFromXml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);628 break;629 case TestCaseCountryProperties.TYPE_GETDIFFERENCESFROMXML:630 testCaseExecutionData = this.property_getDifferencesFromXml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);631 break;632 case TestCaseCountryProperties.TYPE_GETFROMJSON:633 testCaseExecutionData = this.property_getFromJson(testCaseExecutionData, tCExecution, forceRecalculation);634 break;635 case TestCaseCountryProperties.TYPE_GETFROMGROOVY:636 testCaseExecutionData = this.property_getFromGroovy(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);637 break;638 case TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB: // DEPRECATED639 testCaseExecutionData = this.property_executeSoapFromLib(testCaseExecutionData, tCExecution, testCaseStepActionExecution, testCaseCountryProperty, forceRecalculation);640 res = testCaseExecutionData.getPropertyResultMessage();641 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());642 testCaseExecutionData.setPropertyResultMessage(res);643 logEventService.createForPrivateCalls("ENGINE", TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB, MESSAGE_DEPRECATED + " Deprecated Property triggered by TestCase : ['" + test + "|" + testCase + "']");644 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Property " + TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB + " triggered by TestCase : ['" + test + "'|'" + testCase + "']");645 break;646 case TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB: // DEPRECATED647 testCaseExecutionData = this.property_executeSqlFromLib(testCaseExecutionData, testCaseCountryProperty, tCExecution, forceRecalculation);648 res = testCaseExecutionData.getPropertyResultMessage();649 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());650 testCaseExecutionData.setPropertyResultMessage(res);651 logEventService.createForPrivateCalls("ENGINE", TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB, MESSAGE_DEPRECATED + " Deprecated Property triggered by TestCase : ['" + test + "|" + testCase + "']");652 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Property " + TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB + " triggered by TestCase : ['" + test + "'|'" + testCase + "']");653 break;654 default:655 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_UNKNOWNPROPERTY);656 res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseCountryProperty.getType()));657 testCaseExecutionData.setPropertyResultMessage(res);658 }659 execution_count++;660 }661 if (execution_count >= 2) { // If there were at least 1 retry, we notify it in the result message.662 res = testCaseExecutionData.getPropertyResultMessage();663 res.setDescription("Retried " + (execution_count - 1) + " time(s) with " + periodms + "ms period - " + res.getDescription());664 testCaseExecutionData.setPropertyResultMessage(res);665 }666 if (forced_retry) { // If the retry and period parameter was changed, we notify it in the result message.667 res = testCaseExecutionData.getPropertyResultMessage();668 res.setDescription(forced_retry_message + " - " + res.getDescription());669 testCaseExecutionData.setPropertyResultMessage(res);670 }671 } else {672 // cache activated and entry exist. We set the current value with cache entry data and notify the result from the messsage.673 TestCaseExecutionData testCaseExecutionDataFromCache = (TestCaseExecutionData) answerData.getItem();674 testCaseExecutionData.setFromCache("Y");675 testCaseExecutionData.setDataLib(testCaseExecutionDataFromCache.getDataLib());676 testCaseExecutionData.setValue(testCaseExecutionDataFromCache.getValue());677 testCaseExecutionData.setJsonResult(testCaseExecutionDataFromCache.getJsonResult());678 DateFormat df = new SimpleDateFormat(DateUtil.DATE_FORMAT_DISPLAY);679 res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_FROMCACHE).resolveDescription("ID", String.valueOf(testCaseExecutionDataFromCache.getId())).resolveDescription("DATE", df.format(testCaseExecutionDataFromCache.getStart()));680 testCaseExecutionData.setPropertyResultMessage(res);681 if (!StringUtil.isNullOrEmpty(testCaseExecutionDataFromCache.getJsonResult())) {682 // Convert json to HashMap.683 List<HashMap<String, String>> result = null;684 result = new ArrayList();685 try {686 LOG.debug("Converting Json : " + testCaseExecutionDataFromCache.getJsonResult());687 JSONArray json = new JSONArray(testCaseExecutionDataFromCache.getJsonResult());688 for (int i = 0; i < json.length(); i++) {689 JSONObject explrObject = json.getJSONObject(i);690 LOG.debug(explrObject.toString());691 HashMap<String, String> resultHash = new HashMap<String, String>();692 Iterator<String> nameItr = explrObject.keys();693 while (nameItr.hasNext()) {694 String name = nameItr.next();695 if (name.equals("KEY")) {696 resultHash.put("", explrObject.getString(name));697 } else {698 resultHash.put(name, explrObject.getString(name));699 }700 }701 result.add(resultHash);702 }703 } catch (JSONException ex) {704 java.util.logging.Logger.getLogger(PropertyService.class.getName()).log(Level.SEVERE, null, ex);705 LOG.error(ex);706 }707 testCaseExecutionData.setDataLibRawData(result);708 //Record result in filessytem.709 recorderService.recordTestDataLibProperty(tCExecution.getId(), testCaseCountryProperty.getProperty(), 1, result);710 }711 }712 } catch (CerberusEventException ex) {713 LOG.error(ex.toString());714 testCaseExecutionData.setEnd(new Date().getTime());715 testCaseExecutionData.setPropertyResultMessage(ex.getMessageError());716 }717 testCaseExecutionData.setEnd(new Date().getTime());718 if (LOG.isDebugEnabled()) {719 LOG.debug("Finished to calculate Property : '" + testCaseCountryProperty.getProperty() + "'");720 }721 }722 private TestCaseExecutionData property_executeSqlFromLib(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseCountryProperty, TestCaseExecution tCExecution, boolean forceCalculation) {723 try {724 String script = this.sqlLibraryService.findSqlLibraryByKey(testCaseExecutionData.getValue1()).getScript();725 testCaseExecutionData.setValue1(script); //TODO use the new library 726 } catch (CerberusException ex) {727 LOG.warn(ex);728 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_SQLLIB_NOTEXIT);729 res.setDescription(res.getDescription().replace("%SQLLIB%", testCaseExecutionData.getValue1()));730 testCaseExecutionData.setPropertyResultMessage(res);731 testCaseExecutionData.setEnd(732 new Date().getTime());733 return testCaseExecutionData;734 }735 testCaseExecutionData = this.property_getFromSql(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceCalculation);736 return testCaseExecutionData;737 }738 private TestCaseExecutionData property_getFromSql(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {739 return sQLService.calculateOnDatabase(testCaseExecutionData, testCaseCountryProperty, tCExecution);740 }741 private TestCaseExecutionData property_calculateText(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {742 if (TestCaseCountryProperties.NATURE_RANDOM.equals(testCaseCountryProperty.getNature())743 //TODO CTE Voir avec B. Civel "RANDOM_NEW"744 || (testCaseCountryProperty.getNature().equals(TestCaseCountryProperties.NATURE_RANDOMNEW))) {745 if (testCaseCountryProperty.getLength().equals("0")) {746 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_TEXTRANDOMLENGHT0);747 testCaseExecutionData.setPropertyResultMessage(res);748 } else {749 String charset;750 if (testCaseExecutionData.getValue1() != null && !"".equals(testCaseExecutionData.getValue1().trim())) {751 charset = testCaseExecutionData.getValue1();752 } else {753 charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";754 }755 String value = StringUtil.getRandomString(ParameterParserUtil.parseIntegerParam(testCaseCountryProperty.getLength(), 0), charset);756 testCaseExecutionData.setValue(value);757 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_RANDOM);758 res.setDescription(res.getDescription().replace("%FORCED%", forceRecalculation == true ? "Re-" : ""));759 res.setDescription(res.getDescription().replace("%VALUE%", ParameterParserUtil.securePassword(value, testCaseCountryProperty.getProperty())));760 testCaseExecutionData.setPropertyResultMessage(res);761// if (testCaseCountryProperty.getNature().equals("RANDOM_NEW")) {762// //TODO check if value exist on DB ( used in another test case of the revision )763// }764 }765 } else {766 LOG.debug("Setting value : " + testCaseExecutionData.getValue1());767 String value = testCaseExecutionData.getValue1();768 testCaseExecutionData.setValue(value);769 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_TEXT);770 res.setDescription(res.getDescription().replace("%VALUE%", ParameterParserUtil.securePassword(value, testCaseCountryProperty.getProperty())));771 testCaseExecutionData.setPropertyResultMessage(res);772 }773 return testCaseExecutionData;774 }775 private TestCaseExecutionData property_getFromHtmlVisible(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {776 try {777 Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());778 String valueFromHTML = this.webdriverService.getValueFromHTMLVisible(tCExecution.getSession(), identifier);779 if (valueFromHTML != null) {780 testCaseExecutionData.setValue(valueFromHTML);781 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_HTMLVISIBLE);782 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));783 res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));784 testCaseExecutionData.setPropertyResultMessage(res);785 } else {786 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);787 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));788 testCaseExecutionData.setPropertyResultMessage(res);789 }790 } catch (NoSuchElementException exception) {791 LOG.debug(exception.toString());792 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);793 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));794 testCaseExecutionData.setPropertyResultMessage(res);795 }796 return testCaseExecutionData;797 }798 private TestCaseExecutionData property_getFromHtml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {799 if (tCExecution.getApplicationObj().getType().equals(Application.TYPE_APK)800 || tCExecution.getApplicationObj().getType().equals(Application.TYPE_IPA)801 || tCExecution.getApplicationObj().getType().equals(Application.TYPE_GUI)) {802 try {803 Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());804 String valueFromHTML = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);805 if (valueFromHTML != null) {806 testCaseExecutionData.setValue(valueFromHTML);807 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_HTML);808 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));809 res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));810 testCaseExecutionData.setPropertyResultMessage(res);811 }812 } catch (NoSuchElementException exception) {813 LOG.debug(exception.toString());814 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTML_ELEMENTDONOTEXIST);815 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));816 testCaseExecutionData.setPropertyResultMessage(res);817 }818 } else {819 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_FEATURENOTSUPPORTED);820 res.setDescription(res.getDescription().replace("%APPTYPE%", tCExecution.getApplicationObj().getType()));821 res.setDescription(res.getDescription().replace("%PROPTYPE%", testCaseExecutionData.getType()));822 }823 return testCaseExecutionData;824 }825 private TestCaseExecutionData property_getFromJS(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {826 String script = testCaseExecutionData.getValue1();827 String valueFromJS;828 String message = "";829 try {830 valueFromJS = this.webdriverService.getValueFromJS(tCExecution.getSession(), script);831 } catch (Exception e) {832 message = e.getMessage().split("\n")[0];833 LOG.debug("Exception Running JS Script :" + message);834 valueFromJS = null;835 }836 if (valueFromJS != null) {837 testCaseExecutionData.setValue(valueFromJS);838 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_JS);839 res.setDescription(res.getDescription().replace("%SCRIPT%", script));840 res.setDescription(res.getDescription().replace("%VALUE%", valueFromJS));841 testCaseExecutionData.setPropertyResultMessage(res);842 } else {843 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_JS_EXCEPTION);844 res.setDescription(res.getDescription().replace("%EXCEPTION%", message));845 testCaseExecutionData.setPropertyResultMessage(res);846 }847 return testCaseExecutionData;848 }849 private TestCaseExecutionData property_getFromGroovy(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {850 // Check if script has been correctly defined851 String script = testCaseExecutionData.getValue1();852 if (script == null || script.isEmpty()) {853 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMGROOVY_NULL));854 return testCaseExecutionData;855 }856 // Try to evaluate Groovy script857 try {858 String valueFromGroovy = groovyService.eval(script);859 testCaseExecutionData.setValue(valueFromGroovy);860 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMGROOVY)861 .resolveDescription("VALUE", valueFromGroovy));862 } catch (IGroovyService.IGroovyServiceException e) {863 LOG.debug("Exception Running Grrovy Script :" + e.getMessage());864 testCaseExecutionData.setPropertyResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMGROOVY_EXCEPTION).resolveDescription("REASON", e.getMessage()));865 }866 return testCaseExecutionData;867 }868 private TestCaseExecutionData property_getAttributeFromHtml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {869 MessageEvent res;870 try {871 Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());872 String valueFromHTML = this.webdriverService.getAttributeFromHtml(tCExecution.getSession(), identifier, testCaseExecutionData.getValue2());873 if (valueFromHTML != null) {874 testCaseExecutionData.setValue(valueFromHTML);875 res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETATTRIBUTEFROMHTML);876 res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));877 } else {878 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTML_ATTRIBUTEDONOTEXIST);879 }880 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));881 res.setDescription(res.getDescription().replace("%ATTRIBUTE%", testCaseExecutionData.getValue2()));882 } catch (NoSuchElementException exception) {883 LOG.debug(exception.toString());884 res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);885 res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));886 }887 testCaseExecutionData.setPropertyResultMessage(res);888 return testCaseExecutionData;889 }890 private TestCaseExecutionData property_executeSoapFromLib(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {891 String result = null;892 AnswerItem<String> answerDecode = new AnswerItem();893 try {894 AppService appService = this.appServiceService.findAppServiceByKey(testCaseExecutionData.getValue1());895 if (appService != null) {896 String decodedEnveloppe = appService.getServiceRequest();897 String decodedServicePath = appService.getServicePath();898 String decodedMethod = appService.getOperation();899 String decodedAttachement = appService.getAttachementURL();900 if (appService.getServiceRequest().contains("%")) {901 answerDecode = variableService.decodeStringCompletly(appService.getServiceRequest(), tCExecution, testCaseStepActionExecution, false);902 decodedEnveloppe = (String) answerDecode.getItem();903 if (!(answerDecode.isCodeStringEquals("OK"))) {904 // If anything wrong with the decode --> we stop here with decode message in the action result.905 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Service Request"));906 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());907 LOG.debug("Property interupted due to decode 'SOAP Service Request' Error.");908 return testCaseExecutionData;909 }910 }911 if (appService.getServicePath().contains("%")) {912 answerDecode = variableService.decodeStringCompletly(appService.getServicePath(), tCExecution, testCaseStepActionExecution, false);913 decodedServicePath = (String) answerDecode.getItem();914 if (!(answerDecode.isCodeStringEquals("OK"))) {915 // If anything wrong with the decode --> we stop here with decode message in the action result.916 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Service Path"));917 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());918 LOG.debug("Property interupted due to decode 'SOAP Service Path.");919 return testCaseExecutionData;920 }921 }922 if (appService.getOperation().contains("%")) {923 answerDecode = variableService.decodeStringCompletly(appService.getOperation(), tCExecution, testCaseStepActionExecution, false);924 decodedMethod = (String) answerDecode.getItem();925 if (!(answerDecode.isCodeStringEquals("OK"))) {926 // If anything wrong with the decode --> we stop here with decode message in the action result.927 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Operation"));928 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());929 LOG.debug("Property interupted due to decode 'SOAP Operation.");930 return testCaseExecutionData;931 }932 }933 if (appService.getAttachementURL().contains("%")) {934 answerDecode = variableService.decodeStringCompletly(appService.getAttachementURL(), tCExecution, testCaseStepActionExecution, false);935 decodedAttachement = (String) answerDecode.getItem();936 if (!(answerDecode.isCodeStringEquals("OK"))) {937 // If anything wrong with the decode --> we stop here with decode message in the action result.938 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Attachement URL"));939 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());940 LOG.debug("Property interupted due to decode 'SOAP Attachement URL.");941 return testCaseExecutionData;942 }943 }944 //Call Soap and set LastSoapCall of the testCaseExecution.945 AnswerItem soapCall = soapService.callSOAP(decodedEnveloppe, decodedServicePath, decodedMethod, decodedAttachement, null, null, 60000, tCExecution.getApplicationObj().getSystem());946 AppService se1 = (AppService) soapCall.getItem();947// tCExecution.setLastSOAPCalled(soapCall);948 if (soapCall.isCodeEquals(200)) {949// SOAPExecution lastSoapCalled = (SOAPExecution) tCExecution.getLastSOAPCalled().getItem();950 String xmlResponse = se1.getResponseHTTPBody();951 result = xmlUnitService.getFromXml(xmlResponse, appService.getAttachementURL());952 }953 if (result != null) {954 testCaseExecutionData.setValue(result);955 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_SOAP);956 testCaseExecutionData.setPropertyResultMessage(res);957 } else {958 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SOAPFROMLIB_NODATA);959 testCaseExecutionData.setPropertyResultMessage(res);960 }961 }962 } catch (CerberusException exception) {963 LOG.error(exception.toString());964 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_TESTDATA_PROPERTYDONOTEXIST);965 res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseExecutionData.getValue1()));966 testCaseExecutionData.setPropertyResultMessage(res);967 } catch (CerberusEventException ex) {968 LOG.error(ex.toString());969 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP);970 message.setDescription(message.getDescription().replace("%SOAPNAME%", testCaseExecutionData.getValue1()));971 message.setDescription(message.getDescription().replace("%DESCRIPTION%", ex.getMessageError().getDescription()));972 testCaseExecutionData.setPropertyResultMessage(message);973 }974 return testCaseExecutionData;975 }976 private TestCaseExecutionData property_getFromXml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {977 // 1. Get XML value to parse978 String xmlToParse = null;979 // If value2 is defined, then take it as XML value to parse980 if (!(StringUtil.isNullOrEmpty(testCaseExecutionData.getValue2()))) {981 xmlToParse = testCaseExecutionData.getValue2();982 } // Else try to get the last known response from service call983 else if (tCExecution.getLastServiceCalled() != null) {984 xmlToParse = tCExecution.getLastServiceCalled().getResponseHTTPBody();985 } // If XML to parse is still null, then there is an error in XML value definition986 else if (xmlToParse == null) {987 testCaseExecutionData.setPropertyResultMessage(988 new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML)989 .resolveDescription("VALUE1", testCaseExecutionData.getValue1())990 .resolveDescription("VALUE2", testCaseExecutionData.getValue2()));991 return testCaseExecutionData;992 }993 // Else we can try to parse it thanks to the dedicated service994 try {995 String valueFromXml = xmlUnitService.getFromXml(xmlToParse, testCaseExecutionData.getValue1());996 if (valueFromXml != null) {997 testCaseExecutionData.setValue(valueFromXml);998 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMXML);999 res.setDescription(res.getDescription().replace("%VALUE%", valueFromXml));1000 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1001 testCaseExecutionData.setPropertyResultMessage(res);1002 } else {1003 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML);1004 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1005 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1006 testCaseExecutionData.setPropertyResultMessage(res);1007 }1008 } catch (Exception ex) {1009 LOG.debug(ex.toString());1010 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMXML);1011 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1012 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1013 testCaseExecutionData.setPropertyResultMessage(res);1014 }1015 return testCaseExecutionData;1016 }1017 private TestCaseExecutionData property_getFromCookie(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1018 try {1019 String valueFromCookie = this.webdriverService.getFromCookie(tCExecution.getSession(), testCaseExecutionData.getValue1(), testCaseExecutionData.getValue2());1020 if (valueFromCookie != null) {1021 if (!valueFromCookie.equals("cookieNotFound")) {1022 testCaseExecutionData.setValue(valueFromCookie);1023 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMCOOKIE);1024 res.setDescription(res.getDescription().replace("%COOKIE%", testCaseExecutionData.getValue1()));1025 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));1026 res.setDescription(res.getDescription().replace("%VALUE%", valueFromCookie));1027 testCaseExecutionData.setPropertyResultMessage(res);1028 } else {1029 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOOKIE_COOKIENOTFOUND);1030 res.setDescription(res.getDescription().replace("%COOKIE%", testCaseExecutionData.getValue1()));1031 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));1032 testCaseExecutionData.setPropertyResultMessage(res);1033 }1034 } else {1035 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOOKIE_PARAMETERNOTFOUND);1036 res.setDescription(res.getDescription().replace("%COOKIE%", testCaseExecutionData.getValue1()));1037 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));1038 testCaseExecutionData.setPropertyResultMessage(res);1039 }1040 } catch (Exception exception) {1041 LOG.debug(exception.toString());1042 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMCOOKIE_COOKIENOTFOUND);1043 res.setDescription(res.getDescription().replace("%COOKIE%", testCaseExecutionData.getValue1()));1044 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue2()));1045 testCaseExecutionData.setPropertyResultMessage(res);1046 }1047 return testCaseExecutionData;1048 }1049 private TestCaseExecutionData property_getDifferencesFromXml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {1050 try {1051 LOG.debug("Computing differences between " + testCaseExecutionData.getValue1() + " and " + testCaseExecutionData.getValue2());1052 String differences = xmlUnitService.getDifferencesFromXml(testCaseExecutionData.getValue1(), testCaseExecutionData.getValue2());1053 if (differences != null) {1054 LOG.debug("Computing done.");1055 testCaseExecutionData.setValue(differences);1056 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETDIFFERENCESFROMXML);1057 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1058 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1059 testCaseExecutionData.setPropertyResultMessage(res);1060 } else {1061 LOG.debug("Computing failed.");1062 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETDIFFERENCESFROMXML);1063 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1064 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1065 testCaseExecutionData.setPropertyResultMessage(res);1066 }1067 } catch (Exception ex) {1068 LOG.debug(ex.toString());1069 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETDIFFERENCESFROMXML);1070 res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));1071 res.setDescription(res.getDescription().replace("%VALUE2%", testCaseExecutionData.getValue2()));1072 testCaseExecutionData.setPropertyResultMessage(res);1073 }1074 return testCaseExecutionData;1075 }1076 private TestCaseExecutionData property_getFromJson(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, boolean forceRecalculation) {1077 String jsonResponse = "";1078 try {1079 /**1080 * If tCExecution LastServiceCalled exist, get the response;1081 */1082 if (null != tCExecution.getLastServiceCalled()) {1083 jsonResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();1084 }1085 String newUrl = null;1086 if (!(StringUtil.isNullOrEmpty(testCaseExecutionData.getValue2()))) {1087 newUrl = testCaseExecutionData.getValue2();1088 }1089 String valueFromJson = this.jsonService.getFromJson(jsonResponse, newUrl, testCaseExecutionData.getValue1());1090 if (valueFromJson != null) {1091 if (!"".equals(valueFromJson)) {1092 testCaseExecutionData.setValue(valueFromJson);1093 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMJSON);1094 res.setDescription(res.getDescription().replace("%URL%", testCaseExecutionData.getValue2()));1095 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue1()));1096 res.setDescription(res.getDescription().replace("%VALUE%", valueFromJson));1097 testCaseExecutionData.setPropertyResultMessage(res);1098 } else {1099 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMJSON_PARAMETERNOTFOUND);1100 res.setDescription(res.getDescription().replace("%URL%", testCaseExecutionData.getValue2()));1101 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue1()));1102 testCaseExecutionData.setPropertyResultMessage(res);1103 }1104 } else {1105 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMJSON_PARAMETERNOTFOUND);1106 res.setDescription(res.getDescription().replace("%URL%", testCaseExecutionData.getValue2()));1107 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue1()));1108 testCaseExecutionData.setPropertyResultMessage(res);1109 }1110 } catch (Exception exception) {1111 if (LOG.isDebugEnabled()) {1112 LOG.error(exception.toString());1113 }1114 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMJSON_PARAMETERNOTFOUND);1115 res.setDescription(res.getDescription().replace("%URL%", testCaseExecutionData.getValue2()));1116 res.setDescription(res.getDescription().replace("%PARAM%", testCaseExecutionData.getValue1()));1117 res.setDescription(res.getDescription().replace("%ERROR%", exception.toString()));1118 testCaseExecutionData.setPropertyResultMessage(res);1119 }1120 return testCaseExecutionData;1121 }1122 private TestCaseExecutionData property_getFromDataLib(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution,1123 TestCaseStepActionExecution testCaseStepActionExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {1124 MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB);1125 TestDataLib testDataLib;1126 List<HashMap<String, String>> result = null;1127 AnswerItem<String> answerDecode = new AnswerItem();1128 // We get here the correct TestDataLib entry from the Value1 (name) that better match the context on system, environment and country.1129 AnswerItem<TestDataLib> answer = testDataLibService.readByNameBySystemByEnvironmentByCountry(testCaseExecutionData.getValue1(),1130 tCExecution.getApplicationObj().getSystem(), tCExecution.getEnvironmentData(),1131 tCExecution.getCountry());1132 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answer.getItem() != null) {1133 testDataLib = (TestDataLib) answer.getItem();1134 AnswerList serviceAnswer;1135 //check if there are properties defined in the data specification1136 try {1137 if (testDataLib.getType().equals(TestDataLib.TYPE_SQL)) {1138 //check if the script contains properties that neeed to be calculated1139 answerDecode = variableService.decodeStringCompletly(testDataLib.getScript(), tCExecution, testCaseStepActionExecution, false);1140 String decodedScript = (String) answerDecode.getItem();1141 testDataLib.setScript(decodedScript);1142 if (!(answerDecode.isCodeStringEquals("OK"))) {1143 // If anything wrong with the decode --> we stop here with decode message in the action result.1144 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SQL Script"));1145 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1146 LOG.debug("Property interupted due to decode 'SQL Script'.");1147 return testCaseExecutionData;1148 }1149 }1150 } catch (CerberusEventException cex) {1151 LOG.error(cex.toString());1152 }1153 String decodedLength = null;1154 // Here, we try to decode testCaseCountryProperty field `length` to get the value of property if needed1155 try {1156 answerDecode = variableService.decodeStringCompletly(testCaseCountryProperty.getLength(), tCExecution, testCaseStepActionExecution, false);1157 decodedLength = (String) answerDecode.getItem();1158 if (!(answerDecode.isCodeStringEquals("OK"))) {1159 testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "length"));1160 testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());1161 LOG.debug("Property interupted due to decode 'Length field'.");1162 return testCaseExecutionData;1163 }1164 } catch (CerberusEventException cex) {1165 LOG.error(cex.toString());1166 }1167 // We cast from string to integer ((String)testcasecountryproperty field `length` -> (Integer)testcaseexecutiondata field `length`)1168 // if we can't, testCaseExecutionData field `length` will be equal to 01169 // if we can, we set the value of testCaseExecutionData field `length` to the casted value1170 if (decodedLength != null) {1171 try {1172 Integer.parseInt(decodedLength);1173 testCaseExecutionData.setLength(decodedLength);1174 } catch (NumberFormatException e) {1175 LOG.error(e.toString());1176 MessageEvent msg = new MessageEvent(MessageEventEnum.CASTING_OPERATION_FAILED);1177 msg.setDescription(msg.getDescription().replace("%ERROR%", e.toString()));1178 msg.setDescription(msg.getDescription().replace("%FIELD%", "field length"));1179 testCaseExecutionData.setPropertyResultMessage(msg);1180 testCaseExecutionData.setStopExecution(msg.isStopTest());1181 return testCaseExecutionData;1182 }1183 }1184 //we need to recalculate the result for the lib1185 serviceAnswer = dataLibService.getFromDataLib(testDataLib, testCaseCountryProperty, tCExecution, testCaseExecutionData);1186 testCaseExecutionData.setDataLib(testDataLib.getName());1187 res = serviceAnswer.getResultMessage();1188 result = (List<HashMap<String, String>>) serviceAnswer.getDataList(); //test data library returned by the service1189 if (result != null) {1190 // Keeping raw data to testCaseExecutionData object.1191 testCaseExecutionData.setDataLibRawData(result);1192 // Value of testCaseExecutionData object takes the master subdata entry "".1193 String value = (String) result.get(0).get("");1194 if (value == null) {1195 testCaseExecutionData.setValue(VALUE_NULL);1196 } else {1197 testCaseExecutionData.setValue(value);1198 // Converting HashMap to json.1199 String jsonText = "";1200 JSONArray jsonResult = null;1201 try {1202 jsonResult = dataLibService.convertToJSONObject(result);1203 jsonText = jsonResult.toString();1204 } catch (JSONException ex) {1205 java.util.logging.Logger.getLogger(PropertyService.class.getName()).log(Level.SEVERE, null, ex);1206 }1207 testCaseExecutionData.setJsonResult(jsonText);1208 }1209 //Record result in filessytem.1210 recorderService.recordTestDataLibProperty(tCExecution.getId(), testCaseCountryProperty.getProperty(), 1, result);1211 }1212 res.setDescription(res.getDescription().replace("%ENTRY%", testDataLib.getName()).replace("%ENTRYID%", String.valueOf(testDataLib.getTestDataLibID())));1213 } else {//no TestDataLib found was returned1214 //the library does not exist at all1215 AnswerList nameExistsAnswer = testDataLibService.readNameListByName(testCaseExecutionData.getValue1(), 1, false);1216 if (nameExistsAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && nameExistsAnswer.getTotalRows() > 0) {1217 //if the library name exists but was not available or does not exist for the current specification but exists for other countries/environments/systems...

Full Screen

Full Screen

Source:SQLService.java Github

copy

Full Screen

...190 list.add(resultSet.getString(1));191 nbFetch++;192 }193 } catch (SQLException exception) {194 LOG.warn("Unable to execute query : " + exception.toString());195 } finally {196 resultSet.close();197 }198 } catch (SQLTimeoutException exception) {199 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_TIMEOUT);200 msg.setDescription(msg.getDescription().replace("%SQL%", sql));201 msg.setDescription(msg.getDescription().replace("%TIMEOUT%", String.valueOf(defaultTimeOut)));202 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));203 } catch (SQLException exception) {204 LOG.warn(exception.toString());205 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_ERROR);206 msg.setDescription(msg.getDescription().replace("%SQL%", sql));207 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));208 throwEx = true;209 } finally {210 preStat.close();211 }212 } catch (SQLException exception) {213 LOG.warn(exception.toString());214 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_ERROR);215 msg.setDescription(msg.getDescription().replace("%SQL%", sql));216 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));217 throwEx = true;218 } catch (NullPointerException exception) {219 //TODO check where exception occur220 LOG.warn(exception.toString());221 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_CANNOTACCESSJDBC);222 msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));223 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));224 throwEx = true;225 } 226 if (throwEx) {227 throw new CerberusEventException(msg);228 }229 return list;230 }231 @Override232 public MessageEvent executeUpdate(String system, String country, String environment, String database, String sql) {233 String connectionName;234 CountryEnvironmentDatabase countryEnvironmentDatabase;235 MessageEvent msg = new MessageEvent(MessageEventEnum.ACTION_FAILED);236 try {237 countryEnvironmentDatabase = this.countryEnvironmentDatabaseService.convert(this.countryEnvironmentDatabaseService.readByKey(system,238 country, environment, database));239 if (countryEnvironmentDatabase != null) {240 connectionName = countryEnvironmentDatabase.getConnectionPoolName();241 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_GENERIC);242 msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));243 if (!(StringUtil.isNullOrEmpty(connectionName))) {244 if (connectionName.equals("cerberus" + System.getProperty("org.cerberus.environment"))) {245 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_AGAINST_CERBERUS);246 } else {247 try(Connection connection = this.databaseSpring.connect(connectionName);248 PreparedStatement preStat = connection.prepareStatement(sql);) {249 Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_actionexecutesqlupdate_timeout", system, 60);250 preStat.setQueryTimeout(sqlTimeout);251 try {252 LOG.info("Sending to external Database (executeUpdate) : '" + connectionName + "' SQL '" + sql + "'");253 preStat.executeUpdate();254 int nbUpdate = preStat.getUpdateCount();255 msg = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_EXECUTESQLUPDATE)256 .resolveDescription("NBROWS", String.valueOf(nbUpdate))257 .resolveDescription("JDBC", connectionName).resolveDescription("SQL", sql);258 } catch (SQLTimeoutException exception) {259 LOG.warn(exception.toString());260 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_TIMEOUT);261 msg.setDescription(msg.getDescription().replace("%SQL%", sql));262 msg.setDescription(msg.getDescription().replace("%TIMEOUT%", String.valueOf(sqlTimeout)));263 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));264 } catch (SQLException exception) {265 LOG.warn(exception.toString());266 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_ERROR);267 msg.setDescription(msg.getDescription().replace("%SQL%", sql));268 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));269 } 270 } catch (SQLException exception) {271 LOG.warn(exception.toString());272 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_ERROR);273 msg.setDescription(msg.getDescription().replace("%SQL%", sql));274 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));275 } catch (NullPointerException exception) {276 LOG.warn(exception.toString());277 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_CANNOTACCESSJDBC);278 msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));279 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));280 }281 }282 } else {283 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_DATABASECONFIGUREDBUTJDBCPOOLEMPTY);284 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system));285 msg.setDescription(msg.getDescription().replace("%COUNTRY%", country));286 msg.setDescription(msg.getDescription().replace("%ENV%", environment));287 msg.setDescription(msg.getDescription().replace("%DATABASE%", database));288 }289 } else {290 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_DATABASENOTCONFIGURED);291 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system));292 msg.setDescription(msg.getDescription().replace("%COUNTRY%", country));293 msg.setDescription(msg.getDescription().replace("%ENV%", environment));294 msg.setDescription(msg.getDescription().replace("%DATABASE%", database));295 }296 } catch (CerberusException ex) {297 LOG.error(ex.toString());298 }299 return msg;300 }301 @Override302 public MessageEvent executeCallableStatement(String system, String country, String environment, String database, String sql) {303 String connectionName;304 CountryEnvironmentDatabase countryEnvironmentDatabase;305 MessageEvent msg = new MessageEvent(MessageEventEnum.ACTION_FAILED);306 try {307 countryEnvironmentDatabase = this.countryEnvironmentDatabaseService.convert(this.countryEnvironmentDatabaseService.readByKey(system,308 country, environment, database));309 if (countryEnvironmentDatabase != null) {310 connectionName = countryEnvironmentDatabase.getConnectionPoolName();311 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_GENERIC);312 msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));313 if (!(StringUtil.isNullOrEmpty(connectionName))) {314 if (connectionName.contains("cerberus")) {315 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_AGAINST_CERBERUS);316 } else {317 try(Connection connection = this.databaseSpring.connect(connectionName);318 CallableStatement cs = connection.prepareCall(sql);) {319 320 Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_actionexecutesqlstoredprocedure_timeout", system, 60);321 cs.setQueryTimeout(sqlTimeout);322 try {323 cs.execute();324 int nbUpdate = cs.getUpdateCount();325 msg = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_EXECUTESQLSTOREDPROCEDURE)326 .resolveDescription("NBROWS", String.valueOf(nbUpdate))327 .resolveDescription("JDBC", connectionName).resolveDescription("SQL", sql);328 } catch (SQLTimeoutException exception) {329 LOG.warn(exception.toString());330 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_TIMEOUT);331 msg.setDescription(msg.getDescription().replace("%SQL%", sql));332 msg.setDescription(msg.getDescription().replace("%TIMEOUT%", String.valueOf(sqlTimeout)));333 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));334 } catch (SQLException exception) {335 LOG.warn(exception.toString());336 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_ERROR);337 msg.setDescription(msg.getDescription().replace("%SQL%", sql));338 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));339 } finally {340 cs.close();341 }342 } catch (SQLException exception) {343 LOG.warn(exception.toString());344 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_ERROR);345 msg.setDescription(msg.getDescription().replace("%SQL%", sql));346 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));347 } catch (NullPointerException exception) {348 LOG.warn(exception.toString());349 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_CANNOTACCESSJDBC);350 msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));351 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));352 }353 }354 } else {355 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_DATABASECONFIGUREDBUTJDBCPOOLEMPTY);356 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system));357 msg.setDescription(msg.getDescription().replace("%COUNTRY%", country));358 msg.setDescription(msg.getDescription().replace("%ENV%", environment));359 msg.setDescription(msg.getDescription().replace("%DATABASE%", database));360 }361 } else {362 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_DATABASENOTCONFIGURED);363 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system));364 msg.setDescription(msg.getDescription().replace("%COUNTRY%", country));365 msg.setDescription(msg.getDescription().replace("%ENV%", environment));366 msg.setDescription(msg.getDescription().replace("%DATABASE%", database));367 }368 } catch (CerberusException ex) {369 LOG.error(ex.toString());370 }371 return msg;372 }373 @Override374 public AnswerList queryDatabaseNColumns(String connectionName, String sql, int rowLimit, int defaultTimeOut, String system, HashMap<String, String> columnsToGet) {375 AnswerList listResult = new AnswerList();376 List<HashMap<String, String>> list;377 int maxSecurityFetch = parameterService.getParameterIntegerByKey("cerberus_testdatalib_fetchmax", system, 100);378 int maxFetch;379 if (rowLimit > 0 && rowLimit < maxSecurityFetch) {380 maxFetch = rowLimit;381 } else {382 maxFetch = maxSecurityFetch;383 }384 int nbFetch = 0;385 int nbColMatch = 0;386 String error_desc = "";387 MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);388 msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));389 390 try(Connection connection = this.databaseSpring.connect(connectionName);391 PreparedStatement preStat = connection.prepareStatement(sql);) {392 preStat.setQueryTimeout(defaultTimeOut);393 try {394 LOG.info("Sending to external Database (queryDatabaseNColumns) : '" + connectionName + "' SQL '" + sql + "'");395 ResultSet resultSet = preStat.executeQuery();396 int nrColumns = resultSet.getMetaData().getColumnCount();397 list = new ArrayList<HashMap<String, String>>();398 try {399 while ((resultSet.next()) && (nbFetch < maxFetch)) {400 nbColMatch = 0;401 HashMap<String, String> row = new HashMap<String, String>();402 for (Map.Entry<String, String> entry : columnsToGet.entrySet()) {403 String column = entry.getValue();404 String name = entry.getKey();405 try {406 String valueSQL = resultSet.getString(column);407 if (valueSQL == null) { // If data is null from the database, we convert it to the static string <NULL>. 408 valueSQL = "<NULL>";409 }410 row.put(name, valueSQL); // We put the result of the subData.411 nbColMatch++;412 } catch (SQLException exception) {413 if (nbFetch == 0) {414 if ("".equals(error_desc)) {415 error_desc = column;416 } else {417 error_desc = error_desc + ", " + column;418 }419 }420 }421 }422 list.add(row);423 nbFetch++;424 }425 listResult.setDataList(list);426 listResult.setTotalRows(list.size());427 if (list.isEmpty()) { // No data was fetched.428 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_NODATA);429 } else if (nbColMatch == 0) { // None of the columns could be match.430 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_NOCOLUMNMATCH);431 msg.setDescription(msg.getDescription().replace("%BADCOLUMNS%", error_desc));432 } else if (!("".equals(error_desc))) { // At least a column could not be parsed433 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_COLUMNNOTMATCHING);434 msg.setDescription(msg.getDescription().replace("%BADCOLUMNS%", error_desc));435 }436 } catch (SQLTimeoutException exception) {437 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_TIMEOUT);438 msg.setDescription(msg.getDescription().replace("%SQL%", sql));439 msg.setDescription(msg.getDescription().replace("%TIMEOUT%", String.valueOf(defaultTimeOut)));440 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));441 } catch (SQLException exception) {442 LOG.warn("Unable to execute query : " + exception.toString());443 } finally {444 if (resultSet != null) {445 resultSet.close();446 }447 }448 } catch (SQLTimeoutException exception) {449 LOG.warn("TimeOut " + exception.toString());450 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_TIMEOUT);451 msg.setDescription(msg.getDescription().replace("%SQL%", sql));452 msg.setDescription(msg.getDescription().replace("%TIMEOUT%", String.valueOf(defaultTimeOut)));453 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));454 } catch (SQLException exception) {455 LOG.warn(exception.toString());456 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_ERROR);457 msg.setDescription(msg.getDescription().replace("%SQL%", sql));458 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));459 } 460 } catch (SQLException exception) {461 LOG.warn(exception.toString());462 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_ERROR);463 msg.setDescription(msg.getDescription().replace("%SQL%", sql));464 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));465 } catch (NullPointerException exception) {466 //TODO check where exception occur467 LOG.warn(exception.toString());468 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_CANNOTACCESSJDBC);469 msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));470 msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));471 }472 listResult.setResultMessage(msg);473 return listResult;474 }475}...

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.entity;2import java.sql.Timestamp;3public class TestCaseExecutionData {4 private long id;5 private String test;6 private String testCase;7 private int index;8 private String property;9 private String type;10 private String database;11 private String value1;12 private String value2;13 private String value3;14 private String value4;15 private String value5;16 private String value6;17 private String value7;18 private String value8;19 private String value9;20 private String value10;21 private Timestamp dateCreated;22 private Timestamp dateModif;23 public TestCaseExecutionData() {24 }25 public TestCaseExecutionData(long id, String test, String testCase, int index, String property, String type, String database, String value1, String value2, String value3, String value4, String value5, String value6, String value7, String value8, String value9, String value10, Timestamp dateCreated, Timestamp dateModif) {26 this.id = id;27 this.test = test;28 this.testCase = testCase;29 this.index = index;30 this.property = property;31 this.type = type;32 this.database = database;33 this.value1 = value1;34 this.value2 = value2;35 this.value3 = value3;36 this.value4 = value4;37 this.value5 = value5;38 this.value6 = value6;39 this.value7 = value7;40 this.value8 = value8;41 this.value9 = value9;42 this.value10 = value10;43 this.dateCreated = dateCreated;44 this.dateModif = dateModif;45 }46 public long getId() {47 return id;48 }49 public void setId(long id) {50 this.id = id;51 }52 public String getTest() {53 return test;54 }55 public void setTest(String test) {56 this.test = test;57 }58 public String getTestCase() {59 return testCase;60 }61 public void setTestCase(String testCase) {62 this.testCase = testCase;63 }64 public int getIndex() {65 return index;66 }67 public void setIndex(int index) {68 this.index = index;69 }70 public String getProperty() {71 return property;72 }

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecutionData;2public class TestToString {3 public static void main(String[] args) {4 TestCaseExecutionData testCaseExecutionData = new TestCaseExecutionData();5 testCaseExecutionData.setIndex(1);6 testCaseExecutionData.setTest("TEST");7 testCaseExecutionData.setTestCase("TESTCASE");8 testCaseExecutionData.setCountry("COUNTRY");9 testCaseExecutionData.setEnvironment("ENVIRONMENT");10 testCaseExecutionData.setControlStatus("CONTROLSTATUS");11 testCaseExecutionData.setControlMessage("CONTROLMESSAGE");12 testCaseExecutionData.setReturnCode("RETURNCODE");13 testCaseExecutionData.setReturnMessage("RETURNMESSAGE");14 testCaseExecutionData.setApplication("APPLICATION");15 testCaseExecutionData.setApplicationObj("APPLICATIONOBJ");16 testCaseExecutionData.setApplicationObjID("APPLICATIONOBJID");17 testCaseExecutionData.setScreen("SCREEN");18 testCaseExecutionData.setScreenSize("SCREENSIZE");19 testCaseExecutionData.setControlProperty("CONTROLPROPERTY");20 testCaseExecutionData.setControlValue("CONTROLVALUE");21 testCaseExecutionData.setControlType("CONTROLTYPE");22 testCaseExecutionData.setControlName("CONTROLNAME");23 testCaseExecutionData.setControlProperty("CONTROLPROPERTY");24 testCaseExecutionData.setControlValue("CONTROLVALUE");25 testCaseExecutionData.setControlType("CONTROLTYPE");26 testCaseExecutionData.setControlName("CONTROLNAME");27 testCaseExecutionData.setControlProperty("CONTROLPROPERTY");28 testCaseExecutionData.setControlValue("CONTROLVALUE");29 testCaseExecutionData.setControlType("CONTROLTYPE");30 testCaseExecutionData.setControlName("CONTROLNAME");31 testCaseExecutionData.setControlProperty("CONTROLPROPERTY");32 testCaseExecutionData.setControlValue("CONTROLVALUE");33 testCaseExecutionData.setControlType("CONTROLTYPE");34 testCaseExecutionData.setControlName("CONTROLNAME");35 testCaseExecutionData.setControlProperty("CONTROLPROPERTY");36 testCaseExecutionData.setControlValue("CONTROLVALUE");37 testCaseExecutionData.setControlType("CONTROLTYPE");38 testCaseExecutionData.setControlName("CONTROLNAME");39 testCaseExecutionData.setControlProperty("CONTROLPROPERTY");40 testCaseExecutionData.setControlValue("CONTROLVALUE");41 testCaseExecutionData.setControlType("CONTROLTYPE");42 testCaseExecutionData.setControlName("CONTROLNAME");43 testCaseExecutionData.setControlProperty("CONTROLPROPERTY");44 testCaseExecutionData.setControlValue("CONTROLVALUE");45 testCaseExecutionData.setControlType("CONTROLTYPE");46 testCaseExecutionData.setControlName("CONTROLNAME");

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.entity;2import org.cerberus.crud.entity.TestCaseExecutionData;3import java.util.*;4public class 3 {5 public static void main(String[] args) {6 TestCaseExecutionData testCaseExecutionData = new TestCaseExecutionData();7 testCaseExecutionData.setApplication("application");8 testCaseExecutionData.setCountry("country");9 testCaseExecutionData.setEnvironment("environment");10 testCaseExecutionData.setTestCase("testCase");11 testCaseExecutionData.setTest("test");12 testCaseExecutionData.setTestBattery("testBattery");13 testCaseExecutionData.setTestBatteryExecution("testBatteryExecution");14 testCaseExecutionData.setTestBatteryExecutionQueue("testBatteryExecutionQueue");15 testCaseExecutionData.setTestBatteryQueue("testBatteryQueue");16 testCaseExecutionData.setTestExecutionQueue("testExecutionQueue");17 testCaseExecutionData.setTestProject("testProject");18 testCaseExecutionData.setTestSuite("testSuite");19 testCaseExecutionData.setControlStatus("controlStatus");20 testCaseExecutionData.setControlMessage("controlMessage");21 testCaseExecutionData.setControlProperty("controlProperty");22 testCaseExecutionData.setControlValue("controlValue");23 testCaseExecutionData.setControlType("controlType");24 testCaseExecutionData.setControlConditionOperator("controlConditionOperator");25 testCaseExecutionData.setControlConditionValue1("controlConditionValue1");26 testCaseExecutionData.setControlConditionValue2("controlConditionValue2");27 testCaseExecutionData.setControlConditionValue3("controlConditionValue3");28 testCaseExecutionData.setControlConditionValue4("controlConditionValue4");29 testCaseExecutionData.setControlProperty2("controlProperty2");30 testCaseExecutionData.setControlValue2("controlValue2");31 testCaseExecutionData.setControlType2("controlType2");32 testCaseExecutionData.setControlConditionOperator2("controlConditionOperator2");33 testCaseExecutionData.setControlConditionValue1_2("controlConditionValue1_2");34 testCaseExecutionData.setControlConditionValue2_2("controlConditionValue2_2");35 testCaseExecutionData.setControlConditionValue3_2("controlConditionValue3_2");36 testCaseExecutionData.setControlConditionValue4_2("controlConditionValue4_2");37 testCaseExecutionData.setControlProperty3("controlProperty3");38 testCaseExecutionData.setControlValue3("controlValue3");39 testCaseExecutionData.setControlType3("controlType3");40 testCaseExecutionData.setControlConditionOperator3("controlConditionOperator3

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.entity;2import java.io.Serializable;3public class TestCaseExecutionData implements Serializable {4private String property;5private String value;6private String type;7private String description;8public TestCaseExecutionData() {9}10public TestCaseExecutionData(String property, String value, String type, String description) {11 this.property = property;12 this.value = value;13 this.type = type;14 this.description = description;15}16public String getProperty() {17 return property;18}19public void setProperty(String property) {20 this.property = property;21}22public String getValue() {23 return value;24}25public void setValue(String value) {26 this.value = value;27}28public String getType() {29 return type;30}31public void setType(String type) {32 this.type = type;33}34public String getDescription() {35 return description;36}37public void setDescription(String description) {38 this.description = description;39}40public String toString() {41 return "TestCaseExecutionData{" + "property=" + property + ", value=" + value + ", type=" + type + ", description=" + description + '}';42}43}44package org.cerberus.crud.entity;45import java.io.Serializable;46public class TestCaseExecutionData implements Serializable {47private String property;48private String value;49private String type;50private String description;51public TestCaseExecutionData() {52}53public TestCaseExecutionData(String property, String value, String type, String description) {54 this.property = property;55 this.value = value;56 this.type = type;57 this.description = description;58}59public String getProperty() {60 return property;61}62public void setProperty(String property) {63 this.property = property;64}65public String getValue() {66 return value;67}68public void setValue(String value) {69 this.value = value;70}71public String getType() {72 return type;73}74public void setType(String type) {75 this.type = type;76}77public String getDescription() {78 return description;79}80public void setDescription(String description) {81 this.description = description;82}83public String toString() {84 return "TestCaseExecutionData{" + "property=" + property + ", value=" + value + ", type=" + type + ", description=" + description + '}';85}86}

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