[richfaces-svn-commits] JBoss Rich Faces SVN: r15964 - in branches/community/3.3.X/framework/test: src/main/java/org/ajax4jsf/tests and 2 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Sun Nov 22 20:42:32 EST 2009


Author: nbelaevski
Date: 2009-11-22 20:42:31 -0500 (Sun, 22 Nov 2009)
New Revision: 15964

Added:
   branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockResourceHandler.java
   branches/community/3.3.X/framework/test/src/main/resources/META-INF/resources-config.xml
Modified:
   branches/community/3.3.X/framework/test/pom.xml
   branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/Ajax4JsfMockApplicationFactory.java
   branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockExternalContext.java
   branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/config/ConfigParser.java
Log:
Framework: merged from 3.3.x_jsf2 branch

Modified: branches/community/3.3.X/framework/test/pom.xml
===================================================================
--- branches/community/3.3.X/framework/test/pom.xml	2009-11-22 18:29:15 UTC (rev 15963)
+++ branches/community/3.3.X/framework/test/pom.xml	2009-11-23 01:42:31 UTC (rev 15964)
@@ -12,7 +12,36 @@
 	<name>Ajax4Jsf test framework</name>
 	<url>https://ajax4jsf.dev.java.net</url>
 	
+	<profiles>
+			<profile>
+			<id>jsf2_0</id>
+			<dependencies>
+				<dependency>
+					<groupId>org.richfaces.framework</groupId>
+					<artifactId>richfaces-impl</artifactId>
+					<version>${project.version}</version>
+					<scope>provided</scope>
+					<classifier>jsf2</classifier>
+				</dependency>
+			</dependencies>
+		</profile>
+		<profile>
+			<id>jsf1_2</id>
+			<dependencies>
+				<dependency>
+					<groupId>org.richfaces.framework</groupId>
+					<artifactId>richfaces-impl</artifactId>
+					<version>${project.version}</version>
+					<scope>provided</scope>
+				</dependency>
+			</dependencies>
+			<activation>
+				<activeByDefault>true</activeByDefault>
+			</activation>
+		</profile>
+	</profiles>
 	
+	
 	<dependencies>
 		<dependency>
 			<groupId>com.sun.faces</groupId>
@@ -53,11 +82,6 @@
 			</exclusions>
 		</dependency>
 		<dependency>
-			<groupId>org.richfaces.framework</groupId>
-			<artifactId>richfaces-impl</artifactId>
-			<version>3.3.3-SNAPSHOT</version>
-		</dependency>
-		<dependency>
 			<groupId>net.sourceforge.htmlunit</groupId>
 			<artifactId>htmlunit</artifactId>
 			<version>1.14</version>

Modified: branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/Ajax4JsfMockApplicationFactory.java
===================================================================
--- branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/Ajax4JsfMockApplicationFactory.java	2009-11-22 18:29:15 UTC (rev 15963)
+++ branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/Ajax4JsfMockApplicationFactory.java	2009-11-23 01:42:31 UTC (rev 15964)
@@ -49,6 +49,7 @@
 			clazz.getDeclaredFields();
 			
 			application = (MockApplication) clazz.newInstance();
+			application.setResourceHandler(new MockResourceHandler());
 
 			return application;
 		} catch (NoClassDefFoundError e) {

Modified: branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockExternalContext.java
===================================================================
--- branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockExternalContext.java	2009-11-22 18:29:15 UTC (rev 15963)
+++ branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockExternalContext.java	2009-11-23 01:42:31 UTC (rev 15964)
@@ -22,20 +22,25 @@
 package org.ajax4jsf.tests;
 
 import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 
 import javax.faces.FacesException;
 import javax.servlet.ServletContext;
+import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
 
 import org.apache.commons.collections.EnumerationUtils;
 import org.apache.shale.test.mock.MockExternalContext12;
@@ -153,4 +158,165 @@
 		}
 	 };
 	 
