KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > model > web > test > WebModelResolverTest


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.model.web.test;
8
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import com.inversoft.junit.WebTestCase;
14 import com.inversoft.verge.mvc.MVCException;
15 import com.inversoft.verge.mvc.MVCRequest;
16 import com.inversoft.verge.mvc.model.ModelResolution;
17 import com.inversoft.verge.mvc.model.web.WebMetaData;
18 import com.inversoft.verge.mvc.model.web.WebModelResolver;
19 import com.inversoft.verge.util.ScopeConstants;
20
21
22 /**
23  * <p>
24  * This class contains the TestCases for resolver
25  * </p>
26  *
27  * @author Brian Pontarelli
28  * @since 2.0
29  * @version 2.0
30  */

31 public class WebModelResolverTest extends WebTestCase {
32
33     /**
34      * Constructs a new <code>WebModelResolverTest</code> TestCase instance
35      */

36     public WebModelResolverTest(String JavaDoc name) {
37         super(name);
38         setLocal(true);
39     }
40
41
42     /**
43      * Tests the resolver works correctly
44      */

45     public void testAll() {
46
47         Map JavaDoc params = new HashMap JavaDoc();
48         params.put(WebMetaData.CLASS_PARAMETER,
49             "com.inversoft.verge.mvc.model.web.test.Bean1");
50         params.put(WebMetaData.SCOPE_PARAMETER,
51             Integer.toString(ScopeConstants.SESSION_INT));
52         MVCRequest mvcRequest = new MVCRequest(request, response);
53
54         try {
55             WebModelResolver resolver = new WebModelResolver();
56             ModelResolution resolved = resolver.resolve(mvcRequest, "test.string1", params);
57             Object JavaDoc bean = request.getSession().getAttribute("test");
58
59             assertEquals("Objects should be equal", resolved.getModel(), bean);
60         } catch (Exception JavaDoc e) {
61             fail(e.toString());
62         }
63
64         try {
65             WebModelResolver resolver = new WebModelResolver();
66
67             resolver.resolve(mvcRequest, "", params);
68             fail("Should have thrown an Assertion error");
69         } catch (Throwable JavaDoc t) {
70             assertTrue("Should be an MVCException", t instanceof MVCException);
71         }
72     }
73 }
74
Popular Tags