How to use getSubDataFromType method of org.cerberus.service.datalib.impl.DataLibService class

Best Cerberus-source code snippet using org.cerberus.service.datalib.impl.DataLibService.getSubDataFromType

Source:DataLibService.java Github

copy

Full Screen

...114 }115 /**116 * Gets the list of columns (subdata) to get from TestDataLibData.117 */118 resultColumns = getSubDataFromType(lib);119 HashMap<String, String> columnList = null;120 //Manage error message.121 if (resultColumns.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA.getCode()) {122 AnswerItem answerDecode = new AnswerItem<>();123 columnList = resultColumns.getItem();124 // Now that we have the list of column with subdata and value, we can try to decode it.125 if (columnList != null) {126 for (Map.Entry<String, String> entry : columnList.entrySet()) { // Loop on all Column in order to decode all values.127 String eKey = entry.getKey(); // SubData128 String eValue = entry.getValue(); // Parsing Answer129 try {130 answerDecode = variableService.decodeStringCompletly(eValue, execution, null, false);131 columnList.put(eKey, (String) answerDecode.getItem());132 if (!(answerDecode.isCodeStringEquals("OK"))) {133 // If anything wrong with the decode --> we stop here with decode message in the action result.134 result = new AnswerList<>();135 result.setDataList(null);136 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_SUBDATAISSUE);137 msg.setDescription(msg.getDescription().replace("%SUBDATAMESSAGE%", answerDecode.getMessageDescription().replace("%FIELD%", "Column value '" + eValue + "'")));138 result.setResultMessage(msg);139 LOG.debug("Datalib interupted due to decode 'column value' Error.");140 return result;141 }142 } catch (CerberusEventException cex) {143 LOG.warn(cex);144 }145 }146 }147 } else if (resultColumns.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATA.getCode()) {148 result = new AnswerList<>();149 result.setDataList(null);150 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_SUBDATAISSUE);151 msg.setDescription(msg.getDescription().replace("%SUBDATAMESSAGE%", resultColumns.getMessageDescription()));152 result.setResultMessage(msg);153 return result;154 }155 /**156 * Get List of DataObject in a format List<Map<String, String>> - 1 item157 * per row with key = column and value = content158 */159 int rowLimit = testCaseCountryProperty.getRowLimit();160 if (testCaseCountryProperty.getNature().equalsIgnoreCase(TestCaseCountryProperties.NATURE_STATIC)) { // If Nature of the property is static, we don't need to get more than requested record.161 rowLimit = nbRowsRequested;162 }163 resultData = getDataObjectList(lib, columnList, rowLimit, execution, testCaseExecutionData);164 //Manage error message.165 if (resultData.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_DATA.getCode()) {166 if (resultData.getDataList().size() < nbRowsRequested) { // We check if the data provided is enought to provide the answer.167 result = new AnswerList<>();168 result.setDataList(null);169 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NOTENOUGHTDATA);170 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%NBREQUEST%", Integer.toString(nbRowsRequested)));171 result.setResultMessage(msg);172 return result;173 }174 } else if (resultData.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GENERIC_NODATA.getCode()) {175 result = new AnswerList<>();176 result.setDataList(null);177 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NODATA);178 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()));179 result.setResultMessage(msg);180 return result;181 } else {182 result = new AnswerList<>();183 result.setDataList(null);184 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_DATAISSUE);185 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()));186 result.setResultMessage(msg);187 return result;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) {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())));405 }406 } else { // No more entries available.407 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOTINUSE_NOMORERECORD)408 .resolveDescription("TOTNB", Integer.toString(initNB)));409 }410 } catch (CerberusException ex) {411 LOG.warn(ex);412 }413 return result;414 }415 /**416 * Get the list of subData417 *418 * @param dataLib419 * @return420 */421 private AnswerItem<HashMap<String, String>> getSubDataFromType(TestDataLib dataLib) {422 AnswerList<TestDataLibData> answerData = new AnswerList<>();423 AnswerItem<HashMap<String, String>> result = new AnswerItem<>();424 MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);425 List<TestDataLibData> objectDataList = new ArrayList<>();426 HashMap<String, String> row = new HashMap<>();427 switch (dataLib.getType()) {428 case TestDataLib.TYPE_CSV:429 answerData = testDataLibDataService.readByVarious(dataLib.getTestDataLibID(), null, null, "N");430 if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {431 objectDataList = answerData.getDataList();432 boolean missingKey = true;433 for (TestDataLibData tdld : objectDataList) {434 row.put(tdld.getSubData(), tdld.getColumnPosition());435 if (tdld.getSubData().isEmpty()) {...

Full Screen

Full Screen

getSubDataFromType

Using AI Code Generation

copy

Full Screen

1String myDataLib = "myDataLib";2String myDataLibSubData = "myDataLibSubData";3String myDataLibSubDataKey = "myDataLibSubDataKey";4String myDataLibSubDataKeyField = "myDataLibSubDataKeyField";5String myDataLibSubDataKeyFieldKey = "myDataLibSubDataKeyFieldKey";6String myDataLibSubDataKeyFieldKeyField = "myDataLibSubDataKeyFieldKeyField";7String myDataLibSubDataValue = libService.getSubDataFromType(myDataLib, myDataLibSubData, myDataLibSubDataKey, myDataLibSubDataKeyField, myDataLibSubDataKeyFieldKey, myDataLibSubDataKeyFieldKeyField);8String myDataLib = "myDataLib";9String myDataLibSubData = "myDataLibSubData";10String myDataLibSubDataKey = "myDataLibSubDataKey";11String myDataLibSubDataKeyField = "myDataLibSubDataKeyField";12String myDataLibSubDataKeyFieldKey = "myDataLibSubDataKeyFieldKey";13String myDataLibSubDataKeyFieldKeyField = "myDataLibSubDataKeyFieldKeyField";14String myDataLibSubDataKeyFieldKeyFieldField = "myDataLibSubDataKeyFieldKeyFieldField";15String myDataLibSubDataValue = libService.getSubDataFromType(myDataLib, myDataLibSubData, myDataLibSubDataKey, myDataLibSubDataKeyField, myDataLibSubDataKeyFieldKey, myDataLibSubDataKeyFieldKeyField, myDataLibSubDataKeyFieldKeyFieldField);16String myDataLib = "myDataLib";17String myDataLibSubData = "myDataLibSubData";18String myDataLibSubDataKey = "myDataLibSubDataKey";19String myDataLibSubDataKeyField = "myDataLibSubDataKeyField";20String myDataLibSubDataKeyFieldKey = "myDataLibSubDataKeyFieldKey";

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.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful