[richfaces-svn-commits] JBoss Rich Faces SVN: r243 - in trunk/richfaces/suggestionbox/src/test: resources/WEB-INF and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Apr 3 08:51:47 EDT 2007


Author: A.Skokov
Date: 2007-04-03 08:51:47 -0400 (Tue, 03 Apr 2007)
New Revision: 243

Added:
   trunk/richfaces/suggestionbox/src/test/resources/WEB-INF/log4j.xml
Modified:
   trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java
Log:
test updated

Modified: trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java
===================================================================
--- trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java	2007-04-03 11:51:34 UTC (rev 242)
+++ trunk/richfaces/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java	2007-04-03 12:51:47 UTC (rev 243)
@@ -23,44 +23,55 @@
 
 import com.gargoylesoftware.htmlunit.html.HtmlElement;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
 import junit.framework.Assert;
-import org.ajax4jsf.framework.ajax.AjaxViewHandler;
 import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.apache.shale.test.mock.MockViewHandler;
+import org.apache.commons.lang.StringUtils;
 import org.richfaces.component.html.HtmlSuggestionBox;
 import org.richfaces.renderkit.html.SuggestionBoxRenderer;
 
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIForm;
-import javax.faces.component.UIViewRoot;
 import javax.faces.component.html.HtmlInputText;
