use of io.gravitee.management.model.ViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewService_CreateTest method shouldCreate2Views.
@Test
public void shouldCreate2Views() throws TechnicalException {
NewViewEntity v1 = new NewViewEntity();
v1.setName("v1");
NewViewEntity v2 = new NewViewEntity();
v2.setName("v2");
when(mockViewRepository.create(any())).thenReturn(new View());
List<ViewEntity> views = viewService.create(Arrays.asList(v1, v2));
assertNotNull("result is null", views);
assertFalse("result is empty", views.isEmpty());
assertEquals("result size is 2", 2, views.size());
verify(mockAuditService, times(2)).createPortalAuditLog(any(), eq(VIEW_CREATED), any(), isNull(), any());
verify(mockViewRepository, times(1)).create(argThat(new ArgumentMatcher<View>() {
@Override
public boolean matches(Object arg) {
return arg instanceof View && ((View) arg).getName().equals("v1");
}
}));
verify(mockViewRepository, times(1)).create(argThat(new ArgumentMatcher<View>() {
@Override
public boolean matches(Object arg) {
return arg instanceof View && ((View) arg).getName().equals("v2");
}
}));
}
use of io.gravitee.management.model.ViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewService_FindTest method shouldFindView.
@Test
public void shouldFindView() throws TechnicalException {
View view = mock(View.class);
when(view.getId()).thenReturn("view-id");
when(view.getName()).thenReturn("view-name");
when(view.getDescription()).thenReturn("view-description");
when(view.isDefaultView()).thenReturn(true);
when(view.getOrder()).thenReturn(1);
when(view.isHidden()).thenReturn(true);
when(view.getUpdatedAt()).thenReturn(new Date(1234567890L));
when(view.getCreatedAt()).thenReturn(new Date(9876543210L));
when(mockViewRepository.findAll()).thenReturn(singleton(view));
List<ViewEntity> list = viewService.findAll();
assertFalse(list.isEmpty());
assertEquals("one element", 1, list.size());
assertEquals("Id", "view-id", list.get(0).getId());
assertEquals("Name", "view-name", list.get(0).getName());
assertEquals("Description", "view-description", list.get(0).getDescription());
assertEquals("Total APIs", 0, list.get(0).getTotalApis());
assertEquals("default View", true, list.get(0).isDefaultView());
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(mockViewRepository, times(1)).findAll();
}
use of io.gravitee.management.model.ViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewService_UpdateTest method shouldNotUpdateUnknownView.
@Test
public void shouldNotUpdateUnknownView() throws TechnicalException {
UpdateViewEntity mockView = mock(UpdateViewEntity.class);
when(mockView.getId()).thenReturn("unknown");
when(mockViewRepository.findById("unknown")).thenReturn(Optional.empty());
List<ViewEntity> list = viewService.update(singletonList(mockView));
assertTrue(list.isEmpty());
verify(mockViewRepository, times(1)).findById(any());
verify(mockViewRepository, never()).update(any());
verify(mockAuditService, never()).createPortalAuditLog(any(), eq(VIEW_UPDATED), any(), any(), any());
}
use of io.gravitee.management.model.ViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewServiceImpl method create.
@Override
public List<ViewEntity> create(final List<NewViewEntity> viewEntities) {
// First we prevent the duplicate view name
final List<String> viewNames = viewEntities.stream().map(NewViewEntity::getName).collect(Collectors.toList());
final Optional<ViewEntity> optionalView = findAll().stream().filter(view -> viewNames.contains(view.getName())).findAny();
if (optionalView.isPresent()) {
throw new DuplicateViewNameException(optionalView.get().getName());
}
final List<ViewEntity> savedViews = new ArrayList<>(viewEntities.size());
viewEntities.forEach(viewEntity -> {
try {
View view = convert(viewEntity);
savedViews.add(convert(viewRepository.create(view)));
auditService.createPortalAuditLog(Collections.singletonMap(VIEW, view.getId()), VIEW_CREATED, new Date(), null, view);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create view {}", viewEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create view " + viewEntity.getName(), ex);
}
});
return savedViews;
}
use of io.gravitee.management.model.ViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewService_UpdateTest method shouldUpdateView.
@Test
public void shouldUpdateView() throws TechnicalException {
UpdateViewEntity mockView = mock(UpdateViewEntity.class);
when(mockView.getId()).thenReturn("known");
when(mockViewRepository.findById("known")).thenReturn(Optional.of(new View()));
View updatedView = mock(View.class);
when(updatedView.getId()).thenReturn("view-id");
when(updatedView.getName()).thenReturn("view-name");
when(updatedView.getDescription()).thenReturn("view-description");
when(updatedView.isDefaultView()).thenReturn(true);
when(updatedView.getOrder()).thenReturn(1);
when(updatedView.isHidden()).thenReturn(true);
when(updatedView.getUpdatedAt()).thenReturn(new Date(1234567890L));
when(updatedView.getCreatedAt()).thenReturn(new Date(9876543210L));
when(mockViewRepository.update(any())).thenReturn(updatedView);
List<ViewEntity> list = viewService.update(singletonList(mockView));
assertFalse(list.isEmpty());
assertEquals("one element", 1, list.size());
assertEquals("Id", "view-id", list.get(0).getId());
assertEquals("Name", "view-name", list.get(0).getName());
assertEquals("Description", "view-description", list.get(0).getDescription());
assertEquals("Total APIs", 0, list.get(0).getTotalApis());
assertEquals("default View", true, list.get(0).isDefaultView());
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(mockViewRepository, times(1)).findById(any());
verify(mockViewRepository, times(1)).update(any());
verify(mockAuditService, times(1)).createPortalAuditLog(any(), eq(VIEW_UPDATED), any(), any(), any());
}
Aggregations