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: TestEngineOutputs.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import com.meterware.httpunit.*;
011: import com.uwyn.rife.TestCaseServerside;
012: import com.uwyn.rife.engine.exceptions.OutputUnknownException;
013:
014: public class TestEngineOutputs extends TestCaseServerside {
015: public TestEngineOutputs(int siteType, String name) {
016: super (siteType, name);
017: }
018:
019: public void testOutputsValid() throws Exception {
020: setupSite("site/outputs.xml");
021: WebConversation conversation = new WebConversation();
022: WebRequest request = new GetMethodWebRequest(
023: "http://localhost:8181/outputs/valid");
024: WebResponse response = conversation.getResponse(request);
025: assertEquals("the response", response.getText());
026: }
027:
028: public void testOutputsNormalOutjection() throws Exception {
029: setupSite("site/outputs.xml");
030: WebConversation conversation = new WebConversation();
031: WebRequest request = new GetMethodWebRequest(
032: "http://localhost:8181/outputs/normal/outjection");
033: try {
034: WebResponse response = conversation.getResponse(request);
035: assertEquals("11124\n" + "value2\n" + "value3a\n" + "870\n"
036: + "programmatic value5\n" + "default value6\n",
037: response.getText());
038: } catch (Exception e) {
039: getLogSink().getInternalException().printStackTrace();
040: }
041: }
042:
043: public void testOutputsBeanNormal() throws Exception {
044: setupSite("site/outputs.xml");
045: WebConversation conversation = new WebConversation();
046: WebRequest request = new GetMethodWebRequest(
047: "http://localhost:8181/outputs/bean/normal");
048: WebResponse response = null;
049:
050: response = conversation.getResponse(request);
051: // adapt to serialization in different JDK versions
052: assertTrue(("the string,the stringbuffer,23154,893749,u,false,true,false,false,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12,H4sIAAAAAAAAAFvzloG1uIhBOCuxLFGvtCQzR8+xqCix0iezuKSi8ZLszOOJc5kZGD0ZWIozq1IrChgYGFjLWYAkVwkDc35eKlCrIFhrTmJeup5nXklqemqR0KMFS743tlswgTSyliXmlKZWFDEIINT5leYmpRa1rZkqyz3lQTcTAwPYYKYSBtaSjKJUkKH8CMVuOfmJJbfenlx02+bDG6CRbjAjCxnqGFicDA/1A9WLIdQHlxRl5qU7laalpRbps7PffHXi1WUmBmagS5LzS/NKohjYijMSi1JToqHmlDAwRTuDHcDCUFoE4mxQS9vwKLZlDcxhIgxpDJkMZQypDARABQA/lGfcTgEAAA=="
053: + "the string;the stringbuffer;23154;893749;u;null;true;false;0;21;34878.34;25435.98;3434.76;6534.8;34347897;2335454;32;12;[one, 2, three, 44.44, five]")
054: .equals(response.getText())
055: || ("the string,the stringbuffer,23154,893749,u,false,true,false,false,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12,H4sIAAAAAAAAAFvzloG1uIhBOCuxLFGvtCQzR8+xqCix0iezuKSi8ZLszOOJc5kZGD0ZWIozq1IrChgYGFjLWYAkVwkDc35eKlCrIFhrTmJeup5nXklqemqR0KMFS743tlswgTSyliXmlKZWFDEIINT5leYmpRa1rZkqyz3lQTcTAwPYYKYSBtaSjKJUkKH8CMVuOfmJJbfenlx02+bDG6CRbjAjCxnqGFicDA/1A9WLIdQHlxRl5qU7laalpRbps7PffHXi1WVmBmagS5LzS/NKohjYijMSi1JToqHmlDAwRTuDHcDCUFoE4mxQS9vwKLZlDcxhIgxpDJkMZQypDARARQUAL3zR5E8BAAA="
056: + "the string;the stringbuffer;23154;893749;u;null;true;false;0;21;34878.34;25435.98;3434.76;6534.8;34347897;2335454;32;12;[one, 2, three, 44.44, five]")
057: .equals(response.getText()));
058: }
059:
060: public void testOutputsBeanNormalOutjection() throws Exception {
061: setupSite("site/outputs.xml");
062: WebConversation conversation = new WebConversation();
063: WebRequest request = new GetMethodWebRequest(
064: "http://localhost:8181/outputs/bean/normal/outjection");
065: WebResponse response = null;
066:
067: response = conversation.getResponse(request);
068: // adapt to serialization in different JDK versions
069: assertTrue(("the string,the stringbuffer,23154,893749,u,false,true,false,false,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12,H4sIAAAAAAAAAFvzloG1uIhBOCuxLFGvtCQzR8+xqCix0iezuKSi8ZLszOOJc5kZGD0ZWIozq1IrChgYGFjLWYAkVwkDc35eKlCrIFhrTmJeup5nXklqemqR0KMFS743tlswgTSyliXmlKZWFDEIINT5leYmpRa1rZkqyz3lQTcTAwPYYKYSBtaSjKJUkKH8CMVuOfmJJbfenlx02+bDG6CRbjAjCxnqGFicDA/1A9WLIdQHlxRl5qU7laalpRbps7PffHXi1WUmBmagS5LzS/NKohjYijMSi1JToqHmlDAwRTuDHcDCUFoE4mxQS9vwKLZlDcxhIgxpDJkMZQypDARABQA/lGfcTgEAAA=="
070: + "the string;the stringbuffer;23154;893749;u;null;true;false;0;21;34878.34;25435.98;3434.76;6534.8;34347897;2335454;32;12;[one, 2, three, 44.44, five]")
071: .equals(response.getText())
072: || ("the string,the stringbuffer,23154,893749,u,false,true,false,false,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12,H4sIAAAAAAAAAFvzloG1uIhBOCuxLFGvtCQzR8+xqCix0iezuKSi8ZLszOOJc5kZGD0ZWIozq1IrChgYGFjLWYAkVwkDc35eKlCrIFhrTmJeup5nXklqemqR0KMFS743tlswgTSyliXmlKZWFDEIINT5leYmpRa1rZkqyz3lQTcTAwPYYKYSBtaSjKJUkKH8CMVuOfmJJbfenlx02+bDG6CRbjAjCxnqGFicDA/1A9WLIdQHlxRl5qU7laalpRbps7PffHXi1WVmBmagS5LzS/NKohjYijMSi1JToqHmlDAwRTuDHcDCUFoE4mxQS9vwKLZlDcxhIgxpDJkMZQypDARARQUAL3zR5E8BAAA="
073: + "the string;the stringbuffer;23154;893749;u;null;true;false;0;21;34878.34;25435.98;3434.76;6534.8;34347897;2335454;32;12;[one, 2, three, 44.44, five]")
074: .equals(response.getText()));
075: }
076:
077: public void testOutputsBeanPrefix() throws Exception {
078: setupSite("site/outputs.xml");
079: WebConversation conversation = new WebConversation();
080: WebRequest request = new GetMethodWebRequest(
081: "http://localhost:8181/outputs/bean/prefix");
082: WebResponse response = null;
083:
084: response = conversation.getResponse(request);
085: assertEquals(
086: "the string,the stringbuffer,23154,893749,u,false,true,false,false,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
087: response.getText());
088: }
089:
090: public void testOutputsBeanPrefixOutjection() throws Exception {
091: setupSite("site/outputs.xml");
092: WebConversation conversation = new WebConversation();
093: WebRequest request = new GetMethodWebRequest(
094: "http://localhost:8181/outputs/bean/prefix/outjection");
095: WebResponse response = null;
096:
097: response = conversation.getResponse(request);
098: assertEquals(
099: "the string,the stringbuffer,23154,893749,u,false,true,false,false,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
100: response.getText());
101: }
102:
103: public void testOutputsBeanNormalClear() throws Exception {
104: setupSite("site/outputs.xml");
105: WebConversation conversation = new WebConversation();
106: WebRequest request = new GetMethodWebRequest(
107: "http://localhost:8181/outputs/bean/normal/clear");
108: WebResponse response = null;
109:
110: response = conversation.getResponse(request);
111: assertEquals(
112: "ok,null,null,null,null,false,null,null,false,null,null,null,null,null,null,null,null,null",
113: response.getText());
114: }
115:
116: public void testOutputsBeanNormalNamedClear() throws Exception {
117: setupSite("site/outputs.xml");
118: WebConversation conversation = new WebConversation();
119: WebRequest request = new GetMethodWebRequest(
120: "http://localhost:8181/outputs/bean/normal/named/clear");
121: WebResponse response = null;
122:
123: response = conversation.getResponse(request);
124: assertEquals(
125: "ok,null,null,null,null,false,null,null,false,null,null,null,null,null,null,null,null,null",
126: response.getText());
127: }
128:
129: public void testOutputsBeanPrefixClear() throws Exception {
130: setupSite("site/outputs.xml");
131: WebConversation conversation = new WebConversation();
132: WebRequest request = new GetMethodWebRequest(
133: "http://localhost:8181/outputs/bean/prefix/clear");
134: WebResponse response = null;
135:
136: response = conversation.getResponse(request);
137: assertEquals(
138: "ok,null,null,null,null,false,null,null,false,null,null,null,null,null,null,null,null,null",
139: response.getText());
140: }
141:
142: public void testOutputsBeanPrefixNamedClear() throws Exception {
143: setupSite("site/outputs.xml");
144: WebConversation conversation = new WebConversation();
145: WebRequest request = new GetMethodWebRequest(
146: "http://localhost:8181/outputs/bean/prefix/named/clear");
147: WebResponse response = null;
148:
149: response = conversation.getResponse(request);
150: assertEquals(
151: "ok,null,null,null,null,false,null,null,false,null,null,null,null,null,null,null,null,null",
152: response.getText());
153: }
154:
155: public void testOutputsTyped() throws Exception {
156: setupSite("site/outputs.xml");
157: WebConversation conversation = new WebConversation();
158: WebRequest request = new GetMethodWebRequest(
159: "http://localhost:8181/outputs/typed");
160: WebResponse response = conversation.getResponse(request);
161: assertEquals("astring" + "," + "astring2" + "," + "astring3"
162: + "," + "astring4" + "U" + "," + "V" + "bko" + ","
163: + "kkl" + Integer.MAX_VALUE + "," + 78327
164: + Long.MAX_VALUE + "," + 83764987398L + 34798.43 + ","
165: + 893749.56 + 43.18f + "," + 87.34f, response.getText());
166: }
167:
168: public void testOutputsGenerated() throws Exception {
169: setupSite("site/outputs.xml");
170: WebConversation conversation = new WebConversation();
171: WebRequest request = new GetMethodWebRequest(
172: "http://localhost:8181/outputs/generated");
173: WebResponse response = conversation.getResponse(request);
174: assertEquals("Welcome Geert Bevin\n", response.getText());
175: }
176:
177: public void testOutputsInvalid() throws Exception {
178: setupSite("site/outputs.xml");
179: WebConversation conversation = new WebConversation();
180: WebRequest request = new GetMethodWebRequest(
181: "http://localhost:8181/outputs/invalid");
182: try {
183: WebResponse response = conversation.getResponse(request);
184: fail();
185: assertNotNull(response);
186: } catch (HttpInternalErrorException e) {
187: assertTrue(getLogSink().getInternalException() instanceof OutputUnknownException);
188:
189: OutputUnknownException e2 = (OutputUnknownException) getLogSink()
190: .getInternalException();
191: assertEquals("output1", e2.getOutputName());
192: assertEquals(e2.getDeclarationName(),
193: "element/outputs/invalid.xml");
194: }
195: }
196:
197: public void testOutputsDefaults() throws Exception {
198: setupSite("site/outputs.xml");
199: WebConversation conversation = new WebConversation();
200: WebRequest request = new GetMethodWebRequest(
201: "http://localhost:8181/outputs/defaults");
202: WebResponse response = conversation.getResponse(request);
203: assertEquals("the first value" + "2rdb-2rda-2rdc-2rdd"
204: + "the element config value", response.getText());
205: }
206: }
|