01: package com.sun.facelets.tag.ui;
02:
03: import java.io.StringWriter;
04: import java.util.HashMap;
05: import java.util.Map;
06:
07: import javax.faces.component.UIViewRoot;
08: import javax.faces.context.FacesContext;
09:
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
69: .getChildCount());
70: assertNotNull("bound to map", map.get("c"));
71: }
72:
73: public void testComponentClient() throws Exception {
74: FacesContext faces = FacesContext.getCurrentInstance();
75: Map map = new HashMap();
76: faces.getExternalContext().getRequestMap().put("map", map);
77:
78: FaceletFactory f = FaceletFactory.getInstance();
79: Facelet at = f.getFacelet("component-client.xml");
80:
81: UIViewRoot root = faces.getViewRoot();
82: at.apply(faces, root);
83:
84: assertEquals("4 children, the component", 4, root
85: .getChildCount());
86: assertNotNull("bound to map", map.get("c"));
87: }
88:
89: }
|