On 5/2/07, hughes.matt <[EMAIL PROTECTED]> wrote:
I started to write a patch for this and was writing a test case when I came across MockRequestMap. 1) Why do you need to mock a java.util.Map?
At the servlet API level, request attributes are accessed via a set of methods (getAttribute, setAttribute, getAttributeNames etc.) -- not too surprising, since servlets preceded the Java collections API. To make life simpler for developers, JSF requires an ExternalContext to model the request attributes as a Map so you can use familiar semantics. If you look inside a JSF implementation (the RI or MyFaces), you'll see similar sorts of code. So why do we need to mock one? It is to support unit tests that call ExternalContext.getRequestMap() and try to operate on it at test time. The MockExternalContext being used will use MockRequestMap to synthesize the return value. The same principle applies to MockSessionMap and MockApplicationMap.
2) Isn't this implementation of entrySet() incorrect: public Set entrySet() { Set set = new HashSet(); Enumeration keys = request.getAttributeNames(); while (keys.hasMoreElements()) { set.add(request.getAttribute((String) keys.nextElement())); } return set; } This is really returning a valueSet. I came across this during my testing as I kept getting a ClassCastException. I was expecting a Map.EntrySet as specified in the Map docs, but was getting the value object.
Ugh, you're right (and that is probably true on the other mock maps as well). Can you file a bug against those? Craig
hughes.matt wrote: > > As best as I can tell there is a bug in the ViewPhaseListener in > shale-view that is breaking other libraries, namely ajax4jsf by removing > ALL entries from the request map. I'd gladly fix this, but I can't tell > what the code should be doing. > > I have detailed the bug here: > https://issues.apache.org/struts/browse/SHALE-409#action_40918 > https://issues.apache.org/struts/browse/SHALE-409 > -- View this message in context: http://www.nabble.com/SHALE-409-Bug-tf3676627.html#a10287091 Sent from the Shale - Dev mailing list archive at Nabble.com.