1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.updateheadres;
20
21 import javax.faces.application.StateManager;
22 import javax.faces.component.UICommand;
23 import javax.faces.component.UIComponent;
24
25 import org.apache.myfaces.mc.test.core.AbstractMyFacesRequestTestCase;
26 import org.apache.myfaces.shared.config.MyfacesConfig;
27 import org.junit.Assert;
28 import org.junit.Test;
29
30 public class UpdateHeadDynamicViewTestCase extends AbstractMyFacesRequestTestCase
31 {
32
33 @Override
34 protected boolean isScanAnnotations()
35 {
36 return true;
37 }
38
39 @Override
40 protected void setUpWebConfigParams() throws Exception
41 {
42 super.setUpWebConfigParams();
43 servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.view.facelets.updateheadres.managed");
44 servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);
45 servletContext.addInitParameter("javax.faces.PARTIAL_STATE_SAVING", "true");
46 servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS, "auto");
47 servletContext.addInitParameter("org.apache.myfaces.STRICT_JSF_2_REFRESH_TARGET_AJAX", "true");
48 }
49
50 @Test
51 public void testNoUpdateScript1Head() throws Exception
52 {
53 setupRequest("/ajaxContent.xhtml");
54 processLifecycleExecuteAndRender();
55
56 UIComponent content = facesContext.getViewRoot().findComponent("content");
57 UIComponent page1Button = facesContext.getViewRoot().findComponent("mainForm:page1");
58
59 client.ajax((UICommand)page1Button, "action", page1Button.getClientId(facesContext), content.getClientId(facesContext), true);
60
61 processLifecycleExecuteAndRender();
62 String text = getRenderedContent(facesContext);
63
64 Assert.assertFalse(text.contains("update id=\"javax.faces.ViewHead\""));
65
66 tearDownRequest();
67 }
68
69 @Test
70 public void testUpdateScript2Head() throws Exception
71 {
72 setupRequest("/ajaxContent.xhtml");
73 processLifecycleExecuteAndRender();
74
75 UIComponent content = facesContext.getViewRoot().findComponent("content");
76 UIComponent page2Button = facesContext.getViewRoot().findComponent("mainForm:page2");
77
78 client.ajax((UICommand)page2Button, "action", page2Button.getClientId(facesContext), content.getClientId(facesContext), true);
79
80 processLifecycleExecuteAndRender();
81
82 String text = getRenderedContent(facesContext);
83
84 Assert.assertTrue(text.contains("update id=\"javax.faces.ViewHead\""));
85 Assert.assertTrue(text.contains("alert(\"script2\");"));
86
87 tearDownRequest();
88 }
89
90 @Test
91 public void testUpdateScript3Head() throws Exception
92 {
93 setupRequest("/ajaxContent.xhtml");
94 processLifecycleExecuteAndRender();
95
96 UIComponent content = facesContext.getViewRoot().findComponent("content");
97 UIComponent page3Button = facesContext.getViewRoot().findComponent("mainForm:page3");
98
99 client.ajax((UICommand)page3Button, "action", page3Button.getClientId(facesContext), content.getClientId(facesContext), true);
100
101 processLifecycleExecuteAndRender();
102
103 String text = getRenderedContent(facesContext);
104
105 Assert.assertTrue(text.contains("update id=\"javax.faces.ViewHead\""));
106 Assert.assertTrue(text.contains("alert(\"script3\");"));
107 Assert.assertTrue(text.contains("link rel=\"stylesheet\" media=\"screen\" type=\"text/css\" href=\"/test/faces/javax.faces.resource/style3.css\""));
108
109 tearDownRequest();
110 }
111
112 }