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

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

Source:DataLibService.java Github

copy

Full Screen

...310 int initNB = dataObjectList.getDataList().size();311 // We get the list of values that were already used.312 List<String> pastValues = this.testCaseExecutionDataService.getPastValuesOfProperty(tCExecution.getId(),313 testCaseProperties.getProperty(), tCExecution.getTest(), tCExecution.getTestCase(),314 tCExecution.getCountryEnvParam().getBuild(), tCExecution.getEnvironmentData(), tCExecution.getCountry());315 int removedNB = 0;316 // We save all rows that needs to be removed to listToremove.317 List<Map<String, String>> listToremove = new ArrayList<Map<String, String>>();318 list = dataObjectList.getDataList();319 for (String valueToRemove : pastValues) {320 for (Map<String, String> curentRow : list) {321 if (curentRow.get("").equals(valueToRemove)) {322 if (true) {323 listToremove.add(curentRow);324 removedNB++;325 }326 }327 }328 }329 // We remove all listToremove entries from list.330 list.removeAll(listToremove);331 if (list != null && !list.isEmpty()) { // We pick a random value from the left entries of the list.332 if (list.size() < outputRequestedDimention) { // Still some results available but not enougth compared to what we requested.333 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_RANDOMNEW_NOTENOUGTHRECORDS)334 .resolveDescription("REMNB", Integer.toString(listToremove.size()))335 .resolveDescription("TOTNB", Integer.toString(initNB))336 .resolveDescription("NBREQUEST", Integer.toString(outputRequestedDimention)));337 } else {338 // Get a random list.339 List<Integer> listTempRandom = getRandomListOfInteger(dataObjectList.getDataList().size(), outputRequestedDimention);340 String selectedList = "";341 // Pick the result from list.342 for (int i : listTempRandom) {343 int j = i + 1;344 selectedList += Integer.toString(j) + ",";345 resultObject.add(dataObjectList.getDataList().get(i));346 }347 selectedList = StringUtil.removeLastChar(selectedList, 1);348 result.setDataList(resultObject);349 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURERANDOMNEW)350 .resolveDescription("TOTNB", Integer.toString(initNB))351 .resolveDescription("REMNB", Integer.toString(removedNB))352 .resolveDescription("POS", selectedList)353 .resolveDescription("TOTALPOS", Integer.toString(list.size())));354 }355 } else { // No more entries available.356 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_RANDOMNEW_NOMORERECORD)357 .resolveDescription("TOTNB", Integer.toString(initNB)));358 }359 return result;360 }361 @Override362 public AnswerList<HashMap<String, String>> filterWithNatureNOTINUSE(AnswerList<HashMap<String, String>> dataObjectList, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, int outputRequestedDimention) {363 AnswerList<HashMap<String, String>> result = new AnswerList();364 List<HashMap<String, String>> list = dataObjectList.getDataList(); // Temporary list in order to treat the input list365 List<HashMap<String, String>> resultObject;366 resultObject = new ArrayList<HashMap<String, String>>();367 int initNB = dataObjectList.getDataList().size();368 // We get the list of values that are beeing used.369 Integer peTimeout;370 try {371 peTimeout = Integer.valueOf(parameterService.findParameterByKey("cerberus_notinuse_timeout", tCExecution.getApplicationObj().getSystem()).getValue());372 List<String> pastValues = this.testCaseExecutionDataService.getInUseValuesOfProperty(tCExecution.getId(), testCaseCountryProperty.getProperty(), tCExecution.getEnvironmentData(), tCExecution.getCountry(), peTimeout);373 int removedNB = 0;374 // We save all rows that needs to be removed to listToremove.375 List<Map<String, String>> listToremove = new ArrayList<>();376 for (String valueToRemove : pastValues) {377 for (Map<String, String> curentRow : list) {378 if (curentRow.get("").equals(valueToRemove)) {379 if (true) {380 listToremove.add(curentRow);381 removedNB++;382 }383 }384 }385 }386 // We remove all listToremove entries from list.387 list.removeAll(listToremove);388 if (list != null && !list.isEmpty()) { // We pick a random value from the left entries of the list.389 if (list.size() < outputRequestedDimention) { // Still some results available but not enougth compared to what we requested.390 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOTINUSE_NOTENOUGTHRECORDS)391 .resolveDescription("REMNB", Integer.toString(listToremove.size()))392 .resolveDescription("TOTNB", Integer.toString(initNB))393 .resolveDescription("NBREQUEST", Integer.toString(outputRequestedDimention)));394 } else {395 // Get a random list.396 List<Integer> listTempRandom = getRandomListOfInteger(dataObjectList.getDataList().size(), outputRequestedDimention);397 String selectedList = "";398 // Pick the result from list.399 for (int i : listTempRandom) {400 int j = i + 1;401 selectedList += Integer.toString(j) + ",";402 resultObject.add(dataObjectList.getDataList().get(i));403 }404 selectedList = StringUtil.removeLastChar(selectedList, 1);405 result.setDataList(resultObject);406 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURENOTINUSE)407 .resolveDescription("TOTNB", Integer.toString(initNB))408 .resolveDescription("REMNB", Integer.toString(removedNB))409 .resolveDescription("POS", selectedList)410 .resolveDescription("TOTALPOS", Integer.toString(list.size())));411 }412 } else { // No more entries available.413 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOTINUSE_NOMORERECORD)414 .resolveDescription("TOTNB", Integer.toString(initNB)));415 }416 } catch (CerberusException ex) {417 LOG.warn(ex);418 }419 return result;420 }421 /**422 * Get the list of subData423 *424 * @param lib425 * @return426 */427 private AnswerItem<HashMap<String, String>> getSubDataFromType(TestDataLib lib) {428 AnswerList answerData = new AnswerList();429 AnswerItem<HashMap<String, String>> result = new AnswerItem();430 MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);431 List<TestDataLibData> objectDataList = new ArrayList<TestDataLibData>();432 HashMap<String, String> row = new HashMap<String, String>();433 switch (lib.getType()) {434 case TestDataLib.TYPE_CSV:435 answerData = testDataLibDataService.readByVarious(lib.getTestDataLibID(), null, null, "N");436 if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {437 objectDataList = answerData.getDataList();438 boolean missingKey = true;439 for (TestDataLibData tdld : objectDataList) {440 row.put(tdld.getSubData(), tdld.getColumnPosition());441 if (tdld.getSubData().equalsIgnoreCase("")) {442 missingKey = false;443 }444 }445 result.setItem(row);446 if (missingKey) {447 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATACSVNOKEY);448 result.setResultMessage(msg);449 } else {450 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);451 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(answerData.getDataList().size())));452 result.setResultMessage(msg);453 }454 } else if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getDataList().isEmpty()) {455 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOSUBDATACSV);456 result.setResultMessage(msg);457 } else {458 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATACSV);459 result.setResultMessage(msg);460 }461 break;462 case TestDataLib.TYPE_SQL:463 answerData = testDataLibDataService.readByVarious(lib.getTestDataLibID(), "N", null, null);464 if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {465 objectDataList = answerData.getDataList();466 boolean missingKey = true;467 for (TestDataLibData tdld : objectDataList) {468 row.put(tdld.getSubData(), tdld.getColumn());469 if (tdld.getSubData().equalsIgnoreCase("")) {470 missingKey = false;471 }472 }473 result.setItem(row);474 if (missingKey) {475 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASQLNOKEY);476 result.setResultMessage(msg);477 } else {478 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);479 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(answerData.getDataList().size())));480 result.setResultMessage(msg);481 }482 } else if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getDataList().isEmpty()) {483 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOSUBDATASQL);484 result.setResultMessage(msg);485 } else {486 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASQL);487 result.setResultMessage(msg);488 }489 break;490 case TestDataLib.TYPE_SERVICE:491 answerData = testDataLibDataService.readByVarious(lib.getTestDataLibID(), null, "N", null);492 if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {493 objectDataList = answerData.getDataList();494 boolean missingKey = true;495 for (TestDataLibData tdld : objectDataList) {496 row.put(tdld.getSubData(), tdld.getParsingAnswer());497 if (tdld.getSubData().equalsIgnoreCase("")) {498 missingKey = false;499 }500 }501 result.setItem(row);502 if (missingKey) {503 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASOAPNOKEY);504 result.setResultMessage(msg);505 } else {506 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);507 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(answerData.getDataList().size())));508 result.setResultMessage(msg);509 }510 } else if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getDataList().isEmpty()) {511 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOSUBDATASOAP);512 result.setResultMessage(msg);513 } else {514 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASOAP);515 result.setResultMessage(msg);516 }517 break;518 case TestDataLib.TYPE_INTERNAL:519 // For static Type, there is no need to fetch the subdata as subdata are loaded at the same time of the data.520 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);521 result.setResultMessage(msg);522 result.setItem(null);523 break;524 }525 return result;526 }527 /**528 * Get the dataObject List depending on the type529 *530 * @param lib531 * @param columnList532 * @return533 */534 private AnswerList<HashMap<String, String>> getDataObjectList(TestDataLib lib, HashMap<String, String> columnList, int rowLimit,535 TestCaseExecution tCExecution, TestCaseExecutionData testCaseExecutionData) {536 AnswerList result = new AnswerList();537 MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);538 CountryEnvironmentDatabase countryEnvironmentDatabase;539 AnswerList responseList;540 String system = tCExecution.getApplicationObj().getSystem();541 String country = tCExecution.getCountry();542 String environment = tCExecution.getEnvironment();543 Pattern pattern;544 Matcher matcher;545 Parameter p;546 List<HashMap<String, String>> list;547 switch (lib.getType()) {548 case TestDataLib.TYPE_CSV:549 /**550 * Before making the call we check if the Service Path is551 * already a proper URL. If it is not, we prefix with the CsvUrl552 * defined from corresponding database. This is used to get the553 * data from the correct environment.554 */555 String servicePathCsv = lib.getCsvUrl();556 LOG.debug("Service Path (Csv) : " + lib.getCsvUrl());557 // Trying making an URL with database context path.558 if (!StringUtil.isURL(servicePathCsv)) {559 // Url is not valid, we try to get the corresponding DatabaseURL CsvURL to prefix.560 if (!(StringUtil.isNullOrEmpty(lib.getDatabaseCsv()))) {561 try {562 countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(this.countryEnvironmentDatabaseService.readByKey(system,563 country, environment, lib.getDatabaseCsv()));564 if (countryEnvironmentDatabase == null) {565 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKOANDDATABASECSVURLNOTEXIST);566 msg.setDescription(msg.getDescription()567 .replace("%SERVICEURL%", lib.getCsvUrl())568 .replace("%SYSTEM%", system)569 .replace("%COUNTRY%", country)570 .replace("%ENV%", environment)571 .replace("%DATABASE%", lib.getDatabaseCsv()));572 result.setResultMessage(msg);573 return result;574 } else {575 String csvURL = countryEnvironmentDatabase.getCsvUrl();576 if (StringUtil.isNullOrEmpty(csvURL)) {577 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKOANDDATABASECSVURLEMPTY);578 msg.setDescription(msg.getDescription()579 .replace("%SERVICEURL%", lib.getCsvUrl())580 .replace("%SYSTEM%", system)581 .replace("%COUNTRY%", country)582 .replace("%ENV%", environment)583 .replace("%DATABASE%", lib.getDatabaseCsv()));584 result.setResultMessage(msg);585 return result;586 }587 // soapURL from database is not empty so we prefix the Service URL with it.588 servicePathCsv = csvURL + lib.getCsvUrl();589 if (!StringUtil.isURL(servicePathCsv)) {590 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKO);591 msg.setDescription(msg.getDescription()592 .replace("%SERVICEURL%", servicePathCsv)593 .replace("%SOAPURL%", csvURL)594 .replace("%SERVICEPATH%", lib.getCsvUrl())595 .replace("%ENTRY%", lib.getName())596 .replace("%ENTRYID%", lib.getTestDataLibID().toString()));597 result.setResultMessage(msg);598 return result;599 }600 }601 } catch (CerberusException ex) {602 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKOANDDATABASECSVURLNOTEXIST);603 msg.setDescription(msg.getDescription()604 .replace("%SERVICEURL%", lib.getCsvUrl())605 .replace("%SYSTEM%", system)606 .replace("%COUNTRY%", country)607 .replace("%ENV%", environment)608 .replace("%DATABASE%", lib.getDatabaseCsv()));609 result.setResultMessage(msg);610 return result;611 }612 }613 }614 // Trying make a valid path with csv parameter path.615 if (!StringUtil.isURL(servicePathCsv)) {616 // Url is still not valid. We try to add the path from csv parameter.617 String csv_path = parameterService.getParameterStringByKey("cerberus_testdatalibcsv_path", "", "");618 csv_path = StringUtil.addSuffixIfNotAlready(csv_path, File.separator);619 servicePathCsv = csv_path + servicePathCsv;620 }621 // CSV Call is made here.622 responseList = fileService.parseCSVFile(servicePathCsv, lib.getSeparator(), columnList);623 list = responseList.getDataList();624 //if the query returns sucess then we can get the data625 if (responseList.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_CSV.getCode()) {626 if (list != null && !list.isEmpty()) {627 result.setDataList(list);628 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_CSV);629 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())).replace("%CSVURL%", servicePathCsv));630 } else {631 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSVDATABASENODATA);632 msg.setDescription(msg.getDescription().replace("%CSVURL%", servicePathCsv));633 }634 } else {635 msg = responseList.getResultMessage();636 }637 result.setResultMessage(msg);638 break;639 case TestDataLib.TYPE_SQL:640 String connectionName;641 String db = lib.getDatabase();642 try {643 if (StringUtil.isNullOrEmpty(db)) {644 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASEEMPTY);645 } else {646 countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(countryEnvironmentDatabaseService.readByKey(system,647 country, environment, db));648 if (countryEnvironmentDatabase == null) {649 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASENOTCONFIGURED);650 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system)651 .replace("%COUNTRY%", country).replace("%ENV%", environment)652 .replace("%DATABASE%", db));653 } else {654 connectionName = countryEnvironmentDatabase.getConnectionPoolName();655 if (!(StringUtil.isNullOrEmpty(connectionName))) {656 Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_propertyexternalsql_timeout", system, 60);657 //performs a query that returns several rows containing n columns658 responseList = sqlService.queryDatabaseNColumns(connectionName, lib.getScript(), rowLimit, sqlTimeout, system, columnList);659 //if the query returns sucess then we can get the data660 if (responseList.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_SQL.getCode()) {661 list = responseList.getDataList();662 if (list != null && !list.isEmpty()) {663 result.setDataList(list);664 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SQL);665 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())));666 } else {667 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASENODATA);668 }669 } else {670 msg = responseList.getResultMessage();671 }672 msg.setDescription(msg.getDescription().replace("%DATABASE%", db));673 msg.setDescription(msg.getDescription().replace("%SQL%", lib.getScript()));674 msg.setDescription(msg.getDescription().replace("%JDBCPOOLNAME%", connectionName));675 } else {676 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASEJDBCRESSOURCEMPTY);677 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", db));678 }679 }680 }681 } catch (CerberusException ex) {682 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASENOTCONFIGURED);683 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", db));684 }685 result.setResultMessage(msg);686 break;687 case TestDataLib.TYPE_SERVICE:688 AppService appService = new AppService();689 HashMap<String, String> resultHash = new HashMap<>();690 List<HashMap<String, String>> listResult = new ArrayList<HashMap<String, String>>();691 // Temporary list of string.692 List<String> listTemp1 = null;693 // String containing the XML694 String responseString = "";695 /**696 * Before making the call we check if the Service Path is697 * already a propper URL. If it is not, we prefix with the698 * SoapUrl defined from corresponding database. This is used to699 * get the data from the correct environment.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);925 } else {926 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_INTERNAL);927 msg.setDescription(msg.getDescription().replace("%SYSTEM%", lib.getSystem())928 .replace("%ENV%", lib.getEnvironment()).replace("%COUNTRY%", lib.getCountry()));929 result.setResultMessage(msg);930 }931 break;932 }933 return result;934 }935 @Override936 public JSONArray convertToJSONObject(List<HashMap<String, String>> object) throws JSONException {937 JSONArray jsonArray = new JSONArray();938 for (HashMap<String, String> row : object) {939 JSONObject jsonObject = new JSONObject();940 jsonObject.put("KEY", row.get(""));941 for (Map.Entry<String, String> entry : row.entrySet()) {942 String column = entry.getKey();...

Full Screen

Full Screen

getCountry

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestDataLib;2import org.cerberus.crud.entity.TestDataLibData;3public String getCountry(TestDataLibData tdlData){4 TestDataLib tdl = tdlData.getTestDataLib();5 return tdl.getCountry();6}7TestDataLibData tdlData = new TestDataLibData();8log(getCountry(tdlData));9TestDataLib tdl = new TestDataLib();10tdl.setCountry("FR");11TestDataLibData tdlData = new TestDataLibData();12tdlData.setTestDataLib(tdl);13log(getCountry(tdlData));14TestDataLib tdl = new TestDataLib();15tdl.setCountry("FR");16TestDataLibData tdlData = new TestDataLibData();17tdlData.setTestDataLib(tdl);18TestDataLib tdl2 = new TestDataLib();19tdl2.setCountry("US");20TestDataLibData tdlData2 = new TestDataLibData();21tdlData2.setTestDataLib(tdl2);22log(getCountry(tdlData));23log(getCountry(tdlData2));24TestDataLib tdl = new TestDataLib();25tdl.setCountry("FR");26TestDataLibData tdlData = new TestDataLibData();27tdlData.setTestDataLib(tdl);28TestDataLib tdl2 = new TestDataLib();29tdl2.setCountry("US");

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