Search in sources :

Example 6 with WidgetRQ

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());
}
Also used : WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) ErrorRS(com.epam.ta.reportportal.ws.model.ErrorRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 7 with WidgetRQ

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());
}
Also used : WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) ErrorRS(com.epam.ta.reportportal.ws.model.ErrorRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 8 with WidgetRQ

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());
}
Also used : WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) ContentParameters(com.epam.ta.reportportal.ws.model.widget.ContentParameters) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 9 with WidgetRQ

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());
}
Also used : WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) Widget(com.epam.ta.reportportal.entity.widget.Widget) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) MvcResult(org.springframework.test.web.servlet.MvcResult) ContentParameters(com.epam.ta.reportportal.ws.model.widget.ContentParameters) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 10 with WidgetRQ

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"));
}
Also used : AbstractMap(java.util.AbstractMap) HashMap(java.util.HashMap) WidgetRQ(com.epam.ta.reportportal.ws.model.widget.WidgetRQ) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Widget(com.epam.ta.reportportal.entity.widget.Widget) ContentParameters(com.epam.ta.reportportal.ws.model.widget.ContentParameters) Test(org.junit.jupiter.api.Test)

Aggregations

WidgetRQ (com.epam.ta.reportportal.ws.model.widget.WidgetRQ)19 Test (org.junit.jupiter.api.Test)16 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)14 MvcResult (org.springframework.test.web.servlet.MvcResult)11 ErrorRS (com.epam.ta.reportportal.ws.model.ErrorRS)10 ContentParameters (com.epam.ta.reportportal.ws.model.widget.ContentParameters)7 Widget (com.epam.ta.reportportal.entity.widget.Widget)6 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)3 WidgetBuilder (com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)3 ShareableObjectsHandler (com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler)2 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 Condition (com.epam.ta.reportportal.commons.querygen.Condition)2 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 ProjectFilter (com.epam.ta.reportportal.commons.querygen.ProjectFilter)2 EntryCreatedRS (com.epam.ta.reportportal.ws.model.EntryCreatedRS)2 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)2 List (java.util.List)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Pageable (org.springframework.data.domain.Pageable)2 Service (org.springframework.stereotype.Service)2