Search in sources :

Example 21 with CategoryEntity

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

the class CategoriesResourceTest 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);
    doReturn(1L).when(categoryService).getTotalApisByCategory(mockApis, category1);
    CategoryEntity category2 = new CategoryEntity();
    category2.setId("2");
    category2.setHidden(false);
    category2.setOrder(3);
    doReturn(0L).when(categoryService).getTotalApisByCategory(mockApis, category2);
    CategoryEntity category3 = new CategoryEntity();
    category3.setId("3");
    category3.setHidden(true);
    category3.setOrder(1);
    doReturn(2L).when(categoryService).getTotalApisByCategory(mockApis, category3);
    existingCategories = Arrays.asList(category1, category2, category3);
    doReturn(existingCategories).when(categoryService).findAll();
    Mockito.when(categoryMapper.convert(any(), any())).thenCallRealMethod();
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Before(org.junit.Before)

Example 22 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() 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();
    mockImage = new InlinePictureEntity();
    apiLogoContent = Files.readAllBytes(Paths.get(this.getClass().getClassLoader().getResource("media/logo.svg").toURI()));
    mockImage.setContent(apiLogoContent);
    mockImage.setType("image/svg");
    doReturn(mockImage).when(categoryService).getPicture(CATEGORY_ID);
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) HashSet(java.util.HashSet) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Before(org.junit.Before)

Example 23 with CategoryEntity

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

the class CategoryServiceImpl method convert.

private CategoryEntity convert(final Category category) {
    final CategoryEntity categoryEntity = new CategoryEntity();
    categoryEntity.setId(category.getId());
    categoryEntity.setKey(category.getKey());
    categoryEntity.setName(category.getName());
    categoryEntity.setDescription(category.getDescription());
    categoryEntity.setOrder(category.getOrder());
    categoryEntity.setHidden(category.isHidden());
    categoryEntity.setHighlightApi(category.getHighlightApi());
    categoryEntity.setPicture(category.getPicture());
    categoryEntity.setBackground(category.getBackground());
    categoryEntity.setPage(category.getPage());
    categoryEntity.setUpdatedAt(category.getUpdatedAt());
    categoryEntity.setCreatedAt(category.getCreatedAt());
    return categoryEntity;
}
Also used : NewCategoryEntity(io.gravitee.rest.api.model.NewCategoryEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) UpdateCategoryEntity(io.gravitee.rest.api.model.UpdateCategoryEntity)

Example 24 with CategoryEntity

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

the class CategoryService_GetTotalApisByCategoryTest method testEnhanceForOneCategory.

@Test
public void testEnhanceForOneCategory() {
    CategoryEntity v = new CategoryEntity();
    v.setKey("1");
    long totalApisByCategory = categoryService.getTotalApisByCategory(apis, v);
    assertEquals(2, totalApisByCategory);
}
Also used : CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Test(org.junit.Test)

Example 25 with CategoryEntity

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

the class CategoryService_CreateTest method shouldCreateCategory.

@Test
public void shouldCreateCategory() throws TechnicalException {
    NewCategoryEntity v1 = new NewCategoryEntity();
    v1.setName("v1");
    when(mockCategoryRepository.create(argThat(cat -> cat.getCreatedAt() != null))).thenReturn(new Category());
    when(mockEnvironmentService.findById("DEFAULT")).thenReturn(new EnvironmentEntity());
    CategoryEntity category = categoryService.create(v1);
    assertNotNull("result is null", category);
    verify(mockAuditService, times(1)).createEnvironmentAuditLog(any(), eq(CATEGORY_CREATED), any(), isNull(), any());
    verify(mockCategoryRepository, times(1)).create(argThat(arg -> arg != null && arg.getName().equals("v1")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) NewCategoryEntity(io.gravitee.rest.api.model.NewCategoryEntity) InjectMocks(org.mockito.InjectMocks) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Assert.assertNotNull(org.junit.Assert.assertNotNull) CategoryServiceImpl(io.gravitee.rest.api.service.impl.CategoryServiceImpl) Mock(org.mockito.Mock) CATEGORY_CREATED(io.gravitee.repository.management.model.Category.AuditEvent.CATEGORY_CREATED) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) AuditService(io.gravitee.rest.api.service.AuditService) Test(org.junit.Test) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Mockito(org.mockito.Mockito) Category(io.gravitee.repository.management.model.Category) CategoryRepository(io.gravitee.repository.management.api.CategoryRepository) EnvironmentNotFoundException(io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException) DuplicateCategoryNameException(io.gravitee.rest.api.service.exceptions.DuplicateCategoryNameException) Assert(org.junit.Assert) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Category(io.gravitee.repository.management.model.Category) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) NewCategoryEntity(io.gravitee.rest.api.model.NewCategoryEntity) NewCategoryEntity(io.gravitee.rest.api.model.NewCategoryEntity) 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