View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.application;
20  
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertNotNull;
23  
24  import java.io.IOException;
25  import java.util.ArrayList;
26  import java.util.Arrays;
27  import java.util.Collections;
28  import java.util.HashMap;
29  import java.util.LinkedHashSet;
30  import java.util.List;
31  import java.util.Map;
32  import java.util.Set;
33  
34  import javax.faces.FactoryFinder;
35  import javax.faces.application.NavigationCase;
36  
37  import org.apache.myfaces.config.RuntimeConfig;
38  import org.apache.myfaces.config.element.NavigationRule;
39  import org.apache.myfaces.config.impl.digester.DigesterFacesConfigUnmarshallerImpl;
40  import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
41  import org.junit.Assert;
42  import org.junit.Test;
43  import org.xml.sax.SAXException;
44  
45  public class NavigationHandlerImplTest extends AbstractJsfTestCase
46  {
47  
48      private DigesterFacesConfigUnmarshallerImpl _digesterFacesConfigUnmarshaller;
49  
50      public NavigationHandlerImplTest()
51      {
52          super();
53      }
54      
55      @Override
56      public void setUp() throws Exception
57      {
58          super.setUp();
59          _digesterFacesConfigUnmarshaller = new DigesterFacesConfigUnmarshallerImpl(
60                  externalContext);
61      }
62      
63      @Override
64      protected void setFactories() throws Exception
65      {
66          super.setFactories();
67          FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
68              "org.apache.myfaces.context.PartialViewContextFactoryImpl");
69      }
70  
71  
72      @Override
73      public void tearDown() throws Exception
74      {
75          _digesterFacesConfigUnmarshaller = null;
76          super.tearDown();
77      }
78  
79      private void loadTextFacesConfig(String file) throws SAXException,
80              IOException
81      {
82          RuntimeConfig runtimeConfig = RuntimeConfig
83                  .getCurrentInstance(externalContext);
84  
85          org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl config = _digesterFacesConfigUnmarshaller
86                  .getFacesConfig(getClass().getResourceAsStream(file), file);
87  
88          for (NavigationRule rule : config.getNavigationRules())
89          {
90              runtimeConfig.addNavigationRule(rule);
91          }
92      }
93  
94      @Test
95      public void testGetSimpleExactMatchRule() throws Exception
96      {
97          loadTextFacesConfig("simple-rules-config.xml");
98  
99          facesContext.getViewRoot().setViewId("/a.jsp");
100         NavigationHandlerImpl nh = new NavigationHandlerImpl();
101 
102         NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
103 
104         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
105     }
106 
107     @Test
108     public void testHandleSimpleExactMatchRule() throws Exception
109     {
110         loadTextFacesConfig("simple-rules-config.xml");
111 
112         facesContext.getViewRoot().setViewId("/a.jsp");
113         NavigationHandlerImpl nh = new NavigationHandlerImpl();
114 
115         nh.handleNavigation(facesContext, null, "go");
116 
117         Assert.assertEquals("/b.jsp", facesContext.getViewRoot().getViewId());
118     }
119 
120     @Test
121     public void testGetSimpleGlobalExactMatchRule() throws Exception
122     {
123         loadTextFacesConfig("simple-global-rules-config.xml");
124 
125         facesContext.getViewRoot().setViewId("/a.jsp");
126         NavigationHandlerImpl nh = new NavigationHandlerImpl();
127 
128         NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
129 
130         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
131     }
132 
133     @Test
134     public void testHandleSimpleGlobalExactMatchRule() throws Exception
135     {
136         loadTextFacesConfig("simple-global-rules-config.xml");
137 
138         facesContext.getViewRoot().setViewId("/a.jsp");
139         NavigationHandlerImpl nh = new NavigationHandlerImpl();
140 
141         nh.handleNavigation(facesContext, null, "go");
142 
143         Assert.assertEquals("/b.jsp", facesContext.getViewRoot().getViewId());
144     }
145     
146     @Test
147     public void testGetSimpleMixExactMatchRule() throws Exception
148     {
149         loadTextFacesConfig("simple-mix-rules-config.xml");
150 
151         facesContext.getViewRoot().setViewId("/a.jsp");
152         NavigationHandlerImpl nh = new NavigationHandlerImpl();
153 
154         NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
155 
156         Assert.assertEquals("/c.jsp", nc.getToViewId(facesContext));
157         
158         facesContext.getViewRoot().setViewId("/z.jsp");
159 
160         nc = nh.getNavigationCase(facesContext, null, "go");
161 
162         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
163     }
164 
165     @Test
166     public void testHandleSimpleMixExactMatchRule() throws Exception
167     {
168         loadTextFacesConfig("simple-mix-rules-config.xml");
169 
170         facesContext.getViewRoot().setViewId("/a.jsp");
171         NavigationHandlerImpl nh = new NavigationHandlerImpl();
172 
173         nh.handleNavigation(facesContext, null, "go");
174 
175         Assert.assertEquals("/c.jsp", facesContext.getViewRoot().getViewId());
176         
177         facesContext.getViewRoot().setViewId("/z.jsp");
178         
179         nh.handleNavigation(facesContext, null, "go");
180         
181         Assert.assertEquals("/b.jsp", facesContext.getViewRoot().getViewId());
182     }
183     
184     @Test
185     public void testGetSimplePartialExactMatchRule() throws Exception
186     {
187         loadTextFacesConfig("simple-partial-rules-config.xml");
188 
189         facesContext.getViewRoot().setViewId("/a.jsp");
190         NavigationHandlerImpl nh = new NavigationHandlerImpl();
191 
192         NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
193 
194         Assert.assertEquals("/cars/b.jsp", nc.getToViewId(facesContext));
195         
196         facesContext.getViewRoot().setViewId("/cars/z.jsp");
197 
198         nc = nh.getNavigationCase(facesContext, null, "go");
199 
200         Assert.assertEquals("/cars/c.jsp", nc.getToViewId(facesContext));
201     }
202 
203     @Test
204     public void testHandleSimplePartialExactMatchRule() throws Exception
205     {
206         loadTextFacesConfig("simple-partial-rules-config.xml");
207 
208         facesContext.getViewRoot().setViewId("/a.jsp");
209         NavigationHandlerImpl nh = new NavigationHandlerImpl();
210 
211         nh.handleNavigation(facesContext, null, "go");
212 
213         Assert.assertEquals("/cars/b.jsp", facesContext.getViewRoot().getViewId());
214         
215         facesContext.getViewRoot().setViewId("/cars/z.jsp");
216         
217         nh.handleNavigation(facesContext, null, "go");
218         
219         Assert.assertEquals("/cars/c.jsp", facesContext.getViewRoot().getViewId());
220     }
221     
222     @Test
223     public void testGetSimpleELExactMatchRule() throws Exception
224     {
225         loadTextFacesConfig("simple-el-rules-config.xml");
226 
227         facesContext.getViewRoot().setViewId("/a.jsp");
228         
229         NavigationHandlerImpl nh = new NavigationHandlerImpl();
230 
231         NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", "go");
232 
233         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
234     }
235     
236     @Test
237     public void testGetSimpleELExactMatchRuleFailNullOutcome() throws Exception
238     {
239         loadTextFacesConfig("simple-el-rules-config.xml");
240 
241         facesContext.getViewRoot().setViewId("/a.jsp");
242         
243         NavigationHandlerImpl nh = new NavigationHandlerImpl();
244 
245         NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", null);
246 
247         Assert.assertNull(nc);
248     }
249     
250     public static class TestBean
251     {
252         public boolean isTrue()
253         {
254             return true;
255         }
256         
257         public boolean isFalse()
258         {
259             return false;
260         }
261     }
262     
263     @Test
264     public void testGetSimpleIfExactMatchRule() throws Exception
265     {
266         loadTextFacesConfig("simple-if-rules-config.xml");
267 
268         externalContext.getRequestMap().put("test", new TestBean());
269         
270         facesContext.getViewRoot().setViewId("/a.jsp");
271         
272         NavigationHandlerImpl nh = new NavigationHandlerImpl();
273 
274         NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
275 
276         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
277     }
278     
279     @Test
280     public void testGetSimpleIfPreferMathRule() throws Exception
281     {
282         loadTextFacesConfig("simple-if-rules-config-2.xml");
283 
284         externalContext.getRequestMap().put("test", new TestBean());
285         
286         facesContext.getViewRoot().setViewId("/a.jsp");
287         
288         NavigationHandlerImpl nh = new NavigationHandlerImpl();
289 
290         NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
291 
292         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
293     }
294     
295     @Test
296     public void testGetSimpleIfPreferMathRule2() throws Exception
297     {
298         loadTextFacesConfig("simple-if-rules-config-3.xml");
299 
300         externalContext.getRequestMap().put("test", new TestBean());
301         
302         facesContext.getViewRoot().setViewId("/a.jsp");
303         
304         NavigationHandlerImpl nh = new NavigationHandlerImpl();
305 
306         NavigationCase nc = nh.getNavigationCase(facesContext, "go", null);
307 
308         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
309         
310         nc = nh.getNavigationCase(facesContext, "go", "xx");
311 
312         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
313     }
314 
315     @Test
316     public void testGetSimpleNotIfExactMatchRule() throws Exception
317     {
318         loadTextFacesConfig("simple-if-rules-config.xml");
319 
320         externalContext.getRequestMap().put("test", new TestBean());
321         
322         facesContext.getViewRoot().setViewId("/b.jsp");
323         
324         NavigationHandlerImpl nh = new NavigationHandlerImpl();
325 
326         NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
327 
328         Assert.assertEquals("/d.jsp", nc.getToViewId(facesContext));
329     }
330     
331     @Test
332     public void testGetSimplePreemptiveIfExactMatchRule() throws Exception
333     {
334         loadTextFacesConfig("simple-if-rules-config.xml");
335 
336         externalContext.getRequestMap().put("test", new TestBean());
337         
338         facesContext.getViewRoot().setViewId("/x.jsp");
339         
340         NavigationHandlerImpl nh = new NavigationHandlerImpl();
341 
342         NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
343 
344         Assert.assertEquals("/go.jsp", nc.getToViewId(facesContext));
345     }    
346     
347     @Test
348     public void testGetSimpleGlobalPreemptiveMatchRule() throws Exception
349     {
350         loadTextFacesConfig("simple-global-preemptive-rules-config.xml");
351 
352         externalContext.getRequestMap().put("test", new TestBean());
353         
354         facesContext.getViewRoot().setViewId("/x.jsp");
355         
356         NavigationHandlerImpl nh = new NavigationHandlerImpl();
357 
358         NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
359 
360         Assert.assertEquals("/a.jsp", nc.getToViewId(facesContext));
361     }
362     
363     @Test
364     public void testGetSimpleELNoCondMatchRule() throws Exception
365     {
366         loadTextFacesConfig("simple-el-nocond-rules-config.xml");
367 
368         facesContext.getViewRoot().setViewId("/a.jsp");
369         
370         NavigationHandlerImpl nh = new NavigationHandlerImpl();
371 
372         NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", "go");
373 
374         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
375     }
376     
377     @Test
378     public void testGetSimpleELNoCondNullOutcomeMatchRule() throws Exception
379     {
380         loadTextFacesConfig("simple-el-nocond-rules-config.xml");
381 
382         facesContext.getViewRoot().setViewId("/a.jsp");
383         
384         NavigationHandlerImpl nh = new NavigationHandlerImpl();
385 
386         NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", null);
387 
388         Assert.assertNull(nc);
389     }
390     
391     @Test
392     public void testActionOutcomePrecendeceMachRule() throws Exception
393     {
394         loadTextFacesConfig("simple-action-outcome-precedence-config.xml");
395 
396         for (int i = 0; i < 2; i++)
397         {
398             final int j = i;
399             facesContext.getViewRoot().setViewId("/a.jsp");
400             
401             NavigationHandlerImpl nh = new NavigationHandlerImpl(){
402     
403                 @Override
404                 public Map<String, Set<NavigationCase>> getNavigationCases()
405                 {
406                     // We have two conditions, this code is for rotate the ordering so we
407                     // test all possible outputs
408                     Map<String, Set<NavigationCase>> map = super.getNavigationCases();
409                     Map<String, Set<NavigationCase>> map2 = new HashMap<String, Set<NavigationCase>>();
410                     
411                     for (Map.Entry<String, Set<NavigationCase>> entry : map.entrySet())
412                     {
413                         LinkedHashSet<NavigationCase> set = new LinkedHashSet<NavigationCase>();
414                         List<NavigationCase> list = new ArrayList<NavigationCase>();
415                         list.addAll(entry.getValue());
416                         Collections.rotate(list, j);
417                         set.addAll(list);
418                         map2.put(entry.getKey(), set);
419                     }
420                     return map2; 
421                 }
422             };
423     
424             NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", "go");
425     
426             Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
427         }
428     }
429     
430     @Test
431     public void testActionOutcomePrecendeceAlternateOutcomeMachRule() throws Exception
432     {
433         loadTextFacesConfig("simple-action-outcome-precedence-config.xml");
434 
435         for (int i = 0; i < 2; i++)
436         {
437             final int j = i;
438             facesContext.getViewRoot().setViewId("/a.jsp");
439             
440             NavigationHandlerImpl nh = new NavigationHandlerImpl(){
441     
442                 @Override
443                 public Map<String, Set<NavigationCase>> getNavigationCases()
444                 {
445                     // We have two conditions, this code is for rotate the ordering so we
446                     // test all possible outputs
447                     Map<String, Set<NavigationCase>> map = super.getNavigationCases();
448                     Map<String, Set<NavigationCase>> map2 = new HashMap<String, Set<NavigationCase>>();
449                     
450                     for (Map.Entry<String, Set<NavigationCase>> entry : map.entrySet())
451                     {
452                         LinkedHashSet<NavigationCase> set = new LinkedHashSet<NavigationCase>();
453                         List<NavigationCase> list = new ArrayList<NavigationCase>();
454                         list.addAll(entry.getValue());
455                         Collections.rotate(list, j);
456                         set.addAll(list);
457                         map2.put(entry.getKey(), set);
458                     }
459                     return map2; 
460                 }
461             };
462     
463             NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", "nogo");
464     
465             Assert.assertEquals("/c.jsp", nc.getToViewId(facesContext));
466         }
467     }
468 
469     @Test
470     public void testActionOutcomePrecendeceNoOutcomeMachRule() throws Exception
471     {
472         loadTextFacesConfig("simple-action-outcome-precedence-config.xml");
473 
474         for (int i = 0; i < 2; i++)
475         {
476             final int j = i;
477             facesContext.getViewRoot().setViewId("/a.jsp");
478             
479             NavigationHandlerImpl nh = new NavigationHandlerImpl(){
480     
481                 @Override
482                 public Map<String, Set<NavigationCase>> getNavigationCases()
483                 {
484                     // We have two conditions, this code is for rotate the ordering so we
485                     // test all possible outputs
486                     Map<String, Set<NavigationCase>> map = super.getNavigationCases();
487                     Map<String, Set<NavigationCase>> map2 = new HashMap<String, Set<NavigationCase>>();
488                     
489                     for (Map.Entry<String, Set<NavigationCase>> entry : map.entrySet())
490                     {
491                         LinkedHashSet<NavigationCase> set = new LinkedHashSet<NavigationCase>();
492                         List<NavigationCase> list = new ArrayList<NavigationCase>();
493                         list.addAll(entry.getValue());
494                         Collections.rotate(list, j);
495                         set.addAll(list);
496                         map2.put(entry.getKey(), set);
497                     }
498                     return map2; 
499                 }
500             };
501     
502             NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", null);
503     
504             //If the <if> element is absent, only match a non-null outcome
505             Assert.assertNull(nc);
506         }
507     }
508     
509     @Test
510     public void testActionOutcomePrecendece2MachRule() throws Exception
511     {
512         loadTextFacesConfig("simple-action-outcome-precedence-2-config.xml");
513 
514         for (int i = 0; i < 2; i++)
515         {
516             final int j = i;
517             facesContext.getViewRoot().setViewId("/a.jsp");
518             
519             NavigationHandlerImpl nh = new NavigationHandlerImpl(){
520     
521                 @Override
522                 public Map<String, Set<NavigationCase>> getNavigationCases()
523                 {
524                     // We have two conditions, this code is for rotate the ordering so we
525                     // test all possible outputs
526                     Map<String, Set<NavigationCase>> map = super.getNavigationCases();
527                     Map<String, Set<NavigationCase>> map2 = new HashMap<String, Set<NavigationCase>>();
528                     
529                     for (Map.Entry<String, Set<NavigationCase>> entry : map.entrySet())
530                     {
531                         LinkedHashSet<NavigationCase> set = new LinkedHashSet<NavigationCase>();
532                         List<NavigationCase> list = new ArrayList<NavigationCase>();
533                         list.addAll(entry.getValue());
534                         Collections.rotate(list, j);
535                         set.addAll(list);
536                         map2.put(entry.getKey(), set);
537                     }
538                     return map2; 
539                 }
540             };
541     
542             NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", "go");
543     
544             Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
545         }
546     }
547     
548     /**
549      * Tests if the URL parameters of an outcome are correctly
550      * added to the NavigationCase.
551      */
552     @Test
553     public void testFacesRedirectAddsUrlParameters()
554     {
555         NavigationHandlerImpl nh = new NavigationHandlerImpl();
556         
557         // get the NavigationCase
558         // note that the URL parameters can be separated via & or &amp;
559         NavigationCase navigationCase = nh.getNavigationCase(facesContext, null, 
560                 "test.xhtml?faces-redirect=true&a=b&amp;includeViewParams=true&amp;c=d&e=f");
561         
562         // created the expected parameter map
563         Map<String, List<String>> expected = new HashMap<String, List<String>>();
564         expected.put("a", Arrays.asList("b"));
565         expected.put("c", Arrays.asList("d"));
566         expected.put("e", Arrays.asList("f"));
567         // note that faces-redirect and includeViewParams
568         // should not be added as a parameter
569         
570         Assert.assertEquals(expected, navigationCase.getParameters());
571         Assert.assertTrue("includeViewParams=true in the query String must "
572                 + "set includeViewParams to true.", navigationCase.isIncludeViewParams());
573         Assert.assertTrue("redirect=true in the query String must "
574                 + "set redirect to true.", navigationCase.isRedirect());
575     }
576     
577     /**
578      * Tests if the URL parameters of an outcome are correctly
579      * added to the NavigationCase.
580      * Identically to testFacesRedirectAddsUrlParameters(), except that
581      * it uses faces-include-view-params=true instead of includeViewParams=true.
582      */
583     @Test
584     public void testFacesRedirectAddsUrlParametersFacesIncludeViewParams()
585     {
586         NavigationHandlerImpl nh = new NavigationHandlerImpl();
587         
588         // get the NavigationCase
589         // note that the URL parameters can be separated via & or &amp;
590         NavigationCase navigationCase = nh.getNavigationCase(facesContext, null, 
591                 "test.xhtml?faces-redirect=true&a=b&amp;faces-include-view-params=true&amp;c=d&e=f");
592         
593         // created the expected parameter map
594         Map<String, List<String>> expected = new HashMap<String, List<String>>();
595         expected.put("a", Arrays.asList("b"));
596         expected.put("c", Arrays.asList("d"));
597         expected.put("e", Arrays.asList("f"));
598         // note that faces-redirect and faces-include-view-params
599         // should not be added as a parameter
600         
601         Assert.assertEquals(expected, navigationCase.getParameters());
602         Assert.assertTrue("faces-include-view-params=true in the query String must "
603                 + "set includeViewParams to true.", navigationCase.isIncludeViewParams());
604         Assert.assertTrue("redirect=true in the query String must "
605                 + "set redirect to true.", navigationCase.isRedirect());
606     }
607     
608     /**
609      * Test for MYFACES-3101
610      */
611     @Test
612     public void testHandleViewExpiredExpcetion() throws Exception {
613         NavigationHandlerImpl underTest = new NavigationHandlerImpl();
614         // simulate no available ViewRoot (in case of VEE)
615         facesContext.setViewRoot(null);
616         
617         facesContext.getExternalContext().getRequestMap().put("javax.servlet.include.servlet_path", "/faces/home.xhtml");
618         // test is based on:
619         // http://www.nfjsone.com/blog/ed_burns/2009/09/dealing_gracefully_with_viewexpiredexception_in_jsf2
620         underTest.handleNavigation(facesContext, null, "viewExpired");
621 
622         assertNotNull(facesContext.getViewRoot());
623         assertEquals("/viewExpired.xhtml", facesContext.getViewRoot().getViewId());
624     }
625     
626     @Test
627     public void testHandleViewExpiredExpcetion2() throws Exception {
628         NavigationHandlerImpl underTest = new NavigationHandlerImpl();
629         // simulate no available ViewRoot (in case of VEE)
630         facesContext.setViewRoot(null);
631         
632         facesContext.getExternalContext().getRequestMap().put("javax.servlet.include.servlet_path", "/home.jsf");
633         // test is based on:
634         // http://www.nfjsone.com/blog/ed_burns/2009/09/dealing_gracefully_with_viewexpiredexception_in_jsf2
635         underTest.handleNavigation(facesContext, null, "viewExpired.xhtml");
636 
637         assertNotNull(facesContext.getViewRoot());
638         assertEquals("/viewExpired.xhtml", facesContext.getViewRoot().getViewId());
639         
640     }
641     
642     @Test
643     public void testHandleViewExpiredExpcetion3() throws Exception {
644         NavigationHandlerImpl underTest = new NavigationHandlerImpl();
645         // simulate no available ViewRoot (in case of VEE)
646         facesContext.setViewRoot(null);
647         
648         facesContext.getExternalContext().getRequestMap().put("javax.servlet.include.servlet_path", "/home.jsf");
649         // test is based on:
650         // http://www.nfjsone.com/blog/ed_burns/2009/09/dealing_gracefully_with_viewexpiredexception_in_jsf2
651         underTest.handleNavigation(facesContext, null, "viewExpired");
652 
653         assertNotNull(facesContext.getViewRoot());
654         
655         // In this case, we have /viewExpired.jsf, but note the default ViewHandlerImpl converts the viewId
656         // from /viewExpired.jsf to /viewExpired.xhtml, when deriveViewId() is called.
657         assertEquals("/viewExpired.jsf", facesContext.getViewRoot().getViewId());
658         
659     }
660 
661    @Test
662     public void testHandleViewExpiredExpcetion4() throws Exception {
663         NavigationHandlerImpl underTest = new NavigationHandlerImpl();
664         // simulate no available ViewRoot (in case of VEE)
665         facesContext.setViewRoot(null);
666         // test is based on:
667         // http://www.nfjsone.com/blog/ed_burns/2009/09/dealing_gracefully_with_viewexpiredexception_in_jsf2
668         underTest.handleNavigation(facesContext, null, "viewExpired.xhtml");
669 
670         assertNotNull(facesContext.getViewRoot());
671         assertEquals("/viewExpired.xhtml", facesContext.getViewRoot().getViewId());
672         
673     } 
674     
675     /**
676      * Test for MYFACES-3101 - partial request (without redirect)
677      */
678     @Test
679     public void testHandleViewExpiredExpcetionForPartial() throws Exception {
680         NavigationHandlerImpl underTest = new NavigationHandlerImpl();
681         // simulate no available ViewRoot (in case of VEE)
682         facesContext.setViewRoot(null);
683         facesContext.getPartialViewContext().setPartialRequest(true);
684         
685         underTest.handleNavigation(facesContext, null, "/viewExpired.xhtml");
686         
687         assertNotNull(facesContext.getViewRoot());
688         assertEquals("/viewExpired.xhtml", facesContext.getViewRoot().getViewId());
689     }
690     
691     @Test
692     public void testIfDoNotMatchWhenOutcomeNull() throws Exception
693     {
694         loadTextFacesConfig("simple-if-rules-config-4.xml");
695 
696         externalContext.getRequestMap().put("test", new TestBean());
697         
698         facesContext.getViewRoot().setViewId("/a.jsp");
699         
700         NavigationHandlerImpl nh = new NavigationHandlerImpl();
701 
702         NavigationCase nc = nh.getNavigationCase(facesContext, null, null);
703 
704         Assert.assertNull(nc);
705         
706         nc = nh.getNavigationCase(facesContext, null, "go");
707 
708         Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
709     }
710     
711 }