1 5 package com.opensymphony.webwork.views.jsp; 6 7 import javax.servlet.jsp.JspException ; 8 import javax.servlet.jsp.tagext.BodyTag ; 9 import javax.servlet.jsp.tagext.Tag ; 10 import java.io.StringWriter ; 11 import java.util.Map ; 12 13 14 20 public class ParamTagTest extends AbstractTagTest { 21 23 private static final String NAME_EXP = "name"; 24 private static final String NAME_VAL = "name"; 25 private static final String VAL_EXP = "%{'value'}"; 26 private static final String VAL_VAL = "value"; 27 28 30 private ParamTag tag; 31 private ParametereizedBodyTagSupport parentTag; 32 33 35 public void testParamSetWithNameAndBodyContent() throws JspException { 36 StringWriter writer = new StringWriter (); 37 tag.setName(NAME_EXP); 38 39 WebWorkMockBodyContent webWorkMockBodyContent = new WebWorkMockBodyContent(new WebWorkMockJspWriter(writer)); 40 webWorkMockBodyContent.setString(VAL_VAL); 41 tag.setBodyContent(webWorkMockBodyContent); 42 assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag()); 43 assertEquals(Tag.EVAL_PAGE, tag.doEndTag()); 44 45 Map params = parentTag.getParameters(); 46 assertEquals(1, params.size()); 47 assertTrue(params.containsKey(NAME_VAL)); 48 assertEquals(VAL_VAL, params.get(NAME_VAL)); 49 } 50 51 public void testParamSetWithNameAndValueAttributes() throws JspException { 52 tag.setName(NAME_EXP); 53 tag.setValue(VAL_EXP); 54 assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag()); 55 assertEquals(Tag.EVAL_PAGE, tag.doEndTag()); 56 57 Map params = parentTag.getParameters(); 58 assertEquals(1, params.size()); 59 assertTrue(params.containsKey(NAME_VAL)); 60 assertEquals(VAL_VAL, params.get(NAME_VAL)); 61 } 62 63 public void testParamSetWithValueAttributeWhenBothValueAttrAndBodyAreSet() throws JspException { 64 StringWriter writer = new StringWriter (); 65 tag.setName(NAME_EXP); 66 tag.setValue(VAL_EXP); 67 68 WebWorkMockBodyContent webWorkMockBodyContent = new WebWorkMockBodyContent(new WebWorkMockJspWriter(writer)); 69 webWorkMockBodyContent.setString("Will not be used"); 70 tag.setBodyContent(webWorkMockBodyContent); 71 assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag()); 72 assertEquals(Tag.EVAL_PAGE, tag.doEndTag()); 73 74 Map params = parentTag.getParameters(); 75 assertEquals(1, params.size()); 76 assertTrue(params.containsKey(NAME_VAL)); 77 assertEquals(VAL_VAL, params.get(NAME_VAL)); 78 } 79 80 protected void setUp() throws Exception { 81 super.setUp(); 82 tag = new ParamTag(); 83 tag.setPageContext(pageContext); 84 parentTag = new ParametereizedBodyTagSupport(); 85 tag.setParent(parentTag); 86 } 87 } 88 | Popular Tags |