How to use decodeStringWithAlreadyCalculatedProperties method of org.cerberus.engine.gwt.impl.PropertyService class

Best Cerberus-source code snippet using org.cerberus.engine.gwt.impl.PropertyService.decodeStringWithAlreadyCalculatedProperties

Source:PropertyService.java Github

copy

Full Screen

...147 }148 /**149 * We start to decode properties from available executiondata List.150 */151 stringToDecode = decodeStringWithAlreadyCalculatedProperties(stringToDecode, tCExecution);152 /**153 * Look at all the potencial properties still contained in154 * StringToDecode (considering that properties are between %).155 */156 List<String> internalPropertiesFromStringToDecode = this.getPropertiesListFromString(stringToDecode);157 if (LOG.isDebugEnabled()) {158 LOG.debug("Internal potencial properties still found inside property '" + stringToDecode + "' : " + internalPropertiesFromStringToDecode);159 }160 if (internalPropertiesFromStringToDecode.isEmpty()) { // We escape if no property found on the string to decode161 if (LOG.isDebugEnabled()) {162 LOG.debug("Finished to decode (no properties detected in string) : . result : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");163 }164 answer.setItem(stringToDecode);165 answer.setResultMessage(msg);166 return answer;167 }168 /**169 * Get the list of properties needed to calculate the required property170 */171 List<TestCaseCountryProperties> tcProperties = tCExecution.getTestCaseCountryPropertyList();172 List<TestCaseCountryProperties> linkedProperties = new ArrayList<>();173 for (String internalProperty : internalPropertiesFromStringToDecode) { // Looping on potential properties in string to decode.174 List<TestCaseCountryProperties> newLinkedProperties = new ArrayList<>();175 newLinkedProperties = this.getListOfPropertiesLinkedToProperty(country, internalProperty, new ArrayList<>(), tcProperties);176 linkedProperties.addAll(newLinkedProperties);177 if (LOG.isDebugEnabled()) {178 LOG.debug("Property " + internalProperty + " need calculation of these (" + newLinkedProperties.size() + ") property(ies) " + newLinkedProperties);179 }180 }181 /**182 * For all linked properties, calculate it if needed.183 */184 for (TestCaseCountryProperties eachTccp : linkedProperties) {185 TestCaseExecutionData tcExeData;186 /**187 * First create testCaseExecutionData object188 */189 now = new Date().getTime();190 tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), eachTccp.getProperty(), 1, eachTccp.getDescription(), null, eachTccp.getType(), eachTccp.getRank(),191 eachTccp.getValue1(), eachTccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING),192 eachTccp.getRetryNb(), eachTccp.getRetryPeriod(), eachTccp.getDatabase(), eachTccp.getValue1(), eachTccp.getValue2(), eachTccp.getLength(),193 eachTccp.getLength(), eachTccp.getRowLimit(), eachTccp.getNature(), tCExecution.getApplicationObj().getSystem(), tCExecution.getEnvironment(), tCExecution.getCountry(), "", null, "N");194 tcExeData.setTestCaseCountryProperties(eachTccp);195 tcExeData.settCExecution(tCExecution);196 if (LOG.isDebugEnabled()) {197 LOG.debug("Trying to calculate Property : '" + tcExeData.getProperty() + "' " + tcExeData);198 }199 /* First check if property has already been calculated200 * if action is calculateProperty, then set isKnownData to false.201 */202 tcExeData = getExecutionDataFromList(tCExecution.getTestCaseExecutionDataMap(), eachTccp, forceCalculation, tcExeData);203 /**204 * If testcasecountryproperty not defined, set ExecutionData with205 * the same resultMessage206 */207 if (eachTccp.getResult() != null) {208 tcExeData.setPropertyResultMessage(eachTccp.getResult());209 }210 /*211 * If not already calculated, or calculateProperty, then calculate it and insert or update it.212 */213 if (MessageEventEnum.PROPERTY_PENDING.equals(tcExeData.getPropertyResultMessage().getSource())) {214 calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, eachTccp, forceCalculation);215 msg = tcExeData.getPropertyResultMessage();216 //saves the result217 try {218 testCaseExecutionDataService.save(tcExeData);219 /**220 * Add TestCaseExecutionData in TestCaseExecutionData List221 * of the TestCaseExecution222 */223 LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + String.valueOf(tcExeData.getIndex()) + "' Value : '" + tcExeData.getValue() + "'");224 tCExecution.getTestCaseExecutionDataMap().put(tcExeData.getProperty(), tcExeData);225 if (tcExeData.getDataLibRawData() != null) { // If the property is a TestDataLib, we same all rows retreived in order to support nature such as NOTINUSe or RANDOMNEW.226 for (int i = 1; i < (tcExeData.getDataLibRawData().size()); i++) {227 now = new Date().getTime();228 TestCaseExecutionData tcedS = factoryTestCaseExecutionData.create(tcExeData.getId(), tcExeData.getProperty(), (i + 1),229 tcExeData.getDescription(), tcExeData.getDataLibRawData().get(i).get(""), tcExeData.getType(), tcExeData.getRank(), "", "",230 tcExeData.getRC(), "", now, now, now, now, null, 0, 0, "", "", "", "", "", 0, "", tcExeData.getSystem(), tcExeData.getEnvironment(), tcExeData.getCountry(), tcExeData.getDataLib(), null, "N");231 testCaseExecutionDataService.save(tcedS);232 }233 }234 } catch (CerberusException cex) {235 LOG.error(cex.getMessage(), cex);236 }237 }238 /**239 * After calculation, replace properties by value calculated240 */241 stringToDecode = decodeStringWithAlreadyCalculatedProperties(stringToDecode, tCExecution);242 if (LOG.isDebugEnabled()) {243 LOG.debug("Property " + eachTccp.getProperty() + " calculated with Value = " + tcExeData.getValue() + ", Value1 = " + tcExeData.getValue1() + ", Value2 = " + tcExeData.getValue2());244 }245 /**246 * Log TestCaseExecutionData247 */248 if (tCExecution.getVerbose() > 0) {249 LOG.info(tcExeData.toJson(false, true));250 }251 }252 if (LOG.isDebugEnabled()) {253 LOG.debug("Finished to decode String (property) : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");254 }255 answer.setResultMessage(msg);256 answer.setItem(stringToDecode);257 return answer;258 }259 /**260 * Auxiliary method that returns the execution data for a property.261 *262 * @param hashTemp1 list of execution data263 * @param eachTccp property to be calculated264 * @param forceCalculation indicates whether a property must be265 * re-calculated if it was already computed in previous steps266 * @param tecd execution data for the property267 * @return the updated execution data for the property268 */269 private TestCaseExecutionData getExecutionDataFromList(TreeMap<String, TestCaseExecutionData> hashTemp1, TestCaseCountryProperties eachTccp, boolean forceCalculation, TestCaseExecutionData tecd) {270 LOG.debug("Searching " + eachTccp.getProperty() + " Into list of " + hashTemp1.size());271 try {272 if (hashTemp1.containsKey(eachTccp.getProperty())) {273 if (forceCalculation) {274 LOG.debug("Property has already been calculated but forcing new calculation by removing it : " + hashTemp1.get(eachTccp.getProperty()));275 hashTemp1.remove(eachTccp.getProperty());276 return tecd;277 } else {278 LOG.debug("Property has already been calculated : " + hashTemp1.get(eachTccp.getProperty()));279 return hashTemp1.get(eachTccp.getProperty());280 }281 } else {282 LOG.debug("Property was never calculated.");283 return tecd;284 }285 } catch (Exception ex) {286 LOG.error("Exception catched inside getExecutionDataFromList : " + ex, ex);287 }288 return tecd;289 }290 /**291 * Method that takes the potencial @param property, finds it (or not if it292 * is not a existing property) inside the existing property list @param293 * propertiesOfTestcase and gets the list of all other properties required294 * (contained inside value1 or value2).295 *296 * @param country country used to filter property from propertiesOfTestcase297 * @param property property to be calculated298 * @param crossedProperties List of previously found properties.299 * @param propertiesOfTestcase List of properties defined from the testcase.300 * @return list of TestCaseCountryProperties that are included inside the301 * definition of the @param property302 */303 private List<TestCaseCountryProperties> getListOfPropertiesLinkedToProperty(String country, String property, List<String> crossedProperties,304 List<TestCaseCountryProperties> propertiesOfTestcase) {305 List<TestCaseCountryProperties> result = new ArrayList<>();306 TestCaseCountryProperties testCaseCountryProperty = null;307 /*308 * Check if property is not already known (recursive case).309 */310 if (crossedProperties.contains(property)) {311 return result;312 }313 crossedProperties.add(property);314 /*315 * Check if property is defined for this testcase316 */317 AnswerItem ansSearch = findMatchingTestCaseCountryProperty(property, country, propertiesOfTestcase);318 testCaseCountryProperty = (TestCaseCountryProperties) ansSearch.getItem();319 if (testCaseCountryProperty == null) {320 return result;321 }322 /*323 * Check if property value1 and value2 contains internal properties324 */325 List<String> allProperties = new ArrayList<>();326 // Value1 treatment327 List<String> propertiesValue1 = new ArrayList<>();328 //check the properties specified in the test329 for (String propNameFromValue1 : this.getPropertiesListFromString(testCaseCountryProperty.getValue1())) {330 for (TestCaseCountryProperties pr : propertiesOfTestcase) {331 if (pr.getProperty().equals(propNameFromValue1)) {332 propertiesValue1.add(propNameFromValue1);333 break;334 }335 }336 }337 allProperties.addAll(propertiesValue1);338 // Value2 treatment :339 List<String> propertiesValue2 = new ArrayList<>();340 //check the properties specified in the test341 for (String propNameFromValue2 : this.getPropertiesListFromString(testCaseCountryProperty.getValue2())) {342 for (TestCaseCountryProperties pr : propertiesOfTestcase) {343 if (pr.getProperty().equals(propNameFromValue2)) {344 propertiesValue2.add(propNameFromValue2);345 break;346 }347 }348 }349 allProperties.addAll(propertiesValue2);350 for (String internalProperty : allProperties) {351 result.addAll(getListOfPropertiesLinkedToProperty(country, internalProperty, crossedProperties, propertiesOfTestcase));352 }353 result.add(testCaseCountryProperty);354 return result;355 }356 private String decodeStringWithAlreadyCalculatedProperties(String stringToReplace, TestCaseExecution tCExecution) {357 String variableValue = "";358 String variableString1 = "";359 String variableString2 = "";360 TestCaseExecutionData tced;361 for (String key1 : tCExecution.getTestCaseExecutionDataMap().keySet()) {362 tced = tCExecution.getTestCaseExecutionDataMap().get(key1);363 if ((tced.getType() != null) && (tced.getType().equals(TestCaseCountryProperties.TYPE_GETFROMDATALIB))) { // Type could be null in case property do not exist.364 /* Replacement in case of TestDataLib */365 // Key value of the DataLib.366 if (tced.getValue() != null) {367 stringToReplace = stringToReplace.replace("%property." + tced.getProperty() + "%", tced.getValue());368 stringToReplace = stringToReplace.replace("%" + tced.getProperty() + "%", tced.getValue());369 }370 // For each subdata of the getFromDataLib property, we try to replace with PROPERTY(SUBDATA)....

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful