KickJava   Java API By Example, From Geeks To Geeks.

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


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.verge.mvc.view.jsp.html.FormTag;
15 import com.inversoft.verge.mvc.view.jsp.html.ImageTag;
16
17
18 /**
19  * <p>
20  * This class has the tests for the image tag
21  * </p>
22  *
23  * @author Brian Pontarelli
24  * @since 2.0
25  * @version 2.0
26  */

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

33     public ImageTagTest(String JavaDoc name) {
34         super(name);
35         setLocal(true);
36     }
37
38
39     /**
40      * Tests the id attribute
41      */

42     public void testId() {
43         FormTag parent = new FormTag();
44         ImageTag tag = new ImageTag();
45         tag.setParent(parent);
46         tag.setPageContext(pageContext);
47         tag.setId("test");
48         tag.setSrc("test.gif");
49         
50         try {
51             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
52             String JavaDoc tagStr = getPageContext().getMockOut().getText();
53
54             System.out.println("Image tag: " + tagStr);
55             assertTrue("Should start with input", tagStr.startsWith(
56                 "<input type=\"image\" id=\"test\""));
57             assertTrue("Should end with src", tagStr.endsWith(
58                 "src=\"test.gif\"/>"));
59         } catch (JspException JavaDoc e) {
60             fail(e.toString());
61         }
62     }
63
64     /**
65      * Tests the name attribute
66      */

67     public void testName() {
68         FormTag parent = new FormTag();
69         ImageTag tag = new ImageTag();
70         tag.setParent(parent);
71         tag.setPageContext(pageContext);
72         tag.setName("test");
73         tag.setSrc("test.gif");
74         
75         try {
76             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
77             String JavaDoc tagStr = getPageContext().getMockOut().getText();
78
79             System.out.println("Image tag: " + tagStr);
80             assertTrue("Should start with input", tagStr.startsWith(
81                 "<input type=\"image\" name=\"test\""));
82             assertTrue("Should end with src", tagStr.endsWith(
83                 "src=\"test.gif\"/>"));
84         } catch (JspException JavaDoc e) {
85             fail(e.toString());
86         }
87     }
88
89     /**
90      * Tests the src attribute
91      */

92     public void testSrc() {
93         FormTag parent = new FormTag();
94         ImageTag tag = new ImageTag();
95         tag.setParent(parent);
96         tag.setPageContext(pageContext);
97         tag.setSrc("test.gif");
98         
99         try {
100             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
101             String JavaDoc tagStr = getPageContext().getMockOut().getText();
102
103             System.out.println("Image tag: " + tagStr);
104             assertTrue("Should start with input", tagStr.startsWith(
105                 "<input type=\"image\""));
106             assertTrue("Should end with src", tagStr.endsWith(
107                 "src=\"test.gif\"/>"));
108         } catch (JspException JavaDoc e) {
109             fail(e.toString());
110         }
111     }
112
113     /**
114      * Tests the usemap attribute
115      */

116     public void testUseMap() {
117         FormTag parent = new FormTag();
118         ImageTag tag = new ImageTag();
119         tag.setParent(parent);
120         tag.setPageContext(pageContext);
121         tag.setSrc("test.gif");
122         tag.setUsemap("test");
123         
124         try {
125             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
126             String JavaDoc tagStr = getPageContext().getMockOut().getText();
127
128             System.out.println("Image tag: " + tagStr);
129             assertTrue("Should start with input", tagStr.startsWith(
130                 "<input type=\"image\""));
131             assertTrue("Should end with usemap", tagStr.endsWith(
132                 "src=\"test.gif\" usemap=\"test\"/>"));
133         } catch (JspException JavaDoc e) {
134             fail(e.toString());
135         }
136     }
137
138     /**
139      * Tests the ismap attribute
140      */

141     public void testIsMap() {
142         FormTag parent = new FormTag();
143         ImageTag tag = new ImageTag();
144         tag.setParent(parent);
145         tag.setPageContext(pageContext);
146         tag.setSrc("test.gif");
147         tag.setIsmap("test");
148         
149         try {
150             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
151             String JavaDoc tagStr = getPageContext().getMockOut().getText();
152
153             System.out.println("Image tag: " + tagStr);
154             assertTrue("Should start with input", tagStr.startsWith(
155                 "<input type=\"image\""));
156             assertTrue("Should end with ismap", tagStr.endsWith(
157                 "src=\"test.gif\" ismap=\"test\"/>"));
158         } catch (JspException JavaDoc e) {
159             fail(e.toString());
160         }
161     }
162 }
Popular Tags