1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.lifecycle;
20
21 import javax.faces.component.UIViewRoot;
22
23 import junit.framework.Assert;
24
25 import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
26 import org.junit.Test;
27
28 public class RenderResponseExecutorTest extends AbstractJsfTestCase
29 {
30
31 @Test
32 public void testNavigationCondition() throws Exception
33 {
34 UIViewRoot a = new UIViewRoot();
35 UIViewRoot b = new UIViewRoot();
36 UIViewRoot c = new UIViewRoot();
37 UIViewRoot d = new UIViewRoot();
38 a.setViewId("/a.xhtml");
39 b.setViewId("/a.xhtml");
40 c.setViewId("/c.xhtml");
41
42
43 Assert.assertFalse(checkCondition(a, a));
44
45
46 Assert.assertTrue(checkCondition(a, b));
47
48
49 Assert.assertTrue(checkCondition(a, c));
50
51
52 Assert.assertTrue(checkCondition(a, d));
53
54
55 Assert.assertTrue(checkCondition(d, a));
56
57
58 Assert.assertFalse(checkCondition(d, d));
59 }
60
61 protected boolean checkCondition(UIViewRoot previousRoot, UIViewRoot root)
62 {
63 String viewId = previousRoot.getViewId();
64 String newViewId = (root == null) ? null : root.getViewId();
65
66 boolean isNotSameRoot = !( (newViewId == null ? newViewId == viewId : newViewId.equals(viewId) ) &&
67 previousRoot.equals(root) );
68
69 if ((newViewId == null && viewId != null)
70 || (newViewId != null && (!newViewId.equals(viewId) || isNotSameRoot ) ))
71 {
72 return true;
73 }
74 else
75 {
76 return false;
77 }
78 }
79 }