JBoss Rich Faces SVN: r429 - trunk/richfaces/tree/src/main/java/org/richfaces/renderkit.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-14 12:52:43 -0400 (Sat, 14 Apr 2007)
New Revision: 429
Modified:
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
Log:
encodeAjaxChild() -> encodeAjaxChildren()
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-14 16:11:48 UTC (rev 428)
+++ trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-04-14 16:52:43 UTC (rev 429)
@@ -128,9 +128,9 @@
NSUtils.writeNameSpace(context, component);
}
- public void encodeAjaxChild(FacesContext context, UIComponent component,
+ public void encodeAjaxChildren(FacesContext context, UIComponent component,
String path, Set ids, Set renderedAreas) throws IOException {
- super.encodeAjaxChild(context, component, path, ids, renderedAreas);
+ super.encodeAjaxChildren(context, component, path, ids, renderedAreas);
try {
if (component instanceof UITree) {
19 years
JBoss Rich Faces SVN: r428 - in trunk/richfaces: drag-drop/src/test/java/org/richfaces/component and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-14 12:11:48 -0400 (Sat, 14 Apr 2007)
New Revision: 428
Added:
trunk/richfaces/drag-drop/src/test/java/org/richfaces/component/DragDropTest.java
Removed:
trunk/richfaces/drag-drop/src/test/java/org/richfaces/component/JSFComponentTest.java
Modified:
trunk/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java
Log:
Tree & Drag-drop unit tests
Modified: trunk/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java
===================================================================
--- trunk/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java 2007-04-14 15:58:31 UTC (rev 427)
+++ trunk/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java 2007-04-14 16:11:48 UTC (rev 428)
@@ -49,7 +49,7 @@
*/
public class DropzoneRendererContributor implements RendererContributor {
- static final String DROP_TARGET_ID = "dropTargetId";
+ public static final String DROP_TARGET_ID = "dropTargetId";
private static final EventCallback dropEventsCallback = new EventCallback() {
Added: trunk/richfaces/drag-drop/src/test/java/org/richfaces/component/DragDropTest.java
===================================================================
--- trunk/richfaces/drag-drop/src/test/java/org/richfaces/component/DragDropTest.java (rev 0)
+++ trunk/richfaces/drag-drop/src/test/java/org/richfaces/component/DragDropTest.java 2007-04-14 16:11:48 UTC (rev 428)
@@ -0,0 +1,211 @@
+package org.richfaces.component;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIPanel;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.tests.MockViewRoot;
+import org.apache.commons.collections.Buffer;
+import org.apache.commons.lang.StringUtils;
+import org.richfaces.renderkit.DraggableRendererContributor;
+import org.richfaces.renderkit.DropzoneRendererContributor;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+ /**
+ * Unit test for simple Component.
+ */
+public class DragDropTest extends AbstractAjax4JsfTestCase {
+
+ private UIDndParam dndparam;
+
+ private UIDragIndicator dndindicator;
+
+ private UIDragSupport dragsupport;
+
+ private UIDropSupport dropsupport;
+
+ private UIPanel panel1, panel2;
+
+ private UIComponent form;
+
+ private static Set javaScripts = new HashSet();
+ static {
+ javaScripts.add("prototype.js");
+ javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/browser_info.js");
+ javaScripts.add("/a4j.res/dnd.js");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/events.js");
+ javaScripts
+ .add("/org/richfaces/renderkit/html/scripts/simple-draggable.js");
+ javaScripts
+ .add("/org/richfaces/renderkit/html/scripts/simple-dropzone.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/json/json.js");
+ javaScripts
+ .add("/org/richfaces/renderkit/html/scripts/dnd/dnd-common.js");
+ javaScripts
+ .add("/org/richfaces/renderkit/html/scripts/dnd/dnd-dropzone.js");
+ javaScripts
+ .add("/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js");
+ javaScripts
+ .add("/org/richfaces/renderkit/html/scripts/drag-indicator.js");
+ }
+ private static Set eventsSet = new HashSet();
+ static {
+ eventsSet.add("org.richfaces.component.html.HtmlDragSupport");
+ eventsSet.add("org.richfaces.component.html.HtmlDropSupport");
+
+ }
+
+ public DragDropTest(String testName) {
+ super(testName);
+ }
+
+ public void SetUp() throws Exception {
+
+ super.setUp();
+
+ form = new HtmlForm();
+ assertNotNull(form);
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ panel1 = new UIPanel();
+ panel1.setId("panel1");
+
+ panel2 = new UIPanel();
+ panel2.setId("panel2");
+
+ dndparam = (UIDndParam) application
+ .createComponent("org.richfaces.DndParam");
+ dndparam.setId("dndparam");
+
+ dndindicator = (UIDragIndicator) application
+ .createComponent(UIDragIndicator.COMPONENT_TYPE);
+ dndindicator.setId("dndindicator");
+
+ dragsupport = (UIDragSupport) application
+ .createComponent("org.richfaces.DragSupport");
+ dragsupport.setId("dragsupport");
+ dragsupport.setDragType("foto");
+ // panel1.getChildren().add(dragsupport);
+
+ dropsupport = (UIDropSupport) application
+ .createComponent("org.richfaces.DropSupport");
+ dropsupport.setId("dropsupport");
+ dropsupport.setAcceptedTypes("foto");
+ // panel2.getChildren().add(dropsupport);
+
+ form.getChildren().add(panel1);
+ form.getChildren().add(dndindicator);
+ form.getChildren().add(dndparam);
+ form.getChildren().add(dragsupport);
+ form.getChildren().add(dropsupport);
+
+ form.getChildren().add(panel2);
+
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ this.form = null;
+ this.dndindicator = null;
+ this.dragsupport = null;
+ this.dropsupport = null;
+ this.dndparam = null;
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testComponent() throws Exception {
+ SetUp();
+ HtmlPage page = renderView();
+ assertNotNull(page);
+
+ HtmlElement htmlDnDIndicator = page.getHtmlElementById(dndindicator
+ .getClientId(facesContext));
+ assertTrue(htmlDnDIndicator.getAttributeValue("class").contains(
+ "drag_indicator"));
+
+ // HtmlElement htmlDnDParam =
+ // page.getHtmlElementById(dndparam.getClientId(facesContext));
+ // assertTrue(htmlDnDParam.getNodeName().equals("script"));
+
+ HtmlElement htmlDragSupport = page.getHtmlElementById(dragsupport
+ .getClientId(facesContext));
+ assertTrue(htmlDragSupport.getNodeName().equals("script"));
+ assertTrue(dragsupport.getDragType().equals("foto"));
+
+ HtmlElement htmlDropSupport = page.getHtmlElementById(dropsupport
+ .getClientId(facesContext));
+ assertTrue(htmlDropSupport.getNodeName().equals("script"));
+ assertTrue(dropsupport.getAcceptedTypes().equals("foto"));
+ }
+
+ public void testScript() throws Exception {
+ SetUp();
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List scripts = page.getDocumentElement().getHtmlElementsByTagName(
+ "script");
+ System.out.println(page.asXml());
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ String srcAttr = item.getSrcAttribute();
+
+ if (StringUtils.isNotBlank(srcAttr)) {
+ boolean found = false;
+ for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
+ String src = (String) srcIt.next();
+
+ found = srcAttr.contains(src);
+ if (found) {
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+
+ }
+
+ public void testDecode() throws Exception {
+
+ SetUp();
+ externalContext.addRequestParameterMap(DraggableRendererContributor.DRAG_SOURCE_ID, dragsupport.getClientId(facesContext));
+ externalContext.addRequestParameterMap(DropzoneRendererContributor.DROP_TARGET_ID, dropsupport.getClientId(facesContext));
+
+ dragsupport.decode(facesContext);
+ dropsupport.decode(facesContext);
+
+ MockViewRoot root = (MockViewRoot) facesContext.getViewRoot();
+ Buffer queue = root.getEventsQueue(facesContext, PhaseId.ANY_PHASE);
+ assertNotNull(queue);
+ Object[] events = queue.toArray();
+ for(int i=0;i< events.length;i++)
+ {
+ boolean found = false;
+ for (Iterator srcIt = eventsSet.iterator(); srcIt.hasNext();) {
+ String src = (String) srcIt.next();
+ found = events[i].toString().contains(src);
+ if (found) {
+ break;
+ }
+ }
+ assertTrue(found);
+ }
+
+ }
+ }
Deleted: trunk/richfaces/drag-drop/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/drag-drop/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-14 15:58:31 UTC (rev 427)
+++ trunk/richfaces/drag-drop/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-14 16:11:48 UTC (rev 428)
@@ -1,53 +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 junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import javax.faces.component.UIComponent;
-
-/**
- * Unit test for simple Component.
- */
-public class JSFComponentTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public JSFComponentTest( String testName )
- {
- super( testName );
- }
-
-
- /**
- * Rigourous Test :-)
- */
- public void testComponent()
- {
- assertTrue( true );
- }
-}
Modified: trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java 2007-04-14 15:58:31 UTC (rev 427)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java 2007-04-14 16:11:48 UTC (rev 428)
@@ -28,16 +28,13 @@
import java.util.Set;
import javax.faces.component.UICommand;
-import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
-import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlForm;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
import javax.servlet.http.HttpServletResponse;
@@ -56,14 +53,11 @@
import org.richfaces.component.events.NodeSelectedEvent;
import org.richfaces.component.events.NodeSelectedListener;
import org.richfaces.component.state.events.ExpandAllCommandEvent;
-import org.richfaces.component.state.events.TreeStateCommandEvent;
import org.richfaces.component.xml.XmlTreeDataBuilder;
import org.xml.sax.InputSource;
-import com.gargoylesoftware.htmlunit.KeyValuePair;
import com.gargoylesoftware.htmlunit.Page;
-import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
-import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlLink;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlScript;
@@ -72,19 +66,19 @@
* Unit test for simple Component.
*/
public class TreeComponentTest
- extends AbstractAjax4JsfTestCase
+extends AbstractAjax4JsfTestCase
{
- private static Set javaScripts = new HashSet();
+ private static Set javaScripts = new HashSet();
- static {
+ static {
javaScripts.add("/org/richfaces/renderkit/html/scripts/json/json.js");
- javaScripts.add("prototype.js");
- javaScripts.add("dnd.js");
+ javaScripts.add("prototype.js");
+ javaScripts.add("dnd.js");
javaScripts.add("/org/richfaces/renderkit/html/scripts/dnd/dnd-common.js");
javaScripts.add("/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js");
javaScripts.add("/org/richfaces/renderkit/html/scripts/dnd/dnd-dropzone.js");
-
+
javaScripts.add("/org/ajax4jsf/framework/ajax/scripts/AJAX.js");
javaScripts.add("/org/ajax4jsf/renderkit/html/scripts/form.js");
javaScripts.add("/org/richfaces/renderkit/html/scripts/events.js");
@@ -93,39 +87,39 @@
javaScripts.add("/org/richfaces/renderkit/html/scripts/tree-item.js");
javaScripts.add("/org/richfaces/renderkit/html/scripts/tree-item-dnd.js");
javaScripts.add("/org/richfaces/renderkit/html/scripts/drag-indicator.js");
-
- }
- private static Set cssStyles = new HashSet();
+ }
- static {
- cssStyles.add("/org/richfaces/renderkit/html/css/dragIndicator.xcss");
- cssStyles.add("/org/richfaces/renderkit/html/css/tree.xcss");
- }
+ private static Set cssStyles = new HashSet();
- private UICommand command = null;
+ static {
+ cssStyles.add("/org/richfaces/renderkit/html/css/dragIndicator.xcss");
+ cssStyles.add("/org/richfaces/renderkit/html/css/tree.xcss");
+ }
+
+ private UICommand command = null;
private UIInput input = null;
private UIForm form = null;
private UITree tree = null;
private UITreeNode treeNode = null;
-
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public TreeComponentTest( String testName )
- {
- super( testName );
- }
- public void setUp() throws Exception {
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public TreeComponentTest( String testName )
+ {
+ 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
@@ -133,159 +127,204 @@
}
};
input.setId("input");
-
+
form.getChildren().add(input);
command = new HtmlCommandLink();
command.setId("command");
-
+
form.getChildren().add(command);
tree = (UITree) application.createComponent(UITree.COMPONENT_TYPE);
-
+
tree.setValue(
XmlTreeDataBuilder.build(
new InputSource(
this.getClass().
getResourceAsStream("/org/richfaces/component/xml/XmlTreeDataBuilderTest.xml")
- )));
-
+ )));
+
form.getChildren().add(tree);
tree.queueExpandAll();
treeNode = (UITreeNode) application.createComponent(UITreeNode.COMPONENT_TYPE);
treeNode.setType("node");
-
+
tree.getChildren().add(treeNode);
- }
+ }
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception {
super.tearDown();
-
+
this.input = null;
this.form = null;
this.command = null;
this.tree = null;
this.treeNode = null;
- }
+ }
/**
- * Rigourous Test :-)
+ * Rigourous Test :-)
* @throws Exception
- */
- public void testComponent() throws Exception
- {
- HtmlPage renderedView = renderView();
- //System.out.println(renderedView.getWebResponse().getContentAsString());
-/*
+ */
+ public void testComponent() throws Exception
+ {
+ 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());
}
-
+
UIViewRoot root = facesContext.getViewRoot();
root.processDecodes(facesContext);
root.processValidators(facesContext);
root.processUpdates(facesContext);
root.processApplication(facesContext);
-
+
renderedView = renderView();
-*/
- }
-
- public void testRenderStyle() throws Exception {
- HtmlPage page = renderView();
- assertNotNull(page);
- List styles = page.getDocumentElement().getHtmlElementsByTagName("link");
- for (Iterator it = styles.iterator(); it.hasNext();) {
- HtmlLink item = (HtmlLink) it.next();
- String srcAttr = item.getHrefAttribute();
+ */
+ }
- if (StringUtils.isNotBlank(srcAttr)) {
- boolean found = false;
- for (Iterator srcIt = cssStyles.iterator(); srcIt.hasNext();) {
- String src = (String) srcIt.next();
+ public void testRenderStyle() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List styles = page.getDocumentElement().getHtmlElementsByTagName("link");
+ for (Iterator it = styles.iterator(); it.hasNext();) {
+ HtmlLink item = (HtmlLink) it.next();
+ String srcAttr = item.getHrefAttribute();
- found = srcAttr.contains(src);
- if (found) {
- break;
- }
- }
+ if (StringUtils.isNotBlank(srcAttr)) {
+ boolean found = false;
+ for (Iterator srcIt = cssStyles.iterator(); srcIt.hasNext();) {
+ String src = (String) srcIt.next();
- assertTrue(found);
- }
- }
- }
-
- public void testRenderScript() throws Exception {
- HtmlPage page = renderView();
- assertNotNull(page);
- List scripts = page.getDocumentElement().getHtmlElementsByTagName("script");
- for (Iterator it = scripts.iterator(); it.hasNext();) {
- HtmlScript item = (HtmlScript) it.next();
- String srcAttr = item.getSrcAttribute();
+ found = srcAttr.contains(src);
+ if (found) {
+ break;
+ }
+ }
- if (StringUtils.isNotBlank(srcAttr)) {
- boolean found = false;
- for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
- String src = (String) srcIt.next();
+ assertTrue(found);
+ }
+ }
+ }
- found = srcAttr.contains(src);
- if (found) {
- break;
- }
- }
+ public void testRenderScript() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List scripts = page.getDocumentElement().getHtmlElementsByTagName("script");
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ String srcAttr = item.getSrcAttribute();
- assertTrue(found);
- }
- }
- }
+ if (StringUtils.isNotBlank(srcAttr)) {
+ boolean found = false;
+ for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
+ String src = (String) srcIt.next();
- public void testRenderImages() throws Exception {
- renderView();
- InternetResourceBuilder builder = ResourceBuilderImpl.getInstance();
- InternetResource resource = builder.getResource("org/richfaces/renderkit/html/css/tree.xcss");
- assertNotNull(resource);
- String uri = "http:" + resource.getUri(facesContext, null);
- Page page = webClient.getPage(uri);
- assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
+ found = srcAttr.contains(src);
+ if (found) {
+ break;
+ }
+ }
- String[] resources = new String[] {
- "org.richfaces.renderkit.html.images.TreeLineCollapsedImage",
- "org.richfaces.renderkit.html.images.TreeLineExpandedImage",
- "org.richfaces.renderkit.html.images.TreeLineImage",
- "org.richfaces.renderkit.html.images.TreeLineLastImage",
- "org.richfaces.renderkit.html.images.TreeLineNodeImage",
- "org.richfaces.renderkit.html.images.TreeMinusImage",
- "org.richfaces.renderkit.html.images.TreePlusImage"
- };
-
- for (int i = 0; i < resources.length; i++) {
- resource = builder.getResource(resources[i]);
- assertNotNull(resource);
- uri = "http:" + resource.getUri(facesContext, null);
- page = webClient.getPage(uri);
- assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
- ImageInfo info = new ImageInfo();
- info.setInput(page.getWebResponse().getContentAsStream());
- //image recognizable?
- assertTrue(info.check());
- assertEquals(ImageInfo.FORMAT_GIF, info.getFormat());
+ assertTrue(found);
+ }
}
- }
-
- public void testProcess() {
- }
+ }
+ public void testRenderImages() throws Exception {
+ renderView();
+ InternetResourceBuilder builder = ResourceBuilderImpl.getInstance();
+ InternetResource resource = builder.getResource("org/richfaces/renderkit/html/css/tree.xcss");
+ assertNotNull(resource);
+ String uri = "http:" + resource.getUri(facesContext, null);
+ Page page = webClient.getPage(uri);
+ assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
+ String[] resources = new String[] {
+ "org.richfaces.renderkit.html.images.TreeLineCollapsedImage",
+ "org.richfaces.renderkit.html.images.TreeLineExpandedImage",
+ "org.richfaces.renderkit.html.images.TreeLineImage",
+ "org.richfaces.renderkit.html.images.TreeLineLastImage",
+ "org.richfaces.renderkit.html.images.TreeLineNodeImage",
+ "org.richfaces.renderkit.html.images.TreeMinusImage",
+ "org.richfaces.renderkit.html.images.TreePlusImage"
+ };
+
+ for (int i = 0; i < resources.length; i++) {
+ resource = builder.getResource(resources[i]);
+ assertNotNull(resource);
+ uri = "http:" + resource.getUri(facesContext, null);
+ page = webClient.getPage(uri);
+ assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
+ ImageInfo info = new ImageInfo();
+ info.setInput(page.getWebResponse().getContentAsStream());
+ //image recognizable?
+ assertTrue(info.check());
+ assertEquals(ImageInfo.FORMAT_GIF, info.getFormat());
+ }
+ }
+
+ private static Set styleClasses = new HashSet();
+
+ static {
+ styleClasses.add("dr-tree-h-ic dr-tree-h-ic-line-last");
+ styleClasses.add("dr-tree-h-ic dr-tree-h-ic-line-clp");
+ styleClasses.add("dr-tree-h-text rich-tree-node");
+ styleClasses.add("dr-tree-pointer-cursor");
+ styleClasses.add("");
+ }
+
+ public void testProcess() throws Exception {
+
+ HtmlPage renderedView = renderView();
+
+ HtmlElement htmlTree = renderedView.getHtmlElementById(tree
+ .getClientId(facesContext));
+ htmlTree.getAttributeValue("class").equals("dr-tree rich-tree ");
+
+ // System.out.println(htmlTree.getHtmlElementsByAttribute("class",
+ // "highlightedclass", "selectedclass"));
+
+ List tagNames = new ArrayList();
+ tagNames.add("td");
+ tagNames.add("img");
+ tagNames.add("div");
+ List chldList = htmlTree.getHtmlElementsByTagNames(tagNames);
+ System.out.println(chldList);
+
+ for (Iterator it = chldList.iterator(); it.hasNext();) {
+ HtmlElement element = (HtmlElement) it.next();
+
+ if (!element.getAttributeValue("class").equals("")) {
+ boolean found = false;
+ for (Iterator sCIt = styleClasses.iterator(); sCIt.hasNext();) {
+ String src = (String) sCIt.next();
+ found = element.getAttributeValue("class").contains(src);
+ if (found) {
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ ;
+
+ }
+ }
+
+
/**
* Test method for {@link org.richfaces.component.UITreeNode#addChangeExpandListener(org.richfaces.component.events.NodeExpandedListener)}.
*/
@@ -293,9 +332,9 @@
NodeExpandedListener listener = new NodeExpandedListener() {
public void processExpansion(NodeExpandedEvent nodeExpandedEvent)
- throws AbortProcessingException {
+ throws AbortProcessingException {
}
-
+
};
assertTrue(tree.getChangeExpandListeners().length == 0);
assertTrue(treeNode.getChangeExpandListeners().length == 0);
@@ -323,9 +362,9 @@
NodeSelectedListener listener = new NodeSelectedListener() {
public void processSelection(NodeSelectedEvent nodeSelectedEvent)
- throws AbortProcessingException {
+ throws AbortProcessingException {
}
-
+
};
assertTrue(tree.getNodeSelectListeners().length == 0);
assertTrue(treeNode.getNodeSelectListeners().length == 0);
@@ -357,7 +396,7 @@
output.getChildren().add(treeNode2);
try {
treeNode2.getUITree();
-
+
fail();
} catch (Exception e) {
}
@@ -374,7 +413,7 @@
public void processDrop(DropEvent event) {
}
-
+
};
assertTrue(tree.getDropListeners().length == 0);
assertTrue(treeNode.getDropListeners().length == 0);
@@ -387,7 +426,7 @@
assertSame(listener, tree.getDropListeners()[0]);
assertSame(listener, treeNode.getDropListeners()[0]);
-
+
tree.removeDropListener(listener);
treeNode.removeDropListener(listener);
@@ -403,7 +442,7 @@
public void processDrag(DragEvent event) {
}
-
+
};
assertTrue(tree.getDragListeners().length == 0);
assertTrue(treeNode.getDragListeners().length == 0);
@@ -416,7 +455,7 @@
assertSame(listener, tree.getDragListeners()[0]);
assertSame(listener, treeNode.getDragListeners()[0]);
-
+
tree.removeDragListener(listener);
treeNode.removeDragListener(listener);
@@ -564,12 +603,12 @@
defaultFacet.getChildren().add(input1);
tree.setNodeFace("node");
-
+
Iterator dataChildren = tree.dataChildren();
assertTrue(dataChildren.hasNext());
assertSame(treeNode, dataChildren.next());
assertFalse(dataChildren.hasNext());
-
+
tree.setNodeFace("");
dataChildren = tree.dataChildren();
assertTrue(dataChildren.hasNext());
@@ -601,21 +640,21 @@
public final void testFixedChildren() {
Iterator fixedChildren = tree.fixedChildren();
assertFalse(fixedChildren.hasNext());
-
+
UIInput input = new UIInput();
UIOutput output = new UIOutput();
tree.getFacets().put("facet1", input);
tree.getFacets().put("facet2", output);
-
+
fixedChildren = tree.fixedChildren();
List children = new ArrayList();
-
+
assertTrue(fixedChildren.hasNext());
children.add(fixedChildren.next());
assertTrue(fixedChildren.hasNext());
children.add(fixedChildren.next());
assertFalse(fixedChildren.hasNext());
-
+
assertTrue(children.contains(input));
assertTrue(children.contains(output));
assertEquals(2, children.size());
@@ -652,17 +691,17 @@
treeNode.setAjaxSubmitSelection("inherit");
assertFalse(treeNode.hasAjaxSubmitSelection());
-
+
tree.setAjaxSubmitSelection(true);
assertTrue(tree.isAjaxSubmitSelection() == tree.hasAjaxSubmitSelection());
assertTrue(tree.isAjaxSubmitSelection());
-
+
assertTrue(treeNode.hasAjaxSubmitSelection());
-
+
treeNode.setAjaxSubmitSelection("false");
assertTrue(tree.isAjaxSubmitSelection());
assertFalse(treeNode.hasAjaxSubmitSelection());
-
+
treeNode.setAjaxSubmitSelection(null);
treeNode.hasAjaxSubmitSelection();
assertTrue(treeNode.hasAjaxSubmitSelection());
@@ -674,7 +713,7 @@
try {
treeNode.setAjaxSubmitSelection("untrue");
treeNode.hasAjaxSubmitSelection();
-
+
fail();
} catch (IllegalArgumentException e) {
}
19 years
JBoss Rich Faces SVN: r427 - trunk/richfaces/tabPanel/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-14 11:58:31 -0400 (Sat, 14 Apr 2007)
New Revision: 427
Modified:
trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabTest.java
Log:
Missing methods added
Modified: trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabTest.java
===================================================================
--- trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabTest.java 2007-04-14 14:55:48 UTC (rev 426)
+++ trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabTest.java 2007-04-14 15:58:31 UTC (rev 427)
@@ -241,5 +241,12 @@
public void setTimeout(int timeout) {
}
+
+ public String getFocus() {
+ return null;
+ }
+
+ public void setFocus(String arg0) {
+ }
}
}
19 years
JBoss Rich Faces SVN: r426 - trunk/richfaces/dataFilterSlider/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: pkotikov
Date: 2007-04-14 10:55:48 -0400 (Sat, 14 Apr 2007)
New Revision: 426
Modified:
trunk/richfaces/dataFilterSlider/src/test/java/org/richfaces/component/DataFilterSliderComponentTest.java
Log:
Tests updated.
Modified: trunk/richfaces/dataFilterSlider/src/test/java/org/richfaces/component/DataFilterSliderComponentTest.java
===================================================================
--- trunk/richfaces/dataFilterSlider/src/test/java/org/richfaces/component/DataFilterSliderComponentTest.java 2007-04-14 14:29:48 UTC (rev 425)
+++ trunk/richfaces/dataFilterSlider/src/test/java/org/richfaces/component/DataFilterSliderComponentTest.java 2007-04-14 14:55:48 UTC (rev 426)
@@ -27,6 +27,7 @@
import java.util.List;
import java.util.Set;
+import javax.faces.application.FacesMessage;
import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
@@ -35,6 +36,8 @@
import javax.faces.component.html.HtmlForm;
import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.MethodNotFoundException;
import javax.faces.el.PropertyNotFoundException;
import javax.faces.el.ValueBinding;
import javax.servlet.http.HttpServletResponse;
@@ -46,6 +49,7 @@
import org.ajax4jsf.framework.util.image.ImageInfo;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.apache.commons.lang.StringUtils;
+import org.richfaces.event.DataFilterSliderAdapter;
import org.richfaces.event.DataFilterSliderEvent;
import org.richfaces.renderkit.html.images.SliderFieldGradient;
import org.richfaces.renderkit.html.images.SliderTrackGradient;
@@ -274,13 +278,26 @@
assertTrue(bean.getValue().equals("66"));
}
- public void testListener() {
- //HtmlPage page = renderView();
- UIDataFltrSlider slider = (UIDataFltrSlider) dfSlider;
- SliderListenerBean bean = new SliderListenerBean();
- DataFilterSliderEvent event = new DataFilterSliderEvent(slider,Integer.valueOf(10),Integer.valueOf(50));
- //MethodBinding binding = application.createMethodBinding(bean.doSlide(), null);
- //slider.setSliderListener(binding);
+ public void testListener() throws Exception{
+ HtmlPage renderedView = renderView();
+
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+
+ MethodBinding binding = new MethodBinding(){
+ public Object invoke(FacesContext context, Object[] params) throws EvaluationException, MethodNotFoundException {
+ facesContext.addMessage(dfSlider.getClientId(facesContext), new FacesMessage("Method invoked!"));
+ return "invoked";
+ }
+ public Class getType(FacesContext context) throws MethodNotFoundException {
+ return String.class;
+ }
+ };
+
+ DataFilterSliderEvent event = new DataFilterSliderEvent( ((UIDataFltrSlider) dfSlider), new Integer(20), new Integer (50 ) );
+ new DataFilterSliderAdapter(binding).processSlider(event);
+
+ assertTrue(facesContext.getMessages().hasNext());
}
private final class SliderBean {
@@ -300,11 +317,4 @@
}
}
-
- private final class SliderListenerBean {
- public void doSlide(DataFilterSliderEvent event) {
- Integer oldSliderVal = event.getOldSliderVal();
- Integer newSliderVal = event.getNewSliderVal();
- }
- }
-}
+}
\ No newline at end of file
19 years
JBoss Rich Faces SVN: r425 - trunk/richfaces/datascroller/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: d.bulahov
Date: 2007-04-14 10:29:48 -0400 (Sat, 14 Apr 2007)
New Revision: 425
Modified:
trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java
Log:
Unit tests development
Modified: trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java
===================================================================
--- trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java 2007-04-14 14:27:45 UTC (rev 424)
+++ trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java 2007-04-14 14:29:48 UTC (rev 425)
@@ -142,7 +142,7 @@
* @throws Exception
*/
public void testRender() throws Exception {
- HtmlPage page = renderView();
+ HtmlPage page = renderView();
assertNotNull(page);
System.out.println(page.asXml());
@@ -186,8 +186,28 @@
assertTrue(false);
} catch(Exception ex) {
}
+ scroller.processDecodes(facesContext);
+ scroller.processValidators(facesContext);
+ scroller.processUpdates(facesContext);
+ scroller.setFor(data.getId());
}
+ public void testNotRender() throws Exception {
+ data.setRows(25);
+ scroller.setRenderIfSinglePage(false);
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ System.out.println(page.asXml());
+ try {
+ page.getHtmlElementById(scroller.getClientId(facesContext));
+ assertTrue(false);
+ } catch(Exception ex) {
+ }
+
+ }
+
+
/**
* Test style rendering
*
19 years
JBoss Rich Faces SVN: r424 - trunk/richfaces/common/src/main/java/org/richfaces/renderkit/html.
by richfaces-svn-commits@lists.jboss.org
Author: a.izobov
Date: 2007-04-14 10:27:45 -0400 (Sat, 14 Apr 2007)
New Revision: 424
Modified:
trunk/richfaces/common/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
Log:
possibility to paint horizontal gradient added
Modified: trunk/richfaces/common/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
===================================================================
--- trunk/richfaces/common/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2007-04-14 14:21:20 UTC (rev 423)
+++ trunk/richfaces/common/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2007-04-14 14:27:45 UTC (rev 424)
@@ -53,6 +53,7 @@
private int gradientHeight;
private String baseColor;
private String gradientColor;
+ private boolean horizontal = false;
public BaseGradient(int width, int height, int gradientHeight) {
super();
@@ -89,7 +90,43 @@
this.baseColor = baseColor;
this.gradientColor = gradientColor;
}
+
+ public BaseGradient(int width, int height, int gradientHeight, boolean horizontal) {
+ this(width, height, gradientHeight);
+ this.horizontal = horizontal;
+ }
+
+ public BaseGradient(int width, int height, int gradientHeight, String baseColor, String gradientColor, boolean horizontal) {
+ this(width, height, gradientHeight);
+ this.baseColor = baseColor;
+ this.gradientColor = gradientColor;
+ this.horizontal = horizontal;
+ }
+
+ public BaseGradient(int width, int height, boolean horizontal) {
+ this(width, height, horizontal?width:height);
+ this.horizontal = horizontal;
+ }
+
+ public BaseGradient(int width, int height, String baseColor, String gradientColor, boolean horizontal) {
+ this(width, height, horizontal?width:height);
+ this.baseColor = baseColor;
+ this.gradientColor = gradientColor;
+ this.horizontal = horizontal;
+ }
+ public BaseGradient(boolean horizontal) {
+ this(30, 50, 20);
+ this.horizontal = horizontal;
+ }
+
+ public BaseGradient(String baseColor, String gradientColor, boolean horizontal) {
+ this(30, 50, 20);
+ this.baseColor = baseColor;
+ this.gradientColor = gradientColor;
+ this.horizontal = horizontal;
+ }
+
public Dimension getDimensions(FacesContext facesContext, Object data) {
return new Dimension(width, height);
}
@@ -115,7 +152,12 @@
int gradStart = 0;
int gradEnd = gradientHeight;
Color alternateColor = new Color(dataToStore.headerGradientColor.intValue());
- GradientPaint gragient = new GradientPaint(0, gradStart, baseColor, 0, gradEnd, alternateColor);
+ GradientPaint gragient;
+ if (horizontal) {
+ gragient = new GradientPaint(gradStart, 0, baseColor, gradEnd, 0, alternateColor);
+ } else {
+ gragient = new GradientPaint(0, gradStart, baseColor, 0, gradEnd, alternateColor);
+ }
g2d.setPaint(gragient);
g2d.fill(rect);
}
19 years
JBoss Rich Faces SVN: r423 - trunk/richfaces/togglePanel/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: F.antonov
Date: 2007-04-14 10:21:20 -0400 (Sat, 14 Apr 2007)
New Revision: 423
Modified:
trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelComponentTest.java
Log:
TogglePanel test cases development.
Modified: trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelComponentTest.java
===================================================================
--- trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelComponentTest.java 2007-04-14 14:00:05 UTC (rev 422)
+++ trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelComponentTest.java 2007-04-14 14:21:20 UTC (rev 423)
@@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
package org.richfaces.component;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
@@ -28,11 +27,19 @@
import org.richfaces.event.SwitchablePanelSwitchEvent;
import org.richfaces.component.UISwitchablePanel;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.tests.MockViewRoot;
+import org.apache.commons.collections.Buffer;
import org.apache.commons.lang.StringUtils;
+
+import javax.faces.FacesException;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
import javax.faces.component.UIOutput;
import javax.faces.component.html.HtmlForm;
import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -51,45 +58,53 @@
}
private UITogglePanel togglePanel;
+
private UIToggleControl toggleControl;
+
private UIComponent form;
+
private UIOutput a;
+
private UIOutput b;
+
private UIOutput c;
/**
* Create the test case
- *
- * @param testName name of the test case
+ *
+ * @param testName
+ * name of the test case
*/
public TogglePanelComponentTest(String testName) {
super(testName);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
*/
public void setUp() throws Exception {
super.setUp();
-
- a = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
+
+ a = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
a.setId("a_output");
a.setValue("a");
- b = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
+ b = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
b.setId("b_output");
b.setValue("b");
- c = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
+ c = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
c.setId("c_output");
c.setValue("c");
-
-
+
form = new HtmlForm();
form.setId("form");
facesContext.getViewRoot().getChildren().add(form);
- togglePanel = (UITogglePanel)application.createComponent("org.richfaces.TogglePanel");
+ togglePanel = (UITogglePanel) application
+ .createComponent("org.richfaces.TogglePanel");
togglePanel.setId("TogglePanel");
togglePanel.getFacets().put("a", a);
togglePanel.getFacets().put("b", b);
@@ -99,46 +114,51 @@
form.getChildren().add(togglePanel);
- toggleControl = (UIToggleControl)application.createComponent("org.richfaces.ToggleControl");
+ toggleControl = (UIToggleControl) application
+ .createComponent("org.richfaces.ToggleControl");
toggleControl.setId("ToggleControl");
- toggleControl.setFor(togglePanel.getId());
+ toggleControl.setFor(togglePanel.getId());
form.getChildren().add(toggleControl);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
*/
public void tearDown() throws Exception {
super.tearDown();
togglePanel = null;
toggleControl = null;
- form = null;
+ form = null;
}
- /**
+ /**
* Test component rendering
- *
+ *
* @throws Exception
*/
-
+
public void testRender() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
- //System.out.println(page.asXml());
+ // System.out.println(page.asXml());
- HtmlElement div = page.getHtmlElementById(togglePanel.getClientId(facesContext));
+ HtmlElement div = page.getHtmlElementById(togglePanel
+ .getClientId(facesContext));
assertNotNull(div);
assertEquals("div", div.getNodeName());
-
- HtmlElement div_control = page.getHtmlElementById(toggleControl.getClientId(facesContext));
+ HtmlElement div_control = page.getHtmlElementById(toggleControl
+ .getClientId(facesContext));
String classAttr = div_control.getAttributeValue("class");
assertTrue(classAttr.contains("dr-tglctrl"));
assertTrue(classAttr.contains("rich-tglctrl"));
}
+
/**
* Test style rendering
- *
+ *
* @throws Exception
*/
public void testRenderStyle() throws Exception {
@@ -148,17 +168,20 @@
assertEquals(1, links.size());
HtmlElement link = (HtmlElement) links.get(0);
- assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/toggleControl.xcss"));
+ assertTrue(link.getAttributeValue("href").contains(
+ "org/richfaces/renderkit/html/css/toggleControl.xcss"));
}
+
/**
* Test script rendering
- *
+ *
* @throws Exception
- */
+ */
public void testRenderScript() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
- List scripts = page.getDocumentElement().getHtmlElementsByTagName("script");
+ List scripts = page.getDocumentElement().getHtmlElementsByTagName(
+ "script");
for (Iterator it = scripts.iterator(); it.hasNext();) {
HtmlScript item = (HtmlScript) it.next();
@@ -179,62 +202,157 @@
}
}
}
-
+
public void testSwitch() throws Exception {
HtmlPage page = renderView();
- System.out.println(page.asXml());
+ // System.out.println(page.asXml());
togglePanel.setValue("a");
- togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel,null, toggleControl));
- assertFalse(((String)togglePanel.getValue()).equals("a"));
- assertTrue(((String)togglePanel.getValue()).equals("b"));
-
+ togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel, null,
+ toggleControl));
+ assertFalse(((String) togglePanel.getValue()).equals("a"));
+ assertTrue(((String) togglePanel.getValue()).equals("b"));
+
toggleControl.setSwitchToState("a");
- togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel,"null", toggleControl));
- assertFalse(((String)togglePanel.getValue()).equals("b"));
- assertTrue(((String)togglePanel.getValue()).equals("a"));
-
+ togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel,
+ "null", toggleControl));
+ assertFalse(((String) togglePanel.getValue()).equals("b"));
+ assertTrue(((String) togglePanel.getValue()).equals("a"));
+
toggleControl.setSwitchToState(null);
togglePanel.setStateOrder("c,b,a");
- togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel,"null", toggleControl));
- assertFalse(((String)togglePanel.getValue()).equals("a"));
- assertTrue(((String)togglePanel.getValue()).equals("c"));
+ togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel,
+ "null", toggleControl));
+ assertFalse(((String) togglePanel.getValue()).equals("a"));
+ assertTrue(((String) togglePanel.getValue()).equals("c"));
-
togglePanel.setValue(null);
togglePanel.setStateOrder("c,b,a");
- togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel,"null", toggleControl));
- assertTrue(((String)togglePanel.getValue()).equals("c"));
-
+ togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel,
+ "null", toggleControl));
+ assertTrue(((String) togglePanel.getValue()).equals("c"));
- toggleControl.setSwitchToState("d");
+ toggleControl.setSwitchToState("d");
try {
- togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel,"null", toggleControl));
+ togglePanel.broadcast(new SwitchablePanelSwitchEvent(togglePanel,
+ "null", toggleControl));
assertTrue(false);
- } catch(Exception ex) {
- }
- }
+ } catch (Exception ex) {
+ }
+ }
public void testgetPanel() throws Exception {
- assertTrue(toggleControl.getPanel().getId().equals(togglePanel.getId()));
- toggleControl.setFor("xxx");
+ assertTrue(toggleControl.getPanel().getId().equals(togglePanel.getId()));
+ toggleControl.setFor("xxx");
try {
- toggleControl.getPanel();
+ toggleControl.getPanel();
assertTrue(false);
- } catch(Exception ex) {
- }
- toggleControl.setFor(null);
+ } catch (Exception ex) {
+ }
+ toggleControl.setFor(null);
try {
- toggleControl.getPanel();
+ toggleControl.getPanel();
assertTrue(false);
- } catch(Exception ex) {
- }
+ } catch (Exception ex) {
+ }
+ }
-
+ /**
+ * Test for UITogglePanel & UIToggleControl classes methods.
+ *
+ * @throws Exception
+ */
+ public void testUIComponents() throws Exception {
+
+ togglePanel.setStateOrder("A,B,Y,B,C");
+ List stateOrderList = togglePanel.getStateOrderList();
+ assertNotNull(stateOrderList);
+ assertEquals(5, stateOrderList.size());
+
+ togglePanel.setStateOrder(null);
+ stateOrderList = togglePanel.getStateOrderList();
+ assertNotNull(stateOrderList);
+ assertEquals(0, stateOrderList.size());
+
+ Object switchValue = togglePanel.convertSwitchValue(new UIOutput(),
+ "ABYBC");
+ assertEquals("ABYBC", (String) switchValue);
+
+ toggleControl.setPanelId(togglePanel.getClientId(facesContext));
+ toggleControl.setReRender(togglePanel.getClientId(facesContext));
+ assertEquals(togglePanel.getClientId(facesContext), toggleControl
+ .getReRender());
+
+ toggleControl.setFor(null);
+ try {
+ toggleControl.getPanel();
+ assertTrue(false);
+ } catch (FacesException e) {
+ }
}
-
-}
+ /**
+ * Test for TogglePanel in "client" mode.
+ *
+ * @throws Exception
+ */
+ public void testTogglePanelInClientSwichMode() throws Exception {
+ togglePanel.setSwitchType(UITogglePanel.CLIENT_METHOD);
+ toggleControl.getAttributes().put("onclick", "someOnClick");
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ System.out.println(page.asXml());
+
+ HtmlElement div = page.getHtmlElementById(togglePanel
+ .getClientId(facesContext));
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ HtmlElement anchor = (HtmlElement) div.getHtmlElementById(toggleControl
+ .getClientId(facesContext));
+ assertNotNull(anchor);
+ String classAttr = anchor.getAttributeValue("onclick");
+ assertTrue(classAttr.contains("someOnClick;"));
+
+ List divs = div.getHtmlElementsByTagName("div");
+ assertTrue(divs.size() > 0);
+ assertEquals(togglePanel.getStateOrderList().size() + 1, 4);
+ div = (HtmlElement) divs.get(0);
+ assertNotNull(div);
+ classAttr = div.getAttributeValue("style");
+ assertTrue(classAttr.contains("display:"));
+ div = (HtmlElement) divs.get(togglePanel.getStateOrderList().size());
+ assertNotNull(div);
+ classAttr = div.getAttributeValue("style");
+ assertTrue(classAttr.contains("display: none;"));
+ }
+
+ /**
+ * Test "doDecode" method of TogglePanel. Component in "client" mode.
+ * Immediate is true.
+ */
+ public void testTogglePanelDoDecodeClientMode() throws Exception {
+
+ togglePanel.setImmediate(true);
+ togglePanel.setSwitchType(UITogglePanel.CLIENT_METHOD);
+
+ externalContext.getRequestParameterMap().put(
+ togglePanel.getClientId(facesContext), "ABYBC");
+ togglePanel.decode(facesContext);
+
+ MockViewRoot mockViewRoot = (MockViewRoot) facesContext.getViewRoot();
+ Buffer events = mockViewRoot.getEventsQueue(facesContext,
+ PhaseId.APPLY_REQUEST_VALUES);
+ assertNotNull(events);
+ assertEquals(1, events.size());
+
+ FacesEvent event = (FacesEvent) events.iterator().next();
+ assertTrue(event instanceof SwitchablePanelSwitchEvent);
+ SwitchablePanelSwitchEvent switchEvent = (SwitchablePanelSwitchEvent) event;
+ assertEquals(switchEvent.getValue(), "ABYBC");
+ }
+
+}
19 years
JBoss Rich Faces SVN: r422 - trunk/richfaces/datascroller/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: d.bulahov
Date: 2007-04-14 10:00:05 -0400 (Sat, 14 Apr 2007)
New Revision: 422
Modified:
trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java
Log:
Unit tests development
Modified: trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java
===================================================================
--- trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java 2007-04-14 11:59:48 UTC (rev 421)
+++ trunk/richfaces/datascroller/src/test/java/org/richfaces/component/DatascrollerComponentTest.java 2007-04-14 14:00:05 UTC (rev 422)
@@ -36,6 +36,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.ArrayList;
/**
* Unit test for Datascroller component.
@@ -76,8 +77,12 @@
form = new HtmlForm();
form.setId("form");
facesContext.getViewRoot().getChildren().add(form);
-
+ ArrayList dat = new ArrayList();
+ for (int i=0;i<20;i++){
+ dat.add(new Integer(i));
+ }
data = (UIData) application.createComponent(HtmlDataTable.COMPONENT_TYPE);
+ data.setValue(dat);
data.setId("data");
data.setRows(5);
form.getChildren().add(data);
@@ -161,6 +166,26 @@
String classAttr = div.getAttributeValue("class");
assertTrue(classAttr.contains("dr-dscr"));
assertTrue(classAttr.contains("rich-datascr"));
+
+
+ scroller.processDecodes(facesContext);
+ scroller.processValidators(facesContext);
+ scroller.processUpdates(facesContext);
+ scroller.setFor("xxx");
+ try {
+ page = renderView();
+ assertTrue(false);
+ } catch(Exception ex) {
+ }
+ scroller.processDecodes(facesContext);
+ scroller.processValidators(facesContext);
+ scroller.processUpdates(facesContext);
+ scroller.setFor("form");
+ try {
+ page = renderView();
+ assertTrue(false);
+ } catch(Exception ex) {
+ }
}
/**
@@ -300,4 +325,37 @@
data.setMaxRow(13);
assertEquals(13, bs.search(data));
}
+
+ public void testSetPage() throws Exception {
+ assertEquals(4,scroller.getPageCount());
+ scroller.setPage("2");
+ scroller.setFastStep(2);
+ assertEquals(5,data.getFirst());
+ scroller.setPage("next");
+ assertEquals(10,data.getFirst());
+ scroller.setPage("previous");
+ assertEquals(5,data.getFirst());
+ scroller.setPage("fastforward");
+ assertEquals(15,data.getFirst());
+ scroller.setPage("fastrewind");
+ assertEquals(5,data.getFirst());
+ scroller.setPage("first");
+ assertEquals(0,data.getFirst());
+ scroller.setPage("previous");
+ assertEquals(0,data.getFirst());
+ scroller.setPage("fastrewind");
+ assertEquals(0,data.getFirst());
+ scroller.setPage("last");
+ assertEquals(15,data.getFirst());
+ scroller.setPage("next");
+ assertEquals(15,data.getFirst());
+ scroller.setPage("fastforward");
+ assertEquals(15,data.getFirst());
+ scroller.setPage("5");
+ assertEquals(15,data.getFirst());
+ scroller.setPage("0");
+ assertEquals(0,data.getFirst());
+ data.setRows(0);
+
+ }
}
19 years
JBoss Rich Faces SVN: r421 - in trunk/richfaces/tree/src/test/java/org/richfaces/component: state and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-14 07:59:48 -0400 (Sat, 14 Apr 2007)
New Revision: 421
Added:
trunk/richfaces/tree/src/test/java/org/richfaces/component/state/
trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/
trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/CollapseAllCommandEventTest.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/CollapseNodeCommandEventTest.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/ExpandAllCommandEventTest.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/ExpandNodeCommandEventTest.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/MockTreeStateCommandsListener.java
Log:
Tree state events tests added
Added: trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/CollapseAllCommandEventTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/CollapseAllCommandEventTest.java (rev 0)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/CollapseAllCommandEventTest.java 2007-04-14 11:59:48 UTC (rev 421)
@@ -0,0 +1,99 @@
+/**
+ * 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.state.events;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIOutput;
+import javax.faces.event.FacesListener;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 14.04.2007
+ *
+ */
+public class CollapseAllCommandEventTest extends TestCase {
+
+ private CollapseAllCommandEvent event;
+ /**
+ * @param name
+ */
+ public CollapseAllCommandEventTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.event = new CollapseAllCommandEvent(new UIOutput());
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ this.event = null;
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#isAppropriateListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testIsAppropriateListenerFacesListener() {
+ assertTrue((event.isAppropriateListener(new MockTreeStateCommandsListener())));
+ assertFalse((event.isAppropriateListener(new FacesListener() {
+
+ })));
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#processListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testProcessListenerFacesListener() {
+ MockTreeStateCommandsListener listener = new MockTreeStateCommandsListener();
+
+ event.processListener(listener);
+ assertTrue(listener.isCollapseAll());
+ assertFalse(listener.isExpandAll());
+ assertNull(listener.getExpandNode());
+ assertNull(listener.getCollapseNode());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#processListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testProcessListenerExceptionHandle() {
+ MockTreeStateCommandsListener listener = new MockExceptionTreeStateCommandsListener();
+
+ try {
+ event.processListener(listener);
+
+ fail();
+ } catch (FacesException e) {
+ }
+ }
+}
Added: trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/CollapseNodeCommandEventTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/CollapseNodeCommandEventTest.java (rev 0)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/CollapseNodeCommandEventTest.java 2007-04-14 11:59:48 UTC (rev 421)
@@ -0,0 +1,113 @@
+/**
+ * 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.state.events;
+
+import java.util.ArrayList;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIOutput;
+import javax.faces.event.FacesListener;
+
+import org.richfaces.component.ListRowKey;
+import org.richfaces.component.TreeRowKey;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 14.04.2007
+ *
+ */
+public class CollapseNodeCommandEventTest extends TestCase {
+
+ private CollapseNodeCommandEvent event;
+ private TreeRowKey treeRowKey;
+
+ /**
+ * @param name
+ */
+ public CollapseNodeCommandEventTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ ArrayList keyBase = new ArrayList();
+ keyBase.add("string");
+ keyBase.add(new Object());
+ keyBase.add(new Long(-17));
+
+ this.treeRowKey = new ListRowKey(keyBase);
+ this.event = new CollapseNodeCommandEvent(new UIOutput(), treeRowKey);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ this.event = null;
+ this.treeRowKey = null;
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#isAppropriateListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testIsAppropriateListenerFacesListener() {
+ assertTrue((event.isAppropriateListener(new MockTreeStateCommandsListener())));
+ assertFalse((event.isAppropriateListener(new FacesListener() {
+
+ })));
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#processListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testProcessListenerFacesListener() {
+ MockTreeStateCommandsListener listener = new MockTreeStateCommandsListener();
+
+ event.processListener(listener);
+ assertSame(treeRowKey, listener.getCollapseNode());
+ assertFalse(listener.isExpandAll());
+ assertFalse(listener.isCollapseAll());
+ assertNull(listener.getExpandNode());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#processListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testProcessListenerExceptionHandle() {
+ MockTreeStateCommandsListener listener = new MockExceptionTreeStateCommandsListener();
+
+ try {
+ event.processListener(listener);
+
+ fail();
+ } catch (FacesException e) {
+ }
+ }
+}
Added: trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/ExpandAllCommandEventTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/ExpandAllCommandEventTest.java (rev 0)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/ExpandAllCommandEventTest.java 2007-04-14 11:59:48 UTC (rev 421)
@@ -0,0 +1,99 @@
+/**
+ * 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.state.events;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIOutput;
+import javax.faces.event.FacesListener;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 14.04.2007
+ *
+ */
+public class ExpandAllCommandEventTest extends TestCase {
+
+ private ExpandAllCommandEvent event;
+ /**
+ * @param name
+ */
+ public ExpandAllCommandEventTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.event = new ExpandAllCommandEvent(new UIOutput());
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ this.event = null;
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#isAppropriateListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testIsAppropriateListenerFacesListener() {
+ assertTrue((event.isAppropriateListener(new MockTreeStateCommandsListener())));
+ assertFalse((event.isAppropriateListener(new FacesListener() {
+
+ })));
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#processListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testProcessListenerFacesListener() {
+ MockTreeStateCommandsListener listener = new MockTreeStateCommandsListener();
+
+ event.processListener(listener);
+ assertTrue(listener.isExpandAll());
+ assertFalse(listener.isCollapseAll());
+ assertNull(listener.getExpandNode());
+ assertNull(listener.getCollapseNode());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#processListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testProcessListenerExceptionHandle() {
+ MockTreeStateCommandsListener listener = new MockExceptionTreeStateCommandsListener();
+
+ try {
+ event.processListener(listener);
+
+ fail();
+ } catch (FacesException e) {
+ }
+ }
+}
Added: trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/ExpandNodeCommandEventTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/ExpandNodeCommandEventTest.java (rev 0)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/ExpandNodeCommandEventTest.java 2007-04-14 11:59:48 UTC (rev 421)
@@ -0,0 +1,113 @@
+/**
+ * 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.state.events;
+
+import java.util.ArrayList;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIOutput;
+import javax.faces.event.FacesListener;
+
+import org.richfaces.component.ListRowKey;
+import org.richfaces.component.TreeRowKey;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 14.04.2007
+ *
+ */
+public class ExpandNodeCommandEventTest extends TestCase {
+
+ private ExpandNodeCommandEvent event;
+ private TreeRowKey treeRowKey;
+
+ /**
+ * @param name
+ */
+ public ExpandNodeCommandEventTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ ArrayList keyBase = new ArrayList();
+ keyBase.add("string");
+ keyBase.add(new Object());
+ keyBase.add(new Long(-17));
+
+ this.treeRowKey = new ListRowKey(keyBase);
+ this.event = new ExpandNodeCommandEvent(new UIOutput(), treeRowKey);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ this.event = null;
+ this.treeRowKey = null;
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#isAppropriateListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testIsAppropriateListenerFacesListener() {
+ assertTrue((event.isAppropriateListener(new MockTreeStateCommandsListener())));
+ assertFalse((event.isAppropriateListener(new FacesListener() {
+
+ })));
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#processListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testProcessListenerFacesListener() {
+ MockTreeStateCommandsListener listener = new MockTreeStateCommandsListener();
+
+ event.processListener(listener);
+ assertSame(treeRowKey, listener.getExpandNode());
+ assertFalse(listener.isExpandAll());
+ assertFalse(listener.isCollapseAll());
+ assertNull(listener.getCollapseNode());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.state.events.TreeStateCommandEvent#processListener(javax.faces.event.FacesListener)}.
+ */
+ public final void testProcessListenerExceptionHandle() {
+ MockTreeStateCommandsListener listener = new MockExceptionTreeStateCommandsListener();
+
+ try {
+ event.processListener(listener);
+
+ fail();
+ } catch (FacesException e) {
+ }
+ }
+}
Added: trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/MockTreeStateCommandsListener.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/MockTreeStateCommandsListener.java (rev 0)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/state/events/MockTreeStateCommandsListener.java 2007-04-14 11:59:48 UTC (rev 421)
@@ -0,0 +1,92 @@
+/**
+ * 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.state.events;
+
+import java.io.IOException;
+
+import org.richfaces.component.TreeRowKey;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 14.04.2007
+ *
+ */
+class MockTreeStateCommandsListener implements TreeStateCommandsListener {
+
+ private boolean collapseAll;
+ private boolean expandAll;
+ private TreeRowKey collapseNode;
+ private TreeRowKey expandNode;
+
+ public void collapseAll() throws IOException {
+ this.collapseAll = true;
+ }
+
+ public void collapseNode(TreeRowKey rowKey) throws IOException {
+ this.collapseNode = rowKey;
+ }
+
+ public void expandAll() throws IOException {
+ this.expandAll = true;
+ }
+
+ public void expandNode(TreeRowKey rowKey) throws IOException {
+ this.expandNode = rowKey;
+ }
+
+ public boolean isCollapseAll() {
+ return collapseAll;
+ }
+
+ public boolean isExpandAll() {
+ return expandAll;
+ }
+
+ public TreeRowKey getCollapseNode() {
+ return collapseNode;
+ }
+
+ public TreeRowKey getExpandNode() {
+ return expandNode;
+ }
+
+}
+
+class MockExceptionTreeStateCommandsListener extends MockTreeStateCommandsListener {
+
+ public void collapseAll() throws IOException {
+ throw new IOException();
+ }
+
+ public void collapseNode(TreeRowKey rowKey) throws IOException {
+ throw new IOException();
+ }
+
+ public void expandAll() throws IOException {
+ throw new IOException();
+ }
+
+ public void expandNode(TreeRowKey rowKey) throws IOException {
+ throw new IOException();
+ }
+
+}
19 years
JBoss Rich Faces SVN: r420 - trunk/richfaces/dataTable/src/test/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: F.antonov
Date: 2007-04-14 07:59:14 -0400 (Sat, 14 Apr 2007)
New Revision: 420
Added:
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataDefinitionListComponentsTest.java
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataListComponentsTest.java
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataOrderedListComponentsTest.java
Removed:
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java
Log:
DataTable components test cases development.
Deleted: trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java
===================================================================
--- trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java 2007-04-14 01:22:47 UTC (rev 419)
+++ trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java 2007-04-14 11:59:14 UTC (rev 420)
@@ -1,123 +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.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIOutput;
-import javax.faces.component.html.HtmlOutputText;
-import javax.faces.model.ListDataModel;
-
-import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.richfaces.component.html.HtmlColumnGroup;
-import org.richfaces.component.html.HtmlColumn;
-
-import com.gargoylesoftware.htmlunit.html.HtmlElement;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-
-/**
- * Unit test for DataList component.
- */
-public class AbstractListComponentsTest extends AbstractAjax4JsfTestCase {
-
- private UIDataList dataList;
-
- /**
- * Create the test case
- *
- * @param testName
- * name of the test case
- */
- public AbstractListComponentsTest(String testName) {
- super(testName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
- */
- public void setUp() throws Exception {
- super.setUp();
-
- dataList = (UIDataList) application
- .createComponent("org.richfaces.DataList");
- dataList.setId("dataList");
-
- List list = new ArrayList();
- for (int i = 1; i <= 10; i++) {
- list.add(new Date((long) Math.random()));
- }
- dataList.setValue(list);
-
- facesContext.getViewRoot().getChildren().add(dataList);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
- */
- public void tearDown() throws Exception {
- super.tearDown();
- dataList = null;
- }
-
- /**
- * Test DataList component rendering.
- *
- * @throws Exception
- */
- public void testRenderDataList() throws Exception {
-
- HtmlPage page = renderView();
- assertNotNull(page);
- // System.out.println(page.asXml());
-
- // TYPE=disc|circle|square
- dataList.getAttributes().put("type", "circle");
-
- HtmlElement ul = page.getHtmlElementById(dataList
- .getClientId(facesContext));
- assertNotNull(ul);
- assertEquals("ul", ul.getNodeName());
- String classAttr = ul.getAttributeValue("class");
- assertTrue(classAttr.contains("dr-list rich-datalist"));
-
- List lis = ul.getHtmlElementsByTagName("li");
- assertTrue(lis.size() > 0);
- assertEquals(lis.size(), 10);
- HtmlElement li = (HtmlElement) lis.get(0);
- assertNotNull(li);
- classAttr = li.getAttributeValue("class");
- assertTrue(classAttr.contains("dr-list-item rich-list-item"));
-
- }
-
-}
Copied: trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataDefinitionListComponentsTest.java (from rev 419, trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java)
===================================================================
--- trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataDefinitionListComponentsTest.java (rev 0)
+++ trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataDefinitionListComponentsTest.java 2007-04-14 11:59:14 UTC (rev 420)
@@ -0,0 +1,215 @@
+/**
+ * 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.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.html.HtmlOutputLink;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+import javax.faces.model.ListDataModel;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlColumnGroup;
+import org.richfaces.component.html.HtmlColumn;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * Unit test for DataDefinitionList component.
+ */
+public class DataDefinitionListComponentsTest extends AbstractAjax4JsfTestCase {
+
+ private UIDataList dataList;
+
+ /**
+ * Create the test case
+ *
+ * @param testName
+ * name of the test case
+ */
+ public DataDefinitionListComponentsTest(String testName) {
+ super(testName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+
+ dataList = (UIDataList) application
+ .createComponent("org.richfaces.DataDefinitionList");
+ dataList.setId("dataDefinitionList");
+
+ List list = new ArrayList();
+ for (int i = 1; i <= 5; i++) {
+ list.add(new Date((long) Math.random()));
+ }
+ dataList.setValue(new ListDataModel(list));
+
+ UIOutput element1 = (UIOutput) createComponent(
+ HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
+ null, null, null);
+ element1.setValueBinding("value", new ValueBinding() {
+ public Class getType(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return String.class;
+ }
+
+ public Object getValue(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return Long.toString(((Date) dataList.getValue()).getTime());
+ }
+
+ public boolean isReadOnly(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext context, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+ }
+ });
+ dataList.getChildren().add(element1);
+
+ UIOutput element2 = (UIOutput) createComponent(
+ HtmlOutputText.COMPONENT_TYPE, HtmlOutputLink.class.getName(),
+ null, null, null);
+ element2.setValueBinding("value", new ValueBinding() {
+ public Class getType(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return String.class;
+ }
+
+ public Object getValue(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return Long.toString(((Date) dataList.getValue()).getTime());
+ }
+
+ public boolean isReadOnly(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext context, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+ }
+ });
+ dataList.getChildren().add(element2);
+
+ facesContext.getViewRoot().getChildren().add(dataList);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ dataList = null;
+ }
+
+ /**
+ * Test DataDefinitionList component rendering.
+ *
+ * @throws Exception
+ */
+ public void testRenderDataDefinitionList() throws Exception {
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ // System.out.println(page.asXml());
+
+ HtmlElement dl = page.getHtmlElementById(dataList
+ .getClientId(facesContext));
+ assertNotNull(dl);
+ assertEquals("dl", dl.getNodeName());
+ String classAttr = dl.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-deflist rich-deflist"));
+
+ List dds = dl.getHtmlElementsByTagName("dd");
+ assertTrue(dds.size() > 0);
+ assertEquals(dds.size(), 5);
+ HtmlElement dd = (HtmlElement) dds.get(0);
+ assertNotNull(dd);
+ classAttr = dd.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-definition rich-definition"));
+ }
+
+ /**
+ * Test DataDefinitionList component facet rendering.
+ *
+ * @throws Exception
+ */
+ public void testDataDefinitionListFacet() throws Exception {
+
+ UIOutput facet = (UIOutput) createComponent(
+ HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
+ null, null, null);
+ facet.setValue("Term facet");
+ dataList.getFacets().put("term", facet);
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ // System.out.println(page.asXml());
+
+ HtmlElement dl = page.getHtmlElementById(dataList
+ .getClientId(facesContext));
+ assertNotNull(dl);
+ assertEquals("dl", dl.getNodeName());
+ String classAttr = dl.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-deflist rich-deflist"));
+
+ List dts = dl.getHtmlElementsByTagName("dt");
+ assertTrue(dts.size() > 0);
+ assertEquals(dts.size(), 5);
+ HtmlElement dt = (HtmlElement) dts.get(0);
+ assertNotNull(dt);
+ classAttr = dt.getAttributeValue("class");
+ assertTrue(classAttr
+ .contains("dr-definition-term rich-definition-term"));
+
+ List dds = dl.getHtmlElementsByTagName("dd");
+ assertTrue(dds.size() > 0);
+ assertEquals(dds.size(), 5);
+ HtmlElement dd = (HtmlElement) dds.get(0);
+ assertNotNull(dd);
+ classAttr = dd.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-definition rich-definition"));
+ }
+}
Copied: trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataListComponentsTest.java (from rev 419, trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java)
===================================================================
--- trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataListComponentsTest.java (rev 0)
+++ trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataListComponentsTest.java 2007-04-14 11:59:14 UTC (rev 420)
@@ -0,0 +1,180 @@
+/**
+ * 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.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.html.HtmlOutputLink;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+import javax.faces.model.ListDataModel;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlColumnGroup;
+import org.richfaces.component.html.HtmlColumn;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * Unit test for DataList component.
+ */
+public class DataListComponentsTest extends AbstractAjax4JsfTestCase {
+
+ private UIDataList dataList;
+
+ /**
+ * Create the test case
+ *
+ * @param testName
+ * name of the test case
+ */
+ public DataListComponentsTest(String testName) {
+ super(testName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+
+ dataList = (UIDataList) application
+ .createComponent("org.richfaces.DataList");
+ dataList.setId("dataList");
+
+ List list = new ArrayList();
+ for (int i = 1; i <= 5; i++) {
+ list.add(new Date((long) Math.random()));
+ }
+ dataList.setValue(new ListDataModel(list));
+
+ UIOutput element1 = (UIOutput) createComponent(
+ HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
+ null, null, null);
+ element1.setValueBinding("value", new ValueBinding() {
+ public Class getType(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return String.class;
+ }
+
+ public Object getValue(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return Long.toString(((Date) dataList.getValue()).getTime());
+ }
+
+ public boolean isReadOnly(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext context, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+ }
+ });
+ dataList.getChildren().add(element1);
+
+ UIOutput element2 = (UIOutput) createComponent(
+ HtmlOutputText.COMPONENT_TYPE, HtmlOutputLink.class.getName(),
+ null, null, null);
+ element2.setValueBinding("value", new ValueBinding() {
+ public Class getType(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return String.class;
+ }
+
+ public Object getValue(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return Long.toString(((Date) dataList.getValue()).getTime());
+ }
+
+ public boolean isReadOnly(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext context, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+ }
+ });
+ dataList.getChildren().add(element2);
+
+ facesContext.getViewRoot().getChildren().add(dataList);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ dataList = null;
+ }
+
+ /**
+ * Test DataList component rendering.
+ *
+ * @throws Exception
+ */
+ public void testRenderDataList() throws Exception {
+
+ // TYPE=disc|circle|square
+ dataList.getAttributes().put("type", "circle");
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ // System.out.println(page.asXml());
+
+ HtmlElement ul = page.getHtmlElementById(dataList
+ .getClientId(facesContext));
+ assertNotNull(ul);
+ assertEquals("ul", ul.getNodeName());
+ String classAttr = ul.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-list rich-datalist"));
+ classAttr = ul.getAttributeValue("type");
+ assertTrue(classAttr.contains((String) dataList.getAttributes().get(
+ "type")));
+
+ List lis = ul.getHtmlElementsByTagName("li");
+ assertTrue(lis.size() > 0);
+ assertEquals(lis.size(), 5);
+ HtmlElement li = (HtmlElement) lis.get(0);
+ assertNotNull(li);
+ classAttr = li.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-list-item rich-list-item"));
+ }
+
+}
Copied: trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataOrderedListComponentsTest.java (from rev 419, trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java)
===================================================================
--- trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataOrderedListComponentsTest.java (rev 0)
+++ trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataOrderedListComponentsTest.java 2007-04-14 11:59:14 UTC (rev 420)
@@ -0,0 +1,180 @@
+/**
+ * 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.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.html.HtmlOutputLink;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+import javax.faces.model.ListDataModel;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlColumnGroup;
+import org.richfaces.component.html.HtmlColumn;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * Unit test for DataOrderedList component.
+ */
+public class DataOrderedListComponentsTest extends AbstractAjax4JsfTestCase {
+
+ private UIDataList dataList;
+
+ /**
+ * Create the test case
+ *
+ * @param testName
+ * name of the test case
+ */
+ public DataOrderedListComponentsTest(String testName) {
+ super(testName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+
+ dataList = (UIDataList) application
+ .createComponent("org.richfaces.DataOrderedList");
+ dataList.setId("DataOrderedList");
+
+ List list = new ArrayList();
+ for (int i = 1; i <= 5; i++) {
+ list.add(new Date((long) Math.random()));
+ }
+ dataList.setValue(new ListDataModel(list));
+
+ UIOutput element1 = (UIOutput) createComponent(
+ HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
+ null, null, null);
+ element1.setValueBinding("value", new ValueBinding() {
+ public Class getType(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return String.class;
+ }
+
+ public Object getValue(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return Long.toString(((Date) dataList.getValue()).getTime());
+ }
+
+ public boolean isReadOnly(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext context, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+ }
+ });
+ dataList.getChildren().add(element1);
+
+ UIOutput element2 = (UIOutput) createComponent(
+ HtmlOutputText.COMPONENT_TYPE, HtmlOutputLink.class.getName(),
+ null, null, null);
+ element2.setValueBinding("value", new ValueBinding() {
+ public Class getType(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return String.class;
+ }
+
+ public Object getValue(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return Long.toString(((Date) dataList.getValue()).getTime());
+ }
+
+ public boolean isReadOnly(FacesContext context)
+ throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext context, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+ }
+ });
+ dataList.getChildren().add(element2);
+
+ facesContext.getViewRoot().getChildren().add(dataList);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ dataList = null;
+ }
+
+ /**
+ * Test DataOrderedList component rendering.
+ *
+ * @throws Exception
+ */
+ public void testRenderDataOrderedList() throws Exception {
+
+ // TYPE=disc|circle|square
+ dataList.getAttributes().put("type", "circle");
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ // System.out.println(page.asXml());
+
+ HtmlElement ol = page.getHtmlElementById(dataList
+ .getClientId(facesContext));
+ assertNotNull(ol);
+ assertEquals("ol", ol.getNodeName());
+ String classAttr = ol.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-list rich-orderedlist"));
+ classAttr = ol.getAttributeValue("type");
+ assertTrue(classAttr.contains((String) dataList.getAttributes().get(
+ "type")));
+
+ List lis = ol.getHtmlElementsByTagName("li");
+ assertTrue(lis.size() > 0);
+ assertEquals(lis.size(), 5);
+ HtmlElement li = (HtmlElement) lis.get(0);
+ assertNotNull(li);
+ classAttr = li.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-list-item rich-list-item"));
+ }
+
+}
19 years