KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > view > jasperreports > AbstractJasperReportsTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.servlet.view.jasperreports;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Locale JavaDoc;
23 import java.util.Map JavaDoc;
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 /**
36  * @author Rob Harrop
37  * @since 18.11.2004
38  */

39 public abstract class AbstractJasperReportsTests extends TestCase {
40
41     protected static final String JavaDoc COMPILED_REPORT =
42             "org/springframework/ui/jasperreports/DataSourceReport.jasper";
43
44     protected static final String JavaDoc UNCOMPILED_REPORT =
45             "org/springframework/ui/jasperreports/DataSourceReport.jrxml";
46
47     protected static final String JavaDoc 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 JavaDoc 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 JavaDoc getModel() {
78         Map JavaDoc model = new HashMap JavaDoc();
79         model.put("ReportTitle", "Dear Lord!");
80         model.put("dataSource", new JRBeanCollectionDataSource(getData()));
81         extendModel(model);
82         return model;
83     }
84
85     /**
86      * Subclasses can extend the model if they need to.
87      */

88     protected void extendModel(Map JavaDoc model) {
89     }
90
91     protected List JavaDoc getData() {
92         List JavaDoc list = new ArrayList JavaDoc();
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 JavaDoc getProductData() {
104         List JavaDoc list = new ArrayList JavaDoc();
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