Search in sources :

Example 1 with UpdateViewEntity

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"));
}
Also used : UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) Test(org.junit.Test)

Example 2 with UpdateViewEntity

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());
}
Also used : ViewEntity(io.gravitee.management.model.ViewEntity) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) Test(org.junit.Test)

Example 3 with UpdateViewEntity

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"));
}
Also used : UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) View(io.gravitee.repository.management.model.View) Test(org.junit.Test)

Example 4 with UpdateViewEntity

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());
}
Also used : ViewEntity(io.gravitee.management.model.ViewEntity) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) View(io.gravitee.repository.management.model.View) Date(java.util.Date) Test(org.junit.Test)

Example 5 with UpdateViewEntity

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;
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ViewEntity(io.gravitee.management.model.ViewEntity) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) NewViewEntity(io.gravitee.management.model.NewViewEntity) View(io.gravitee.repository.management.model.View) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

UpdateViewEntity (io.gravitee.management.model.UpdateViewEntity)5 Test (org.junit.Test)4 ViewEntity (io.gravitee.management.model.ViewEntity)3 View (io.gravitee.repository.management.model.View)3 NewViewEntity (io.gravitee.management.model.NewViewEntity)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 Date (java.util.Date)1