Best Testsigma code snippet using com.testsigma.service.NaturalTextActionsService.findById
Source:TestStepService.java
...94 public void destroy(TestStep testStep) throws ResourceNotFoundException {95 repository.decrementPosition(testStep.getPosition(), testStep.getTestCaseId());96 repository.delete(testStep);97 if (testStep.getAddonActionId() != null) {98 AddonNaturalTextAction addonNaturalTextAction = addonNaturalTextActionService.findById(testStep.getAddonActionId());99 addonService.notifyActionNotUsing(addonNaturalTextAction);100 }101 publishEvent(testStep, EventType.DELETE);102 }103 public TestStep find(Long id) throws ResourceNotFoundException {104 return this.repository.findById(id).orElseThrow(() -> new ResourceNotFoundException("TestStep missing with id:" + id));105 }106 private TestStep updateDetails(TestStep testStep) {107 RestStep restStep = testStep.getRestStep();108 testStep.setRestStep(null);109 testStep = this.repository.save(testStep);110 if (restStep != null) {111 restStep.setStepId(testStep.getId());112 restStep = this.restStepService.update(restStep);113 testStep.setRestStep(restStep);114 }115 return testStep;116 }117 public TestStep update(TestStep testStep) {118 testStep = updateDetails(testStep);119 this.updateDisablePropertyForChildSteps(testStep);120 publishEvent(testStep, EventType.UPDATE);121 return testStep;122 }123 private void updateDisablePropertyForChildSteps(TestStep testStep) {124 List<TestStep> childSteps = this.repository.findAllByParentIdOrderByPositionAsc(testStep.getId());125 if (childSteps.size() > 0) {126 for (TestStep childStep : childSteps) {127 childStep.setDisabled(testStep.getDisabled());128 this.update(childStep);129 }130 }131 }132 public TestStep create(TestStep testStep) throws ResourceNotFoundException {133 this.repository.incrementPosition(testStep.getPosition(), testStep.getTestCaseId());134 RestStep restStep = testStep.getRestStep();135 testStep.setRestStep(null);136 testStep = this.repository.save(testStep);137 if (restStep != null) {138 RestStep newRestStep = mapper.mapStep(restStep);139 newRestStep.setStepId(testStep.getId());140 newRestStep = this.restStepService.create(newRestStep);141 testStep.setRestStep(newRestStep);142 }143 if (testStep.getAddonActionId() != null) {144 AddonNaturalTextAction addonNaturalTextAction = addonNaturalTextActionService.findById(testStep.getAddonActionId());145 addonService.notifyActionUsing(addonNaturalTextAction);146 }147 publishEvent(testStep, EventType.CREATE);148 return testStep;149 }150 public void bulkUpdateProperties(Long[] ids, TestStepPriority testStepPriority, Integer waitTime, Boolean disabled,151 Boolean ignoreStepResult,Boolean visualEnabled) {152 this.repository.bulkUpdateProperties(ids, testStepPriority != null ? testStepPriority.toString() : null, waitTime,visualEnabled);153 if (disabled != null || ignoreStepResult != null)154 this.bulkUpdateDisableAndIgnoreResultProperties(ids, disabled, ignoreStepResult);155 }156 private void bulkUpdateDisableAndIgnoreResultProperties(Long[] ids, Boolean disabled, Boolean ignoreStepResult) {157 List<TestStep> testSteps = this.repository.findAllByIdInOrderByPositionAsc(ids);158 for (TestStep testStep : testSteps) {159 if (disabled != null) {160 if (!disabled && testStep.getParentStep() == null) {161 testStep.setDisabled(false);162 } else if (!disabled && testStep.getParentStep() != null) {163 testStep.setDisabled(testStep.getParentStep().getDisabled());164 } else {165 testStep.setDisabled(disabled);166 }167 }168 if (ignoreStepResult != null) {169 testStep.setIgnoreStepResult(ignoreStepResult);170 }171 this.updateDetails(testStep);172 }173 }174 public List<TestStep> findAllByTestCaseIdAndIdIn(Long testCaseId, List<Long> stepIds) {175 return this.repository.findAllByTestCaseIdAndIdInOrderByPosition(testCaseId, stepIds);176 }177 public void updateTestDataParameterName(Long testDataId, String parameter, String newParameterName) {178 this.repository.updateTopLevelTestDataParameter(newParameterName, parameter, testDataId);179 List<TestStep> topConditionalSteps = this.repository.getTopLevelConditionalStepsExceptLoop(testDataId);180 for (TestStep step : topConditionalSteps) {181 updateChildLoops(step.getId(), parameter, newParameterName);182 }183 List<TestStep> loopSteps = this.repository.getAllLoopSteps(testDataId);184 for (TestStep step : loopSteps) {185 updateChildLoops(step.getId(), parameter, newParameterName);186 }187 }188 public void updateElementName(String oldName, String newName) {189 this.repository.updateElementName(newName, oldName);190 }191 private void updateChildLoops(Long parentId, String parameter, String newParameterName) {192 this.repository.updateChildStepsTestDataParameter(newParameterName, parameter, parentId);193 this.repository.updateChildStepsTestDataParameterUsingTestDataProfileId(newParameterName, parameter, parentId);194 List<TestStep> conditionalSteps = this.repository.getChildConditionalStepsExceptLoop(parentId);195 for (TestStep step : conditionalSteps) {196 updateChildLoops(step.getId(), parameter, newParameterName);197 }198 }199 public List<TestStep> findAllByTestCaseIdAndNaturalTextActionIds(Long id, List<Integer> ids) {200 return this.repository.findAllByTestCaseIdAndNaturalTextActionIdIn(id, ids);201 }202 public Integer countAllByAddonActionIdIn(List<Long> ids) {203 return this.repository.countAllByAddonActionIdIn(ids);204 }205 public void updateAddonElementsName(String oldName, String newName) {206 List<TestStep> testSteps = this.repository.findAddonElementsByName(oldName);207 testSteps.forEach(testStep -> {208 Map<String, AddonElementData> elements = testStep.getAddonElements();209 for (Map.Entry<String, AddonElementData> entry : elements.entrySet()) {210 if (entry.getValue().getName().equals(oldName)) {211 entry.getValue().setName(newName);212 }213 }214 testStep.setAddonElements(elements);215 this.repository.save(testStep);216 });217 }218 public void export(BackupDTO backupDTO) throws IOException, ResourceNotFoundException {219 if (!backupDTO.getIsTestStepEnabled()) return;220 log.debug("backup process for test step initiated");221 writeXML("test_steps", backupDTO, PageRequest.of(0, 25));222 log.debug("backup process for test step completed");223 }224 public Specification<TestStep> getExportXmlSpecification(BackupDTO backupDTO) {225 List<TestCase> testCaseList = testCaseService.findAllByWorkspaceVersionId(backupDTO.getWorkspaceVersionId());226 List<Long> testcaseIds = testCaseList.stream().map(testCase -> testCase.getId()).collect(Collectors.toList());227 SearchCriteria criteria = new SearchCriteria("testCaseId", SearchOperation.IN, testcaseIds);228 List<SearchCriteria> params = new ArrayList<>();229 params.add(criteria);230 TestStepSpecificationsBuilder testStepSpecificationsBuilder = new TestStepSpecificationsBuilder();231 testStepSpecificationsBuilder.params = params;232 return testStepSpecificationsBuilder.build();233 }234 @Override235 protected List<TestStepXMLDTO> mapToXMLDTOList(List<TestStep> list) {236 return exportTestStepMapper.mapTestSteps(list);237 }238 public void publishEvent(TestStep testSuite, EventType eventType) {239 TestStepEvent<TestStep> event = createEvent(testSuite, eventType);240 log.info("Publishing event - " + event.toString());241 applicationEventPublisher.publishEvent(event);242 }243 public TestStepEvent<TestStep> createEvent(TestStep testSuite, EventType eventType) {244 TestStepEvent<TestStep> event = new TestStepEvent<>();245 event.setEventData(testSuite);246 event.setEventType(eventType);247 return event;248 }249 private void generateXLSheet(BackupDTO importDTO){250 HashMap<TestStep, String> stepsMap= this.affectedTestCaseXLSExportService.getStepsMap();251 if (stepsMap !=null && !stepsMap.isEmpty()) {252 XSSFWorkbook workbook = this.affectedTestCaseXLSExportService.initializeWorkBook();253 try {254 this.affectedTestCaseXLSExportService.addToExcelSheet(stepsMap, workbook, importDTO, 1);255 } catch (Exception e) {256 log.error(e.getMessage());257 }258 }259 }260 public void importXML(BackupDTO importDTO) throws IOException, ResourceNotFoundException {261 if (!importDTO.getIsTestStepEnabled()) return;262 log.debug("import process for Test step initiated");263 this.affectedTestCaseXLSExportService.setStepsMap(new HashMap<>());264 importFiles("test_steps", importDTO);265 generateXLSheet(importDTO);266 log.debug("import process for Test step completed");267 }268 @Override269 public List<TestStep> readEntityListFromXmlData(String xmlData, XmlMapper xmlMapper, BackupDTO importDTO) throws JsonProcessingException, ResourceNotFoundException {270 if (importDTO.getIsCloudImport()) {271 List<TestStep> steps = mapper.mapTestStepsCloudList(xmlMapper.readValue(xmlData, new TypeReference<List<TestStepCloudXMLDTO>>() {272 }));273 HashMap<TestStep, String> stepsMap= this.affectedTestCaseXLSExportService.getStepsMap();274 for (TestStep step : steps) {275 String message =null;276 try {277 if (step.getAddonActionId() != null && step.getAddonActionId() > 0) {278 message = "Not supported Addon Step!";279 addonNaturalTextActionService.findById(step.getAddonActionId());280 }281 if (step.getNaturalTextActionId() != null && step.getNaturalTextActionId() > 0) {282 if (step.getNaturalTextActionId()==574){ //// TODO: need to changes on Cloud side [Siva Nagaraju]283 step.setNaturalTextActionId(1038);284 continue;285 }286 message = "Deprecated Action!";287 try {288 naturalTextActionsService.findById(Long.valueOf(step.getNaturalTextActionId()));289 }290 catch (Exception e){291 if (this.depreciatedIds.contains(step.getNaturalTextActionId()))292 this.mapDeprecatedActionsWithUpdatesOnes(step);293 else {294 log.error(e.getMessage() + " and Not able to Map this Action Id with the Mapper");295 step.setDisabled(true);296 step.setAddonActionId(null);297 stepsMap.put(step, message);298 }299 }300 }301 if (Objects.equals(step.getTestDataType(), TestDataType.function.getDispName()) && step.getType() != TestStepType.CUSTOM_FUNCTION) {302 message = "Deprecated Data Generator / Data Generator not found!";303 defaultDataGeneratorService.find(step.getTestDataFunctionId());304 }305 } catch (Exception e) {306 log.error(e.getMessage());307 step.setDisabled(true);308 step.setAddonActionId(null);309 stepsMap.put(step, message);310 log.info("disabling test steps having template id or addon action id or custom function id is not found!");311 }312 if (step.getType() == TestStepType.CUSTOM_FUNCTION) {313 step.setDisabled(true);314 stepsMap.put(step, "Custom Functions not supported in OS");315 log.info("disabling Custom function test step to avoid further issues, since CSFs are deprecated");316 }317 if (step.getType() == TestStepType.FOR_LOOP) {318 Optional<TestData> testData = testDataService.getRecentImportedEntity(importDTO, step.getForLoopTestDataId());319 if (testData.isPresent())320 step.setForLoopTestDataId(testData.get().getId());321 }322 }323 return steps;324 } else {325 List<TestStep> steps = mapper.mapTestStepsList(xmlMapper.readValue(xmlData, new TypeReference<List<TestStepXMLDTO>>() {326 }));327 for (TestStep step : steps) {328 if (step.getTestDataProfileStepId() != null) {329 Optional<TestData> testData = testDataService.getRecentImportedEntity(importDTO, step.getTestDataProfileStepId());330 testData.ifPresent(data -> step.setTestDataProfileStepId(data.getId()));331 }332 if (step.getType() == TestStepType.FOR_LOOP) {333 Optional<TestData> testData = testDataService.getRecentImportedEntity(importDTO, step.getForLoopTestDataId());334 testData.ifPresent(data -> step.setForLoopTestDataId(data.getId()));335 }336 }337 return steps;338 }339 }340 private void mapDeprecatedActionsWithUpdatesOnes(TestStep step) {341 ActionTestDataMap filteredMap = this.actionTestDataMap.stream().filter(dataMap -> dataMap.getTestDataHash().containsKey(step.getNaturalTextActionId())).findFirst().orElse(null);342 if (filteredMap != null) {343 step.setTestData(filteredMap.getTestDataHash().get(step.getNaturalTextActionId()));344 step.setNaturalTextActionId(filteredMap.getOptimizedActionId());345 step.setTestDataType(TestDataType.raw.getDispName());346 }347 }348 @Override349 public Optional<TestStep> findImportedEntity(TestStep testStep, BackupDTO importDTO) {350 Optional<TestCase> testCase = testCaseService.getRecentImportedEntity(importDTO, testStep.getTestCaseId());351 if (testCase.isEmpty()) {352 return Optional.empty();353 }354 Optional<TestStep> previous = repository.findByTestCaseIdInAndImportedId(List.of(testCase.get().getId()), testStep.getId());355 return previous;356 }357 @Override358 public TestStep processBeforeSave(Optional<TestStep> previous, TestStep present, TestStep toImport, BackupDTO importDTO) throws ResourceNotFoundException {359 present.setImportedId(present.getId());360 if (previous.isPresent() && importDTO.isHasToReset()) {361 present.setId(previous.get().getId());362 } else {363 present.setId(null);364 }365 setTemplateId(present, importDTO);366 processTestDataMap(present, importDTO);367 Optional<TestCase> testCase = testCaseService.getRecentImportedEntity(importDTO, present.getTestCaseId());368 if (testCase.isPresent())369 present.setTestCaseId(testCase.get().getId());370 if (present.getStepGroupId() != null) {371 Optional<TestCase> testComponent = testCaseService.getRecentImportedEntity(importDTO, present.getStepGroupId());372 if (testComponent.isPresent())373 present.setStepGroupId(testComponent.get().getId());374 }375 if (present.getParentId() != null) {376 Optional<TestStep> testStep = getRecentImportedEntity(importDTO, present.getParentId());377 if (testStep.isPresent()) {378 present.setParentId(testStep.get().getId());379 if (testStep.get().getDisabled()) {380 present.setDisabled(true);381 }382 }383 }384 if (present.getPreRequisiteStepId() != null) {385 Optional<TestStep> recentPrerequisite = getRecentImportedEntityForPreq(present.getTestCaseId(), present.getPreRequisiteStepId());386 if (recentPrerequisite.isPresent())387 present.setPreRequisiteStepId(recentPrerequisite.get().getId());388 }389 return present;390 }391 public boolean hasToSkip(TestStep testStep, BackupDTO importDTO) {392 Optional<TestCase> testCase = testCaseService.getRecentImportedEntity(importDTO, testStep.getTestCaseId());393 return testCase.isEmpty();394 }395 @Override396 void updateImportedId(TestStep testStep, TestStep previous, BackupDTO importDTO) {397 previous.setImportedId(testStep.getId());398 save(previous);399 }400 private void processTestDataMap(TestStep present, BackupDTO importDTO) {401 TestStepDataMap testStepDataMap = present.getDataMapBean();402 if (testStepDataMap != null) {403 if ((testStepDataMap.getForLoop() != null || testStepDataMap.getWhileCondition() != null)404 && testStepDataMap.getForLoop() != null && testStepDataMap.getForLoop().getTestDataId() != null) {405 Optional<TestData> testData = testDataService.getRecentImportedEntity(importDTO, testStepDataMap.getForLoop().getTestDataId());406 if (testData.isPresent())407 testStepDataMap.getForLoop().setTestDataId(testData.get().getId());408 }409 }410 }411 private void setTemplateId(TestStep present, BackupDTO importDTO) throws ResourceNotFoundException {412 if (!importDTO.getIsSameApplicationType() && present.getNaturalTextActionId() != null && present.getNaturalTextActionId() > 0) {413 try {414 NaturalTextActions nlpTemplate = naturalTextActionsService.findById(present.getNaturalTextActionId().longValue());415 if (importDTO.getWorkspaceType().equals(WorkspaceType.WebApplication)) {416 present.setNaturalTextActionId(nlpTemplate.getImportToWeb().intValue());417 if (nlpTemplate.getImportToWeb().intValue() == 0) {418 present.setDisabled(true);419 }420 } else if (importDTO.getWorkspaceType().equals(WorkspaceType.MobileWeb)) {421 present.setNaturalTextActionId(nlpTemplate.getImportToMobileWeb().intValue());422 if (nlpTemplate.getImportToMobileWeb().intValue() == 0) {423 present.setDisabled(true);424 }425 } else if (importDTO.getWorkspaceType().equals(WorkspaceType.AndroidNative)) {426 present.setNaturalTextActionId(nlpTemplate.getImportToAndroidNative().intValue());427 if (nlpTemplate.getImportToAndroidNative().intValue() == 0) {428 present.setDisabled(true);...
Source:NaturalTextActionsService.java
...24 private final NaturalTextActionsRepository naturalTextActionsRepository;25 public Page<NaturalTextActions> findAll(Specification<NaturalTextActions> spec, Pageable pageable) {26 return naturalTextActionsRepository.findAll(spec, pageable);27 }28 public NaturalTextActions findById(Long naturalTextActionId) {29 return this.naturalTextActionsRepository.findById(naturalTextActionId).orElse(null);30 }31 public List<NaturalTextActions> findByDisplayName(String displayName) {32 return this.naturalTextActionsRepository.findAllByDisplayName(displayName);33 }34}...
findById
Using AI Code Generation
1public class NaturalTextActionsServiceTest {2 public void testFindById() {3 NaturalTextActionsService naturalTextActionsService = new NaturalTextActionsService();4 NaturalTextActions naturalTextActions = naturalTextActionsService.findById(1);5 System.out.println(naturalTextActions);6 }7}8public class NaturalTextActionsServiceTest {9 public void testFindById() {10 NaturalTextActionsService naturalTextActionsService = new NaturalTextActionsService();11 NaturalTextActions naturalTextActions = naturalTextActionsService.findById(1);12 System.out.println(naturalTextActions);13 }14}15public class NaturalTextActionsServiceTest {16 public void testFindById() {17 NaturalTextActionsService naturalTextActionsService = new NaturalTextActionsService();18 NaturalTextActions naturalTextActions = naturalTextActionsService.findById(1);19 System.out.println(naturalTextActions);20 }21}22public class NaturalTextActionsServiceTest {23 public void testFindById() {24 NaturalTextActionsService naturalTextActionsService = new NaturalTextActionsService();25 NaturalTextActions naturalTextActions = naturalTextActionsService.findById(1);26 System.out.println(naturalTextActions);27 }28}29public class NaturalTextActionsServiceTest {30 public void testFindById() {31 NaturalTextActionsService naturalTextActionsService = new NaturalTextActionsService();32 NaturalTextActions naturalTextActions = naturalTextActionsService.findById(1);33 System.out.println(naturalTextActions);34 }35}36public class NaturalTextActionsServiceTest {37 public void testFindById() {38 NaturalTextActionsService naturalTextActionsService = new NaturalTextActionsService();39 NaturalTextActions naturalTextActions = naturalTextActionsService.findById(1);
findById
Using AI Code Generation
1import com.testsigma.service.NaturalTextActionsService;2import com.testsigma.service.NaturalTextActionsService.NaturalTextActionsServiceBuilder;3import com.testsigma.service.NaturalTextActionsService.NaturalTextAction;4import com.testsigma.service.NaturalTextActionsService.NaturalTextActionType;5import com.testsigma.service.NaturalTextActionsService.NaturalTextAction.NaturalTextActionBuilder;6import com.testsigma.service.NaturalTextActionsService.NaturalTextActionType.NaturalTextActionTypeBuilder;7import com.testsigma.service.NaturalTextActionsService.NaturalTextActionType.NaturalTextActionTypeBuilder.NaturalTextActionTypeBuilderBuilder;8import com.testsigma.service.NaturalTextActionsService.NaturalTextActionType.NaturalTextActionTypeBuilder.NaturalTextActionTypeBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilder;9import com.testsigma.service.NaturalTextActionsService.NaturalTextActionType.NaturalTextActionTypeBuilder.NaturalTextActionTypeBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilder;10import com.testsigma.service.NaturalTextActionsService.NaturalTextActionType.NaturalTextActionTypeBuilder.NaturalTextActionTypeBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilderBuilder;11import com.testsigma.service.NaturalTextActionsService.NaturalTextActionType.NaturalTextActionTypeBuilder.NaturalTextActionTypeBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilderBuilderBuilder;12import com.testsigma.service.NaturalTextActionsService.NaturalTextActionType.NaturalTextActionTypeBuilder.NaturalTextActionTypeBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilderBuilderBuilderBuilder;13import com.testsigma.service.NaturalTextActionsService.NaturalTextActionType.NaturalTextActionTypeBuilder.NaturalTextActionTypeBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilderBuilder.NaturalTextActionTypeBuilderBuilderBuilderBuilderBuilderBuilder;14import com.testsigma.service.NaturalText
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!!