KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > context > servlet > ServletFacesContextImplTest


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.context.servlet;
17
18 import org.apache.myfaces.MyFacesBaseTest;
19
20 import javax.faces.application.FacesMessage;
21 import javax.faces.context.FacesContext;
22 import java.util.Iterator JavaDoc;
23
24 /**
25  * @author Manfred Geiler (latest modification by $Author: matze $)
26  * @version $Revision: 1.3 $ $Date: 2004/10/13 11:50:59 $
27  * $Log: ServletFacesContextImplTest.java,v $
28  * Revision 1.3 2004/10/13 11:50:59 matze
29  * renamed packages to org.apache
30  *
31  * Revision 1.2 2004/07/01 22:01:09 mwessendorf
32  * ASF switch
33  *
34  * Revision 1.1 2004/04/16 13:57:00 manolito
35  * Bug #922317 - ClassCastException in action handler after adding message
36  *
37  */

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

43     public ServletFacesContextImplTest(String JavaDoc name)
44     {
45         super(name);
46     }
47
48     public void testGetMessages()
49     {
50         int cnt;
51         FacesContext context = new ServletFacesContextImpl(_servletContext,
52                                                            _httpServletRequest,
53                                                            _httpServletResponse);
54
55         context.addMessage("clientId1", new FacesMessage("summary1", "detail1"));
56         context.addMessage("clientId2", new FacesMessage("summary2", "detail2"));
57         context.addMessage(null, new FacesMessage("summary3", "detail3"));
58         context.addMessage("clientId2", new FacesMessage("summary4", "detail4"));
59         context.addMessage(null, new FacesMessage("summary5", "detail5"));
60         context.addMessage(null, new FacesMessage("summary6", "detail6"));
61
62         System.out.println("\nAll messages");
63         cnt = 0;
64         for (Iterator JavaDoc it = context.getMessages(); it.hasNext(); cnt++)
65         {
66             FacesMessage m = (FacesMessage)it.next();
67             System.out.println(m.getSummary() + "/" + m.getDetail());
68         }
69         assertEquals(cnt, 6);
70
71         System.out.println("\nclientId2 messages");
72         cnt = 0;
73         for (Iterator JavaDoc it = context.getMessages("clientId2"); it.hasNext(); cnt++)
74         {
75             FacesMessage m = (FacesMessage)it.next();
76             System.out.println(m.getSummary() + "/" + m.getDetail());
77         }
78         assertEquals(cnt, 2);
79
80         System.out.println("\nnull messages");
81         cnt = 0;
82         for (Iterator JavaDoc it = context.getMessages(null); it.hasNext(); cnt++)
83         {
84             FacesMessage m = (FacesMessage)it.next();
85             System.out.println(m.getSummary() + "/" + m.getDetail());
86         }
87         assertEquals(cnt, 3);
88     }
89 }
90
Popular Tags