1 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 ; 23 24 38 public class ServletFacesContextImplTest 39 extends MyFacesBaseTest 40 { 41 43 public ServletFacesContextImplTest(String 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 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 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 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 |