View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.kuali.rice.edl.impl;
19  
20  /*import java.io.ByteArrayOutputStream;
21  import java.io.IOException;
22  
23  import org.apache.commons.httpclient.methods.PostMethod;
24  import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
25  import org.apache.commons.httpclient.methods.multipart.Part;
26  import org.apache.commons.httpclient.methods.multipart.StringPart;*/
27  import org.junit.Ignore;
28  import org.junit.Test;
29  import org.kuali.rice.test.BaseRiceTestCase;
30  
31  /**
32   * Tests the behavior of EDocLiteForm in the presence of various types of input
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class EDocLiteFormTest extends BaseRiceTestCase {
36      /**
37       * Tests how EDocLiteForm handles parameters with multiple values
38       */
39  	@Ignore("This test needs to be implemented!")
40  	@Test public void testMultipleValuesPlainPOST() throws Exception {
41  //        MockHttpServletRequest req = new MockHttpServletRequest();
42  //        req.setMethod("post");
43  //        req.addParameter("multiple_value", "value0");
44  //        req.addParameter("multiple_value", "value1");
45  //        req.addParameter("single_value", "value0");
46  //        String[] values = req.getParameterValuesAsString("multiple_value");
47  //        assertNotNull(values);
48  //        assertEquals(2, values.length);
49  //        values = req.getParameterValuesAsString("single_value");
50  //        assertNotNull(values);
51  //        assertEquals(1, values.length);
52  //
53  //        values = (String[]) req.getParameterMap().get("multiple_value");
54  //        assertNotNull(values);
55  //        assertEquals(2, values.length);
56  //        values = (String[]) req.getParameterMap().get("single_value");
57  //        assertNotNull(values);
58  //        assertEquals(1, values.length);
59  //
60  //        EDocLiteForm form = new EDocLiteForm(req);
61  //        values = (String[]) form.getParameterMap().get("multiple_value");
62  //        assertNotNull(values);
63  //        assertEquals(2, values.length);
64  //        values = (String[]) form.getParameterMap().get("single_value");
65  //        assertNotNull(values);
66  //        assertEquals(1, values.length);
67  //
68  //        req.addParameter("action", "testAction");
69  //        form = new EDocLiteForm(req);
70  //        assertEquals("testAction", form.getAction());
71  //
72  //        req.addParameter("action", "testAction2");
73  //        form = new EDocLiteForm(req);
74  //        assertEquals("testAction", form.getAction());
75      }
76  
77      /* this requires Jakarta Commons HttpClient to compile and
78         Commons Codec, IO, and Collections as well to run */
79      /*
80      public void testMultipleValuesMultipart() throws IOException {
81          Part[] parts = {
82              new StringPart("multiple_value", "value0"),
83              new StringPart("multiple_value", "value1"),
84              new StringPart("single_value", "value0")
85          };
86          MultipartRequestEntity mp = new MultipartRequestEntity(parts, new PostMethod().getParams());
87          ByteArrayOutputStream baos = new ByteArrayOutputStream();
88          mp.writeRequest(baos);
89  
90          MockHttpServletRequest req = new MockHttpServletRequest();
91          req.setMethod("post");
92          req.setContentType(mp.getContentType());
93          req.setContent(baos.toByteArray());
94  
95          EDocLiteForm form = new EDocLiteForm(req);
96          Object o = form.getParameterMap().get("multiple_value");
97          assertNotNull(o);
98          log.info(o.toString());
99          assertTrue("multiple_value parameter value is not a String[]: " + o.getClass(), o instanceof String[]);
100 
101         String[] values = (String[]) o;
102         assertEquals(2, values.length);
103         o = form.getParameterMap().get("single_value");
104         assertNotNull(o);
105         assertTrue("single_value parameter value is not a String[]: " + o.getClass(), o instanceof String[]);
106         values = (String[]) o;
107         assertNotNull(values);
108         assertEquals(1, values.length);
109         assertEquals("testAction", form.getAction());
110     }*/
111 }