Best Testsigma code snippet using com.testsigma.service.TestStepService.publishEvent
Source:TestCaseService.java
...145 return testCase;146 }147 public TestCase create(TestCase testCaseRequest) {148 TestCase testCase = testCaseRepository.save(testCaseRequest);149 publishEvent(testCase, EventType.CREATE);150 return testCase;151 }152 public TestCase update(TestCase testCase) {153 testCase = this.testCaseRepository.save(testCase);154 publishEvent(testCase, EventType.UPDATE);155 return testCase;156 }157 public TestCase update(TestCaseRequest testCaseRequest, Long id) throws TestsigmaException, SQLException {158 TestCase testCase = testCaseRepository.findById(id).get();159 Long oldPreRequisite = testCase.getPreRequisite();160 testCase.setUpdatedDate(new Timestamp(Calendar.getInstance().getTimeInMillis()));161 setStatusTimeAndBy(testCaseRequest, testCase);162 testCaseMapper.map(testCaseRequest, testCase);163 List<Long> preReqList = new ArrayList<>();164 preReqList.add(testCase.getId());165 validatePreRequisiteIsValid(testCase, preReqList);166 testCase = update(testCase);167 if (testCaseRequest.getTags() != null) {168 tagService.updateTags(testCaseRequest.getTags(), TagType.TEST_CASE, testCase.getId());169 }170 if (testCase.getPreRequisite() != null && !testCase.getPreRequisite().equals(oldPreRequisite)){171 testSuiteService.handlePreRequisiteChange(testCase);172 }173 return testCase;174 }175 private void validatePreRequisiteIsValid(TestCase testCase, List<Long> preReqList) throws TestsigmaException {176 Long preRequisiteId = testCase.getPreRequisite();177 if (preRequisiteId != null) {178 if (preReqList.size() > 5) {179 log.debug("Testcase Prerequisite hierarchy is more than 5,Prerequisite IDs:" + preReqList);180 throw new TestsigmaException("Prerequisite hierarchy crossed the allowed limit of 5");181 } else if (preReqList.contains(testCase.getPreRequisite())) {182 log.debug("Cyclic dependency for Testsuite prerequisites found for Testsuite:" + testCase);183 throw new TestsigmaException("Prerequisite to the TestCase is not valid. This prerequisite causes cyclic dependencies for TestCase.");184 }185 preReqList.add(preRequisiteId);186 TestCase preRequisiteTestCase = find(preRequisiteId);187 if (preRequisiteTestCase.getPreRequisite() != null) {188 validatePreRequisiteIsValid(preRequisiteTestCase, preReqList);189 }190 } else {191 return;192 }193 }194 //TODO:need to revisit this code[chandra]195 private void setStatusTimeAndBy(TestCaseRequest testCaseRequest, TestCase testcase) throws ResourceNotFoundException, TestsigmaDatabaseException, SQLException {196 TestCaseStatus status = testCaseRequest.getStatus();197 Timestamp at = new Timestamp(System.currentTimeMillis());198 if (status.equals(TestCaseStatus.DRAFT)) {199 testCaseRequest.setDraftAt(at);200 } else if (status.equals(TestCaseStatus.IN_REVIEW)) {201 if (!testcase.getStatus().equals(TestCaseStatus.IN_REVIEW)) {202 testCaseRequest.setReviewSubmittedAt(at);203 }204 } else if (status.equals(TestCaseStatus.READY)) {205 if (testcase.getStatus().equals(TestCaseStatus.IN_REVIEW)) {206 testCaseRequest.setReviewedAt(at);207 }208 } else if (status.equals(TestCaseStatus.OBSOLETE)) {209 testCaseRequest.setObsoleteAt(at);210 }211 }212 public Integer markAsDelete(List<Long> ids) {213 return testCaseRepository.markAsDelete(ids);214 }215 public void restore(Long id) {216 testCaseRepository.markAsRestored(id);217 }218 public void destroy(Long id) throws ResourceNotFoundException {219 TestCase testcase = this.find(id);220 testCaseRepository.delete(testcase);221 publishEvent(testcase, EventType.DELETE);222 }223 public Long automatedCountByVersion(Long versionId) {224 return this.testCaseRepository.countByVersion(versionId);225 }226 public Long testCaseCountByPreRequisite(Long testCaseId){227 return this.testCaseRepository.countByPreRequisite(testCaseId);228 }229 public List<Long> getTestCaseIdsByPreRequisite(Long testCaseId){230 return this.testCaseRepository.getTestCaseIdsByPreRequisite(testCaseId);231 }232 public List<TestCaseStatusBreakUpDTO> breakUpByStatus(Long versionId) {233 return this.testCaseRepository.breakUpByStatus(versionId);234 }235 public List<TestCaseTypeBreakUpDTO> breakUpByType(Long versionId) {236 return this.testCaseRepository.breakUpByType(versionId);237 }238 public TestCase copy(TestCaseCopyRequest testCaseRequest) throws ResourceNotFoundException, SQLException {239 TestCase parentCase = this.find(testCaseRequest.getTestCaseId());240 TestCase testCase = this.testCaseMapper.copy(parentCase);241 testCase.setStatus(parentCase.getStatus());242 testCase.setName(testCaseRequest.getName());243 testCase.setCreatedDate(new Timestamp(Calendar.getInstance().getTimeInMillis()));244 testCase.setLastRunId(null);245 if (testCaseRequest.getIsStepGroup()) {246 testCase.setTestDataStartIndex(null);247 testCase.setTestDataId(null);248 testCase.setIsDataDriven(false);249 }250 testCase.setIsStepGroup(testCaseRequest.getIsStepGroup());251 testCase.setCopiedFrom(parentCase.getId());252 testCase.setPreRequisiteCase(null);253 testCase = create(testCase);254 List<String> tags = tagService.list(TagType.TEST_CASE, parentCase.getId());255 tagService.updateTags(tags, TagType.TEST_CASE, testCase.getId());256 List<TestStep> steps = this.fetchTestSteps(parentCase, testCaseRequest.getStepIds());257 List<TestStep> newSteps = new ArrayList<>();258 Map<Long, TestStep> parentStepIds = new HashMap<Long, TestStep>();259 Integer position = 0;260 TestStep firstStep = steps.get(0);261 if(firstStep.getConditionType() == TestStepConditionType.LOOP_WHILE){262 TestStep whileStep = this.testStepService.find(firstStep.getParentId());263 steps.add(0, whileStep);264 }265 for (TestStep parent : steps) {266 if (testCase.getIsStepGroup() && parent.getStepGroupId() != null)267 continue;268 TestStep step = this.testStepMapper.copy(parent);269 step.setPosition(position);270 step.setCreatedDate(new Timestamp(Calendar.getInstance().getTimeInMillis()));271 step.setTestCaseId(testCase.getId());272 TestStep parentStep = parentStepIds.get(parent.getParentId());273 step.setParentId(parentStep != null ? parentStep.getId() : null);274 TestStep prerequiste = parentStepIds.get(parentStep != null ? parent.getPreRequisiteStepId() : null);275 step.setPreRequisiteStepId(prerequiste != null ? prerequiste.getId() : null);276 step.setId(null);277 step.setParentStep(parentStep);278 step = this.testStepService.create(step);279 parentStepIds.put(parent.getId(), step);280 newSteps.add(step);281 position++;282 }283 return testCase;284 }285 private List<TestStep> fetchTestSteps(TestCase testCase, List<Long> stepIds) {286 if (stepIds != null)287 return this.testStepService.findAllByTestCaseIdAndIdIn(testCase.getId(), stepIds);288 else289 return this.testStepService.findAllByTestCaseId(testCase.getId());290 }291 public void publishEvent(TestCase testCase, EventType eventType) {292 TestCaseEvent<TestCase> event = createEvent(testCase, eventType);293 log.info("Publishing event - " + event.toString());294 applicationEventPublisher.publishEvent(event);295 }296 public TestCaseEvent<TestCase> createEvent(TestCase testCase, EventType eventType) {297 TestCaseEvent<TestCase> event = new TestCaseEvent<>();298 event.setEventData(testCase);299 event.setEventType(eventType);300 return event;301 }302 public void export(BackupDTO backupDTO) throws IOException, ResourceNotFoundException {303 if (!backupDTO.getIsTestCaseEnabled()) return;304 log.debug("backup process for testcase initiated");305 writeXML("testcases", backupDTO, PageRequest.of(0, 25));306 log.debug("backup process for testcase completed");307 }308 public Specification<TestCase> getExportXmlSpecification(BackupDTO backupDTO) throws ResourceNotFoundException {...
Source:ElementService.java
...66 }67 public Element create(Element element) {68 element = this.save(element);69 this.markAsDuplicated(element);70 publishEvent(element, EventType.CREATE);71 return element;72 }73 public Element update(Element element, String oldName, String previousLocatorValue, LocatorType previousLocatorType, Long previousScreenNameId)74 throws ResourceNotFoundException {75 element = this.save(element);76 if (!Objects.equals(element.getLocatorValue(), previousLocatorValue) || element.getLocatorType() != previousLocatorType77 || !Objects.equals(element.getScreenNameId(), previousScreenNameId)) {78 this.markAsDuplicated(element);79 this.resetDuplicate(element.getWorkspaceVersionId(), previousLocatorValue, previousLocatorType, previousScreenNameId);80 }81 this.eventCallForUpdate(oldName, element);82 return element;83 }84 public Element update(Element element, String oldName) {85 element = this.save(element);86 this.eventCallForUpdate(oldName, element);87 return element;88 }89 public void delete(Element element) {90 elementRepository.delete(element);91 this.resetDuplicate(element.getWorkspaceVersionId(), element.getLocatorValue(), element.getLocatorType(), element.getScreenNameId());92 publishEvent(element, EventType.DELETE);93 }94 public void bulkDelete(Long[] ids, Long workspaceVersionId) throws Exception {95 Boolean allIdsDeleted = true;96 TestCaseSpecificationsBuilder builder = new TestCaseSpecificationsBuilder();97 for (Long id : ids) {98 List<SearchCriteria> params = new ArrayList<>();99 Element element = this.find(id);100 params.add(new SearchCriteria("element", SearchOperation.EQUALITY, element.getName()));101 params.add(new SearchCriteria("workspaceVersionId", SearchOperation.EQUALITY, workspaceVersionId));102 builder.setParams(params);103 Specification<TestCase> spec = builder.build();104 Page<TestCase> linkedTestCases = testCaseService.findAll(spec, PageRequest.of(0, 1));105 if (linkedTestCases.getTotalElements() == 0) {106 this.delete(element);107 } else {108 allIdsDeleted = false;109 }110 }111 if (!allIdsDeleted) {112 throw new DataIntegrityViolationException("dataIntegrityViolationException: Failed to delete some of the Elements " +113 "since they are already associated to some Test Cases.");114 }115 }116 public void bulkUpdateScreenNameAndTags(Long[] ids, String screenName, String[] tags) throws ResourceNotFoundException {117 for (Long id : ids) {118 Element element = find(id);119 if (screenName.length() > 0) {120 ElementScreenNameRequest elementScreenNameRequest = new ElementScreenNameRequest();121 elementScreenNameRequest.setName(screenName);122 elementScreenNameRequest.setWorkspaceVersionId(element.getWorkspaceVersionId());123 ElementScreenName elementScreenName = screenNameService.save(elementScreenNameRequest);124 element.setScreenNameId(elementScreenName.getId());125 }126 update(element, element.getName(), element.getLocatorValue(), element.getLocatorType(), element.getScreenNameId());127 tagService.updateTags(Arrays.asList(tags), TagType.ELEMENT, id);128 }129 }130 public void updateByName(String name, ElementRequest elementRequest) {131 Element element = findByNameAndVersionId(name, elementRequest.getWorkspaceVersionId());132 String oldName = element.getName();133 elementMapper.merge(elementRequest, element);134 update(element, oldName);135 }136 public void publishEvent(Element element, EventType eventType) {137 ElementEvent<Element> event = createEvent(element, eventType);138 log.info("Publishing event - " + event.toString());139 applicationEventPublisher.publishEvent(event);140 }141 public ElementEvent<Element> createEvent(Element element, EventType eventType) {142 ElementEvent<Element> event = new ElementEvent<>();143 event.setEventData(element);144 event.setEventType(eventType);145 return event;146 }147 public void export(BackupDTO backupDTO) throws IOException, ResourceNotFoundException {148 if (!backupDTO.getIsElementEnabled()) return;149 log.debug("backup process for element initiated");150 writeXML("elements", backupDTO, PageRequest.of(0, 25));151 log.debug("backup process for element completed");152 }153 public Specification<Element> getExportXmlSpecification(BackupDTO backupDTO) {154 SearchCriteria criteria = new SearchCriteria("workspaceVersionId", SearchOperation.EQUALITY, backupDTO.getWorkspaceVersionId());155 List<SearchCriteria> params = new ArrayList<>();156 params.add(criteria);157 ElementSpecificationsBuilder elementSpecificationsBuilder = new ElementSpecificationsBuilder();158 elementSpecificationsBuilder.params = params;159 return elementSpecificationsBuilder.build();160 }161 @Override162 protected List<ElementXMLDTO> mapToXMLDTOList(List<Element> list) {163 return elementMapper.mapElements(list);164 }165 private void eventCallForUpdate(String oldName, Element element){166 if (!oldName.equals(element.getName())) {167 testStepService.updateElementName(oldName, element.getName());168 testStepService.updateAddonElementsName(oldName, element.getName());169 }170 publishEvent(element, EventType.UPDATE);171 }172 public List<Element> findAllMatchedElements(Long applicationVersionId, String definition,173 LocatorType locatorType, Long screenNameId, Boolean duplicatedStatus) {174 return this.elementRepository.findAllMatchedElements(applicationVersionId, definition, locatorType, screenNameId, duplicatedStatus);175 }176 public List<Element> findAllMatchedElements(Long applicationVersionId, String definition,177 LocatorType locatorType, Long screenNameId) {178 return this.elementRepository.findAllMatchedElements(applicationVersionId, definition, locatorType, screenNameId);179 }180 private void markAsDuplicated(Element element) {181 List<Element> matchedElements = this.findAllMatchedElements182 (element.getWorkspaceVersionId(), element.getLocatorValue(), element.getLocatorType(),183 element.getScreenNameId());184 if(matchedElements.size() == 1){...
publishEvent
Using AI Code Generation
1import com.testsigma.service.TestStepService;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.support.FindBy;5import org.openqa.selenium.support.How;6import org.openqa.selenium.support.PageFactory;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9public class Page {10 private final TestStepService testStepService = new TestStepService();11 @FindBy(how = How.ID, using = "id")12 private WebElement element;13 private final WebDriver driver;14 public Page(WebDriver driver) {15 this.driver = driver;16 PageFactory.initElements(driver, this);17 }18 public void clickOnElement() {19 WebDriverWait wait = new WebDriverWait(driver, 10);20 wait.until(ExpectedConditions.elementToBeClickable(element));21 testStepService.publishEvent("Clicking on element");22 element.click();23 }24}25import com.testsigma.service.TestStepService;26import org.openqa.selenium.WebDriver;27import org.openqa.selenium.WebElement;28import org.openqa.selenium.support.FindBy;29import org.openqa.selenium.support.How;30import org.openqa.selenium.support.PageFactory;31import org.openqa.selenium.support.ui.ExpectedConditions;32import org.openqa.selenium.support.ui.WebDriverWait;33public class Page {34 private final TestStepService testStepService = new TestStepService();35 @FindBy(how = How.ID, using = "id")36 private WebElement element;37 private final WebDriver driver;38 public Page(WebDriver driver) {39 this.driver = driver;40 PageFactory.initElements(driver, this);41 }42 public void clickOnElement() {43 WebDriverWait wait = new WebDriverWait(driver, 10);44 wait.until(ExpectedConditions.elementToBeClickable(element));45 testStepService.publishEvent("Clicking on element");46 element.click();47 }48}49import com.testsigma.service.TestStepService;50import org.openqa.selenium.WebDriver;51import org.openqa.selenium.WebElement;52import org.openqa.selenium.support.FindBy;53import org.openqa.selenium.support.How;54import org.openqa.selenium.support.PageFactory;55import org.openqa.selenium.support.ui.ExpectedConditions;56import org.openqa.selenium.support.ui.WebDriverWait;57public class Page {58 private final TestStepService testStepService = new TestStepService();59 @FindBy(how = How.ID, using
publishEvent
Using AI Code Generation
1import com.testsigma.service.TestStepService;2import com.testsigma.service.TestStepServiceFactory;3import com.testsigma.service.TestStepServiceFactoryImpl;4import com.testsigma.service.TestStepServiceException;5import com.testsigma.service.TestStepServiceFactory;6import com.testsigma.service.TestStepServiceFactoryImpl;7import com.testsigma.service.TestStepServiceException;8import com.testsigma.service.TestStepService;9import com.testsigma.service.TestStepServiceFactory;10import com.testsigma.service.TestStepServiceFactoryImpl;11import com.testsigma.service.TestStepServiceException;12import com.testsigma.service.TestStepServiceFactory;13import com.testsigma.service.TestStepServiceFactoryImpl;14import com.testsigma.service.TestStepServiceException;15import com.testsigma.service.TestStepService;16import com.testsigma.service.TestStepServiceFactory;17import com.testsigma.service.TestStepServiceFactoryImpl;18import com.testsigma.service.TestStepServiceException;19import com.testsigma.service.TestStepServiceFactory;20import com.testsigma.service.TestStepServiceFactoryImpl;21import com.testsigma.service.TestStepServiceException;22import com.testsigma.service.TestStepService;23import com.testsigma.service.TestStepServiceFactory;24import com.testsigma.service.TestStepServiceFactoryImpl;25import com.testsigma.service.TestStepServiceException;26import com.testsigma.service.TestStepServiceFactory;27import com.testsigma.service.TestStepServiceFactoryImpl;28import com.testsigma.service.TestStepServiceException;29import com.testsigma.service.TestStepService;30import com.testsigma.service.TestStepServiceFactory;31import com.testsigma.service.TestStepServiceFactoryImpl;32import com.testsigma.service.TestStepServiceException;33import com.testsigma.service.TestStepServiceFactory;34import com.testsigma.service.TestStepServiceFactoryImpl;35import com.testsigma.service.TestStepServiceException;36import com.testsigma.service.TestStepService;37import com.testsigma.service.TestStepServiceFactory;38import com.testsigma.service.TestStepServiceFactoryImpl;39import com.testsigma.service.TestStepServiceException;40import com.testsigma.service.TestStepServiceFactory;41import com.testsigma.service.TestStepServiceFactoryImpl;42import com.testsigma.service.TestStepServiceException;43import com.testsigma.service.TestStepService;44import com.testsigma.service.TestStepServiceFactory;45import com.testsigma.service.TestStepServiceFactoryImpl;46import com.testsigma.service.TestStepServiceException;47import com.testsigma.service.TestStepServiceFactory;48import com.testsigma.service.TestStepServiceFactoryImpl;49import com.testsigma.service.TestStepServiceException;50import
publishEvent
Using AI Code Generation
1import com.testsigma.service.TestStepService;2public class TestStepServiceExample {3 public static void main(String[] args) {4 TestStepService testStepService = new TestStepService();5 testStepService.publishEvent("testStepName", "testStepStatus", "testStepMessage");6 }7}8import com.testsigma.service.TestStepService;9public class TestStepServiceExample {10 public static void main(String[] args) {11 TestStepService testStepService = new TestStepService();12 testStepService.publishEvent("testStepName", "testStepStatus", "testStepMessage", "testStepScreenshot");13 }14}15import com.testsigma.service.TestStepService;16public class TestStepServiceExample {17 public static void main(String[] args) {18 TestStepService testStepService = new TestStepService();19 testStepService.publishEvent("testStepName", "testStepStatus", "testStepMessage", "testStepScreenshot", "testStepAttachment");20 }21}22import com.testsigma.service.TestStepService;23public class TestStepServiceExample {24 public static void main(String[] args) {25 TestStepService testStepService = new TestStepService();26 testStepService.publishEvent("testStepName", "testStepStatus", "testStepMessage", "testStepScreenshot", "testStepAttachment", "testStepStartTime", "testStepEndTime");27 }28}29import com.testsigma.service.TestStepService;30public class TestStepServiceExample {31 public static void main(String[] args) {32 TestStepService testStepService = new TestStepService();33 testStepService.publishEvent("testStepName", "testStepStatus", "testStepMessage", "testStepScreenshot", "testStepAttachment", "testStepStartTime", "testStepEndTime", "testStepDuration");34 }35}36import com.test
publishEvent
Using AI Code Generation
1package com.testsigma.test;2import com.testsigma.service.TestStepService;3import com.testsigma.service.TestSuiteService;4import java.util.HashMap;5import java.util.Map;6public class TestPublishEvent {7 public static void main(String[] args) {8 TestSuiteService testSuiteService = new TestSuiteService();9 TestStepService testStepService = new TestStepService();10 Map<String, String> map = new HashMap<String, String>();11 map.put("key1", "value1");12 map.put("key2", "value2");13 map.put("key3", "value3");14 testStepService.publishEvent("event1", map);15 testSuiteService.publishEvent("event2", map);16 }17}18package com.testsigma.test;19import com.testsigma.service.TestStepService;20import com.testsigma.service.TestSuiteService;21import java.util.HashMap;22import java.util.Map;23public class TestPublishEvent {24 public static void main(String[] args) {25 TestSuiteService testSuiteService = new TestSuiteService();26 TestStepService testStepService = new TestStepService();27 Map<String, String> map = new HashMap<String, String>();28 map.put("key1", "value1");29 map.put("key2", "value2");30 map.put("key3", "value3");31 testStepService.publishEvent("event1", map);32 testSuiteService.publishEvent("event2", map);33 }34}35package com.testsigma.test;36import com.testsigma.service.TestStepService;37import com.testsigma.service.TestSuiteService;38import java.util.HashMap;39import java.util.Map;40public class TestPublishEvent {41 public static void main(String[] args) {42 TestSuiteService testSuiteService = new TestSuiteService();43 TestStepService testStepService = new TestStepService();44 Map<String, String> map = new HashMap<String, String>();45 map.put("key1", "value1");46 map.put("key2", "value2");47 map.put("key3", "value3");48 testStepService.publishEvent("event1", map);49 testSuiteService.publishEvent("event2", map);50 }51}
publishEvent
Using AI Code Generation
1import com.testsigma.service.TestStepService;2import com.testsigma.service.TestStepServiceFactory;3import org.apache.camel.Exchange;4import org.apache.camel.Processor;5import org.apache.camel.builder.RouteBuilder;6import org.apache.camel.impl.DefaultCamelContext;7import org.apache.camel.impl.DefaultExchange;8import org.apache.camel.impl.DefaultProducerTemplate;9import org.apache.camel.impl.SimpleRegistry;10import org.apache.camel.spi.Registry;11import org.apache.camel.test.junit4.CamelTestSupport;12import org.junit.Test;13public class TestStepServiceTest extends CamelTestSupport {14 public void testPublishEvent() throws Exception {15 Registry registry = new SimpleRegistry();16 registry.put("testStepService", new TestStepService());17 DefaultCamelContext context = new DefaultCamelContext(registry);18 context.start();19 DefaultProducerTemplate template = context.createProducerTemplate();20 Exchange exchange = new DefaultExchange(context);21 exchange.getIn().setBody("Hello World");22 template.send("direct:hello", exchange);23 context.stop();24 }25 protected RouteBuilder createRouteBuilder() throws Exception {26 return new RouteBuilder() {27 public void configure() throws Exception {28 from("direct:hello")29 .process(new Processor() {30 public void process(Exchange exchange) throws Exception {31 TestStepService testStepService = TestStepServiceFactory.getTestStepService();32 testStepService.publishEvent("Hello World");33 }34 });35 }36 };37 }38}39import com.testsigma.service.TestStepService;40import com.testsigma.service.TestStepServiceFactory;41import org.apache.camel.Exchange;42import org.apache.camel.Processor;43import org.apache.camel.builder.RouteBuilder;44import org.apache.camel.impl.DefaultCamelContext;45import org.apache.camel.impl.DefaultExchange;46import org
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!!