1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.context.servlet;
20
21 import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
22 import org.junit.After;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28
29 import java.io.IOException;
30 import java.io.StringWriter;
31 import java.util.Arrays;
32 import java.util.Collection;
33 import java.util.HashMap;
34 import java.util.HashSet;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Set;
38
39 import javax.faces.component.UIViewRoot;
40 import javax.faces.context.FacesContext;
41
42 import org.apache.myfaces.view.facelets.FaceletTestCase;
43 import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
44
45
46
47
48
49
50
51 @RunWith(JUnit4.class)
52 public class FacesContextImplBaseTest extends FaceletTestCase {
53
54 @Before
55 @Override
56 public void setUp() throws Exception {
57 super.setUp();
58 }
59
60 @After
61 @Override
62 public void tearDown() throws Exception {
63 super.tearDown();
64 }
65
66
67
68
69
70 @Test
71 public void testViewMapCleared() throws Exception
72 {
73
74 FacesContextImpl fci = new FacesContextImpl(facesContext.getExternalContext(), null, null);
75 UIViewRoot firstRoot = new UIViewRoot();
76 UIViewRoot secondRoot = new UIViewRoot();
77 fci.setViewRoot(firstRoot);
78 Map<String, Object> viewMap = firstRoot.getViewMap();
79 viewMap.put("entry", Boolean.TRUE);
80
81
82 fci.setViewRoot(secondRoot);
83 Assert.assertEquals("The ViewMap was not cleared as expected", 0, viewMap.size());
84 }
85
86
87
88
89
90 @Test
91 public void testViewMapNotClearedWhileBuildingViewMetadata() throws Exception
92 {
93 FacesContextImpl fci = new FacesContextImpl(facesContext.getExternalContext(), null, null);
94 UIViewRoot firstRoot = new UIViewRoot();
95 UIViewRoot secondRoot = new UIViewRoot();
96 fci.getAttributes().put(FaceletViewDeclarationLanguage.BUILDING_VIEW_METADATA, Boolean.TRUE);
97 fci.setViewRoot(firstRoot);
98 Map<String, Object> viewMap = firstRoot.getViewMap();
99 viewMap.put("entry", Boolean.TRUE);
100
101
102 fci.setViewRoot(secondRoot);
103 Assert.assertEquals("The ViewMap was incorrectly cleared while the BUILDING_VIEW_METADATA attribute was set", 1, viewMap.size());
104 }
105 }