RepositoryAspect { @After("execution(* org.bonitasoft.web.designer.repository.Repository+.save(..))") public void postSave(JoinPoint joinPoint) { postSaveAndUpdateDate(joinPoint); } @Inject  RepositoryAspect(WorkspaceResourceHandler handler); @After("execution(* org.bonitasoft.web.designer.repository.Repository+.updateLastUpdateAndSave(..)) ") void postSaveAndUpdateDate(JoinPoint joinPoint); @After("execution(* org.bonitasoft.web.designer.repository.Repository+.save(..))") void postSave(JoinPoint joinPoint); @Around("execution(* org.bonitasoft.web.designer.repository.AbstractRepository.delete(String))") void delete(JoinPoint joinPoint); @After("execution(* org.bonitasoft.web.designer.repository.Repository+.delete(String))") void postDelete(JoinPoint joinPoint);  }
@Test public void should_trigger_postSave_on_workspaceResourceHandler_when_saving_on_formRepository() throws Exception { formRepository.save(aPage().withId("aPageId").build()); verify(workspaceResourceHandler, times(1)).postSave(formRepository.resolvePath("aPageId")); }
@Test public void should_trigger_postSave_on_workspaceResourceHandler_when_saving_and_updating_last_update_date_on_formRepository() throws Exception { formRepository.updateLastUpdateAndSave(aPage().withId("aPageId").build()); verify(workspaceResourceHandler, times(1)).postSave(formRepository.resolvePath("aPageId")); }
@Test public void should_not_trigger_postSave_on_workspaceResourceHandler_when_saving_several_widgets_in_widgetRepository() throws Exception { widgetRepository.saveAll(Arrays.asList( aWidget().id("widgetId1").build(), aWidget().id("widgetId2").build()) ); verify(workspaceResourceHandler, never()).postSave(any(Path.class)); }
@Test public void should_trigger_postSave_on_workspaceResourceHandler_when_saving_widget_on_widgetRepository() throws Exception { widgetRepository.updateLastUpdateAndSave( aWidget().id("widgetId1").build() ); verify(workspaceResourceHandler).postSave(any(Path.class)); }
@Test(expected = RepositoryException.class) public void should_throw_a_RepositoryException_when_saving_if_resource_is_not_found() throws Exception { doThrow(ResourceNotFoundException.class).when(workspaceResourceHandler).postSave(any(Path.class)); formRepository.updateLastUpdateAndSave(aPage().withId("a_form_id").build()); }