1 package org.displaytag.jsptests; 2 3 import java.io.InputStream ; 4 5 import org.displaytag.properties.MediaTypeEnum; 6 import org.displaytag.tags.TableTagParameters; 7 import org.displaytag.test.DisplaytagCase; 8 import org.displaytag.util.ParamEncoder; 9 10 import com.meterware.httpunit.GetMethodWebRequest; 11 import com.meterware.httpunit.WebRequest; 12 import com.meterware.httpunit.WebResponse; 13 14 15 20 public class Displ107Test extends DisplaytagCase 21 { 22 23 26 public String getJspName() 27 { 28 return "DISPL-107.jsp"; 29 } 30 31 36 public void doTest(String jspName) throws Exception 37 { 38 WebRequest request = new GetMethodWebRequest(jspName); 39 40 WebResponse response = runner.getResponse(request); 41 assertEquals("Wrong encoding", "UTF8", response.getCharacterSet()); 42 43 ParamEncoder encoder = new ParamEncoder("table"); 44 String mediaParameter = encoder.encodeParameterName(TableTagParameters.PARAMETER_EXPORTTYPE); 45 request = new GetMethodWebRequest(jspName); 46 request.setParameter(mediaParameter, Integer.toString(MediaTypeEnum.CSV.getCode())); 47 48 response = runner.getResponse(request); 49 checkContent(response); 50 51 request.setParameter(TableTagParameters.PARAMETER_EXPORTING, "1"); 53 response = runner.getResponse(request); 54 checkContent(response); 55 56 } 57 58 63 private void checkContent(WebResponse response) throws Exception 64 { 65 assertEquals("Expected a different content type.", "text/csv", response.getContentType()); 67 assertEquals("Wrong encoding", "UTF8", response.getCharacterSet()); 68 69 InputStream stream = response.getInputStream(); 70 byte[] result = new byte[11]; 71 stream.read(result); 72 73 byte[] expected = "ant,àèì\n".getBytes("utf-8"); 74 if (log.isDebugEnabled()) 75 { 76 log.debug("expected: [" + new String (expected, "utf-8") + "]"); 77 log.debug("result: [" + new String (result, "utf-8") + "]"); 78 } 79 assertEquals("Wrong length", expected.length, result.length); 80 81 for (int j = 0; j < result.length; j++) 82 { 83 assertEquals( 84 "Wrong byte at position " + j + ", output=" + new String (result, "utf-8"), 85 expected[j], 86 result[j]); 87 88 } 89 } 90 91 } | Popular Tags |