001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.edl.impl;
017
018 /*import java.io.ByteArrayOutputStream;
019 import java.io.IOException;
020
021 import org.apache.commons.httpclient.methods.PostMethod;
022 import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
023 import org.apache.commons.httpclient.methods.multipart.Part;
024 import org.apache.commons.httpclient.methods.multipart.StringPart;*/
025 import org.junit.Ignore;
026 import org.junit.Test;
027 import org.kuali.rice.test.BaseRiceTestCase;
028
029 /**
030 * Tests the behavior of EDocLiteForm in the presence of various types of input
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033 public class EDocLiteFormTest extends BaseRiceTestCase {
034 /**
035 * Tests how EDocLiteForm handles parameters with multiple values
036 */
037 @Ignore("This test needs to be implemented!")
038 @Test public void testMultipleValuesPlainPOST() throws Exception {
039 // MockHttpServletRequest req = new MockHttpServletRequest();
040 // req.setMethod("post");
041 // req.addParameter("multiple_value", "value0");
042 // req.addParameter("multiple_value", "value1");
043 // req.addParameter("single_value", "value0");
044 // String[] values = req.getParameterValuesAsString("multiple_value");
045 // assertNotNull(values);
046 // assertEquals(2, values.length);
047 // values = req.getParameterValuesAsString("single_value");
048 // assertNotNull(values);
049 // assertEquals(1, values.length);
050 //
051 // values = (String[]) req.getParameterMap().get("multiple_value");
052 // assertNotNull(values);
053 // assertEquals(2, values.length);
054 // values = (String[]) req.getParameterMap().get("single_value");
055 // assertNotNull(values);
056 // assertEquals(1, values.length);
057 //
058 // EDocLiteForm form = new EDocLiteForm(req);
059 // values = (String[]) form.getParameterMap().get("multiple_value");
060 // assertNotNull(values);
061 // assertEquals(2, values.length);
062 // values = (String[]) form.getParameterMap().get("single_value");
063 // assertNotNull(values);
064 // assertEquals(1, values.length);
065 //
066 // req.addParameter("action", "testAction");
067 // form = new EDocLiteForm(req);
068 // assertEquals("testAction", form.getAction());
069 //
070 // req.addParameter("action", "testAction2");
071 // form = new EDocLiteForm(req);
072 // assertEquals("testAction", form.getAction());
073 }
074
075 /* this requires Jakarta Commons HttpClient to compile and
076 Commons Codec, IO, and Collections as well to run */
077 /*
078 public void testMultipleValuesMultipart() throws IOException {
079 Part[] parts = {
080 new StringPart("multiple_value", "value0"),
081 new StringPart("multiple_value", "value1"),
082 new StringPart("single_value", "value0")
083 };
084 MultipartRequestEntity mp = new MultipartRequestEntity(parts, new PostMethod().getParams());
085 ByteArrayOutputStream baos = new ByteArrayOutputStream();
086 mp.writeRequest(baos);
087
088 MockHttpServletRequest req = new MockHttpServletRequest();
089 req.setMethod("post");
090 req.setContentType(mp.getContentType());
091 req.setContent(baos.toByteArray());
092
093 EDocLiteForm form = new EDocLiteForm(req);
094 Object o = form.getParameterMap().get("multiple_value");
095 assertNotNull(o);
096 log.info(o.toString());
097 assertTrue("multiple_value parameter value is not a String[]: " + o.getClass(), o instanceof String[]);
098
099 String[] values = (String[]) o;
100 assertEquals(2, values.length);
101 o = form.getParameterMap().get("single_value");
102 assertNotNull(o);
103 assertTrue("single_value parameter value is not a String[]: " + o.getClass(), o instanceof String[]);
104 values = (String[]) o;
105 assertNotNull(values);
106 assertEquals(1, values.length);
107 assertEquals("testAction", form.getAction());
108 }*/
109 }