Author: maksimkaszynski
Date: 2008-03-25 12:17:30 -0400 (Tue, 25 Mar 2008)
New Revision: 7183
Modified:
trunk/ui/menu-components/src/test/java/org/richfaces/component/MenuGroupComponentTest.java
trunk/ui/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java
Log:
http://jira.jboss.com/jira/browse/RF-2726
Modified:
trunk/ui/menu-components/src/test/java/org/richfaces/component/MenuGroupComponentTest.java
===================================================================
---
trunk/ui/menu-components/src/test/java/org/richfaces/component/MenuGroupComponentTest.java 2008-03-25
16:17:22 UTC (rev 7182)
+++
trunk/ui/menu-components/src/test/java/org/richfaces/component/MenuGroupComponentTest.java 2008-03-25
16:17:30 UTC (rev 7183)
@@ -22,11 +22,11 @@
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.UIComponentBase;
import javax.faces.component.UIForm;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputText;
@@ -37,22 +37,33 @@
import org.ajax4jsf.resource.ResourceBuilderImpl;
import org.ajax4jsf.resource.image.ImageInfo;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.apache.commons.lang.StringUtils;
+import org.ajax4jsf.tests.HtmlTestUtils;
import org.richfaces.component.html.HtmlMenuGroup;
import org.richfaces.renderkit.html.images.MenuNodeImage;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.gargoylesoftware.htmlunit.html.HtmlScript;
/**
* Unit test for MenuGroup Component.
*/
public class MenuGroupComponentTest extends AbstractAjax4JsfTestCase {
- private static Set javaScripts = new HashSet();
+ private static class UIMenu extends UIComponentBase implements MenuComponent {
+ @Override
+ public String getFamily() {
+ return null;
+ }
+ public String getSubmitMode() {
+ return null;
+ }
+ public void setSubmitMode(String submitMode) {
+ }
+ }
+ private static Set<String> javaScripts = new HashSet<String>();
+
static {
javaScripts.add("PrototypeScript");
javaScripts.add("AjaxScript");
@@ -79,12 +90,16 @@
form.setId("form");
facesContext.getViewRoot().getChildren().add(form);
+ UIMenu menu = new UIMenu();
+ menu.setId("menu");
+ form.getChildren().add(menu);
+
menuGroup = (HtmlMenuGroup) application
.createComponent(HtmlMenuGroup.COMPONENT_TYPE);
menuGroup.setId("menuGroup");
menuGroup.setValue("Menu Group");
- form.getChildren().add(menuGroup);
+ menu.getChildren().add(menuGroup);
}
public void tearDown() throws Exception {
@@ -250,27 +265,17 @@
public void testRenderScript() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
- // System.out.println(page.asXml());
- List scripts = page.getDocumentElement().getHtmlElementsByTagName(
- "script");
- 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);
- }
- }
+ List<String> scriptSources = HtmlTestUtils.extractScriptSources(page);
+ for (String javascript : javaScripts) {
+ boolean found = false;
+ for (String script : scriptSources) {
+ if (script.indexOf(javascript) >= 0) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue("Component script " + javascript + " is not found in
the response", found);
+ }
}
public void testRenderImages() throws Exception {
Modified:
trunk/ui/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java
===================================================================
---
trunk/ui/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java 2008-03-25
16:17:22 UTC (rev 7182)
+++
trunk/ui/menu-components/src/test/java/org/richfaces/component/MenuItemComponentTest.java 2008-03-25
16:17:30 UTC (rev 7183)
@@ -22,11 +22,11 @@
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.UIComponentBase;
import javax.faces.component.UIForm;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputText;
@@ -39,22 +39,34 @@
import org.ajax4jsf.resource.ResourceBuilderImpl;
import org.ajax4jsf.resource.image.ImageInfo;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.tests.HtmlTestUtils;
import org.ajax4jsf.tests.MockViewRoot;
-import org.apache.commons.collections.Buffer;
-import org.apache.commons.lang.StringUtils;
import org.richfaces.component.html.HtmlMenuItem;
import org.richfaces.renderkit.html.images.background.MenuItemBackground;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.gargoylesoftware.htmlunit.html.HtmlScript;
/**
* Unit test for MenuItem Component.
*/
public class MenuItemComponentTest extends AbstractAjax4JsfTestCase {
- private static Set javaScripts = new HashSet();
+
+ private static class UIMenu extends UIComponentBase implements MenuComponent {
+ @Override
+ public String getFamily() {
+ return null;
+ }
+ public String getSubmitMode() {
+ return null;
+ }
+ public void setSubmitMode(String submitMode) {
+ }
+ }
+
+
+ private static Set<String> javaScripts = new HashSet<String>();
static {
javaScripts.add("PrototypeScript");
@@ -66,6 +78,7 @@
private UIMenuItem menuItem;
+
private UIForm form;
/**
@@ -85,12 +98,16 @@
form.setId("form");
facesContext.getViewRoot().getChildren().add(form);
+ UIMenu menu = new UIMenu();
+ menu.setId("menu");
+ form.getChildren().add(menu);
+
menuItem = (UIMenuItem) application
.createComponent(HtmlMenuItem.COMPONENT_TYPE);
menuItem.setId("menuItem");
menuItem.setValue("Menu Item");
- form.getChildren().add(menuItem);
+ menu.getChildren().add(menuItem);
}
public void tearDown() throws Exception {
@@ -284,27 +301,17 @@
public void testRenderScript() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
- // System.out.println(page.asXml());
- List scripts = page.getDocumentElement().getHtmlElementsByTagName(
- "script");
- 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);
- }
- }
+ List<String> scriptSources = HtmlTestUtils.extractScriptSources(page);
+ for (String javascript : javaScripts) {
+ boolean found = false;
+ for (String script : scriptSources) {
+ if (script.indexOf(javascript) >= 0) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue("Component script " + javascript + " is not found in
the response", found);
+ }
}
/**