Search in sources :

Example 26 with ApiEntity

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

the class ApiMetricsResourceTest method shouldNotFoundApiWhileGettingApiMetrics.

@Test
public void shouldNotFoundApiWhileGettingApiMetrics() {
    // init
    ApiEntity userApi = new ApiEntity();
    userApi.setId("1");
    doReturn(emptySet()).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    // test
    final Response response = target(API).path("metrics").request().get();
    assertEquals(NOT_FOUND_404, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.api.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Api [" + API + "] can not be found.", error.getMessage());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) java.util(java.util) Collections.emptySet(java.util.Collections.emptySet) ApiMetrics(io.gravitee.rest.api.portal.rest.model.ApiMetrics) OK_200(io.gravitee.common.http.HttpStatusCode.OK_200) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) NOT_FOUND_404(io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) IOException(java.io.IOException) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Collections.singletonList(java.util.Collections.singletonList) Response(javax.ws.rs.core.Response) StatsQuery(io.gravitee.rest.api.model.analytics.query.StatsQuery) Assert(org.junit.Assert) Mockito.doReturn(org.mockito.Mockito.doReturn) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) Before(org.junit.Before) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 27 with ApiEntity

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

the class ApiPageResourceTest method shouldNotFoundApiWhileGettingApiPage.

@Test
public void shouldNotFoundApiWhileGettingApiPage() {
    // init
    ApiEntity userApi = new ApiEntity();
    userApi.setId("1");
    doReturn(false).when(accessControlService).canAccessApiFromPortal(API);
    // test
    final Response response = target(API).path("pages").path(PAGE).request().get();
    assertEquals(NOT_FOUND_404, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.api.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Api [" + API + "] can not be found.", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 28 with ApiEntity

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

the class ApiPageResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    doReturn(mockApi).when(apiService).findById(API);
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    doReturn(true).when(accessControlService).canAccessApiFromPortal(API);
    PageEntity page1 = new PageEntity();
    page1.setPublished(true);
    page1.setVisibility(Visibility.PUBLIC);
    page1.setContent(PAGE_CONTENT);
    doReturn(page1).when(pageService).findById(PAGE, null);
    doReturn(true).when(accessControlService).canAccessPageFromPortal(API, page1);
    doReturn(new Page()).when(pageMapper).convert(any(), any(), any());
    doReturn(new PageLinks()).when(pageMapper).computePageLinks(any(), any());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) PageLinks(io.gravitee.rest.api.portal.rest.model.PageLinks) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Page(io.gravitee.rest.api.portal.rest.model.Page) Collections.singletonList(java.util.Collections.singletonList) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Mockito.doThrow(org.mockito.Mockito.doThrow) PageNotFoundException(io.gravitee.rest.api.service.exceptions.PageNotFoundException) Builder(javax.ws.rs.client.Invocation.Builder) Response(javax.ws.rs.core.Response) Visibility(io.gravitee.rest.api.model.Visibility) Assert(org.junit.Assert) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) PageEntity(io.gravitee.rest.api.model.PageEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Page(io.gravitee.rest.api.portal.rest.model.Page) PageLinks(io.gravitee.rest.api.portal.rest.model.PageLinks) Before(org.junit.Before)

Example 29 with ApiEntity

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

the class ApiPlansResourceTest method shouldHaveNotFoundWhileGettingApiPlans.

@Test
public void shouldHaveNotFoundWhileGettingApiPlans() {
    // init
    ApiEntity userApi = new ApiEntity();
    userApi.setId("1");
    doReturn(emptySet()).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    // test
    final Response response = target(API).path("plans").request().get();
    assertEquals(NOT_FOUND_404, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.api.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Api [" + API + "] can not be found.", error.getMessage());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Arrays(java.util.Arrays) PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) Collections.emptySet(java.util.Collections.emptySet) OK_200(io.gravitee.common.http.HttpStatusCode.OK_200) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Assert.assertNotNull(org.junit.Assert.assertNotNull) NOT_FOUND_404(io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404) Set(java.util.Set) Plan(io.gravitee.rest.api.portal.rest.model.Plan) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) List(java.util.List) Response(javax.ws.rs.core.Response) io.gravitee.rest.api.model(io.gravitee.rest.api.model) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 30 with ApiEntity

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

the class ApiRatingAnswersResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    RatingEntity ratingEntity = new RatingEntity();
    ratingEntity.setId(RATING);
    ratingEntity.setApi(API);
    ratingEntity.setComment(RATING);
    ratingEntity.setRate(Integer.valueOf(1).byteValue());
    doReturn(ratingEntity).when(ratingService).findById(eq(RATING));
    doReturn(ratingEntity).when(ratingService).createAnswer(any());
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) Assert.assertNotNull(org.junit.Assert.assertNotNull) RatingEntity(io.gravitee.rest.api.model.RatingEntity) io.gravitee.rest.api.portal.rest.model(io.gravitee.rest.api.portal.rest.model) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) Entity(javax.ws.rs.client.Entity) Collections.singletonList(java.util.Collections.singletonList) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Response(javax.ws.rs.core.Response) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) RatingEntity(io.gravitee.rest.api.model.RatingEntity) Before(org.junit.Before)

Aggregations

ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)273 Test (org.junit.Test)180 Response (javax.ws.rs.core.Response)65 Before (org.junit.Before)46 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)35 Error (io.gravitee.rest.api.portal.rest.model.Error)32 java.util (java.util)30 Collectors (java.util.stream.Collectors)27 Mockito.doReturn (org.mockito.Mockito.doReturn)27 Mockito (org.mockito.Mockito)25 ArgumentMatchers (org.mockito.ArgumentMatchers)24 UpdateApiEntity (io.gravitee.rest.api.model.api.UpdateApiEntity)23 Assert (org.junit.Assert)22 Collections.singletonList (java.util.Collections.singletonList)21 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)20 IOException (java.io.IOException)20 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)19 Entity (javax.ws.rs.client.Entity)19 HashSet (java.util.HashSet)18 Api (io.gravitee.repository.management.model.Api)17