Author: nbelaevski
Date: 2007-04-02 20:33:01 -0400 (Mon, 02 Apr 2007)
New Revision: 238
Added:
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeModelTest.java
Removed:
trunk/richfaces/tree/src/main/java/org/richfaces/component/AbstractTreeDataModelStrategyWrapper.java
Modified:
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/JSFComponentTest.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeNodeTest.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/xml/TreeDataBuilderTest.java
trunk/richfaces/tree/src/test/resources/org/richfaces/component/xml/XmlTreeDataBuilderTest.xml
Log:
New model test
Tests updated - coverage increased
Deleted:
trunk/richfaces/tree/src/main/java/org/richfaces/component/AbstractTreeDataModelStrategyWrapper.java
===================================================================
---
trunk/richfaces/tree/src/main/java/org/richfaces/component/AbstractTreeDataModelStrategyWrapper.java 2007-04-02
16:45:04 UTC (rev 237)
+++
trunk/richfaces/tree/src/main/java/org/richfaces/component/AbstractTreeDataModelStrategyWrapper.java 2007-04-03
00:33:01 UTC (rev 238)
@@ -1,70 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.component;
-
-import java.io.IOException;
-
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.ajax.repeat.DataVisitor;
-import org.ajax4jsf.ajax.repeat.Range;
-
-/**
- * @author Nick Belaevski - nbelaevski(a)exadel.com
- * created 08.12.2006
- * Wrapper class for {@link AbstractTreeDataModel} instances. Allows developer to change
behaviuor
- * easily by implementing customized {@link #getAbstractTreeDataModel()} method
- * @see PersistedDataModel for an example of customized wrapper allowing to address calls
to backing model
- * or to cached one
- */
-public abstract class AbstractTreeDataModelStrategyWrapper extends AbstractTreeDataModel
{
-
- public Object getRowData() {
- return getAbstractTreeDataModel().getRowData();
- }
-
- public Object getRowKey() {
- return getAbstractTreeDataModel().getRowKey();
- }
-
- public boolean isLeaf() {
- return getAbstractTreeDataModel().isLeaf();
- }
-
- public boolean isRowAvailable() {
- return getAbstractTreeDataModel().isRowAvailable();
- }
-
- public void setRowKey(Object key) {
- getAbstractTreeDataModel().setRowKey(key);
- }
-
- public void walk(FacesContext context, DataVisitor dataVisitor, Range range, TreeRowKey
rowKey, Object argument, boolean last) throws IOException {
- getAbstractTreeDataModel().walk(context, dataVisitor, range, rowKey, argument, last);
- }
-
- /**
- * returns wrapped {@link AbstractTreeDataModel}
- * @return wrapped {@link AbstractTreeDataModel} instance
- */
- protected abstract AbstractTreeDataModel getAbstractTreeDataModel();
-}
Modified:
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
---
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-04-02
16:45:04 UTC (rev 237)
+++
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-04-03
00:33:01 UTC (rev 238)
@@ -234,20 +234,6 @@
return "";
}
- protected String getWaitOnLoadId(FacesContext context, UITree tree) {
- if(tree.getAttributes().get("waitOnLoadId") instanceof String) {
- String waitOnLoadId = (String) tree.getAttributes().get("waitOnLoadId");
- if (waitOnLoadId != null) {
- UIComponent component = tree.getParent().findComponent(waitOnLoadId);
- if (component != null) {
- return component.getClientId(context);
- }
- }
- }
-
- return "";
- }
-
protected String getScriptContributions(FacesContext context, UITree tree) {
return super.getScriptContributions(getJavaScriptVarName(context, tree), context,
tree);
}
Modified:
trunk/richfaces/tree/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
---
trunk/richfaces/tree/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-02
16:45:04 UTC (rev 237)
+++
trunk/richfaces/tree/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-03
00:33:01 UTC (rev 238)
@@ -21,17 +21,40 @@
package org.richfaces.component;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlCommandLink;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.context.FacesContext;
+import org.ajax4jsf.framework.ViewHandlerWrapper;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.xml.XmlTreeDataBuilder;
+import org.xml.sax.InputSource;
+
+import com.gargoylesoftware.htmlunit.KeyValuePair;
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
/**
* Unit test for simple Component.
*/
public class JSFComponentTest
- extends TestCase
+ extends AbstractAjax4JsfTestCase
{
+ private UICommand command = null;
+ private UIInput input = null;
+ private UIForm form = null;
+ private UIComponent tree = null;
+
/**
* Create the test case
*
@@ -42,12 +65,112 @@
super( testName );
}
+ public void setUp() throws Exception {
+ super.setUp();
+
+ form = new HtmlForm();
+
+ facesContext.getViewRoot().getChildren().add(form);
+
+ input = new UIInput() {
+ public void decode(FacesContext context) {
+ // TODO Auto-generated method stub
+ super.decode(context);
+ }
+ };
+ input.setId("input");
+
+ form.getChildren().add(input);
- /**
+ command = new HtmlCommandLink();
+ command.setId("command");
+
+ form.getChildren().add(command);
+
+ application.setViewHandler(new ViewHandlerWrapper(application.getViewHandler()) {
+ public void writeState(FacesContext context) throws IOException {
+ //System.out.println(".writeState()");
+ }
+
+ public String getResourceURL(FacesContext context, String url) {
+ // TODO Auto-generated method stub
+ return url;
+ }
+
+ public String getActionURL(FacesContext context, String url) {
+ // TODO Auto-generated method stub
+ return url;
+ }
+
+ public UIViewRoot restoreView(FacesContext context, String viewId) {
+ // TODO Auto-generated method stub
+ return super.restoreView(context, viewId);
+ }
+
+ public UIViewRoot createView(FacesContext context, String viewId) {
+ // TODO Auto-generated method stub
+ return super.createView(context, viewId);
+ }
+ });
+
+ tree = application.createComponent(UITree.COMPONENT_TYPE);
+
+ ((UITree) tree).setValue(
+ XmlTreeDataBuilder.build(
+ new InputSource(
+ this.getClass().
+ getResourceAsStream("/org/richfaces/component/xml/XmlTreeDataBuilderTest.xml")
+ )));
+
+ form.getChildren().add(tree);
+ ((UITree) tree).queueExpandAll();
+ }
+
+
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ this.input = null;
+ this.form = null;
+ this.command = null;
+ this.tree = null;
+ }
+
+ /**
* Rigourous Test :-)
+ * @throws Exception
*/
- public void testComponent()
+ public void testComponent() throws Exception
{
- assertTrue( true );
+ HtmlPage renderedView = renderView();
+ System.out.println(renderedView.getWebResponse().getContentAsString());
+
+ HtmlInput htmlInput = (HtmlInput)
renderedView.getHtmlElementById(input.getClientId(facesContext));
+ htmlInput.setValueAttribute("testInput");
+
+ HtmlAnchor htmlLink = (HtmlAnchor)
renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+
+ List lastParameters = this.webConnection.getLastParameters();
+ for (Iterator iterator = lastParameters.iterator(); iterator.hasNext();) {
+ KeyValuePair keyValue = (KeyValuePair) iterator.next();
+
+ externalContext.addRequestParameterMap((String) keyValue.getKey(), (String)
keyValue.getValue());
+ }
+
+ System.out.println(this.webConnection.getLastParameters());
+
+ UIViewRoot root = facesContext.getViewRoot();
+ root.processDecodes(facesContext);
+ root.processValidators(facesContext);
+ root.processUpdates(facesContext);
+ root.processApplication(facesContext);
+
+ renderedView = renderView();
+ System.out.println(renderedView.getWebResponse().getContentAsString());
}
+
+ public void testProcess() {
+ }
}
Added: trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeModelTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeModelTest.java
(rev 0)
+++
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeModelTest.java 2007-04-03
00:33:01 UTC (rev 238)
@@ -0,0 +1,139 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.faces.context.FacesContext;
+
+import junit.framework.TestCase;
+
+import org.ajax4jsf.ajax.repeat.DataVisitor;
+import org.richfaces.component.xml.XmlNodeData;
+import org.richfaces.component.xml.XmlTreeDataBuilder;
+import org.xml.sax.InputSource;
+
+/**
+ * @author Nick - mailto:nbelaevski@exadel.com
+ * created 03.04.2007
+ *
+ */
+public class TreeModelTest extends TestCase {
+ private TreeNode node = null;
+ private AbstractTreeDataModel model = new TreeDataModel();
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ InputStream stream =
this.getClass().getResourceAsStream("/org/richfaces/component/xml/XmlTreeDataBuilderTest.xml");
+ try {
+ node = XmlTreeDataBuilder.build(new InputSource(stream));
+ } finally {
+ stream.close();
+ }
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ node = null;
+ model = null;
+ }
+
+ public void testBaseProperties() {
+ assertNull(model.getWrappedData());
+ model.setWrappedData(node);
+ assertSame(model.getWrappedData(), node);
+
+ assertEquals(-1, model.getRowCount());
+ assertEquals(-1, model.getRowIndex());
+
+ try {
+ model.setRowIndex(1);
+
+ fail();
+ } catch (IllegalArgumentException e) {
+
+ }
+
+ model.setRowIndex(-1);
+ }
+
+ public void testWalk() throws Exception {
+ final Set set = new HashSet();
+ set.add("web-app");
+ set.add("login-config");
+ set.add("auth-method");
+ set.add("url-pattern");
+ set.add("load-on-startup-id");
+ set.add("dispatcher");
+ set.add("filter-class");
+ set.add("param-value");
+
+ model.setWrappedData(node);
+
+ model.walk(null, new Walker1(model, set) {
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+ model.setRowKey(rowKey);
+
+ XmlNodeData data = (XmlNodeData) model.getRowData();
+ if (data == null || set.contains(data.getName())) {
+ assertTrue(isLast());
+ } else {
+ assertFalse(isLast());
+ }
+ }
+ }, null, null);
+
+ model.setRowKey(new ListRowKey("testId:displayName"));
+ assertEquals("tree-demo", ((XmlNodeData) model.getRowData()).getText());
+
+ model.setRowKey(new ListRowKey("testId:1:1"));
+ assertEquals(".xhtml", ((XmlNodeData) model.getRowData()).getText());
+ }
+}
+
+abstract class Walker1 implements DataVisitor, LastElementAware {
+
+ private boolean last = false;
+ private AbstractTreeDataModel model;
+ private Set lastElementNames = null;
+
+ public Walker1(AbstractTreeDataModel model, Set lastElementNames) {
+ super();
+ this.model = model;
+ this.lastElementNames = lastElementNames;
+ }
+
+ public void resetLastElement() {
+ this.last = false;
+ }
+
+ public void setLastElement() {
+ this.last = true;
+ }
+
+ public boolean isLast() {
+ return last;
+ }
+}
Modified: trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeNodeTest.java
===================================================================
---
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeNodeTest.java 2007-04-02
16:45:04 UTC (rev 237)
+++
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeNodeTest.java 2007-04-03
00:33:01 UTC (rev 238)
@@ -52,6 +52,11 @@
node = new TreeNodeImpl();
}
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ node = null;
+ }
+
public void testChildrenNew() {
assertFalse(node.getChildren().hasNext());
}
Modified:
trunk/richfaces/tree/src/test/java/org/richfaces/component/xml/TreeDataBuilderTest.java
===================================================================
---
trunk/richfaces/tree/src/test/java/org/richfaces/component/xml/TreeDataBuilderTest.java 2007-04-02
16:45:04 UTC (rev 237)
+++
trunk/richfaces/tree/src/test/java/org/richfaces/component/xml/TreeDataBuilderTest.java 2007-04-03
00:33:01 UTC (rev 238)
@@ -50,6 +50,7 @@
protected void tearDown() throws Exception {
super.tearDown();
+ treeNode = null;
}
public void testIds() {
Modified:
trunk/richfaces/tree/src/test/resources/org/richfaces/component/xml/XmlTreeDataBuilderTest.xml
===================================================================
---
trunk/richfaces/tree/src/test/resources/org/richfaces/component/xml/XmlTreeDataBuilderTest.xml 2007-04-02
16:45:04 UTC (rev 237)
+++
trunk/richfaces/tree/src/test/resources/org/richfaces/component/xml/XmlTreeDataBuilderTest.xml 2007-04-03
00:33:01 UTC (rev 238)
@@ -39,8 +39,6 @@
<filter-mapping>
<filter-name>a4j</filter-name>
<servlet-name>Faces Servlet</servlet-name>
- <dispatcher>FORWARD</dispatcher>
- <dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<servlet>