+	 //JSF 2.0 methods 
+	 
+//	 public javax.faces.context.Flash getFlash() {
+//		 
+//	 };
+	 
+	 public void addResponseCookie(String name, String value, java.util.Map<String,Object> properties) {
+		 Cookie cookie = new Cookie(name, value);
+		 if (properties != null) {
+			 String comment = (String) properties.get("comment");
+			 if (comment != null) {
+				 cookie.setComment(comment);
+			 }
+			 String domain = (String) properties.get("domain");
+			 if (domain != null) {
+				 cookie.setDomain(domain);
+			 }
+			 String path = (String) properties.get("path");
+			 if (path != null) {
+				 cookie.setPath(path);
+			 }
+			 Integer maxAge = (Integer) properties.get("maxAge");
+			 if (maxAge != null) {
+				 cookie.setMaxAge(maxAge);
+			 }
+			 Boolean secure = (Boolean) properties.get("secure");
+			 if (secure != null) {
+				 cookie.setSecure(secure);
+			 }
+		 }
+		 
+		 ((HttpServletResponse) getResponse()).addCookie(cookie);
+	 };
+	 
+	 public String encodePartialActionURL(String url) {
+		 return encodeActionURL(url);
+	 };
+
+	 public String getMimeType(String file) {
+		 return "text/html";
+	 }
+	 
+	public String getContextName() {
+		return ((ServletContext) this.getContext()).getServletContextName();
+	}
+	
+	public String getRequestScheme() {
+		return ((HttpServletRequest) this.getRequest()).getScheme();
+	}
+	
+	public String getRequestServerName() {
+		return ((HttpServletRequest) this.getRequest()).getServerName();
+	}
+	
+	public int getRequestServerPort() {
+		return ((HttpServletRequest) this.getRequest()).getServerPort();
+	}
+	
+	public String getRealPath(String path) {
+		return ((ServletContext) this.getContext()).getRealPath(path);
+	}
+
+	public int getRequestContentLength() {
+		return ((HttpServletRequest) this.getRequest()).getContentLength();
+	}
+	
+	public OutputStream getResponseOutputStream() throws IOException {
+		return ((HttpServletResponse) this.getResponse()).getOutputStream();
+	}
+	
+	public Writer getResponseOutputWriter() throws IOException {
+		return ((HttpServletResponse) this.getResponse()).getWriter();
+	}
+	
+	public void setResponseContentType(String contentType) {
+		((HttpServletResponse) this.getResponse()).setContentType(contentType);
+	}
+	
+	public void invalidateSession() {
+		Object session = getSession(false);
+		if (session != null) {
+			((HttpSession) session).invalidate();
+		}
+	}
+
+	public void setResponseHeader(String name, String value) {
+		((HttpServletResponse) this.getResponse()).setHeader(name, value);
+	}
+	
+	public void addResponseHeader(String name, String value) {
+		((HttpServletResponse) this.getResponse()).addHeader(name, value);
+	}
+	
+	public void setResponseBufferSize(int size) {
+		((HttpServletResponse) this.getResponse()).setBufferSize(size);
+	}
+	
+	public int getResponseBufferSize() {
+		return ((HttpServletResponse) this.getResponse()).getBufferSize();
+	}
+	
+	public boolean isResponseCommitted() {
+		return ((HttpServletResponse) this.getResponse()).isCommitted();
+	}
+	
+	public void responseReset() {
+		((HttpServletResponse) this.getResponse()).reset();
+	}
+	
+	public void responseSendError(int statusCode, String message)
+			throws IOException {
+		((HttpServletResponse) this.getResponse()).sendError(statusCode, message);
+	}
+	
+	public void setResponseStatus(int statusCode) {
+		((HttpServletResponse) this.getResponse()).setStatus(statusCode);
+	}
+	
+	public void responseFlushBuffer() throws IOException {
+		((HttpServletResponse) this.getResponse()).flushBuffer();
+	}
+	
+	public void setResponseContentLength(int length) {
+		((HttpServletResponse) this.getResponse()).setContentLength(length);
+	}
+	
+	private String encodeUrl(String baseUrl,
+			Map<String, List<String>> parameters) {
+		
+		StringBuilder sb = new StringBuilder(baseUrl);
+		sb.append('?');
+		
+		if (parameters != null) {
+			for (Map.Entry<String, List<String>> entry: parameters.entrySet()) {
+				List<String> values = entry.getValue();
+				if (values != null) {
+					String name = entry.getKey();
+					for (String value: values) {
+						sb.append(name);
+						sb.append('=');
+						sb.append(value);
+						sb.append('&');
+					}
+				}
+			}
+		}
+		
+		return sb.toString();
+	}
+	
+	public String encodeBookmarkableURL(String baseUrl,
+			Map<String, List<String>> parameters) {
+		
+		return encodeUrl(baseUrl, parameters);
+	}
+	
+	public String encodeRedirectURL(String baseUrl,
+			Map<String, List<String>> parameters) {
+
+		return encodeUrl(baseUrl, parameters);
+	}
 }

