1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package ar.com.fdvs.dj.test;
31
32 import java.io.FileNotFoundException;
33 import java.util.Arrays;
34 import java.util.Collection;
35 import java.util.List;
36
37 import junit.framework.TestCase;
38 import net.sf.jasperreports.engine.JRException;
39 import net.sf.jasperreports.engine.JasperPrint;
40 import ar.com.fdvs.dj.core.DynamicJasperHelper;
41 import ar.com.fdvs.dj.core.layout.ClassicLayoutManager;
42 import ar.com.fdvs.dj.domain.DynamicReport;
43 import ar.com.fdvs.dj.domain.builders.ReflectiveReportBuilder;
44 import ar.com.fdvs.dj.util.SortUtils;
45
46 public class ReflectiveReportTest extends TestCase {
47
48
49
50
51
52
53
54
55 public void testReport() {
56 final Collection data = TestRepositoryProducts.getDummyCollection();
57 DynamicReport dynamicReport = new ReflectiveReportBuilder(data).build();
58 doReport(dynamicReport, data, "");
59 }
60
61
62
63
64 public void testOrderedReport() {
65 final Collection data = TestRepositoryProducts.getDummyCollection();
66 final List items = SortUtils.sortCollection(data, Arrays.asList(new String[]{"productLine", "item", "state"}));
67 String[] columOrders = new String[]{"productLine", "item", "state", "id", "branch", "quantity", "amount"};
68 DynamicReport dynamicReport = new ReflectiveReportBuilder(items, columOrders).addGroups(3).build();
69 doReport(dynamicReport, items, "ordered");
70 }
71
72 public void doReport(final DynamicReport _report, final Collection _data, String name) {
73 try {
74 final JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(_report, new ClassicLayoutManager(), _data);
75
76 ReportExporter.exportReport(jasperPrint, System.getProperty("user.dir")+ "/target/ReflectiveReportTest "+ name + ".pdf");
77 } catch (FileNotFoundException e) {
78 e.printStackTrace();
79 } catch (JRException e) {
80 e.printStackTrace();
81 }
82 }
83
84 public static void main(final String[] _args) {
85 final ReflectiveReportTest reportTest = new ReflectiveReportTest();
86 reportTest.testReport();
87 reportTest.testOrderedReport();
88 }
89 }