PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://sigma-h.googlecode.com/
Java | 131 lines | 106 code | 25 blank | 0 comment | 0 complexity | 40a9c0334ff82a8b5faa3f010265e23f MD5 | raw file
  1package org.sigmah.server.report;
  2
  3import java.io.File;
  4import java.io.FileOutputStream;
  5import java.io.FileWriter;
  6import java.io.IOException;
  7import java.io.InputStreamReader;
  8import java.util.ArrayList;
  9
 10import javax.xml.bind.JAXBContext;
 11import javax.xml.bind.JAXBException;
 12import javax.xml.bind.Marshaller;
 13import javax.xml.bind.Unmarshaller;
 14
 15import org.junit.Before;
 16import org.junit.Test;
 17import org.sigmah.server.report.renderer.excel.ExcelChartRenderer;
 18import org.sigmah.server.report.renderer.excel.ExcelPivotTableRenderer;
 19import org.sigmah.server.report.renderer.excel.ExcelReportRenderer;
 20import org.sigmah.server.report.renderer.excel.ExcelStaticRenderer;
 21import org.sigmah.server.report.renderer.excel.ExcelTableRenderer;
 22import org.sigmah.server.report.renderer.itext.HtmlReportRenderer;
 23import org.sigmah.server.report.renderer.itext.ItextChartRenderer;
 24import org.sigmah.server.report.renderer.itext.ItextMapRenderer;
 25import org.sigmah.server.report.renderer.itext.ItextPivotTableRenderer;
 26import org.sigmah.server.report.renderer.itext.ItextStaticRenderer;
 27import org.sigmah.server.report.renderer.itext.ItextTableRenderer;
 28import org.sigmah.server.report.renderer.itext.PdfReportRenderer;
 29import org.sigmah.server.report.renderer.itext.RtfReportRenderer;
 30import org.sigmah.server.report.util.HtmlWriter;
 31import org.sigmah.shared.report.content.FilterDescription;
 32import org.sigmah.shared.report.content.ReportContent;
 33import org.sigmah.shared.report.model.Report;
 34
 35
 36public class StaticElementRenderTest{
 37
 38	 @Before
 39	 public void setup() {
 40		File file = new File("target/report-tests");
 41		file.mkdirs();
 42	 }
 43
 44
 45	public Report parseXml(String filename) throws JAXBException {
 46		JAXBContext jc = JAXBContext.newInstance(Report.class.getPackage().getName());
 47		Unmarshaller um = jc.createUnmarshaller();
 48		um.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
 49		return (Report) um.unmarshal(new InputStreamReader(
 50				getClass().getResourceAsStream("/report-def/parse-test/" + filename)));
 51	}
 52	
 53	public Report getStatic() throws JAXBException {
 54		Report r = parseXml("static.xml");
 55		r.setContent( new ReportContent());
 56		r.getContent().setFilterDescriptions(new ArrayList <FilterDescription> ());
 57		return r;
 58	}
 59
 60	public static void dumpXml(Report report) throws JAXBException {
 61		JAXBContext jc = JAXBContext.newInstance(Report.class.getPackage().getName());
 62		Marshaller m = jc.createMarshaller();
 63		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
 64		m.marshal(report, System.out);
 65	}
 66
 67
 68	@Test
 69	public void testPdfRender() throws JAXBException, IOException {
 70		Report r = getStatic();
 71		PdfReportRenderer renderer = new PdfReportRenderer(new ItextPivotTableRenderer(),
 72                new ItextChartRenderer(null), new ItextMapRenderer(null), new ItextTableRenderer(null), new ItextStaticRenderer()); 
 73	
 74		FileOutputStream fos = new FileOutputStream("target/report-tests/render-static" + renderer.getFileSuffix());
 75		renderer.render(r, fos);
 76		fos.close();
 77	}
 78	
 79	@Test
 80	public void testRtfRender() throws JAXBException, IOException {
 81		Report r = getStatic();
 82		RtfReportRenderer renderer = new RtfReportRenderer(new ItextPivotTableRenderer(),
 83                new ItextChartRenderer(null), new ItextMapRenderer(null), new ItextTableRenderer(null), new ItextStaticRenderer()); 
 84	
 85		FileOutputStream fos = new FileOutputStream("target/report-tests/render-static" + renderer.getFileSuffix());
 86		renderer.render(r, fos);
 87		fos.close();
 88	}
 89
 90	@Test
 91	public void testExcelRender() throws JAXBException, IOException {
 92		Report r = getStatic();
 93		ExcelReportRenderer renderer = new ExcelReportRenderer(new ExcelPivotTableRenderer(),
 94                new ExcelTableRenderer(), new ExcelChartRenderer(), new ExcelStaticRenderer()); 
 95	
 96		FileOutputStream fos = new FileOutputStream("target/report-tests/render-static" + renderer.getFileSuffix());
 97		renderer.render(r, fos);
 98		fos.close();
 99	}
100	
101	@Test
102	public void testHtmlRender() throws JAXBException, IOException {
103		Report r = getStatic();
104		HtmlReportRenderer renderer =new HtmlReportRenderer(new ItextPivotTableRenderer(),
105                new ItextChartRenderer(null), new ItextMapRenderer(null), new ItextTableRenderer(null), new ItextStaticRenderer()); 
106		FileOutputStream fos = new FileOutputStream("target/report-tests/render-static" + renderer.getFileSuffix());
107		renderer.render(r, fos);
108		fos.close();
109	}
110	
111	@Test
112	public void testOldHtmlRender() throws JAXBException, IOException {
113		Report r = getStatic();
114		org.sigmah.server.report.renderer.html.HtmlReportRenderer renderer = new org.sigmah.server.report.renderer.html.HtmlReportRenderer(new org.sigmah.server.report.renderer.html.HtmlPivotTableRenderer(), 
115				new org.sigmah.server.report.renderer.html.HtmlChartRendererJC(),
116				new org.sigmah.server.report.renderer.html.HtmlTableRenderer(null),
117				new org.sigmah.server.report.renderer.html.HtmlMapRenderer(null),
118				new org.sigmah.server.report.renderer.html.HtmlStaticRenderer());
119
120		FileWriter fw = new FileWriter("target/report-tests/render-static-old.html");
121		HtmlWriter writer = new HtmlWriter();;
122		renderer.render(writer, new NullImageStorageProvider(), r);
123		fw.write(writer.toString());
124		fw.close();
125	}
126	
127	
128
129
130
131}