DashboardItemDeletionHandler extends DeletionHandler { @Override public void deleteReport( Report report ) { for ( DashboardItem item : dashboardService.getReportDashboardItems( report ) ) { while ( item.getReports().contains( report ) ) { item.getReports().remove( report ); } if ( item.getReports().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 testDeleteReport() { Report reportA = new Report(); Report reportB = new Report(); reportA.setName( "A" ); reportB.setName( "B" ); reportService.saveReport( reportA ); reportService.saveReport( reportB ); dashboardItem.getReports().add ( reportA ); dashboardItem.getReports().add ( reportA ); dashboardItem.getReports().add ( reportB ); dashboardService.saveDashboard( dashboard ); assertEquals(1, dashboardService.getReportDashboardItems( reportA ).size() ); assertEquals(1, dashboardService.getReportDashboardItems( reportB ).size() ); assertEquals( 1, dashboard.getItemCount() ); reportService.deleteReport( reportA ); assertEquals(0, dashboardService.getReportDashboardItems( reportA ).size() ); assertEquals(1, dashboardService.getReportDashboardItems( reportB ).size() ); assertEquals( 1, dashboard.getItemCount() ); reportService.deleteReport( reportB ); assertEquals(0, dashboardService.getReportDashboardItems( reportA ).size() ); assertEquals(0, dashboardService.getReportDashboardItems( reportB ).size() ); assertEquals( 0, dashboard.getItemCount() ); }