[jboss-cvs] jboss-seam/src/main/org/jboss/seam/mock ...
Peter Muir
peter at bleepbleep.org.uk
Sun Mar 11 11:30:38 EDT 2007
User: pmuir
Date: 07/03/11 11:30:37
Modified: src/main/org/jboss/seam/mock MockFacesContext.java
MockExternalContext.java
Log:
JBSEAM-996
Revision Changes Path
1.14 +41 -3 jboss-seam/src/main/org/jboss/seam/mock/MockFacesContext.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MockFacesContext.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockFacesContext.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- MockFacesContext.java 2 Mar 2007 15:05:08 -0000 1.13
+++ MockFacesContext.java 11 Mar 2007 15:30:37 -0000 1.14
@@ -4,12 +4,16 @@
*/
package org.jboss.seam.mock;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import javax.el.ELContext;
+import javax.el.ELResolver;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
@@ -26,11 +30,13 @@
/**
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
public class MockFacesContext extends FacesContext
{
+ private static final String JSF_12_ELCONTEXT = "com.sun.faces.el.ELContextImpl";
+
private UIViewRoot viewRoot;// = new UIViewRoot();
private Map<FacesMessage, String> messages = new HashMap<FacesMessage, String>();
@@ -41,13 +47,16 @@
private RenderKitFactory renderKitFactory;
+ private ELContext elContext;
+
public MockFacesContext(ExternalContext externalContext, Application application)
{
this.externalContext = externalContext;
this.application = application;
}
- // Create a MockFacesContext using a ApplicationFactory to get the Application
+ // Create a MockFacesContext using a ApplicationFactory to get the
+ // Application
public MockFacesContext(ExternalContext externalContext)
{
application = ((ApplicationFactory) FactoryFinder
@@ -212,4 +221,33 @@
return this;
}
+ /**
+ * @since 1.2
+ */
+ // This probably only works for the RI.
+ public ELContext getELContext()
+ {
+ if (elContext == null)
+ {
+ try
+ {
+ Class elContextClass = FacesContext.class.forName(JSF_12_ELCONTEXT);
+ Constructor<ELContext> constructor = elContextClass.getConstructor(ELResolver.class);
+ Method m = getApplication().getClass().getMethod("getELResolver", new Class[0]);
+ elContext = constructor.newInstance(m.invoke(getApplication(), new Object[0]));
+ elContext.putContext(FacesContext.class, this);
+ UIViewRoot root = this.getViewRoot();
+ if (null != root)
+ {
+ elContext.setLocale(root.getLocale());
+ }
+ }
+ catch (Exception e)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+ return elContext;
+ }
+
}
1.16 +504 -481 jboss-seam/src/main/org/jboss/seam/mock/MockExternalContext.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MockExternalContext.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockExternalContext.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- MockExternalContext.java 11 Feb 2007 19:10:25 -0000 1.15
+++ MockExternalContext.java 11 Mar 2007 15:30:37 -0000 1.16
@@ -1,9 +1,7 @@
/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
+ * * JBoss, Home of Professional Open Source * * Distributable under LGPL
+ * license. * See terms of license at gnu.org.
+ */
package org.jboss.seam.mock;
import java.io.IOException;
@@ -12,11 +10,13 @@
import java.net.URL;
import java.security.Principal;
import java.util.AbstractSet;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -34,26 +34,27 @@
/**
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
*/
public class MockExternalContext extends ExternalContext
{
private ServletContext context;
+
private HttpServletRequest request;
- private HttpServletResponse response;
+ private HttpServletResponse response;
public MockExternalContext()
{
this.context = new MockServletContext();
- this.request = new MockHttpServletRequest( new MockHttpSession(context) );
+ this.request = new MockHttpServletRequest(new MockHttpSession(context));
this.response = new MockHttpServletResponse();
}
public MockExternalContext(ServletContext context)
{
this.context = context;
- this.request = new MockHttpServletRequest( new MockHttpSession(context) );
+ this.request = new MockHttpServletRequest(new MockHttpSession(context));
this.response = new MockHttpServletResponse();
}
@@ -71,7 +72,8 @@
this.response = new MockHttpServletResponse();
}
- public MockExternalContext(ServletContext context, HttpServletRequest request, HttpServletResponse response)
+ public MockExternalContext(ServletContext context, HttpServletRequest request,
+ HttpServletResponse response)
{
this.context = context;
this.request = request;
@@ -112,11 +114,13 @@
{
return context.getAttributeNames();
}
+
@Override
public Object getAttribute(String key)
{
return context.getAttribute(key);
}
+
@Override
public void setAttribute(String key, Object value)
{
@@ -148,10 +152,10 @@
{
Map result = new HashMap();
Enumeration e = context.getInitParameterNames();
- while ( e.hasMoreElements() )
+ while (e.hasMoreElements())
{
String name = (String) e.nextElement();
- result.put( name, context.getInitParameter(name) );
+ result.put(name, context.getInitParameter(name));
}
return result;
}
@@ -178,7 +182,7 @@
public Map getRequestCookieMap()
{
Map<String, Cookie> cookieMap = new HashMap<String, Cookie>();
- for ( Cookie cookie : request.getCookies() )
+ for (Cookie cookie : request.getCookies())
{
cookieMap.put(cookie.getName(), cookie);
}
@@ -190,10 +194,10 @@
{
Map result = new HashMap();
Enumeration<String> names = request.getHeaderNames();
- while ( names.hasMoreElements() )
+ while (names.hasMoreElements())
{
String name = names.nextElement();
- result.put( name, request.getHeader(name) );
+ result.put(name, request.getHeader(name));
}
return result;
}
@@ -201,11 +205,18 @@
@Override
public Map getRequestHeaderValuesMap()
{
- Map<String, Enumeration> result = new HashMap<String, Enumeration>();
+ Map<String, String[]> result = new HashMap<String, String[]>();
Enumeration<String> en = request.getHeaderNames();
- while ( en.hasMoreElements() )
+ while (en.hasMoreElements())
{
- result.put( en.nextElement(), request.getHeaders( en.nextElement() ) );
+ String header = en.nextElement();
+ List<String> headerList = Collections.list(request.getHeaders(header));
+ String[] headers = new String[headerList.size()];
+ for (int i = 0; i < headerList.size(); i++)
+ {
+ headers[i] = headerList.get(i);
+ }
+ result.put(header, headers);
}
return result;
}
@@ -232,11 +243,13 @@
{
return request.getAttributeNames();
}
+
@Override
public Object getAttribute(String key)
{
return request.getAttribute(key);
}
+
@Override
public void setAttribute(String key, Object value)
{
@@ -250,10 +263,10 @@
{
Map map = new HashMap();
Enumeration<String> names = request.getParameterNames();
- while ( names.hasMoreElements() )
+ while (names.hasMoreElements())
{
String name = names.nextElement();
- map.put( name, request.getParameter(name) );
+ map.put(name, request.getParameter(name));
}
return map;
}
@@ -323,11 +336,13 @@
{
return session.getAttributeNames();
}
+
@Override
public Object getAttribute(String key)
{
return session.getAttribute(key);
}
+
@Override
public void setAttribute(String key, Object value)
{
@@ -343,13 +358,13 @@
public Object get(Object key)
{
- return getAttribute((String)key);
+ return getAttribute((String) key);
}
public Object put(Object key, Object value)
{
Object result = get(key);
- setAttribute((String)key, value);
+ setAttribute((String) key, value);
return result;
}
@@ -358,7 +373,7 @@
Enumeration e = keys();
while (e.hasMoreElements())
{
- remove( e.nextElement() );
+ remove(e.nextElement());
}
}
@@ -367,7 +382,7 @@
Enumeration e = keys();
while (e.hasMoreElements())
{
- if( key.equals( e.nextElement() ) ) return true;
+ if (key.equals(e.nextElement())) return true;
}
return false;
}
@@ -377,7 +392,7 @@
Enumeration e = keys();
while (e.hasMoreElements())
{
- if ( value.equals( get( e.nextElement() ) ) ) return true;
+ if (value.equals(get(e.nextElement()))) return true;
}
return false;
}
@@ -391,7 +406,7 @@
public boolean isEmpty()
{
- return size()==0;
+ return size() == 0;
}
public Set keySet()
@@ -402,7 +417,7 @@
@Override
public Iterator iterator()
{
- return new EnumerationIterator( keys() );
+ return new EnumerationIterator(keys());
}
@Override
@@ -418,9 +433,9 @@
public void putAll(Map t)
{
- for (Map.Entry me: (Set<Map.Entry>) t.entrySet())
+ for (Map.Entry me : (Set<Map.Entry>) t.entrySet())
{
- put( me.getKey(), me.getValue() );
+ put(me.getKey(), me.getValue());
}
}
@@ -431,7 +446,7 @@
public int size()
{
- int i=0;
+ int i = 0;
Enumeration e = keys();
while (e.hasMoreElements())
{
@@ -478,4 +493,12 @@
FacesContext.getCurrentInstance().responseComplete();
}
+ /**
+ * @since 1.2
+ */
+ public String getResponseContentType()
+ {
+ return response.getContentType();
+ }
+
}
More information about the jboss-cvs-commits
mailing list