use of com.epam.ta.reportportal.ws.model.widget.WidgetRQ in project service-api by reportportal.
the class WidgetControllerValidationTest method createWidgetShouldReturnErrorWhenNameConsistsOfWhitespaces.
@Test
public void createWidgetShouldReturnErrorWhenNameConsistsOfWhitespaces() throws Exception {
// GIVEN
WidgetRQ widgetRQ = prepareWidget();
widgetRQ.setName(WHITESPACES_NAME_VALUE);
// WHEN
MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + WIDGET_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_BLANK_MESSAGE + " " + FIELD_NAME_SIZE_MESSAGE + "] ", error.getMessage());
}
use of com.epam.ta.reportportal.ws.model.widget.WidgetRQ in project service-api by reportportal.
the class WidgetControllerValidationTest method updateWidgetShouldReturnErrorWhenNameIsLessThanThreeCharacters.
@Test
public void updateWidgetShouldReturnErrorWhenNameIsLessThanThreeCharacters() throws Exception {
// GIVEN
WidgetRQ widgetRQ = prepareWidget();
widgetRQ.setName(SHORT_NAME_VALUE);
// 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_SIZE_MESSAGE + "] ", error.getMessage());
}
use of com.epam.ta.reportportal.ws.model.widget.WidgetRQ in project service-api by reportportal.
the class WidgetControllerTest method updateWidgetWithDuplicatedName.
@Test
void updateWidgetWithDuplicatedName() throws Exception {
final WidgetRQ rq = new WidgetRQ();
rq.setName("LAUNCH STATISTICS");
rq.setDescription("updated");
rq.setWidgetType("activityStream");
rq.setShare(false);
final ContentParameters contentParameters = new ContentParameters();
contentParameters.setContentFields(Arrays.asList("number", "start_time", "user"));
contentParameters.setItemsCount(50);
rq.setContentParameters(contentParameters);
mockMvc.perform(put(SUPERADMIN_PROJECT_BASE_URL + "/widget/5").with(token(oAuthHelper.getSuperadminToken())).content(objectMapper.writeValueAsBytes(rq)).contentType(APPLICATION_JSON)).andExpect(status().isConflict());
}
use of com.epam.ta.reportportal.ws.model.widget.WidgetRQ in project service-api by reportportal.
the class WidgetControllerTest method createWidgetPositive.
@Test
void createWidgetPositive() throws Exception {
WidgetRQ rq = new WidgetRQ();
rq.setName("widget");
rq.setDescription("description");
rq.setWidgetType("oldLineChart");
ContentParameters contentParameters = new ContentParameters();
contentParameters.setContentFields(Collections.singletonList("statistics$executions$passed"));
contentParameters.setItemsCount(50);
rq.setFilterIds(Collections.singletonList(3L));
rq.setContentParameters(contentParameters);
rq.setShare(true);
final MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/widget").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(rq)).contentType(APPLICATION_JSON)).andExpect(status().isCreated()).andReturn();
final EntryCreatedRS entryCreatedRS = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), EntryCreatedRS.class);
final Optional<Widget> optionalWidget = widgetRepository.findById(entryCreatedRS.getId());
assertTrue(optionalWidget.isPresent());
assertEquals("widget", optionalWidget.get().getName());
assertEquals("description", optionalWidget.get().getDescription());
}
use of com.epam.ta.reportportal.ws.model.widget.WidgetRQ in project service-api by reportportal.
the class WidgetBuilderTest method widgetBuilderTest.
@Test
void widgetBuilderTest() {
final WidgetRQ widgetRQ = new WidgetRQ();
final String name = "name";
widgetRQ.setName(name);
final String description = "description";
widgetRQ.setDescription(description);
final boolean share = true;
widgetRQ.setShare(share);
final String widgetType = "oldLineChart";
widgetRQ.setWidgetType(widgetType);
final ContentParameters contentParameters = new ContentParameters();
contentParameters.setContentFields(Collections.singletonList("contentField"));
contentParameters.setItemsCount(10);
final HashMap<String, Object> widgetOptions = new HashMap<>();
widgetOptions.put("param", "val");
contentParameters.setWidgetOptions(widgetOptions);
widgetRQ.setContentParameters(contentParameters);
final String owner = "owner";
final UserFilter userFilter = new UserFilter();
userFilter.setId(1L);
final Widget widget = new WidgetBuilder().addWidgetRq(widgetRQ).addFilters(Collections.singletonList(userFilter)).addOwner(owner).get();
assertEquals(name, widget.getName());
assertEquals(description, widget.getDescription());
assertEquals(share, widget.isShared());
assertEquals(owner, widget.getOwner());
assertEquals(widgetType, widget.getWidgetType());
assertThat(widget.getFilters()).containsExactly(userFilter);
assertThat(widget.getContentFields()).containsExactly("contentField");
assertThat(widget.getWidgetOptions().getOptions()).containsExactly(new AbstractMap.SimpleEntry<>("param", "val"));
}
Aggregations