Best Cerberus-source code snippet using org.cerberus.service.datalib.impl.DataLibService.filterWithNatureNOTINUSE
Source:DataLibService.java
...231 return filterWithNatureRANDOM(dataObjectList, outputRequestedDimention);232 case TestCaseCountryProperties.NATURE_RANDOMNEW:233 return filterWithNatureRANDOMNEW(dataObjectList, tCExecution, testCaseCountryProperties, outputRequestedDimention);234 case TestCaseCountryProperties.NATURE_NOTINUSE:235 return filterWithNatureNOTINUSE(dataObjectList, tCExecution, testCaseCountryProperties, outputRequestedDimention);236 }237 //TODO throw exception when Nature not known238 return null;239 }240 private List<Integer> getRandomListOfInteger(int inputRange, int nbOfResult) {241 List<Integer> listTempRandom;242 listTempRandom = new ArrayList<>();243 for (int i = 0; i < inputRange; i++) {244 listTempRandom.add(i);245 }246 List<Integer> listRandom;247 listRandom = new ArrayList<>();248 for (int i = 0; i < nbOfResult; i++) {249 Random r = new Random();250 int position = r.nextInt(listTempRandom.size());251 listRandom.add(listTempRandom.remove(position));252 }253 return listRandom;254 }255 @Override256 public AnswerList<HashMap<String, String>> filterWithNatureSTATIC(AnswerList<HashMap<String, String>> dataObjectList, int outputRequestedDimention) {257 AnswerList<HashMap<String, String>> result = new AnswerList<>();258 List<HashMap<String, String>> resultObject;259 resultObject = new ArrayList<>();260 for (int i = 0; i < outputRequestedDimention; i++) {261 resultObject.add(dataObjectList.getDataList().get(i));262 }263 result.setDataList(resultObject);264 String rowMessage = "";265 if (outputRequestedDimention < 2) {266 rowMessage = "row";267 } else {268 rowMessage = Integer.toString(outputRequestedDimention) + " rows";269 }270 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURESTATIC).resolveDescription("ROW", rowMessage));271 return result;272 }273 @Override274 public AnswerList<HashMap<String, String>> filterWithNatureRANDOM(AnswerList<HashMap<String, String>> dataObjectList, int outputRequestedDimention) {275 AnswerList<HashMap<String, String>> result = new AnswerList<>();276 String selectedList = "";277 List<HashMap<String, String>> resultObject;278 resultObject = new ArrayList<>();279 List<Integer> listTempRandom = getRandomListOfInteger(dataObjectList.getDataList().size(), outputRequestedDimention);280 for (int i : listTempRandom) {281 int j = i + 1;282 selectedList += Integer.toString(j) + ",";283 resultObject.add(dataObjectList.getDataList().get(i));284 }285 selectedList = StringUtil.removeLastChar(selectedList, 1);286 result.setDataList(resultObject);287 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURERANDOM)288 .resolveDescription("POS", selectedList).resolveDescription("TOTALPOS", Integer.toString(dataObjectList.getDataList().size())));289 return result;290 }291 @Override292 public AnswerList<HashMap<String, String>> filterWithNatureRANDOMNEW(AnswerList<HashMap<String, String>> dataObjectList, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseProperties, int outputRequestedDimention) {293 AnswerList<HashMap<String, String>> result = new AnswerList<>();294 List<HashMap<String, String>> list; // Temporary list in order to treat the input list295 List<HashMap<String, String>> resultObject;296 resultObject = new ArrayList<>();297 int initNB = dataObjectList.getDataList().size();298 // We get the list of values that were already used.299 List<String> pastValues = new LinkedList<>();300 try {301 pastValues = this.testCaseExecutionDataService.getPastValuesOfProperty(tCExecution.getId(),302 testCaseProperties.getProperty(), tCExecution.getTest(), tCExecution.getTestCase(),303 tCExecution.getCountryEnvParam().getBuild(), tCExecution.getEnvironmentData(), tCExecution.getCountry());304 } catch (CerberusException e) {305 LOG.error(e.getMessage(), e);306 result.setResultMessage(new MessageEvent(MessageEventEnum.GENERIC_ERROR)307 .resolveDescription("REASON", e.getMessage()));308 }309 int removedNB = 0;310 // We save all rows that needs to be removed to listToremove.311 List<Map<String, String>> listToremove = new ArrayList<>();312 list = dataObjectList.getDataList();313 for (String valueToRemove : pastValues) {314 for (Map<String, String> curentRow : list) {315 if (curentRow.get("").equals(valueToRemove)) {316 if (true) {317 listToremove.add(curentRow);318 removedNB++;319 }320 }321 }322 }323 // We remove all listToremove entries from list.324 list.removeAll(listToremove);325 if (list != null && !list.isEmpty()) { // We pick a random value from the left entries of the list.326 if (list.size() < outputRequestedDimention) { // Still some results available but not enougth compared to what we requested.327 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_RANDOMNEW_NOTENOUGTHRECORDS)328 .resolveDescription("REMNB", Integer.toString(listToremove.size()))329 .resolveDescription("TOTNB", Integer.toString(initNB))330 .resolveDescription("NBREQUEST", Integer.toString(outputRequestedDimention)));331 } else {332 // Get a random list.333 List<Integer> listTempRandom = getRandomListOfInteger(dataObjectList.getDataList().size(), outputRequestedDimention);334 String selectedList = "";335 // Pick the result from list.336 for (int i : listTempRandom) {337 int j = i + 1;338 selectedList += Integer.toString(j) + ",";339 resultObject.add(dataObjectList.getDataList().get(i));340 }341 selectedList = StringUtil.removeLastChar(selectedList, 1);342 result.setDataList(resultObject);343 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURERANDOMNEW)344 .resolveDescription("TOTNB", Integer.toString(initNB))345 .resolveDescription("REMNB", Integer.toString(removedNB))346 .resolveDescription("POS", selectedList)347 .resolveDescription("TOTALPOS", Integer.toString(list.size())));348 }349 } else { // No more entries available.350 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_RANDOMNEW_NOMORERECORD)351 .resolveDescription("TOTNB", Integer.toString(initNB)));352 }353 return result;354 }355 @Override356 public AnswerList<HashMap<String, String>> filterWithNatureNOTINUSE(AnswerList<HashMap<String, String>> dataObjectList, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, int outputRequestedDimention) {357 AnswerList<HashMap<String, String>> result = new AnswerList<>();358 List<HashMap<String, String>> list = dataObjectList.getDataList(); // Temporary list in order to treat the input list359 List<HashMap<String, String>> resultObject;360 resultObject = new ArrayList<>();361 int initNB = dataObjectList.getDataList().size();362 // We get the list of values that are beeing used.363 Integer peTimeout;364 try {365 peTimeout = Integer.valueOf(parameterService.findParameterByKey("cerberus_notinuse_timeout", tCExecution.getApplicationObj().getSystem()).getValue());366 List<String> pastValues = this.testCaseExecutionDataService.getInUseValuesOfProperty(tCExecution.getId(), testCaseCountryProperty.getProperty(), tCExecution.getEnvironmentData(), tCExecution.getCountry(), peTimeout);367 int removedNB = 0;368 // We save all rows that needs to be removed to listToremove.369 List<Map<String, String>> listToremove = new ArrayList<>();370 for (String valueToRemove : pastValues) {...
filterWithNatureNOTINUSE
Using AI Code Generation
1dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL", "Cerberus");2dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-SELECT", "Cerberus");3dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-INSERT", "Cerberus");4dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-UPDATE", "Cerberus");5dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-DELETE", "Cerberus");6dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-SELECT-ORACLE", "Cerberus");7dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-SELECT-MSSQL", "Cerberus");8dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-SELECT-POSTGRESQL", "Cerberus");9dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-SELECT-MYSQL", "Cerberus");10dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-SELECT-MARIADB", "Cerberus");11dataLibs = dataLibService.filterWithNatureNOTINUSE("SQL-SELECT-DB2", "Cerberus");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!