use of io.gravitee.rest.api.model.CategoryEntity 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());
}
use of io.gravitee.rest.api.model.CategoryEntity in project gravitee-management-rest-api by gravitee-io.
the class CategoryService_UpdateTest method shouldNotUpdateUnknownCategory_multi_mode.
@Test
public void shouldNotUpdateUnknownCategory_multi_mode() throws TechnicalException {
UpdateCategoryEntity mockCategory = mock(UpdateCategoryEntity.class);
when(mockCategory.getId()).thenReturn("unknown");
when(mockCategoryRepository.findById("unknown")).thenReturn(Optional.empty());
List<CategoryEntity> list = categoryService.update(singletonList(mockCategory));
assertTrue(list.isEmpty());
verify(mockCategoryRepository, times(1)).findById(any());
verify(mockCategoryRepository, never()).update(any());
verify(mockAuditService, never()).createEnvironmentAuditLog(any(), eq(CATEGORY_UPDATED), any(), any(), any());
}
use of io.gravitee.rest.api.model.CategoryEntity 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());
}
use of io.gravitee.rest.api.model.CategoryEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_DeleteTest method shouldNotDeletePageBecauseUsedInCategory.
@Test(expected = PageActionException.class)
public void shouldNotDeletePageBecauseUsedInCategory() throws TechnicalException {
Page page = mock(Page.class);
when(page.getType()).thenReturn(PageType.MARKDOWN.name());
when(pageRepository.findById(PAGE_ID)).thenReturn(Optional.of(page));
CategoryEntity category1 = new CategoryEntity();
category1.setKey("cat_1");
CategoryEntity category2 = new CategoryEntity();
category2.setKey("cat_2");
doReturn(Arrays.asList(category1, category2)).when(categoryService).findByPage(PAGE_ID);
pageService.delete(PAGE_ID);
}
Aggregations