1 15 package org.apache.tapestry.multipart; 16 17 import java.util.Enumeration ; 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import javax.servlet.http.HttpServletRequest ; 22 23 import org.apache.hivemind.test.HiveMindTestCase; 24 25 31 public class TestUploadFormParametersWrapper extends HiveMindTestCase 32 { 33 private HttpServletRequest newRequest() 34 { 35 return (HttpServletRequest ) newMock(HttpServletRequest .class); 36 } 37 38 public void testMapIsNotModifiable() 39 { 40 HttpServletRequest request = newRequest(); 41 42 replayControls(); 43 44 Map map = new HashMap (); 45 46 map.put("key", new String [] 47 { "value" }); 48 49 HttpServletRequest r = new UploadFormParametersWrapper(request, map); 50 51 Map pmap = r.getParameterMap(); 52 53 assertNotSame(map, pmap); 54 55 assertSame(map.get("key"), pmap.get("key")); 56 57 try 58 { 59 pmap.put("foo", "bar"); 60 unreachable(); 61 } 62 catch (UnsupportedOperationException ex) 63 { 64 } 66 67 verifyControls(); 68 } 69 70 public void testGetSingleParameterWhenNull() 71 { 72 HttpServletRequest request = newRequest(); 73 74 replayControls(); 75 76 HttpServletRequest r = new UploadFormParametersWrapper(request, new HashMap ()); 77 78 assertNull(r.getParameter("unknown-key")); 79 80 verifyControls(); 81 } 82 83 public void testGetSingleParameterWhenEmptyArray() 84 { 85 HttpServletRequest request = newRequest(); 86 87 replayControls(); 88 89 HashMap params = new HashMap (); 90 91 params.put("empty-key", new String [0]); 92 93 HttpServletRequest r = new UploadFormParametersWrapper(request, params); 94 95 assertNull(r.getParameter("empty-key")); 96 97 verifyControls(); 98 } 99 100 public void testGetParameterValues() 101 { 102 String [] values = 103 { "fred", "barney" }; 104 105 HttpServletRequest request = newRequest(); 106 107 replayControls(); 108 109 HashMap params = new HashMap (); 110 111 params.put("key", values); 112 113 HttpServletRequest r = new UploadFormParametersWrapper(request, params); 114 115 assertSame(values, r.getParameterValues("key")); 116 117 verifyControls(); 118 } 119 120 public void testGetParameterNames() 121 { 122 HttpServletRequest request = newRequest(); 123 124 replayControls(); 125 126 HashMap params = new HashMap (); 127 128 params.put("key", new String [0]); 129 130 HttpServletRequest r = new UploadFormParametersWrapper(request, params); 131 132 Enumeration e = r.getParameterNames(); 133 134 assertEquals(true, e.hasMoreElements()); 135 assertEquals("key", e.nextElement()); 136 assertEquals(false, e.hasMoreElements()); 137 138 verifyControls(); 139 } 140 } | Popular Tags |