1 16 package org.apache.myfaces.bug925693; 17 18 import javax.faces.FactoryFinder; 19 import javax.faces.application.Application; 20 import javax.faces.context.FacesContext; 21 import javax.faces.context.FacesContextFactory; 22 import javax.faces.el.ValueBinding; 23 import javax.faces.lifecycle.Lifecycle; 24 import javax.faces.lifecycle.LifecycleFactory; 25 import javax.faces.webapp.FacesServlet; 26 import javax.servlet.RequestDispatcher ; 27 28 import org.apache.cactus.ServletTestCase; 29 import org.apache.cactus.WebRequest; 30 31 import com.meterware.httpunit.WebResponse; 32 import com.meterware.httpunit.WebTable; 33 34 public class Bug925693CactusTest extends ServletTestCase { 35 36 public static void main(String [] args) { 37 junit.textui.TestRunner.run(Bug925693CactusTest.class); 38 } 39 40 protected void setUp() throws Exception { 41 super.setUp(); 42 } 43 44 protected void tearDown() throws Exception { 45 super.tearDown(); 46 } 47 48 public Bug925693CactusTest(String name) { 49 super(name); 50 } 51 52 public void testSimpleRender() throws Exception { 53 RequestDispatcher rd = config.getServletContext().getRequestDispatcher( 54 "/home.jsf"); 55 rd.forward(request, response); 57 } 58 59 public void endSimpleRender(WebResponse response) throws Exception { 60 WebTable tables[] = response.getTables(); 61 assertEquals(1, tables.length); 62 WebTable table = tables[0]; 63 System.err.println("table = " + table); 64 assertEquals(2, table.getRowCount()); 66 } 67 68 public void beginAddARow(WebRequest request) throws Exception { 69 } 70 71 public void testAddARow() throws Exception { 72 FacesContext ctx = performFacesContextConfig(); 74 addLineItem(ctx); 76 RequestDispatcher rd = config.getServletContext().getRequestDispatcher( 78 "/home.jsf"); 79 rd.forward(request, response); 81 } 82 83 private void addLineItem(FacesContext ctx) { 84 Application app = ctx.getApplication(); 85 ValueBinding binding = app.createValueBinding("#{invoice}"); 86 Invoice invoice = (Invoice) binding.getValue(ctx); 87 invoice.addLineItem(); 88 } 89 90 private FacesContext performFacesContextConfig() { 91 LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder 92 .getFactory(FactoryFinder.LIFECYCLE_FACTORY); 93 Lifecycle lifecycle = lifecycleFactory.getLifecycle(getLifecycleId()); 94 FacesContextFactory facesCtxFactory = (FacesContextFactory) FactoryFinder 95 .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); 96 FacesContext ctx = facesCtxFactory.getFacesContext(config 97 .getServletContext(), request, response, lifecycle); 98 return ctx; 99 } 100 101 private String getLifecycleId() { 102 String lifecycleId = this.config.getServletContext().getInitParameter( 103 FacesServlet.LIFECYCLE_ID_ATTR); 104 return lifecycleId != null ? lifecycleId 105 : LifecycleFactory.DEFAULT_LIFECYCLE; 106 } 107 108 public void endAddARow(WebResponse response) throws Exception { 109 WebTable tables[] = response.getTables(); 110 assertEquals(1, tables.length); 111 WebTable table = tables[0]; 112 System.err.println("table = " + table); 113 assertEquals(3, table.getRowCount()); 115 } 116 117 } | Popular Tags |