use of io.gravitee.common.http.HttpStatusCode.OK_200 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.common.http.HttpStatusCode.OK_200 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.common.http.HttpStatusCode.OK_200 in project gravitee-management-rest-api by gravitee-io.
the class ApiSubscribersResourceTest method shouldGetApiSubscribersNotAsPrimaryOwner.
@Test
public void shouldGetApiSubscribersNotAsPrimaryOwner() {
ApiEntity mockApi = new ApiEntity();
mockApi.setId(API);
UserEntity user = new UserEntity();
user.setId("ANOTHER_NAME");
PrimaryOwnerEntity primaryOwner = new PrimaryOwnerEntity(user);
mockApi.setPrimaryOwner(primaryOwner);
Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
doReturn(mockApis).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
TopHitsAnalytics mockAnalytics = new TopHitsAnalytics();
Map<String, Long> mockedValues = new HashMap<>();
mockedValues.put("A", 10L);
mockedValues.put("B", 20L);
mockedValues.put("C", 30L);
mockAnalytics.setValues(mockedValues);
doReturn(mockAnalytics).when(analyticsService).execute(any(GroupByQuery.class));
SubscriptionEntity subA1 = new SubscriptionEntity();
subA1.setApplication("A");
subA1.setApi(API);
SubscriptionEntity subC1 = new SubscriptionEntity();
subC1.setApplication("C");
subC1.setApi(API);
doReturn(Arrays.asList(subA1, subC1)).when(subscriptionService).search(any());
ApplicationEntity appA = new ApplicationEntity();
appA.setId("A");
doReturn(appA).when(applicationService).findById("A");
doReturn(new Application().id("A")).when(applicationMapper).convert(eq(appA), any());
ApplicationEntity appC = new ApplicationEntity();
appC.setId("C");
doReturn(appC).when(applicationService).findById("C");
doReturn(new Application().id("C")).when(applicationMapper).convert(eq(appC), any());
ApplicationListItem appLIA = new ApplicationListItem();
appLIA.setId("A");
ApplicationListItem appLIC = new ApplicationListItem();
appLIC.setId("C");
doReturn(new HashSet<>(Arrays.asList(appLIA, appLIC))).when(applicationService).findByUser(USER_NAME);
final Response response = target(API).path("subscribers").request().get();
assertEquals(OK_200, response.getStatus());
ArgumentCaptor<SubscriptionQuery> queryCaptor = ArgumentCaptor.forClass(SubscriptionQuery.class);
Mockito.verify(subscriptionService).search(queryCaptor.capture());
SubscriptionQuery value = queryCaptor.getValue();
assertNotNull(value.getApplications());
assertEquals(2, value.getApplications().size());
assertTrue(value.getApplications().contains("A"));
assertTrue(value.getApplications().contains("C"));
final ApplicationsResponse applicationsResponse = response.readEntity(ApplicationsResponse.class);
assertNotNull(applicationsResponse);
assertEquals(2, applicationsResponse.getData().size());
assertEquals("C", applicationsResponse.getData().get(0).getId());
assertEquals("A", applicationsResponse.getData().get(1).getId());
}
Aggregations