1 package org.displaytag.jsptests; 2 3 import org.apache.commons.lang.StringUtils; 4 import org.displaytag.test.DisplaytagCase; 5 6 import com.meterware.httpunit.GetMethodWebRequest; 7 import com.meterware.httpunit.WebLink; 8 import com.meterware.httpunit.WebRequest; 9 import com.meterware.httpunit.WebResponse; 10 import com.meterware.httpunit.WebTable; 11 12 13 /** 14 * Tests for DISPL-56 - unable to dinamically generate multiple tables on the same page with indipendent sorting 15 * (different id). 16 * @author Fabrizio Giustina 17 * @version $Revision: 894 $ ($Author: fgiust $) 18 */ 19 public class Displ056Test extends DisplaytagCase 20 { 21 22 /** 23 * @see org.displaytag.test.DisplaytagCase#getJspName() 24 */ 25 public String getJspName() 26 { 27 return "DISPL-056.jsp"; 28 } 29 30 /** 31 * Try to sort generated tables. 32 * @param jspName jsp name, with full path 33 * @throws Exception any axception thrown during test. 34 */ 35 public void doTest(String jspName) throws Exception 36 { 37 WebRequest request = new GetMethodWebRequest(jspName); 38 WebResponse response; 39 40 response = runner.getResponse(request); 41 42 if (log.isDebugEnabled()) 43 { 44 log.debug(response.getText()); 45 } 46 47 WebTable[] tables = response.getTables(); 48 assertEquals("Wrong number of tables in result.", 3, tables.length); 49 50 for (int j = 0; j < tables.length; j++) 51 { 52 assertEquals("invalid id", "row" + j, tables[j].getID()); 53 } 54 55 WebLink[] links = response.getLinks(); 56 assertEquals("Wrong number of links in result.", 3, links.length); 57 58 // click to sort the first table 59 response = links[0].click(); 60 61 // get the links 62 links = response.getLinks(); 63 assertEquals("Wrong number of links in result.", 3, links.length); 64 65 // and click again to sort in reversed order 66 response = links[0].click(); 67 68 if (log.isDebugEnabled()) 69 { 70 log.debug(response.getText()); 71 } 72 73 tables = response.getTables(); 74 assertEquals("Wrong number of tables in result.", 3, tables.length); 75 76 // first is sorted, other aren't 77 assertTrue("First table should be sorted. Wrong class attribute.", // 78 StringUtils.contains(tables[0].getTableCell(0, 0).getClassName(), "sorted")); 79 assertEquals("Second table should not be sorted. Wrong class attribute.", // 80 "sortable", 81 tables[1].getTableCell(0, 0).getClassName()); 82 assertEquals("Third table should not be sorted. Wrong class attribute.", // 83 "sortable", 84 tables[2].getTableCell(0, 0).getClassName()); 85 86 // and just to be sure also check values: sorted table 87 for (int j = 1; j < tables[0].getRowCount(); j++) 88 { 89 assertEquals("Unexpected value in table cell", Integer.toString(4 - j), tables[0].getCellAsText(j, 0)); 90 } 91 92 // unsorted tables: 93 for (int j = 1; j < tables[1].getRowCount(); j++) 94 { 95 assertEquals("Unexpected value in table cell", Integer.toString(j), tables[1].getCellAsText(j, 0)); 96 assertEquals("Unexpected value in table cell", Integer.toString(j), tables[2].getCellAsText(j, 0)); 97 } 98 } 99 }