Author: alexsmirnov
Date: 2009-02-26 20:46:12 -0500 (Thu, 26 Feb 2009)
New Revision: 12764
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingInitialContextFactoryBuilder.java
Modified:
branches/jsf2.0/framework/jsf-test/pom.xml
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/staging/ServerResourcePathTest.java
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/staging/UrlResourceLoadingTest.java
branches/jsf2.0/framework/pom.xml
branches/jsf2.0/tests/ajax/pom.xml
branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/UIDataTest.java
Log:
Fixed bug in the stagging test web application context pathnames.
Modified: branches/jsf2.0/framework/jsf-test/pom.xml
===================================================================
--- branches/jsf2.0/framework/jsf-test/pom.xml 2009-02-26 23:55:44 UTC (rev 12763)
+++ branches/jsf2.0/framework/jsf-test/pom.xml 2009-02-27 01:46:12 UTC (rev 12764)
@@ -23,7 +23,7 @@
<version>2.4</version>
</dependency>
<dependency>
- <groupId>javax.faces</groupId>
+ <groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java 2009-02-26
23:55:44 UTC (rev 12763)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java 2009-02-27
01:46:12 UTC (rev 12764)
@@ -3,11 +3,13 @@
*/
package org.richfaces.test;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.EventListener;
import java.util.Locale;
+import java.util.Properties;
import java.util.logging.LogManager;
import javax.faces.FactoryFinder;
@@ -214,9 +216,31 @@
/**
* This template method called from the {@link #setUp()} to populate virtual server
content.
- * The default implementation do nothing.
+ * The default implementation tries to load web content from directory pointed by the
System property
+ * "webroot" or same property from the "/webapp.properties" file.
*/
protected void setupWebContent() {
+ String webappDirectory = System.getProperty("webroot");
+ File webFile = null;
+ if (null == webappDirectory) {
+ URL resource =
this.getClass().getResource("/webapp.properties");
+ if (null != resource &&
"file".equals(resource.getProtocol())) {
+ Properties webProperties = new Properties();
+ try {
+ InputStream inputStream = resource.openStream();
+ webProperties.load(inputStream);
+ inputStream.close();
+ webFile = new File(resource.getPath());
+ webFile = new File(webFile.getParentFile(),
webProperties.getProperty("webroot")).getAbsoluteFile();
+ facesServer.addResourcesFromDirectory("/", webFile);
+ } catch (IOException e) {
+ throw new TestException(e);
+ }
+ }
+ } else {
+ webFile = new File(webappDirectory);
+ facesServer.addResourcesFromDirectory("/", webFile);
+ }
}
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java 2009-02-26
23:55:44 UTC (rev 12763)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java 2009-02-27
01:46:12 UTC (rev 12764)
@@ -16,9 +16,9 @@
private static final Pattern SLASH = Pattern.compile("/");
- public static final ServerResourcePath WEB_INF=new
ServerResourcePath("/WEB-INF");
+ public static final ServerResourcePath WEB_INF=new
ServerResourcePath("/WEB-INF/");
- public static final ServerResourcePath META_INF=new
ServerResourcePath("/META-INF");
+ public static final ServerResourcePath META_INF=new
ServerResourcePath("/META-INF/");
public static final ServerResourcePath WEB_XML=new
ServerResourcePath("/WEB-INF/web.xml");
public static final ServerResourcePath FACES_CONFIG=new
ServerResourcePath("/WEB-INF/faces-config.xml");
@@ -45,7 +45,13 @@
if (!path.startsWith("/")) {
throw new IllegalArgumentException();
}
- pathElements = SLASH.split(path);
+ String[] split = SLASH.split(path);
+ if(split.length >1 && path.endsWith("/")){
+ pathElements = new String[split.length+1];
+ System.arraycopy(split, 0, pathElements, 0, split.length);
+ } else {
+ pathElements = split;
+ }
}
/**
@@ -53,17 +59,21 @@
* @return true for a last element in the path.
*/
public boolean isFile() {
- return pathElements.length <= 1;
+ return pathElements.length <= 1 || null == pathElements[1];
}
/**
* Name of the next element ( directory or file ) name.
- * For the "/foo/bar/baz" it should be "foo" , /bar/baz :
"bar" , "/" : null.
+ * For the "/foo/bar/baz" it should be "foo/" , /bar/baz :
"bar/" , "/" : null.
* @return name of the next element or null if it is last element in the chain ( file
).
*/
public String getNextElementName() {
if (pathElements.length > 1) {
- return pathElements[1];
+ String name = pathElements[1];
+ if(pathElements.length>2){
+ name+='/';
+ }
+ return name;
} else {
return null;
}
@@ -75,7 +85,7 @@
* @return next subdirectory path or null.
*/
public ServerResourcePath getNextPath() {
- if (pathElements.length > 1) {
+ if (pathElements.length > 1 && null != pathElements[1]) {
String[] nextElenemts = new String[pathElements.length - 1];
System.arraycopy(pathElements, 1, nextElenemts, 0, nextElenemts.length);
return new ServerResourcePath(nextElenemts);
@@ -90,7 +100,10 @@
if (pathElements.length > 1) {
for (int i = 1; i < pathElements.length; i++) {
String element = pathElements[i];
- str.append("/").append(element);
+ str.append("/");
+ if(null != element){
+ str.append(element);
+ }
}
} else {
str.append("/");
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingInitialContextFactoryBuilder.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingInitialContextFactoryBuilder.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingInitialContextFactoryBuilder.java 2009-02-27
01:46:12 UTC (rev 12764)
@@ -0,0 +1,249 @@
+/*
+ * $Id$
+ */
+
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License").
You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at
https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package org.richfaces.test.staging;
+
+import java.util.Hashtable;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+
+/**
+ * <p class="changed_added_2_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class StagingInitialContextFactoryBuilder implements
+ InitialContextFactoryBuilder {
+
+ private static final class StagingInitialContext implements Context {
+ public Object addToEnvironment(String propName,
+ Object propVal) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void bind(Name name, Object obj)
+ throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void bind(String name, Object obj)
+ throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void close() throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Name composeName(Name name, Name prefix)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String composeName(String name, String prefix)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Context createSubcontext(Name name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Context createSubcontext(String name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void destroySubcontext(Name name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void destroySubcontext(String name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Hashtable<?, ?> getEnvironment()
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getNameInNamespace() throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NameParser getNameParser(Name name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NameParser getNameParser(String name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NamingEnumeration<NameClassPair> list(Name name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NamingEnumeration<NameClassPair> list(String name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NamingEnumeration<Binding> listBindings(Name name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NamingEnumeration<Binding> listBindings(String name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object lookup(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object lookup(String name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object lookupLink(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object lookupLink(String name)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void rebind(Name name, Object obj)
+ throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void rebind(String name, Object obj)
+ throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Object removeFromEnvironment(String propName)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void rename(Name oldName, Name newName)
+ throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void rename(String oldName, String newName)
+ throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unbind(Name name) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unbind(String name) throws NamingException {
+ // TODO Auto-generated method stub
+
+ }
+ }
+
+ public static final class StagingInitialContextFactory implements
+ InitialContextFactory {
+ public Context getInitialContext(Hashtable<?, ?> environment)
+ throws NamingException {
+ // TODO Auto-generated method stub
+ return new StagingInitialContext();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.naming.spi.InitialContextFactoryBuilder#createInitialContextFactory(java.util.Hashtable)
+ */
+ public InitialContextFactory createInitialContextFactory(
+ Hashtable<?, ?> environment) throws NamingException {
+ return new StagingInitialContextFactory();
+ }
+
+}
Property changes on:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingInitialContextFactoryBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2009-02-26
23:55:44 UTC (rev 12763)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2009-02-27
01:46:12 UTC (rev 12764)
@@ -20,6 +20,8 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import javax.naming.NamingException;
+import javax.naming.spi.NamingManager;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
@@ -450,6 +452,9 @@
if (!directory.isDirectory()) {
directory = directory.getParentFile();
}
+ if(!directory.exists()){
+ throw new TestException("directory does not
exist:"+directory.getAbsolutePath());
+ }
try {
addFiles(baseDirectory, directory);
} catch (MalformedURLException e) {
@@ -531,13 +536,15 @@
throws MalformedURLException {
File[] files = file.listFiles();
for (File subfile : files) {
- ServerResourcePath serverResourcePath = new ServerResourcePath("/"
- + subfile.getName());
if (subfile.isDirectory()) {
+ ServerResourcePath serverResourcePath = new ServerResourcePath("/"
+ + subfile.getName()+"/");
ServerResourcesDirectory subDir = new ServerResourcesDirectory();
baseDirectory.addResource(serverResourcePath, subDir);
addFiles(subDir, subfile);
} else {
+ ServerResourcePath serverResourcePath = new ServerResourcePath("/"
+ + subfile.getName());
UrlServerResource resource = new UrlServerResource(subfile
.toURL());
baseDirectory.addResource(serverResourcePath, resource);
@@ -749,6 +756,13 @@
} catch (ServletException e) {
throw new TestException("Servlet initialisation error ", e);
}
+ try {
+ NamingManager.setInitialContextFactoryBuilder(new
StagingInitialContextFactoryBuilder());
+ } catch (NamingException e) {
+ log.warning("Error set initial context factory builder.");
+ } catch (IllegalStateException e) {
+ log.warning("Initial context factory builder already set.");
+ }
this.initialised = true;
}
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java 2009-02-26
23:55:44 UTC (rev 12763)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java 2009-02-27
01:46:12 UTC (rev 12764)
@@ -10,6 +10,7 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -175,11 +176,18 @@
*/
@SuppressWarnings("unchecked")
public Set getResourcePaths(String path) {
+ HashSet result=null;
ServerResource resource = getServerResource(path);
if(null != resource){
- return resource.getPaths();
+ Set<String> paths = resource.getPaths();
+ if(null != paths && paths.size()>0){
+ result = new HashSet(paths.size());
+ for (String resourcePath : paths) {
+ result.add(path+resourcePath);
+ }
+ }
}
- return null;
+ return result;
}
/* (non-Javadoc)
Modified:
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/staging/ServerResourcePathTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/staging/ServerResourcePathTest.java 2009-02-26
23:55:44 UTC (rev 12763)
+++
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/staging/ServerResourcePathTest.java 2009-02-27
01:46:12 UTC (rev 12764)
@@ -35,8 +35,8 @@
assertNotNull(path.getNextPath());
assertNotNull(path.getNextElementName());
assertFalse(path.isFile());
- assertEquals("WEB-INF", path.getNextElementName());
- assertEquals("/WEB-INF", path.toString());
+ assertEquals("WEB-INF/", path.getNextElementName());
+ assertEquals("/WEB-INF/", path.toString());
path = path.getNextPath();
assertNotNull(path);
assertTrue(path.isFile());
@@ -53,8 +53,8 @@
assertNotNull(path.getNextPath());
assertNotNull(path.getNextElementName());
assertFalse(path.isFile());
- assertEquals("WEB-INF", path.getNextElementName());
- assertEquals("/WEB-INF", path.toString());
+ assertEquals("WEB-INF/", path.getNextElementName());
+ assertEquals("/WEB-INF/", path.toString());
path = path.getNextPath();
assertNotNull(path);
assertTrue(path.isFile());
@@ -70,7 +70,7 @@
public void testWebXmlPath() {
ServerResourcePath path = ServerResourcePath.WEB_XML;
assertFalse(path.isFile());
- assertEquals("WEB-INF", path.getNextElementName());
+ assertEquals("WEB-INF/", path.getNextElementName());
assertEquals("/WEB-INF/web.xml", path.toString());
path = path.getNextPath();
assertNotNull(path.getNextElementName());
@@ -84,5 +84,11 @@
assertNull(path);
}
+ @Test
+ public void testDirPath() throws Exception {
+ ServerResourcePath path = new ServerResourcePath("/foo/bar");
+ assertEquals("foo/", path.getNextElementName());
+ assertEquals("bar", path.getNextPath().getNextElementName());
+ }
}
Modified:
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/staging/UrlResourceLoadingTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/staging/UrlResourceLoadingTest.java 2009-02-26
23:55:44 UTC (rev 12763)
+++
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/staging/UrlResourceLoadingTest.java 2009-02-27
01:46:12 UTC (rev 12764)
@@ -42,7 +42,7 @@
URL resource =
this.getClass().getClassLoader().getResource("java/util/Set.class");
assertNotNull(resource);
StagingServer server = new StagingServer();
- server.addResourcesFromDirectory("/WEB-INF/classes/java/util", resource);
+ server.addResourcesFromDirectory("/WEB-INF/classes/java/util/", resource);
try {
server.init();
assertNotNull(server.getContext().getResource("/WEB-INF/classes/java/util/Map.class"));
Modified: branches/jsf2.0/framework/pom.xml
===================================================================
--- branches/jsf2.0/framework/pom.xml 2009-02-26 23:55:44 UTC (rev 12763)
+++ branches/jsf2.0/framework/pom.xml 2009-02-27 01:46:12 UTC (rev 12764)
@@ -92,7 +92,7 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>javax.faces</groupId>
+ <groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
Modified: branches/jsf2.0/tests/ajax/pom.xml
===================================================================
--- branches/jsf2.0/tests/ajax/pom.xml 2009-02-26 23:55:44 UTC (rev 12763)
+++ branches/jsf2.0/tests/ajax/pom.xml 2009-02-27 01:46:12 UTC (rev 12764)
@@ -63,7 +63,7 @@
</build>
<dependencies>
<dependency>
- <groupId>javax.faces</groupId>
+ <groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
<exclusions>
Modified:
branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/UIDataTest.java
===================================================================
---
branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/UIDataTest.java 2009-02-26
23:55:44 UTC (rev 12763)
+++
branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/UIDataTest.java 2009-02-27
01:46:12 UTC (rev 12764)
@@ -5,11 +5,13 @@
import static org.junit.Assert.*;
+import java.net.URL;
import java.util.List;
import java.util.Locale;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
+import javax.faces.FactoryFinder;
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
@@ -18,6 +20,7 @@
import javax.faces.component.UIOutput;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlDataTable;
+import javax.faces.context.FacesContextFactory;
import javax.faces.event.PhaseId;
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
@@ -29,88 +32,139 @@
import org.richfaces.test.DataBean;
import org.richfaces.test.staging.HttpMethod;
-
/**
* @author asmirnov
- *
+ *
*/
public class UIDataTest extends AbstractFacesTest {
@Before
- public void setUpData(){
-
+ public void setUpData() {
+
}
@Override
protected void setupWebContent() {
- facesServer.addResource("/WEB-INF/faces-config.xml",
"WEB-INF/faces-config.xml");
+ facesServer.addResource("/WEB-INF/faces-config.xml",
+ "WEB-INF/faces-config.xml");
facesServer.addResource("/test.xhtml", "test.xhtml");
}
@Override
protected UIViewRoot setupView() {
+ return null;
+ }
+
+ protected UIViewRoot createView() {
facesContext.setCurrentPhaseId(PhaseId.RESTORE_VIEW);
ELContext elContext = facesContext.getELContext();
- ExpressionFactory expressionFactory = application.getExpressionFactory();
+ ExpressionFactory expressionFactory = application
+ .getExpressionFactory();
UIViewRoot root = super.setupView();
- UIComponent output = application.createComponent(UIOutput.COMPONENT_TYPE);
+ UIComponent output = application
+ .createComponent(UIOutput.COMPONENT_TYPE);
output.setId(root.createUniqueId());
root.getChildren().add(output);
- UIData data = (UIData) application.createComponent(UIData.COMPONENT_TYPE);
+ UIData data = (UIData) application
+ .createComponent(UIData.COMPONENT_TYPE);
data.setId("data");
data.setVar("var");
- data.setValueExpression("value",
expressionFactory.createValueExpression(elContext, "#{dataBean.data}",
List.class));
+ data.setValueExpression("value", expressionFactory
+ .createValueExpression(elContext, "#{dataBean.data}",
+ List.class));
output.getChildren().add(data);
- UIComponent column = application.createComponent(UIColumn.COMPONENT_TYPE);
+ UIComponent column = application
+ .createComponent(UIColumn.COMPONENT_TYPE);
data.getChildren().add(column);
- UIData enclosedData = (UIData) application.createComponent(UIData.COMPONENT_TYPE);
+ UIData enclosedData = (UIData) application
+ .createComponent(UIData.COMPONENT_TYPE);
enclosedData.setId("data1");
enclosedData.setVar("var1");
- enclosedData.setValueExpression("value",
expressionFactory.createValueExpression(elContext, "#{var.items}",
List.class));
+ enclosedData.setValueExpression("value", expressionFactory
+ .createValueExpression(elContext, "#{var.items}", List.class));
column.getChildren().add(enclosedData);
- UIComponent enclosedColumn = application.createComponent(UIColumn.COMPONENT_TYPE);
+ UIComponent enclosedColumn = application
+ .createComponent(UIColumn.COMPONENT_TYPE);
enclosedData.getChildren().add(enclosedColumn);
- UIForm form = (UIForm) application.createComponent(UIForm.COMPONENT_TYPE);
+ UIForm form = (UIForm) application
+ .createComponent(UIForm.COMPONENT_TYPE);
form.setId("form");
enclosedColumn.getChildren().add(form);
- UIInput input = (UIInput) application.createComponent(UIInput.COMPONENT_TYPE);
+ UIInput input = (UIInput) application
+ .createComponent(UIInput.COMPONENT_TYPE);
input.setId("input");
- input.setValueExpression("value",
expressionFactory.createValueExpression(elContext, "#{var1.name}",
String.class));
+ input
+ .setValueExpression("value", expressionFactory
+ .createValueExpression(elContext, "#{var1.name}",
+ String.class));
form.getChildren().add(input);
- ///
+ // /
input = (UIInput) application.createComponent(UIInput.COMPONENT_TYPE);
input.setId("priceinput");
- input.setValueExpression("value",
expressionFactory.createValueExpression(elContext, "#{var1.price}",
Integer.class));
+ input.setValueExpression("value", expressionFactory
+ .createValueExpression(elContext, "#{var1.price}",
+ Integer.class));
enclosedColumn.getChildren().add(input);
input = (UIInput) application.createComponent(UIInput.COMPONENT_TYPE);
input.setId("nameinput");
- input.setValueExpression("value",
expressionFactory.createValueExpression(elContext, "#{var.name}",
String.class));
+ input.setValueExpression("value", expressionFactory
+ .createValueExpression(elContext, "#{var.name}", String.class));
column.getChildren().add(input);
return root;
}
-
+
@Override
protected void setupConnection() {
- this.connection.addRequestParameter(ResponseStateManager.VIEW_STATE_PARAM,
"id1");
+ this.connection.addRequestParameter(
+ ResponseStateManager.VIEW_STATE_PARAM, "j_id1:j_id2");
this.connection.addRequestParameter("data:3:nameinput", "foo");
this.connection.addRequestParameter("data:5:data1:4:priceinput",
"333");
- this.connection.addRequestParameter("data:6:data1:5:form",
"data:6:data1:5:form");
+ this.connection.addRequestParameter("data:6:data1:5:form",
+ "data:6:data1:5:form");
this.connection.addRequestParameter("data:6:data1:5:form:input",
"bar");
connection.setRequestMethod(HttpMethod.POST);
}
-
+
@Test
public void testDecode() throws Exception {
setupFacesRequest();
+ facesContext.setViewRoot(createView());
long startTime = System.currentTimeMillis();
lifecycle.execute(facesContext);
- System.err.println("Execute time
"+(System.currentTimeMillis()-startTime)+"ms");
+ System.err.println("Execute time "
+ + (System.currentTimeMillis() - startTime) + "ms");
lifecycle.render(facesContext);
- DataBean dataBean = (DataBean)
this.facesServer.getSession().getAttribute("dataBean");
+ DataBean dataBean = (DataBean) this.facesServer.getSession()
+ .getAttribute("dataBean");
assertNotNull(dataBean);
assertEquals("foo", dataBean.getData().get(3).getName());
- assertEquals(333, dataBean.getData().get(5).getItems().get(4).getPrice());
- assertEquals("bar", dataBean.getData().get(6).getItems().get(5).getName());
+ assertEquals(333, dataBean.getData().get(5).getItems().get(4)
+ .getPrice());
+ assertEquals("bar", dataBean.getData().get(6).getItems().get(5)
+ .getName());
}
-
+
+ @Test
+ public void testCycleRequest() throws Exception {
+ setupFacesRequest();
+ facesContext.setViewRoot(createView());
+ lifecycle.execute(facesContext);
+ lifecycle.render(facesContext);
+ facesContext.release();
+ facesContext = null;
+ connection.finish();
+ this.facesServer.getSession().removeAttribute("dataBean");
+ setupFacesRequest();
+ lifecycle.execute(facesContext);
+ assertTrue(facesContext.getViewRoot().getChildCount()>0);
+ DataBean dataBean = (DataBean) this.facesServer.getSession()
+ .getAttribute("dataBean");
+ assertNotNull(dataBean);
+ assertEquals("foo", dataBean.getData().get(3).getName());
+ assertEquals(333, dataBean.getData().get(5).getItems().get(4)
+ .getPrice());
+ assertEquals("bar", dataBean.getData().get(6).getItems().get(5)
+ .getName());
+ }
+
}