Best Cerberus-source code snippet using org.cerberus.service.datalib.impl.DataLibService.getRandomListOfInteger
Source:DataLibService.java
...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) {371 for (Map<String, String> curentRow : list) {372 if (curentRow.get("").equals(valueToRemove)) {373 if (true) {374 listToremove.add(curentRow);375 removedNB++;376 }377 }378 }379 }380 // We remove all listToremove entries from list.381 list.removeAll(listToremove);382 if (list != null && !list.isEmpty()) { // We pick a random value from the left entries of the list.383 if (list.size() < outputRequestedDimention) { // Still some results available but not enougth compared to what we requested.384 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOTINUSE_NOTENOUGTHRECORDS)385 .resolveDescription("REMNB", Integer.toString(listToremove.size()))386 .resolveDescription("TOTNB", Integer.toString(initNB))387 .resolveDescription("NBREQUEST", Integer.toString(outputRequestedDimention)));388 } else {389 // Get a random list.390 List<Integer> listTempRandom = getRandomListOfInteger(dataObjectList.getDataList().size(), outputRequestedDimention);391 String selectedList = "";392 // Pick the result from list.393 for (int i : listTempRandom) {394 int j = i + 1;395 selectedList += Integer.toString(j) + ",";396 resultObject.add(dataObjectList.getDataList().get(i));397 }398 selectedList = StringUtil.removeLastChar(selectedList, 1);399 result.setDataList(resultObject);400 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURENOTINUSE)401 .resolveDescription("TOTNB", Integer.toString(initNB))402 .resolveDescription("REMNB", Integer.toString(removedNB))403 .resolveDescription("POS", selectedList)404 .resolveDescription("TOTALPOS", Integer.toString(list.size())));...
getRandomListOfInteger
Using AI Code Generation
1import org.cerberus.service.datalib.impl.DataLibService;2import org.cerberus.util.answer.AnswerItem;3DataLibService dataLibService = new DataLibService();4AnswerItem answer = dataLibService.getRandomListOfInteger(5, 1, 10);5List<Integer> randomList = (List<Integer>) answer.getItem();6import org.cerberus.service.datalib.impl.DataLibService;7import org.cerberus.util.answer.AnswerItem;8DataLibService dataLibService = new DataLibService();9AnswerItem answer = dataLibService.getRandomListOfString(5, 1, 10);10List<String> randomList = (List<String>) answer.getItem();11import org.cerberus.service.datalib.impl.DataLibService;12import org.cerberus.util.answer.AnswerItem;13DataLibService dataLibService = new DataLibService();14AnswerItem answer = dataLibService.getRandomListOfDate(5, "2017-01-01", "2017-12-31");15List<Date> randomList = (List<Date>) answer.getItem();16import org.cerberus.service.datalib.impl.DataLibService;17import org.cerberus.util.answer.AnswerItem;18DataLibService dataLibService = new DataLibService();19AnswerItem answer = dataLibService.getRandomListOfDouble(5, 1, 10);20List<Double> randomList = (List<Double>) answer.getItem();21import org.cerberus.service.datalib.impl.DataLibService;22import org.cerberus.util.answer.AnswerItem;
getRandomListOfInteger
Using AI Code Generation
1myRandomList = [];2myRandomList = org.cerberus.service.datalib.impl.DataLibService.getRandomListOfInteger(1, 100, 10);3display(myRandomList);4display(myRandomList.length);5display(myRandomList[2]);6display(myRandomList[3]);7display(myRandomList[4]);8display(myRandomList[5]);9display(myRandomList[6]);10display(myRandomList[7]);11display(myRandomList[8]);12display(myRandomList[9]);13display(myRandomList[10]);14display(myRandomList[11]);15display(myRandomList[12]);16display(myRandomList[13]);17display(myRandomList[14
getRandomListOfInteger
Using AI Code Generation
1def randomList = getRandomListOfInteger(10, 0, 100)2log("The list of 10 random integers is: " + randomList)3putTestCaseExecutionContext("randomList", randomList)4log("The test case execution context is: " + getTestCaseExecutionContext())5def randomList2 = getRandomListOfInteger(10, 0, 100)6log("The list of 10 random integers is: " + randomList2)7putTestCaseExecutionContext("randomList2", randomList2)8log("The test case execution context is: " + getTestCaseExecutionContext())9def randomList3 = getRandomListOfInteger(10, 0, 100)10log("The list of 10 random integers is: " + randomList3)11putTestCaseExecutionContext("randomList3", randomList3)12log("The test case execution context is: " + getTestCaseExecutionContext())
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!!