001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestElements.java 3669 2007-02-26 13:51:23Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import java.util.Arrays;
011:
012: import com.meterware.httpunit.GetMethodWebRequest;
013: import com.meterware.httpunit.WebConversation;
014: import com.meterware.httpunit.WebRequest;
015: import com.meterware.httpunit.WebResponse;
016: import com.uwyn.rife.TestCaseServerside;
017:
018: public class TestElements extends TestCaseServerside {
019: public TestElements(int siteType, String name) {
020: super (siteType, name);
021: }
022:
023: public void testPrintTemplate() throws Exception {
024: setupSite("site/elements.xml");
025: WebConversation conversation = new WebConversation();
026: WebRequest request = null;
027: WebResponse response = null;
028:
029: request = new GetMethodWebRequest(
030: "http://localhost:8181/print_template_staticproperties");
031: response = conversation.getResponse(request);
032: assertEquals(
033: "<html>\n\t<head>\n\t\t<title>PrintTemplate elements test</title>\n\t</head>\n\n\t<body>\n\t\t<h1>This template should be printed by the PrintTemplate element.</h1>\n\t</body>\n</html>\n",
034: response.getText());
035: }
036:
037: public void testPrintTemplateXhtml() throws Exception {
038: setupSite("site/elements.xml");
039: WebConversation conversation = new WebConversation();
040: WebRequest request = null;
041: WebResponse response = null;
042:
043: request = new GetMethodWebRequest(
044: "http://localhost:8181/print_template_staticproperties_xhtml");
045: response = conversation.getResponse(request);
046: assertEquals(
047: "<html>\n\t<head>\n\t\t<title>PrintTemplate elements test</title>\n\t</head>\n\n\t<body>\n\t\t<h1>This xhtml template should be printed by the PrintTemplate element.</h1>\n\t</body>\n</html>\n",
048: response.getText());
049: }
050:
051: public void testPrintTemplateProperties() throws Exception {
052: setupSite("site/elements.xml");
053: WebConversation conversation = new WebConversation();
054: WebRequest request = null;
055: WebResponse response = null;
056:
057: request = new GetMethodWebRequest(
058: "http://localhost:8181/print_template_properties");
059: response = conversation.getResponse(request);
060: assertEquals(
061: "<html>\n\t<head>\n\t\t<title>PrintTemplate elements test</title>\n\t</head>\n\n\t<body>\n\t\t<h1>This template should be printed by the PrintTemplate element.</h1>\n\t</body>\n</html>\n",
062: response.getText());
063: }
064:
065: public void testRedirectStaticProperties() throws Exception {
066: setupSite("site/elements.xml");
067: WebConversation conversation = new WebConversation();
068: WebRequest request = null;
069: WebResponse response = null;
070:
071: request = new GetMethodWebRequest(
072: "http://localhost:8181/redirect_staticproperties");
073: response = conversation.getResponse(request);
074: assertEquals(
075: "<html>\n\t<head>\n\t\t<title>PrintTemplate elements test</title>\n\t</head>\n\n\t<body>\n\t\t<h1>This template should be printed by the PrintTemplate element.</h1>\n\t</body>\n</html>\n",
076: response.getText());
077: }
078:
079: public void testRedirectProperties() throws Exception {
080: setupSite("site/elements.xml");
081: WebConversation conversation = new WebConversation();
082: WebRequest request = null;
083: WebResponse response = null;
084:
085: request = new GetMethodWebRequest(
086: "http://localhost:8181/redirect_properties");
087: response = conversation.getResponse(request);
088: assertEquals(
089: "<html>\n\t<head>\n\t\t<title>PrintTemplate elements test</title>\n\t</head>\n\n\t<body>\n\t\t<h1>This template should be printed by the PrintTemplate element.</h1>\n\t</body>\n</html>\n",
090: response.getText());
091: }
092:
093: public void testRedirectStaticPropertiesType() throws Exception {
094: setupSite("site/elements.xml");
095: WebConversation conversation = new WebConversation();
096: WebRequest request = null;
097: WebResponse response = null;
098:
099: request = new GetMethodWebRequest(
100: "http://localhost:8181/redirect_staticproperties_type");
101: response = conversation.getResponse(request);
102: assertEquals(
103: "<html>\n\t<head>\n\t\t<title>PrintTemplate elements test</title>\n\t</head>\n\n\t<body>\n\t\t<h1>This template should be printed by the PrintTemplate element.</h1>\n\t</body>\n</html>\n",
104: response.getText());
105: }
106:
107: public void testRedirectPropertiesType() throws Exception {
108: setupSite("site/elements.xml");
109: WebConversation conversation = new WebConversation();
110: WebRequest request = null;
111: WebResponse response = null;
112:
113: request = new GetMethodWebRequest(
114: "http://localhost:8181/redirect_properties_type");
115: response = conversation.getResponse(request);
116: assertEquals(
117: "<html>\n\t<head>\n\t\t<title>PrintTemplate elements test</title>\n\t</head>\n\n\t<body>\n\t\t<h1>This xhtml template should be printed by the PrintTemplate element.</h1>\n\t</body>\n</html>\n",
118: response.getText());
119: }
120:
121: public void testUncached() throws Exception {
122: setupSite("site/elements.xml");
123: WebConversation conversation = new WebConversation();
124: WebRequest request = null;
125: WebResponse response = null;
126:
127: request = new GetMethodWebRequest(
128: "http://localhost:8181/uncached");
129: response = conversation.getResponse(request);
130: assertEquals(response.getHeaderFields("Cache-Control").length,
131: 3);
132: assertTrue(Arrays.asList(
133: response.getHeaderFields("Cache-Control")).contains(
134: "no-cache"));
135: assertTrue(Arrays.asList(
136: response.getHeaderFields("Cache-Control")).contains(
137: "no-store"));
138: assertTrue(Arrays.asList(
139: response.getHeaderFields("Cache-Control")).contains(
140: "must-revalidate"));
141: assertEquals(response.getHeaderFields("Pragma").length, 1);
142: assertEquals(response.getHeaderField("Pragma"), "no-cache");
143: assertEquals(response.getHeaderFields("Expires").length, 1);
144: assertEquals(response.getHeaderField("Expires"), "1");
145:
146: request = new GetMethodWebRequest(
147: "http://localhost:8181/cached");
148: response = conversation.getResponse(request);
149: assertNull(response.getHeaderField("Cache-Control"));
150: assertNull(response.getHeaderField("Pragma"));
151: assertNull(response.getHeaderField("Expires"));
152: }
153: }
|