Best Cerberus-source code snippet using org.cerberus.engine.gwt.impl.PropertyService.findMatchingTestCaseCountryProperty
Source:PropertyService.java
...292 crossedProperties.add(property);293 /*294 * Check if property is defined for this testcase295 */296 AnswerItem ansSearch = findMatchingTestCaseCountryProperty(property, country, propertiesOfTestcase);297 testCaseCountryProperty = (TestCaseCountryProperties) ansSearch.getItem();298 if (testCaseCountryProperty == null) {299 return result;300 }301 /* 302 * Check if property value1 and value2 contains internal properties303 */304 List<String> allProperties = new ArrayList();305 // Value1 treatment306 List<String> propertiesValue1 = new ArrayList();307 //check the properties specified in the test308 for (String propNameFromValue1 : this.getPropertiesListFromString(testCaseCountryProperty.getValue1())) {309 for (TestCaseCountryProperties pr : propertiesOfTestcase) {310 if (pr.getProperty().equals(propNameFromValue1)) {311 propertiesValue1.add(propNameFromValue1);312 break;313 }314 }315 }316 allProperties.addAll(propertiesValue1);317 // Value2 treatment :318 List<String> propertiesValue2 = new ArrayList();319 //check the properties specified in the test320 for (String propNameFromValue2 : this.getPropertiesListFromString(testCaseCountryProperty.getValue2())) {321 for (TestCaseCountryProperties pr : propertiesOfTestcase) {322 if (pr.getProperty().equals(propNameFromValue2)) {323 propertiesValue2.add(propNameFromValue2);324 break;325 }326 }327 }328 allProperties.addAll(propertiesValue2);329 for (String internalProperty : allProperties) {330 result.addAll(getListOfPropertiesLinkedToProperty(country, internalProperty, crossedProperties, propertiesOfTestcase));331 }332 result.add(testCaseCountryProperty);333 return result;334 }335 private String decodeStringWithAlreadyCalculatedProperties(String stringToReplace, TestCaseExecution tCExecution) {336 String variableValue = "";337 String variableString1 = "";338 String variableString2 = "";339 TestCaseExecutionData tced;340 for (String key1 : tCExecution.getTestCaseExecutionDataMap().keySet()) {341 tced = tCExecution.getTestCaseExecutionDataMap().get(key1);342 if ((tced.getType() != null) && (tced.getType().equals(TestCaseCountryProperties.TYPE_GETFROMDATALIB))) { // Type could be null in case property do not exist.343 /* Replacement in case of TestDataLib */344 // Key value of the DataLib.345 if (tced.getValue() != null) {346 stringToReplace = stringToReplace.replace("%property." + tced.getProperty() + "%", tced.getValue());347 stringToReplace = stringToReplace.replace("%" + tced.getProperty() + "%", tced.getValue());348 }349 // For each subdata of the getFromDataLib property, we try to replace with PROPERTY(SUBDATA).350 if (!(tced.getDataLibRawData() == null)) {351 int ind = 0;352 for (HashMap<String, String> dataRow : tced.getDataLibRawData()) { // We loop every row result.353 for (String key : dataRow.keySet()) { // We loop every subdata354 if (dataRow.get(key) != null) {355 variableValue = dataRow.get(key);356 variableString1 = tced.getProperty() + "(" + (ind + 1) + ")" + "(" + key + ")";357 stringToReplace = stringToReplace.replace("%property." + variableString1 + "%", variableValue);358 stringToReplace = stringToReplace.replace("%" + variableString1 + "%", variableValue);359 variableString2 = tced.getProperty() + "." + (ind + 1) + "." + key;360 stringToReplace = stringToReplace.replace("%property." + variableString2 + "%", variableValue);361 stringToReplace = stringToReplace.replace("%" + variableString2 + "%", variableValue);362 if (key.equals("")) { // If subdata is empty we can omit the () or .363 variableString1 = tced.getProperty() + "(" + (ind + 1) + ")";364 stringToReplace = stringToReplace.replace("%property." + variableString1 + "%", variableValue);365 stringToReplace = stringToReplace.replace("%" + variableString1 + "%", variableValue);366 variableString2 = tced.getProperty() + "." + (ind + 1);367 stringToReplace = stringToReplace.replace("%property." + variableString2 + "%", variableValue);368 stringToReplace = stringToReplace.replace("%" + variableString2 + "%", variableValue);369 }370 if (ind == 0) { // Dimention of the data is not mandatory for the 1st row.371 variableString1 = tced.getProperty() + "(" + key + ")";372 stringToReplace = stringToReplace.replace("%property." + variableString1 + "%", variableValue);373 stringToReplace = stringToReplace.replace("%" + variableString1 + "%", variableValue);374 variableString2 = tced.getProperty() + "." + key;375 stringToReplace = stringToReplace.replace("%property." + variableString2 + "%", variableValue);376 stringToReplace = stringToReplace.replace("%" + variableString2 + "%", variableValue);377 }378 }379 }380 ind++;381 }382 }383 } else if (tced.getValue() != null) {384 /* Replacement in case of normal PROPERTY */385 stringToReplace = stringToReplace.replace("%property." + tced.getProperty() + "%", tced.getValue());386 stringToReplace = stringToReplace.replace("%" + tced.getProperty() + "%", tced.getValue());387 }388 }389 return stringToReplace;390 }391 /**392 * Gets all properties names contained into the given {@link String}393 *394 * <p>395 * A property is defined by including its name between two '%' character.396 * </p>397 *398 * @param str the {@link String} to get all properties399 * @param variableType400 * @return a list of properties contained into the given {@link String}401 */402 private List<String> getPropertiesListFromString(String str) {403 List<String> properties = new ArrayList<String>();404 LOG.debug("Starting to guess properties from string : " + str);405 if (str == null) {406 LOG.debug("Stoping to guess properties - Empty String ");407 return properties;408 }409 String[] text1 = str.split("%");410 int i = 0;411 for (String rawProperty : text1) {412 if (((i > 0) || (str.startsWith("%"))) && ((i < (text1.length - 1)) || str.endsWith("%"))) { // First and last string from split is not to be considered.413 // Removes "property." string.414 rawProperty = rawProperty.replaceFirst("^property\\.", "");415 // Removes the variable part of the property eg : (subdata)416 String[] ramProp1 = rawProperty.split("\\(");417 // Removes the variable part of the property eg : .subdata418 String[] ramProp2 = ramProp1[0].split("\\.");419 if (!(StringUtil.isNullOrEmpty(ramProp2[0].trim())) // Avoid getting empty Property names.420 && ramProp2[0].trim().length() <= TestCaseCountryProperties.MAX_PROPERTY_LENGTH // Properties cannot be bigger than n caracters.421 && !ramProp2[0].trim().contains("\n")) { // Properties cannot contain \n.422 properties.add(ramProp2[0].trim());423 LOG.debug("Adding string to result " + ramProp2[0].trim());424 } else {425 LOG.debug("Discarding string (empty or too big or contains cariage return).");426 }427 // Avoid getting empty Property names.428 } else {429 LOG.debug("Discarding string (first or last split).");430 }431 i++;432 }433 LOG.debug("Stopping to guess properties - Finished.");434 return properties;435 }436 /**437 * Auxiliary method that verifies if a property is defined in the scope of438 * the test case.439 *440 * @param property - property name441 * @param country - country were the property was implemented442 * @param propertieOfTestcase - list of properties defined for the test case443 * @return an AnswerItem that contains the property in case of success, and444 * null otherwise. also it returns a message indicating error or success.445 */446 private AnswerItem<TestCaseCountryProperties> findMatchingTestCaseCountryProperty(String property, String country, List<TestCaseCountryProperties> propertieOfTestcase) {447 AnswerItem<TestCaseCountryProperties> item = new AnswerItem<TestCaseCountryProperties>();448 boolean propertyDefined = false;449 item.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS));450 TestCaseCountryProperties testCaseCountryProperty = null;451 //searches for properties that match the propertyname (even if they use the getFromDataLib syntax)452 for (TestCaseCountryProperties tccp : propertieOfTestcase) {453 if (tccp.getProperty().equals(property)) {454 //property is defined455 propertyDefined = true;456 //check if is defined for country457 if (tccp.getCountry().equals(country)) {458 //if is a sub data access then we create a auxiliary property459 testCaseCountryProperty = tccp;460 if (LOG.isDebugEnabled()) {...
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!!