use of com.epam.ta.reportportal.ws.model.widget.WidgetRQ in project service-api by reportportal.
the class WidgetControllerValidationTest method updateWidgetShouldReturnErrorWhenNameIsNull.
@Test
public void updateWidgetShouldReturnErrorWhenNameIsNull() throws Exception {
// GIVEN
WidgetRQ widgetRQ = prepareWidget();
// WHEN
MvcResult mvcResult = mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + WIDGET_PATH + ID_PATH).with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(widgetRQ)).contentType(APPLICATION_JSON)).andExpect(status().isBadRequest()).andReturn();
// THEN
ErrorRS error = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ErrorRS.class);
assertEquals(INCORRECT_REQUEST, error.getErrorType());
assertEquals(INCORRECT_REQUEST_MESSAGE + FIELD_NAME_IS_NULL_MESSAGE, error.getMessage());
}
use of com.epam.ta.reportportal.ws.model.widget.WidgetRQ in project service-api by reportportal.
the class CreateWidgetHandlerImpl method createWidget.
@Override
public EntryCreatedRS createWidget(WidgetRQ createWidgetRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
List<UserFilter> userFilter = getUserFilters(createWidgetRQ.getFilterIds(), projectDetails.getProjectId(), user.getUsername());
BusinessRule.expect(widgetRepository.existsByNameAndOwnerAndProjectId(createWidgetRQ.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.RESOURCE_ALREADY_EXISTS, createWidgetRQ.getName());
Widget widget = new WidgetBuilder().addWidgetRq(createWidgetRQ).addProject(projectDetails.getProjectId()).addFilters(userFilter).addOwner(user.getUsername()).get();
widgetContentFieldsValidator.validate(widget);
widgetPostProcessors.stream().filter(widgetPostProcessor -> widgetPostProcessor.supports(widget)).forEach(widgetPostProcessor -> widgetPostProcessor.postProcess(widget));
widgetRepository.save(widget);
aclHandler.initAcl(widget, user.getUsername(), projectDetails.getProjectId(), BooleanUtils.isTrue(createWidgetRQ.getShare()));
if (widget.isShared()) {
ofNullable(widget.getFilters()).ifPresent(filters -> updateUserFilterHandler.updateSharing(filters, projectDetails.getProjectId(), widget.isShared()));
}
messageBus.publishActivity(new WidgetCreatedEvent(TO_ACTIVITY_RESOURCE.apply(widget), user.getUserId(), user.getUsername()));
return new EntryCreatedRS(widget.getId());
}
use of com.epam.ta.reportportal.ws.model.widget.WidgetRQ in project service-api by reportportal.
the class HealthCheckTableReadyContentResolverTest method getContentTest.
@Test
void getContentTest() {
WidgetRQ widgetRQ = new WidgetRQ();
widgetRQ.setName("name");
widgetRQ.setWidgetType("componentHealthCheckTable");
ContentParameters contentParameters = new ContentParameters();
contentParameters.setContentFields(new ArrayList<>());
contentParameters.setItemsCount(600);
Map<String, Object> options = new HashMap<>();
contentParameters.setWidgetOptions(options);
widgetRQ.setContentParameters(contentParameters);
widgetRQ.setFilterIds(Collections.singletonList(1L));
widgetRQ.setDescription("descr");
SortEntry sortEntry = new SortEntry();
sortEntry.setSortingColumn("passingRate");
Widget widget = new WidgetBuilder().addWidgetRq(widgetRQ).addOption("viewName", "name").addOption("sort", sortEntry).addOption(ATTRIBUTE_KEYS, Lists.newArrayList("k1", "k2")).get();
HealthCheckTableContent content = new HealthCheckTableContent();
content.setAttributeValue("v2");
content.setPassingRate(50.00);
HashMap<String, Integer> statistics = new HashMap<>();
statistics.put(EXECUTIONS_PASSED, 5);
statistics.put(EXECUTIONS_TOTAL, 10);
content.setStatistics(statistics);
when(widgetContentRepository.componentHealthCheckTable(any())).thenReturn(Lists.newArrayList(content));
MultiValueMap<String, String> values = new LinkedMultiValueMap<>();
values.put(ATTRIBUTES, Lists.newArrayList("v1"));
Map<String, Object> result = contentResolver.loadContent(widget, values);
List<HealthCheckTableContent> resultList = (List<HealthCheckTableContent>) result.get("result");
HealthCheckTableContent tableContent = resultList.get(0);
assertEquals(content.getPassingRate(), tableContent.getPassingRate());
assertEquals(content.getAttributeValue(), tableContent.getAttributeValue());
}
use of com.epam.ta.reportportal.ws.model.widget.WidgetRQ in project service-api by reportportal.
the class DemoDashboardsService method createWidgets.
private List<Widget> createWidgets(ReportPortalUser user, Long projectId, UserFilter filter) {
try {
TypeReference<List<WidgetRQ>> type = new TypeReference<>() {
};
List<Widget> widgets = objectMapper.readValue(resource.getURL(), type).stream().map(it -> {
final WidgetBuilder widgetBuilder = new WidgetBuilder().addWidgetRq(it).addProject(projectId).addOwner(user.getUsername());
final WidgetType widgetType = WidgetType.findByName(it.getWidgetType()).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_TO_CREATE_WIDGET, "Widget type '" + it.getWidgetType() + "' does not exists"));
if (!WidgetType.FLAKY_TEST_CASES.equals(widgetType) || !WidgetType.TOP_TEST_CASES.equals(widgetType)) {
widgetBuilder.addFilters(Sets.newHashSet(filter));
}
return widgetBuilder.get();
}).collect(toList());
widgetRepository.saveAll(widgets);
widgets.forEach(it -> aclHandler.initAcl(it, user.getUsername(), projectId, it.isShared()));
return widgets;
} catch (IOException e) {
throw new ReportPortalException("Unable to load demo_widgets.json. " + e.getMessage(), e);
}
}
Aggregations