Search in sources :

Example 6 with CategoryEntity

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

the class CategoryResourceTest method init.

@Before
public void init() {
    mockCategory = new CategoryEntity();
    mockCategory.setId(CATEGORY);
    mockCategory.setName(CATEGORY);
    mockCategory.setUpdatedAt(new Date());
    doReturn(mockCategory).when(categoryService).findById(CATEGORY);
    updateCategoryEntity = new UpdateCategoryEntity();
    updateCategoryEntity.setDescription("toto");
    updateCategoryEntity.setName(CATEGORY);
    doReturn(mockCategory).when(categoryService).update(eq(CATEGORY), any());
}
Also used : UpdateCategoryEntity(io.gravitee.rest.api.model.UpdateCategoryEntity) Date(java.util.Date) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) UpdateCategoryEntity(io.gravitee.rest.api.model.UpdateCategoryEntity) Before(org.junit.Before)

Example 7 with CategoryEntity

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

the class CategoriesResourceNotAuthenticatedTest method init.

@Before
public void init() {
    resetAllMocks();
    Set<ApiEntity> mockApis = new HashSet<>();
    doReturn(mockApis).when(apiService).findPublishedByUser(any());
    CategoryEntity category1 = new CategoryEntity();
    category1.setId("1");
    category1.setHidden(false);
    category1.setOrder(2);
    CategoryEntity category2 = new CategoryEntity();
    category2.setId("2");
    category2.setHidden(false);
    category2.setOrder(3);
    CategoryEntity category3 = new CategoryEntity();
    category3.setId("3");
    category3.setHidden(true);
    category3.setOrder(1);
    List<CategoryEntity> mockCategories = Arrays.asList(category1, category2, category3);
    doReturn(mockCategories).when(categoryService).findAll();
    doReturn(1L).when(categoryService).getTotalApisByCategory(any(), any());
    doReturn(false).when(ratingService).isEnabled();
    Mockito.when(categoryMapper.convert(any(), any())).thenCallRealMethod();
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) HashSet(java.util.HashSet) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Before(org.junit.Before)

Example 8 with CategoryEntity

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

the class CategoryResourceNotAuthenticatedTest method init.

@Before
public void init() throws IOException, URISyntaxException {
    resetAllMocks();
    CategoryEntity categoryEntity = new CategoryEntity();
    categoryEntity.setId(CATEGORY_ID);
    categoryEntity.setHidden(false);
    doReturn(categoryEntity).when(categoryService).findNotHiddenById(CATEGORY_ID);
    Set<ApiEntity> mockApis = new HashSet<>();
    doReturn(mockApis).when(apiService).findPublishedByUser(any());
    Mockito.when(categoryMapper.convert(any(), any())).thenCallRealMethod();
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 9 with CategoryEntity

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

the class ApisResourceTest method shouldHavePromotedApiIfCategoryWithoutHighLightedApi.

@Test
public void shouldHavePromotedApiIfCategoryWithoutHighLightedApi() throws TechnicalException {
    doReturn(new CategoryEntity()).when(categoryService).findById("myCat");
    final Response response = target().queryParam("size", 3).queryParam("promoted", true).queryParam("category", "myCat").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    ArgumentCaptor<ApiEntity> apiEntityCaptor = ArgumentCaptor.forClass(ApiEntity.class);
    Mockito.verify(apiMapper, Mockito.times(1)).convert(apiEntityCaptor.capture());
    final List<String> allNameValues = apiEntityCaptor.getAllValues().stream().map(a -> a.getName()).collect(Collectors.toList());
    assertEquals(1, allNameValues.size());
    assertTrue(allNameValues.containsAll(Arrays.asList("1")));
    ApisResponse apiResponse = response.readEntity(ApisResponse.class);
    assertEquals(1, apiResponse.getData().size());
}
Also used : Response(javax.ws.rs.core.Response) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) ApiLifecycleState(io.gravitee.rest.api.model.api.ApiLifecycleState) io.gravitee.rest.api.portal.rest.model(io.gravitee.rest.api.portal.rest.model) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Mockito(org.mockito.Mockito) ArgumentCaptor(org.mockito.ArgumentCaptor) Response(javax.ws.rs.core.Response) Assert(org.junit.Assert) Mockito.doReturn(org.mockito.Mockito.doReturn) FilteredEntities(io.gravitee.rest.api.model.filtering.FilteredEntities) Before(org.junit.Before) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Test(org.junit.Test)

Example 10 with CategoryEntity

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

the class ApisResourceTest method shouldHaveAllButPromotedApiIfCategoryWithHighLightedApi.

@Test
public void shouldHaveAllButPromotedApiIfCategoryWithHighLightedApi() throws TechnicalException {
    CategoryEntity myCatEntity = new CategoryEntity();
    myCatEntity.setHighlightApi("4");
    doReturn(myCatEntity).when(categoryService).findById("myCat");
    final Response response = target().queryParam("size", 3).queryParam("promoted", false).queryParam("category", "myCat").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    ArgumentCaptor<ApiEntity> apiEntityCaptor = ArgumentCaptor.forClass(ApiEntity.class);
    Mockito.verify(apiMapper, Mockito.times(4)).convert(apiEntityCaptor.capture());
    final List<String> allNameValues = apiEntityCaptor.getAllValues().stream().map(a -> a.getName()).collect(Collectors.toList());
    assertEquals(4, allNameValues.size());
    assertTrue(allNameValues.containsAll(Arrays.asList("1", "3", "5", "6")));
    ApisResponse apiResponse = response.readEntity(ApisResponse.class);
    assertEquals(3, apiResponse.getData().size());
}
Also used : Response(javax.ws.rs.core.Response) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) ApiLifecycleState(io.gravitee.rest.api.model.api.ApiLifecycleState) io.gravitee.rest.api.portal.rest.model(io.gravitee.rest.api.portal.rest.model) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Mockito(org.mockito.Mockito) ArgumentCaptor(org.mockito.ArgumentCaptor) Response(javax.ws.rs.core.Response) Assert(org.junit.Assert) Mockito.doReturn(org.mockito.Mockito.doReturn) FilteredEntities(io.gravitee.rest.api.model.filtering.FilteredEntities) Before(org.junit.Before) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Test(org.junit.Test)

Aggregations

CategoryEntity (io.gravitee.rest.api.model.CategoryEntity)29 Test (org.junit.Test)14 UpdateCategoryEntity (io.gravitee.rest.api.model.UpdateCategoryEntity)13 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)12 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)12 Before (org.junit.Before)11 Assert (org.junit.Assert)9 Mockito (org.mockito.Mockito)9 Category (io.gravitee.repository.management.model.Category)7 NewCategoryEntity (io.gravitee.rest.api.model.NewCategoryEntity)7 java.util (java.util)7 Collectors (java.util.stream.Collectors)7 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)6 ApiLifecycleState (io.gravitee.rest.api.model.api.ApiLifecycleState)6 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)6 FilteredEntities (io.gravitee.rest.api.model.filtering.FilteredEntities)6 io.gravitee.rest.api.portal.rest.model (io.gravitee.rest.api.portal.rest.model)6 Error (io.gravitee.rest.api.portal.rest.model.Error)6 Entity (javax.ws.rs.client.Entity)6 Response (javax.ws.rs.core.Response)6