-import javax.faces.context.FacesContext;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 /**
- * Unit test for simple Component.
+ * Unit test for SuggestionBox component.
  */
 public class SuggestionBoxComponentTest extends AbstractAjax4JsfTestCase {
+    static Set sbScripts = new HashSet();
 
+    static {
+        sbScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
+        sbScripts.add("prototype.js");
+        sbScripts.add("org.ajax4jsf.framework.resource.SmartPositionScript");
+        sbScripts.add("org/richfaces/renderkit/html/scripts/browser_info.js");
+        sbScripts.add("org/richfaces/renderkit/html/scripts/scriptaculo.js");
+        sbScripts.add("org/richfaces/renderkit/html/scripts/suggestionbox.js");
+        sbScripts.add("org/richfaces/renderkit/html/scripts/suggestionbox.js");
+    }
 
-    HtmlSuggestionBox htmlSuggestionBox;
-    UIForm form;
+    HtmlSuggestionBox sb;
+    UIComponent form;
+    UIComponent input;
 
     /**
      * Create the test case
      *
      * @param testName name of the test case
      */
-    public SuggestionBoxComponentTest( String testName ) {
-        super( testName );
+    public SuggestionBoxComponentTest(String testName) {
+        super(testName);
     }
 
     public void setUp() throws Exception {
         super.setUp();
-        application.setViewHandler(new AjaxViewHandler(new MyMockViewHandler()));
 
-        UIComponent form = createComponent(UIForm.COMPONENT_TYPE, UIForm.class.getName(), null, null , null);
-        UIComponent input = createComponent(HtmlInputText.COMPONENT_TYPE, HtmlInputText.class.getName(), null, null , null);
+        form = createComponent(UIForm.COMPONENT_TYPE, UIForm.class.getName(), null, null, null);
+        input = createComponent(HtmlInputText.COMPONENT_TYPE, HtmlInputText.class.getName(), null, null, null);
 
         form.setId("form");
         input.setId("text");
@@ -68,76 +79,83 @@
 
         form.getChildren().add(input);
 
-        htmlSuggestionBox = new HtmlSuggestionBox();
-        htmlSuggestionBox.setId("suggestionBox");
-        htmlSuggestionBox.setFor(input.getId());
-        htmlSuggestionBox.setRendererType("suggestionBoxRenderer");
-        renderKit.addRenderer(HtmlSuggestionBox.COMPONENT_FAMILY, "suggestionBoxRenderer", new SuggestionBoxRenderer());
+        sb = new HtmlSuggestionBox();
+        sb.setId("suggestionBox");
+        sb.setFor(input.getId());
+        sb.setRendererType(HtmlSuggestionBox.COMPONENT_TYPE);
+        renderKit.addRenderer(HtmlSuggestionBox.COMPONENT_FAMILY, HtmlSuggestionBox.COMPONENT_TYPE, new SuggestionBoxRenderer());
 
-        form.getChildren().add(htmlSuggestionBox);
+        form.getChildren().add(sb);
     }
 
     public void tearDown() throws Exception {
         super.tearDown();
-        htmlSuggestionBox = null;
+        sb = null;
         form = null;
+        input = null;
     }
+
     /**
      * Rigourous Test :-)
+     *
      * @throws Exception
      */
     public void testRender() throws Exception {
         HtmlPage page = renderView();
         Assert.assertNotNull(page);
         System.out.println(page.asXml());
-        HtmlElement div = page.getHtmlElementById("form:suggestionBox");
+        HtmlElement div = page.getHtmlElementById(form.getId() + ":" + sb.getId());
         Assert.assertNotNull(div);
         Assert.assertEquals("div", div.getNodeName());
+        Assert.assertEquals("dr-sb-common-container rich-sb-common-container", div.getAttributeValue("class"));
+        HtmlElement table = page.getHtmlElementById(form.getId() + ":" + sb.getId() + ":suggest");
+        Assert.assertNotNull(table);
+        Assert.assertEquals("table", table.getNodeName());
+        HtmlElement iframe = page.getHtmlElementById(form.getId() + ":" + sb.getId() + "_iframe");
+        Assert.assertNotNull(iframe);
+        Assert.assertEquals("iframe", iframe.getNodeName());
     }
 
     /**
      * Rigourous Test :-)
+     *
      * @throws Exception
      */
     public void testRenderStyle() throws Exception {
         HtmlPage page = renderView();
         Assert.assertNotNull(page);
-        List elementsByTagName = page.getDocumentElement().getHtmlElementsByTagName("link");
-        Assert.assertEquals(1, elementsByTagName.size());
-        HtmlElement link = (HtmlElement) elementsByTagName.get(0);
+        List links = page.getDocumentElement().getHtmlElementsByTagName("link");
+        Assert.assertEquals(1, links.size());
+        HtmlElement link = (HtmlElement) links.get(0);
         Assert.assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/suggestionbox.xcss"));
     }
 
     /**
      * Rigourous Test :-)
+     *
      * @throws Exception
      */
-    public void testRenderAttributes() throws Exception {
-        /*
-        Object[][] attributes ={{"style","xxx","style","xxx"},{"onclick","alert()","onclick","alert()"},{"styleClass","yyy","class","dr-pnl rich-panel yyy"}};
-        for (int i = 0; i < attributes.length; i++) {
-            Object[] attr = attributes[i];
-            htmlSuggestionBox.getAttributes().put(attr[0], attr[1]);
-        }
+    public void testRenderScript() throws Exception {
         HtmlPage page = renderView();
         Assert.assertNotNull(page);
-        System.out.println(page.asXml());
-        HtmlElement div = page.getHtmlElementById("form:suggestionBox");
-        Assert.assertNotNull(div);
-        for (int i = 0; i < attributes.length; i++) {
-            Object[] attr = attributes[i];
-            Assert.assertEquals(attr[3],div.getAttributeValue((String) attr[2]));
-        }
-        */
-    }
+        List scripts = page.getDocumentElement().getHtmlElementsByTagName("script");
+        for (Iterator it = scripts.iterator(); it.hasNext();) {
+            HtmlScript item = (HtmlScript) it.next();
+            String srcAttr = item.getSrcAttribute();
 
-    class MyMockViewHandler extends MockViewHandler {
-        public UIViewRoot restoreView(FacesContext context, String viewId) {
-            return null;
-        }
+            if (StringUtils.isNotBlank(srcAttr)) {
+                boolean found = false;
+                for (Iterator srcIt = sbScripts.iterator(); srcIt.hasNext();) {
+                    String src = (String) srcIt.next();
 
-        public void writeState(FacesContext context) {
+                    found = srcAttr.contains(src);
+                    if (found) {
+                        break;
+                    }
+                }
 
+                assertTrue(found);
+            }
         }
     }
 }

Added: trunk/richfaces/suggestionbox/src/test/resources/WEB-INF/log4j.xml
===================================================================
--- trunk/richfaces/suggestionbox/src/test/resources/WEB-INF/log4j.xml	                        (rev 0)
+++ trunk/richfaces/suggestionbox/src/test/resources/WEB-INF/log4j.xml	2007-04-03 12:51:47 UTC (rev 243)
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "file:///eclipse/dtdcache/log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+    <!-- This is a sample configuration for log4j.
+         It simply just logs everything into a single
+         log file.
+         Note, that you can use properties for value substitution.
+    -->
+    <appender name="DEFAULT" class="org.apache.log4j.ConsoleAppender">
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%t %-5p %c{2} - %m:%n"/>
+        </layout>	    
+    </appender>
+
+<!-- 
+    <appender name="FACES" class="org.apache.log4j.ConsoleAppender">
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%t %-5p %c{2} - %m:%n"/>
+        </layout>	    
+    </appender>
+
+    <appender name="CHAMELEON" class="org.apache.log4j.ConsoleAppender">
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%t %-5p %c{2} - %m:%n"/>
+        </layout>	    
+    </appender>
+ -->
+     <category name="com.sun.faces">
+         <priority value="DEBUG" />
+         <appender-ref ref="DEFAULT"/>
+     </category>    
+    
+     <category name="org.apache.myfaces">
+         <priority value="DEBUG" />
+         <appender-ref ref="DEFAULT"/>
+     </category>    
+
+     <category name="javax.faces">
+         <priority value="INFO" />
+         <appender-ref ref="DEFAULT"/>
+     </category>
+    
+     <category name="faces">
+         <priority value="INFO" />
+         <appender-ref ref="DEFAULT"/>
+     </category>    
+        
+     <category name="com.exadel.vcp">
+         <priority value="DEBUG" />
+         <appender-ref ref="DEFAULT"/>
+     </category>    
+
+        
+     <category name="org.ajax4jsf">
+         <priority value="DEBUG" />
+         <appender-ref ref="DEFAULT"/>
+     </category>    
+
+       <!-- 
+    <root>
+      <priority value ="info" />
+      <appender-ref ref="DEFAULT" />
+    </root>
+     -->
+</log4j:configuration>




More information about the richfaces-svn-commits mailing list