Search in sources :

Example 31 with WidgetOptions

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

the class BugTrendChartContentValidatorTest 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());
        bugTrendChartContentValidator.validate(Collections.singletonList("statistics$defects$automation_bug$total'"), 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)

Example 32 with WidgetOptions

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

the class ChartInvestigatedContentValidatorTest method testValidateWithException.

@Test
public void testValidateWithException() {
    Exception exception = assertThrows(ReportPortalException.class, () -> {
        chartInvestigatedContentValidator.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 33 with WidgetOptions

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

the class WidgetBuilder method addOption.

public WidgetBuilder addOption(String key, Object value) {
    WidgetOptions widgetOptions = ofNullable(widget.getWidgetOptions()).orElseGet(() -> {
        WidgetOptions opts = new WidgetOptions();
        widget.setWidgetOptions(opts);
        return opts;
    });
    Map<String, Object> options = ofNullable(widgetOptions.getOptions()).orElseGet(() -> {
        LinkedHashMap<String, Object> opts = new LinkedHashMap<>();
        widgetOptions.setOptions(opts);
        return opts;
    });
    options.put(key, value);
    return this;
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) LinkedHashMap(java.util.LinkedHashMap)

Example 34 with WidgetOptions

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

the class WidgetBuilder method addWidgetRq.

public WidgetBuilder addWidgetRq(WidgetRQ widgetRQ) {
    ofNullable(widgetRQ.getName()).ifPresent(name -> widget.setName(name));
    ofNullable(widgetRQ.getShare()).ifPresent(it -> widget.setShared(it));
    widget.setDescription(widgetRQ.getDescription());
    ofNullable(widgetRQ.getContentParameters().getWidgetOptions()).ifPresent(wo -> {
        WidgetOptions widgetOptions = ofNullable(widget.getWidgetOptions()).orElseGet(WidgetOptions::new);
        Map<String, Object> options = ofNullable(widgetOptions.getOptions()).orElseGet(LinkedHashMap::new);
        options.putAll(wo);
        widgetOptions.setOptions(options);
        widget.setWidgetOptions(widgetOptions);
    });
    widget.setWidgetType(widgetRQ.getWidgetType());
    widget.setItemsCount(widgetRQ.getContentParameters().getItemsCount());
    widget.getContentFields().clear();
    widget.getContentFields().addAll(ofNullable(widgetRQ.getContentParameters().getContentFields()).orElse(Collections.emptyList()));
    return this;
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) LinkedHashMap(java.util.LinkedHashMap)

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