Search in sources :

Example 11 with Category

use of io.gravitee.repository.management.model.Category 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)

Example 12 with Category

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

the class CategoryService_FindTest method shouldFindCategory.

@Test
public void shouldFindCategory() throws TechnicalException {
    Category category = mock(Category.class);
    when(category.getId()).thenReturn("category-id");
    when(category.getName()).thenReturn("category-name");
    when(category.getDescription()).thenReturn("category-description");
    when(category.getOrder()).thenReturn(1);
    when(category.isHidden()).thenReturn(true);
    when(category.getUpdatedAt()).thenReturn(new Date(1234567890L));
    when(category.getCreatedAt()).thenReturn(new Date(9876543210L));
    when(mockCategoryRepository.findAllByEnvironment(any())).thenReturn(singleton(category));
    List<CategoryEntity> list = categoryService.findAll();
    assertFalse(list.isEmpty());
    assertEquals("one element", 1, list.size());
    assertEquals("Id", "category-id", list.get(0).getId());
    assertEquals("Name", "category-name", list.get(0).getName());
    assertEquals("Description", "category-description", list.get(0).getDescription());
    assertEquals("Total APIs", 0, list.get(0).getTotalApis());
    assertEquals("Order", 1, list.get(0).getOrder());
    assertEquals("Hidden", true, list.get(0).isHidden());
    assertEquals("UpdatedAt", new Date(1234567890L), list.get(0).getUpdatedAt());
    assertEquals("CreatedAt", new Date(9876543210L), list.get(0).getCreatedAt());
    verify(mockCategoryRepository, times(1)).findAllByEnvironment(any());
}
Also used : Category(io.gravitee.repository.management.model.Category) Date(java.util.Date) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Test(org.junit.Test)

Example 13 with Category

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

the class CategoryService_UpdateTest method shouldUpdateCategory_multi_mode.

@Test
public void shouldUpdateCategory_multi_mode() throws TechnicalException {
    UpdateCategoryEntity mockCategory = mock(UpdateCategoryEntity.class);
    when(mockCategory.getId()).thenReturn("known");
    when(mockCategory.getName()).thenReturn("Known");
    when(mockCategoryRepository.findById("known")).thenReturn(Optional.of(new Category()));
    Category updatedCategory = mock(Category.class);
    when(updatedCategory.getId()).thenReturn("category-id");
    when(updatedCategory.getName()).thenReturn("category-name");
    when(updatedCategory.getDescription()).thenReturn("category-description");
    when(updatedCategory.getOrder()).thenReturn(1);
    when(updatedCategory.isHidden()).thenReturn(true);
    when(updatedCategory.getUpdatedAt()).thenReturn(new Date(1234567890L));
    when(updatedCategory.getCreatedAt()).thenReturn(new Date(9876543210L));
    when(mockCategoryRepository.update(argThat(cat -> cat.getUpdatedAt() != null))).thenReturn(updatedCategory);
    List<CategoryEntity> list = categoryService.update(singletonList(mockCategory));
    assertFalse(list.isEmpty());
    assertEquals("one element", 1, list.size());
    assertEquals("Id", "category-id", list.get(0).getId());
    assertEquals("Name", "category-name", list.get(0).getName());
    assertEquals("Description", "category-description", list.get(0).getDescription());
    assertEquals("Total APIs", 0, list.get(0).getTotalApis());
    assertEquals("Order", 1, list.get(0).getOrder());
    assertEquals("Hidden", true, list.get(0).isHidden());
    assertEquals("UpdatedAt", new Date(1234567890L), list.get(0).getUpdatedAt());
    assertEquals("CreatedAt", new Date(9876543210L), list.get(0).getCreatedAt());
    verify(mockCategoryRepository, times(1)).findById(any());
    verify(mockCategoryRepository, times(1)).update(any());
    verify(mockAuditService, times(1)).createEnvironmentAuditLog(any(), eq(CATEGORY_UPDATED), any(), any(), any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InjectMocks(org.mockito.InjectMocks) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) CategoryServiceImpl(io.gravitee.rest.api.service.impl.CategoryServiceImpl) Date(java.util.Date) Mock(org.mockito.Mock) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) CategoryNotFoundException(io.gravitee.rest.api.service.exceptions.CategoryNotFoundException) AuditService(io.gravitee.rest.api.service.AuditService) Test(org.junit.Test) UpdateCategoryEntity(io.gravitee.rest.api.model.UpdateCategoryEntity) Collections.singletonList(java.util.Collections.singletonList) Mockito(org.mockito.Mockito) Category(io.gravitee.repository.management.model.Category) List(java.util.List) CategoryRepository(io.gravitee.repository.management.api.CategoryRepository) Optional(java.util.Optional) Assert(org.junit.Assert) CATEGORY_UPDATED(io.gravitee.repository.management.model.Category.AuditEvent.CATEGORY_UPDATED) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Category(io.gravitee.repository.management.model.Category) 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) Test(org.junit.Test)

Aggregations

Category (io.gravitee.repository.management.model.Category)13 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)9 CategoryEntity (io.gravitee.rest.api.model.CategoryEntity)7 CategoryRepository (io.gravitee.repository.management.api.CategoryRepository)5 NewCategoryEntity (io.gravitee.rest.api.model.NewCategoryEntity)5 UpdateCategoryEntity (io.gravitee.rest.api.model.UpdateCategoryEntity)5 CategoryNotFoundException (io.gravitee.rest.api.service.exceptions.CategoryNotFoundException)5 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)5 Test (org.junit.Test)5 AuditService (io.gravitee.rest.api.service.AuditService)4 Date (java.util.Date)4 DuplicateCategoryNameException (io.gravitee.rest.api.service.exceptions.DuplicateCategoryNameException)3 CategoryServiceImpl (io.gravitee.rest.api.service.impl.CategoryServiceImpl)3 Optional (java.util.Optional)3 Assert (org.junit.Assert)3 RunWith (org.junit.runner.RunWith)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 InjectMocks (org.mockito.InjectMocks)3 Mock (org.mockito.Mock)3 Mockito (org.mockito.Mockito)3