ReportDefinition rd = new ReportDefinition();
rd.setDatabase(db);
rd.setName("test report one");
rd.setSql("select * from user");
rd.setQueryType(QueryBuilder.QUERY_TYPE_STATIC);
ReportDefinitionService rs=(ReportDefinitionService)context.getBean("reportDefinitionService");
rs.createReportDefinition(rd);
ReportDefinition rd2 = new ReportDefinition();
rd2.setDatabase(db);
rd2.setName("test report two");
rd2.setSql("select * from user");
rd2.setQueryType(QueryBuilder.QUERY_TYPE_STATIC);
rs.createReportDefinition(rd2);
DrillDownColumn ddc=new DrillDownColumn();
ddc.setName("name");
ddc.setParametersIndex(2);
rd.addDrillDownColumn(ddc);
rd2.addAssociatedDrillDownColumn(ddc);
ddcService.createDrillDownColumn(ddc);
assertEquals(rd.getDrillDownColumns().size(),1);
//getting the stored entity from session is redundant ?
DrillDownColumn stored=ddcService.getDrillDownColumn(ddc.getId());
assertEquals(ddc.getId(),stored.getId());
assertEquals(stored.getName(),"name");
assertEquals(stored.getParametersIndex(),2);
assertEquals(stored.getReportDefinition().getId(),rd.getId());
assertEquals(stored.getToReportDefinition().getId(),rd2.getId());
stored.setName("changed name");
ddcService.updateDrillDownColumn(stored);
assertEquals(stored.getName(),"changed name");
//test for cascade delete all associated DrillDownColumns
this.closeSession();
this.openSession();
rs=(ReportDefinitionService)context.getBean("reportDefinitionService");
rd2=rs.getReportDefinition(rd2.getId());
rs.deleteReportDefinition(rd2);
assertNull(ddcService.getDrillDownColumn(ddc.getId()));
rd=rs.getReportDefinition(rd.getId());
assertEquals(rd.getDrillDownColumns().size(),0);
}