KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > html > test > ImgTagTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.html.test;
8
9
10 import javax.servlet.jsp.JspException JavaDoc;
11 import javax.servlet.jsp.tagext.Tag JavaDoc;
12
13 import com.inversoft.junit.JspTestCase;
14 import com.inversoft.junit.Request;
15 import com.inversoft.junit.URL;
16 import com.inversoft.verge.mvc.view.jsp.html.ImgTag;
17
18
19 /**
20  * <p>
21  * This class has the test cases for the img tag
22  * </p>
23  *
24  * @author Brian Pontarelli
25  * @since 2.0
26  * @version 2.0
27  */

28 public class ImgTagTest extends JspTestCase {
29
30     /**
31      * Constructor for ImgTagTest.
32      * @param name
33      */

34     public ImgTagTest(String JavaDoc name) {
35         super(name);
36         setLocal(true);
37     }
38
39
40     /**
41      * Test that the image works without the context path
42      */

43     public void testWithoutContext() {
44         ImgTag tag = new ImgTag();
45         tag.setPageContext(pageContext);
46         tag.setName("testName");
47         tag.setSrc("test.gif");
48
49         try {
50             assertEquals("Should have returned EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
51             String JavaDoc tagStr = getPageContext().getMockOut().getText();
52
53             System.out.println("Img tag: " + tagStr);
54             assertEquals("Should have tag", tagStr,
55                 "<img name=\"testName\" SRC=\"test.gif\"/>");
56         } catch (JspException JavaDoc e) {
57             fail(e.toString());
58         }
59     }
60
61     /**
62      * Sets up a context path
63      */

64     public void beginContext(Request request) {
65         URL url = new URL("context", null, "http", null, "test", "test");
66         request.setURL(url);
67     }
68
69     /**
70      * Test that the image works with the context path
71      */

72     public void testContext() {
73         ImgTag tag = new ImgTag();
74         tag.setPageContext(pageContext);
75         tag.setSrc("/test.gif");
76
77         try {
78             assertEquals("Should have returned EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
79             String JavaDoc tagStr = getPageContext().getMockOut().getText();
80
81             System.out.println("Img tag: " + tagStr);
82             assertEquals("Should have tag", tagStr,
83                 "<img SRC=\"/context/test.gif\"/>");
84         } catch (JspException JavaDoc e) {
85             fail(e.toString());
86         }
87     }
88
89     /**
90      * Sets up a context path
91      */

92     public void beginNoContext(Request request) {
93         URL url = new URL("context", null, "http", null, "test", "test");
94         request.setURL(url);
95     }
96
97     /**
98      * Test that the image works with the context path
99      */

100     public void testNoContext() {
101         ImgTag tag = new ImgTag();
102         tag.setPageContext(pageContext);
103         tag.setSrc("/test.gif");
104         tag.setContext(Boolean.FALSE);
105
106         try {
107             assertEquals("Should have returned EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
108             String JavaDoc tagStr = getPageContext().getMockOut().getText();
109
110             System.out.println("Img tag: " + tagStr);
111             assertEquals("Should have tag", tagStr,
112                 "<img SRC=\"/test.gif\"/>");
113         } catch (JspException JavaDoc e) {
114             fail(e.toString());
115         }
116     }
117 }
Popular Tags