1 16 17 package org.springframework.web.servlet.view.jasperreports; 18 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 import java.util.Locale ; 23 import java.util.Map ; 24 25 import junit.framework.TestCase; 26 import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; 27 28 import org.springframework.mock.web.MockHttpServletRequest; 29 import org.springframework.mock.web.MockHttpServletResponse; 30 import org.springframework.ui.jasperreports.PersonBean; 31 import org.springframework.ui.jasperreports.ProductBean; 32 import org.springframework.web.servlet.DispatcherServlet; 33 import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; 34 35 39 public abstract class AbstractJasperReportsTests extends TestCase { 40 41 protected static final String COMPILED_REPORT = 42 "org/springframework/ui/jasperreports/DataSourceReport.jasper"; 43 44 protected static final String UNCOMPILED_REPORT = 45 "org/springframework/ui/jasperreports/DataSourceReport.jrxml"; 46 47 protected static final String SUB_REPORT_PARENT = 48 "org/springframework/ui/jasperreports/subReportParent.jrxml"; 49 50 protected static boolean canCompileReport; 51 52 static { 53 try { 54 Class.forName("org.eclipse.jdt.internal.compiler.Compiler"); 55 canCompileReport = true; 56 } 57 catch (ClassNotFoundException ex) { 58 canCompileReport = false; 59 } 60 } 61 62 63 protected MockHttpServletRequest request; 64 65 protected MockHttpServletResponse response; 66 67 68 public void setUp() { 69 request = new MockHttpServletRequest(); 70 response = new MockHttpServletResponse(); 71 72 request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver()); 73 request.addPreferredLocale(Locale.GERMAN); 74 } 75 76 77 protected Map getModel() { 78 Map model = new HashMap (); 79 model.put("ReportTitle", "Dear Lord!"); 80 model.put("dataSource", new JRBeanCollectionDataSource(getData())); 81 extendModel(model); 82 return model; 83 } 84 85 88 protected void extendModel(Map model) { 89 } 90 91 protected List getData() { 92 List list = new ArrayList (); 93 for (int x = 0; x < 10; x++) { 94 PersonBean bean = new PersonBean(); 95 bean.setId(x); 96 bean.setName("Rob Harrop"); 97 bean.setStreet("foo"); 98 list.add(bean); 99 } 100 return list; 101 } 102 103 protected List getProductData() { 104 List list = new ArrayList (); 105 for (int x = 0; x < 10; x++) { 106 ProductBean bean = new ProductBean(); 107 bean.setId(x); 108 bean.setName("Foo Bar"); 109 bean.setPrice(1.9f); 110 bean.setQuantity(1.0f); 111 112 list.add(bean); 113 } 114 return list; 115 } 116 117 } 118 | Popular Tags |