You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by pa...@apache.org on 2007/01/02 17:07:32 UTC

svn commit: r491826 - in /myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces: component/html/ext/HtmlDataTableTest.java test/AbstractTomahawkJsfTestCase.java

Author: paulsp
Date: Tue Jan  2 08:07:31 2007
New Revision: 491826

URL: http://svn.apache.org/viewvc?view=rev&rev=491826
Log:
o Add test to verify component was rendered
o Cleanup unneeded code

Modified:
    myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java
    myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTomahawkJsfTestCase.java

Modified: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java?view=diff&rev=491826&r1=491825&r2=491826
==============================================================================
--- myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java (original)
+++ myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java Tue Jan  2 08:07:31 2007
@@ -25,7 +25,6 @@
 import java.util.HashSet;
 import java.util.List;
 
-import javax.faces.FactoryFinder;
 import javax.faces.component.UIColumn;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIData;
@@ -61,17 +60,12 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-        servletContext.addInitParameter("org.apache.myfaces.PRETTY_HTML",
-                "false");
-
         _dataTable = new HtmlDataTable();
     }
 
     protected void tearDown() throws Exception
     {
         super.tearDown();
-        // once shale-test is updated in maven, this will not be necessary
-        FactoryFinder.releaseFactories();
         _dataTable = null;
     }
 
@@ -121,24 +115,28 @@
     public void testDefaultRenderer()
     {
         // Define the component
-        UIData dataTable = new HtmlDataTable();
+        UIData component = new HtmlDataTable();
+        component.setId("TestComponent");
 
         // Add rows to the table
         List rows = new ArrayList();
         rows.add(new TestData("test1", "test1"));
         rows.add(new TestData("test2", "test2"));
         rows.add(new TestData("test3", "test3"));
-        dataTable.setValue(new ListDataModel(rows));
+        component.setValue(new ListDataModel(rows));
 
         // Render the component
         try
         {
-            TestUtils.renderComponent(facesContext, dataTable);
+            TestUtils.renderComponent(facesContext, component);
         }
         catch (IOException e)
         {
             fail(e.getMessage());
         }
+
+        // Verify component was rendered
+        assertIdExists(component.getId());
     }
 
     private UIInput createInputInTree(FacesContext context)

Modified: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTomahawkJsfTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTomahawkJsfTestCase.java?view=diff&rev=491826&r1=491825&r2=491826
==============================================================================
--- myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTomahawkJsfTestCase.java (original)
+++ myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTomahawkJsfTestCase.java Tue Jan  2 08:07:31 2007
@@ -18,12 +18,11 @@
  */
 package org.apache.myfaces.test;
 
-import java.io.BufferedWriter;
-import java.io.CharArrayWriter;
+import java.io.StringWriter;
 
 import org.apache.myfaces.shared_tomahawk.config.MyfacesConfig;
 import org.apache.myfaces.test.utils.TestUtils;
-import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.base.AbstractViewControllerTestCase;
 import org.apache.shale.test.mock.MockResponseWriter;
 
 /**
@@ -31,8 +30,10 @@
  * overrides <code>setUp()</code> and/or <code>tearDown()</code>, then those
  * methods but call the overwitten method to insure a valid test environment.
  */
-public class AbstractTomahawkJsfTestCase extends AbstractJsfTestCase
+public class AbstractTomahawkJsfTestCase extends AbstractViewControllerTestCase
 {
+    /** Response Writer */
+    private MockResponseWriter writer;
 
     /**
      * Construct a new instance of the test.
@@ -55,10 +56,11 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-
         // additional setup not provided automatically by the shale mock stuff
-        facesContext.getExternalContext().getApplicationMap().put(MyfacesConfig.class.getName(), new MyfacesConfig());
-        facesContext.setResponseWriter(new MockResponseWriter(new BufferedWriter(new CharArrayWriter()), null, null));
+        facesContext.getExternalContext().getApplicationMap().put(
+                MyfacesConfig.class.getName(), new MyfacesConfig());
+        writer = new MockResponseWriter(new StringWriter(), null, null);
+        facesContext.setResponseWriter(writer);
 
         TestUtils.addDefaultRenderers(facesContext);
     }
@@ -69,6 +71,26 @@
     protected void tearDown() throws Exception
     {
         super.tearDown();
+    }
+
+    /**
+     * Verify the following:
+     * <ul>
+     * <li>id is not null</li>
+     * <li>Response is complete</li>
+     * <li>Responce contains the id</li>
+     * </ul>
+     * 
+     * @param id ID to verify
+     */
+    protected void assertIdExists(String id)
+    {
+        assertNotNull("ID is not null", id);
+        assertTrue("Response Complete", facesContext.getResponseComplete());
+        String output = writer.getWriter().toString();
+//        System.out.println("Output = '" + output + "'");
+        assertNotNull("Has output", output);
+        assertTrue("Contains id '" + id + "'", output.indexOf(id) != -1);
     }
 
 }