1 20 package org.apache.cactus.sample.servlet; 21 22 import javax.servlet.jsp.tagext.Tag ; 23 24 import org.apache.cactus.JspTestCase; 25 import org.apache.cactus.WebResponse; 26 27 32 public class TestSampleTag extends JspTestCase 33 { 34 37 private SampleTag tag; 38 39 42 public void setUp() 43 { 44 this.tag = new SampleTag(); 45 this.tag.setPageContext(this.pageContext); 46 } 47 48 50 57 public void testDoStartTag() throws Exception 58 { 59 this.pageContext.setAttribute("test-key", "test-value"); 61 62 this.tag.setShowBody("false"); 63 64 int result = this.tag.doStartTag(); 65 66 assertEquals(Tag.SKIP_BODY, result); 68 } 69 70 76 public void endDoStartTag(WebResponse theResponse) 77 { 78 assertContains(theResponse, 81 "The following attributes exist in page scope: <BR>"); 82 83 assertContains(theResponse, "test-key = test-value <BR>"); 84 } 85 86 88 94 public void testDoStartTagInclude() throws Exception 95 { 96 this.tag.setShowBody("true"); 97 98 int result = this.tag.doStartTag(); 99 100 assertEquals(Tag.EVAL_BODY_INCLUDE, result); 102 } 103 104 110 public void endDoStartTagInclude(WebResponse theResponse) 111 { 112 assertContains(theResponse, "Body Content Follows: <BR>"); 114 } 115 116 118 124 public void testDoEndTagContinue() throws Exception 125 { 126 this.tag.setParent(new SampleTag()); 127 this.tag.setStopPage("false"); 128 129 int result = this.tag.doEndTag(); 130 131 assertEquals(Tag.EVAL_PAGE, result); 132 } 133 134 140 public void endDoEndTagContinue(WebResponse theResponse) 141 { 142 assertContains(theResponse, "This tag has a parent. <BR>"); 143 } 144 145 147 153 public void testDoEndTagStop() throws Exception 154 { 155 this.tag.setStopPage("true"); 157 158 int result = this.tag.doEndTag(); 159 160 assertEquals(Tag.SKIP_PAGE, result); 161 } 162 163 169 public void endDoEndTagStop(WebResponse theResponse) 170 { 171 String target = theResponse.getText(); 172 boolean containsMessage = 173 target.indexOf("This tag has a parent. <BR>") > 0; 174 assertTrue(!containsMessage); 175 } 176 177 179 186 public void assertContains(WebResponse theResponse, String theSubstring) 187 { 188 String target = theResponse.getText(); 189 190 if (target.indexOf(theSubstring) < 0) 191 { 192 fail("Response did not contain the substring: [" + theSubstring 193 + "]"); 194 } 195 } 196 } 197 | Popular Tags |