How to use getMethod method of org.cerberus.crud.entity.TestDataLib class

Best Cerberus-source code snippet using org.cerberus.crud.entity.TestDataLib.getMethod

Source:DataLibService.java Github

copy

Full Screen

...700 */701 String servicePath = lib.getServicePath();702 LOG.debug("Service Path : " + lib.getServicePath());703 // Service Call is made here.704 AnswerItem ai = serviceService.callService(lib.getService(), lib.getDatabaseUrl(), lib.getEnvelope(), lib.getServicePath(), lib.getMethod(), tCExecution);705 msg = ai.getResultMessage();706 //if the call returns success then we can process the soap ressponse707 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {708 appService = (AppService) ai.getItem();709 //Record result in filessytem.710// testCaseExecutionData.addFileList(recorderService.recordServiceCall(tCExecution, null, 0, testCaseExecutionData.getProperty(), appService));711 recorderService.recordServiceCall(tCExecution, null, 0, testCaseExecutionData.getProperty(), appService);712 // Call successful so we can start to parse the result and build RawData per columns from subdata entries.713 /**714 * This Step will calculate hashTemp1 : Hash of List from715 * the Service response.716 */717 // Will contain the nb of row of the target list of Hash.718 int finalnbRow = 0;719 // Will contain the result of the XML parsing.720 HashMap<String, List<String>> hashTemp1 = new HashMap<>();721 if (columnList.isEmpty()) { // No subdata could be found on the testdatalib.722 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_NOSUBDATA);723 msg.setDescription(msg.getDescription()724 .replace("%ENTRY%", lib.getName())725 .replace("%ENTRYID%", lib.getTestDataLibID().toString()));726 } else {727 switch (appService.getResponseHTTPBodyContentType()) {728 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:729 Document xmlDocument = xmlUnitService.getXmlDocument(appService.getResponseHTTPBody());730 // We get the content of the XML in order to report it log messages.731 responseString = appService.getResponseHTTPBody();732 for (Map.Entry<String, String> entry : columnList.entrySet()) {733 String subDataColumnToTreat = entry.getKey(); // SubData734 String subDataParsingAnswer = entry.getValue(); // Parsing Answer735 listTemp1 = new ArrayList<>();736 try {737 // We try to parse the XML with the subdata Parsing Answer.738 NodeList candidates = XmlUtil.evaluate(xmlDocument, subDataParsingAnswer);739 if (candidates.getLength() > 0) {740 for (int i = 0; i < candidates.getLength(); i++) { // Loop on all Values that match in XML.741 //We get the value from XML742 String value = candidates.item(i).getNodeValue();743 if (value == null) { // No value found.744 if (candidates.item(i) != null) {745 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_CHECK_XPATH);746 msg.setDescription(msg.getDescription()747 .replace("%XPATH%", subDataParsingAnswer)748 .replace("%SUBDATA%", subDataColumnToTreat)749 .replace("%ENTRY%", lib.getName())750 .replace("%ENTRYID%", lib.getTestDataLibID().toString()));751 } else {752 //no elements were returned by the XPATH expression753 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XML_NOTFOUND);754 msg.setDescription(msg.getDescription()755 .replace("%XPATH%", subDataParsingAnswer)756 .replace("%SUBDATA%", subDataColumnToTreat)757 .replace("%ENTRY%", lib.getName())758 .replace("%XMLCONTENT%", responseString)759 .replace("%ENTRYID%", lib.getTestDataLibID().toString())760 );761 }762 } else { // Value were found we add it to the current list.763 listTemp1.add(value);764 }765 }766 // Add the Subdata with associated list in the HashMap.767 hashTemp1.put(subDataColumnToTreat, listTemp1);768 // Getting the nb of row of the final result. (Max of all the Subdata retrieved from the XML)769 if (listTemp1.size() > finalnbRow) {770 finalnbRow = listTemp1.size();771 }772 } else {773 //no elements were returned by the XPATH expression774 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XML_NOTFOUND);775 msg.setDescription(msg.getDescription()776 .replace("%XPATH%", subDataParsingAnswer)777 .replace("%SUBDATA%", subDataColumnToTreat)778 .replace("%ENTRY%", lib.getName())779 .replace("%XMLCONTENT%", responseString)780 .replace("%ENTRYID%", lib.getTestDataLibID().toString())781 );782 }783 } catch (XmlUtilException ex) {784 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XMLEXCEPTION);785 msg.setDescription(msg.getDescription()786 .replace("%XPATH%", subDataParsingAnswer)787 .replace("%SUBDATA%", subDataColumnToTreat)788 .replace("%ENTRY%", lib.getName())789 .replace("%ENTRYID%", lib.getTestDataLibID().toString())790 .replace("%REASON%", ex.toString() + " Detail answer " + responseString));791 } catch (Exception ex) {792 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XMLEXCEPTION);793 msg.setDescription(msg.getDescription()794 .replace("%XPATH%", lib.getSubDataParsingAnswer())795 .replace("%SUBDATA%", "")796 .replace("%REASON%", ex.toString()));797 }798 }799 /**800 * This Step will convert hashTemp1 (Hash of801 * List) to target listResult (list of Hash).802 */803 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {804 for (int i = 0; i < finalnbRow; i++) { // Loop on all Values that match in XML.805 resultHash = new HashMap<String, String>();806 for (Map.Entry<String, String> entry : columnList.entrySet()) { // Loop on all SubData of the TestDataLib.807 listTemp1 = hashTemp1.get(entry.getKey());808 if (listTemp1 != null) {809 if (i < listTemp1.size()) {810 resultHash.put(entry.getKey(), listTemp1.get(i));811 } else {812 resultHash.put(entry.getKey(), "");813 }814 }815 }816 listResult.add(resultHash);817 }818 }819 /**820 * This Step will pick the correct listResult821 * (list of Hash) from the type of Property.822 */823 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {824 result.setDataList(listResult);825 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SOAP);826 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size()))827 .replace("%URL%", servicePath).replace("%OPER%", lib.getMethod()));828 }829 break;830 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:831 // We get the content of the XML in order to report it log messages.832 responseString = appService.getResponseHTTPBody();833 for (Map.Entry<String, String> entry : columnList.entrySet()) {834 String subDataColumnToTreat = entry.getKey(); // SubData835 String subDataParsingAnswer = entry.getValue(); // Parsing Answer836 listTemp1 = new ArrayList<>();837 try {838 // We try to parse the XML with the subdata Parsing Answer.839 listTemp1 = jsonService.getFromJson(responseString, subDataParsingAnswer);840 if (listTemp1.size() > 0) {841 // Add the Subdata with associated list in the HashMap.842 hashTemp1.put(subDataColumnToTreat, listTemp1);843 // Getting the nb of row of the final result. (Max of all the Subdata retrieved from the XML)844 if (listTemp1.size() > finalnbRow) {845 finalnbRow = listTemp1.size();846 }847 } else {848 //no elements were returned by the XPATH expression849 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_JSON_NOTFOUND);850 msg.setDescription(msg.getDescription()851 .replace("%XPATH%", subDataParsingAnswer)852 .replace("%SUBDATA%", subDataColumnToTreat)853 .replace("%ENTRY%", lib.getName())854 .replace("%XMLCONTENT%", responseString)855 .replace("%ENTRYID%", lib.getTestDataLibID().toString())856 );857 }858 } catch (Exception ex) {859 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_JSONEXCEPTION);860 msg.setDescription(msg.getDescription()861 .replace("%XPATH%", lib.getSubDataParsingAnswer())862 .replace("%SUBDATA%", "")863 .replace("%REASON%", ex.toString()));864 }865 }866 /**867 * This Step will convert hashTemp1 (Hash of868 * List) to target listResult (list of Hash).869 */870 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {871 for (int i = 0; i < finalnbRow; i++) { // Loop on all Values that match in XML.872 resultHash = new HashMap<String, String>();873 for (Map.Entry<String, String> entry : columnList.entrySet()) { // Loop on all SubData of the TestDataLib.874 listTemp1 = hashTemp1.get(entry.getKey());875 if (listTemp1 != null) {876 if (i < listTemp1.size()) {877 resultHash.put(entry.getKey(), listTemp1.get(i));878 } else {879 resultHash.put(entry.getKey(), "");880 }881 }882 }883 listResult.add(resultHash);884 }885 }886 /**887 * This Step will pick the correct listResult888 * (list of Hash) from the type of Property.889 */890 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {891 result.setDataList(listResult);892 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SOAP);893 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size()))894 .replace("%URL%", servicePath).replace("%OPER%", lib.getMethod()));895 }896 break;897 default:898 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOTSUPPORTEDSERVICERESULT);899 msg.setDescription(msg.getDescription().replace("%FORMAT%", appService.getResponseHTTPBodyContentType()));900 }901 }902 } else {903 String soapError = msg.getDescription();904 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_SOAPCALLFAILED);905 msg.setDescription(msg.getDescription()906 .replace("%SOAPERROR%", soapError));907 }908 msg.setDescription(msg.getDescription()909 .replace("%SERVICE%", servicePath)910 .replace("%OPERATION%", lib.getMethod()));911 result.setResultMessage(msg);912 break;913 case TestDataLib.TYPE_INTERNAL:914 result = testDataLibService.readINTERNALWithSubdataByCriteria(lib.getName(), lib.getSystem(), lib.getCountry(), lib.getEnvironment(), rowLimit, system);915 //if the sql service returns a success message then we can process it916 if ((result.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !result.getDataList().isEmpty()) {917 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_INTERNAL);918 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())));919 result.setResultMessage(msg);920 } else if ((result.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && result.getDataList().isEmpty()) {921 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_INTERNALNODATA);922 msg.setDescription(msg.getDescription().replace("%SYSTEM%", lib.getSystem())923 .replace("%ENV%", lib.getEnvironment()).replace("%COUNTRY%", lib.getCountry()));924 result.setResultMessage(msg);...

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