[richfaces-svn-commits] JBoss Rich Faces SVN: r397 - trunk/richfaces/tabPanel/src/test/java/org/richfaces/component.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Apr 13 08:08:52 EDT 2007


Author: A.Skokov
Date: 2007-04-13 08:08:52 -0400 (Fri, 13 Apr 2007)
New Revision: 397

Added:
   trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabPanelTest.java
Modified:
   trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/TabPanelComponentTest.java
   trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabTest.java
Log:
test updated

Modified: trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/TabPanelComponentTest.java
===================================================================
--- trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/TabPanelComponentTest.java	2007-04-13 11:50:11 UTC (rev 396)
+++ trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/TabPanelComponentTest.java	2007-04-13 12:08:52 UTC (rev 397)
@@ -21,17 +21,20 @@
 
 package org.richfaces.component;
 
+import com.gargoylesoftware.htmlunit.Page;
 import com.gargoylesoftware.htmlunit.html.HtmlElement;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import com.gargoylesoftware.htmlunit.html.HtmlScript;
+import org.ajax4jsf.framework.resource.InternetResource;
+import org.ajax4jsf.framework.resource.InternetResourceBuilder;
+import org.ajax4jsf.framework.resource.ResourceBuilderImpl;
+import org.ajax4jsf.framework.util.image.ImageInfo;
 import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
 import org.apache.commons.lang.StringUtils;
-import org.richfaces.component.html.HtmlTab;
-import org.richfaces.component.html.HtmlTabPanel;
-import org.richfaces.renderkit.TabPanelRendererBase;
 
 import javax.faces.component.UIForm;
 import javax.faces.component.html.HtmlForm;
+import javax.servlet.http.HttpServletResponse;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -76,15 +79,15 @@
         form.setId("form");
         facesContext.getViewRoot().getChildren().add(form);
 
-        tabPanel = (UITabPanel)application.createComponent("org.richfaces.TabPanel");
+        tabPanel = (UITabPanel) application.createComponent("org.richfaces.TabPanel");
         tabPanel.setId("tabPanel");
         form.getChildren().add(tabPanel);
 
-        tab1 = (UITab)application.createComponent("org.richfaces.Tab");
+        tab1 = (UITab) application.createComponent("org.richfaces.Tab");
         tab1.setId("tab1");
         tabPanel.getChildren().add(tab1);
 
-        tab2 = (UITab)application.createComponent("org.richfaces.Tab");
+        tab2 = (UITab) application.createComponent("org.richfaces.Tab");
         tab2.setId("tab2");
         tab2.setActive(false);
         tabPanel.getChildren().add(tab2);
@@ -194,7 +197,8 @@
 
             if (StringUtils.isNotBlank(srcAttr)) {
                 boolean found = false;
-                for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
+                for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();)
+                {
                     String src = (String) srcIt.next();
 
                     found = srcAttr.contains(src);
@@ -207,4 +211,36 @@
             }
         }
     }
+
+    public void testRenderImages() throws Exception {
+        HtmlPage view = renderView();
+        assertNotNull(view);
+        System.out.println(view.asXml());
+
+        InternetResourceBuilder builder = ResourceBuilderImpl.getInstance();
+        InternetResource resource = builder.getResource("org/richfaces/renderkit/html/css/tabPanel.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.images.TabGradientA",
+                "org.richfaces.renderkit.images.TabGradientB",
+                "org.richfaces.renderkit.images.TabStripeImage"
+        };
+
+        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());
+        }
+    }
 }

