Search in sources :

Example 6 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class TopPatternContentValidatorTest method testValidateWithException.

@Test
public void testValidateWithException() {
    Exception exception = assertThrows(ReportPortalException.class, () -> {
        topPatternContentValidator.validate(Collections.singletonList("test"), new HashMap<>(), new WidgetOptions(), new String[] {}, new HashMap<>(), 5);
    });
    String expectedMessage = "Filter-Sort mapping should not be empty";
    String actualMessage = exception.getMessage();
    assertTrue(actualMessage.contains(expectedMessage));
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Test(org.junit.jupiter.api.Test)

Example 7 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class LaunchesDurationContentValidatorTest method testValidateWithException.

@Test
public void testValidateWithException() {
    Exception exception = assertThrows(ReportPortalException.class, () -> {
        launchesDurationContentValidator.validate(Collections.singletonList("test"), new HashMap<>(), new WidgetOptions(), 5);
    });
    String expectedMessage = "Filter-Sort mapping should not be empty";
    String actualMessage = exception.getMessage();
    assertTrue(actualMessage.contains(expectedMessage));
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Test(org.junit.jupiter.api.Test)

Example 8 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class ComponentHealthCheckContentLoader method loadContent.

@Override
public Map<String, Object> loadContent(List<String> contentFields, Map<Filter, Sort> filterSortMapping, WidgetOptions widgetOptions, String[] attributes, MultiValueMap<String, String> params, int limit) {
    List<String> attributeKeys = WidgetOptionUtil.getListByKey(ATTRIBUTE_KEYS, widgetOptions);
    List<String> attributeValues = ofNullable(attributes).map(Arrays::asList).orElseGet(Collections::emptyList);
    int currentLevel = attributeValues.size();
    BusinessRule.expect(attributeKeys, keys -> keys.size() > currentLevel).verify(ErrorType.UNABLE_LOAD_WIDGET_CONTENT, "Incorrect level definition");
    Filter launchesFilter = GROUP_FILTERS.apply(filterSortMapping.keySet());
    Sort launchesSort = GROUP_SORTS.apply(filterSortMapping.values());
    boolean latestMode = WidgetOptionUtil.getBooleanByKey(LATEST_OPTION, widgetOptions);
    Filter testItemFilter = Filter.builder().withTarget(TestItem.class).withCondition(getTestItemCondition(attributeKeys, attributeValues)).build();
    String currentLevelKey = attributeKeys.get(currentLevel);
    List<ComponentHealthCheckContent> content = widgetContentRepository.componentHealthCheck(launchesFilter, launchesSort, latestMode, limit, testItemFilter, currentLevelKey);
    return CollectionUtils.isNotEmpty(content) ? Collections.singletonMap(RESULT, content) : emptyMap();
}
Also used : TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) IntStream(java.util.stream.IntStream) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) Arrays(java.util.Arrays) TestItem(com.epam.ta.reportportal.entity.item.TestItem) ContentLoaderConstants(com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) GROUP_FILTERS(com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_FILTERS) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) TestItemCriteriaConstant(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant) CRITERIA_COMPOSITE_ATTRIBUTE(com.epam.ta.reportportal.commons.querygen.constant.ItemAttributeConstant.CRITERIA_COMPOSITE_ATTRIBUTE) Lists(com.google.common.collect.Lists) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) Sort(org.springframework.data.domain.Sort) KEY_VALUE_SEPARATOR(com.epam.ta.reportportal.commons.querygen.constant.ItemAttributeConstant.KEY_VALUE_SEPARATOR) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) GROUP_SORTS(com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_SORTS) Collections.emptyMap(java.util.Collections.emptyMap) Optional.ofNullable(java.util.Optional.ofNullable) WidgetOptionUtil(com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil) MultiValueMap(org.springframework.util.MultiValueMap) MultilevelLoadContentStrategy(com.epam.ta.reportportal.core.widget.content.MultilevelLoadContentStrategy) WidgetContentRepository(com.epam.ta.reportportal.dao.WidgetContentRepository) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) com.epam.ta.reportportal.commons.querygen(com.epam.ta.reportportal.commons.querygen) Collections(java.util.Collections) ComponentHealthCheckContent(com.epam.ta.reportportal.entity.widget.content.healthcheck.ComponentHealthCheckContent) Sort(org.springframework.data.domain.Sort) ComponentHealthCheckContent(com.epam.ta.reportportal.entity.widget.content.healthcheck.ComponentHealthCheckContent) Collections(java.util.Collections)

