use of io.gravitee.rest.api.model.api.TicketQuery in project gravitee-management-rest-api by gravitee-io.
the class PlatformTicketsResourceTest method shouldSearchTickets.
@Test
public void shouldSearchTickets() {
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(fakeTicketEntity), 1, 1, 1));
Response response = envTarget().queryParam("page", 1).queryParam("size", 10).queryParam("order", "-subject").request().get();
assertEquals(OK_200, response.getStatus());
TicketQuery query = queryCaptor.getValue();
SortableImpl sortable = sortableCaptor.getValue();
assertEquals("Query user", USER_NAME, query.getFromUser());
assertEquals("Sort field", "subject", sortable.getField());
assertEquals("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));
}
use of io.gravitee.rest.api.model.api.TicketQuery in project gravitee-management-rest-api by gravitee-io.
the class PlatformTicketsResourceTest method shouldSearchTicketsWithoutSorting.
@Test
public void shouldSearchTicketsWithoutSorting() {
ArgumentCaptor<TicketQuery> queryCaptor = ArgumentCaptor.forClass(TicketQuery.class);
when(ticketService.search(queryCaptor.capture(), any(), any())).thenReturn(new Page<>(singletonList(fakeTicketEntity), 1, 1, 1));
Response response = envTarget().queryParam("page", 1).queryParam("size", 10).request().get();
assertEquals(OK_200, response.getStatus());
TicketQuery query = queryCaptor.getValue();
assertEquals("Query user", USER_NAME, query.getFromUser());
verify(ticketService, Mockito.times(1)).search(any(), isNull(), argThat(o -> o.getPageNumber() == 1 && o.getPageSize() == 10));
}
use of io.gravitee.rest.api.model.api.TicketQuery in project gravitee-management-rest-api by gravitee-io.
the class TicketServiceTest method shouldSearchForTicketsFromUser.
@Test
public void shouldSearchForTicketsFromUser() throws TechnicalException {
Ticket ticket = new Ticket();
ticket.setId("generatedId");
ticket.setApi(API_ID);
ticket.setApplication(APPLICATION_ID);
ticket.setSubject(EMAIL_SUBJECT);
ticket.setContent(EMAIL_CONTENT);
ticket.setCreatedAt(new Date());
ticket.setFromUser(USERNAME);
ApiEntity apiEntity = new ApiEntity();
ApplicationEntity appEntity = new ApplicationEntity();
List<Ticket> ticketList = new ArrayList<>();
for (int i = 0; i < 20; i++) {
Ticket t = new Ticket(ticket);
t.setId("ticket" + i);
ticketList.add(t);
}
when(ticketRepository.search(any(TicketCriteria.class), any(Sortable.class), any(Pageable.class))).thenReturn(new Page<>(ticketList, 0, 20, 20));
when(apiService.findById(API_ID)).thenReturn(apiEntity);
when(applicationService.findById(APPLICATION_ID)).thenReturn(appEntity);
TicketQuery query = new TicketQuery();
query.setFromUser("fromUser");
Page<TicketEntity> searchResult = ticketService.search(query, new SortableImpl("subject", true), new PageableImpl(1, Integer.MAX_VALUE));
assertEquals(searchResult.getContent().size(), 20);
assertEquals(searchResult.getPageNumber(), 1);
assertEquals(searchResult.getTotalElements(), 20);
}
use of io.gravitee.rest.api.model.api.TicketQuery 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.model.api.TicketQuery in project gravitee-management-rest-api by gravitee-io.
the class TicketsResource method getTickets.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getTickets(@Valid @BeanParam PaginationParam paginationParam, @BeanParam TicketsParam ticketsParam) {
TicketQuery query = new TicketQuery();
query.setApi(ticketsParam.getApi());
query.setApplication(ticketsParam.getApplication());
query.setApi(ticketsParam.getApi());
query.setFromUser(getAuthenticatedUser());
Sortable sortable = null;
if (ticketsParam.getOrder() != null) {
sortable = new SortableImpl(ticketsParam.getOrder().getField(), ticketsParam.getOrder().isSorted());
}
Page<TicketEntity> tickets = ticketService.search(query, sortable, new PageableImpl(paginationParam.getPage(), paginationParam.getSize()));
final Map<String, Object> metadataTotal = new HashMap<>();
metadataTotal.put(METADATA_DATA_TOTAL_KEY, tickets.getTotalElements());
final Map<String, Map<String, Object>> metadata = new HashMap<>();
metadata.put(METADATA_DATA_KEY, metadataTotal);
return createListResponse(tickets.getContent(), paginationParam, metadata, false);
}
Aggregations