Search in sources :

Example 1 with TicketEntity

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

the class PlatformTicketsResourceTest method setUp.

@Before
public void setUp() {
    reset(ticketService);
    fakeTicketEntity = new TicketEntity();
    fakeTicketEntity.setId(TICKET);
    fakeTicketEntity.setSubject("subject");
}
Also used : TicketEntity(io.gravitee.rest.api.model.TicketEntity) Before(org.junit.Before)

Example 2 with TicketEntity

use of io.gravitee.rest.api.model.TicketEntity 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());
}
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) 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 3 with TicketEntity

use of io.gravitee.rest.api.model.TicketEntity 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);
}
Also used : PageableImpl(io.gravitee.rest.api.model.common.PageableImpl) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) Sortable(io.gravitee.rest.api.model.common.Sortable) HashMap(java.util.HashMap) TicketEntity(io.gravitee.rest.api.model.TicketEntity) HashMap(java.util.HashMap) Map(java.util.Map) TicketQuery(io.gravitee.rest.api.model.api.TicketQuery)

Example 4 with TicketEntity

use of io.gravitee.rest.api.model.TicketEntity 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)

Aggregations

TicketEntity (io.gravitee.rest.api.model.TicketEntity)4 TicketQuery (io.gravitee.rest.api.model.api.TicketQuery)3 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)3 Page (io.gravitee.common.data.domain.Page)2 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)2 ParameterReferenceType (io.gravitee.rest.api.model.parameters.ParameterReferenceType)2 TicketInput (io.gravitee.rest.api.portal.rest.model.TicketInput)2 TicketsResponse (io.gravitee.rest.api.portal.rest.model.TicketsResponse)2 Collections.singletonList (java.util.Collections.singletonList)2 Entity (javax.ws.rs.client.Entity)2 HttpHeaders (javax.ws.rs.core.HttpHeaders)2 Response (javax.ws.rs.core.Response)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNull (org.junit.Assert.assertNull)2 Test (org.junit.Test)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 ArgumentMatchers (org.mockito.ArgumentMatchers)2 Mockito (org.mockito.Mockito)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2