type.session = session;
ColumnAliasDAO detail = new ColumnAliasDAO();
detail.session = session;
Dashboard dashboard = new Dashboard(0,0);
ReportDAO reportDAO = new ReportDAO();
Report report = new Report();
report.setName("reportTest");
report.setUser(user.findById(1l));
report.setDashboard(dashboard);
report.setNumRecordsPerPage(25);
ReportDesign design = new ReportDesign();
design.setMappingAxis("x");
design.setColumnAlias(detail.findById(99999l));
design.setReport(report);
report.setReportType(type.findById(1l));
ArrayList<ReportDesign> designs = new ArrayList<ReportDesign>();
designs.add(design);
report.setDesigns(designs);
GroupBys groupBys = new GroupBys();
RowAlias alias = new RowAlias();
alias.setId(99999);
RowAlias alias1 = new RowAlias();
alias1.setId(19999);
List<GroupBy> groupByList = new ArrayList<GroupBy>();
GroupBy groupBy = new GroupBy();
groupBy.setRowAlias(alias);
groupBy.setPosition(1);
GroupBy groupBy1 = new GroupBy();
groupBy1.setRowAlias(alias1);
groupBy1.setPosition(2);
groupByList.add(groupBy);
groupByList.add(groupBy1);
groupBys.setGroupBy(groupByList);
groupBys.setReport(report);
report.setGroupBys(groupBys);
reportDAO.session = session;
reportDAO.transaction = reportDAO.session.getTransaction();
long reportId = reportDAO.save(report);
long designId = design.getId();
ResultSet rs = stmt.executeQuery("select * from report where id="
+ reportId);
while (rs.next()) {
assertEquals(rs.getLong("userId"), 1l);
assertEquals(rs.getString("name"), "reportTest");
assertEquals(rs.getLong("reportTypeId"), 1l);
assertEquals(rs.getLong("dashboardId"),dashboard.getId());
assertEquals(rs.getLong("numRecordsPerPage"),25);
}
rs.close();
ResultSet rs1 = stmt
.executeQuery("select * from reportDesign where id=" + designId);
while (rs1.next()) {
assertEquals(rs1.getLong("reportId"), reportId);
assertEquals(rs1.getLong("columnAliasId"), 99999l);
assertEquals(rs1.getString("mappingAxis"), "x");
}
rs1.close();
rs = stmt.executeQuery("select id, reportId from groupBys");
long groupBysId = -1;
if (rs!= null && rs.first()) {
groupBysId = rs.getLong(1);
assertFalse(-1 == groupBysId);
assertEquals(reportId, rs.getLong(2));
rs.close();
}
else {
fail("GroupBys not created");
}
rs1 = stmt.executeQuery("select id, groupBysId,rowAliasId, position from groupBy");
if (rs1 != null && rs1.first()) {
assertNotNull(rs1.getLong(1));
assertEquals(groupBysId, rs1.getLong(2));
assertEquals(99999, rs1.getLong(3));
assertEquals(1, rs1.getInt(4));
rs1.next();
assertNotNull(rs1.getLong(1));
assertEquals(groupBysId, rs1.getLong(2));
assertEquals(19999, rs1.getLong(3));
assertEquals(2, rs1.getInt(4));
rs1.close();
}
else {
fail("Groupbys should have created groupBy");
}
stmt.executeUpdate("delete from groupBy");
stmt.executeUpdate("delete from groupBys");
stmt.executeUpdate("delete from reportDesign where id=" + designId);
stmt.executeUpdate("delete from report where id=" + reportId);
stmt.executeUpdate("delete from rowAlias");
stmt.executeUpdate("delete from columnAlias where id=" + 99999);
stmt.executeUpdate("delete from mapping where id=" + 99999);
stmt.executeUpdate("delete from connection where id=" + 99999);
stmt.executeUpdate("delete from dashboard where id=" + dashboard.getId());
reportDAO.session.close();
stmt.close();
}