KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > jsptests > MediaSupportXmlTest


1 package org.displaytag.jsptests;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.displaytag.properties.MediaTypeEnum;
5 import org.displaytag.tags.TableTagParameters;
6 import org.displaytag.test.DisplaytagCase;
7 import org.displaytag.test.KnownValue;
8 import org.displaytag.util.ParamEncoder;
9
10 import com.meterware.httpunit.GetMethodWebRequest;
11 import com.meterware.httpunit.WebRequest;
12 import com.meterware.httpunit.WebResponse;
13
14
15 /**
16  * Tests for "media" attribute support.
17  * @author Fabrizio Giustina
18  * @version $Revision: 707 $ ($Author: fgiust $)
19  */

20 public class MediaSupportXmlTest extends DisplaytagCase
21 {
22
23     /**
24      * @see org.displaytag.test.DisplaytagCase#getJspName()
25      */

26     public String JavaDoc getJspName()
27     {
28         return "media.jsp";
29     }
30
31     /**
32      * Test as Xml.
33      * @param jspName jsp name, with full path
34      * @throws Exception any axception thrown during test.
35      */

36     public void doTest(String JavaDoc jspName) throws Exception JavaDoc
37     {
38
39         ParamEncoder encoder = new ParamEncoder("table");
40         String JavaDoc mediaParameter = encoder.encodeParameterName(TableTagParameters.PARAMETER_EXPORTTYPE);
41
42         WebRequest request = new GetMethodWebRequest(jspName);
43         request.setParameter(mediaParameter, "" + MediaTypeEnum.XML.getCode());
44
45         WebResponse response = runner.getResponse(request);
46
47         if (log.isDebugEnabled())
48         {
49             log.debug("RESPONSE: " + response.getText());
50         }
51
52         // we are really testing an xml output?
53
assertEquals("Expected a different content type.", "text/xml", response.getContentType());
54
55         String JavaDoc output = response.getText();
56
57         assertTrue("Expected value [" + KnownValue.BEE + "] missing", StringUtils.contains(output, KnownValue.BEE));
58         assertTrue("Expected value [" + KnownValue.CAMEL + "] missing", StringUtils.contains(output, KnownValue.CAMEL));
59         assertTrue("Unexpected value [" + KnownValue.ANT + "] found", !StringUtils.contains(output, KnownValue.ANT));
60
61     }
62
63 }
Popular Tags