Best Testsigma code snippet using com.testsigma.service.OnPremiseStorageService.getRootDirectory
Source: OnPremiseStorageService.java
...33 this.jwtTokenService = jwtTokenService;34 }35 private String getFilePathRelativeToRoot(String filePath) {36 if (!filePath.trim().toLowerCase().startsWith(FILE_PROTOCOL)) {37 String root = getRootDirectory();38 if (root.contains("\\") || root.contains("\\\\")) {39 filePath = String.valueOf(root.charAt(root.length() - 1)).equals("\\") ? root +40 filePath.replaceAll("/", "\\\\").substring(1) : root + filePath.replaceAll("/", "\\\\");41 filePath = filePath.substring(0, 8) + filePath.substring(8).replaceAll ("\\\\\\\\", "\\\\");42 } else43 filePath = root + File.separator + filePath;44 } else {45 filePath = filePath.substring(5);46 }47 return filePath;48 }49 @Override50 public void addFile(String filePathToAdd, File fileToAdd) {51 String filePathFromRoot = getFilePathRelativeToRoot(filePathToAdd);52 log.info(String.format("Copying file from %s to %s", fileToAdd, filePathFromRoot));53 File newFile = new File(filePathFromRoot);54 try {55 if (newFile.exists()) {56 FileUtils.forceDeleteOnExit(newFile);57 }58 FileUtils.copyFile(fileToAdd, newFile);59 } catch (IOException e) {60 log.error("Unable to create a new file", e);61 }62 }63 @Override64 public void addFile(String filePathToAdd, InputStream inputStream) {65 String filePathFromRoot = getFilePathRelativeToRoot(filePathToAdd);66 log.info(String.format("Copying data from input stream to %s", filePathFromRoot));67 File newFile = new File(filePathFromRoot);68 try {69 if (newFile.exists()) {70 FileUtils.forceDelete(newFile);71 }72 FileUtils.copyInputStreamToFile(inputStream, new File(filePathFromRoot));73 } catch (IOException e) {74 log.error("Unable to create a new file from input stream", e);75 }76 }77 public void addDirectory(String directoryPathFromRoot) {78 File newDir = new File(getFilePathRelativeToRoot(directoryPathFromRoot));79 try {80 FileUtils.forceMkdir(newDir);81 } catch (IOException e) {82 log.error("Unable to create a new directory", e);83 }84 }85 @Override86 public URL generatePreSignedURL(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel, Integer expiryTimeInMinutes) {87 log.info("Generating pre-signed URL for:" + relativeFilePathFromBase);88 Calendar cal = Calendar.getInstance();89 cal.add(Calendar.MINUTE, expiryTimeInMinutes);90 URL preSignedURL = null;91 try {92 String token = jwtTokenService.generateAttachmentToken(relativeFilePathFromBase, cal.getTime(), getHttpMethod(storageAccessLevel));93 MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();94 queryParams.add(STORAGE_SIGNATURE, token);95 if (relativeFilePathFromBase.contains("\\") || relativeFilePathFromBase.contains("\\\\") )96 relativeFilePathFromBase = relativeFilePathFromBase.replaceAll("\\\\", "/");97 relativeFilePathFromBase = relativeFilePathFromBase.replaceAll("\\\\\\\\", "/");98 UriComponents uriComponents =99 UriComponentsBuilder.fromUriString(URLConstants.PRESIGNED_BASE_URL + "/{key}").queryParams(queryParams)100 .build().expand(relativeFilePathFromBase).encode();101 preSignedURL = new URL(applicationConfig.getServerUrl() + uriComponents.toUriString());102 log.info("Before normalizing - " + preSignedURL.toString());103 preSignedURL = preSignedURL.toURI().normalize().toURL();104 log.info("After normalizing - " + preSignedURL.toString());105 } catch (Exception e) {106 log.error("Unable to construct pre-signed URL object from path," + relativeFilePathFromBase, e);107 }108 return preSignedURL;109 }110 @Override111 public Optional<URL> generatePreSignedURLIfExists(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel, Integer expiryTimeInMinutes) {112 log.debug("Generating File URL if exists:" + relativeFilePathFromBase);113 Optional<URL> returnURL = Optional.empty();114 String rootDirectory = getRootDirectory();115 if (rootDirectory.contains("\\") || rootDirectory.contains("\\\\") ){116 String lastChar = String.valueOf(rootDirectory.charAt(rootDirectory.length() - 1));117 relativeFilePathFromBase = lastChar.equals("\\") || lastChar.equals("\\\\") ?118 relativeFilePathFromBase.replaceAll("/", "\\\\").substring(1) :119 relativeFilePathFromBase.replaceAll("/", "\\\\");120 }121 File file = Paths.get(rootDirectory, relativeFilePathFromBase).toFile();122 if (file.exists()) {123 log.debug("File exists, generating pre-signed URL for:" + relativeFilePathFromBase);124 returnURL = Optional.ofNullable(generatePreSignedURL(relativeFilePathFromBase, storageAccessLevel, expiryTimeInMinutes));125 }126 return returnURL;127 }128 @Override129 public Optional<URL> generatePreSignedURLIfExists(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) {130 return generatePreSignedURLIfExists(relativeFilePathFromBase, storageAccessLevel, 600);131 }132 @Override133 public URL generatePreSignedURL(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) {134 return generatePreSignedURL(relativeFilePathFromBase, storageAccessLevel, 600);135 }136 @Override137 public String downloadToLocal(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) throws TestsigmaException {138 return getRootDirectory() + File.separator + relativeFilePathFromBase;139 }140 @Override141 public void deleteFile(String filePath) {142 FileUtils.deleteQuietly(new File(filePath));143 }144 @Override145 protected String getRootDirectory() {146 return Paths.get(applicationConfig.getDataDir(), storageConfig.getOnPremiseRootDirectory()).toString();147 }148 public String getAbsoluteFilePath(String relativePathFromRoot) {149 return getRootDirectory() + File.separator + relativePathFromRoot;150 }151 private HttpMethod getHttpMethod(StorageAccessLevel storageAccessLevel) {152 switch (storageAccessLevel) {153 case WRITE:154 case FULL_ACCESS:155 return HttpMethod.POST;156 case DELETE:157 return HttpMethod.DELETE;158 default:159 return HttpMethod.GET;160 }161 }162}...
getRootDirectory
Using AI Code Generation
1com.testsigma.service.OnPremiseStorageService service = new com.testsigma.service.OnPremiseStorageService();2String rootDirectory = service.getRootDirectory();3com.testsigma.service.OnPremiseStorageService service = new com.testsigma.service.OnPremiseStorageService();4String rootDirectory = service.getRootDirectory();5C:\Program Files (x86)\TestSigma\bin\lib\com\testsigma\service6C:\Program Files (x86)\TestSigma\bin\lib\com\testsigma\service7C:\Program Files (x86)\TestSigma\bin\lib\com\testsigma\service8C:\Program Files (x86)\TestSigma\bin\lib\com\testsigma\service9C:\Program Files (x86)\TestSigma\bin\lib\com
getRootDirectory
Using AI Code Generation
1import com.testsigma.service.OnPremiseStorageService2def storageService = new OnPremiseStorageService()3def rootDir = storageService.getRootDirectory()4def newDir = new File(rootDir, "newDirectory")5newDir.mkdir()6def newFile = new File(newDir, "newFile.txt")7newFile.createNewFile()8newFile.write("This is a new file created by TestSigma")9newFile.delete()10newDir.delete()11def newDir2 = new File(rootDir, "newDirectory2")12newDir2.mkdir()13def newFile2 = new File(newDir2, "newFile2.txt")14newFile2.createNewFile()15newFile2.write("This is a new file created by TestSigma")16newFile2.delete()17newDir2.delete()18def newDir3 = new File(rootDir, "newDirectory3")19newDir3.mkdir()20def newFile3 = new File(newDir3, "newFile3.txt")21newFile3.createNewFile()22newFile3.write("This is a new file created by TestSigma")
getRootDirectory
Using AI Code Generation
1import com.testsigma.service.OnPremiseStorageService2def rootDirectory = OnPremiseStorageService.getRootDirectory()3import com.testsigma.service.OnPremiseStorageService4def directory = OnPremiseStorageService.getDirectory("testData")5import com.testsigma.service.OnPremiseStorageService6def directory = OnPremiseStorageService.getDirectory("testData", "parentTestData")7import com.testsigma.service.OnPremiseStorageService8def directory = OnPremiseStorageService.getDirectory("testData", "parentTestData", "grandParentTestData")9import com.testsigma.service.OnPremiseStorageService10def directory = OnPremiseStorageService.getDirectory("testData", "parentTestData", "grandParentTestData", "greatGrandParentTestData")
getRootDirectory
Using AI Code Generation
1var onPremiseStorageService = new com.testsigma.service.OnPremiseStorageService();2var rootDirectory = onPremiseStorageService.getRootDirectory();3console.log(rootDirectory);4var onPremiseStorageService = new com.testsigma.service.OnPremiseStorageService();5var rootDirectory = onPremiseStorageService.getRootDirectory();6console.log(rootDirectory);
Check out the latest blogs from LambdaTest on this topic:
The key to successful test automation is to focus on tasks that maximize the return on investment (ROI), ensuring that you are automating the right tests and automating them in the right way. This is where test automation strategies come into play.
Selenium, a project hosted by the Apache Software Foundation, is an umbrella open-source project comprising a variety of tools and libraries for test automation. Selenium automation framework enables QA engineers to perform automated web application testing using popular programming languages like Python, Java, JavaScript, C#, Ruby, and PHP.
Estimates are critical if you want to be successful with projects. If you begin with a bad estimating approach, the project will almost certainly fail. To produce a much more promising estimate, direct each estimation-process issue toward a repeatable standard process. A smart approach reduces the degree of uncertainty. When dealing with presales phases, having the most precise estimation findings can assist you to deal with the project plan. This also helps the process to function more successfully, especially when faced with tight schedules and the danger of deviation.
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
While there is a huge demand and need to run Selenium Test Automation, the experts always suggest not to automate every possible test. Exhaustive Testing is not possible, and Automating everything is not sustainable.
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!!