1 package org.displaytag.properties;
2
3 import org.displaytag.localization.I18nResourceProvider;
4 import org.displaytag.localization.LocaleResolver;
5 import org.displaytag.test.DisplaytagCase;
6 import org.displaytag.test.KnownValue;
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 /**
15 * Tests for "titlekey" column attribute.
16 * @author Fabrizio Giustina
17 * @version $Revision: 707 $ ($Author: fgiust $)
18 */
19 public abstract class AbstractTitleKeyAutoColumnTest extends DisplaytagCase
20 {
21
22 /**
23 * @see org.displaytag.test.DisplaytagCase#getJspName()
24 */
25 public String getJspName()
26 {
27 return "titlekeyautocolumn.jsp";
28 }
29
30 /**
31 * Returns the suffix expected in the specific resource bundle.
32 * @return expected suffix
33 */
34 protected abstract String getExpectedSuffix();
35
36 /**
37 * Returns the LocaleResolver instance to be used in this test.
38 * @return LocaleResolver
39 */
40 protected abstract LocaleResolver getResolver();
41
42 /**
43 * Returns the I18nResourceProvider instance to be used in this test.
44 * @return I18nResourceProvider
45 */
46 protected abstract I18nResourceProvider getI18nResourceProvider();
47
48 /**
49 * Test that headers are correctly removed.
50 * @param jspName jsp name, with full path
51 * @throws Exception any axception thrown during test.
52 */
53 public void doTest(String jspName) throws Exception
54 {
55 // test keep
56 WebRequest request = new GetMethodWebRequest(jspName);
57
58 TableProperties.setLocaleResolver(getResolver());
59 TableProperties.setResourceProvider(getI18nResourceProvider());
60
61 WebResponse response;
62 try
63 {
64 response = runner.getResponse(request);
65 }
66 finally
67 {
68 // reset
69 TableProperties.setLocaleResolver(null);
70 TableProperties.setResourceProvider(null);
71 }
72
73 if (log.isDebugEnabled())
74 {
75 log.debug(response.getText());
76 }
77
78 WebTable[] tables = response.getTables();
79 assertEquals("Expected one table", 1, tables.length);
80
81 // find the "camel" column
82 int j;
83 for (j = 0; j < tables[0].getColumnCount(); j++)
84 {
85 if (KnownValue.CAMEL.equals(tables[0].getCellAsText(1, j)))
86 {
87 break;
88 }
89 }
90
91 // resource should be used also without the property attribute for the "camel" header
92 assertEquals("Header from resource is not valid.", "camel title" + getExpectedSuffix(), tables[0]
93 .getCellAsText(0, j));
94
95 }
96 }