1 package org.displaytag.jsptests; 2 3 import org.displaytag.properties.MediaTypeEnum; 4 import org.displaytag.tags.TableTagParameters; 5 import org.displaytag.test.DisplaytagCase; 6 import org.displaytag.util.ParamEncoder; 7 8 import com.meterware.httpunit.GetMethodWebRequest; 9 import com.meterware.httpunit.WebRequest; 10 import com.meterware.httpunit.WebResponse; 11 import com.meterware.httpunit.WebTable; 12 13 14 19 public class OptimizedIterationTest extends DisplaytagCase 20 { 21 22 25 public String getJspName() 26 { 27 return "optimizediteration.jsp"; 28 } 29 30 36 public void doTest(String jspName) throws Exception 37 { 38 39 WebRequest request = new GetMethodWebRequest(jspName); 40 ParamEncoder encoder = new ParamEncoder("table"); 41 42 request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "1"); 44 checkNumberOfIterations(runner.getResponse(request), 1); 45 46 request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "2"); 48 checkNumberOfIterations(runner.getResponse(request), 1); 49 50 request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_SORT), "1"); 52 request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "1"); 53 checkNumberOfIterations(runner.getResponse(request), 4); 54 55 request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_EXPORTTYPE), Integer 57 .toString(MediaTypeEnum.CSV.getCode())); 58 request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "1"); 59 60 WebResponse response = runner.getResponse(request); 61 String csvExport = response.getText(); 62 if (log.isDebugEnabled()) 63 { 64 log.debug(response.getText()); 65 } 66 67 assertEquals("Wrong csv export", "ant,1\nant,2\nant,3\nant,4\n", csvExport); 68 69 } 70 71 76 private void checkNumberOfIterations(WebResponse response, int iterations) throws Exception 77 { 78 if (log.isDebugEnabled()) 79 { 80 log.debug(response.getText()); 81 } 82 83 WebTable[] tables = response.getTables(); 84 assertEquals("Expected 1 table in result.", 1, tables.length); 85 assertEquals("Expected 2 rows in table.", 2, tables[0].getRowCount()); 86 87 assertEquals("Wrong number of iterations. Evaluated column bodies number is different from expected", Integer 88 .toString(iterations), response.getElementWithID("iterations").getText()); 89 } 90 } | Popular Tags |