DashboardItemDeletionHandler extends DeletionHandler { @Override public void deleteDocument( Document document ) { for ( DashboardItem item : dashboardService.getDocumentDashboardItems( document ) ) { while ( item.getResources().contains( document ) ) { item.getResources().remove( document ); } if ( item.getResources().isEmpty() ) { dashboardService.deleteDashboardItem( item ); } } } DashboardItemDeletionHandler( DashboardService dashboardService ); @Override void deleteVisualization( Visualization visualization ); @Override void deleteReportTable( ReportTable reportTable ); @Override void deleteChart( Chart chart ); @Override void deleteEventChart( EventChart eventChart ); @Override void deleteMap( Map map ); @Override void deleteEventReport( EventReport eventReport ); @Override void deleteUser( User user ); @Override void deleteReport( Report report ); @Override void deleteDocument( Document document );  }
@Test public void testDeleteDocument() { Document documentA = new Document(); Document documentB = new Document(); documentA.setName( "A" ); documentB.setName( "B" ); documentA.setUrl( "UrlA.com" ); documentB.setUrl( "UrlB.com" ); documentService.saveDocument( documentA ); documentService.saveDocument( documentB ); dashboardItem.getResources().add ( documentA ); dashboardItem.getResources().add ( documentA ); dashboardItem.getResources().add ( documentB ); dashboardService.saveDashboard( dashboard ); assertEquals(1, dashboardService.getDocumentDashboardItems( documentA ).size() ); assertEquals(1, dashboardService.getDocumentDashboardItems( documentB ).size() ); assertEquals( 1, dashboard.getItemCount() ); documentService.deleteDocument( documentA ); assertEquals(0, dashboardService.getDocumentDashboardItems( documentA ).size() ); assertEquals(1, dashboardService.getDocumentDashboardItems( documentB ).size() ); assertEquals( 1, dashboard.getItemCount() ); documentService.deleteDocument( documentB ); assertEquals(0, dashboardService.getDocumentDashboardItems( documentA ).size() ); assertEquals(0, dashboardService.getDocumentDashboardItems( documentB ).size() ); assertEquals( 0, dashboard.getItemCount() ); }