Added: trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabPanelTest.java
===================================================================
--- trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabPanelTest.java	                        (rev 0)
+++ trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabPanelTest.java	2007-04-13 12:08:52 UTC (rev 397)
@@ -0,0 +1,120 @@
+package org.richfaces.component;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.component.html.HtmlOutputText;
+import java.util.Iterator;
+
+/**
+ * Unit test for UITabPanel.
+ */
+public class UITabPanelTest extends AbstractAjax4JsfTestCase {
+
+    private UITabPanel tabPanel;
+    private UITab tab1;
+    private UITab tab2;
+    private UITab tab3;
+    private UIComponent form;
+    private UIOutput out1;
+    private UIOutput out2;
+    private UIOutput out3;
+
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public UITabPanelTest(String testName) {
+        super(testName);
+    }
+
+    /* (non-Javadoc)
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+     */
+    public void setUp() throws Exception {
+        super.setUp();
+
+        form = new HtmlForm();
+        form.setId("form");
+        facesContext.getViewRoot().getChildren().add(form);
+
+        tabPanel = (UITabPanel) application.createComponent("org.richfaces.TabPanel");
+        form.getChildren().add(tabPanel);
+
+        tab1 = (UITab) application.createComponent("org.richfaces.Tab");
+        tab1.setId("Tab1_ID");
+        tab1.setName("Tab1");
+        out1 = (UIOutput) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+        out1.setValue("output1");
+        tab1.getChildren().add(out1);
+        tabPanel.getChildren().add(tab1);
+
+        tab2 = (UITab) application.createComponent("org.richfaces.Tab");
+        tab2.setId("Tab2_ID");
+        tab2.setName("Tab2");
+        out2 = (UIOutput) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+        out2.setValue("output2");
+        tab2.getChildren().add(out2);
+        tabPanel.getChildren().add(tab2);
+
+        tab3 = (UITab) application.createComponent("org.richfaces.Tab");
+        tab3.setId("Tab3_ID");
+        tab3.setName("Tab3");
+        out3 = (UIOutput) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+        out3.setValue("output3");
+        tab3.getChildren().add(out3);
+        tabPanel.getChildren().add(tab3);
+    }
+
+    /* (non-Javadoc)
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+     */
+    public void tearDown() throws Exception {
+        super.tearDown();
+        tabPanel = null;
+        tab1 = null;
+        tab2 = null;
+        tab3 = null;
+        form = null;
+        out1 = null;
+        out2 = null;
+        out3 = null;
+    }
+
+    public void testConvertSwitchValue() throws Exception {
+        assertEquals("switchValue",
+                tabPanel.convertSwitchValue(tab1, "switchValue"));
+        assertEquals("Tab1", tabPanel.convertSwitchValue(tab1, null));
+
+        try {
+            assertEquals("Tab1", tabPanel.convertSwitchValue(tabPanel, null));
+            assertTrue(false);
+        } catch(ClassCastException ex) {
+        }
+    }
+
+    public void testGetSwitchedFacetsAndChildren1() throws Exception {
+        tab1.setSwitchType(UISwitchablePanel.SERVER_METHOD);
+        tab2.setSwitchType(UISwitchablePanel.SERVER_METHOD);
+        tab3.setSwitchType(UISwitchablePanel.SERVER_METHOD);
+
+        tabPanel.setRenderedValue(tab3.getName());
+
+        Iterator it = tabPanel.getSwitchedFacetsAndChildren();
+        assertEquals(tab3.getId(), ((UITab)it.next()).getId());
+    }
+
+    public void testGetSwitchedFacetsAndChildren2() throws Exception {
+        tab1.setSwitchType(UISwitchablePanel.CLIENT_METHOD);
+        tab2.setSwitchType(UISwitchablePanel.CLIENT_METHOD);
+        tab3.setSwitchType(UISwitchablePanel.CLIENT_METHOD);
+
+        Iterator it = tabPanel.getSwitchedFacetsAndChildren();
+        assertEquals(tab1.getId(), ((UITab)it.next()).getId());
+        assertEquals(tab2.getId(), ((UITab)it.next()).getId());
+        assertEquals(tab3.getId(), ((UITab)it.next()).getId());
+    }
+}

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-13 11:50:11 UTC (rev 396)
+++ trunk/richfaces/tabPanel/src/test/java/org/richfaces/component/UITabTest.java	2007-04-13 12:08:52 UTC (rev 397)
@@ -22,18 +22,19 @@
 package org.richfaces.component;
 
 import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.richfaces.component.html.HtmlTabPanel;
