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.impl;
20
21 import java.io.IOException;
22 import java.util.List;
23 import javax.faces.application.StateManager;
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UIViewRoot;
26 import org.apache.myfaces.view.facelets.FaceletTestCase;
27 import org.junit.Assert;
28 import org.junit.Test;
29
30 public class ResourceMarkDeleteTest extends FaceletTestCase
31 {
32 @Override
33 protected void setUpServletObjects() throws Exception
34 {
35 super.setUpServletObjects();
36 servletContext.addInitParameter(StateManager.PARTIAL_STATE_SAVING_PARAM_NAME, "false");
37 }
38
39 @Test
40 public void test_only_ajs_is_included() throws IOException
41 {
42 UIViewRoot root = facesContext.getViewRoot();
43
44
45
46 vdl.buildView(facesContext, root, "test_conditional_include_resources.xhtml");
47
48 List<UIComponent> resources = root.getComponentResources(facesContext, "head");
49
50 Assert.assertTrue("Only one script is included.", resources.size() == 1);
51 Assert.assertTrue("a.js is included.", resources.get(0).getAttributes().get("name").equals("a.js"));
52 }
53
54 @Test
55 public void test_ajs_and_xjs_are_included() throws IOException
56 {
57 facesContext.getAttributes().put("includeResource", Boolean.TRUE);
58 UIViewRoot root = facesContext.getViewRoot();
59
60
61
62 vdl.buildView(facesContext, root, "test_conditional_include_resources.xhtml");
63
64 List<UIComponent> resources = root.getComponentResources(facesContext, "head");
65
66 Assert.assertTrue("Two scripts are included.", resources.size() == 2);
67 }
68
69 @Test
70 public void test_only_ajs_after_refresh_view_is_included() throws IOException
71 {
72 UIViewRoot view = facesContext.getViewRoot();
73
74
75
76 vdl.buildView(facesContext, view, "test_conditional_include_resources.xhtml");
77
78 {
79 List<UIComponent> resources = view.getComponentResources(facesContext, "head");
80
81 Assert.assertTrue("Only one script is included.", resources.size() == 1);
82 }
83
84
85 facesContext.getAttributes().remove(view);
86
87
88
89 facesContext.getAttributes().put("includeResource", Boolean.TRUE);
90 vdl.buildView(facesContext, view);
91
92 {
93 List<UIComponent> resources = view.getComponentResources(facesContext, "head");
94
95 Assert.assertTrue("Two scripts are included.", resources.size() == 2);
96 }
97
98
99 facesContext.getAttributes().remove(view);
100
101
102
103 facesContext.getAttributes().remove("includeResource");
104 vdl.buildView(facesContext, view);
105
106 {
107 List<UIComponent> resources = view.getComponentResources(facesContext, "head");
108
109 Assert.assertTrue("Only one script is included.", resources.size() == 1);
110 }
111 }
112 }