Search in sources :

Example 1 with CATEGORY_CREATED

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

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 CategoryRepository (io.gravitee.repository.management.api.CategoryRepository)1 Category (io.gravitee.repository.management.model.Category)1 CATEGORY_CREATED (io.gravitee.repository.management.model.Category.AuditEvent.CATEGORY_CREATED)1 CategoryEntity (io.gravitee.rest.api.model.CategoryEntity)1 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)1 NewCategoryEntity (io.gravitee.rest.api.model.NewCategoryEntity)1 AuditService (io.gravitee.rest.api.service.AuditService)1 DuplicateCategoryNameException (io.gravitee.rest.api.service.exceptions.DuplicateCategoryNameException)1 EnvironmentNotFoundException (io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException)1 CategoryServiceImpl (io.gravitee.rest.api.service.impl.CategoryServiceImpl)1 Collections (java.util.Collections)1 Assert (org.junit.Assert)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 InjectMocks (org.mockito.InjectMocks)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1