1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.mockobjects.dynamic.C; 8 import com.mockobjects.dynamic.Mock; 9 10 import javax.servlet.ServletContext ; 11 import javax.servlet.http.HttpSession ; 12 import javax.servlet.jsp.JspException ; 13 import javax.servlet.jsp.tagext.Tag ; 14 15 16 20 public class SetTagTest extends AbstractUITagTest { 21 23 Chewbacca chewie; 24 SetTag tag; 25 26 28 public void testApplicationScope() throws JspException { 29 Mock application = new Mock(ServletContext .class); 30 application.expect("setAttribute", C.args(C.eq("foo"), C.eq("chewie"))); 31 pageContext.setServletContext((ServletContext ) application.proxy()); 32 33 tag.setName("foo"); 34 tag.setValue("name"); 35 tag.setScope("application"); 36 assertEquals(Tag.SKIP_BODY, tag.doStartTag()); 37 application.verify(); 38 } 39 40 public void testPageScope() throws JspException { 41 tag.setName("foo"); 42 tag.setValue("name"); 43 tag.setScope("page"); 44 assertEquals(Tag.SKIP_BODY, tag.doStartTag()); 45 } 46 47 public void testRequestScope() throws JspException { 48 tag.setName("foo"); 49 tag.setValue("name"); 50 tag.setScope("request"); 51 assertEquals(Tag.SKIP_BODY, tag.doStartTag()); 52 assertEquals("chewie", request.getAttribute("foo")); 53 } 54 55 public void testSessionScope() throws JspException { 56 Mock session = new Mock(HttpSession .class); 57 session.expect("setAttribute", C.args(C.eq("foo"), C.eq("chewie"))); 58 pageContext.setSession((HttpSession ) session.proxy()); 59 60 tag.setName("foo"); 61 tag.setValue("name"); 62 tag.setScope("session"); 63 assertEquals(Tag.SKIP_BODY, tag.doStartTag()); 64 session.verify(); 65 } 66 67 public void testWebWorkScope() throws JspException { 68 tag.setName("foo"); 69 tag.setValue("name"); 70 assertEquals(Tag.SKIP_BODY, tag.doStartTag()); 71 assertEquals("chewie", context.get("foo")); 72 } 73 74 public void testWebWorkScope2() throws JspException { 75 tag.setName("chewie"); 76 assertEquals(Tag.SKIP_BODY, tag.doStartTag()); 77 assertEquals(chewie, context.get("chewie")); 78 } 79 80 protected void setUp() throws Exception { 81 super.setUp(); 82 83 tag = new SetTag(); 84 chewie = new Chewbacca("chewie", true); 85 stack.push(chewie); 86 tag.setPageContext(pageContext); 87 } 88 89 91 public class Chewbacca { 92 String name; 93 boolean furry; 94 95 public Chewbacca(String name, boolean furry) { 96 this.name = name; 97 this.furry = furry; 98 } 99 100 public void setFurry(boolean furry) { 101 this.furry = furry; 102 } 103 104 public boolean isFurry() { 105 return furry; 106 } 107 108 public void setName(String name) { 109 this.name = name; 110 } 111 112 public String getName() { 113 return name; 114 } 115 } 116 } 117 | Popular Tags |