use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiRatingsResourceTest method shouldBadRequestWhileCreatingApiRatings.
@Test
public void shouldBadRequestWhileCreatingApiRatings() {
// init
ApiEntity userApi = new ApiEntity();
userApi.setId("1");
Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(userApi));
doReturn(mockApis).when(apiService).findPublishedByUser(any());
// test
final Response response = target(API).path("ratings").request().post(Entity.json(null));
assertEquals(BAD_REQUEST_400, 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.unexpected", error.getCode());
assertEquals("400", error.getStatus());
assertEquals("Input must not be null.", error.getMessage());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiRatingsResourceTest method init.
@Before
public void init() throws IOException {
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 rating1 = new RatingEntity();
RatingEntity rating2 = new RatingEntity();
List<RatingEntity> ratingEntityPage = Arrays.asList(rating1, rating2);
doReturn(ratingEntityPage).when(ratingService).findByApi(eq(API));
Rating rating = new Rating();
rating.setId(RATING);
rating.setComment(RATING);
rating.setValue(1);
doReturn(rating).when(ratingMapper).convert(any(), any());
RatingEntity createdRating = new RatingEntity();
createdRating.setId(RATING);
createdRating.setComment(RATING);
createdRating.setRate((byte) 1);
doReturn(createdRating).when(ratingService).create(any());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiResourceTest method shouldHaveNotFoundWhileGettingApiPicture.
@Test
public void shouldHaveNotFoundWhileGettingApiPicture() {
// init
ApiEntity userApi = new ApiEntity();
userApi.setId("1");
Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(userApi));
doReturn(mockApis).when(apiService).findByUser(any(), any(), eq(true));
// test
final Response response = target(API).path("picture").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());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiResourceTest method shouldHaveNotFoundWhileGettingApi.
@Test
public void shouldHaveNotFoundWhileGettingApi() {
// init
ApiEntity userApi = new ApiEntity();
userApi.setId("1");
doReturn(false).when(accessControlService).canAccessApiFromPortal(API);
// test
final Response response = target(API).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());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApisResourceNotAuthenticatedTest method init.
@Before
public void init() {
resetAllMocks();
ApiEntity publishedApi = new ApiEntity();
publishedApi.setLifecycleState(ApiLifecycleState.PUBLISHED);
publishedApi.setName("A");
publishedApi.setId("A");
ApiEntity unpublishedApi = new ApiEntity();
unpublishedApi.setLifecycleState(ApiLifecycleState.UNPUBLISHED);
unpublishedApi.setName("B");
unpublishedApi.setId("B");
ApiEntity anotherPublishedApi = new ApiEntity();
anotherPublishedApi.setLifecycleState(ApiLifecycleState.PUBLISHED);
anotherPublishedApi.setName("C");
anotherPublishedApi.setId("C");
Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(publishedApi, anotherPublishedApi));
doReturn(mockApis).when(apiService).findPublishedByUser(isNull(), any(ApiQuery.class));
doReturn(new FilteredEntities<ApiEntity>(new ArrayList<>(mockApis), null)).when(filteringService).filterApis(any(), any(), any());
doReturn(false).when(ratingService).isEnabled();
doReturn(new Api().name("A").id("A")).when(apiMapper).convert(publishedApi);
doReturn(new Api().name("B").id("B")).when(apiMapper).convert(unpublishedApi);
doReturn(new Api().name("C").id("C")).when(apiMapper).convert(anotherPublishedApi);
}
Aggregations