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