1 package org.displaytag.jsptests; 2 3 import org.displaytag.test.DisplaytagCase; 4 import org.xml.sax.SAXException ; 5 6 import com.meterware.httpunit.GetMethodWebRequest; 7 import com.meterware.httpunit.TableCell; 8 import com.meterware.httpunit.WebLink; 9 import com.meterware.httpunit.WebRequest; 10 import com.meterware.httpunit.WebResponse; 11 import com.meterware.httpunit.WebTable; 12 13 14 19 public class Displ017Test extends DisplaytagCase 20 { 21 22 25 public String getJspName() 26 { 27 return "DISPL-017.jsp"; 28 } 29 30 35 public void doTest(String jspName) throws Exception 36 { 37 38 WebRequest request = new GetMethodWebRequest(jspName); 39 40 WebResponse response = runner.getResponse(request); 41 42 for (int j = 0; j < 4; j++) 43 { 44 WebLink[] links = response.getLinks(); 45 response = links[j].click(); 46 47 if (log.isDebugEnabled()) 48 { 49 log.debug("After clicking on " + j + ":\n" + response.getText()); 50 } 51 checkOnlyOneSorted(response, j); 52 } 53 54 } 55 56 62 private void checkOnlyOneSorted(WebResponse response, int sortedColumn) throws SAXException 63 { 64 WebTable[] tables = response.getTables(); 65 66 assertEquals("Wrong number of tables.", 1, tables.length); 67 assertEquals("Wrong number of columns in result.", 4, tables[0].getColumnCount()); 68 69 for (int j = 0; j < 4; j++) 70 { 71 TableCell cell = tables[0].getTableCell(0, j); 72 boolean containsSorted = (cell.getAttribute("class").indexOf("sorted") > -1); 73 if (j == sortedColumn) 74 { 75 assertTrue("Column " + j + " is not sorted as expected", containsSorted); 76 } 77 else 78 { 79 assertFalse("Column " + j + " is sorted, but only " + sortedColumn + " should be", containsSorted); 80 } 81 82 } 83 84 } 85 86 } | Popular Tags |