use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.
the class AttachmentDataStoreServiceTest method saveLoadAndDeleteTest.
@Test
void saveLoadAndDeleteTest() throws IOException {
InputStream inputStream = new ClassPathResource("meh.jpg").getInputStream();
String fileId = attachmentDataStoreService.save(random.nextLong() + "meh.jpg", inputStream);
Optional<InputStream> loadedData = attachmentDataStoreService.load(fileId);
assertTrue(loadedData.isPresent());
assertTrue(Files.exists(Paths.get(storageRootPath, attachmentDataStoreService.dataEncoder.decode(fileId))));
attachmentDataStoreService.delete(fileId);
ReportPortalException exception = assertThrows(ReportPortalException.class, () -> attachmentDataStoreService.load(fileId));
assertEquals("Unable to load binary data by id 'Unable to find file'", exception.getMessage());
assertFalse(Files.exists(Paths.get(storageRootPath, attachmentDataStoreService.dataEncoder.decode(fileId))));
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.
the class LocalDataStore method save.
@Override
public String save(String filePath, InputStream inputStream) {
try {
Path targetPath = Paths.get(storageRootPath, filePath);
Path targetDirectory = targetPath.getParent();
if (Objects.nonNull(targetDirectory) && !Files.isDirectory(targetDirectory)) {
Files.createDirectories(targetDirectory);
}
logger.debug("Saving to: {} ", targetPath.toAbsolutePath());
Files.copy(inputStream, targetPath, StandardCopyOption.REPLACE_EXISTING);
return filePath;
} catch (IOException e) {
logger.error("Unable to save log file '{}'", filePath, e);
throw new ReportPortalException(ErrorType.INCORRECT_REQUEST, "Unable to save log file");
}
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.
the class LocalDataStoreTest method save_load_delete.
@Test
void save_load_delete() throws Exception {
// given:
AttachmentMetaInfo attachmentMetaInfo = AttachmentMetaInfo.builder().withProjectId(1L).withLaunchId(2L).withItemId(3L).withLogId(4L).build();
String generatedDirectory = "/test";
when(fileNameGenerator.generate(attachmentMetaInfo)).thenReturn(generatedDirectory);
FileUtils.deleteDirectory(new File(Paths.get(ROOT_PATH, generatedDirectory).toUri()));
// when: save new file
String savedFilePath = localDataStore.save(TEST_FILE, new ByteArrayInputStream("test text".getBytes(Charsets.UTF_8)));
// and: load it back
InputStream loaded = localDataStore.load(savedFilePath);
// then: saved and loaded files should be the same
byte[] bytes = IOUtils.toByteArray(loaded);
String result = new String(bytes, Charsets.UTF_8);
assertEquals("test text", result, "saved and loaded files should be the same");
// when: delete saved file
localDataStore.delete(savedFilePath);
// and: load file again
boolean isNotFound = false;
try {
localDataStore.load(savedFilePath);
} catch (ReportPortalException e) {
isNotFound = true;
}
// then: deleted file should not be found
assertTrue("deleted file should not be found", isNotFound);
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.
the class LogLevelTest method toLevelIntFail.
@Test
void toLevelIntFail() {
Collections.shuffle(disallowedCodes);
final Integer code = disallowedCodes.get(0);
final ReportPortalException exception = assertThrows(ReportPortalException.class, () -> LogLevel.toLevel(code));
assertEquals("Error in Save Log Request. Wrong level = " + code, exception.getMessage());
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.
the class WidgetContentRepositoryImpl method productStatusGroupedByFilterStatistics.
@Override
public Map<String, List<ProductStatusStatisticsContent>> productStatusGroupedByFilterStatistics(Map<Filter, Sort> filterSortMapping, List<String> contentFields, Map<String, String> customColumns, boolean isLatest, int limit) {
Select<? extends Record> select = filterSortMapping.entrySet().stream().map(f -> (Select<? extends Record>) buildFilterGroupedQuery(f.getKey(), isLatest, f.getValue(), limit, contentFields, customColumns)).collect(Collectors.toList()).stream().reduce((prev, curr) -> curr = prev.unionAll(curr)).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Query building for Product Status Widget failed"));
Map<String, List<ProductStatusStatisticsContent>> productStatusContent = PRODUCT_STATUS_FILTER_GROUPED_FETCHER.apply(select.fetch(), customColumns);
productStatusContent.put(TOTAL, countFilterTotalStatistics(productStatusContent));
return productStatusContent;
}
Aggregations