How to use TestSuiteEvent class of com.testsigma.event package

Best Testsigma code snippet using com.testsigma.event.TestSuiteEvent

Source:TestSuiteService.java Github

copy

Full Screen

...7package com.testsigma.service;8import com.testsigma.dto.BackupDTO;9import com.testsigma.dto.export.TestSuiteXMLDTO;10import com.testsigma.event.EventType;11import com.testsigma.event.TestSuiteEvent;12import com.testsigma.exception.ResourceNotFoundException;13import com.testsigma.exception.TestsigmaException;14import com.testsigma.mapper.TestSuiteMapper;15import com.testsigma.model.*;16import com.testsigma.repository.SuiteTestCaseMappingRepository;17import com.testsigma.repository.TagRepository;18import com.testsigma.repository.TestSuiteRepository;19import com.testsigma.specification.SearchCriteria;20import com.testsigma.specification.SearchOperation;21import com.testsigma.specification.TestPlanSpecificationsBuilder;22import com.testsigma.specification.TestSuiteSpecificationsBuilder;23import lombok.Data;24import lombok.RequiredArgsConstructor;25import lombok.extern.log4j.Log4j2;26import org.springframework.beans.factory.annotation.Autowired;27import org.springframework.context.ApplicationEventPublisher;28import org.springframework.dao.DataIntegrityViolationException;29import org.springframework.data.domain.Page;30import org.springframework.data.domain.PageRequest;31import org.springframework.data.domain.Pageable;32import org.springframework.data.jpa.domain.Specification;33import org.springframework.stereotype.Service;34import java.io.IOException;35import java.util.ArrayList;36import java.util.List;37import java.util.Optional;38import java.util.stream.Collectors;39@Log4j240@Service41@Data42@RequiredArgsConstructor(onConstructor = @__(@Autowired))43public class TestSuiteService extends XMLExportService<TestSuite> {44 private final TestSuiteRepository repository;45 private final TagRepository tagRepository;46 private final TagService tagService;47 private final SuiteTestCaseMappingService suiteTestCaseMappingService;48 private final SuiteTestCaseMappingRepository suiteTestCaseMappingRepository;49 private final TestPlanService testPlanService;50 private final ApplicationEventPublisher applicationEventPublisher;51 private final TestDeviceSuiteService suiteMappingService;52 private final TestSuiteMapper mapper;53 public Page<TestSuite> findAll(Specification spec, Pageable pageble) {54 return repository.findAll(spec, pageble);55 }56 public List<AbstractTestSuite> findAllByTestDeviceId(Long environmentId) {57 return this.repository.findAllByTestDeviceId(environmentId);58 }59 public List<TestSuite> findByPrerequisiteId(Long prerequisite) {60 return this.repository.findAllByPreRequisite(prerequisite);61 }62 public TestSuite find(Long id) throws ResourceNotFoundException {63 return this.repository.findById(id)64 .orElseThrow(() -> new ResourceNotFoundException(65 "TestSuite Resource not found with id:" + id));66 }67 public TestSuite create(TestSuite testSuite) throws TestsigmaException {68 List<String> tagNames = testSuite.getTags();69 List<Long> testCaseIds = testSuite.getTestCaseIds();70 testSuite.setTags(tagNames);71 List<Long> prereq = new ArrayList<>();72 prereq.add(testSuite.getId());73 validatePreRequisiteIsValid(testSuite, prereq);74 testSuite = this.repository.save(testSuite);75 testSuite.setTestCaseIds(testCaseIds);76 tagService.updateTags(testSuite.getTags(), TagType.TEST_SUITE, testSuite.getId());77 this.handleTestCaseMappings(testSuite);78 publishEvent(testSuite, EventType.CREATE);79 return testSuite;80 }81 public TestSuite update(TestSuite testSuite) throws TestsigmaException {82 List<Long> testCaseIds = testSuite.getTestCaseIds();83 List<String> tagNames = testSuite.getTags();84 List<Long> prereq = new ArrayList<>();85 prereq.add(testSuite.getId());86 validatePreRequisiteIsValid(testSuite, prereq);87 testSuite = this.repository.save(testSuite);88 testSuite.setTestCaseIds(testCaseIds);89 testSuite.setTags(tagNames);90 if (testSuite.getTags() != null)91 tagService.updateTags(testSuite.getTags(), TagType.TEST_SUITE, testSuite.getId());92 this.handleTestCaseMappings(testSuite);93 publishEvent(testSuite, EventType.UPDATE);94 return testSuite;95 }96 public void handlePrequisiteChange(TestSuite testSuite){97 this.suiteMappingService.handlePreRequisiteChange(testSuite);98 }99 private void validatePreRequisiteIsValid(TestSuite testSuite, List<Long> preReqList) throws TestsigmaException {100 Long preRequsiteId = testSuite.getPreRequisite();101 if (preRequsiteId != null) {102 if (preReqList.size() > 5) {103 log.debug("Testsuite Prerequisite hierarchy is more than 5,Prerequisite IDs:" + preReqList);104 throw new TestsigmaException("Prerequisite hierarchy crossed the allowed limit of 5");105 } else if (preReqList.contains(testSuite.getPreRequisite())) {106 log.debug("Cyclic dependency for Testsuite prerequisites found for Testsuite:" + testSuite);107 throw new TestsigmaException("Prerequisite to the Testsuite is not valid. This prerequisite causes cyclic dependencies for Testsuites.");108 }109 preReqList.add(preRequsiteId);110 TestSuite preReqTestSuite = find(preRequsiteId);111 if (preReqTestSuite.getPreRequisite() != null) {112 validatePreRequisiteIsValid(preReqTestSuite, preReqList);113 }114 } else {115 return;116 }117 }118 public TestSuite updateSuite(TestSuite testSuite) {119 testSuite = this.repository.save(testSuite);120 publishEvent(testSuite, EventType.UPDATE);121 return testSuite;122 }123 public void destroy(Long id) throws ResourceNotFoundException {124 TestSuite testSuite = this.find(id);125 publishEvent(testSuite, EventType.DELETE);126 this.repository.deleteById(id);127 }128 public void handleTestCaseMappings(TestSuite testSuite) {129 int position = 0;130 List<SuiteTestCaseMapping> newMappings = new ArrayList<>();131 List<SuiteTestCaseMapping> updatedMappings = new ArrayList<>();132 this.cleanupOrphanCaseMappings(testSuite);133 List<SuiteTestCaseMapping> mappings = this.suiteTestCaseMappingRepository.findBySuiteIdAndTestCaseIds(testSuite.getId(), testSuite.getTestCaseIds());134 for (Long testCaseId : testSuite.getTestCaseIds()) {135 SuiteTestCaseMapping suiteTestCaseMapping = new SuiteTestCaseMapping();136 Optional<SuiteTestCaseMapping> existing = mappings.stream().filter(mapping -> mapping.getTestCaseId().equals(testCaseId)).findFirst();137 position++;138 if (existing.isPresent()) {139 suiteTestCaseMapping = existing.get();140 if (!suiteTestCaseMapping.getPosition().equals(position)) {141 suiteTestCaseMapping.setPosition(position);142 suiteTestCaseMapping = this.suiteTestCaseMappingService.update(suiteTestCaseMapping);143 updatedMappings.add(suiteTestCaseMapping);144 }145 } else {146 suiteTestCaseMapping.setSuiteId(testSuite.getId());147 suiteTestCaseMapping.setTestCaseId(testCaseId);148 suiteTestCaseMapping.setPosition(position);149 suiteTestCaseMapping = this.suiteTestCaseMappingService.add(suiteTestCaseMapping);150 newMappings.add(suiteTestCaseMapping);151 }152 }153 testSuite.setUpdatedTestCases(updatedMappings);154 testSuite.setAddedTestCases(newMappings);155 }156 private void cleanupOrphanCaseMappings(TestSuite testSuite) {157 List<SuiteTestCaseMapping> suiteTestCaseMappings = this.suiteTestCaseMappingService.findAllBySuiteId(testSuite.getId());158 List<Long> existingCaseIds = suiteTestCaseMappings.stream().map(SuiteTestCaseMapping::getTestCaseId).collect(Collectors.toList());159 existingCaseIds.removeAll(testSuite.getTestCaseIds());160 if (existingCaseIds.size() > 0) {161 this.deleteAllBySuiteIdAndCaseIds(testSuite, existingCaseIds);162 List<Long> testCaseIds = testSuite.getTestCaseIds();163 testCaseIds.removeAll(existingCaseIds);164 testSuite.setTestCaseIds(testCaseIds);165 }166 }167 private void deleteAllBySuiteIdAndCaseIds(TestSuite suite, List<Long> existingCaseIds) {168 List<SuiteTestCaseMapping> mappings = this.suiteTestCaseMappingRepository.findBySuiteIdAndTestCaseIds(suite.getId(), existingCaseIds);169 suite.setRemovedTestCases(mappings);170 this.suiteTestCaseMappingService.deleteAll(mappings);171 }172 public void bulkDelete(Long[] ids) throws Exception {173 Boolean allIdsDeleted = true;174 TestPlanSpecificationsBuilder builder = new TestPlanSpecificationsBuilder();175 for (Long id : ids) {176 List<SearchCriteria> params = new ArrayList<>();177 params.add(new SearchCriteria("suiteId", SearchOperation.EQUALITY, id));178 builder.setParams(params);179 Specification<TestPlan> spec = builder.build();180 Page<TestPlan> linkedTestPlans = testPlanService.findAll(spec, PageRequest.of(0, 1));181 if (linkedTestPlans.getTotalElements() == 0) {182 this.destroy(id);183 } else {184 allIdsDeleted = false;185 }186 }187 if (!allIdsDeleted) {188 throw new DataIntegrityViolationException("dataIntegrityViolationException");189 }190 }191 public void publishEvent(TestSuite testSuite, EventType eventType) {192 TestSuiteEvent<TestSuite> event = createEvent(testSuite, eventType);193 log.info("Publishing event - " + event.toString());194 applicationEventPublisher.publishEvent(event);195 }196 public TestSuiteEvent<TestSuite> createEvent(TestSuite testSuite, EventType eventType) {197 TestSuiteEvent<TestSuite> event = new TestSuiteEvent<>();198 event.setEventData(testSuite);199 event.setEventType(eventType);200 return event;201 }202 public void export(BackupDTO backupDTO) throws IOException, ResourceNotFoundException {203 if (!backupDTO.getIsSuitesEnabled()) return;204 writeXML("test_suites", backupDTO, PageRequest.of(0, 25));205 }206 public Specification<TestSuite> getExportXmlSpecification(BackupDTO backupDTO) {207 SearchCriteria criteria = new SearchCriteria("workspaceVersionId", SearchOperation.EQUALITY, backupDTO.getWorkspaceVersionId());208 List<SearchCriteria> params = new ArrayList<>();209 params.add(criteria);210 TestSuiteSpecificationsBuilder testStepSpecificationsBuilder = new TestSuiteSpecificationsBuilder();211 testStepSpecificationsBuilder.params = params;...

Full Screen

Full Screen

Source:TestSuiteEventListener.java Github

copy

Full Screen

1package com.testsigma.os.stats.listener;2import com.testsigma.event.EventType;3import com.testsigma.event.TestSuiteEvent;4import com.testsigma.exception.TestsigmaException;5import com.testsigma.model.TestSuite;6import com.testsigma.os.stats.service.TestsigmaOsStatsService;7import lombok.RequiredArgsConstructor;8import lombok.extern.log4j.Log4j2;9import org.springframework.beans.factory.annotation.Autowired;10import org.springframework.context.event.EventListener;11import org.springframework.stereotype.Component;12@Log4j213@Component14@RequiredArgsConstructor(onConstructor = @__(@Autowired))15public class TestSuiteEventListener {16 private final TestsigmaOsStatsService testsigmaOsStatsService;17 @EventListener(classes = TestSuiteEvent.class)18 public void OnTestSuiteEvent(TestSuiteEvent<TestSuite> event) {19 log.info("Caught TestSuiteEvent - " + event);20 try {21 if (event.getEventType() == EventType.CREATE) {22 testsigmaOsStatsService.sendTestSuiteStats(event.getEventData(), com.testsigma.os.stats.event.EventType.CREATE);23 } else if (event.getEventType() == EventType.DELETE) {24 testsigmaOsStatsService.sendTestSuiteStats(event.getEventData(), com.testsigma.os.stats.event.EventType.DELETE);25 }26 } catch (TestsigmaException e) {27 log.error(e.getMessage(), e);28 }29 }30}...

Full Screen

Full Screen

TestSuiteEvent

Using AI Code Generation

copy

Full Screen

1package com.testsigma.event.test;2import java.util.ArrayList;3import java.util.List;4import org.testng.Assert;5import org.testng.annotations.Test;6import com.testsigma.event.TestSuiteEvent;7import com.testsigma.event.TestSuiteEventListener;8public class TestSuiteEventTest {9 public void test() {10 TestSuiteEvent event = new TestSuiteEvent();11 List<TestSuiteEventListener> listeners = new ArrayList<TestSuiteEventListener>();12 listeners.add(new TestSuiteEventListener() {13 public void onTestSuiteStart() {14 System.out.println("Test Suite Start");15 }16 public void onTestSuiteEnd() {17 System.out.println("Test Suite End");18 }19 });20 event.addListener(listeners);21 event.fireTestSuiteStart();22 event.fireTestSuiteEnd();23 Assert.assertTrue(true);24 }25}26package com.testsigma.event.test;27import org.testng.Assert;28import org.testng.annotations.Test;29import com.testsigma.event.TestSuiteEvent;30import com.testsigma.event.TestSuiteEventListener;31public class TestSuiteEventTest2 {32 public void test() {33 TestSuiteEvent event = new TestSuiteEvent();34 List<TestSuiteEventListener> listeners = new ArrayList<TestSuiteEventListener>();35 listeners.add(new TestSuiteEventListener() {36 public void onTestSuiteStart() {37 System.out.println("Test Suite Start");38 }39 public void onTestSuiteEnd() {40 System.out.println("Test Suite End");41 }42 });43 event.addListener(listeners);44 event.fireTestSuiteStart();45 event.fireTestSuiteEnd();46 Assert.assertTrue(true);47 }48}49package com.testsigma.event.test;50import org.testng.Assert;51import org.testng.annotations.Test;52import com.testsigma.event.TestSuiteEvent;53import com.testsigma.event.TestSuiteEventListener;54public class TestSuiteEventTest3 {55 public void test() {56 TestSuiteEvent event = new TestSuiteEvent();57 List<TestSuiteEventListener> listeners = new ArrayList<TestSuiteEventListener>();58 listeners.add(new TestSuiteEventListener() {59 public void onTestSuiteStart() {60 System.out.println("Test Suite Start");61 }62 public void onTestSuiteEnd() {63 System.out.println("Test Suite End");64 }65 });66 event.addListener(listeners

Full Screen

Full Screen

TestSuiteEvent

Using AI Code Generation

copy

Full Screen

1package com.testsigma.event;2import com.testsigma.event.TestSuiteEvent;3import com.testsigma.event.TestSuiteEventType;4public class TestSuiteEventExample {5 public static void main(String[] args) {6 TestSuiteEvent testSuiteEvent = new TestSuiteEvent();7 testSuiteEvent.setEventType(TestSuiteEventType.TESTSUITE_STARTED);8 testSuiteEvent.setEventDescription("test suite started");9 testSuiteEvent.setEventTimeStamp(System.currentTimeMillis());10 System.out.println(testSuiteEvent.toString());11 }12}13package com.testsigma.event;14import com.testsigma.event.TestSuiteEvent;15import com.testsigma.event.TestSuiteEventType;16public class TestSuiteEventExample {17 public static void main(String[] args) {18 TestSuiteEvent testSuiteEvent = new TestSuiteEvent();19 testSuiteEvent.setEventType(TestSuiteEventType.TESTSUITE_STARTED);20 testSuiteEvent.setEventDescription("test suite started");21 testSuiteEvent.setEventTimeStamp(System.currentTimeMillis());22 System.out.println(testSuiteEvent.toString());23 }24}25package com.testsigma.event;26import com.testsigma.event.TestSuiteEvent;27import com.testsigma.event.TestSuiteEventType;28public class TestSuiteEventExample {29 public static void main(String[] args) {30 TestSuiteEvent testSuiteEvent = new TestSuiteEvent();31 testSuiteEvent.setEventType(TestSuiteEventType.TESTSUITE_STARTED);32 testSuiteEvent.setEventDescription("test suite started");

Full Screen

Full Screen

TestSuiteEvent

Using AI Code Generation

copy

Full Screen

1import com.testsigma.event.*;2import java.util.*;3public class TestSuiteEventTest {4public static void main(String args[]) {5TestSuiteEvent tse = new TestSuiteEvent();6tse.setTestSuiteName("TestSuite1");7tse.setStartTime(new Date());8tse.setEndTime(new Date());9tse.setStatus("Passed");10tse.setExecutionTime(100);11tse.setDescription("This is a test suite");12TestSuiteEventList.addTestSuiteEvent(tse);13tse = new TestSuiteEvent();14tse.setTestSuiteName("TestSuite2");15tse.setStartTime(new Date());16tse.setEndTime(new Date());17tse.setStatus("Failed");18tse.setExecutionTime(200);19tse.setDescription("This is another test suite");20TestSuiteEventList.addTestSuiteEvent(tse);21tse = new TestSuiteEvent();22tse.setTestSuiteName("TestSuite3");23tse.setStartTime(new Date());24tse.setEndTime(new Date());25tse.setStatus("Passed");26tse.setExecutionTime(300);27tse.setDescription("This is another another test suite");28TestSuiteEventList.addTestSuiteEvent(tse);29tse = new TestSuiteEvent();30tse.setTestSuiteName("TestSuite4");

Full Screen

Full Screen

TestSuiteEvent

Using AI Code Generation

copy

Full Screen

1package com.testsigma.event.test;2import com.testsigma.event.TestSuiteEvent;3public class TestSuiteEventTest {4 public static void main(String[] args) {5 TestSuiteEvent testSuiteEvent = new TestSuiteEvent("TestSuiteEvent", "TestSuiteEventTest", "TestSuiteEventTest", "TestSuiteEventTest", "TestSuiteEventTest");6 testSuiteEvent.setTestSuiteName("TestSuiteEventTest");7 testSuiteEvent.setTestSuiteStartTime("TestSuiteEventTest");8 testSuiteEvent.setTestSuiteEndTime("TestSuiteEventTest");9 testSuiteEvent.setTestSuiteStatus("TestSuiteEventTest");10 testSuiteEvent.setTestSuiteResult("TestSuiteEventTest");11 System.out.println(testSuiteEvent.getTestSuiteName());12 System.out.println(testSuiteEvent.getTestSuiteStartTime());13 System.out.println(testSuiteEvent.getTestSuiteEndTime());14 System.out.println(testSuiteEvent.getTestSuiteStatus());15 System.out.println(testSuiteEvent.getTestSuiteResult());16 }17}18package com.testsigma.event.test;19import com.testsigma.event.TestSuiteEvent;20public class TestSuiteEventTest {21 public static void main(String[] args) {22 TestSuiteEvent testSuiteEvent = new TestSuiteEvent("TestSuiteEvent", "TestSuiteEventTest", "TestSuiteEventTest", "TestSuiteEventTest", "TestSuiteEventTest");23 testSuiteEvent.setTestSuiteName("TestSuiteEventTest");24 testSuiteEvent.setTestSuiteStartTime("TestSuiteEventTest");25 testSuiteEvent.setTestSuiteEndTime("TestSuiteEventTest");26 testSuiteEvent.setTestSuiteStatus("TestSuiteEventTest");27 testSuiteEvent.setTestSuiteResult("TestSuiteEventTest");28 System.out.println(testSuiteEvent.getTestSuiteName());29 System.out.println(testSuiteEvent.getTestSuiteStartTime());30 System.out.println(testSuiteEvent.getTestSuiteEndTime());31 System.out.println(testSuiteEvent.getTestSuiteStatus());32 System.out.println(testSuiteEvent.getTestSuiteResult());33 }34}35package com.testsigma.event.test;36import com.testsigma.event.TestSuiteEvent;37public class TestSuiteEventTest {

Full Screen

Full Screen

TestSuiteEvent

Using AI Code Generation

copy

Full Screen

1import com.testsigma.event.*;2import java.util.*;3import java.io.*;4import java.lang.*;5import java.util.*;6import java.util.concurrent.*;7import java.util.concurrent.atomic.*;8import java.util.concurrent.locks.*;9import java.util.concurrent.locks.ReentrantLock;10import java.util.concurrent.locks.Condition;11import java.util.concurrent.locks.ReentrantReadWriteLock;12import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;13import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;14import java.util.concurrent.locks.Lock;15import java.util.concurrent.locks.ReentrantLock;16import java.util.concurrent.locks.Condition;17import java.util.concurrent.locks.ReentrantReadWriteLock;18import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;19import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;20import java.util.concurrent.locks.Lock;21import java.util.concurrent.locks.ReentrantLock;22import java.util.concurrent.locks.Condition;23import java.util.concurrent.locks.ReentrantReadWriteLock;24import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;25import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;26import java.util.concurrent.locks.Lock;27import java.util.concurrent.locks.ReentrantLock;28import java.util.concurrent.locks.Condition;29import java.util.concurrent.locks.ReentrantReadWriteLock;30import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;31import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;32import java.util.concurrent.locks.Lock;33import java.util.concurrent.locks.ReentrantLock;34import java.util.concurrent.locks.Condition;35import java.util.concurrent.locks.ReentrantReadWriteLock;36import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;37import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;38import java.util.concurrent.locks.Lock;39import java.util.concurrent.locks.ReentrantLock;40import java.util.concurrent.locks.Condition;41import java.util.concurrent.locks.ReentrantReadWriteLock;42import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;43import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;44import java.util.concurrent.locks.Lock;45import java.util.concurrent.locks.ReentrantLock;46import java.util.concurrent.locks.Condition;47import java.util.concurrent.locks.ReentrantReadWriteLock;48import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;49import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;50import java.util.concurrent.locks.Lock;51import java.util.concurrent.locks.ReentrantLock;52import java.util.concurrent.locks.Condition

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.

Run Testsigma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in TestSuiteEvent

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful