Search in sources :

Example 6 with TicketQuery

use of io.gravitee.rest.api.model.api.TicketQuery in project gravitee-management-rest-api by gravitee-io.

the class PlatformTicketsResource method getTickets.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Search for platform tickets written by current user")
@ApiResponses({ @ApiResponse(code = 200, message = "List platform tickets written by current user", response = Page.class), @ApiResponse(code = 500, message = "Internal server error") })
public Page<TicketEntity> getTickets(@Valid @BeanParam Pageable pageable, @Valid @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().isOrder());
    }
    return ticketService.search(query, sortable, pageable.toPageable());
}
Also used : SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) Sortable(io.gravitee.rest.api.model.common.Sortable) TicketQuery(io.gravitee.rest.api.model.api.TicketQuery) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with TicketQuery

use of io.gravitee.rest.api.model.api.TicketQuery 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());
}
Also used : TicketsResponse(io.gravitee.rest.api.portal.rest.model.TicketsResponse) Response(javax.ws.rs.core.Response) ArgumentMatchers(org.mockito.ArgumentMatchers) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) Page(io.gravitee.common.data.domain.Page) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Entity(javax.ws.rs.client.Entity) TicketInput(io.gravitee.rest.api.portal.rest.model.TicketInput) Collections.singletonList(java.util.Collections.singletonList) Mockito.verify(org.mockito.Mockito.verify) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) TicketsResponse(io.gravitee.rest.api.portal.rest.model.TicketsResponse) TicketEntity(io.gravitee.rest.api.model.TicketEntity) Mockito(org.mockito.Mockito) Assert.assertNull(org.junit.Assert.assertNull) HttpHeaders(javax.ws.rs.core.HttpHeaders) ArgumentCaptor(org.mockito.ArgumentCaptor) Response(javax.ws.rs.core.Response) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) TicketQuery(io.gravitee.rest.api.model.api.TicketQuery) Assert.assertEquals(org.junit.Assert.assertEquals) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) TicketEntity(io.gravitee.rest.api.model.TicketEntity) TicketsResponse(io.gravitee.rest.api.portal.rest.model.TicketsResponse) TicketQuery(io.gravitee.rest.api.model.api.TicketQuery) Test(org.junit.Test)

Example 8 with TicketQuery

use of io.gravitee.rest.api.model.api.TicketQuery in project gravitee-management-rest-api by gravitee-io.

the class TicketServiceTest method shouldNotSearchSearchIfRepositoryThrowException.

@Test(expected = TechnicalManagementException.class)
public void shouldNotSearchSearchIfRepositoryThrowException() 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);
    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))).thenThrow(new TechnicalException());
    TicketQuery query = new TicketQuery();
    query.setFromUser("fromUser");
    ticketService.search(query, new SortableImpl("subject", true), new PageableImpl(1, Integer.MAX_VALUE));
}
Also used : PageableImpl(io.gravitee.rest.api.model.common.PageableImpl) Ticket(io.gravitee.repository.management.model.Ticket) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) Pageable(io.gravitee.repository.management.api.search.Pageable) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Sortable(io.gravitee.repository.management.api.search.Sortable) TicketCriteria(io.gravitee.repository.management.api.search.TicketCriteria) TicketQuery(io.gravitee.rest.api.model.api.TicketQuery) Test(org.junit.Test)

Aggregations

TicketQuery (io.gravitee.rest.api.model.api.TicketQuery)8 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)8 Test (org.junit.Test)6 TicketEntity (io.gravitee.rest.api.model.TicketEntity)5 Page (io.gravitee.common.data.domain.Page)4 Collections.singletonList (java.util.Collections.singletonList)4 Response (javax.ws.rs.core.Response)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 ArgumentCaptor (org.mockito.ArgumentCaptor)4 Mockito (org.mockito.Mockito)4 Mockito.verify (org.mockito.Mockito.verify)4 Mockito.when (org.mockito.Mockito.when)4 PageableImpl (io.gravitee.rest.api.model.common.PageableImpl)3 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)2 NOT_FOUND_404 (io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404)2 OK_200 (io.gravitee.common.http.HttpStatusCode.OK_200)2 Pageable (io.gravitee.repository.management.api.search.Pageable)2 Sortable (io.gravitee.repository.management.api.search.Sortable)2 TicketCriteria (io.gravitee.repository.management.api.search.TicketCriteria)2 Ticket (io.gravitee.repository.management.model.Ticket)2