KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.jdom.Document;
14 import org.jdom.Element;
15
16 import com.inversoft.config.ConfigurationException;
17 import com.inversoft.junit.JspTestCase;
18 import com.inversoft.junit.internal.http.MockHttpServletRequest;
19 import com.inversoft.verge.mvc.view.jsp.html.ATag;
20 import com.inversoft.verge.util.url.config.URLConfigBuilder;
21 import com.inversoft.verge.util.url.config.URLConfigRegistry;
22
23
24 /**
25  * <p>
26  * This class has the test cases for the a tag
27  * </p>
28  *
29  * @author Brian Pontarelli
30  * @since 2.0
31  * @version 2.0
32  */

33 public class ATagTest2 extends JspTestCase {
34
35     static {
36         URLConfigBuilder builder = new URLConfigBuilder();
37         Document doc = createGoodDocument();
38
39         try {
40             builder.build(doc,
41                 URLConfigRegistry.getInstance(new MockHttpServletRequest(null)));
42         } catch (ConfigurationException ce) {
43             fail(ce.toString());
44         }
45     }
46
47     /**
48      * Constructor for ATagTest.
49      * @param name
50      */

51     public ATagTest2(String JavaDoc name) {
52         super(name);
53         setLocal(true);
54     }
55
56
57     /**
58      * Test that the URLGenerator system works with the a tag
59      */

60     public void testURLGenerator() {
61         ATag tag = new ATag();
62         tag.setPageContext(pageContext);
63         tag.setHref("/some.jsp");
64         tag.setBodyContent(createBodyContent());
65
66         try {
67             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
68             String JavaDoc tagStr = getPageContext().getMockOut().getText();
69             String JavaDoc expected = "<a HREF=\"http://www.yahoo.com:8001/YahooContext/some.jsp\"></a>";
70
71             System.out.println("a tag: " + tagStr);
72             System.out.println("expected: " + expected);
73             assertEquals("Should have tag", tagStr, expected);
74         } catch (JspException JavaDoc e) {
75             fail(e.toString());
76         }
77     }
78
79     public static Document createGoodDocument() {
80         Element root = new Element("url");
81         Document doc = new Document(root);
82
83         Element cat = new Element("category");
84         cat.setAttribute("name", "category1");
85         Element protocol = new Element("protocol");
86         protocol.addContent("https");
87         Element host = new Element("host");
88         host.addContent("www.inversoft.com");
89         Element port = new Element("port");
90         port.addContent("8000");
91         Element context = new Element("context");
92         context.addContent("MyWebApp");
93         cat.addContent(protocol);
94         cat.addContent(host);
95         cat.addContent(port);
96         cat.addContent(context);
97         root.addContent(cat);
98
99         cat = new Element("category");
100         cat.setAttribute("name", "view");
101         protocol = new Element("protocol");
102         protocol.addContent("http");
103         host = new Element("host");
104         host.addContent("www.yahoo.com");
105         port = new Element("port");
106         port.addContent("8001");
107         context = new Element("context");
108         context.addContent("YahooContext");
109         cat.addContent(protocol);
110         cat.addContent(host);
111         cat.addContent(port);
112         cat.addContent(context);
113         root.addContent(cat);
114
115         return doc;
116     }
117 }
Popular Tags