1 package com.sun.facelets.tag.ui; 2 3 import java.io.StringWriter ; 4 import java.util.HashMap ; 5 import java.util.Map ; 6 7 import javax.faces.component.UIViewRoot; 8 import javax.faces.context.FacesContext; 9 10 import com.sun.facelets.Facelet; 11 import com.sun.facelets.FaceletFactory; 12 import com.sun.facelets.FaceletTestCase; 13 import com.sun.facelets.mock.MockResponseWriter; 14 import com.sun.faces.util.DebugUtil; 15 16 public class UITestCase extends FaceletTestCase { 17 18 public void testRelativePaths() throws Exception { 19 FacesContext faces = FacesContext.getCurrentInstance(); 20 21 FaceletFactory f = FaceletFactory.getInstance(); 22 Facelet at = f.getFacelet("parent.xml"); 23 24 UIViewRoot root = faces.getViewRoot(); 25 at.apply(faces, root); 26 27 StringWriter sw = new StringWriter (); 28 MockResponseWriter mrw = new MockResponseWriter(sw); 29 faces.setResponseWriter(mrw); 30 root.encodeAll(faces); 31 sw.flush(); 32 System.out.println("************************"); 33 System.out.println(sw.toString()); 34 System.out.println("************************"); 35 } 36 37 public void testCompositionTemplate() throws Exception { 38 FacesContext faces = FacesContext.getCurrentInstance(); 39 40 FaceletFactory f = FaceletFactory.getInstance(); 41 Facelet at = f.getFacelet("composition-template.xml"); 42 43 UIViewRoot root = faces.getViewRoot(); 44 at.apply(faces, root); 45 } 46 47 public void testCompositionTemplateSimple() throws Exception { 48 FacesContext faces = FacesContext.getCurrentInstance(); 49 50 FaceletFactory f = FaceletFactory.getInstance(); 51 Facelet at = f.getFacelet("composition-template-simple.xml"); 52 53 UIViewRoot root = faces.getViewRoot(); 54 at.apply(faces, root); 55 } 56 57 public void testComponent() throws Exception { 58 FacesContext faces = FacesContext.getCurrentInstance(); 59 Map map = new HashMap (); 60 faces.getExternalContext().getRequestMap().put("map", map); 61 62 FaceletFactory f = FaceletFactory.getInstance(); 63 Facelet at = f.getFacelet("component.xml"); 64 65 UIViewRoot root = faces.getViewRoot(); 66 at.apply(faces, root); 67 68 assertEquals("only one child, the component", 1, root.getChildCount()); 69 assertNotNull("bound to map", map.get("c")); 70 } 71 72 public void testComponentClient() throws Exception { 73 FacesContext faces = FacesContext.getCurrentInstance(); 74 Map map = new HashMap (); 75 faces.getExternalContext().getRequestMap().put("map", map); 76 77 FaceletFactory f = FaceletFactory.getInstance(); 78 Facelet at = f.getFacelet("component-client.xml"); 79 80 UIViewRoot root = faces.getViewRoot(); 81 at.apply(faces, root); 82 83 assertEquals("4 children, the component", 4, root.getChildCount()); 84 assertNotNull("bound to map", map.get("c")); 85 } 86 87 } 88 | Popular Tags |