1 package org.displaytag.jsptests; 2 3 import java.io.InputStream ; 4 5 import org.displaytag.export.ExportViewFactory; 6 import org.displaytag.properties.MediaTypeEnum; 7 import org.displaytag.tags.TableTagParameters; 8 import org.displaytag.test.DisplaytagCase; 9 import org.displaytag.util.ParamEncoder; 10 11 import com.lowagie.text.pdf.PdfReader; 12 import com.meterware.httpunit.GetMethodWebRequest; 13 import com.meterware.httpunit.WebRequest; 14 import com.meterware.httpunit.WebResponse; 15 16 17 22 public class ExportPdfTest extends DisplaytagCase 23 { 24 25 28 public String getJspName() 29 { 30 return "exportfull.jsp"; 31 } 32 33 38 public void doTest(String jspName) throws Exception 39 { 40 41 ParamEncoder encoder = new ParamEncoder("table"); 42 String mediaParameter = encoder.encodeParameterName(TableTagParameters.PARAMETER_EXPORTTYPE); 43 WebRequest request = new GetMethodWebRequest(jspName); 44 45 ExportViewFactory.getInstance(); 47 MediaTypeEnum pdfMedia = MediaTypeEnum.fromName("pdf"); 48 assertNotNull("Pdf export view not correctly registered.", pdfMedia); 49 request.setParameter(mediaParameter, Integer.toString(pdfMedia.getCode())); 50 51 WebResponse response = runner.getResponse(request); 52 53 assertEquals("Expected a different content type.", "application/pdf", response.getContentType()); 55 56 InputStream stream = response.getInputStream(); 57 byte[] result = new byte[3000]; 58 stream.read(result); 59 60 PdfReader reader = new PdfReader(result); 61 assertEquals("Expected a valid pdf file with a single page", 1, reader.getNumberOfPages()); 62 63 } 64 65 } | Popular Tags |