use of io.gravitee.management.model.UpdateViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewService_DeleteTest method shouldNotDeleteUnknownView.
@Test
public void shouldNotDeleteUnknownView() throws TechnicalException {
UpdateViewEntity mockView = mock(UpdateViewEntity.class);
when(mockView.getId()).thenReturn("unknown");
when(mockViewRepository.findById("unknown")).thenReturn(Optional.empty());
viewService.delete("unknown");
verify(mockViewRepository, times(1)).findById(any());
verify(mockViewRepository, never()).delete(any());
verify(mockAuditService, never()).createPortalAuditLog(any(), eq(VIEW_UPDATED), any(), any(), any());
verify(mockApiService, never()).deleteViewFromAPIs(eq("unknown"));
}
use of io.gravitee.management.model.UpdateViewEntity 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.UpdateViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewService_DeleteTest method shouldDeleteView.
@Test
public void shouldDeleteView() throws TechnicalException {
UpdateViewEntity mockView = mock(UpdateViewEntity.class);
when(mockView.getId()).thenReturn("known");
when(mockViewRepository.findById("known")).thenReturn(Optional.of(new View()));
viewService.delete("known");
verify(mockViewRepository, times(1)).findById(eq("known"));
verify(mockViewRepository, times(1)).delete(eq("known"));
verify(mockAuditService, times(1)).createPortalAuditLog(any(), eq(VIEW_DELETED), any(), any(), any());
verify(mockApiService, times(1)).deleteViewFromAPIs(eq("known"));
}
use of io.gravitee.management.model.UpdateViewEntity 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());
}
use of io.gravitee.management.model.UpdateViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewServiceImpl method update.
@Override
public List<ViewEntity> update(final List<UpdateViewEntity> viewEntities) {
final List<ViewEntity> savedViews = new ArrayList<>(viewEntities.size());
viewEntities.forEach(viewEntity -> {
try {
View view = convert(viewEntity);
Optional<View> viewOptional = viewRepository.findById(view.getId());
if (viewOptional.isPresent()) {
savedViews.add(convert(viewRepository.update(view)));
auditService.createPortalAuditLog(Collections.singletonMap(VIEW, view.getId()), VIEW_UPDATED, new Date(), viewOptional.get(), view);
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to update view {}", viewEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to update view " + viewEntity.getName(), ex);
}
});
return savedViews;
}
Aggregations