PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/report/FullTest.java

http://sigma-h.googlecode.com/
Java | 85 lines | 47 code | 21 blank | 17 comment | 3 complexity | a594a520e47251365fd31c1001119eca MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.server.report;
 7
 8import com.google.inject.Inject;
 9import org.junit.Ignore;
10import org.junit.Test;
11import org.junit.runner.RunWith;
12import org.sigmah.server.dao.hibernate.HibernateModule;
13import org.sigmah.shared.domain.User;
14import org.sigmah.server.report.generator.ReportGenerator;
15import org.sigmah.server.report.renderer.Renderer;
16import org.sigmah.server.report.renderer.RendererFactory;
17import org.sigmah.shared.command.RenderElement;
18import org.sigmah.shared.report.model.Report;
19import org.sigmah.test.InjectionSupport;
20import org.sigmah.test.Modules;
21
22import javax.persistence.EntityManager;
23import java.io.File;
24import java.io.FileOutputStream;
25import java.io.InputStreamReader;
26
27@Ignore("Needs to be rewritten -- figure out what to do with dependency on the map icons folder")
28@RunWith(InjectionSupport.class)
29@Modules({ReportModule.class, HibernateModule.class})
30public class FullTest {
31
32
33    @Inject
34    private EntityManager em;
35
36    @Inject
37    private ReportGenerator rgtor;
38
39    @Inject
40    private RendererFactory factory;
41
42
43
44    @Test
45    public void test() throws Throwable {
46
47
48
49
50        /*
51           *
52           * Parse the XML report definition
53           */
54        Report report = ReportParserJaxb.parseXML(new InputStreamReader(
55                getClass().getResourceAsStream("/report-def/full-test.xml")));
56
57
58        /*
59         * Set up our envionnement
60         */
61        User user = (User) em.createQuery("select u from User u where u.email = :email")
62                .setParameter("email", "akbertram@gmail.com").getResultList().get(0);
63
64        /*
65         * Generate
66         */
67        rgtor.generate(user, report, null, null);
68
69        File file = new File("target/report-test");
70        file.mkdirs();
71
72        /*
73           * Render
74           */
75        for (RenderElement.Format format : RenderElement.Format.values()) {
76            if (format != RenderElement.Format.Excel_Data) {
77                Renderer renderer = factory.get(format);
78                FileOutputStream fos = new FileOutputStream("target/report-tests/full-test" + renderer.getFileSuffix());
79
80                renderer.render(report, fos);
81                fos.close();
82            }
83        }
84    }
85}