View Javadoc

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