[richfaces-svn-commits] JBoss Rich Faces SVN: r328 - in trunk/richfaces/modal-panel/src: test/java/org/richfaces/component and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Apr 9 14:08:12 EDT 2007


Author: sergeyhalipov
Date: 2007-04-09 14:08:12 -0400 (Mon, 09 Apr 2007)
New Revision: 328

Added:
   trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/ModalPanelComponentTest.java
Removed:
   trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/JSFComponentTest.java
Modified:
   trunk/richfaces/modal-panel/src/main/java/org/richfaces/component/UIModalPanel.java
Log:
JUnit tests for modal panel component.

Modified: trunk/richfaces/modal-panel/src/main/java/org/richfaces/component/UIModalPanel.java
===================================================================
--- trunk/richfaces/modal-panel/src/main/java/org/richfaces/component/UIModalPanel.java	2007-04-09 17:43:32 UTC (rev 327)
+++ trunk/richfaces/modal-panel/src/main/java/org/richfaces/component/UIModalPanel.java	2007-04-09 18:08:12 UTC (rev 328)
@@ -29,7 +29,7 @@
  */
 public abstract class UIModalPanel extends UIComponentBase {
 	
-	private static final String COMPONENT_TYPE = "org.richfaces.ModalPanel";
+	public static final String COMPONENT_TYPE = "org.richfaces.ModalPanel";
 	
 	private static final String COMPONENT_FAMILY = "org.richfaces.ModalPanel";
 

Deleted: trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/JSFComponentTest.java	2007-04-09 17:43:32 UTC (rev 327)
+++ trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/JSFComponentTest.java	2007-04-09 18:08:12 UTC (rev 328)
@@ -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 );
-    }
-}

Copied: trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/ModalPanelComponentTest.java (from rev 321, trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/JSFComponentTest.java)
===================================================================
--- trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/ModalPanelComponentTest.java	                        (rev 0)
+++ trunk/richfaces/modal-panel/src/test/java/org/richfaces/component/ModalPanelComponentTest.java	2007-04-09 18:08:12 UTC (rev 328)
@@ -0,0 +1,175 @@
+/**
+ * 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.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+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.HtmlForm;
+import javax.faces.component.html.HtmlOutputText;
+
+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 simple Component.
+ */
+public class ModalPanelComponentTest extends AbstractAjax4JsfTestCase {
+	private static Set javaScripts = new HashSet();
+
+    static {
+    	javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
+    	javaScripts.add("prototype.js");
+        javaScripts.add("scripts/utils.js");
+        javaScripts.add("scripts/modalPanel.js");
+        javaScripts.add("scripts/modalPanelBorders.js");
+        javaScripts.add("scripts/browser_info.js");
+    }
+	
+    private UIComponent modalPanel;
+    private UIComponent form;
+    
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public ModalPanelComponentTest( String testName )
+    {
+        super( testName );
+    }
+
+    /* (non-Javadoc)
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+     */
+    public void setUp() throws Exception {
+        super.setUp();
+        
+        form = new HtmlForm();
+    	facesContext.getViewRoot().getChildren().add(form);
+    	
+    	modalPanel = application.createComponent(UIModalPanel.COMPONENT_TYPE);
+    	modalPanel.setId("modalPanel");
+    	
+    	HtmlOutputText outputText = new HtmlOutputText();
+    	outputText.setValue("test");
+    	modalPanel.getFacets().put("header", outputText);
+    	
+    	form.getChildren().add(modalPanel);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+     */
+    public void tearDown() throws Exception {
+        super.tearDown();
+        form = null;
+        modalPanel = null;
+    }
+    
+    /**
+     * Test component renders correctly
+     *  
+     * @throws Exception
+     */
+    public void testRender() throws Exception {
+    	HtmlPage renderedView = renderView();
+    	
+    	assertNotNull(renderedView);
+    	
+    	HtmlElement htmlModalPanel = renderedView.getHtmlElementById(modalPanel.getClientId(facesContext));
+    	assertNotNull(htmlModalPanel);
+    	assertEquals("div", htmlModalPanel.getNodeName());
+    	
+    	HtmlElement htmlModalPanelCDiv = renderedView.getHtmlElementById(modalPanel.getClientId(facesContext) + "CDiv");
+    	assertNotNull(htmlModalPanelCDiv);
+    	assertTrue(htmlModalPanelCDiv.getAttributeValue("class").contains("dr-mpnl-panel rich-mpnl_panel"));
+    	
+    	HtmlElement htmlContentDiv = renderedView.getHtmlElementById(modalPanel.getClientId(facesContext) + "ContentDiv");
+    	assertNotNull(htmlContentDiv);
+    	assertTrue(htmlContentDiv.getAttributeValue("class").contains("dr-mpnl-pnl"));
+    	
+    	HtmlElement header = renderedView.getHtmlElementById(modalPanel.getClientId(facesContext) + "Header");
+    	assertNotNull(header);
+    	System.out.println(header.getAttributeValue("class"));
+    	assertTrue(header.getAttributeValue("class").contains("dr-mpnl-pnl-text dr-mpnl-pnl-h"));
+    	assertTrue(header.getAttributeValue("class").contains("rich-mpnl-text"));
+    	assertTrue(header.getAttributeValue("class").contains("rich-mpnl-header"));
+    }
+    
+    /**
+     * Test style rendering
+     *
+     * @throws Exception
+     */
+    public void testRenderStyle() throws Exception {
+        HtmlPage page = renderView();
+        assertNotNull(page);
+        List links = page.getDocumentElement().getHtmlElementsByTagName("link");
+
+        assertEquals(1, links.size());
+        HtmlElement link = (HtmlElement) links.get(0);
+        assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/modalPanel.xcss"));
+    }
+    
+    /**
+     * Test script rendering
+     *
+     * @throws Exception
+     */
+    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();
+
+            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);
+            }
+        }
+    }
+    
+}




More information about the richfaces-svn-commits mailing list