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

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

Source:PropertyService.java Github

copy

Full Screen

...131 /**132 * Look at all the potencial properties still contained in133 * StringToDecode (considering that properties are between %).134 */135 List<String> internalPropertiesFromStringToDecode = this.getPropertiesListFromString(stringToDecode);136 if (LOG.isDebugEnabled()) {137 LOG.debug("Internal potencial properties still found inside property '" + stringToDecode + "' : " + internalPropertiesFromStringToDecode);138 }139 if (internalPropertiesFromStringToDecode.isEmpty()) { // We escape if no property found on the string to decode140 if (LOG.isDebugEnabled()) {141 LOG.debug("Finished to decode (no properties detected in string) : . result : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");142 }143 answer.setItem(stringToDecode);144 answer.setResultMessage(msg);145 return answer;146 }147 /**148 * Get the list of properties needed to calculate the required property149 */150 List<TestCaseCountryProperties> tcProperties = tCExecution.getTestCaseCountryPropertyList();151 List<TestCaseCountryProperties> linkedProperties = new ArrayList();152 for (String internalProperty : internalPropertiesFromStringToDecode) { // Looping on potential properties in string to decode.153 List<TestCaseCountryProperties> newLinkedProperties = new ArrayList();154 newLinkedProperties = this.getListOfPropertiesLinkedToProperty(country, internalProperty, new ArrayList(), tcProperties);155 linkedProperties.addAll(newLinkedProperties);156 if (LOG.isDebugEnabled()) {157 LOG.debug("Property " + internalProperty + " need calculation of these (" + newLinkedProperties.size() + ") property(ies) " + newLinkedProperties);158 }159 }160 /**161 * For all linked properties, calculate it if needed.162 */163 for (TestCaseCountryProperties eachTccp : linkedProperties) {164 TestCaseExecutionData tcExeData;165 /**166 * First create testCaseExecutionData object167 */168 now = new Date().getTime();169 tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), eachTccp.getProperty(), 1, eachTccp.getDescription(), null, eachTccp.getType(),170 eachTccp.getValue1(), eachTccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING),171 eachTccp.getRetryNb(), eachTccp.getRetryPeriod(), eachTccp.getDatabase(), eachTccp.getValue1(), eachTccp.getValue2(), eachTccp.getLength(),172 eachTccp.getLength(), eachTccp.getRowLimit(), eachTccp.getNature(), tCExecution.getApplicationObj().getSystem(), tCExecution.getEnvironment(), tCExecution.getCountry(), "", null, "N");173 tcExeData.setTestCaseCountryProperties(eachTccp);174 tcExeData.settCExecution(tCExecution);175 if (LOG.isDebugEnabled()) {176 LOG.debug("Trying to calculate Property : '" + tcExeData.getProperty() + "' " + tcExeData);177 }178 /* First check if property has already been calculated 179 * if action is calculateProperty, then set isKnownData to false. 180 */181 tcExeData = getExecutionDataFromList(tCExecution.getTestCaseExecutionDataMap(), eachTccp, forceCalculation, tcExeData);182 /**183 * If testcasecountryproperty not defined, set ExecutionData with184 * the same resultMessage185 */186 if (eachTccp.getResult() != null) {187 tcExeData.setPropertyResultMessage(eachTccp.getResult());188 }189 /*190 * If not already calculated, or calculateProperty, then calculate it and insert or update it.191 */192 if (MessageEventEnum.PROPERTY_PENDING.equals(tcExeData.getPropertyResultMessage().getSource())) {193 calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, eachTccp, forceCalculation);194 msg = tcExeData.getPropertyResultMessage();195 //saves the result 196 try {197 testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcExeData));198 /**199 * Add TestCaseExecutionData in TestCaseExecutionData List200 * of the TestCaseExecution201 */202 LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + String.valueOf(tcExeData.getIndex()) + "' Value : '" + tcExeData.getValue() + "'");203 tCExecution.getTestCaseExecutionDataMap().put(tcExeData.getProperty(), tcExeData);204 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.205 for (int i = 1; i < (tcExeData.getDataLibRawData().size()); i++) {206 now = new Date().getTime();207 TestCaseExecutionData tcedS = factoryTestCaseExecutionData.create(tcExeData.getId(), tcExeData.getProperty(), (i + 1),208 tcExeData.getDescription(), tcExeData.getDataLibRawData().get(i).get(""), tcExeData.getType(), "", "",209 tcExeData.getRC(), "", now, now, now, now, null, 0, 0, "", "", "", "", "", 0, "", tcExeData.getSystem(), tcExeData.getEnvironment(), tcExeData.getCountry(), tcExeData.getDataLib(), null, "N");210 testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcedS));211 }212 }213 } catch (CerberusException cex) {214 LOG.error(cex.getMessage(), cex);215 }216 }217 /**218 * After calculation, replace properties by value calculated219 */220 stringToDecode = decodeStringWithAlreadyCalculatedProperties(stringToDecode, tCExecution);221 if (LOG.isDebugEnabled()) {222 LOG.debug("Property " + eachTccp.getProperty() + " calculated with Value = " + tcExeData.getValue() + ", Value1 = " + tcExeData.getValue1() + ", Value2 = " + tcExeData.getValue2());223 }224 /**225 * Log TestCaseExecutionData226 */227 if (tCExecution.getVerbose() > 0) {228 LOG.info(tcExeData.toJson(false, true));229 }230 }231 if (LOG.isDebugEnabled()) {232 LOG.debug("Finished to decode String (property) : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");233 }234 answer.setResultMessage(msg);235 answer.setItem(stringToDecode);236 return answer;237 }238 /**239 * Auxiliary method that returns the execution data for a property.240 *241 * @param dataList list of execution data242 * @param eachTccp property to be calculated243 * @param forceCalculation indicates whether a property must be244 * re-calculated if it was already computed in previous steps245 * @param tecd execution data for the property246 * @return the updated execution data for the property247 */248 private TestCaseExecutionData getExecutionDataFromList(TreeMap<String, TestCaseExecutionData> hashTemp1, TestCaseCountryProperties eachTccp, boolean forceCalculation, TestCaseExecutionData tecd) {249 LOG.debug("Searching " + eachTccp.getProperty() + " Into list of " + hashTemp1.size());250 try {251 if (hashTemp1.containsKey(eachTccp.getProperty())) {252 if (forceCalculation) {253 LOG.debug("Property has already been calculated but forcing new calculation by removing it : " + hashTemp1.get(eachTccp.getProperty()));254 hashTemp1.remove(eachTccp.getProperty());255 return tecd;256 } else {257 LOG.debug("Property has already been calculated : " + hashTemp1.get(eachTccp.getProperty()));258 return hashTemp1.get(eachTccp.getProperty());259 }260 } else {261 LOG.debug("Property was never calculated.");262 return tecd;263 }264 } catch (Exception ex) {265 LOG.error("Exception catched inside getExecutionDataFromList : " + ex);266 }267 return tecd;268 }269 /**270 * Method that takes the potencial @param property, finds it (or not if it271 * is not a existing property) inside the existing property list @param272 * propertiesOfTestcase and gets the list of all other properties required273 * (contained inside value1 or value2).274 *275 * @param country country used to filter property from propertiesOfTestcase276 * @param property property to be calculated277 * @param crossedProperties List of previously found properties.278 * @param propertiesOfTestcase List of properties defined from the testcase.279 * @return list of TestCaseCountryProperties that are included inside the280 * definition of the @param property281 */282 private List<TestCaseCountryProperties> getListOfPropertiesLinkedToProperty(String country, String property, List<String> crossedProperties,283 List<TestCaseCountryProperties> propertiesOfTestcase) {284 List<TestCaseCountryProperties> result = new ArrayList();285 TestCaseCountryProperties testCaseCountryProperty = null;286 /*287 * Check if property is not already known (recursive case).288 */289 if (crossedProperties.contains(property)) {290 return result;291 }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("\\(");...

Full Screen

Full Screen

getPropertiesListFromString

Using AI Code Generation

copy

Full Screen

1String propertiesString = "prop1=abc;prop2=123;prop3=xyz";2PropertyService propertyService = new PropertyService();3List<Property> properties = propertyService.getPropertiesListFromString(propertiesString);4for (Property property : properties) {5 System.out.println(property.getProperty() + "=" + property.getValue());6}7String propertiesJson = "[{\"property\":\"prop1\",\"value\":\"abc\"},{\"property\":\"prop2\",\"value\":\"123\"},{\"property\":\"prop3\",\"value\":\"xyz\"}]";8PropertyService propertyService = new PropertyService();9List<Property> properties = propertyService.getPropertiesListFromJson(propertiesJson);10for (Property property : properties) {11 System.out.println(property.getProperty() + "=" + property.getValue());12}13String propertiesXml = "<properties><property><name>prop1</name><value>abc</value></property><property><name>prop2</name><value>123</value></property><property><name>prop3</name><value>xyz</value></property></properties>";14PropertyService propertyService = new PropertyService();15List<Property> properties = propertyService.getPropertiesListFromXml(propertiesXml);16for (Property property : properties) {17 System.out.println(property.getProperty() + "=" + property.getValue());18}19prop3=xyz";20PropertyService propertyService = new PropertyService();21List<Property> properties = propertyService.getPropertiesListFromProperties(propertiesProperties);22for (Property property : properties) {23 System.out.println(property.getProperty() + "=" + property.getValue());24}

Full Screen

Full Screen

getPropertiesListFromString

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.gwt.impl.PropertyService;2import org.cerberus.engine.gwt.impl.Property;3String propString = "property1=value1;property2=value2;property3=value3";4List<Property> propertiesList = PropertyService.getPropertiesListFromString(propString);5for (Property property : propertiesList) {6 System.out.println(property.getName() + " = " + property.getValue());7}

Full Screen

Full Screen

getPropertiesListFromString

Using AI Code Generation

copy

Full Screen

1var earFile = new org.cerberus.engine.entity.File();2earFile.setPath("test.ear");3var warFile = new org.cerberus.engine.entity.File();4warFile.setPath("test.war");5var jarFile = new org.cerberus.engine.entity.File();6jarFile.setPath("test.jar");7var zipFile = new org.cerberus.engine.entity.File();8zipFile.setPath("test.zip");9var file = new org.cerberus.engine.entity.File();10file.setPath("test.properties");11var propertyService = new org.cerberus.engine.gwt.impl.PropertyService();12var stringBuilder = new java.lang.StringBuilder();13stringBuilder.append("test1=value1").append("14");15stringBuilder.append("test2=value2").append("16");17stringBuilder.append("test3=value3").append("18");19stringBuilder.append("test4=value4").append("20");21stringBuilder.append("test5=value5").append("22");23stringBuilder.append("test6=value6").append("24");25file.setContent(stringBuilder.toString());26zipFile.addFile(file);27jarFile.addFile(zipFile);28warFile.addFile(jarFile);29earFile.addFile(warFile);30var propertiesList = propertyService.getPropertiesListFromString(earFile);31for (var i = 0; i < propertiesList.size(); i++) {32 var property = propertiesList.get(i);33 out.println(property.getKey() + " = " + property.getValue());34}

Full Screen

Full Screen

getPropertiesListFromString

Using AI Code Generation

copy

Full Screen

1List<PropertyDTO> list = getPropertyService().getPropertiesListFromString("key1=value1;key2=value2;key3=value3");2for (PropertyDTO propertyDTO : list) {3 out.println(propertyDTO.getProperty() + " " + propertyDTO.getValue());4}5List<PropertyDTO> list = getPropertyService().getPropertiesListFromString("key1=value1|key2=value2|key3=value3", "|");6for (PropertyDTO propertyDTO : list) {7 out.println(propertyDTO.getProperty() + " " + propertyDTO.getValue());8}9List<PropertyDTO> list = getPropertyService().getPropertiesListFromString("key1=value1|key2=value2|key3=value3", "|", "=");10for (PropertyDTO propertyDTO : list) {11 out.println(propertyDTO.getProperty() + " " + propertyDTO.getValue());12}

Full Screen

Full Screen

getPropertiesListFromString

Using AI Code Generation

copy

Full Screen

1importClass(org.cerberus.engine.entity.Property);2importClass(org.cerberus.engine.entity.PropertyList);3importClass(org.cerberus.engine.gwt.impl.PropertyService);4importClass(java.util.ArrayList);5var propertyService = new PropertyService();6var propertyList = new PropertyList();7var properties = new ArrayList();8var propertyString = "prop1,prop2,prop3";9properties = propertyService.getPropertiesListFromString(propertyString);10propertyList.setProperties(properties);11print(propertyList.toString());12var propertyFile = "C:\\Users\\cerberus\\Documents\\cerberus\\cerberus-engine\\src\\test\\resources\\properties\\properties.properties";13properties = propertyService.getPropertiesListFromString(propertyFile);14propertyList.setProperties(properties);15print(propertyList.toString());

Full Screen

Full Screen

getPropertiesListFromString

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.Property2import org.cerberus.engine.gwt.impl.PropertyService3def prop = new PropertyService()4def propList = prop.getPropertiesListFromString(testCase.cerberus_property)5assertNotNull(propList)6assertFalse(propList.isEmpty())7assertEquals(3, propList.size())8assertEquals("name1", propList.get(0).getName())9assertEquals("value1", propList.get(0).getValue())10assertEquals("name2", propList.get(1).getName())11assertEquals("value2", propList.get(1).getValue())12assertEquals("name3", propList.get(2).getName())13assertEquals("value3", propList.get(2).getValue())14assertEquals("value1", prop.getPropertyValue(propList, "name1"))15assertEquals("value2", prop.getPropertyValue(propList, "name2"))16assertEquals("value3", prop.getPropertyValue(propList, "name3"))17assertNull(prop.getPropertyValue(propList, "name4"))18assertEquals("value1", prop.getPropertyValue(testCase.cerberus_property, "name1"))

Full Screen

Full Screen

getPropertiesListFromString

Using AI Code Generation

copy

Full Screen

1property2=value2";2var propertiesList = org.cerberus.engine.gwt.impl.PropertyService.getPropertiesListFromString(propertiesString);3if(propertiesList.size() > 0){4 for(var i = 0; i < propertiesList.size(); i++){5 var property = propertiesList.get(i);6 var propertyName = property.name;7 var propertyValue = property.value;8 console.log("property name: " + propertyName + ", property value: " + propertyValue);9 }10}

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