KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > application > NavigationHandlerImplTest


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.application;
17
18 import org.apache.myfaces.MyFacesBaseTest;
19
20 import javax.faces.application.NavigationHandler;
21 import javax.faces.component.UIViewRoot;
22
23 /**
24  * @author Manfred Geiler (latest modification by $Author: matze $)
25  * @version $Revision: 1.3 $ $Date: 2004/10/13 11:50:59 $
26  * $Log: NavigationHandlerImplTest.java,v $
27  * Revision 1.3 2004/10/13 11:50:59 matze
28  * renamed packages to org.apache
29  *
30  * Revision 1.2 2004/07/01 22:01:14 mwessendorf
31  * ASF switch
32  *
33  * Revision 1.1 2004/04/26 11:24:15 manolito
34  * new NavigationHandlerImplTest and some junit refactoring
35  *
36  */

37 public class NavigationHandlerImplTest
38          extends MyFacesBaseTest
39 {
40     //private static final Log log = LogFactory.getLog(NavigationHandlerImplTest.class);
41

42     public NavigationHandlerImplTest(String JavaDoc name)
43     {
44         super(name);
45     }
46
47     public void test()
48     {
49         NavigationHandler navigationHandler = _application.getNavigationHandler();
50
51         UIViewRoot viewRoot = new UIViewRoot();
52
53         // case 1: no from-view-id
54
viewRoot.setViewId("/anypage.jsp");
55         _facesContext.setViewRoot(viewRoot);
56         navigationHandler.handleNavigation(_facesContext, "#{anyaction}", "outcome1");
57         assertEquals(_facesContext.getViewRoot().getViewId(), "/page1.jsp");
58
59         // case 2: from-view-id = *, with from-outcome, no from-action
60
viewRoot.setViewId("/anypage.jsp");
61         _facesContext.setViewRoot(viewRoot);
62         navigationHandler.handleNavigation(_facesContext, "#{anyaction}", "outcome2");
63         assertEquals(_facesContext.getViewRoot().getViewId(), "/page2.jsp");
64
65         // case 3: from-view-id = *, with from-outcome and from-action
66
viewRoot.setViewId("/anypage.jsp");
67         _facesContext.setViewRoot(viewRoot);
68         navigationHandler.handleNavigation(_facesContext, "#{action3}", "outcome3");
69         assertEquals(_facesContext.getViewRoot().getViewId(), "/page3.jsp");
70
71         // case 4: from-view-id = *, no from-outcome, with from-action
72
viewRoot.setViewId("/anypage.jsp");
73         _facesContext.setViewRoot(viewRoot);
74         navigationHandler.handleNavigation(_facesContext, "#{action4}", "anyoutcome");
75         assertEquals(_facesContext.getViewRoot().getViewId(), "/page4.jsp");
76
77         // case 5: exact from-view-id match, with from-outcome, no from-action
78
viewRoot.setViewId("/from5.jsp");
79         _facesContext.setViewRoot(viewRoot);
80         navigationHandler.handleNavigation(_facesContext, "#{anyaction}", "outcome5");
81         assertEquals(_facesContext.getViewRoot().getViewId(), "/page5.jsp");
82
83         // case 6: wildcard from-view-id match, with from-outcome, no from-action
84
viewRoot.setViewId("/context6/anypage.jsp");
85         _facesContext.setViewRoot(viewRoot);
86         navigationHandler.handleNavigation(_facesContext, "#{anyaction}", "outcome6");
87         assertEquals(_facesContext.getViewRoot().getViewId(), "/page6.jsp");
88
89         // no match
90
viewRoot.setViewId("/anycontext/anypage.jsp");
91         _facesContext.setViewRoot(viewRoot);
92         navigationHandler.handleNavigation(_facesContext, "#{anyaction}", "anyoutcome");
93         assertEquals(_facesContext.getViewRoot().getViewId(), "/anycontext/anypage.jsp");
94
95     }
96
97 }
98
Popular Tags