How to use AgentDevice class of com.testsigma.model package

Best Testsigma code snippet using com.testsigma.model.AgentDevice

Source:AgentDevicesController.java Github

copy

Full Screen

...10import com.fasterxml.jackson.core.type.TypeReference;11import com.testsigma.config.StorageServiceFactory;12import com.testsigma.config.URLConstants;13import com.testsigma.model.StorageAccessLevel;14import com.testsigma.dto.AgentDeviceDTO;15import com.testsigma.dto.IosDeveloperImageDTO;16import com.testsigma.dto.IosWdaResponseDTO;17import com.testsigma.exception.ResourceNotFoundException;18import com.testsigma.exception.TestsigmaDatabaseException;19import com.testsigma.exception.TestsigmaException;20import com.testsigma.mapper.AgentDeviceMapper;21import com.testsigma.model.Agent;22import com.testsigma.model.AgentDevice;23import com.testsigma.model.ProvisioningProfileDevice;24import com.testsigma.service.AgentDeviceService;25import com.testsigma.service.AgentService;26import com.testsigma.service.ProvisioningProfileDeviceService;27import com.testsigma.service.TestsigmaOSConfigService;28import com.testsigma.util.HttpClient;29import com.testsigma.util.HttpResponse;30import com.testsigma.web.request.AgentDeviceRequest;31import lombok.RequiredArgsConstructor;32import lombok.extern.log4j.Log4j2;33import org.apache.http.Header;34import org.apache.http.HttpHeaders;35import org.apache.http.message.BasicHeader;36import org.springframework.beans.factory.annotation.Autowired;37import org.springframework.web.bind.annotation.*;38import java.net.URL;39import java.util.ArrayList;40@Log4j241@RestController(value = "agentAgentDevicesController")42@RequestMapping(value = {"/api/agents/{agentUuid}/devices"})43@RequiredArgsConstructor(onConstructor = @__({@Autowired}))44public class AgentDevicesController {45 private final AgentDeviceService agentDeviceService;46 private final AgentDeviceMapper agentDeviceMapper;47 private final AgentService agentService;48 private final HttpClient httpClient;49 private final StorageServiceFactory storageServiceFactory;50 private final ProvisioningProfileDeviceService provisioningProfileDeviceService;51 private final TestsigmaOSConfigService testsigmaOSConfigService;52 @RequestMapping(value = "/status", method = RequestMethod.PUT)53 public void syncInitialDeviceStatus(@PathVariable("agentUuid") String agentUuid) throws TestsigmaDatabaseException,54 ResourceNotFoundException {55 log.info(String.format("Received a PUT request api/agents/%s/devices/status ", agentUuid));56 Agent agent = agentService.findByUniqueId(agentUuid);57 agentDeviceService.updateDevicesStatus(agent.getId());58 }59 @RequestMapping(value = "/{uniqueId}", method = RequestMethod.GET)60 public AgentDeviceDTO show(@PathVariable("agentUuid") String agentUuid, @PathVariable("uniqueId") String uniqueId)61 throws ResourceNotFoundException {62 log.info(String.format("Received a GET request api/agents/%s/devices/%s ", agentUuid, uniqueId));63 Agent agent = agentService.findByUniqueId(agentUuid);64 AgentDevice agentDevice = agentDeviceService.findAgentDeviceByUniqueId(agent.getId(), uniqueId);65 return agentDeviceMapper.map(agentDevice);66 }67 @RequestMapping(method = RequestMethod.POST)68 public AgentDeviceDTO create(@PathVariable("agentUuid") String agentUuid,69 @RequestBody AgentDeviceRequest agentDeviceRequest)70 throws TestsigmaDatabaseException, ResourceNotFoundException {71 log.info(String.format("Received a POST request api/agents/%s/devices . Request body is [%s] ",72 agentUuid, agentDeviceRequest));73 Agent agent = agentService.findByUniqueId(agentUuid);74 AgentDevice agentDevice = agentDeviceMapper.map(agentDeviceRequest);75 agentDevice.setAgentId(agent.getId());76 agentDevice = agentDeviceService.create(agentDevice);77 return agentDeviceMapper.map(agentDevice);78 }79 @RequestMapping(value = "/{uniqueId}", method = RequestMethod.PUT)80 public AgentDeviceDTO update(@PathVariable("agentUuid") String agentUuid,81 @PathVariable("uniqueId") String uniqueId,82 @RequestBody AgentDeviceRequest agentDeviceRequest)83 throws TestsigmaDatabaseException, ResourceNotFoundException {84 log.info(String.format("Received a PUT request api/agents/%s/devices/%s . Request body is [%s] ",85 agentUuid, uniqueId, agentDeviceRequest));86 Agent agent = agentService.findByUniqueId(agentUuid);87 AgentDevice agentDevice = agentDeviceService.findAgentDeviceByUniqueId(agent.getId(), uniqueId);88 agentDeviceMapper.map(agentDeviceRequest, agentDevice);89 agentDevice = agentDeviceService.update(agentDevice);90 return agentDeviceMapper.map(agentDevice);91 }92 @RequestMapping(value = "/{uniqueId}", method = RequestMethod.DELETE)93 public AgentDeviceDTO delete(@PathVariable("agentUuid") String agentUuid,94 @PathVariable("uniqueId") String uniqueId)95 throws TestsigmaDatabaseException, ResourceNotFoundException {96 log.info(String.format("Received a DELETE request api/agents/%s/devices/%s", agentUuid, uniqueId));97 Agent agent = agentService.findByUniqueId(agentUuid);98 AgentDevice agentDevice = agentDeviceService.findAgentDeviceByUniqueId(agent.getId(), uniqueId);99 agentDeviceService.destroy(agentDevice);100 return agentDeviceMapper.map(agentDevice);101 }102 @RequestMapping(value = "/developer/{osVersion}/", method = RequestMethod.GET)103 public IosDeveloperImageDTO developer(@PathVariable("agentUuid") String agentUuid,104 @PathVariable("osVersion") String deviceOsVersion) throws TestsigmaException {105 log.info(String.format("Received a GET request api/agents/%s/devices/developer/%s", agentUuid, deviceOsVersion));106 HttpResponse<IosDeveloperImageDTO> response = httpClient.get(testsigmaOSConfigService.getUrl() +107 URLConstants.TESTSIGMA_OS_PUBLIC_IOS_IMAGE_FILES_URL + "/" + deviceOsVersion, getHeaders(), new TypeReference<>() {108 });109 IosDeveloperImageDTO iosDeveloperImageDTO = response.getResponseEntity();110 log.info("Ios developer image url DTO - " + iosDeveloperImageDTO);111 return iosDeveloperImageDTO;112 }113 @RequestMapping(value = "/{deviceUuid}/wda", method = RequestMethod.GET)114 public IosWdaResponseDTO deviceWdaUrl(@PathVariable String agentUuid, @PathVariable String deviceUuid)115 throws TestsigmaException {116 log.info(String.format("Received a GET request api/agents/%s/devices/%s/wda", agentUuid, deviceUuid));117 IosWdaResponseDTO iosWdaResponseDTO = new IosWdaResponseDTO();118 Agent agent = agentService.findByUniqueId(agentUuid);119 AgentDevice agentDevice = agentDeviceService.findAgentDeviceByUniqueId(agent.getId(), deviceUuid);120 ProvisioningProfileDevice profileDevice = provisioningProfileDeviceService.findByAgentDeviceId(agentDevice.getId());121 if (profileDevice != null) {122 URL presignedUrl = storageServiceFactory.getStorageService().generatePreSignedURL("wda/"123 + profileDevice.getProvisioningProfileId() + "/wda.ipa", StorageAccessLevel.READ, 180);124 iosWdaResponseDTO.setWdaPresignedUrl(presignedUrl.toString());125 log.info("Ios Wda Response DTO - " + iosWdaResponseDTO);126 return iosWdaResponseDTO;127 } else {128 throw new TestsigmaException("could not find a provisioning profile for this device. Unable to fetch WDA");129 }130 }131 private ArrayList<Header> getHeaders() {132 ArrayList<Header> headers = new ArrayList<>();133 headers.add(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"));134 return headers;...

Full Screen

Full Screen

Source:AgentDeviceService.java Github

copy

Full Screen

...6 * ****************************************************************************7 *8 */9package com.testsigma.service;10import com.testsigma.dto.AgentDeviceDTO;11import com.testsigma.event.AgentDeviceEvent;12import com.testsigma.event.EventType;13import com.testsigma.exception.ResourceNotFoundException;14import com.testsigma.exception.TestsigmaDatabaseException;15import com.testsigma.model.AgentDevice;16import com.testsigma.model.ProvisioningProfileDevice;17import com.testsigma.repository.AgentDeviceRepository;18import lombok.RequiredArgsConstructor;19import lombok.extern.log4j.Log4j2;20import org.springframework.beans.factory.annotation.Autowired;21import org.springframework.context.ApplicationEventPublisher;22import org.springframework.context.annotation.Lazy;23import org.springframework.data.domain.Page;24import org.springframework.data.domain.Pageable;25import org.springframework.stereotype.Service;26import java.util.List;27@Service28@Log4j229@RequiredArgsConstructor(onConstructor = @__({@Autowired, @Lazy}))30public class AgentDeviceService {31 private final AgentDeviceRepository agentDeviceRepository;32 private final ProvisioningProfileDeviceService profileDeviceService;33 private final ApplicationEventPublisher applicationEventPublisher;34 public Page<AgentDevice> findAllByAgentId(Long agentId, Pageable pageable) {35 return agentDeviceRepository.findAllByAgentId(agentId, pageable);36 }37 public List<AgentDevice> findAllByAgent(Long agentId) {38 return agentDeviceRepository.findAllByAgentId(agentId);39 }40 public Page<AgentDevice> findAllByAgentIdAndIsOnline(Long agentId, Pageable pageable) {41 return agentDeviceRepository.findAllByAgentIdAndIsOnline(agentId, true, pageable);42 }43 public AgentDevice create(AgentDevice agentDevice) throws TestsigmaDatabaseException {44 try {45 agentDevice = agentDeviceRepository.save(agentDevice);46 profileDeviceService.updateAgentDevice(agentDevice);47 publishEvent(agentDevice, EventType.CREATE);48 return agentDevice;49 } catch (Exception e) {50 throw new TestsigmaDatabaseException(e.getMessage());51 }52 }53 public AgentDevice update(AgentDevice agentDevice) throws TestsigmaDatabaseException {54 try {55 agentDevice = agentDeviceRepository.save(agentDevice);56 publishEvent(agentDevice, EventType.UPDATE);57 return agentDevice;58 } catch (Exception e) {59 throw new TestsigmaDatabaseException(e.getMessage());60 }61 }62 public void destroy(AgentDevice agentDevice) throws TestsigmaDatabaseException {63 try {64 agentDeviceRepository.delete(agentDevice);65 publishEvent(agentDevice, EventType.DELETE);66 } catch (Exception e) {67 throw new TestsigmaDatabaseException(e.getMessage());68 }69 }70 public AgentDevice findAgentDeviceByUniqueId(Long agentId, String uniqueId) throws ResourceNotFoundException {71 return agentDeviceRepository.findAgentDeviceByAgentIdAndUniqueId(agentId, uniqueId).orElseThrow(() -> new ResourceNotFoundException(72 "Device not found with uniqueId " + uniqueId + " associated to agent " + agentId73 ));74 }75 public void updateDevicesStatus(Long agentId) throws TestsigmaDatabaseException {76 try {77 agentDeviceRepository.updateAgentDevice(agentId);78 } catch (Exception e) {79 throw new TestsigmaDatabaseException(e.getMessage());80 }81 }82 public AgentDevice find(Long id) throws ResourceNotFoundException {83 return agentDeviceRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("AgentDevice is not " +84 "found with id:" + id));85 }86 public List<AgentDevice> findByUniqueId(String deviceUDID) throws ResourceNotFoundException {87 return this.agentDeviceRepository.findAllByUniqueId(deviceUDID);88 }89 public void setProvisionedFlag(List<AgentDeviceDTO> agentDeviceDTOs) {90 for (AgentDeviceDTO agentDeviceDTO : agentDeviceDTOs) {91 ProvisioningProfileDevice profileDevice = profileDeviceService.findByAgentDeviceId(agentDeviceDTO.getId());92 agentDeviceDTO.setProvisioned(profileDevice != null);93 }94 }95 public void publishEvent(AgentDevice agentDevice, EventType eventType) {96 AgentDeviceEvent<AgentDevice> event = createEvent(agentDevice, eventType);97 log.info("Publishing event - " + event.toString());98 applicationEventPublisher.publishEvent(event);99 }100 public AgentDeviceEvent<AgentDevice> createEvent(AgentDevice agentDevice, EventType eventType) {101 AgentDeviceEvent<AgentDevice> event = new AgentDeviceEvent<>();102 event.setEventData(agentDevice);103 event.setEventType(eventType);104 return event;105 }106 public boolean isDeviceOnline(Long deviceId) throws ResourceNotFoundException{107 AgentDevice agentDevice = find(deviceId);108 return agentDevice.getIsOnline();109 }110}...

Full Screen

Full Screen

Source:AgentDeviceMapper.java Github

copy

Full Screen

1package com.testsigma.mapper;2import com.testsigma.dto.AgentDeviceDTO;3import com.testsigma.model.AgentDevice;4import com.testsigma.web.request.AgentDeviceRequest;5import org.mapstruct.*;6import java.util.List;7@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE,8 nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,9 nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)10public interface AgentDeviceMapper {11 @Mapping(target = "browserList", expression = "java(agentDeviceRequest.getAgentBrowserList())")12 void map(AgentDeviceRequest agentDeviceRequest, @MappingTarget AgentDevice agentDevice);13 @Mapping(target = "browserList", expression = "java(agentDeviceRequest.getAgentBrowserList())")14 AgentDevice map(AgentDeviceRequest agentDeviceRequest);15 AgentDeviceDTO map(AgentDevice agentDevice);16 List<AgentDeviceDTO> map(List<AgentDevice> agentDevices);17}...

Full Screen

Full Screen

AgentDevice

Using AI Code Generation

copy

Full Screen

1import com.testsigma.model.AgentDevice;2public class 2 {3public static void main(String[] args) {4AgentDevice agentDevice = new AgentDevice();5agentDevice.setDeviceId("abc");6agentDevice.setDeviceName("xyz");7agentDevice.setDeviceType("mobile");8agentDevice.setOs("android");9agentDevice.setOsVersion("9.0");10agentDevice.setAgentId("agentId");11agentDevice.setAgentName("agentName");12agentDevice.setAgentVersion("agentVersion");13agentDevice.setDeviceStatus("deviceStatus");14agentDevice.setDeviceStatusMsg("deviceStatusMsg");15agentDevice.setDeviceIp("deviceIp");16agentDevice.setDevicePort("devicePort");17agentDevice.setDeviceUdid("deviceUdid");18agentDevice.setDeviceSerial("deviceSerial");19agentDevice.setDeviceModel("deviceModel");20agentDevice.setDeviceManufacturer("deviceManufacturer");21agentDevice.setDeviceResolution("deviceResolution");22agentDevice.setDeviceOs("deviceOs");23agentDevice.setDeviceOsVersion("deviceOsVersion");24agentDevice.setDeviceBattery("deviceBattery");25agentDevice.setDeviceCpu("deviceCpu");26agentDevice.setDeviceRam("deviceRam");27agentDevice.setDeviceInternalStorage("deviceInternalStorage");28agentDevice.setDeviceExternalStorage("deviceExternalStorage");29agentDevice.setDeviceNetwork("deviceNetwork");30agentDevice.setDeviceCamera("deviceCamera");31agentDevice.setDeviceSensor("deviceSensor");32agentDevice.setDeviceSim("deviceSim");33agentDevice.setDeviceLocation("deviceLocation");34agentDevice.setDeviceFingerprint("deviceFingerprint");35agentDevice.setDeviceSimulator("deviceSimulator");36agentDevice.setDeviceEmulator("deviceEmulator");37agentDevice.setDeviceRooted("deviceRooted");38agentDevice.setDeviceLocked("deviceLocked");39agentDevice.setDeviceScreenOn("deviceScreenOn");40agentDevice.setDeviceScreenOff("deviceScreenOff");41agentDevice.setDeviceScreenLocked("deviceScreenLocked");42agentDevice.setDeviceScreenUnlocked("deviceScreenUnlocked");43agentDevice.setDeviceScreenOnTime("deviceScreenOnTime");44agentDevice.setDeviceScreenOffTime("deviceScreenOffTime");45agentDevice.setDeviceScreenLockedTime("deviceScreenLockedTime");46agentDevice.setDeviceScreenUnlockedTime("deviceScreenUnlockedTime");47agentDevice.setDeviceScreenOnCount("deviceScreenOnCount");48agentDevice.setDeviceScreenOffCount("deviceScreenOffCount");49agentDevice.setDeviceScreenLockedCount("deviceScreenLockedCount");

Full Screen

Full Screen

AgentDevice

Using AI Code Generation

copy

Full Screen

1import com.testsigma.model.AgentDevice;2import com.testsigma.model.Device;3import com.testsigma.model.DeviceType;4import com.testsigma.model.DeviceStatus;5import com.testsigma.model.DeviceCategory;6import com.testsigma.model.DeviceModel;7import com.testsigma.model.DeviceManufacturer;8import com.testsigma.model.DeviceOS;9import com.testsigma.model.DeviceOSVersion;10import com.testsigma.model.DeviceEnvironment;11import com.testsigma.model.DeviceCapability;12import com.testsigma.model.DeviceCapabilityType;13import com.testsigma.model.DeviceCapabilityValue;14import com.testsigma.model.DeviceCapabilityUnit;15import com.testsigma.model.DeviceCapabilityUnitType;16import com.testsigma.model.DeviceCapabilityUnitCategory;17import com.testsigma.model.DeviceCapabilityUnitSubCategory;18import com.testsigma.model.DeviceCapabilityUnitSubSubCategory;19import com.testsigma.model.DeviceCapabilityUnitSubSubSubCategory;20import com.testsigma.model.DeviceCapabilityUnitSubSubSubSubCategory;21import com.testsigma.model.DeviceCapabilityUnitSubSubSubSubSubCategory;22import com.testsigma.model.DeviceCapabilityUnitSubSubSubSubSubSubCategory;23import com.testsigma.model.DeviceCapabilityUnitSubSubSubSubSubSubSubCategory;24import com.testsigma.model.DeviceCapabilityUnitSubSubSubSubSubSubSubSubCategory;25import com.testsigma.model.DeviceCapabilityUnitSubSubSubSubSubSubSubSubSubCategory;26import com.testsigma.model

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.

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