Author: sergeyhalipov
Date: 2007-11-28 14:53:51 -0500 (Wed, 28 Nov 2007)
New Revision: 4330
Added:
branches/3.1.x/ui/contextMenu/src/test/java/org/richfaces/component/ContextMenuComponentTest.java
Removed:
branches/3.1.x/ui/contextMenu/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
http://jira.jboss.com/jira/browse/RF-1302
JUnit tests for context menu (not finished).
Copied:
branches/3.1.x/ui/contextMenu/src/test/java/org/richfaces/component/ContextMenuComponentTest.java
(from rev 4308,
branches/3.1.x/ui/contextMenu/src/test/java/org/richfaces/component/JSFComponentTest.java)
===================================================================
---
branches/3.1.x/ui/contextMenu/src/test/java/org/richfaces/component/ContextMenuComponentTest.java
(rev 0)
+++
branches/3.1.x/ui/contextMenu/src/test/java/org/richfaces/component/ContextMenuComponentTest.java 2007-11-28
19:53:51 UTC (rev 4330)
@@ -0,0 +1,190 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIOutput;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.lang.StringUtils;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+/**
+ * Unit test for context menu component.
+ */
+public class ContextMenuComponentTest extends AbstractAjax4JsfTestCase {
+ private static Set javaScripts = new HashSet();
+
+ private UIContextMenu menu = null;
+ private HtmlForm form = null;
+ private UIOutput output = null;
+ private UIMenuItem menuItem = null;
+
+ static {
+ javaScripts.add("org.ajax4jsf.javascript.PrototypeScript");
+ javaScripts.add("org.ajax4jsf.javascript.AjaxScript");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/utils.js");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/json/json-dom.js");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/context-menu.js");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/menu.js");
+ }
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public ContextMenuComponentTest( String testName ) {
+ super( testName );
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ application.addComponent(UIContextMenu.COMPONENT_TYPE,
"org.richfaces.component.html.ContextMenu");
+ application.addComponent(UIMenuItem.COMPONENT_TYPE,
"org.richfaces.component.html.HtmlMenuItem");
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ output = new UIOutput();
+ output.setId("output");
+ output.setValue("value");
+
+ menu = (UIContextMenu)application.createComponent(UIContextMenu.COMPONENT_TYPE);
+ menu.setId("contextMenu");
+ output.getChildren().add(menu);
+
+ menuItem = (UIMenuItem)application.createComponent(UIMenuItem.COMPONENT_TYPE);
+ menuItem.setId("menuItem");
+ menuItem.setValue("value");
+ menu.getChildren().add(menuItem);
+
+ form.getChildren().add(output);
+ }
+
+ public void tearDown() throws Exception {
+ menu = null;
+ form = null;
+ output = null;
+
+ super.tearDown();
+ }
+
+ /**
+ * Test script rendering
+ *
+ * @throws Exception
+ */
+ public void testRenderScript() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ System.out.println(page.asXml());
+ List scripts =
page.getDocumentElement().getHtmlElementsByTagName("script");
+ int foundCount = 0;
+ 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) {
+ foundCount++;
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+ assertEquals(foundCount, javaScripts.size());
+ }
+
+ /**
+ * Test common rendering
+ *
+ * @throws Exception
+ */
+ public void testRender() throws Exception {
+ HtmlPage view = renderView();
+ assertNotNull(view);
+
+ HtmlElement div = view.getHtmlElementById(menu.getClientId(facesContext));
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ HtmlElement script = (HtmlElement) div.getFirstChild();
+ assertNotNull(script);
+ assertEquals("script", script.getNodeName());
+
+ assertNull(script.getNextSibling());
+
+ menu.setEvent(null);
+ menu.setValueBinding("event", new ValueBinding() {
+
+ public Class getType(FacesContext arg0) throws EvaluationException,
+ PropertyNotFoundException {
+ return String.class;
+ }
+
+ public Object getValue(FacesContext arg0)
+ throws EvaluationException, PropertyNotFoundException {
+ return null;
+ }
+
+ public boolean isReadOnly(FacesContext arg0)
+ throws EvaluationException, PropertyNotFoundException {
+ return true;
+ }
+
+ public void setValue(FacesContext arg0, Object arg1)
+ throws EvaluationException, PropertyNotFoundException {
+ }
+
+ });
+ try {
+ renderView();
+ assertTrue("Attribute 'event' is not set, but exception isn't
thrown!", false);
+ } catch (FacesException e) {
+
+ }
+ }
+
+}
Deleted:
branches/3.1.x/ui/contextMenu/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
---
branches/3.1.x/ui/contextMenu/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-11-28
18:52:05 UTC (rev 4329)
+++
branches/3.1.x/ui/contextMenu/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-11-28
19:53:51 UTC (rev 4330)
@@ -1,53 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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 );
- }
-}