Best Testsigma code snippet using com.testsigma.model.DefaultDataGenerator.getMetaData
Source:StepProcessor.java
1package com.testsigma.step.processors;2import com.testsigma.automator.entity.DefaultDataGeneratorsEntity;3import com.testsigma.config.StorageServiceFactory;4import com.testsigma.constants.MessageConstants;5import com.testsigma.constants.NaturalTextActionConstants;6import com.testsigma.dto.*;7import com.testsigma.exception.ExceptionErrorCodes;8import com.testsigma.exception.ResourceNotFoundException;9import com.testsigma.exception.TestsigmaException;10import com.testsigma.mapper.ElementMapper;11import com.testsigma.mapper.TestStepMapper;12import com.testsigma.model.TestDataSet;13import com.testsigma.model.*;14import com.testsigma.service.*;15import lombok.extern.log4j.Log4j2;16import org.apache.commons.lang3.StringUtils;17import org.springframework.web.context.WebApplicationContext;18import java.util.*;19import java.util.regex.Matcher;20import java.util.regex.Pattern;21@Log4j222public class StepProcessor {23 protected static Integer LOOP_END = -1;24 protected Long testPlanId;25 protected List<TestCaseStepEntityDTO> testCaseStepEntityDTOS;26 protected WorkspaceType workspaceType;27 protected Map<String, Element> elementMap;28 protected TestDataSet testDataSet;29 protected TestStepDTO testStepDTO;30 protected Map<String, String> environmentParameters;31 protected TestCaseEntityDTO testCaseEntityDTO;32 protected String environmentParamSetName;33 protected String dataProfile;34 protected TestDataProfileService testDataProfileService;35 protected ElementMapper elementMapper;36 protected NaturalTextActionsService naturalTextActionsService;37 protected StorageService storageService;38 protected RestStepService restStepService;39 protected TestStepMapper testStepMapper;40 protected ProxyAddonService addonService;41 protected DefaultDataGeneratorService defaultDataGeneratorService;42 WebApplicationContext webApplicationContext;43 public StepProcessor(WebApplicationContext webApplicationContext, List<TestCaseStepEntityDTO> testCaseStepEntityDTOS,44 WorkspaceType workspaceType, Map<String, Element> elementMap,45 TestStepDTO testStepDTO, Long testPlanId, TestDataSet testDataSet,46 Map<String, String> environmentParameters, TestCaseEntityDTO testCaseEntityDTO, String environmentParamSetName,47 String dataProfile) {48 this.webApplicationContext = webApplicationContext;49 this.testCaseStepEntityDTOS = testCaseStepEntityDTOS;50 this.workspaceType = workspaceType;51 this.elementMap = elementMap;52 this.testStepDTO = testStepDTO;53 this.testPlanId = testPlanId;54 this.testDataSet = testDataSet;55 this.environmentParameters = environmentParameters;56 this.testCaseEntityDTO = testCaseEntityDTO;57 this.environmentParamSetName = environmentParamSetName;58 this.dataProfile = dataProfile;59 this.testDataProfileService = (TestDataProfileService) webApplicationContext.getBean("testDataProfileService");60 this.elementMapper = (ElementMapper) webApplicationContext.getBean("elementMapperImpl");61 this.testStepMapper = (TestStepMapper) webApplicationContext.getBean("testStepMapperImpl");62 this.naturalTextActionsService = (NaturalTextActionsService) webApplicationContext.getBean("naturalTextActionsService");63 this.storageService = webApplicationContext.getBean(StorageServiceFactory.class).getStorageService();64 this.restStepService = (RestStepService) webApplicationContext.getBean("restStepService");65 this.defaultDataGeneratorService = (DefaultDataGeneratorService) webApplicationContext.getBean("defaultDataGeneratorService");66 this.testStepMapper = (TestStepMapper) webApplicationContext.getBean("testStepMapperImpl");67 this.addonService = (ProxyAddonService) webApplicationContext.getBean("proxyAddonService");68 }69 protected void processDefault(TestCaseStepEntityDTO exeTestStepEntity) throws TestsigmaException {70 exeTestStepEntity.setId(testStepDTO.getId());71 exeTestStepEntity.setType(testStepDTO.getType());72 exeTestStepEntity.setTestCaseId(testStepDTO.getTestCaseId());73 exeTestStepEntity.setAction(testStepDTO.getAction());74 exeTestStepEntity.setTestPlanId(testPlanId);75 exeTestStepEntity.setPriority(testStepDTO.getPriority());76 exeTestStepEntity.setPreRequisite(testStepDTO.getPreRequisiteStepId());77 exeTestStepEntity.setPosition(testStepDTO.getPosition());78 exeTestStepEntity.setIfConditionExpectedResults(testStepDTO.getIfConditionExpectedResults());79 exeTestStepEntity.setAdditionalData(testStepDTO.getDataMapJson());80 exeTestStepEntity.setAddonTestData(testStepDTO.getAddonTestData());81 populateStepDetails(testStepDTO, exeTestStepEntity);82 }83 public TestCaseStepEntityDTO processStep() throws TestsigmaException {84 TestCaseStepEntityDTO exeTestStepEntity = new TestCaseStepEntityDTO();85 exeTestStepEntity.setId(testStepDTO.getId());86 exeTestStepEntity.setType(testStepDTO.getType());87 exeTestStepEntity.setNaturalTextActionId(testStepDTO.getNaturalTextActionId());88 exeTestStepEntity.setTestCaseId(testStepDTO.getTestCaseId());89 exeTestStepEntity.setAction(testStepDTO.getAction());90 exeTestStepEntity.setTestPlanId(testPlanId);91 exeTestStepEntity.setPriority(testStepDTO.getPriority());92 exeTestStepEntity.setPreRequisite(testStepDTO.getPreRequisiteStepId());93 exeTestStepEntity.setPosition(testStepDTO.getPosition());94 exeTestStepEntity.setWaitTime(testStepDTO.getWaitTime() == null ? 0 : testStepDTO.getWaitTime());95 exeTestStepEntity.setIfConditionExpectedResults(testStepDTO.getIfConditionExpectedResults());96 exeTestStepEntity.setAdditionalData(testStepDTO.getDataMapJson());97 populateStepDetails(testStepDTO, exeTestStepEntity);98 if ((testStepDTO.getType() != null &&99 (testStepDTO.getType() == com.testsigma.model.TestStepType.STEP_GROUP)100 || (testStepDTO.getType() == com.testsigma.model.TestStepType.FOR_LOOP))) {101 return exeTestStepEntity;102 }103 if (testStepDTO.getNaturalTextActionId() != null && testStepDTO.getNaturalTextActionId() > 0) {104 NaturalTextActions naturalTextActions = naturalTextActionsService.findById(testStepDTO.getNaturalTextActionId().longValue());105 exeTestStepEntity.setSnippetClass(naturalTextActions.getSnippetClass());106 } else if (testStepDTO.getAddonActionId() != null) {107 exeTestStepEntity.setSnippetEnabled(Boolean.FALSE);108 exeTestStepEntity.setAddonNaturalTextActionEntity(addonService.fetchPluginEntity(testStepDTO.getAddonActionId()));109 }110 setElementMap(exeTestStepEntity);111 setTestDataMap(exeTestStepEntity);112 setAttributesMap(exeTestStepEntity);113 exeTestStepEntity.getStepDetails().setTestDataName(exeTestStepEntity.getTestDataName());114 exeTestStepEntity.getStepDetails().setTestDataValue(exeTestStepEntity.getTestDataValue());115 setAddonPluginStepDetails(exeTestStepEntity);116 return exeTestStepEntity;117 }118 public void setElementMap(TestCaseStepEntityDTO exeTestStepEntity) throws TestsigmaException {119 Map<String, ElementPropertiesDTO> elementsMap = new HashMap<>();120 if (testStepDTO.getAddonActionId() != null) {121 Map<String, AddonElementData> elements = testStepDTO.getAddonElements();122 for (Map.Entry<String, AddonElementData> entry : elements.entrySet()) {123 AddonElementData addonElementData = entry.getValue();124 String elementName = addonElementData.getName();125 ElementPropertiesDTO elementPropertiesDTO = getElementEntityDTO(elementName);126 elementsMap.put(entry.getKey(), elementPropertiesDTO);127 }128 } else {129 String elementName = testStepDTO.getElement();130 String fromElementName = testStepDTO.getFromElement();131 String toElementName = testStepDTO.getToElement();132 if (!org.apache.commons.lang3.StringUtils.isEmpty(elementName)) {133 ElementPropertiesDTO elementPropertiesDTO = getElementEntityDTO(elementName);134 elementsMap.put(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_ELEMENT, elementPropertiesDTO);135 }136 if (!org.apache.commons.lang3.StringUtils.isEmpty(fromElementName)) {137 ElementPropertiesDTO elementPropertiesDTO = getElementEntityDTO(fromElementName);138 elementsMap.put(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_FROM_ELEMENT, elementPropertiesDTO);139 }140 if (!org.apache.commons.lang3.StringUtils.isEmpty(toElementName)) {141 ElementPropertiesDTO elementPropertiesDTO = getElementEntityDTO(toElementName);142 elementsMap.put(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TO_ELEMENT, elementPropertiesDTO);143 }144 }145 exeTestStepEntity.setElementsMap(elementsMap);146 }147 public void setTestDataMap(TestCaseStepEntityDTO exeTestStepEntity) throws TestsigmaException {148 LinkedHashMap<String, com.testsigma.automator.entity.TestDataPropertiesEntity> testDatasMap = new LinkedHashMap<>();149 if (testStepDTO.getAddonActionId() != null || testStepDTO.getAddonTestData() != null) {150 Map<String, AddonTestStepTestData> testDataMap = testStepDTO.getAddonTestData();151 for (Map.Entry<String, AddonTestStepTestData> entry : testDataMap.entrySet()) {152 AddonTestStepTestData addonTestStepTestData = entry.getValue();153 String testDataName = entry.getKey();154 String testDataValue = addonTestStepTestData.getValue();155 String testDataType = addonTestStepTestData.getType().getDispName();156 com.testsigma.automator.entity.TestDataPropertiesEntity testDataPropertiesEntity = getTestDataEntityDTO(testDataName,157 testDataValue, testDataType, addonTestStepTestData,exeTestStepEntity);158 if (com.testsigma.model.TestDataType.getTypeFromName(testDataType) == com.testsigma.model.TestDataType.raw) {159 testDataPropertiesEntity.setTestDataValue(addonTestStepTestData.getValue());160 }161 testDatasMap.put(entry.getKey(), testDataPropertiesEntity);162 }163 } else {164 String testDataName = NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA;165 String testDataValue = testStepDTO.getTestData();166 String testDataType = testStepDTO.getTestDataType();167 if (!org.apache.commons.lang3.StringUtils.isEmpty(testDataName)) {168 com.testsigma.automator.entity.TestDataPropertiesEntity testDataPropertiesEntity = getTestDataEntityDTO(testDataName,169 testDataValue, testDataType, null, exeTestStepEntity);170 if (TestDataType.getTypeFromName(testDataType) == TestDataType.raw) {171 testDataPropertiesEntity.setTestDataValue(testStepDTO.getTestData());172 }173 testDatasMap.put(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA, testDataPropertiesEntity);174 }175 }176 exeTestStepEntity.setTestDataMap(testDatasMap);177 }178 public void setAttributesMap(TestCaseStepEntityDTO exeTestStepEntity) {179 Map<String, AttributePropertiesEntityDTO> attributesMap = new HashMap<>();180 //Custom Action (Or Addon) doesn't have the concept of attributes. They are treated as test-data itself181 //Even normal Action shouldn't have them but since it was supported earlier so we are keeping it for now182 //And should be migrated as normal test data later.183 if (testStepDTO.getAddonActionId() == null) {184 String attributeName = testStepDTO.getAttribute();185 if (!org.apache.commons.lang3.StringUtils.isEmpty(attributeName)) {186 AttributePropertiesEntityDTO attributePropertiesEntityDTO = new AttributePropertiesEntityDTO();187 attributePropertiesEntityDTO.setAttributeName(attributeName);188 attributesMap.put(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_ATTRIBUTE, attributePropertiesEntityDTO);189 }190 }191 exeTestStepEntity.setAttributesMap(attributesMap);192 }193 private ElementPropertiesDTO getElementEntityDTO(String elementName) throws TestsigmaException {194 Element element = elementMap.get(elementName.toLowerCase());195 ElementDTO elementDTO = elementMapper.map(element);196 if (element == null) {197 throw new TestsigmaException(ExceptionErrorCodes.ELEMENT_NOT_FOUND,198 MessageConstants.getMessage(MessageConstants.ELEMENT_WITH_THE_NAME_IS_NOT_AVAILABLE, elementName));199 }200 String locatorValue = updateElement(element, testDataSet, environmentParameters);201 ElementPropertiesDTO elementPropertiesDTO = new ElementPropertiesDTO();202 elementPropertiesDTO.setElementName(elementName);203 elementPropertiesDTO.setLocatorValue(locatorValue);204 elementPropertiesDTO.setLocatorStrategyName(element.getLocatorType().toString());205 elementPropertiesDTO.setFindByType(FindByType.getType(element.getLocatorType()));206 elementPropertiesDTO.setElementEntity(elementDTO);207 return elementPropertiesDTO;208 }209 private com.testsigma.automator.entity.TestDataPropertiesEntity getTestDataEntityDTO(String testDataName, String testDataValue,210 String testDataType, AddonTestStepTestData211 addonTestStepTestData, TestCaseStepEntityDTO testCaseStepEntityDTO)212 throws TestsigmaException {213 com.testsigma.automator.entity.TestDataPropertiesEntity testDataPropertiesEntity = new com.testsigma.automator.entity.TestDataPropertiesEntity();214 testDataPropertiesEntity.setTestDataType(testDataType);215 switch (com.testsigma.model.TestDataType.getTypeFromName(testDataType)) {216 case environment:217 if ((environmentParameters == null)) {218 throw new TestsigmaException(ExceptionErrorCodes.ENVIRONMENT_PARAMETERS_NOT_CONFIGURED,219 MessageConstants.getMessage(MessageConstants.MSG_UNKNOWN_ENVIRONMENT_DATA_SET));220 } else if (environmentParameters.get(testDataValue) == null) {221 throw new TestsigmaException(ExceptionErrorCodes.ENVIRONMENT_PARAMETER_NOT_FOUND,222 MessageConstants.getMessage(MessageConstants.MSG_UNKNOWN_ENVIRONMENT_PARAMETER_IN_TEST_STEP, testDataValue,223 testCaseEntityDTO.getTestCaseName(), environmentParamSetName));224 }225 String originalTestDataEnvironmentValue = testDataValue;226 testDataValue = environmentParameters.get(testDataValue);227 break;228 case parameter:229 if ((testDataSet == null) || (testDataSet.getData() == null)) {230 throw new TestsigmaException(ExceptionErrorCodes.TEST_DATA_SET_NOT_FOUND,231 com.testsigma.constants.MessageConstants.getMessage(MessageConstants.MSG_UNKNOWN_TEST_DATA_SET));232 }233 String originalTestDataValue = testDataValue;234 testDataValue = testDataSet.getData().has(testDataValue) ? (String) testDataSet.getData().get(testDataValue) :235 null;236 if (testDataValue == null) {237 throw new TestsigmaException(ExceptionErrorCodes.TEST_DATA_NOT_FOUND,238 MessageConstants.getMessage(MessageConstants.MSG_UNKNOWN_TEST_DATA_PARAMETER_IN_TEST_STEP,239 testDataName, testCaseEntityDTO.getTestCaseName(), dataProfile));240 }241 break;242 case random:243 case runtime:244 break;245 case function:246 populateDefaultDataGeneratorsEntity(testDataPropertiesEntity, addonTestStepTestData,testCaseStepEntityDTO);247 break;248 default:249 }250 testDataPropertiesEntity.setTestDataName(testDataName);251 testDataPropertiesEntity.setTestDataValue(testDataValue);252 return testDataPropertiesEntity;253 }254 public void populateStepDetails(TestStepDTO testStepDTO, TestCaseStepEntityDTO testCaseStepEntityDTO) {255 StepDetailsDTO stepDetails = new StepDetailsDTO();256 stepDetails.setNaturalTextActionId(testStepDTO.getNaturalTextActionId());257 stepDetails.setAction(testStepDTO.getAction());258 stepDetails.setPriority(Optional.ofNullable(testStepDTO.getPriority()).orElse(null));259 stepDetails.setPreRequisiteStepId(testStepDTO.getPreRequisiteStepId());260 stepDetails.setConditionType(testStepDTO.getConditionType());261 stepDetails.setParentId(testStepDTO.getParentId());262 stepDetails.setType(Optional.ofNullable(testStepDTO.getType()).orElse(null));263 stepDetails.setStepGroupId(testStepDTO.getStepGroupId());264 stepDetails.setAction(testStepDTO.getAction());265 stepDetails.setPosition(testStepDTO.getPosition());266 stepDetails.setTestDataName(testCaseStepEntityDTO.getTestDataName());267 stepDetails.setTestDataValue(testCaseStepEntityDTO.getTestDataValue());268 stepDetails.setDataMap(testStepMapper.mapDataMap(testStepDTO.getDataMapBean()));269 stepDetails.setIgnoreStepResult(testStepDTO.getIgnoreStepResult());270 testCaseStepEntityDTO.setStepDetails(stepDetails);271 }272 private void setAddonPluginStepDetails(TestCaseStepEntityDTO exeTestStepEntity) {273 if (testStepDTO.getAddonActionId() != null) {274 exeTestStepEntity.setAddonTestData(testStepDTO.getAddonTestData());275 exeTestStepEntity.setAddonElements(testStepDTO.getAddonElements());276 }277 }278 public void loadLoop(TestStepDTO stepDTOEntity, List<TestStepDTO> stepDTOEntities,279 List<Long> loopIds) {280 List<TestStepDTO> loopSteps = new ArrayList<>();281 TestStepDTO childTestStepDTO;282 List<Long> childConditions = new ArrayList<>();283 for (int index = 0; index < stepDTOEntities.size(); index++) {284 childTestStepDTO = stepDTOEntities.get(index);285 if ((childTestStepDTO.getParentId() != null && childTestStepDTO.getParentId() > 0 && stepDTOEntity.getId() != null286 && (childTestStepDTO.getParentId().equals(stepDTOEntity.getId()) ||287 (childConditions.indexOf(childTestStepDTO.getParentId()) > -1)))) {288 if (childTestStepDTO.getType() != null &&289 (com.testsigma.model.TestStepType.FOR_LOOP.equals(childTestStepDTO.getType())290 || TestStepConditionType.LOOP_WHILE.equals(childTestStepDTO.getConditionType()))) {291 loadLoop(childTestStepDTO, stepDTOEntities, loopIds);292 } else {293 childConditions.add(childTestStepDTO.getId());294 }295 loopIds.add(childTestStepDTO.getId());296 loopSteps.add(childTestStepDTO);297 }298 }299 stepDTOEntity.setTestStepDTOS(loopSteps);300 }301 private void populateDefaultDataGeneratorsEntity(com.testsigma.automator.entity.TestDataPropertiesEntity testDataPropertiesEntity,302 AddonTestStepTestData addonTestStepTestData, TestCaseStepEntityDTO exeTestStepEntity)303 throws TestsigmaException {304 DefaultDataGeneratorsEntity defaultDataGeneratorsEntity = new DefaultDataGeneratorsEntity();305 try {306 if (testStepDTO.getAddonActionId() != null) {307 populateTestDataFunctionDetailsFromId(defaultDataGeneratorsEntity, addonTestStepTestData, exeTestStepEntity);308 } else {309 populateTestDataFunctionDetailsFromMap(defaultDataGeneratorsEntity, exeTestStepEntity);310 }311 testDataPropertiesEntity.setDefaultDataGeneratorsEntity(defaultDataGeneratorsEntity);312 } catch (Exception e) {313 throw new TestsigmaException(e.getMessage(), e);314 }315 }316 private void populateTestDataFunctionDetailsFromId(DefaultDataGeneratorsEntity testDataFunctionEntity,317 AddonTestStepTestData addonTestStepTestData, TestCaseStepEntityDTO exeTestStepEntity) throws ResourceNotFoundException {318 Map<String, String> arguments = addonTestStepTestData.getTestDataFunctionArguments();319 testDataFunctionEntity.setArguments(arguments);320 if (addonTestStepTestData.getIsAddonFn()) {321 AddonPluginTestDataFunctionEntityDTO tdfEntityDTO = addonService.fetchPluginTestDataFunctionEntities(addonTestStepTestData.getTestDataFunctionId());322 ArrayList<AddonPluginTestDataFunctionEntityDTO> tdfEntityDTOList = new ArrayList<AddonPluginTestDataFunctionEntityDTO>();323 tdfEntityDTOList.add(tdfEntityDTO);324 if (exeTestStepEntity.getAddonPluginTDFEntityList() == null) {325 exeTestStepEntity.setAddonPluginTDFEntityList(tdfEntityDTOList);326 } else {327 exeTestStepEntity.getAddonPluginTDFEntityList().addAll(tdfEntityDTOList);328 }329 testDataFunctionEntity.setIsAddonFn(addonTestStepTestData.getIsAddonFn());330 } else {331 DefaultDataGenerator customFunction = defaultDataGeneratorService.find(addonTestStepTestData.getTestDataFunctionId());332 DefaultDataGeneratorFile customFunctionFile = defaultDataGeneratorService.findFileById(customFunction.getFileId());333 testDataFunctionEntity.setClassName(customFunctionFile.getClassName());334 testDataFunctionEntity.setFunctionName(customFunction.getFunctionName());335 Map<String, String> functionArguments = new ObjectMapperService().parseJson(336 customFunction.getArguments().get("arg_types").toString(), HashMap.class);337 testDataFunctionEntity.setArgumentTypes(functionArguments);338 testDataFunctionEntity.setClassPackage(customFunctionFile.getClassPackage());339 testDataFunctionEntity.setCustomFunctionType(CustomFunctionType.DefaultTestData);340// testDataFunctionEntity.setBinaryFileUrl(getSignedURL(customFunctionFile.getBinary_file_url(), customFunctionFile.getClassName()));341 }342 testDataFunctionEntity.setId(addonTestStepTestData.getTestDataFunctionId());343 }344 private void populateTestDataFunctionDetailsFromMap(DefaultDataGeneratorsEntity defaultDataGeneratorsEntity, TestCaseStepEntityDTO exeTestStepEntity)345 throws TestsigmaException {346 TestStepDataMap testStepDataMap = testStepDTO.getDataMapBean();347 if (testStepDataMap != null) {348 if (testStepDataMap.getAddonTDF() != null) {349 defaultDataGeneratorsEntity.setArguments(testStepDataMap.getAddonTDF().getTestDataFunctionArguments());350 defaultDataGeneratorsEntity.setIsAddonFn(true);351 AddonPluginTestDataFunctionEntityDTO tdfEntityDTO = addonService.fetchPluginTestDataFunctionEntities(testStepDataMap.getAddonTDF().getTestDataFunctionId());352 ArrayList<AddonPluginTestDataFunctionEntityDTO> tdfEntityDTOList = new ArrayList<AddonPluginTestDataFunctionEntityDTO>();353 tdfEntityDTOList.add(tdfEntityDTO);354 exeTestStepEntity.setAddonPluginTDFEntityList(tdfEntityDTOList);355 return;356 }357 }358 if (testStepDTO.getTestDataFunctionId() == null) {359 throw new TestsigmaException(ExceptionErrorCodes.TEST_DATA_NOT_FOUND_TEST_STEP,360 MessageConstants.getMessage(MessageConstants.INVALID_TEST_DATA));361 }362 DefaultDataGenerator defaultDataGenerator = defaultDataGeneratorService.find(testStepDTO.getTestDataFunctionId());363 defaultDataGeneratorsEntity.setClassName(defaultDataGenerator.getFile().getClassName());364 defaultDataGeneratorsEntity.setFunctionName(defaultDataGenerator.getFunctionName());365 defaultDataGeneratorsEntity.setArguments(testStepDTO.getTestDataFunctionArgs());366 Map<String, String> argsTypes = (HashMap) defaultDataGenerator.getArguments().get("arg_types");367 defaultDataGeneratorsEntity.setArgumentTypes(argsTypes);368 defaultDataGeneratorsEntity.setClassPackage(defaultDataGenerator.getFile().getClassPackage());369 }370 public String updateElement(Element element, TestDataSet testData, Map<String, String> environmentParams) {371 String locatorValue = element.getLocatorValue();372 try {373 if (element.getIsDynamic()) {374 ElementMetaData metaData = element.getMetadata();375 if (metaData.getTestData() != null) {376 //JsonObject to Map Casting failed377 Map<String, Object> rawDataMap = metaData.getTestData().toMap();378 Map<String, String> stringTypeDataMap = new HashMap();379 for (Map.Entry<String, Object> entry : rawDataMap.entrySet()) {380 if (entry.getValue() instanceof String) {381 stringTypeDataMap.put(entry.getKey(), (String) entry.getValue());382 }383 }384 Map<String, String> dataMap = stringTypeDataMap;385 if (dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA_TYPE).equals(TestDataType.parameter.name())) {386 //TODO: Handle null and exception cases..387 if (!(testData == null || testData.getData() == null || org.apache.commons.lang3.StringUtils.isEmpty(dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA)) ||388 org.apache.commons.lang3.StringUtils.isEmpty(testData.getData().optString(dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA))))) {389 String data = testData.getData().getString(dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA));390 locatorValue =391 element.getLocatorValue().replaceAll(NaturalTextActionConstants.TEST_DATA_PARAMETER_PREFIX + "\\|" + Pattern.quote(dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA)) + "\\|",392 Matcher.quoteReplacement(data));393 }394 } else if (dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA_TYPE).equals(TestDataType.environment.name())) {395 if (environmentParams != null && StringUtils.isNotEmpty(dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA))) {396 String data = environmentParams.get(dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA));397 if (data != null) {398 locatorValue =399 element.getLocatorValue().replaceAll(NaturalTextActionConstants.TEST_DATA_ENVIRONMENT_PARAM_PREFIX + "\\|" + Pattern.quote(dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA)) + "\\|",400 Matcher.quoteReplacement(data));401 }else {402 String errorMessage = com.testsigma.constants.MessageConstants.getMessage(403 MessageConstants.MSG_UNKNOWN_ENVIRONMENT_PARAMETER_IN_ELEMENT, dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA), this.testCaseEntityDTO.getTestCaseName(), element.getName());404 throw new TestsigmaException(ExceptionErrorCodes.ENVIRONMENT_PARAMETER_NOT_FOUND, errorMessage);405 }406 }407 //TODO: Handle null and exception cases..408 } else if (dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA_TYPE).equals(TestDataType.runtime.name())) {409 //TODO: Handle null and exception cases..410 } else if (dataMap.get(NaturalTextActionConstants.TEST_STEP_DATA_MAP_KEY_TEST_DATA_TYPE).equals(TestDataType.function.name())) {411 //TODO: Handle null and exception cases..s412 }413 }414 }415 } catch (TestsigmaException e) {416 log.info(e.getMessage(),e);417 }418 return locatorValue;419 }420}...
Source:DefaultDataGenerator.java
...53 if (arguments == null)54 return null;55 return JSONObjectConverter.toJsonObject(arguments).toMap();56 }57// public JSONObject getMetaData() {58// return JSONObjectConverter.toJsonObject(metaData);59// }60//61// public void setMetaData(JSONObject metaData) {62// this.metaData = metaData == null ? null : metaData.toString();63// }64}...
getMetaData
Using AI Code Generation
1package com.testsigma.model;2import java.sql.Connection;3import java.sql.DriverManager;4import java.sql.ResultSet;5import java.sql.SQLException;6import java.sql.Statement;7import java.util.ArrayList;8import java.util.List;9public class DefaultDataGenerator {10public static void main(String[] args) throws SQLException, ClassNotFoundException {11 DefaultDataGenerator defaultDataGenerator = new DefaultDataGenerator();12 List<String> list = defaultDataGenerator.getMetaData("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle", "select * from employee");13 System.out.println(list);14}15public List<String> getMetaData(String url, String username, String password, String query) throws SQLException, ClassNotFoundException {16 List<String> list = new ArrayList<String>();17 Class.forName("oracle.jdbc.driver.OracleDriver");18 Connection con = DriverManager.getConnection(url, username, password);19 Statement stmt = con.createStatement();20 ResultSet rs = stmt.executeQuery(query);21 int columnCount = rs.getMetaData().getColumnCount();22 for (int i = 1; i <= columnCount; i++) {23 list.add(rs.getMetaData().getColumnName(i));24 }25 return list;26}27}
getMetaData
Using AI Code Generation
1import com.testsigma.model.DefaultDataGenerator;2import java.sql.ResultSetMetaData;3import java.sql.SQLException;4public class 2 {5 public static void main(String args[]) throws SQLException {6 DefaultDataGenerator ddg = new DefaultDataGenerator();7 ResultSetMetaData rsmd = ddg.getMetaData("select * from emp");8 int colCount = rsmd.getColumnCount();9 for (int i = 1; i <= colCount; i++) {10 System.out.println(rsmd.getColumnName(i));11 }12 }13}14import com.testsigma.model.DefaultDataGenerator;15import java.sql.ResultSetMetaData;16import java.sql.SQLException;17public class 3 {18 public static void main(String args[]) throws SQLException {19 DefaultDataGenerator ddg = new DefaultDataGenerator();20 ResultSetMetaData rsmd = ddg.getMetaData("select * from emp");21 int colCount = rsmd.getColumnCount();22 for (int i = 1; i <= colCount; i++) {23 System.out.println(rsmd.getColumnTypeName(i));24 }25 }26}27import com.testsigma.model.DefaultDataGenerator;28import java.sql.ResultSetMetaData;29import java.sql.SQLException;30public class 4 {31 public static void main(String args[]) throws SQLException {32 DefaultDataGenerator ddg = new DefaultDataGenerator();33 ResultSetMetaData rsmd = ddg.getMetaData("select * from emp");34 int colCount = rsmd.getColumnCount();35 for (int i = 1; i <= colCount; i++) {36 System.out.println(rsmd.getColumnDisplaySize(i));37 }38 }39}40import com.testsigma.model.DefaultDataGenerator;41import java.sql.ResultSetMetaData;42import java.sql.SQLException;43public class 5 {44 public static void main(String args[]) throws SQLException
getMetaData
Using AI Code Generation
1import com.testsigma.model.DefaultDataGenerator;2import java.sql.ResultSetMetaData;3import java.sql.SQLException;4public class 4 {5 public static void main(String args[]) throws SQLException {6 DefaultDataGenerator ddg = new DefaultDataGenerator();7 ResultSetMetaData rsmd = ddg.getMetaData("select * from emp");8 int colCount = rsmd.getColumnCount();9 for (int i = 1; i <= colCount; i++) {10 System.out.println(rsmd.getColumnName(i));11 }12 }13}14import com.testsigma.model.DefaultDataGenerator;15import java.sql.ResultSetMetaData;16import java.sql.SQLException;17public class 3 {18 public static void main(String args[]) throws SQLException {19 DefaultDataGenerator ddg = new DefaultDataGenerator();20 ResultSetMetaData rsmd = ddg.getMetaData("select * from emp");21 int colCount = rsmd.getColumnCount();22 for (int i = 1; i <= colCount; i++) {23 System.out.println(rsmd.getColumnTypeName(i));24 }25 }26}27import com.testsigma.model.DefaultDataGenerator;28import java.sql.ResultSetMetaData;29import java.sql.SQLException;30public class 4 {31 public static void main(String args[]) throws SQLException {32 DefaultDataGenerator ddg = new DefaultDataGenerator();33 ResultSetMetaData rsmd = ddg.getMetaData("select * from emp");34 int colCount = rsmd.getColumnCount();35 for (int i = 1; i <= colCount; i++) {36 System.out.println(rsmd.getColumnDisplaySize(i));37 }38 }39}40import com.testsigma.model.DefaultDataGenerator;41import java.sql.ResultSetMetaData;42import java.sql.SQLException;43public class 5 {44 public static void main(String args[]) throws SQLException
getMetaData
Using AI Code Generation
1import com.testsigma.model.DefaultDataGenerator;2import java.sql.*;3{4public static void main(String args[])5{6{7DefaultDataGenerator ddg=new DefaultDataGenerator();8Connection con=ddg.getMetaData("jdbc:odbc:mydsn");9Statement st=con.createStatement();10ResultSet rs=st.executeQuery("select * from emp");11while(rs.next())12{13System.out.println(rs.getString(1)+""+rs.getString(2)+""+rs.getString(3));14}15}16catch(Exception e)17{18e.printStackTrace();19}20}21}22import com.testsigma.model.DefaultDataGenerator;23import java.sql.*;24{25public static void main(String args[])26{27{28DefaultDataGenerator ddg=new DefaultDataGenerator();29Connection con=ddg.getMetaData("jdbc:odbc:mydsn");30DatabaseMetaData dbmd=con.getMetaData();31System.out.println(dbmd.getDatabaseProductName());32System.out.println(dbmd.getDatabaseProductVersion());33System.out.println(dbmd.getDriverName());34System.out.println(dbmd.getDriverVersion());35System.out.println(dbmd.getURL());36System.out.println(dbmd.getUserName());37}38catch(Exception e)39{40e.printStackTrace();41}42}43}
getMetaData
Using AI Code Generation
1import com.testsigma.model.DefaultDataGenerator;2import com.testsigma.model.DataGenerator;3import com.testsigma.model.DataGeneratorFactory;4public class 2 {5 public static void main(String[] args) {6 DataGeneratorFactory factory = DataGeneratorFactory.getInstance();7 DataGenerator generator = factory.getDataGenerator("DefaultDataGenerator");8 System.out.println(generator.getMetaData());9 }10}11import com.testsigma.model.DefaultDataGenerator;12import com.testsigma.model.DataGenerator;13import com.testsigma.model.DataGeneratorFactory;14public class 3 {15 public static void main(String[] args) {16 DataGeneratorFactory factory = DataGeneratorFactory.getInstance();17 DataGenerator generator = factory.getDataGenerator("DefaultDataGenerator");18 System.out.println(generator.getMetaData());19 }20}21import com.testsigma.model.DefaultDataGenerator;22import com.testsigma.model.DataGenerator;23import com.testsigma.model.DataGeneratorFactory;24public class 4 {25 public static void main(String[] args) {26 DataGeneratorFactory factory = DataGeneratorFactory.getInstance();27 DataGenerator generator = factory.getDataGenerator("DefaultDataGenerator");28 System.out.println(generator.getMetaData());29 }30}31import com.testsigma.model.DefaultDataGenerator;32import com.testsigma.model.DataGenerator;33import com.testsigma.moel.DataGeneratorFactory;34public class 5 {35 public static void main(String[] args) {36 DataGeneratorFactory factory = DataGeneratorFactory.getInstance();37 DataGenerator generator = factory.getDataGenerator("DefaultDataGenerator");38 System.out.println(generator.getMetaData());39 }40}41import com.testsigma.model.DefaultDataGenerator;42import com.testsigma.model.DataGenerator;43import com.testsigma.model.DataGeneratorFactory;44public class 6 {45 public static void main(String[]46import java.util.*;47{48public static void main(String[] args)49{50{51DefaultDataGenerator ddg = new DefaultDataGenerator();52Connection con = ddg.getConnection();53DatabaseMetaData dbmd = ddg.getMetaData();54System.out.println("Database Product Name:" + dbmd.getDatabaseProductName());55System.out.println("Database Product Version:" + dbmd.getDatabaseProductVersion());56System.out.println("Driver Name:" + dbmd.getDriverName());57System.out.println("Driver Version:" + dbmd.getDriverVersion());58System.out.println("Driver Major Version:" + dbmd.getDriverMajorVersion());59System.out.println("Driver Minor Version:" + dbmd.getDriverMinorVersion());60System.out.println("Database Major Version:" + dbmd.getDatabaseMajorVersion());61System.out.println("Database Minor Version:" + dbmd.getDatabaseMinorVersion());62System.out.println("URL:" + dbmd.getURL());63System.out.println("User Name:" + dbmd.getUserName());64System.out.println("JDBC Major Version:" + dbmd.getJDBCMajorVersion());65System.out.println("JDBC Minor Version:" + dbmd.getJDBCMinorVersion());66System.out.println("Maximum Connections:" + dbmd.getMaxConnections());67System.out.println("Maximum Columns in Table:" + dbmd.getMaxColumnsInTable());68System.out.println("Maximum Columns in Index:" + dbmd.getMaxColumnsInIndex());69System.out.println("Maximum Row Size:" + dbmd.getMaxRowSize());70System.out.println("Maximum Statement Length:" + dbmd.getMaxStatementLength());71System.out.println("Maximum Tables in Select:" + dbmd.getMaxTablesInSelect());72System.out.println("Maximum Columns in Group By:" + dbmd.getMaxColumnsInGroupBy());73System.out.println("Maximum Columns in Order By:" + dbmd.getMaxColumnsInOrderBy());74System.out.println("Maximum Columns in Select:" + dbmd.getMaxColumnsInSelect());75System.out.println("Maximum Columns in Insert:" + dbmd.getMaxColumnsInInsert());76System.out.println("Maximum Columns in Table:" + dbmd.getMaxColumnsInTable());77System.out.println("Maximum Columns in Index:" + dbmd.getMaxColumnsInIndex());78System.out.println("Maximum Row Size:" + dbmd.getMaxRowSize());79System.out.println("Maximum Statement Length:" + dbmd.getMaxStatementLength());80System.out.println("Maximum Tables in Select:" + dbmd.getMaxTablesInSelect());81System.out.println("Maximum
getMetaData
Using AI Code Generation
1import com.testsigma.model.DefaultDataGenerator;2public class 2 {3 public static void main(String[] args) {4 DefaultDataGenerator d = new DefaultDataGenerator();5 System.out.println(metaData);6 }7}8import com.testsigma.model.DefaultDataGenerator;9public class 3 {10 public static void main(String[] args) {11 DefaultDataGenerator d = new DefaultDataGenerator();12 System.out.println(links);13 }14}15import com.testsigma.model.DefaultDataGenerator;16public class 4 {17 public static void main(String[] args) {18 DefaultDataGenerator d = new DefaultDataGenerator();19 System.out.println(links);20 }21}
getMetaData
Using AI Code Generation
1package com.testsigma.model;2import java.sql.*;3public class getMetaData {4public static void main(String args[]) {5DefaultDataGenerator d = new DefaultDataGenerator();6try {7ResultSetMetaData rsmd = d.getMetaData();8System.out.println("Number of columns: " + rsmd.getColumnCount());9System.out.println("Column Name of 1st column: " + rsmd.getColumnName(1));10System.out.println("Column Type Name of 1st column: " + rsmd.getColumnTypeName(1));11} catch (SQLException e) {12System.out.println(e.getMessage());13}14}15}
getMetaData
Using AI Code Generation
1import com.testsigma.model.DefaultDataGenerator;2public class 2 {3 public static void main(String[] args) {4 DefaultDataGenerator d = new DefaultDataGenerator();5 System.out.println(metaData);6 }7}8import com.testsigma.model.DefaultDataGenerator;9public class 3 {10 public static void main(String[] args) {11 DefaultDataGenerator d = new DefaultDataGenerator();12 System.out.println(links);13 }14}15import com.testsigma.model.DefaultDataGenerator;16public class 4 {17 public static void main(String[] args) {18 DefaultDataGenerator d = new DefaultDataGenerator();19 System.out.println(links);20 }21}
getMetaData
Using AI Code Generation
1package com.testsigma.model;2import java.sql.*;3public class getMetaData {4public static void main(String args[]) {5DefaultDataGenerator d = new DefaultDataGenerator();6try {7ResultSetMetaData rsmd = d.getMetaData();8System.out.println("Number of columns: " + rsmd.getColumnCount());9System.out.println("Column Name of 1st column: " + rsmd.getColumnName(1));10System.out.println("Column Type Name of 1st column: " + rsmd.getColumnTypeName(1));11} catch (SQLException e) {12System.out.println(e.getMessage());13}14}15}
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!!