Example 9 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class MaterializedViewContentRemover method validateState.

private void validateState(WidgetOptions widgetOptions) {
    WidgetState widgetState = ofNullable(WidgetOptionUtil.getValueByKey(STATE, widgetOptions)).flatMap(WidgetState::findByName).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_UPDATE_WIDGET_REQUEST, "Widget state not provided"));
    BusinessRule.expect(widgetState, it -> !WidgetState.RENDERING.equals(it)).verify(ErrorType.BAD_UPDATE_WIDGET_REQUEST, "Unable to remove widget in 'rendering' state");
}
Also used : BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) WidgetState(com.epam.ta.reportportal.entity.widget.WidgetState) VIEW_NAME(com.epam.ta.reportportal.core.widget.content.loader.materialized.handler.MaterializedWidgetStateHandler.VIEW_NAME) Optional.ofNullable(java.util.Optional.ofNullable) WidgetOptionUtil(com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) WidgetContentRepository(com.epam.ta.reportportal.dao.WidgetContentRepository) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) Widget(com.epam.ta.reportportal.entity.widget.Widget) STATE(com.epam.ta.reportportal.core.widget.content.updater.MaterializedWidgetStateUpdater.STATE) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) WidgetState(com.epam.ta.reportportal.entity.widget.WidgetState)

Example 10 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class CasesTrendContentValidatorTest method testValidateWithException.

@Test
public void testValidateWithException() {
    Exception exception = assertThrows(ReportPortalException.class, () -> {
        HashMap<Filter, Sort> filterSortMap = new HashMap<>();
        filterSortMap.put(Filter.builder().withTarget(Launch.class).withCondition(FilterCondition.builder().eq("id", "1").build()).build(), Sort.unsorted());
        casesTrendContentValidator.validate(Collections.singletonList("test"), filterSortMap, new WidgetOptions(), 5);
    });
    String expectedMessage = "Bad content fields format";
    String actualMessage = exception.getMessage();
    assertTrue(actualMessage.contains(expectedMessage));
}
Also used : Filter(com.epam.ta.reportportal.commons.querygen.Filter) HashMap(java.util.HashMap) WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) Sort(org.springframework.data.domain.Sort) Launch(com.epam.ta.reportportal.entity.launch.Launch) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Test(org.junit.jupiter.api.Test)

Aggregations

WidgetOptions (com.epam.ta.reportportal.entity.widget.WidgetOptions)34 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)20 Test (org.junit.jupiter.api.Test)20 Sort (org.springframework.data.domain.Sort)15 Filter (com.epam.ta.reportportal.commons.querygen.Filter)13 WidgetOptionUtil (com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil)10 Launch (com.epam.ta.reportportal.entity.launch.Launch)10 HashMap (java.util.HashMap)10 Optional.ofNullable (java.util.Optional.ofNullable)10 WidgetContentRepository (com.epam.ta.reportportal.dao.WidgetContentRepository)8 Map (java.util.Map)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Service (org.springframework.stereotype.Service)7 ContentLoaderConstants (com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants)6 GROUP_FILTERS (com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_FILTERS)6 List (java.util.List)6 CollectionUtils (org.apache.commons.collections.CollectionUtils)6 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)5 LoadContentStrategy (com.epam.ta.reportportal.core.widget.content.LoadContentStrategy)5 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)5