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.ArrayList ; 12 import java.util.List ; 13 import java.util.Map ; 14 15 16 22 public class ParamTagUnnamedTest extends AbstractTagTest { 23 25 private static final String NAME_EXP = "'name'"; 26 private static final String NAME_VAL = "name"; 27 private static final String VAL_EXP = "'value'"; 28 private static final String VAL_VAL = "value"; 29 30 32 private ParamTag tag; 33 private UnnamedParametricBodyTag parentTag; 34 35 37 public void testParamSetWithBodyContent() throws JspException { 38 StringWriter writer = new StringWriter (); 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 List params = parentTag.getValuesList(); 46 assertEquals(1, params.size()); 47 assertEquals(VAL_VAL, params.get(0)); 48 } 49 50 public void testParamSetWithValueAttribute() throws JspException { 51 tag.setValue(VAL_EXP); 52 assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag()); 53 assertEquals(Tag.EVAL_PAGE, tag.doEndTag()); 54 55 List params = parentTag.getValuesList(); 56 assertEquals(1, params.size()); 57 assertEquals(VAL_VAL, params.get(0)); 58 } 59 60 public void testParamSetWithValueAttributeWhenBothValueAttrAndBodyAreSet() throws JspException { 61 StringWriter writer = new StringWriter (); 62 tag.setValue(VAL_EXP); 63 64 WebWorkMockBodyContent webWorkMockBodyContent = new WebWorkMockBodyContent(new WebWorkMockJspWriter(writer)); 65 webWorkMockBodyContent.setString("Will not be used"); 66 tag.setBodyContent(webWorkMockBodyContent); 67 assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag()); 68 assertEquals(Tag.EVAL_PAGE, tag.doEndTag()); 69 70 List params = parentTag.getValuesList(); 71 assertEquals(1, params.size()); 72 assertEquals(VAL_VAL, params.get(0)); 73 } 74 75 protected void setUp() throws Exception { 76 super.setUp(); 77 tag = new ParamTag(); 78 tag.setPageContext(pageContext); 79 parentTag = new UnnamedParametricBodyTag(); 80 tag.setParent(parentTag); 81 } 82 83 85 private class UnnamedParametricBodyTag extends WebWorkBodyTagSupport implements ParamTag.UnnamedParametric { 86 private List values; 87 88 public Map getParameters() { 89 return null; 90 } 91 92 public List getValuesList() { 93 return values; 94 } 95 96 public void addParameter(String aName, Object aValue) { 97 addParameter(aValue); 98 } 99 100 public void addParameter(Object aValue) { 101 if (aValue == null) { 102 return; 103 } 104 105 if (values == null) { 106 values = new ArrayList (); 107 } 108 109 values.add(aValue); 110 } 111 } 112 } 113 | Popular Tags |