-import org.richfaces.component.html.HtmlTab;
 
 import javax.faces.component.UIForm;
 import javax.faces.component.html.HtmlForm;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
 
 /**
- * Unit test for UITabTest.
+ * Unit test for UITab.
  */
 public class UITabTest extends AbstractAjax4JsfTestCase {
 
     private UITab tab;
+    private UITab tab2;
     private UITabPanel tabPanel;
     private UIForm form;
 
@@ -52,11 +53,13 @@
     public void setUp() throws Exception {
         super.setUp();
 
-        tab = (UITab)application.createComponent("org.richfaces.Tab");
+        tab = (UITab) application.createComponent("org.richfaces.Tab");
         tab.setId("tab");
 
-        tabPanel = (UITabPanel)application.createComponent("org.richfaces.TabPanel");
+        tab2 = (UITab) application.createComponent("org.richfaces.Tab");
 
+        tabPanel = (UITabPanel) application.createComponent("org.richfaces.TabPanel");
+
         form = new HtmlForm();
     }
 
@@ -66,6 +69,7 @@
     public void tearDown() throws Exception {
         super.tearDown();
         tab = null;
+        tab2 = null;
         tabPanel = null;
         form = null;
     }
@@ -85,7 +89,157 @@
         try {
             tab.getPane();
             assertTrue(false);
-        } catch(Exception ex) {
+        } catch (Exception ex) {
         }
     }
+
+    public void testEncodeTab() throws Exception {
+        try {
+            tab.encodeTab(null, false);
+            assertTrue(false);
+        } catch (NullPointerException ex) {
+        }
+
+        try {
+            FakeUITab fakeTab = new FakeUITab();
+            fakeTab.setRendered(false);
+            fakeTab.encodeTab(facesContext, false);
+        } catch (NullPointerException ex) {
+            assertTrue(false);
+        }
+    }
+
+    public void testSaveRestore() throws Exception {
+        tab.setSwitchType("switchType");
+        assertEquals("switchType", tab.getSwitchType());
+
+        Object state = tab.saveState(facesContext);
+        tab2.restoreState(facesContext, state);
+        assertEquals("switchType", tab2.getSwitchType());
+    }
+
+    class FakeUITab extends UITab {
+        protected Renderer getRenderer(FacesContext context) {
+            throw new NullPointerException("Never executed");
+        }
+
+        public Object getValue() {
+            return null;
+        }
+
+        public void setValue(Object newvalue) {
+        }
+
+        public Object getName() {
+            return null;
+        }
+
+        public void setName(Object newvalue) {
+        }
+
+        public boolean isDisabled() {
+            return false;
+        }
+
+        public void setDisabled(boolean disabled) {
+        }
+
+        public String getLabel() {
+            return null;
+        }
+
+        public void setLabel(String newvalue) {
+        }
+
+        public String getLabelWidth() {
+            return null;
+        }
+
+        public void setLabelWidth(String newvalue) {
+        }
+
+        public String getTitle() {
+            return null;
+        }
+
+        public void setTitle(String newvalue) {
+        }
+
+        public void setReRender(Object targetId) {
+        }
+
+        public Object getReRender() {
+            return null;
+        }
+
+        public void setStatus(String status) {
+        }
+
+        public String getStatus() {
+            return null;
+        }
+
+        public void setOncomplete(String oncomplete) {
+        }
+
+        public String getOncomplete() {
+            return null;
+        }
+
+        public void setData(Object data) {
+        }
+
+        public Object getData() {
+            return null;
+        }
+
+        public void setLimitToList(boolean submitForm) {
+        }
+
+        public boolean isLimitToList() {
+            return false;
+        }
+
+        public void setAjaxSingle(boolean single) {
+        }
+
+        public boolean isAjaxSingle() {
+            return false;
+        }
+
+        public boolean isBypassUpdates() {
+            return false;
+        }
+
+        public void setBypassUpdates(boolean bypass) {
+        }
+
+        public String getEventsQueue() {
+            return null;
+        }
+
+        public void setIgnoreDupResponses(boolean newvalue) {
+        }
+
+        public boolean isIgnoreDupResponses() {
+            return false;
+        }
+
+        public void setEventsQueue(String newvalue) {
+        }
+
+        public int getRequestDelay() {
+            return 0;
+        }
+
+        public void setRequestDelay(int newvalue) {
+        }
+
+        public int getTimeout() {
+            return 0;
+        }
+
+        public void setTimeout(int timeout) {
+        }
+    }
 }




More information about the richfaces-svn-commits mailing list