Search in sources :

Example 6 with ReportPortalException

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))));
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 7 with ReportPortalException

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");
    }
}
Also used : Path(java.nio.file.Path) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IOException(java.io.IOException)

Example 8 with ReportPortalException

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) File(java.io.File) AttachmentMetaInfo(com.epam.ta.reportportal.entity.attachment.AttachmentMetaInfo) Test(org.junit.jupiter.api.Test)

Example 9 with ReportPortalException

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());
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Test(org.junit.jupiter.api.Test)

Example 10 with ReportPortalException

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;
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) DSL(org.jooq.impl.DSL) QueryBuilder(com.epam.ta.reportportal.commons.querygen.QueryBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired) HealthCheckTableInitParams(com.epam.ta.reportportal.entity.widget.content.healthcheck.HealthCheckTableInitParams) StringUtils(org.apache.commons.lang3.StringUtils) QueryUtils.collectJoinFields(com.epam.ta.reportportal.dao.util.QueryUtils.collectJoinFields) BigDecimal(java.math.BigDecimal) org.jooq(org.jooq) WidgetProviderChain(com.epam.ta.reportportal.dao.widget.WidgetProviderChain) Sort(org.springframework.data.domain.Sort) Repository(org.springframework.stereotype.Repository) KEY_VALUE_SEPARATOR(com.epam.ta.reportportal.commons.querygen.constant.ItemAttributeConstant.KEY_VALUE_SEPARATOR) RoundingMode(java.math.RoundingMode) CRITERIA_START_TIME(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_START_TIME) TEST_ITEM_RESULTS(com.epam.ta.reportportal.jooq.tables.JTestItemResults.TEST_ITEM_RESULTS) ACTIVITY(com.epam.ta.reportportal.jooq.tables.JActivity.ACTIVITY) Filter(com.epam.ta.reportportal.commons.querygen.Filter) WidgetContentRepositoryConstants(com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants) USERS(com.epam.ta.reportportal.jooq.tables.JUsers.USERS) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Collectors(java.util.stream.Collectors) PROJECT(com.epam.ta.reportportal.jooq.tables.JProject.PROJECT) HealthCheckTableContent(com.epam.ta.reportportal.entity.widget.content.healthcheck.HealthCheckTableContent) VALUES_SEPARATOR(com.epam.ta.reportportal.commons.querygen.Condition.VALUES_SEPARATOR) ISSUE_TICKET(com.epam.ta.reportportal.jooq.tables.JIssueTicket.ISSUE_TICKET) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) ComponentHealthCheckContent(com.epam.ta.reportportal.entity.widget.content.healthcheck.ComponentHealthCheckContent) ActivityResource(com.epam.ta.reportportal.ws.model.ActivityResource) java.util(java.util) TICKET(com.epam.ta.reportportal.jooq.tables.JTicket.TICKET) PostgresDSL(org.jooq.util.postgres.PostgresDSL) com.epam.ta.reportportal.entity.widget.content(com.epam.ta.reportportal.entity.widget.content) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) Tables(com.epam.ta.reportportal.jooq.Tables) ISSUE(com.epam.ta.reportportal.jooq.tables.JIssue.ISSUE) Lists(com.google.common.collect.Lists) CRITERIA_DURATION(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_DURATION) HealthCheckTableGetParams(com.epam.ta.reportportal.entity.widget.content.healthcheck.HealthCheckTableGetParams) QueryUtils(com.epam.ta.reportportal.dao.util.QueryUtils) JooqFieldNameTransformer.fieldName(com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName) STATISTICS_KEY(com.epam.ta.reportportal.commons.querygen.QueryBuilder.STATISTICS_KEY) Nullable(javax.annotation.Nullable) CriteriaHolder(com.epam.ta.reportportal.commons.querygen.CriteriaHolder) JTestItemTypeEnum(com.epam.ta.reportportal.jooq.enums.JTestItemTypeEnum) Optional.ofNullable(java.util.Optional.ofNullable) WidgetContentUtil(com.epam.ta.reportportal.dao.util.WidgetContentUtil) JItemAttribute(com.epam.ta.reportportal.jooq.tables.JItemAttribute) ID(com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID) WidgetSortUtils(com.epam.ta.reportportal.util.WidgetSortUtils) TEST_ITEM(com.epam.ta.reportportal.jooq.tables.JTestItem.TEST_ITEM) LAUNCH(com.epam.ta.reportportal.jooq.tables.JLaunch.LAUNCH) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Aggregations

ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)33 Test (org.junit.jupiter.api.Test)7 InputStream (java.io.InputStream)6 AuthIntegrationType (com.epam.reportportal.auth.integration.AuthIntegrationType)5 BaseTest (com.epam.ta.reportportal.BaseTest)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 Integration (com.epam.ta.reportportal.entity.integration.Integration)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 IntegrationType (com.epam.ta.reportportal.entity.integration.IntegrationType)3 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)3 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)3 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 QueryBuilder (com.epam.ta.reportportal.commons.querygen.QueryBuilder)2 ID (com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID)2 JooqFieldNameTransformer.fieldName (com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName)2 QueryUtils (com.epam.ta.reportportal.dao.util.QueryUtils)2 ServerSettings (com.epam.ta.reportportal.database.entity.settings.ServerSettings)2 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)2 Log (com.epam.ta.reportportal.entity.log.Log)2 JStatusEnum (com.epam.ta.reportportal.jooq.enums.JStatusEnum)2