Best Cerberus-source code snippet using org.cerberus.service.datalib.impl.DataLibService.filterWithNature
Source:DataLibService.java
...188 }189 /**190 * Filter out the result from requested rows depending on the nature191 */192 result = filterWithNature(testCaseCountryProperty.getNature(), resultData, execution, testCaseCountryProperty, nbRowsRequested);193 //Manage error message.194 if (result.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURE.getCode()) {195 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_GLOBAL);196 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription())197 .replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));198 result.setResultMessage(msg);199 } else if (result.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GENERIC_NATURENOMORERECORD.getCode()) {200 //if the script does not return 201 result.setDataList(null);202 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NODATALEFT);203 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription())204 .replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));205 result.setResultMessage(msg);206 } else {207 //other error had occured208 result.setDataList(null);209 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_GENERIC);210 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription())211 .replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));212 result.setResultMessage(msg);213 }214 return result;215 }216 /**217 * This method route to the method regarding the nature218 *219 * @param nature : Nature of the property220 * @param dataObjectList : List of dataObject221 * @param tCExecution : TestCaseExecution222 * @param testCaseCountryProperties : TestCaseCountryProperties223 * @return List of items (dataObject) from the dataObjectList filtered out224 * of records depending on the nature.225 */226 private AnswerList<HashMap<String, String>> filterWithNature(String nature, AnswerList<HashMap<String, String>> dataObjectList, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperties, int outputRequestedDimention) {227 switch (nature) {228 case TestCaseCountryProperties.NATURE_STATIC:229 return filterWithNatureSTATIC(dataObjectList, outputRequestedDimention);230 case TestCaseCountryProperties.NATURE_RANDOM: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) {...
filterWithNature
Using AI Code Generation
1import java.util.ArrayList;2import java.util.List;3import java.util.Map;4import org.cerberus.engine.entity.MessageEvent;5import org.cerberus.engine.entity.MessageGeneral;6import org.cerberus.engine.execution.IExecution;7import org.cerberus.engine.execution.impl.ExecutionFactory;8import org.cerberus.engine.execution.impl.TestDataLibExecution;9import org.cerberus.engine.threadpool.IExecutionThreadPool;10import org.cerberus.engine.threadpool.impl.ExecutionThreadPool;11import org.cerberus.engine.threadpool.impl.TestDataLibThreadPool;12import org.cerberus.exception.CerberusException;13import org.cerberus.service.datalib.impl.DataLibService;14import org.cerberus.service.datalib.impl.TestDataLibService;15import org.cerberus.service.engine.impl.EngineService;16import org.cerberus.service.engine.impl.TestCaseService;17import org.cerberus.service.engine.impl.TestService;18import org.cerberus.service.engine.impl.TestStepService;19import org.cerberus.service.engine.impl.VariableService;20import org.cerberus.service.engine.impl.factory.IExecutionServiceFactory;21import org.cerberus.service.engine.impl.factory.impl.ExecutionServiceFactory;22import org.cerberus.service.engine.impl.factory.impl.TestCaseServiceFactory;23import org.cerberus.service.engine.impl.factory.impl.TestServiceFactory;24import org.cerberus.service.engine.impl.factory.impl.TestStepServiceFactory;25import org.cerberus.service.engine.impl.factory.impl.VariableServiceFactory;26import org.cerberus.util.answer.AnswerList;27import org.cerberus.util.answer.AnswerUtil;28import org.cerberus.util.answer.IAnswer;29import org.cerberus.crud.entity.CountryEnvironmentDatabase;30import org.cerberus.crud.entity.DataLib;31import org.cerberus.crud.entity.TestCaseExecution;32import org.cerberus.crud.entity.TestDataLib;33import org.cerberus.crud.entity.TestDataLibData;34import org.cerberus.crud.entity.TestDataLibDataLib;35import org.cerberus.crud.entity.TestDataLibTestDataLib;36import org.cerberus.crud.entity.TestDataLibVariable;37import org.cerberus.crud.entity
filterWithNature
Using AI Code Generation
1List<DataLib> dataLibList = new ArrayList<DataLib>();2String nature = "TestData";3String system = "QA";4String country = "FR";5dataLibList = dataLibService.filterWithNature(nature, system, country);6System.out.println("List of dataLib objects with nature " + nature + " for system " + system + " and country " + country + " :");7for (DataLib dataLib : dataLibList) {8 System.out.println("dataLib object : " + dataLib);9}10System.out.println("Number of dataLib objects with nature " + nature + " for system " + system + " and country " + country + " : " + dataLibList.size());11System.out.println("List of dataLib objects with nature " + nature + " :");12for (DataLib dataLib : dataLibList) {13 System.out.println("dataLib object : " + dataLib);
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!!