0001: /*
0002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
0003: * Distributed under the terms of either:
0004: * - the common development and distribution license (CDDL), v1.0; or
0005: * - the GNU Lesser General Public License, v2.1 or later
0006: * $Id: TestEngineSubmissions.java 3693 2007-03-14 10:55:56Z gbevin $
0007: */
0008: package com.uwyn.rife.engine;
0009:
0010: import com.meterware.httpunit.*;
0011: import com.uwyn.rife.tools.*;
0012:
0013: import com.meterware.httpunit.Base64;
0014: import com.uwyn.rife.TestCaseServerside;
0015: import com.uwyn.rife.config.Config;
0016: import com.uwyn.rife.config.RifeConfig;
0017: import com.uwyn.rife.engine.exceptions.MultipartFileTooBigException;
0018: import com.uwyn.rife.engine.exceptions.ParameterUnknownException;
0019: import com.uwyn.rife.engine.exceptions.SubmissionUnknownException;
0020: import com.uwyn.rife.engine.testelements.submission.BeanImpl.SerializableParam;
0021: import com.uwyn.rife.resources.ResourceFinderClasspath;
0022: import com.uwyn.rife.template.TemplateFactory;
0023: import com.uwyn.rife.tools.exceptions.FileUtilsErrorException;
0024: import java.io.ByteArrayInputStream;
0025: import java.io.File;
0026: import java.io.InputStream;
0027: import java.io.StringBufferInputStream;
0028: import java.util.HashMap;
0029: import java.util.logging.Formatter;
0030: import java.util.logging.Handler;
0031: import java.util.logging.Logger;
0032:
0033: public class TestEngineSubmissions extends TestCaseServerside {
0034: public TestEngineSubmissions(int siteType, String name) {
0035: super (siteType, name);
0036: }
0037:
0038: public void testContextIndependence() throws Exception {
0039: WebConversation conversation = null;
0040: WebRequest request = null;
0041: WebResponse response = null;
0042:
0043: setupSite("site/submissions.xml");
0044: conversation = new WebConversation();
0045: request = new PostMethodWebRequest(
0046: "http://localhost:8181/submissions/valid");
0047: request.setParameter(ReservedParameters.SUBMISSION, "login");
0048: request.setParameter("login", "gbevin");
0049: request.setParameter("password", "mypassword");
0050: request.setParameter("array", new String[] { "1", "3", "4" });
0051: response = conversation.getResponse(request);
0052:
0053: assertEquals("gbevin,mypassword,1|3|4", response.getText());
0054:
0055: setupSite("/PREFIX", "site/submissions.xml");
0056: conversation = new WebConversation();
0057: request = new PostMethodWebRequest(
0058: "http://localhost:8181/PREFIX/submissions/valid");
0059: request.setParameter(ReservedParameters.SUBMISSION, "login");
0060: request.setParameter("login", "gbevin");
0061: request.setParameter("password", "mypassword");
0062: request.setParameter("array", new String[] { "1", "3", "4" });
0063: response = conversation.getResponse(request);
0064:
0065: assertEquals("gbevin,mypassword,1|3|4", response.getText());
0066: }
0067:
0068: public void testParameters() throws Exception {
0069: setupSite("site/submissions.xml");
0070:
0071: WebConversation conversation = new WebConversation();
0072: WebRequest request = new PostMethodWebRequest(
0073: "http://localhost:8181/submissions/valid");
0074: request.setParameter(ReservedParameters.SUBMISSION, "login");
0075: request.setParameter("login", "gbevin");
0076: request.setParameter("password", "mypassword");
0077: request.setParameter("array", new String[] { "1", "3", "4" });
0078: WebResponse response = conversation.getResponse(request);
0079:
0080: assertEquals("gbevin,mypassword,1|3|4", response.getText());
0081: }
0082:
0083: public void testParametersRegexp() throws Exception {
0084: setupSite("site/submissions.xml");
0085:
0086: WebConversation conversation = new WebConversation();
0087: WebRequest request = new PostMethodWebRequest(
0088: "http://localhost:8181/params/regexp");
0089: WebResponse response = null;
0090: request.setParameter(ReservedParameters.SUBMISSION, "login");
0091: request.setParameter("login", "gbevin");
0092: request.setParameter("password", "mypassword");
0093: request.setParameter("array", new String[] { "1", "3", "4" });
0094: request.setParameter("loffin", "gbevin2");
0095: request.setParameter("paword", "mypasswordtoo");
0096: request.setParameter("aray", new String[] { "9", "4", "2" });
0097:
0098: response = conversation.getResponse(request);
0099:
0100: assertEquals(
0101: "9|4|2,1|3|4,gbevin2,gbevin,mypassword,mypasswordtoo,mypassword,mypasswordtoo,",
0102: response.getText());
0103: }
0104:
0105: public void testParametersTyped() throws Exception {
0106: setupSite("site/submissions.xml");
0107:
0108: WebConversation conversation = new WebConversation();
0109: WebRequest request = new PostMethodWebRequest(
0110: "http://localhost:8181/submissions/typed");
0111: WebResponse response = null;
0112: request.setParameter(ReservedParameters.SUBMISSION, "typed");
0113: request.setParameter("paramstring1", "astring");
0114: request.setParameter("paramint1", "" + Integer.MAX_VALUE);
0115: request.setParameter("paramlong1", "" + Long.MAX_VALUE);
0116: request.setParameter("paramdouble1", "9873434.4334");
0117: request.setParameter("paramfloat1", "23.12");
0118: response = conversation.getResponse(request);
0119: assertEquals("paramstring1:astring" + "paramstring2:null"
0120: + "paramstring2default:stringdefault" + "paramint1:"
0121: + Integer.MAX_VALUE + "paramint2:0"
0122: + "paramint2default:123" + "paramlong1:"
0123: + Long.MAX_VALUE + "paramlong2:0"
0124: + "paramlong2default:983749876"
0125: + "paramdouble1:9873434.4334" + "paramdouble2:0.0"
0126: + "paramdouble2default:34778.34" + "paramfloat1:23.12"
0127: + "paramfloat2:0.0" + "paramfloat2default:324.34",
0128: response.getText());
0129: }
0130:
0131: public void testParametersTypedInjection() throws Exception {
0132: setupSite("site/submissions.xml");
0133:
0134: WebConversation conversation = new WebConversation();
0135: WebRequest request = new PostMethodWebRequest(
0136: "http://localhost:8181/submissions/typed_injection");
0137: WebResponse response = null;
0138: request.setParameter(ReservedParameters.SUBMISSION, "typed");
0139: request.setParameter("paramstring1", "astring");
0140: request.setParameter("paramint1", "" + Integer.MAX_VALUE);
0141: request.setParameter("paramlong1", "" + Long.MAX_VALUE);
0142: request.setParameter("paramdouble1", "9873434.4334");
0143: request.setParameter("paramfloat1", "23.12");
0144: request.setParameter("parammultiple", new String[] { "one",
0145: "two", "three" });
0146: response = conversation.getResponse(request);
0147: assertEquals("paramstring1:astring" + "paramstring2:null"
0148: + "paramint1:" + Integer.MAX_VALUE + "paramint2:378"
0149: + "paramlong1:" + Long.MAX_VALUE + "paramlong2:0"
0150: + "paramdouble1:9873434.4334" + "paramdouble2:0.0"
0151: + "paramfloat1:23.12" + "paramfloat2:0.0"
0152: + "parammultiple:one-two-three", response.getText());
0153: }
0154:
0155: public void testParametersTypedMultiple() throws Exception {
0156: setupSite("site/submissions.xml");
0157:
0158: WebConversation conversation = new WebConversation();
0159: WebRequest request = new PostMethodWebRequest(
0160: "http://localhost:8181/submissions/typed/multiple");
0161: WebResponse response = null;
0162: request.setParameter(ReservedParameters.SUBMISSION,
0163: "typed_multiple");
0164: request.setParameter("paramstring", new String[] { "one",
0165: "two", "three" });
0166: request.setParameter("paramint", new String[] {
0167: String.valueOf(89), "ok", String.valueOf(12),
0168: String.valueOf(2), "cracotte", String.valueOf(56) });
0169: request.setParameter("paramlong", new String[] {
0170: String.valueOf(4342), String.valueOf(54543), "okko",
0171: String.valueOf(3434), "kili", String.valueOf(44342) });
0172: request.setParameter("paramdouble", new String[] { "rokko",
0173: String.valueOf(9873434.4334d),
0174: String.valueOf(23984.945d),
0175: String.valueOf(348900.6534d),
0176: String.valueOf(153932.343d), "kirri" });
0177: request.setParameter("paramfloat", new String[] {
0178: String.valueOf(432.34f), "ohno",
0179: String.valueOf(9234.65f), String.valueOf(2345.98f),
0180: "nokki", String.valueOf(633.9f) });
0181: response = conversation.getResponse(request);
0182: assertEquals(
0183: "paramstring:one,two,three"
0184: + "paramint:89,12,2,56"
0185: + "paramlong:4342,54543,3434,44342"
0186: + "paramdouble:9873434.4334,23984.945,348900.6534,153932.343"
0187: + "paramfloat:432.34,9234.65,2345.98,633.9",
0188: response.getText());
0189: }
0190:
0191: public void testParametersMissingSubmission() throws Exception {
0192: setupSite("site/submissions.xml");
0193:
0194: WebConversation conversation = new WebConversation();
0195: WebRequest request = new GetMethodWebRequest(
0196: "http://localhost:8181/submissions/valid");
0197: WebResponse response = null;
0198: request.setParameter("login", "gbevin");
0199: request.setParameter("password", "mypassword");
0200: request.setParameter("array", new String[] { "1", "3", "4" });
0201: response = conversation.getResponse(request);
0202: assertEquals("null,null,null", response.getText());
0203: }
0204:
0205: public void testParametersUnknownSubmission() throws Exception {
0206: setupSite("site/submissions.xml");
0207:
0208: WebConversation conversation = new WebConversation();
0209: WebRequest request = new PostMethodWebRequest(
0210: "http://localhost:8181/submissions/unknown");
0211:
0212: try {
0213: conversation.getResponse(request);
0214: fail();
0215: } catch (HttpInternalErrorException e) {
0216: assertTrue(getLogSink().getInternalException() instanceof SubmissionUnknownException);
0217:
0218: SubmissionUnknownException e2 = (SubmissionUnknownException) getLogSink()
0219: .getInternalException();
0220: assertEquals("unknown", e2.getSubmissionName());
0221: assertEquals(e2.getDeclarationName(),
0222: "element/submission/unknown.xml");
0223: }
0224: }
0225:
0226: public void testParameterDoesntExist() throws Exception {
0227: setupSite("site/submissions.xml");
0228:
0229: WebConversation conversation = new WebConversation();
0230: WebRequest request = new PostMethodWebRequest(
0231: "http://localhost:8181/submissions/doesntexist");
0232: request.setParameter(ReservedParameters.SUBMISSION, "login");
0233: request.setParameter("login", "gbevin");
0234: request.setParameter("password", "mypassword");
0235: request.setParameter("array", new String[] { "1", "3", "4" });
0236:
0237: try {
0238: conversation.getResponse(request);
0239: fail();
0240: } catch (HttpInternalErrorException e) {
0241: assertTrue(getLogSink().getInternalException() instanceof ParameterUnknownException);
0242:
0243: ParameterUnknownException e2 = (ParameterUnknownException) getLogSink()
0244: .getInternalException();
0245: assertEquals("login", e2.getParameterName());
0246: assertEquals(e2.getDeclarationName(),
0247: "element/submission/doesntexist.xml");
0248: }
0249: }
0250:
0251: public void testParametersUnknown() throws Exception {
0252: setupSite("site/submissions.xml");
0253:
0254: WebConversation conversation = new WebConversation();
0255: WebRequest request = new GetMethodWebRequest(
0256: "http://localhost:8181/submissions/params_unknown");
0257: request.setParameter("login", "gbevin");
0258: request.setParameter("password", "mypassword");
0259: try {
0260: conversation.getResponse(request);
0261: fail();
0262: } catch (HttpInternalErrorException e) {
0263: assertTrue(getLogSink().getInternalException() instanceof ParameterUnknownException);
0264:
0265: ParameterUnknownException e2 = (ParameterUnknownException) getLogSink()
0266: .getInternalException();
0267: assertEquals("login_unknown", e2.getParameterName());
0268: assertEquals(e2.getDeclarationName(),
0269: "element/submission/params_unknown.xml");
0270: }
0271: }
0272:
0273: public void testSubmissionMultiple() throws Exception {
0274: setupSite("site/submissions.xml");
0275:
0276: WebConversation conversation = new WebConversation();
0277: WebRequest request = null;
0278: WebResponse response = null;
0279: WebForm form = null;
0280:
0281: request = new GetMethodWebRequest(
0282: "http://localhost:8181/submissions/multiple");
0283: response = conversation.getResponse(request);
0284: form = response.getFormWithName("login");
0285: form.setParameter("login", "gbevin");
0286: form.setParameter("password", "mypassword");
0287: form.setParameter("language", form.getOptionValues("language"));
0288: response = form.submit();
0289: assertEquals("gbevin,mypassword,fr|nl", response.getText());
0290:
0291: request = new GetMethodWebRequest(
0292: "http://localhost:8181/submissions/multiple");
0293: response = conversation.getResponse(request);
0294: form = response.getFormWithName("register");
0295: form.setParameter("login", "gbevin");
0296: form.setParameter("password", "mypassword");
0297: form.setParameter("firstname", "Geert");
0298: form.setParameter("lastname", "Bevin");
0299: response = form.submit();
0300: assertEquals("gbevin,mypassword,Geert,Bevin", response
0301: .getText());
0302: }
0303:
0304: public void testSubmissionSendGet() throws Exception {
0305: setupSite("site/submissions.xml");
0306:
0307: WebConversation conversation = new WebConversation();
0308: WebRequest request = new GetMethodWebRequest(
0309: "http://localhost:8181/submissions/sendget");
0310: WebResponse response = conversation.getResponse(request);
0311: WebLink submission_link = response
0312: .getLinkWith("submissionlink");
0313: submission_link.click();
0314: response = conversation.getCurrentPage();
0315:
0316: assertEquals("gbevin,stillmypassword", response.getText());
0317: }
0318:
0319: public void testSubmissionSendPost() throws Exception {
0320: setupSite("site/submissions.xml");
0321:
0322: WebConversation conversation = new WebConversation();
0323: WebRequest request = new GetMethodWebRequest(
0324: "http://localhost:8181/submissions/sendpost");
0325: WebResponse response = conversation.getResponse(request);
0326: WebForm submission_form = response.getForms()[0];
0327: submission_form.setParameter("login", "gbevin2");
0328: submission_form.setParameter("password", "oncemoremypassword");
0329: response = submission_form.submit();
0330:
0331: assertEquals("gbevin2,oncemoremypassword", response.getText());
0332: }
0333:
0334: public void testSubmissionSendPostHidden() throws Exception {
0335: setupSite("site/submissions.xml");
0336:
0337: WebConversation conversation = new WebConversation();
0338: WebRequest request = new GetMethodWebRequest(
0339: "http://localhost:8181/submissions/sendposthidden");
0340: WebResponse response = conversation.getResponse(request);
0341: WebForm submission_form = response.getForms()[0];
0342: submission_form.setParameter("login", "gbevin2");
0343: submission_form.setParameter("password", "oncemoremypassword");
0344: response = submission_form.submit();
0345:
0346: assertEquals("gbevin2,oncemoremypassword", response.getText());
0347: }
0348:
0349: public void testSubmissionSendGetHidden() throws Exception {
0350: setupSite("site/submissions.xml");
0351:
0352: WebConversation conversation = new WebConversation();
0353: WebRequest request = new GetMethodWebRequest(
0354: "http://localhost:8181/submissions/sendgethidden");
0355: WebResponse response = conversation.getResponse(request);
0356: WebForm submission_form = response.getForms()[0];
0357: submission_form.setParameter("login", "gbevin2");
0358: submission_form.setParameter("password", "oncemoremypassword");
0359: response = submission_form.submit();
0360:
0361: assertEquals("gbevin2,oncemoremypassword", response.getText());
0362: }
0363:
0364: public void testSubmissionGeneratedUrl() throws Exception {
0365: setupSite("site/submissions.xml");
0366:
0367: WebConversation conversation = new WebConversation();
0368: WebRequest request = null;
0369: WebResponse response = null;
0370: WebLink submission_link = null;
0371: WebForm submission_form = null;
0372:
0373: request = new GetMethodWebRequest(
0374: "http://localhost:8181/submissions/generatedurl");
0375: response = conversation.getResponse(request);
0376: submission_link = response.getLinkWith("submission1");
0377: submission_link.click();
0378: response = conversation.getCurrentPage();
0379:
0380: assertEquals("thevalue", response.getText());
0381:
0382: request = new GetMethodWebRequest(
0383: "http://localhost:8181/submissions/generatedurl");
0384: response = conversation.getResponse(request);
0385: submission_form = response.getForms()[0];
0386: submission_form.setParameter("login", "gbevin2");
0387: response = submission_form.submit();
0388: submission_form = response.getForms()[0];
0389: submission_form.setParameter("password", "oncemoremypassword");
0390: response = submission_form.submit();
0391:
0392: assertEquals("gbevin2,oncemoremypassword", response.getText());
0393:
0394: request = new GetMethodWebRequest(
0395: "http://localhost:8181/submissions/generatedurl");
0396: response = conversation.getResponse(request);
0397: submission_form = response.getForms()[1];
0398: response = submission_form.submit();
0399: submission_form = response.getForms()[1];
0400: submission_form.setParameter("login", "me");
0401: response = submission_form.submit();
0402:
0403: assertEquals("me,it is", response.getText());
0404:
0405: request = new GetMethodWebRequest(
0406: "http://localhost:8181/submissions/generatedurl");
0407: response = conversation.getResponse(request);
0408: submission_link = response.getLinkWith("submission4");
0409: submission_link.click();
0410: response = conversation.getCurrentPage();
0411:
0412: assertEquals("submission4", response.getText());
0413: }
0414:
0415: public void testSubmissionGeneratedUrlPathinfo() throws Exception {
0416: setupSite("site/submissions.xml");
0417:
0418: WebConversation conversation = new WebConversation();
0419: WebRequest request = null;
0420: WebResponse response = null;
0421: WebLink submission_link = null;
0422: WebForm submission_form = null;
0423:
0424: request = new GetMethodWebRequest(
0425: "http://localhost:8181/submissions/generatedurlpathinfo");
0426: response = conversation.getResponse(request);
0427: submission_link = response.getLinkWith("submission1");
0428: submission_link.click();
0429: response = conversation.getCurrentPage();
0430:
0431: assertEquals("/" + "thevalue", response.getText());
0432:
0433: request = new GetMethodWebRequest(
0434: "http://localhost:8181/submissions/generatedurlpathinfo");
0435: response = conversation.getResponse(request);
0436: submission_form = response.getForms()[0];
0437: submission_form.setParameter("login", "gbevin2");
0438: response = submission_form.submit();
0439: submission_form = response.getForms()[0];
0440: submission_form.setParameter("password", "oncemoremypassword");
0441: response = submission_form.submit();
0442:
0443: assertEquals("/" + "gbevin2,oncemoremypassword", response
0444: .getText());
0445:
0446: request = new GetMethodWebRequest(
0447: "http://localhost:8181/submissions/generatedurlpathinfo");
0448: response = conversation.getResponse(request);
0449: submission_form = response.getForms()[1];
0450: response = submission_form.submit();
0451: submission_form = response.getForms()[1];
0452: submission_form.setParameter("login", "me");
0453: response = submission_form.submit();
0454:
0455: assertEquals("/" + "me,it is", response.getText());
0456:
0457: request = new GetMethodWebRequest(
0458: "http://localhost:8181/submissions/generatedurlpathinfo");
0459: response = conversation.getResponse(request);
0460: submission_link = response.getLinkWith("submission4");
0461: submission_link.click();
0462: response = conversation.getCurrentPage();
0463:
0464: assertEquals("/" + "submission4", response.getText());
0465:
0466: request = new GetMethodWebRequest(
0467: "http://localhost:8181/submissions/generatedurlpathinfo/thepathinfo");
0468: response = conversation.getResponse(request);
0469: submission_link = response.getLinkWith("submission1");
0470: submission_link.click();
0471: response = conversation.getCurrentPage();
0472:
0473: assertEquals("/thepathinfo" + "thevalue", response.getText());
0474:
0475: request = new GetMethodWebRequest(
0476: "http://localhost:8181/submissions/generatedurlpathinfo/thepathinfo2");
0477: response = conversation.getResponse(request);
0478: submission_form = response.getForms()[0];
0479: submission_form.setParameter("login", "gbevin2");
0480: response = submission_form.submit();
0481: submission_form = response.getForms()[0];
0482: submission_form.setParameter("password", "oncemoremypassword");
0483: response = submission_form.submit();
0484:
0485: assertEquals("/thepathinfo2" + "gbevin2,oncemoremypassword",
0486: response.getText());
0487:
0488: request = new GetMethodWebRequest(
0489: "http://localhost:8181/submissions/generatedurlpathinfo/thepathinfo3");
0490: response = conversation.getResponse(request);
0491: submission_form = response.getForms()[1];
0492: response = submission_form.submit();
0493: submission_form = response.getForms()[1];
0494: submission_form.setParameter("login", "me");
0495: response = submission_form.submit();
0496:
0497: assertEquals("/thepathinfo3" + "me,it is", response.getText());
0498:
0499: request = new GetMethodWebRequest(
0500: "http://localhost:8181/submissions/generatedurlpathinfo/thepathinfo4");
0501: response = conversation.getResponse(request);
0502: submission_link = response.getLinkWith("submission4");
0503: submission_link.click();
0504: response = conversation.getCurrentPage();
0505:
0506: assertEquals("/thepathinfo4" + "submission4", response
0507: .getText());
0508: }
0509:
0510: public void testSubmissionGeneratedUrlOverflow() throws Exception {
0511: setupSite("site/submissions.xml");
0512:
0513: // setup swallowing log formatters
0514: HashMap<Handler, Formatter> formatters = new HashMap<Handler, Formatter>();
0515: SwallowingLogFormatter formatter = new SwallowingLogFormatter();
0516: Logger logger = Logger.getLogger("");
0517: for (Handler handler : logger.getHandlers()) {
0518: formatters.put(handler, handler.getFormatter());
0519: handler.setFormatter(formatter);
0520: }
0521:
0522: try {
0523: WebConversation conversation = new WebConversation();
0524: WebRequest request = null;
0525: WebResponse response = null;
0526: WebLink submission_link = null;
0527:
0528: request = new GetMethodWebRequest(
0529: "http://localhost:8181/submissions/generatedurloverflow");
0530: response = conversation.getResponse(request);
0531: submission_link = response.getLinkWith("submission1");
0532: submission_link.click();
0533: response = conversation.getCurrentPage();
0534:
0535: assertEquals(StringUtils.repeat(
0536: "abcdefghijklmnopqrstuvwxyz", 74)
0537: + "01234567890", response.getText());
0538:
0539: assertEquals(1, formatter.getRecords().size());
0540: assertEquals(
0541: "The submission 'submission1' of element '.GENERATEDURLOVERFLOW' generated an URL whose length of 2049 exceeds the maximum length of 2048 bytes, using session state store instead. The generated URL was '/submissions/generatedurloverflow?submission=submission1¶meter="
0542: + StringUtils.repeat(
0543: "abcdefghijklmnopqrstuvwxyz", 74)
0544: + "01234567890"
0545: + "&submissioncontext=LkdFTkVSQVRFRFVSTE9WRVJGTE9X'.",
0546: formatter.getRecords().get(0).getMessage());
0547: } finally {
0548: // restore the previous formatters
0549: for (Handler handler : logger.getHandlers()) {
0550: handler.setFormatter(formatters.get(handler));
0551: }
0552: }
0553: }
0554:
0555: public void testSubmissionInputsPreserved() throws Exception {
0556: setupSite("site/submissions.xml");
0557:
0558: WebConversation conversation = new WebConversation();
0559: WebRequest request = null;
0560: WebResponse response = null;
0561: WebLink submission_link = null;
0562: WebForm submission_form = null;
0563:
0564: request = new GetMethodWebRequest(
0565: "http://localhost:8181/submissions/inputspreserved");
0566: request.setParameter("input1", "submission1input1value");
0567: request.setParameter("input4", "submission1input4value");
0568: response = conversation.getResponse(request);
0569: submission_link = response.getLinkWith("submission1");
0570: String url = submission_link.getURLString();
0571: request = new GetMethodWebRequest("http://localhost:8181" + url);
0572: response = conversation.getResponse(request);
0573: assertEquals("thevalue" + "submission1input1value" + "null"
0574: + "input3default", response.getText());
0575: request = new GetMethodWebRequest("http://localhost:8181" + url
0576: + "&input1=submission1input1overriddenvalue");
0577: response = conversation.getResponse(request);
0578: assertEquals("thevalue" + "submission1input1value" + "null"
0579: + "input3default", response.getText());
0580:
0581: request = new GetMethodWebRequest(
0582: "http://localhost:8181/submissions/inputspreserved");
0583: request.setParameter("input1", "submission2input1value");
0584: request.setParameter("input4", "submission2input4value");
0585: response = conversation.getResponse(request);
0586: submission_form = response.getForms()[0];
0587: submission_form.setParameter("login", "gbevin2");
0588: response = submission_form.submit();
0589: submission_form = response.getForms()[0];
0590: submission_form.setParameter("password", "oncemoremypassword");
0591: response = submission_form.submit();
0592: assertEquals("gbevin2,oncemoremypassword"
0593: + "submission2input1value" + "null" + "input3default",
0594: response.getText());
0595:
0596: request = new GetMethodWebRequest(
0597: "http://localhost:8181/submissions/inputspreserved");
0598: request.setParameter("input1", "submission3input1value");
0599: request.setParameter("input4", "submission3input4value");
0600: response = conversation.getResponse(request);
0601: submission_form = response.getForms()[1];
0602: response = submission_form.submit();
0603: submission_form = response.getForms()[1];
0604: submission_form.setParameter("login", "me");
0605: response = submission_form.submit();
0606: assertEquals("me,it is" + "submission3input1value" + "null"
0607: + "input3default", response.getText());
0608:
0609: request = new GetMethodWebRequest(
0610: "http://localhost:8181/submissions/inputspreserved");
0611: request.setParameter("input1", "submission4input1value");
0612: request.setParameter("input4", "submission4input4value");
0613: response = conversation.getResponse(request);
0614: submission_link = response.getLinkWith("submission4");
0615: url = submission_link.getURLString();
0616: request = new GetMethodWebRequest("http://localhost:8181" + url);
0617: response = conversation.getResponse(request);
0618: assertEquals("submission4" + "submission4input1value" + "null"
0619: + "input3default", response.getText());
0620: request = new GetMethodWebRequest("http://localhost:8181" + url
0621: + "&input1=submission1input1overriddenvalue");
0622: response = conversation.getResponse(request);
0623: assertEquals("submission4" + "submission4input1value" + "null"
0624: + "input3default", response.getText());
0625: }
0626:
0627: public void testSubmissionBean() throws Exception {
0628: setupSite("site/submissions.xml");
0629:
0630: WebConversation conversation = new WebConversation();
0631: WebRequest request = new GetMethodWebRequest(
0632: "http://localhost:8181/submissions/bean/normal");
0633: WebResponse response = null;
0634: WebForm form = null;
0635: response = conversation.getResponse(request);
0636:
0637: form = response.getFormWithName("submissionform");
0638: request = form.getRequest();
0639: request.setParameter("enum", "WEDNESDAY");
0640: request.setParameter("string", "the string");
0641: request.setParameter("boolean", "y");
0642: request.setParameter("string", "the string");
0643: request.setParameter("stringbuffer", "the stringbuffer");
0644: request.setParameter("int", "23154");
0645: request.setParameter("integer", "893749");
0646: request.setParameter("char", "u");
0647: request.setParameter("character", "R");
0648: request.setParameter("boolean", "y");
0649: request.setParameter("booleanObject", "no");
0650: request.setParameter("byte", "120");
0651: request.setParameter("byteObject", "21");
0652: request.setParameter("double", "34878.34");
0653: request.setParameter("doubleObject", "25435.98");
0654: request.setParameter("float", "3434.76");
0655: request.setParameter("floatObject", "6534.8");
0656: request.setParameter("long", "34347897");
0657: request.setParameter("longObject", "2335454");
0658: request.setParameter("short", "32");
0659: request.setParameter("shortObject", "12");
0660: request.setParameter("date", "2005-08-20 09:44");
0661: request.setParameter("dateFormatted",
0662: "Sat 20 Aug 2005 09:44:00");
0663: request.setParameter("datesFormatted",
0664: new String[] { "Sun 21 Aug 2005 11:06:14",
0665: "Mon 17 Jul 2006 16:05:31" });
0666: request.setParameter("serializableParam",
0667: SerializationUtils
0668: .serializeToString(new SerializableParam(13,
0669: "Thirteen")));
0670: request.setParameter("serializableParams", new String[] {
0671: SerializationUtils
0672: .serializeToString(new SerializableParam(9,
0673: "Nine")),
0674: SerializationUtils
0675: .serializeToString(new SerializableParam(91,
0676: "NinetyOne")) });
0677: request
0678: .selectFile("stringFile", "somedesign.html",
0679: new StringBufferInputStream(
0680: "this is some html content"),
0681: "text/html");
0682: byte[] image_bytes = ResourceFinderClasspath.getInstance()
0683: .useStream("uwyn.png", new InputStreamUser() {
0684: public Object useInputStream(InputStream stream)
0685: throws InnerClassException {
0686: try {
0687: return FileUtils.readBytes(stream);
0688: } catch (FileUtilsErrorException e) {
0689: throwException(e);
0690: }
0691:
0692: return null;
0693: }
0694: });
0695: request.selectFile("bytesFile", "someimage.png",
0696: new ByteArrayInputStream(image_bytes), "image/png");
0697: request.selectFile("streamFile", "somefile.png",
0698: new ByteArrayInputStream(image_bytes), null);
0699:
0700: response = conversation.getResponse(request);
0701:
0702: assertEquals(
0703: "WEDNESDAY,the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12,this is some html content,true,someimage.png,true,Sat 20 Aug 2005 09:44:00,Sun 21 Aug 2005 11:06:14,Mon 17 Jul 2006 16:05:31,13:Thirteen,9:Nine,91:NinetyOne",
0704: response.getText());
0705:
0706: request = new GetMethodWebRequest(
0707: "http://localhost:8181/submissions/bean/normal");
0708: response = conversation.getResponse(request);
0709:
0710: form = response.getFormWithName("submissionform");
0711: request = form.getRequest();
0712: request.setParameter("enum", "invalid");
0713: request.setParameter("string", "the string");
0714: request.setParameter("boolean", "y");
0715: request.setParameter("string", "the string");
0716: request.setParameter("stringbuffer", "the stringbuffer");
0717: request.setParameter("int", "23fd33");
0718: request.setParameter("char", "u");
0719: request.setParameter("character", "R");
0720: request.setParameter("boolean", "y");
0721: request.setParameter("booleanObject", "no");
0722: request.setParameter("byte", "120");
0723: request.setParameter("byteObject", "21");
0724: request.setParameter("double", "zef.34");
0725: request.setParameter("doubleObject", "25435.98");
0726: request.setParameter("float", "3434.76");
0727: request.setParameter("floatObject", "6534.8");
0728: request.setParameter("long", "34347897");
0729: request.setParameter("longObject", "233f5454");
0730: request.setParameter("short", "32");
0731: request.setParameter("shortObject", "");
0732: request.setParameter("datesFormatted",
0733: new String[] { "Sun 21 Aug 2005 11:06:14",
0734: "Mon 18 Jul 2006 16:05:31" });
0735: request.setParameter("serializableParam", "invalid");
0736: request.setParameter("serializableParams", new String[] {
0737: "invalid",
0738: SerializationUtils
0739: .serializeToString(new SerializableParam(91,
0740: "NinetyOne")) });
0741:
0742: response = conversation.getResponse(request);
0743:
0744: assertEquals(
0745: "INVALID : datesFormatted\nNOTNUMERIC : double\nINVALID : enum\nNOTNUMERIC : int\nNOTNUMERIC : longObject\nINVALID : serializableParam\nINVALID : serializableParams\nnull,the string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null,null,null,null,null,null,Sun 21 Aug 2005 11:06:14,null,null,null,91:NinetyOne",
0746: response.getText());
0747: }
0748:
0749: public void testSubmissionBeanPrefix() throws Exception {
0750: setupSite("site/submissions.xml");
0751:
0752: WebConversation conversation = new WebConversation();
0753: WebRequest request = new GetMethodWebRequest(
0754: "http://localhost:8181/submissions/bean/prefix");
0755: WebResponse response = null;
0756: WebForm form = null;
0757: response = conversation.getResponse(request);
0758:
0759: form = response.getFormWithName("submissionform");
0760: request = form.getRequest();
0761: request.setParameter(ReservedParameters.SUBMISSION, "bean");
0762: request.setParameter("prefix_enum", "MONDAY");
0763: request.setParameter("prefix_string", "the string");
0764: request.setParameter("prefix_boolean", "y");
0765: request.setParameter("prefix_string", "the string");
0766: request.setParameter("prefix_stringbuffer", "the stringbuffer");
0767: request.setParameter("prefix_int", "23154");
0768: request.setParameter("prefix_integer", "893749");
0769: request.setParameter("prefix_char", "u");
0770: request.setParameter("prefix_character", "R");
0771: request.setParameter("prefix_boolean", "y");
0772: request.setParameter("prefix_booleanObject", "no");
0773: request.setParameter("prefix_byte", "120");
0774: request.setParameter("prefix_byteObject", "21");
0775: request.setParameter("prefix_double", "34878.34");
0776: request.setParameter("prefix_doubleObject", "25435.98");
0777: request.setParameter("prefix_float", "3434.76");
0778: request.setParameter("prefix_floatObject", "6534.8");
0779: request.setParameter("prefix_long", "34347897");
0780: request.setParameter("prefix_longObject", "2335454");
0781: request.setParameter("prefix_short", "32");
0782: request.setParameter("prefix_shortObject", "12");
0783: request.setParameter("prefix_date", "2005-08-20 09:44");
0784: request.setParameter("prefix_dateFormatted",
0785: "Sat 20 Aug 2005 09:44:00");
0786: request.setParameter("prefix_datesFormatted",
0787: new String[] { "Sun 21 Aug 2005 11:06:14",
0788: "Mon 17 Jul 2006 16:05:31" });
0789: request.setParameter("prefix_serializableParam",
0790: SerializationUtils
0791: .serializeToString(new SerializableParam(13,
0792: "Thirteen")));
0793: request.setParameter("prefix_serializableParams", new String[] {
0794: SerializationUtils
0795: .serializeToString(new SerializableParam(9,
0796: "Nine")),
0797: SerializationUtils
0798: .serializeToString(new SerializableParam(91,
0799: "NinetyOne")) });
0800: request
0801: .selectFile("prefix_stringFile", "somedesign.html",
0802: new StringBufferInputStream(
0803: "this is some html content"),
0804: "text/html");
0805: byte[] image_bytes = ResourceFinderClasspath.getInstance()
0806: .useStream("uwyn.png", new InputStreamUser() {
0807: public Object useInputStream(InputStream stream)
0808: throws InnerClassException {
0809: try {
0810: return FileUtils.readBytes(stream);
0811: } catch (FileUtilsErrorException e) {
0812: throwException(e);
0813: }
0814:
0815: return null;
0816: }
0817: });
0818: request.selectFile("prefix_bytesFile", "someimage.png",
0819: new ByteArrayInputStream(image_bytes), "image/png");
0820: request.selectFile("prefix_streamFile", "somefile.png",
0821: new ByteArrayInputStream(image_bytes), null);
0822:
0823: response = conversation.getResponse(request);
0824:
0825: assertEquals(
0826: "MONDAY,the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12,this is some html content,true,someimage.png,true,Sat 20 Aug 2005 09:44:00,Sun 21 Aug 2005 11:06:14,Mon 17 Jul 2006 16:05:31,13:Thirteen,9:Nine,91:NinetyOne",
0827: response.getText());
0828:
0829: request = new GetMethodWebRequest(
0830: "http://localhost:8181/submissions/bean/prefix");
0831: response = conversation.getResponse(request);
0832:
0833: form = response.getFormWithName("submissionform");
0834: request = form.getRequest();
0835: request.setParameter("prefix_enum", "invalid");
0836: request.setParameter("prefix_string", "the string");
0837: request.setParameter("prefix_boolean", "y");
0838: request.setParameter("prefix_string", "the string");
0839: request.setParameter("prefix_stringbuffer", "the stringbuffer");
0840: request.setParameter("prefix_int", "23fd33");
0841: request.setParameter("prefix_char", "u");
0842: request.setParameter("prefix_character", "R");
0843: request.setParameter("prefix_boolean", "y");
0844: request.setParameter("prefix_booleanObject", "no");
0845: request.setParameter("prefix_byte", "120");
0846: request.setParameter("prefix_byteObject", "21");
0847: request.setParameter("prefix_double", "zef.34");
0848: request.setParameter("prefix_doubleObject", "25435.98");
0849: request.setParameter("prefix_float", "3434.76");
0850: request.setParameter("prefix_floatObject", "6534.8");
0851: request.setParameter("prefix_long", "34347897");
0852: request.setParameter("prefix_longObject", "233f5454");
0853: request.setParameter("prefix_short", "32");
0854: request.setParameter("prefix_shortObject", "");
0855: request.setParameter("prefix_datesFormatted",
0856: new String[] { "Sun 21 Aug 2005 11:06:14",
0857: "Mon 18 Jul 2006 16:05:31" });
0858: request.setParameter("prefix_serializableParam", "invalid");
0859: request.setParameter("prefix_serializableParams", new String[] {
0860: "invalid",
0861: SerializationUtils
0862: .serializeToString(new SerializableParam(91,
0863: "NinetyOne")) });
0864: response = conversation.getResponse(request);
0865:
0866: assertEquals(
0867: "INVALID : datesFormatted\nNOTNUMERIC : double\nINVALID : enum\nNOTNUMERIC : int\nNOTNUMERIC : longObject\nINVALID : serializableParam\nINVALID : serializableParams\nnull,the string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null,null,null,null,null,null,Sun 21 Aug 2005 11:06:14,null,null,null,91:NinetyOne",
0868: response.getText());
0869: }
0870:
0871: public void testNamedSubmissionBean() throws Exception {
0872: setupSite("site/submissions.xml");
0873:
0874: WebConversation conversation = new WebConversation();
0875: WebRequest request = new PostMethodWebRequest(
0876: "http://localhost:8181/submissions/named_bean/normal");
0877: request.setParameter(ReservedParameters.SUBMISSION, "bean");
0878: request.setParameter("enum", "SATURDAY");
0879: request.setParameter("string", "the string");
0880: request.setParameter("boolean", "y");
0881: request.setParameter("string", "the string");
0882: request.setParameter("stringbuffer", "the stringbuffer");
0883: request.setParameter("int", "23154");
0884: request.setParameter("integer", "893749");
0885: request.setParameter("char", "u");
0886: request.setParameter("character", "R");
0887: request.setParameter("boolean", "y");
0888: request.setParameter("booleanObject", "no");
0889: request.setParameter("byte", "120");
0890: request.setParameter("byteObject", "21");
0891: request.setParameter("double", "34878.34");
0892: request.setParameter("doubleObject", "25435.98");
0893: request.setParameter("float", "3434.76");
0894: request.setParameter("floatObject", "6534.8");
0895: request.setParameter("long", "34347897");
0896: request.setParameter("longObject", "2335454");
0897: request.setParameter("short", "32");
0898: request.setParameter("shortObject", "12");
0899: WebResponse response = conversation.getResponse(request);
0900:
0901: assertEquals(
0902: "SATURDAY,the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
0903: response.getText());
0904:
0905: request = new PostMethodWebRequest(
0906: "http://localhost:8181/submissions/named_bean/normal");
0907: request.setParameter(ReservedParameters.SUBMISSION, "bean");
0908: request.setParameter("enum", "invalid");
0909: request.setParameter("string", "the string");
0910: request.setParameter("boolean", "y");
0911: request.setParameter("string", "the string");
0912: request.setParameter("stringbuffer", "the stringbuffer");
0913: request.setParameter("int", "23fd33");
0914: request.setParameter("char", "u");
0915: request.setParameter("character", "R");
0916: request.setParameter("boolean", "y");
0917: request.setParameter("booleanObject", "no");
0918: request.setParameter("byte", "120");
0919: request.setParameter("byteObject", "21");
0920: request.setParameter("double", "zef.34");
0921: request.setParameter("doubleObject", "25435.98");
0922: request.setParameter("float", "3434.76");
0923: request.setParameter("floatObject", "6534.8");
0924: request.setParameter("long", "34347897");
0925: request.setParameter("longObject", "233f5454");
0926: request.setParameter("short", "32");
0927: request.setParameter("shortObject", "");
0928: response = conversation.getResponse(request);
0929:
0930: assertEquals(
0931: "NOTNUMERIC : double\nINVALID : enum\nNOTNUMERIC : int\nNOTNUMERIC : longObject\nnull,the string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
0932: response.getText());
0933: }
0934:
0935: public void testNamedSubmissionBeanPrefix() throws Exception {
0936: setupSite("site/submissions.xml");
0937:
0938: WebConversation conversation = new WebConversation();
0939: WebRequest request = new PostMethodWebRequest(
0940: "http://localhost:8181/submissions/named_bean/prefix");
0941: request.setParameter(ReservedParameters.SUBMISSION, "bean");
0942: request.setParameter("prefix_enum", "TUESDAY");
0943: request.setParameter("prefix_string", "the string");
0944: request.setParameter("prefix_boolean", "y");
0945: request.setParameter("prefix_string", "the string");
0946: request.setParameter("prefix_stringbuffer", "the stringbuffer");
0947: request.setParameter("prefix_int", "23154");
0948: request.setParameter("prefix_integer", "893749");
0949: request.setParameter("prefix_char", "u");
0950: request.setParameter("prefix_character", "R");
0951: request.setParameter("prefix_boolean", "y");
0952: request.setParameter("prefix_booleanObject", "no");
0953: request.setParameter("prefix_byte", "120");
0954: request.setParameter("prefix_byteObject", "21");
0955: request.setParameter("prefix_double", "34878.34");
0956: request.setParameter("prefix_doubleObject", "25435.98");
0957: request.setParameter("prefix_float", "3434.76");
0958: request.setParameter("prefix_floatObject", "6534.8");
0959: request.setParameter("prefix_long", "34347897");
0960: request.setParameter("prefix_longObject", "2335454");
0961: request.setParameter("prefix_short", "32");
0962: request.setParameter("prefix_shortObject", "12");
0963: WebResponse response = conversation.getResponse(request);
0964:
0965: assertEquals(
0966: "TUESDAY,the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
0967: response.getText());
0968:
0969: request = new PostMethodWebRequest(
0970: "http://localhost:8181/submissions/named_bean/prefix");
0971: request.setParameter(ReservedParameters.SUBMISSION, "bean");
0972: request.setParameter("prefix_enum", "invalid");
0973: request.setParameter("prefix_string", "the string");
0974: request.setParameter("prefix_boolean", "y");
0975: request.setParameter("prefix_string", "the string");
0976: request.setParameter("prefix_stringbuffer", "the stringbuffer");
0977: request.setParameter("prefix_int", "23fd33");
0978: request.setParameter("prefix_char", "u");
0979: request.setParameter("prefix_character", "R");
0980: request.setParameter("prefix_boolean", "y");
0981: request.setParameter("prefix_booleanObject", "no");
0982: request.setParameter("prefix_byte", "120");
0983: request.setParameter("prefix_byteObject", "21");
0984: request.setParameter("prefix_double", "zef.34");
0985: request.setParameter("prefix_doubleObject", "25435.98");
0986: request.setParameter("prefix_float", "3434.76");
0987: request.setParameter("prefix_floatObject", "6534.8");
0988: request.setParameter("prefix_long", "34347897");
0989: request.setParameter("prefix_longObject", "233f5454");
0990: request.setParameter("prefix_short", "32");
0991: request.setParameter("prefix_shortObject", "");
0992: response = conversation.getResponse(request);
0993:
0994: assertEquals(
0995: "NOTNUMERIC : double\nINVALID : enum\nNOTNUMERIC : int\nNOTNUMERIC : longObject\nnull,the string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
0996: response.getText());
0997: }
0998:
0999: public void testNamedSubmissionBeanInjection() throws Exception {
1000: setupSite("site/submissions.xml");
1001:
1002: WebConversation conversation = new WebConversation();
1003: WebRequest request = new PostMethodWebRequest(
1004: "http://localhost:8181/submissions/named_bean/normal/injection");
1005: request.setParameter(ReservedParameters.SUBMISSION, "bean");
1006: request.setParameter("enum", "THURSDAY");
1007: request.setParameter("string", "the string");
1008: request.setParameter("boolean", "y");
1009: request.setParameter("string", "the string");
1010: request.setParameter("stringbuffer", "the stringbuffer");
1011: request.setParameter("int", "23154");
1012: request.setParameter("integer", "893749");
1013: request.setParameter("char", "u");
1014: request.setParameter("character", "R");
1015: request.setParameter("boolean", "y");
1016: request.setParameter("booleanObject", "no");
1017: request.setParameter("byte", "120");
1018: request.setParameter("byteObject", "21");
1019: request.setParameter("double", "34878.34");
1020: request.setParameter("doubleObject", "25435.98");
1021: request.setParameter("float", "3434.76");
1022: request.setParameter("floatObject", "6534.8");
1023: request.setParameter("long", "34347897");
1024: request.setParameter("longObject", "2335454");
1025: request.setParameter("short", "32");
1026: request.setParameter("shortObject", "12");
1027: WebResponse response = conversation.getResponse(request);
1028:
1029: assertEquals(
1030: "THURSDAY,the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
1031: response.getText());
1032:
1033: request = new PostMethodWebRequest(
1034: "http://localhost:8181/submissions/named_bean/normal/injection");
1035: request.setParameter(ReservedParameters.SUBMISSION, "bean");
1036: request.setParameter("enum", "invalid");
1037: request.setParameter("string", "the string");
1038: request.setParameter("boolean", "y");
1039: request.setParameter("string", "the string");
1040: request.setParameter("stringbuffer", "the stringbuffer");
1041: request.setParameter("int", "23fd33");
1042: request.setParameter("char", "u");
1043: request.setParameter("character", "R");
1044: request.setParameter("boolean", "y");
1045: request.setParameter("booleanObject", "no");
1046: request.setParameter("byte", "120");
1047: request.setParameter("byteObject", "21");
1048: request.setParameter("double", "zef.34");
1049: request.setParameter("doubleObject", "25435.98");
1050: request.setParameter("float", "3434.76");
1051: request.setParameter("floatObject", "6534.8");
1052: request.setParameter("long", "34347897");
1053: request.setParameter("longObject", "233f5454");
1054: request.setParameter("short", "32");
1055: request.setParameter("shortObject", "");
1056: response = conversation.getResponse(request);
1057:
1058: assertEquals(
1059: "NOTNUMERIC : double\nINVALID : enum\nNOTNUMERIC : int\nNOTNUMERIC : longObject\nnull,the string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
1060: response.getText());
1061: }
1062:
1063: public void testNamedSubmissionBeanPrefixInjection()
1064: throws Exception {
1065: setupSite("site/submissions.xml");
1066:
1067: WebConversation conversation = new WebConversation();
1068: WebRequest request = new PostMethodWebRequest(
1069: "http://localhost:8181/submissions/named_bean/prefix/injection");
1070: request.setParameter(ReservedParameters.SUBMISSION, "bean");
1071: request.setParameter("prefix_enum", "TUESDAY");
1072: request.setParameter("prefix_string", "the string");
1073: request.setParameter("prefix_boolean", "y");
1074: request.setParameter("prefix_string", "the string");
1075: request.setParameter("prefix_stringbuffer", "the stringbuffer");
1076: request.setParameter("prefix_int", "23154");
1077: request.setParameter("prefix_integer", "893749");
1078: request.setParameter("prefix_char", "u");
1079: request.setParameter("prefix_character", "R");
1080: request.setParameter("prefix_boolean", "y");
1081: request.setParameter("prefix_booleanObject", "no");
1082: request.setParameter("prefix_byte", "120");
1083: request.setParameter("prefix_byteObject", "21");
1084: request.setParameter("prefix_double", "34878.34");
1085: request.setParameter("prefix_doubleObject", "25435.98");
1086: request.setParameter("prefix_float", "3434.76");
1087: request.setParameter("prefix_floatObject", "6534.8");
1088: request.setParameter("prefix_long", "34347897");
1089: request.setParameter("prefix_longObject", "2335454");
1090: request.setParameter("prefix_short", "32");
1091: request.setParameter("prefix_shortObject", "12");
1092: WebResponse response = conversation.getResponse(request);
1093:
1094: assertEquals(
1095: "TUESDAY,the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
1096: response.getText());
1097:
1098: request = new PostMethodWebRequest(
1099: "http://localhost:8181/submissions/named_bean/prefix/injection");
1100: request.setParameter(ReservedParameters.SUBMISSION, "bean");
1101: request.setParameter("prefix_enum", "invalid");
1102: request.setParameter("prefix_string", "the string");
1103: request.setParameter("prefix_boolean", "y");
1104: request.setParameter("prefix_string", "the string");
1105: request.setParameter("prefix_stringbuffer", "the stringbuffer");
1106: request.setParameter("prefix_int", "23fd33");
1107: request.setParameter("prefix_char", "u");
1108: request.setParameter("prefix_character", "R");
1109: request.setParameter("prefix_boolean", "y");
1110: request.setParameter("prefix_booleanObject", "no");
1111: request.setParameter("prefix_byte", "120");
1112: request.setParameter("prefix_byteObject", "21");
1113: request.setParameter("prefix_double", "zef.34");
1114: request.setParameter("prefix_doubleObject", "25435.98");
1115: request.setParameter("prefix_float", "3434.76");
1116: request.setParameter("prefix_floatObject", "6534.8");
1117: request.setParameter("prefix_long", "34347897");
1118: request.setParameter("prefix_longObject", "233f5454");
1119: request.setParameter("prefix_short", "32");
1120: request.setParameter("prefix_shortObject", "");
1121: response = conversation.getResponse(request);
1122:
1123: assertEquals(
1124: "NOTNUMERIC : double\nINVALID : enum\nNOTNUMERIC : int\nNOTNUMERIC : longObject\nnull,the string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
1125: response.getText());
1126: }
1127:
1128: public void testSubmissionFillBean() throws Exception {
1129: setupSite("site/submissions.xml");
1130:
1131: WebConversation conversation = new WebConversation();
1132: WebRequest request = new GetMethodWebRequest(
1133: "http://localhost:8181/submissions/fill/bean/normal");
1134: WebResponse response = null;
1135: WebForm form = null;
1136: response = conversation.getResponse(request);
1137:
1138: form = response.getFormWithName("submissionform");
1139: request = form.getRequest();
1140: request.setParameter("enum", "MONDAY");
1141: request.setParameter("string", "the string");
1142: request.setParameter("boolean", "y");
1143: request.setParameter("string", "the string");
1144: request.setParameter("stringbuffer", "the stringbuffer");
1145: request.setParameter("int", "23154");
1146: request.setParameter("integer", "893749");
1147: request.setParameter("char", "u");
1148: request.setParameter("character", "R");
1149: request.setParameter("boolean", "y");
1150: request.setParameter("booleanObject", "no");
1151: request.setParameter("byte", "120");
1152: request.setParameter("byteObject", "21");
1153: request.setParameter("double", "34878.34");
1154: request.setParameter("doubleObject", "25435.98");
1155: request.setParameter("float", "3434.76");
1156: request.setParameter("floatObject", "6534.8");
1157: request.setParameter("long", "34347897");
1158: request.setParameter("longObject", "2335454");
1159: request.setParameter("short", "32");
1160: request.setParameter("shortObject", "12");
1161: request
1162: .selectFile("stringFile", "somedesign.html",
1163: new StringBufferInputStream(
1164: "this is some html content"),
1165: "text/html");
1166: byte[] image_bytes = ResourceFinderClasspath.getInstance()
1167: .useStream("uwyn.png", new InputStreamUser() {
1168: public Object useInputStream(InputStream stream)
1169: throws InnerClassException {
1170: try {
1171: return FileUtils.readBytes(stream);
1172: } catch (FileUtilsErrorException e) {
1173: throwException(e);
1174: }
1175:
1176: return null;
1177: }
1178: });
1179: request.selectFile("bytesFile", "someimage.png",
1180: new ByteArrayInputStream(image_bytes), "image/png");
1181: request.selectFile("streamFile", "somefile.png",
1182: new ByteArrayInputStream(image_bytes), null);
1183:
1184: response = conversation.getResponse(request);
1185:
1186: assertEquals(
1187: "MONDAY,the string,the stringbuffer,23154,893749,u,b,true,false,22,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12,this is some html content,true,someimage.png,true",
1188: response.getText());
1189:
1190: request = new GetMethodWebRequest(
1191: "http://localhost:8181/submissions/fill/bean/normal");
1192: response = conversation.getResponse(request);
1193:
1194: form = response.getFormWithName("submissionform");
1195: request = form.getRequest();
1196: request.setParameter("enum", "invalid");
1197: request.setParameter("string", "the string");
1198: request.setParameter("boolean", "y");
1199: request.setParameter("string", "the string");
1200: request.setParameter("stringbuffer", "the stringbuffer");
1201: request.setParameter("int", "23fd33");
1202: request.setParameter("char", "u");
1203: request.setParameter("character", "R");
1204: request.setParameter("boolean", "y");
1205: request.setParameter("booleanObject", "no");
1206: request.setParameter("byte", "120");
1207: request.setParameter("byteObject", "21");
1208: request.setParameter("double", "zef.34");
1209: request.setParameter("doubleObject", "25435.98");
1210: request.setParameter("float", "3434.76");
1211: request.setParameter("floatObject", "6534.8");
1212: request.setParameter("long", "34347897");
1213: request.setParameter("longObject", "233f5454");
1214: request.setParameter("short", "32");
1215: request.setParameter("shortObject", "");
1216:
1217: response = conversation.getResponse(request);
1218:
1219: assertEquals(
1220: "NOTNUMERIC : double\nINVALID : enum\nNOTNUMERIC : int\nNOTNUMERIC : longObject\nnull,the string,the stringbuffer,999,null,u,b,true,false,22,21,123.45,25435.98,3434.76,6534.8,34347897,55,32,null,stringFile,false,null,false",
1221: response.getText());
1222: }
1223:
1224: public void testSubmissionFillBeanGroup() throws Exception {
1225: setupSite("site/submissions.xml");
1226:
1227: WebConversation conversation = new WebConversation();
1228: WebRequest request = new GetMethodWebRequest(
1229: "http://localhost:8181/submissions/fill/bean/group");
1230: WebResponse response = null;
1231: WebForm form = null;
1232: response = conversation.getResponse(request);
1233:
1234: form = response.getFormWithName("submissionform");
1235: request = form.getRequest();
1236: request.setParameter("enum", "SUNDAY");
1237: request.setParameter("string", "the string");
1238: request.setParameter("boolean", "y");
1239: request.setParameter("string", "the string");
1240: request.setParameter("stringbuffer", "the stringbuffer");
1241: request.setParameter("int", "23154");
1242: request.setParameter("integer", "893749");
1243: request.setParameter("char", "u");
1244: request.setParameter("character", "R");
1245: request.setParameter("boolean", "y");
1246: request.setParameter("booleanObject", "no");
1247: request.setParameter("byte", "120");
1248: request.setParameter("byteObject", "21");
1249: request.setParameter("double", "34878.34");
1250: request.setParameter("doubleObject", "25435.98");
1251: request.setParameter("float", "3434.76");
1252: request.setParameter("floatObject", "6534.8");
1253: request.setParameter("long", "34347897");
1254: request.setParameter("longObject", "2335454");
1255: request.setParameter("short", "32");
1256: request.setParameter("shortObject", "12");
1257: request
1258: .selectFile("stringFile", "somedesign.html",
1259: new StringBufferInputStream(
1260: "this is some html content"),
1261: "text/html");
1262: byte[] image_bytes = ResourceFinderClasspath.getInstance()
1263: .useStream("uwyn.png", new InputStreamUser() {
1264: public Object useInputStream(InputStream stream)
1265: throws InnerClassException {
1266: try {
1267: return FileUtils.readBytes(stream);
1268: } catch (FileUtilsErrorException e) {
1269: throwException(e);
1270: }
1271:
1272: return null;
1273: }
1274: });
1275: request.selectFile("bytesFile", "someimage.png",
1276: new ByteArrayInputStream(image_bytes), "image/png");
1277: request.selectFile("streamFile", "somefile.png",
1278: new ByteArrayInputStream(image_bytes), null);
1279:
1280: response = conversation.getResponse(request);
1281:
1282: assertEquals(
1283: "SUNDAY,the string,stringbuffer,23154,111,a,b,false,true,22,33,123.45,234.56,321.54,432.65,44,2335454,32,77,stringFile,false,null,false",
1284: response.getText());
1285:
1286: request = new GetMethodWebRequest(
1287: "http://localhost:8181/submissions/fill/bean/group");
1288: response = conversation.getResponse(request);
1289:
1290: form = response.getFormWithName("submissionform");
1291: request = form.getRequest();
1292: request.setParameter("enum", "invalid");
1293: request.setParameter("string", "the string");
1294: request.setParameter("boolean", "y");
1295: request.setParameter("string", "the string");
1296: request.setParameter("stringbuffer", "the stringbuffer");
1297: request.setParameter("int", "23fd33");
1298: request.setParameter("char", "u");
1299: request.setParameter("character", "R");
1300: request.setParameter("boolean", "y");
1301: request.setParameter("booleanObject", "no");
1302: request.setParameter("byte", "120");
1303: request.setParameter("byteObject", "21");
1304: request.setParameter("double", "zef.34");
1305: request.setParameter("doubleObject", "25435.98");
1306: request.setParameter("float", "3434.76");
1307: request.setParameter("floatObject", "6534.8");
1308: request.setParameter("long", "34347897");
1309: request.setParameter("longObject", "233f5454");
1310: request.setParameter("shortObject", "");
1311:
1312: response = conversation.getResponse(request);
1313:
1314: assertEquals(
1315: "NOTNUMERIC : int\nNOTNUMERIC : longObject\nSATURDAY,the string,stringbuffer,999,111,a,b,false,true,22,33,123.45,234.56,321.54,432.65,44,55,-24,77,stringFile,false,null,false",
1316: response.getText());
1317: }
1318:
1319: public void testParamsGenerated() throws Exception {
1320: setupSite("site/submissions.xml");
1321:
1322: WebConversation conversation = new WebConversation();
1323: WebRequest request = null;
1324: WebResponse response = null;
1325:
1326: request = new PostMethodWebRequest(
1327: "http://localhost:8181/params/generated");
1328: request.setParameter(ReservedParameters.SUBMISSION, "name");
1329: request.setParameter("wantsupdates", "on");
1330: request.setParameter("colors", new String[] { "orange", "blue",
1331: "green" });
1332: request.setParameter("firstname", "Geert");
1333: request.setParameter("lastname", "Bevin");
1334: response = conversation.getResponse(request);
1335: assertEquals(
1336: "Geert, Bevin\n"
1337: + "<input type=\"checkbox\" name=\"wantsupdates\" checked=\"checked\"> I want updates<br />\n"
1338: + "<input type=\"checkbox\" name=\"colors\" value=\"orange\" checked=\"checked\">orange<br />\n"
1339: + "<input type=\"checkbox\" name=\"colors\" value=\"blue\" checked=\"checked\">blue<br />\n"
1340: + "<input type=\"checkbox\" name=\"colors\" value=\"red\">red<br />\n"
1341: + "<input type=\"radio\" name=\"firstname\" checked=\"checked\"> Geert\n"
1342: + "<input type=\"radio\" name=\"firstname\"> Nathalie\n"
1343: + "<select name=\"lastname\">\n"
1344: + "\t<option value=\"Bevin\" selected=\"selected\">Bevin</option>\n"
1345: + "\t<option value=\"Mafessoni\">Mafessoni</option>\n"
1346: + "</select>\n", response.getText());
1347:
1348: request = new PostMethodWebRequest(
1349: "http://localhost:8181/params/generated");
1350: request.setParameter(ReservedParameters.SUBMISSION, "name");
1351: response = conversation.getResponse(request);
1352: assertEquals(
1353: ", \n"
1354: + "<input type=\"checkbox\" name=\"wantsupdates\"> I want updates<br />\n"
1355: + "<input type=\"checkbox\" name=\"colors\" value=\"orange\">orange<br />\n"
1356: + "<input type=\"checkbox\" name=\"colors\" value=\"blue\">blue<br />\n"
1357: + "<input type=\"checkbox\" name=\"colors\" value=\"red\">red<br />\n"
1358: + "<input type=\"radio\" name=\"firstname\"> Geert\n"
1359: + "<input type=\"radio\" name=\"firstname\"> Nathalie\n"
1360: + "<select name=\"lastname\">\n"
1361: + "\t<option value=\"Bevin\">Bevin</option>\n"
1362: + "\t<option value=\"Mafessoni\">Mafessoni</option>\n"
1363: + "</select>\n", response.getText());
1364: }
1365:
1366: public void testFormGenerated() throws Exception {
1367: setupSite("site/submissions.xml");
1368:
1369: WebConversation conversation = new WebConversation();
1370: WebRequest request = null;
1371: WebResponse response = null;
1372:
1373: request = new PostMethodWebRequest(
1374: "http://localhost:8181/form/generated");
1375: request.setParameter(ReservedParameters.SUBMISSION, "form");
1376: response = conversation.getResponse(request);
1377: assertEquals(TemplateFactory.ENGINEHTML.get(
1378: "formbuilder_fields_out_constrained_empty")
1379: .getContent(), response.getText());
1380: }
1381:
1382: public void testSetSubmissionBean() throws Exception {
1383: setupSite("site/submissions.xml");
1384:
1385: WebConversation conversation = new WebConversation();
1386: WebRequest request = null;
1387: WebResponse response = null;
1388:
1389: request = new GetMethodWebRequest(
1390: "http://localhost:8181/set_submission_bean");
1391: response = conversation.getResponse(request);
1392: assertEquals(
1393: ", \n"
1394: + "<input type=\"checkbox\" name=\"wantsupdates\"> I want updates<br />\n"
1395: + "<input type=\"checkbox\" name=\"colors\" value=\"orange\">orange<br />\n"
1396: + "<input type=\"checkbox\" name=\"colors\" value=\"blue\">blue<br />\n"
1397: + "<input type=\"checkbox\" name=\"colors\" value=\"red\">red<br />\n"
1398: + "<input type=\"radio\" name=\"firstname\"> Geert\n"
1399: + "<input type=\"radio\" name=\"firstname\"> Nathalie\n"
1400: + "<select name=\"lastname\">\n"
1401: + "\t<option value=\"Bevin\">Bevin</option>\n"
1402: + "\t<option value=\"Mafessoni\">Mafessoni</option>\n"
1403: + "</select>\n", response.getText());
1404:
1405: request = new GetMethodWebRequest(
1406: "http://localhost:8181/set_submission_bean");
1407: request.setParameter("populated", "yes");
1408: response = conversation.getResponse(request);
1409: assertEquals(
1410: "Geert, Bevin\n"
1411: + "<input type=\"checkbox\" name=\"wantsupdates\" checked=\"checked\"> I want updates<br />\n"
1412: + "<input type=\"checkbox\" name=\"colors\" value=\"orange\" checked=\"checked\">orange<br />\n"
1413: + "<input type=\"checkbox\" name=\"colors\" value=\"blue\">blue<br />\n"
1414: + "<input type=\"checkbox\" name=\"colors\" value=\"red\" checked=\"checked\">red<br />\n"
1415: + "<input type=\"radio\" name=\"firstname\" checked=\"checked\"> Geert\n"
1416: + "<input type=\"radio\" name=\"firstname\"> Nathalie\n"
1417: + "<select name=\"lastname\">\n\t<option value=\"Bevin\" selected=\"selected\">Bevin</option>\n"
1418: + "\t<option value=\"Mafessoni\">Mafessoni</option>\n"
1419: + "</select>\n", response.getText());
1420: }
1421:
1422: public void testParamsDefaults() throws Exception {
1423: setupSite("site/submissions.xml");
1424:
1425: WebConversation conversation = new WebConversation();
1426: WebRequest request = new PostMethodWebRequest(
1427: "http://localhost:8181/params/defaults");
1428: request.setParameter(ReservedParameters.SUBMISSION, "name");
1429: WebResponse response = conversation.getResponse(request);
1430: assertEquals("John|Paul,27,the element config value,", response
1431: .getText());
1432: }
1433:
1434: public void testFileUploadOmitted() throws Exception {
1435: setupSite("site/submissions.xml");
1436:
1437: WebConversation conversation = new WebConversation();
1438: WebRequest request = null;
1439: WebResponse response = null;
1440: WebForm form = null;
1441:
1442: // no file provided
1443: request = new GetMethodWebRequest(
1444: "http://localhost:8181/fileupload/simple");
1445: response = conversation.getResponse(request);
1446: form = response.getForms()[0];
1447:
1448: form.setParameter("purpose", "it will serve you well");
1449: response = form.submit();
1450: assertEquals("no file 1;no file 2;it will serve you well",
1451: response.getText());
1452: }
1453:
1454: public void testFileUploadEmpty() throws Exception {
1455: setupSite("site/submissions.xml");
1456:
1457: WebConversation conversation = new WebConversation();
1458: WebRequest request = null;
1459: WebResponse response = null;
1460: WebForm form = null;
1461:
1462: // empty file provided
1463: request = new GetMethodWebRequest(
1464: "http://localhost:8181/fileupload/simple");
1465: response = conversation.getResponse(request);
1466: form = response.getForms()[0];
1467:
1468: File empty_upload = File.createTempFile("rifetest", ".tmp");
1469: empty_upload.deleteOnExit();
1470: FileUtils.writeString("", empty_upload);
1471:
1472: form.setParameter("purpose", "it will serve you well");
1473: UploadFileSpec empty_upload_spec = new UploadFileSpec(
1474: empty_upload);
1475: form.setParameter("doc1",
1476: new UploadFileSpec[] { empty_upload_spec });
1477:
1478: response = form.submit();
1479: assertEquals("empty file 1;no file 2;it will serve you well",
1480: response.getText());
1481:
1482: empty_upload.delete();
1483: }
1484:
1485: public void testFileUploadSingleParam() throws Exception {
1486: setupSite("site/submissions.xml");
1487:
1488: WebConversation conversation = new WebConversation();
1489: WebRequest request = null;
1490: WebResponse response = null;
1491: WebForm form = null;
1492:
1493: request = new GetMethodWebRequest(
1494: "http://localhost:8181/fileupload/simple");
1495: response = conversation.getResponse(request);
1496: form = response.getForms()[0];
1497:
1498: String upload_content = "abcdefghijklmnopqrstuvwxyz";
1499: File upload = File.createTempFile("rifetest", ".tmp");
1500: upload.deleteOnExit();
1501: FileUtils.writeString(upload_content, upload);
1502:
1503: form.setParameter("purpose", "it will serve you well");
1504: UploadFileSpec upload_spec = new UploadFileSpec(upload);
1505: form.setParameter("doc1", new UploadFileSpec[] { upload_spec });
1506:
1507: response = form.submit();
1508: assertEquals(upload_content
1509: + ";no file 2;it will serve you well", response
1510: .getText());
1511:
1512: upload.delete();
1513: }
1514:
1515: public void testFileUploadInjection() throws Exception {
1516: setupSite("site/submissions.xml");
1517:
1518: WebConversation conversation = new WebConversation();
1519: WebRequest request = null;
1520: WebResponse response = null;
1521: WebForm form = null;
1522:
1523: request = new GetMethodWebRequest(
1524: "http://localhost:8181/fileupload/injection");
1525: response = conversation.getResponse(request);
1526: form = response.getForms()[0];
1527:
1528: String upload_content = "abcdefghijklmnopqrstuvwxyz";
1529: File upload = File.createTempFile("rifetest", ".tmp");
1530: upload.deleteOnExit();
1531: FileUtils.writeString(upload_content, upload);
1532:
1533: form.setParameter("purpose", "it will serve you well");
1534: UploadFileSpec upload_spec = new UploadFileSpec(upload);
1535: form.setParameter("doc1", new UploadFileSpec[] { upload_spec });
1536:
1537: response = form.submit();
1538: assertEquals(upload_content + ";it will serve you well",
1539: response.getText());
1540:
1541: upload.delete();
1542: }
1543:
1544: public void testFileUploadMultipleParams() throws Exception {
1545: setupSite("site/submissions.xml");
1546:
1547: WebConversation conversation = new WebConversation();
1548: WebRequest request = null;
1549: WebResponse response = null;
1550: WebForm form = null;
1551:
1552: request = new GetMethodWebRequest(
1553: "http://localhost:8181/fileupload/simple");
1554: response = conversation.getResponse(request);
1555: form = response.getForms()[0];
1556:
1557: String upload1_content = "abcdefghijklmnopqrstuvwxyz";
1558: File upload1 = File.createTempFile("rifetest", ".tmp");
1559: String upload2_content = "oiuezroizehfkjsdgfhgizeugfizuhfksjdhfiuzhfiuzehfizeuhfziuh";
1560: File upload2 = File.createTempFile("rifetest", ".tmp");
1561: upload1.deleteOnExit();
1562: FileUtils.writeString(upload1_content, upload1);
1563: upload2.deleteOnExit();
1564: FileUtils.writeString(upload2_content, upload2);
1565:
1566: form.setParameter("purpose", "it will serve you well");
1567: UploadFileSpec upload_spec1 = new UploadFileSpec(upload1);
1568: UploadFileSpec upload_spec2 = new UploadFileSpec(upload2);
1569: form
1570: .setParameter("doc1",
1571: new UploadFileSpec[] { upload_spec1 });
1572: form
1573: .setParameter("doc2",
1574: new UploadFileSpec[] { upload_spec2 });
1575:
1576: response = form.submit();
1577: assertEquals(upload1_content + ";" + upload2_content
1578: + ";it will serve you well", response.getText());
1579:
1580: upload1.delete();
1581: upload2.delete();
1582: }
1583:
1584: public void testFileUploadSingleParamMultipleFiles()
1585: throws Exception {
1586: setupSite("site/submissions.xml");
1587:
1588: WebConversation conversation = new WebConversation();
1589: WebRequest request = null;
1590: WebResponse response = null;
1591: WebForm form = null;
1592:
1593: request = new GetMethodWebRequest(
1594: "http://localhost:8181/fileupload/simple");
1595: response = conversation.getResponse(request);
1596: form = response.getForms()[0];
1597:
1598: String upload1_content = "abcdefghijklmnopqrstuvwxyz";
1599: File upload1 = File.createTempFile("rifetest", ".tmp");
1600: String upload2_content = "oiuezroizehfkjsdgfhgizeugfizuhfksjdhfiuzhfiuzehfizeuhfziuh";
1601: File upload2 = File.createTempFile("rifetest", ".tmp");
1602: upload1.deleteOnExit();
1603: FileUtils.writeString(upload1_content, upload1);
1604: upload2.deleteOnExit();
1605: FileUtils.writeString(upload2_content, upload2);
1606:
1607: form.setParameter("purpose", "it will serve you well");
1608: UploadFileSpec upload_spec1 = new UploadFileSpec(upload1);
1609: UploadFileSpec upload_spec2 = new UploadFileSpec(upload2);
1610: form.setParameter("doc1", new UploadFileSpec[] { upload_spec1,
1611: upload_spec2 });
1612:
1613: response = form.submit();
1614: assertEquals(upload1_content + "," + upload2_content
1615: + ";no file 2;it will serve you well", response
1616: .getText());
1617:
1618: upload1.delete();
1619: upload2.delete();
1620: }
1621:
1622: public void testFileUploadRegexp() throws Exception {
1623: setupSite("site/submissions.xml");
1624:
1625: WebConversation conversation = new WebConversation();
1626: WebRequest request = null;
1627: WebResponse response = null;
1628: WebForm form = null;
1629:
1630: request = new GetMethodWebRequest(
1631: "http://localhost:8181/fileupload/regexp");
1632: response = conversation.getResponse(request);
1633: form = response.getForms()[0];
1634:
1635: form
1636: .setParameter("somefile",
1637: new UploadFileSpec[] { new UploadFileSpec(
1638: "file1.txt",
1639: new StringBufferInputStream(
1640: "file1somefilecontent"),
1641: "text/plain") });
1642: form
1643: .setParameter("yourdoc1",
1644: new UploadFileSpec[] { new UploadFileSpec(
1645: "file2.txt",
1646: new StringBufferInputStream(
1647: "file2yourdoc1content"),
1648: "text/plain") });
1649: form
1650: .setParameter("hisdoc1",
1651: new UploadFileSpec[] { new UploadFileSpec(
1652: "file3.txt",
1653: new StringBufferInputStream(
1654: "file3hisdoc1content"),
1655: "text/plain") });
1656: form
1657: .setParameter("thisdoc2",
1658: new UploadFileSpec[] { new UploadFileSpec(
1659: "file4.txt",
1660: new StringBufferInputStream(
1661: "file4thisdoc2content"),
1662: "text/plain") });
1663:
1664: response = form.submit();
1665: assertEquals(
1666: "file1somefilecontent,\nfile3hisdoc1content,file4thisdoc2content,",
1667: response.getText());
1668: }
1669:
1670: public void testFileUploadSizeLimit() throws Exception {
1671: setupSite("site/submissions.xml");
1672:
1673: WebConversation conversation = new WebConversation();
1674: WebRequest request = null;
1675: WebResponse response = null;
1676: WebForm form = null;
1677:
1678: String upload_content_part = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"; // 128 bytes
1679: StringBuffer upload_content = new StringBuffer();
1680: File upload = File.createTempFile("rifetest", ".tmp");
1681: upload.deleteOnExit();
1682: for (int i = 0; i < 4; i++) {
1683: for (int j = 0; j < 8; j++) // 1KB
1684: {
1685: upload_content.append(upload_content_part);
1686: }
1687: }
1688: FileUtils.writeString(upload_content.toString(), upload);
1689: UploadFileSpec upload_spec = null;
1690:
1691: // exactly the same size as the limit
1692: Config.getRepInstance().setParameter(
1693: RifeConfig.Engine.PARAM_FILEUPLOAD_SIZE_LIMIT,
1694: "" + upload_content.length());
1695: request = new GetMethodWebRequest(
1696: "http://localhost:8181/fileupload/simple");
1697: response = conversation.getResponse(request);
1698: form = response.getForms()[0];
1699:
1700: form.setParameter("purpose", "it will serve you well");
1701: upload_spec = new UploadFileSpec(upload);
1702: form.setParameter("doc1", new UploadFileSpec[] { upload_spec });
1703:
1704: response = form.submit();
1705: assertEquals(upload_content.toString()
1706: + ";no file 2;it will serve you well", response
1707: .getText());
1708:
1709: // exceeding the size by 1
1710: Config.getRepInstance().setParameter(
1711: RifeConfig.Engine.PARAM_FILEUPLOAD_SIZE_LIMIT,
1712: "" + (upload_content.length() - 1));
1713: request = new GetMethodWebRequest(
1714: "http://localhost:8181/fileupload/simple");
1715: response = conversation.getResponse(request);
1716: form = response.getForms()[0];
1717:
1718: // throw no exception when size is exceeded, but don't provide the uploaded file
1719: Config.getRepInstance().setParameter(
1720: RifeConfig.Engine.PARAM_FILEUPLOAD_SIZE_EXCEPTION,
1721: false);
1722: form.setParameter("purpose", "it will serve you well");
1723: upload_spec = new UploadFileSpec(upload);
1724: form.setParameter("doc1", new UploadFileSpec[] { upload_spec });
1725: response = form.submit();
1726: assertEquals(
1727: "file 1 size exceeded;no file 2;it will serve you well",
1728: response.getText());
1729:
1730: // throw exception when size is exceeded
1731: Config
1732: .getRepInstance()
1733: .setParameter(
1734: RifeConfig.Engine.PARAM_FILEUPLOAD_SIZE_EXCEPTION,
1735: true);
1736: form.setParameter("purpose", "it will serve you well");
1737: upload_spec = new UploadFileSpec(upload);
1738: form.setParameter("doc1", new UploadFileSpec[] { upload_spec });
1739:
1740: try {
1741: response = form.submit();
1742: fail();
1743: } catch (HttpInternalErrorException e) {
1744: assertTrue(getLogSink().getInternalException() instanceof MultipartFileTooBigException);
1745:
1746: MultipartFileTooBigException e2 = (MultipartFileTooBigException) getLogSink()
1747: .getInternalException();
1748: assertEquals("doc1", e2.getFileName());
1749: assertEquals(upload_content.length() - 1, e2.getSizeLimit());
1750: }
1751:
1752: // disable size limit
1753: Config.getRepInstance().setParameter(
1754: RifeConfig.Engine.PARAM_FILEUPLOAD_SIZE_CHECK, false);
1755: request = new GetMethodWebRequest(
1756: "http://localhost:8181/fileupload/simple");
1757: response = conversation.getResponse(request);
1758: form = response.getForms()[0];
1759:
1760: form.setParameter("purpose", "it will serve you well");
1761: upload_spec = new UploadFileSpec(upload);
1762: form.setParameter("doc1", new UploadFileSpec[] { upload_spec });
1763:
1764: response = form.submit();
1765:
1766: upload.delete();
1767:
1768: Config.getRepInstance().setParameter(
1769: RifeConfig.Engine.PARAM_FILEUPLOAD_SIZE_CHECK, "true");
1770: }
1771:
1772: public void testExitActivation() throws Exception {
1773: setupSite("site/submissions.xml");
1774:
1775: WebConversation conversation = new WebConversation();
1776: WebRequest request = new PostMethodWebRequest(
1777: "http://localhost:8181/exit/source");
1778: request.setParameter(ReservedParameters.SUBMISSION,
1779: "activate_exit");
1780: request.setParameter("submitted_value", "the value");
1781: WebResponse response = conversation.getResponse(request);
1782:
1783: assertEquals("exit target : the value", response.getText());
1784: }
1785:
1786: public void testDifferentSubmissioncontext() throws Exception {
1787: setupSite("site/submissions.xml");
1788:
1789: WebConversation conversation = new WebConversation();
1790: WebRequest request = new PostMethodWebRequest(
1791: "http://localhost:8181/submissions/valid");
1792: request.setParameter(ReservedParameters.SUBMISSION, "login");
1793: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1794: Base64.encode(".VALID"));
1795: request.setParameter("login", "gbevin");
1796: request.setParameter("password", "mypassword");
1797: request.setParameter("array", new String[] { "1", "3", "4" });
1798: WebResponse response = conversation.getResponse(request);
1799:
1800: assertEquals("gbevin,mypassword,1|3|4", response.getText());
1801:
1802: request = new PostMethodWebRequest(
1803: "http://localhost:8181/submissions/valid");
1804: request.setParameter(ReservedParameters.SUBMISSION, "login");
1805: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1806: Base64.encode(".TYPED^.VALID"));
1807: request.setParameter("login", "gbevin");
1808: request.setParameter("password", "mypassword");
1809: request.setParameter("array", new String[] { "1", "3", "4" });
1810: response = conversation.getResponse(request);
1811:
1812: assertEquals("null,null,null", response.getText());
1813: }
1814:
1815: public void testInvalidSubmissioncontext() throws Exception {
1816: setupSite("site/submissions.xml");
1817:
1818: WebConversation conversation = new WebConversation();
1819: WebRequest request = new PostMethodWebRequest(
1820: "http://localhost:8181/submissions/valid");
1821: request.setParameter(ReservedParameters.SUBMISSION, "login");
1822: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1823: Base64.encode("129:.9990::PPLM^.VALID"));
1824: request.setParameter("login", "gbevin");
1825: request.setParameter("password", "mypassword");
1826: request.setParameter("array", new String[] { "1", "3", "4" });
1827: WebResponse response = conversation.getResponse(request);
1828:
1829: assertEquals("null,null,null", response.getText());
1830: }
1831:
1832: public void testDifferentSubmissiontarget() throws Exception {
1833: setupSite("site/submissions.xml");
1834:
1835: WebConversation conversation = new WebConversation();
1836: WebRequest request = new PostMethodWebRequest(
1837: "http://localhost:8181/submissions/valid");
1838: request.setParameter(ReservedParameters.SUBMISSION, "login");
1839: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1840: Base64.encode(".VALID"));
1841: request.setParameter("login", "gbevin");
1842: request.setParameter("password", "mypassword");
1843: request.setParameter("array", new String[] { "1", "3", "4" });
1844: WebResponse response = conversation.getResponse(request);
1845:
1846: assertEquals("gbevin,mypassword,1|3|4", response.getText());
1847:
1848: request = new PostMethodWebRequest(
1849: "http://localhost:8181/submissions/valid");
1850: request.setParameter(ReservedParameters.SUBMISSION, "login");
1851: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1852: Base64.encode(".VALID^.TYPED"));
1853: request.setParameter("login", "gbevin");
1854: request.setParameter("password", "mypassword");
1855: request.setParameter("array", new String[] { "1", "3", "4" });
1856: response = conversation.getResponse(request);
1857:
1858: assertEquals("gbevin,mypassword,1|3|4", response.getText());
1859: }
1860:
1861: public void testInvalidSubmissiontarget() throws Exception {
1862: setupSite("site/submissions.xml");
1863:
1864: WebConversation conversation = new WebConversation();
1865: WebRequest request = new PostMethodWebRequest(
1866: "http://localhost:8181/submissions/valid");
1867: request.setParameter(ReservedParameters.SUBMISSION, "login");
1868: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1869: Base64.encode(".VALID^OIJH:98//JHSD::8"));
1870: request.setParameter("login", "gbevin");
1871: request.setParameter("password", "mypassword");
1872: request.setParameter("array", new String[] { "1", "3", "4" });
1873: WebResponse response = conversation.getResponse(request);
1874:
1875: assertEquals("gbevin,mypassword,1|3|4", response.getText());
1876: }
1877:
1878: public void testNonParamInputsOverlap() throws Exception {
1879: setupSite("site/submissions.xml");
1880:
1881: WebConversation conversation = new WebConversation();
1882: WebRequest request = null;
1883: WebResponse response = null;
1884:
1885: // trigger a first submission through direct request parameters with
1886: // inputs, check if it arrived correrctly
1887: request = new GetMethodWebRequest(
1888: "http://localhost:8181/submissions/inputsnonparam");
1889: request.setParameter("input1", "input1value");
1890: request.setParameter("input4", "input4value");
1891: request.setParameter(ReservedParameters.SUBMISSION,
1892: "submission1");
1893: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1894: Base64.encode(".INPUTSNONPARAM"));
1895: request.setParameter("parameter1", "parameter1value");
1896: request.setParameter("parameter2", "parameter2value");
1897: response = conversation.getResponse(request);
1898: assertEquals(
1899: "parameter1value"
1900: + "parameter2value"
1901: + "input1value"
1902: + "null"
1903: + "input3default"
1904: + "<a href=\"/submissions/inputsnonparam?submission=submission1&submissioncontext=LklOUFVUU05PTlBBUkFN&inputs=LklOUFVUU05PTlBBUkFNYwBpbnB1dDFuAGlucHV0MXZhbHVl\">thelink</a>",
1905: response.getText());
1906: // extract the link and the inputs parameter to construct a new
1907: // request which makes it possible to check that overlapped inputs
1908: // are still preserved
1909: request = new GetMethodWebRequest(
1910: "http://localhost:8181/submissions/inputsnonparam");
1911: request.setParameter(ReservedParameters.SUBMISSION,
1912: new String[] { "submission1", "submissionoverlap" });
1913: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1914: new String[] { Base64.encode(".INPUTSNONPARAM"),
1915: Base64.encode(".INPUTSOVERLAP") });
1916: request.setParameter("parameter1", "parameter1value");
1917: request.setParameter("parameter2", "parameter2value");
1918: request.setParameter("input1", "input1value");
1919: request.setParameter("input4", "input4value");
1920: request.setParameter("inputs", response.getLinkWith("thelink")
1921: .getParameterValues("inputs"));
1922: assertEquals(
1923: "parameter1value"
1924: + "parameter2value"
1925: + "input1value"
1926: + "null"
1927: + "input3default"
1928: + "<a href=\"/submissions/inputsnonparam?submission=submission1&submissioncontext=LklOUFVUU05PTlBBUkFN&inputs=LklOUFVUU05PTlBBUkFNYwBpbnB1dDFuAGlucHV0MXZhbHVl\">thelink</a>",
1929: response.getText());
1930:
1931: // check that inputs are not obtained from prohibited request parameters
1932: request = new GetMethodWebRequest(
1933: "http://localhost:8181/submissions/inputsnonparam");
1934: request.setParameter(ReservedParameters.SUBMISSION,
1935: new String[] { "submission1", "submissionoverlap" });
1936: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1937: new String[] { Base64.encode(".INPUTSNONPARAM"),
1938: Base64.encode(".INPUTSOVERLAP") });
1939: request.setParameter("parameter1", "parameter1value");
1940: request.setParameter("parameter2", "parameter2value");
1941: request.setParameter("input1", "input1value");
1942: request.setParameter("input4", "input4value");
1943: response = conversation.getResponse(request);
1944: assertEquals(
1945: "parameter1value"
1946: + "parameter2value"
1947: + "null"
1948: + "null"
1949: + "input3default"
1950: + "<a href=\"/submissions/inputsnonparam?submission=submission1&submissioncontext=LklOUFVUU05PTlBBUkFN\">thelink</a>",
1951: response.getText());
1952: request = new GetMethodWebRequest(
1953: "http://localhost:8181/submissions/inputsnonparam");
1954: request.setParameter(ReservedParameters.SUBMISSION,
1955: new String[] { "submissionoverlap", "submission1" });
1956: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1957: new String[] { Base64.encode(".INPUTSOVERLAP"),
1958: Base64.encode(".INPUTSNONPARAM") });
1959: request.setParameter("parameter1", "parameter1value");
1960: request.setParameter("parameter2", "parameter2value");
1961: request.setParameter("input1", "input1value");
1962: request.setParameter("input4", "input4value");
1963: response = conversation.getResponse(request);
1964: assertEquals(
1965: "parameter1value"
1966: + "parameter2value"
1967: + "null"
1968: + "null"
1969: + "input3default"
1970: + "<a href=\"/submissions/inputsnonparam?submission=submission1&submissioncontext=LklOUFVUU05PTlBBUkFN\">thelink</a>",
1971: response.getText());
1972: }
1973:
1974: public void testParameterOverlap() throws Exception {
1975: setupSite("site/submissions.xml");
1976:
1977: WebConversation conversation = new WebConversation();
1978: WebRequest request = new PostMethodWebRequest(
1979: "http://localhost:8181/submissions/valid");
1980: request.setParameter(ReservedParameters.SUBMISSION,
1981: new String[] { "login", "loginoverlap" });
1982: request.setParameter(ReservedParameters.SUBMISSIONCONTEXT,
1983: new String[] { Base64.encode(".VALID"),
1984: Base64.encode(".PARAMETERSOVERLAP") });
1985: request.setParameter("login", "gbevin");
1986: request.setParameter("password", "mypassword");
1987: request.setParameter("array", new String[] { "1", "3", "4" });
1988: WebResponse response = conversation.getResponse(request);
1989:
1990: assertEquals("gbevin,mypassword,1|3|4", response.getText());
1991: }
1992: }
|