Execute as many Jasper Reports tests in IDE as possible

Previously, the use of Assume.group(CUSTOM_COMPILATION) in
AbstractJasperReportsTests excluded all JR tests when executing in the
IDE (e.g., Eclipse). This commit executes the assumption only where
necessary.
This commit is contained in:
Sam Brannen 2014-03-28 14:06:00 +01:00
parent db66ef0f6f
commit 6aaae7e258
3 changed files with 56 additions and 48 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,10 +26,10 @@ import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import org.junit.Before;
import org.junit.BeforeClass;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.ui.jasperreports.PersonBean;
import org.springframework.ui.jasperreports.ProductBean;
import org.springframework.util.ClassUtils;
@ -39,6 +39,7 @@ import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Sam Brannen
*/
public abstract class AbstractJasperReportsTests {
@ -60,7 +61,6 @@ public abstract class AbstractJasperReportsTests {
@BeforeClass
public static void assumptions() {
Assume.canLoadNativeDirFonts();
Assume.group(TestGroup.CUSTOM_COMPILATION);
}
@Before
@ -72,9 +72,8 @@ public abstract class AbstractJasperReportsTests {
request.addPreferredLocale(Locale.GERMAN);
}
protected Map<String, Object> getModel() {
Map model = new HashMap();
Map<String, Object> model = new HashMap<String, Object>();
model.put("ReportTitle", "Dear Lord!");
model.put("dataSource", new JRBeanCollectionDataSource(getData()));
extendModel(model);
@ -87,8 +86,8 @@ public abstract class AbstractJasperReportsTests {
protected void extendModel(Map<String, Object> model) {
}
protected List getData() {
List list = new ArrayList();
protected List<Object> getData() {
List<Object> list = new ArrayList<Object>();
for (int x = 0; x < 10; x++) {
PersonBean bean = new PersonBean();
bean.setId(x);
@ -99,15 +98,14 @@ public abstract class AbstractJasperReportsTests {
return list;
}
protected List getProductData() {
List list = new ArrayList();
protected List<Object> getProductData() {
List<Object> list = new ArrayList<Object>();
for (int x = 0; x < 10; x++) {
ProductBean bean = new ProductBean();
bean.setId(x);
bean.setName("Foo Bar");
bean.setPrice(1.9f);
bean.setQuantity(1.0f);
list.add(bean);
}
return list;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -35,8 +35,11 @@ import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContextException;
import org.springframework.mock.web.test.MockServletContext;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.ui.jasperreports.PersonBean;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
@ -47,6 +50,7 @@ import static org.mockito.BDDMockito.*;
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Sam Brannen
*/
public abstract class AbstractJasperReportsViewTests extends AbstractJasperReportsTests {
@ -79,6 +83,8 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testUncompiledReport() throws Exception {
Assume.group(TestGroup.CUSTOM_COMPILATION);
if (!canCompileReport) {
return;
}
@ -88,26 +94,14 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
assertTrue(response.getContentAsByteArray().length > 0);
}
@Test
@Test(expected = ApplicationContextException.class)
public void testWithInvalidPath() throws Exception {
try {
getView("foo.jasper");
fail("Invalid path should throw ApplicationContextException");
}
catch (ApplicationContextException ex) {
// good!
}
getView("foo.jasper");
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testInvalidExtension() throws Exception {
try {
getView("foo.bar");
fail("Invalid extension should throw IllegalArgumentException");
}
catch (IllegalArgumentException ex) {
// expected
}
getView("foo.bar");
}
@Test
@ -119,7 +113,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testWithoutDatasource() throws Exception {
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
AbstractJasperReportsView view = getView(COMPILED_REPORT);
view.render(model, request, response);
@ -128,7 +122,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testWithCollection() throws Exception {
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
model.put("reportData", getData());
AbstractJasperReportsView view = getView(COMPILED_REPORT);
@ -137,8 +131,9 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
}
@Test
@SuppressWarnings("rawtypes")
public void testWithMultipleCollections() throws Exception {
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
model.put("reportData", getData());
model.put("otherData", new LinkedList());
@ -149,7 +144,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testWithJRDataSourceProvider() throws Exception {
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
model.put("dataSource", new MockDataSourceProvider(PersonBean.class));
AbstractJasperReportsView view = getView(COMPILED_REPORT);
@ -158,8 +153,9 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
}
@Test
@SuppressWarnings("rawtypes")
public void testWithSpecificCollection() throws Exception {
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
model.put("reportData", getData());
model.put("otherData", new LinkedList());
@ -171,7 +167,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testWithArray() throws Exception {
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
model.put("reportData", getData().toArray());
AbstractJasperReportsView view = getView(COMPILED_REPORT);
@ -181,7 +177,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testWithMultipleArrays() throws Exception {
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
model.put("reportData", getData().toArray());
model.put("otherData", new String[0]);
@ -192,7 +188,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testWithSpecificArray() throws Exception {
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
model.put("reportData", getData().toArray());
model.put("otherData", new String[0]);
@ -208,7 +204,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
return;
}
Map model = getModel();
Map<String, Object> model = getModel();
model.put("SubReportData", getProductData());
Properties subReports = new Properties();
@ -230,7 +226,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
return;
}
Map model = getModel();
Map<String, Object> model = getModel();
model.put("SubReportData", getProductData());
Properties subReports = new Properties();
@ -243,7 +239,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
try {
view.initApplicationContext();
fail("Invalid report URL should throw ApplicationContext Exception");
fail("Invalid report URL should throw ApplicationContextException");
}
catch (ApplicationContextException ex) {
// success
@ -261,14 +257,14 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
String characterEncoding = "UTF-8";
String overiddenCharacterEncoding = "ASCII";
Map parameters = new HashMap();
Map<Object, Object> parameters = new HashMap<Object, Object>();
parameters.put(JRExporterParameter.CHARACTER_ENCODING, characterEncoding);
view.setExporterParameters(parameters);
view.convertExporterParameters();
Map model = getModel();
model.put(JRExporterParameter.CHARACTER_ENCODING, overiddenCharacterEncoding);
Map<String, Object> model = getModel();
model.put(JRExporterParameter.CHARACTER_ENCODING.toString(), overiddenCharacterEncoding);
view.render(model, this.request, this.response);
@ -281,7 +277,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
return;
}
Map model = getModel();
Map<String, Object> model = getModel();
model.put("SubReportData", getProductData());
Properties subReports = new Properties();
@ -339,6 +335,8 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testWithJdbcDataSource() throws Exception {
Assume.group(TestGroup.CUSTOM_COMPILATION);
if (!canCompileReport) {
return;
}
@ -346,7 +344,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
AbstractJasperReportsView view = getView(UNCOMPILED_REPORT);
view.setJdbcDataSource(getMockJdbcDataSource());
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
try {
@ -360,13 +358,15 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testWithJdbcDataSourceInModel() throws Exception {
Assume.group(TestGroup.CUSTOM_COMPILATION);
if (!canCompileReport) {
return;
}
AbstractJasperReportsView view = getView(UNCOMPILED_REPORT);
Map model = getModel();
Map<String, Object> model = getModel();
model.remove("dataSource");
model.put("someKey", getMockJdbcDataSource());
@ -381,6 +381,8 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
@Test
public void testJRDataSourceOverridesJdbcDataSource() throws Exception {
Assume.group(TestGroup.CUSTOM_COMPILATION);
if (!canCompileReport) {
return;
}
@ -412,7 +414,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
String characterEncoding = "UTF-8";
Map parameters = new HashMap();
Map<Object, Object> parameters = new HashMap<Object, Object>();
parameters.put(JRExporterParameter.CHARACTER_ENCODING, characterEncoding);
view.setExporterParameters(parameters);
@ -430,7 +432,7 @@ public abstract class AbstractJasperReportsViewTests extends AbstractJasperRepor
private class MockDataSourceProvider extends JRAbstractBeanDataSourceProvider {
public MockDataSourceProvider(Class clazz) {
public MockDataSourceProvider(Class<?> clazz) {
super(clazz);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,8 @@ import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JasperPrint;
import org.junit.Test;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import static org.junit.Assert.*;
@ -41,6 +43,8 @@ public class JasperReportsMultiFormatViewTests extends AbstractJasperReportsView
@Test
public void testSimpleHtmlRender() throws Exception {
Assume.group(TestGroup.CUSTOM_COMPILATION);
if (!canCompileReport) {
return;
}
@ -58,6 +62,8 @@ public class JasperReportsMultiFormatViewTests extends AbstractJasperReportsView
@Override
@Test
public void testOverrideContentDisposition() throws Exception {
Assume.group(TestGroup.CUSTOM_COMPILATION);
if (!canCompileReport) {
return;
}
@ -82,6 +88,8 @@ public class JasperReportsMultiFormatViewTests extends AbstractJasperReportsView
@Test
public void testExporterParametersAreCarriedAcross() throws Exception {
Assume.group(TestGroup.CUSTOM_COMPILATION);
if (!canCompileReport) {
return;
}
@ -134,7 +142,7 @@ public class JasperReportsMultiFormatViewTests extends AbstractJasperReportsView
public static final String TEST_PARAM = "net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI";
@Override
protected void renderReport(JasperPrint filledReport, Map parameters, HttpServletResponse response) {
protected void renderReport(JasperPrint filledReport, Map<String, Object> parameters, HttpServletResponse response) {
assertNotNull("Exporter parameters are null", getExporterParameters());
assertEquals("Incorrect number of exporter parameters", 1, getExporterParameters().size());
}