use of io.gravitee.rest.api.portal.rest.model.TicketsResponse in project gravitee-management-rest-api by gravitee-io.
the class TicketsResourceTest method shouldSearchTicketsWithoutSorting.
@Test
public void shouldSearchTicketsWithoutSorting() {
resetAllMocks();
TicketEntity ticketEntity = new TicketEntity();
ticketEntity.setId("1");
ArgumentCaptor<TicketQuery> queryCaptor = ArgumentCaptor.forClass(TicketQuery.class);
when(ticketService.search(queryCaptor.capture(), any(), any())).thenReturn(new Page<>(singletonList(ticketEntity), 1, 1, 1));
Response response = target().queryParam("apiId", "apiId").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
TicketQuery query = queryCaptor.getValue();
assertEquals("Criteria user", USER_NAME, query.getFromUser());
assertEquals("Criteria api", "apiId", query.getApi());
verify(ticketService, Mockito.times(1)).search(any(), isNull(), argThat(o -> o.getPageNumber() == 1 && o.getPageSize() == 10));
TicketsResponse ticketsResponse = response.readEntity(TicketsResponse.class);
assertEquals("Ticket list had not the good size", 1, ticketsResponse.getData().size());
}
use of io.gravitee.rest.api.portal.rest.model.TicketsResponse in project gravitee-management-rest-api by gravitee-io.
the class TicketsResourceTest method shouldSearchTickets.
@Test
public void shouldSearchTickets() {
resetAllMocks();
TicketEntity ticketEntity = new TicketEntity();
ticketEntity.setId("1");
ArgumentCaptor<TicketQuery> queryCaptor = ArgumentCaptor.forClass(TicketQuery.class);
ArgumentCaptor<SortableImpl> sortableCaptor = ArgumentCaptor.forClass(SortableImpl.class);
when(ticketService.search(queryCaptor.capture(), sortableCaptor.capture(), any())).thenReturn(new Page<>(singletonList(ticketEntity), 1, 1, 1));
Response response = target().queryParam("page", 1).queryParam("size", 10).queryParam("apiId", "apiId").queryParam("order", "-subject").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
TicketQuery query = queryCaptor.getValue();
SortableImpl sortable = sortableCaptor.getValue();
assertEquals("Criteria user", USER_NAME, query.getFromUser());
assertEquals("Criteria api", "apiId", query.getApi());
assertEquals("Query sort field", "subject", sortable.getField());
assertEquals("Query sort order", false, sortable.isAscOrder());
verify(ticketService, Mockito.times(1)).search(any(), argThat(o -> o.getField().equals("subject") && !o.isAscOrder()), argThat(o -> o.getPageNumber() == 1 && o.getPageSize() == 10));
TicketsResponse ticketsResponse = response.readEntity(TicketsResponse.class);
assertEquals("Ticket list had not the good size", 1, ticketsResponse.getData().size());
}
Aggregations