Added: branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockResourceHandler.java
===================================================================
--- branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockResourceHandler.java	                        (rev 0)
+++ branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockResourceHandler.java	2009-11-23 01:42:31 UTC (rev 15964)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */ 
+
+package org.ajax4jsf.tests;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.resource.FacesResourceContext;
+import org.ajax4jsf.resource.InternetResource;
+import org.ajax4jsf.resource.InternetResourceBuilder;
+import org.ajax4jsf.resource.ResourceNotFoundException;
+
+public class MockResourceHandler extends ResourceHandler {
+
+	@Override
+	public Resource createResource(String resourceName) {
+		return createResource(resourceName, null);
+	}
+
+	@Override
+	public Resource createResource(String resourceName, String libraryName) {
+		return createResource(resourceName, libraryName, null);
+	}
+
+	@Override
+	public Resource createResource(String resourceName, String libraryName,
+			String contentType) {
+
+		StringBuilder path = new StringBuilder();
+		if (libraryName != null) {
+			path.append(libraryName);
+		}
+		
+		if (libraryName.length() > 0) {
+			path.append('/');
+		}
+		
+		path.append(resourceName);
+		
+		InternetResourceBuilder resourceBuilder = InternetResourceBuilder.getInstance();
+		try {
+			final InternetResource resource = resourceBuilder.getResource(path.toString());
+			return new Resource() {
+				
+				@Override
+				public boolean userAgentNeedsUpdate(FacesContext context) {
+					return true;
+				}
+				
+				@Override
+				public URL getURL() {
+					throw new UnsupportedOperationException();
+				}
+				
+				@Override
+				public Map<String, String> getResponseHeaders() {
+					return new HashMap<String, String>();
+				}
+				
+				@Override
+				public String getRequestPath() {
+					return resource.getUri(FacesContext.getCurrentInstance(), null);
+				}
+				
+				@Override
+				public InputStream getInputStream() throws IOException {
+					FacesContext facesContext = FacesContext.getCurrentInstance();
+					return resource.getResourceAsStream(new FacesResourceContext(facesContext));
+				}
+			};
+		} catch (ResourceNotFoundException e) {
+			//ignore
+		}
+		
+		return null;
+	}
+
+	@Override
+	public String getRendererTypeForResourceName(String resourceName) {
+		if (resourceName.endsWith(".js")) {
+			return "javax.faces.resource.Script";
+		}
+		
+		if (resourceName.endsWith(".css")) {
+			return "javax.faces.resource.Stylesheet";
+		}
+		
+		return null;
+	}
+
+	@Override
+	public void handleResourceRequest(FacesContext context) throws IOException {
+		throw new IllegalStateException();
+	}
+
+	@Override
+	public boolean isResourceRequest(FacesContext context) {
+		return false;
+	}
+
+	@Override
+	public boolean libraryExists(String libraryName) {
+		return true;
+	}
+
+}

Modified: branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/config/ConfigParser.java
===================================================================
--- branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/config/ConfigParser.java	2009-11-22 18:29:15 UTC (rev 15963)
+++ branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/org/apache/shale/test/config/ConfigParser.java	2009-11-23 01:42:31 UTC (rev 15964)
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.net.URL;
+
 import javax.faces.FactoryFinder;
 import javax.faces.application.Application;
 import javax.faces.application.ApplicationFactory;
@@ -210,6 +211,16 @@
               ("faces-config/validator/validator-id", "setValidatorId", 0);
             digester.addCallMethod
               ("faces-config/validator/validator-class", "setValidatorClass", 0);
+            
+            digester.addRule("faces-config/factory/visit-context-factory", new Rule() {
+            	@Override
+            	public void body(String namespace, String name, String text)
+            			throws Exception {
+            		if (text != null && text.trim().length() != 0) {
+                		FactoryFinder.setFactory("javax.faces.component.visit.VisitContextFactory", text.trim());
+            		}
+            	}
+            });
         }
         
         digester.setEntityResolver(new FacesEntityResolver());

Added: branches/community/3.3.X/framework/test/src/main/resources/META-INF/resources-config.xml
===================================================================
--- branches/community/3.3.X/framework/test/src/main/resources/META-INF/resources-config.xml	                        (rev 0)
+++ branches/community/3.3.X/framework/test/src/main/resources/META-INF/resources-config.xml	2009-11-23 01:42:31 UTC (rev 15964)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resource-config>
+	<resource>
+		<name>javax.faces/jsf.js</name>
+		<path>META-INF/resources/javax.faces/jsf.js</path>
+		<renderer class="org.ajax4jsf.resource.ScriptRenderer"/>
+	</resource>
+</resource-config>



More information about the richfaces-svn-commits mailing list