You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2008/01/19 22:03:34 UTC
svn commit: r613451 - in
/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago:
mock/faces/MockExternalContext.java mock/servlet/MockServletContext.java
taglib/component/GenericComponentTagUnitTest.java
Author: bommel
Date: Sat Jan 19 13:03:33 2008
New Revision: 613451
URL: http://svn.apache.org/viewvc?rev=613451&view=rev
Log:
(TOBAGO-600) Simplify ResourceManagerImpl.CacheKey and ClientProperties handling in UIViewRoot and ViewHandlerImpl
Modified:
myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockExternalContext.java
myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/servlet/MockServletContext.java
myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java
Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockExternalContext.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockExternalContext.java?rev=613451&r1=613450&r2=613451&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockExternalContext.java (original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockExternalContext.java Sat Jan 19 13:03:33 2008
@@ -32,231 +32,247 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.Collections;
public class MockExternalContext extends ExternalContext {
- public MockExternalContext(ServletContext context,
- ServletRequest request,
- ServletResponse response) {
- this.context = context;
- this.request = request;
- this.response = response;
- }
+ public MockExternalContext(ServletContext context,
+ ServletRequest request,
+ ServletResponse response) {
+ this.context = context;
+ this.request = request;
+ this.response = response;
+ }
- private ServletContext context = null;
- private ServletRequest request = null;
- private ServletResponse response = null;
+ private ServletContext context = null;
+ private ServletRequest request = null;
+ private ServletResponse response = null;
- public Object getSession(boolean create) {
- throw new UnsupportedOperationException();
+ public Object getSession(boolean create) {
+ if (sessionMap == null && create) {
+ sessionMap = new MockSessionMap
+ (((HttpServletRequest) request).getSession(true));
}
+ return sessionMap;
+ }
- public Object getContext() {
- return (context);
- }
+ public Object getContext() {
+ return (context);
+ }
- public Object getRequest() {
- return (request);
- }
+ public Object getRequest() {
+ return (request);
+ }
- public Object getResponse() {
- return (response);
- }
-
+ public Object getResponse() {
+ return (response);
+ }
- private Map applicationMap = null;
- public Map getApplicationMap() {
- if (applicationMap == null) {
- applicationMap = new MockApplicationMap(context);
- }
- return (applicationMap);
- }
+ private Map applicationMap = null;
- private Map sessionMap = null;
- public Map getSessionMap() {
- if (sessionMap == null) {
- sessionMap = new MockSessionMap
- (((HttpServletRequest) request).getSession(true));
- }
- return (sessionMap);
+ public Map getApplicationMap() {
+ if (applicationMap == null) {
+ applicationMap = new MockApplicationMap(context);
}
+ return (applicationMap);
+ }
+
+ private Map sessionMap = null;
- private Map requestMap = null;
- public Map getRequestMap() {
- if (requestMap == null) {
- requestMap = new MockRequestMap(request);
- }
- return (requestMap);
+ public Map getSessionMap() {
+ if (sessionMap == null) {
+ sessionMap = new MockSessionMap
+ (((HttpServletRequest) request).getSession(true));
}
+ return (sessionMap);
+ }
- private Map requestParameterMap = null;
- public Map getRequestParameterMap() {
- if (requestParameterMap != null) {
- return (requestParameterMap);
- } else {
- throw new UnsupportedOperationException();
- }
- }
- public void setRequestParameterMap(Map requestParameterMap) {
- this.requestParameterMap = requestParameterMap;
+ private Map requestMap = null;
+
+ public Map getRequestMap() {
+ if (requestMap == null) {
+ requestMap = new MockRequestMap(request);
}
+ return (requestMap);
+ }
+
+ private Map requestParameterMap = null;
- public Map getRequestParameterValuesMap() {
- throw new UnsupportedOperationException();
+ public Map getRequestParameterMap() {
+ if (requestParameterMap != null) {
+ return (requestParameterMap);
+ } else {
+ return Collections.EMPTY_MAP;
}
+ }
+ public void setRequestParameterMap(Map requestParameterMap) {
+ this.requestParameterMap = requestParameterMap;
+ }
- public Iterator getRequestParameterNames() {
- throw new UnsupportedOperationException();
- }
+ public Map getRequestParameterValuesMap() {
+ return Collections.EMPTY_MAP;
+ }
- public Map getRequestHeaderMap() {
- throw new UnsupportedOperationException();
- }
+ public Iterator getRequestParameterNames() {
+ throw new UnsupportedOperationException();
+ }
- public Map getRequestHeaderValuesMap() {
- throw new UnsupportedOperationException();
- }
+ public Map getRequestHeaderMap() {
+ return Collections.EMPTY_MAP;
+ }
- public Map getRequestCookieMap() {
- throw new UnsupportedOperationException();
- }
+ public Map getRequestHeaderValuesMap() {
+ throw new UnsupportedOperationException();
+ }
- public Locale getRequestLocale() {
- return (request.getLocale());
- }
+ public Map getRequestCookieMap() {
+ throw new UnsupportedOperationException();
+ }
- public Iterator getRequestLocales() {
- return (new LocalesIterator(request.getLocales()));
- }
+ public Locale getRequestLocale() {
+ return (request.getLocale());
+ }
- public String getRequestPathInfo() {
- throw new UnsupportedOperationException();
- }
+ public Iterator getRequestLocales() {
+ return (new LocalesIterator(request.getLocales()));
+ }
- public String getRequestContextPath() {
- throw new UnsupportedOperationException();
- }
- public String getRequestServletPath() {
- throw new UnsupportedOperationException();
- }
+ public String getRequestPathInfo() {
+ throw new UnsupportedOperationException();
+ }
- public String getInitParameter(String name) {
- if (name.equals(javax.faces.application.StateManager.STATE_SAVING_METHOD_PARAM_NAME)) {
- return null;
- }
- throw new UnsupportedOperationException();
- }
+ public String getRequestContextPath() {
+ throw new UnsupportedOperationException();
+ }
+ public String getRequestServletPath() {
+ throw new UnsupportedOperationException();
+ }
- public Map getInitParameterMap() {
- throw new UnsupportedOperationException();
+
+ public String getInitParameter(String name) {
+ if (name.equals(javax.faces.application.StateManager.STATE_SAVING_METHOD_PARAM_NAME)) {
+ return null;
}
+ throw new UnsupportedOperationException();
+ }
- public Set getResourcePaths(String path) {
- throw new UnsupportedOperationException();
- }
+ public Map getInitParameterMap() {
+ throw new UnsupportedOperationException();
+ }
- public URL getResource(String path) throws MalformedURLException {
- throw new UnsupportedOperationException();
- }
+ public Set getResourcePaths(String path) {
+ throw new UnsupportedOperationException();
+ }
- public InputStream getResourceAsStream(String path) {
- throw new UnsupportedOperationException();
- }
+ public URL getResource(String path) throws MalformedURLException {
+ throw new UnsupportedOperationException();
+ }
- public String encodeActionURL(String sb) {
- throw new UnsupportedOperationException();
- }
+ public InputStream getResourceAsStream(String path) {
+ throw new UnsupportedOperationException();
+ }
- public String encodeResourceURL(String sb) {
- throw new UnsupportedOperationException();
- }
+ public String encodeActionURL(String sb) {
+ throw new UnsupportedOperationException();
+ }
- public String encodeNamespace(String aValue) {
- return aValue;
- }
+ public String encodeResourceURL(String sb) {
+ throw new UnsupportedOperationException();
+ }
- public void dispatch(String requestURI)
- throws IOException, FacesException {
- throw new UnsupportedOperationException();
- }
+ public String encodeNamespace(String aValue) {
+ return aValue;
+ }
- public void redirect(String requestURI)
- throws IOException {
- throw new UnsupportedOperationException();
- }
+ public void dispatch(String requestURI)
+ throws IOException, FacesException {
+ throw new UnsupportedOperationException();
+ }
- public void log(String message) {
- context.log(message);
- }
+ public void redirect(String requestURI)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
- public void log(String message, Throwable throwable) {
- context.log(message, throwable);
- }
+ public void log(String message) {
+ context.log(message);
+ }
- public String getAuthType() {
- return (((HttpServletRequest) request).getAuthType());
- }
+ public void log(String message, Throwable throwable) {
+ context.log(message, throwable);
+ }
- public String getRemoteUser() {
- return (((HttpServletRequest) request).getRemoteUser());
- }
- public java.security.Principal getUserPrincipal() {
- return (((HttpServletRequest) request).getUserPrincipal());
- }
+ public String getAuthType() {
+ return (((HttpServletRequest) request).getAuthType());
+ }
- public boolean isUserInRole(String role) {
- return (((HttpServletRequest) request).isUserInRole(role));
- }
+ public String getRemoteUser() {
+ return (((HttpServletRequest) request).getRemoteUser());
+ }
+ public java.security.Principal getUserPrincipal() {
+ return (((HttpServletRequest) request).getUserPrincipal());
+ }
- private class LocalesIterator implements Iterator {
+ public boolean isUserInRole(String role) {
+ return (((HttpServletRequest) request).isUserInRole(role));
+ }
- public LocalesIterator(Enumeration locales) {
- this.locales = locales;
- }
- private Enumeration locales;
+ private class LocalesIterator implements Iterator {
- public boolean hasNext() { return locales.hasMoreElements(); }
+ public LocalesIterator(Enumeration locales) {
+ this.locales = locales;
+ }
- public Object next() { return locales.nextElement(); }
+ private Enumeration locales;
- public void remove() { throw new UnsupportedOperationException(); }
+ public boolean hasNext() {
+ return locales.hasMoreElements();
+ }
+ public Object next() {
+ return locales.nextElement();
}
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
}
Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/servlet/MockServletContext.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/servlet/MockServletContext.java?rev=613451&r1=613450&r2=613451&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/servlet/MockServletContext.java (original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/servlet/MockServletContext.java Sat Jan 19 13:03:33 2008
@@ -26,15 +26,18 @@
import java.net.URL;
import java.util.Enumeration;
import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
public class MockServletContext implements ServletContext {
+ private Map attributes = new HashMap();
public Set getResourcePaths(String reference) {
return null;
}
public Object getAttribute(String s) {
- return null;
+ return attributes.get(s);
}
public Enumeration getAttributeNames() {
@@ -122,5 +125,6 @@
}
public void setAttribute(String s, Object o) {
+ attributes.put(s, o);
}
}
Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java?rev=613451&r1=613450&r2=613451&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java (original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java Sat Jan 19 13:03:33 2008
@@ -30,6 +30,9 @@
import org.apache.myfaces.tobago.mock.servlet.MockHttpServletResponse;
import org.apache.myfaces.tobago.mock.servlet.MockPageContext;
import org.apache.myfaces.tobago.mock.servlet.MockServletContext;
+import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.apache.myfaces.tobago.context.Theme;
+import org.apache.myfaces.tobago.context.RenderersConfig;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
@@ -50,6 +53,10 @@
import javax.servlet.jsp.tagext.Tag;
import java.util.Iterator;
import java.util.Map;
+import java.util.List;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Collections;
import net.sf.maventaglib.checker.Tld;
@@ -72,7 +79,16 @@
tldPaths[0] = "META-INF/org/apache/myfaces/tobago/taglib/component/tobago.tld";
super.setUp();
- ServletContext servletContext = new MockServletContext();
+ MockServletContext servletContext = new MockServletContext();
+ TobagoConfig tobagoConfig = new TobagoConfig();
+ Theme theme = new MockTheme("default", Collections.EMPTY_LIST);
+ Theme theme1 = new MockTheme("one", Arrays.asList(theme));
+ Map<String, Theme> availableThemes = new HashMap<String, Theme>();
+ availableThemes.put(theme.getName(), theme);
+ availableThemes.put(theme1.getName(), theme1);
+ tobagoConfig.setAvailableThemes(availableThemes);
+ tobagoConfig.resolveThemes();
+ servletContext.setAttribute(TobagoConfig.TOBAGO_CONFIG, tobagoConfig);
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
pageContext = new MockPageContext(request);
@@ -156,6 +172,35 @@
assertTrue(ComponentUtil.getBooleanAttribute(command, ATTR_DISABLED));
assertFalse(ComponentUtil.getBooleanAttribute(command, ATTR_HEIGHT));
+ }
+ }
+ private static class MockTheme implements Theme {
+ private String name;
+ private List<Theme> fallbackThemeList;
+
+ private MockTheme(String name, List<Theme> fallbackThemeList) {
+ this.name = name;
+ this.fallbackThemeList = fallbackThemeList;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<Theme> getFallbackList() {
+ return fallbackThemeList;
+ }
+
+ public String getDisplayName() {
+ return "";
+ }
+
+ public String getResourcePath() {
+ return null;
+ }
+
+ public RenderersConfig getRenderersConfig() {
+ return null;
}
}
}