KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > properties > AbstractTitleKeyTest


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
7 import com.meterware.httpunit.GetMethodWebRequest;
8 import com.meterware.httpunit.WebRequest;
9 import com.meterware.httpunit.WebResponse;
10 import com.meterware.httpunit.WebTable;
11
12
13 /**
14  * Tests for "titlekey" column attribute.
15  * @author Fabrizio Giustina
16  * @version $Revision: 907 $ ($Author: fgiust $)
17  */

18 public abstract class AbstractTitleKeyTest extends DisplaytagCase
19 {
20
21     /**
22      * @see org.displaytag.test.DisplaytagCase#getJspName()
23      */

24     public String JavaDoc getJspName()
25     {
26         return "titlekey.jsp";
27     }
28
29     /**
30      * Returns the LocaleResolver instance to be used in this test.
31      * @return LocaleResolver
32      */

33     protected abstract LocaleResolver getResolver();
34
35     /**
36      * Returns the I18nResourceProvider instance to be used in this test.
37      * @return I18nResourceProvider
38      */

39     protected abstract I18nResourceProvider getI18nResourceProvider();
40
41     /**
42      * Returns the suffix expected in the specific resource bundle.
43      * @return expected suffix
44      */

45     protected abstract String JavaDoc getExpectedSuffix();
46
47     /**
48      * Test that headers are correctly removed.
49      * @param jspName jsp name, with full path
50      * @throws Exception any axception thrown during test.
51      */

52     public void doTest(String JavaDoc jspName) throws Exception JavaDoc
53     {
54         // test keep
55
WebRequest request = new GetMethodWebRequest(jspName);
56
57         TableProperties.setLocaleResolver(getResolver());
58         TableProperties.setResourceProvider(getI18nResourceProvider());
59
60         WebResponse response;
61         try
62         {
63             response = runner.getResponse(request);
64         }
65         finally
66         {
67             // reset
68
TableProperties.setLocaleResolver(null);
69             TableProperties.setResourceProvider(null);
70         }
71
72         if (log.isDebugEnabled())
73         {
74             log.debug(response.getText());
75         }
76
77         WebTable[] tables = response.getTables();
78         assertEquals("Expected one table", 1, tables.length);
79
80         assertEquals("Header from resource is not valid.", //
81
"foo title" + getExpectedSuffix(),
82             tables[0].getCellAsText(0, 0));
83
84         assertEquals("Header from resource is not valid.", //
85
"baz title" + getExpectedSuffix(),
86             tables[0].getCellAsText(0, 1));
87
88         assertEquals("Header from resource is not valid.", //
89
"camel title" + getExpectedSuffix(),
90             tables[0].getCellAsText(0, 2));
91
92         assertEquals("Missing resource should generate the ???missing??? header.", "???missing???", tables[0]
93             .getCellAsText(0, 3));
94
95     }
96 }
Popular Tags