KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > test > GenericResultTest


1 /*
2  * Copyright (c) 2003-2004, 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.controller.test;
8
9
10 import org.jdom.Document;
11 import org.jdom.Element;
12
13 import com.inversoft.config.ConfigurationException;
14 import com.inversoft.junit.WebTestCase;
15 import com.inversoft.verge.mvc.controller.GenericResult;
16 import com.inversoft.verge.util.url.config.URLConfigBuilder;
17 import com.inversoft.verge.util.url.config.URLConfigRegistry;
18
19
20 /**
21  * <p>
22  * This class tests the GenericResult class.
23  * </p>
24  *
25  * @author Brian Pontarelli
26  */

27 public class GenericResultTest extends WebTestCase {
28
29     /**
30      * Constructs a new <code>GenericResultTest</code>.
31      */

32     public GenericResultTest(String JavaDoc name) {
33         super(name);
34         setLocal(true);
35     }
36
37
38     /**
39      * Tests the basics of the GenericResult.
40      */

41     public void testBasics() throws Exception JavaDoc {
42         GenericResult result = new GenericResult("foo", null);
43         assertEquals("foo", result.getURL());
44         assertFalse(result.isForward());
45         assertNull(result.getCategory());
46         assertEquals("foo", result.getGeneratedURL(request));
47
48         result = new GenericResult("foo2", null, true);
49         assertEquals("foo2", result.getURL());
50         assertTrue(result.isForward());
51         assertNull(result.getCategory());
52         assertEquals("foo2", result.getGeneratedURL(request));
53
54         result = new GenericResult("foo3", "cat", false);
55         assertEquals("foo3", result.getURL());
56         assertFalse(result.isForward());
57         assertEquals("cat", result.getCategory());
58         assertEquals("foo3", result.getGeneratedURL(request));
59
60         result = new GenericResult("foo4", "cat", true);
61         assertEquals("foo4", result.getURL());
62         assertTrue(result.isForward());
63         assertEquals("cat", result.getCategory());
64         assertEquals("foo4", result.getGeneratedURL(request));
65     }
66
67     /**
68      * Tests a basic category.
69      */

70     public void testCategory() throws Exception JavaDoc {
71         // Setup some categories
72
URLConfigBuilder builder = new URLConfigBuilder();
73         Document doc = createGoodDocument();
74
75         try {
76             builder.build(doc,
77                 URLConfigRegistry.getInstance(request));
78         } catch (ConfigurationException ce) {
79             fail(ce.toString());
80         }
81
82         GenericResult result = new GenericResult("foo", "testCat1");
83         assertEquals("foo", result.getURL());
84         assertFalse(result.isForward());
85         assertEquals("testCat1", result.getCategory());
86         assertEquals("https://www.inversoft.com:8000/MyWebApp/foo",
87             result.getGeneratedURL(request));
88     }
89
90     /**
91      * Creates a category for testing.
92      */

93     public static Document createGoodDocument() {
94         Element root = new Element("url");
95         Document doc = new Document(root);
96
97         Element cat = new Element("category");
98         cat.setAttribute("name", "testCat1");
99         Element protocol = new Element("protocol");
100         protocol.addContent("https");
101         Element host = new Element("host");
102         host.addContent("www.inversoft.com");
103         Element port = new Element("port");
104         port.addContent("8000");
105         Element context = new Element("context");
106         context.addContent("MyWebApp");
107         cat.addContent(protocol);
108         cat.addContent(host);
109         cat.addContent(port);
110         cat.addContent(context);
111         root.addContent(cat);
112
113         return doc;
114     }
115 }
Popular Tags