KickJava   Java API By Example, From Geeks To Geeks.

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


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

28 public class WebMetaDataTest extends WebTestCase {
29
30     /**
31      * Constructs a new <code>WebMetaDataTest</code> TestCase instance
32      */

33     public WebMetaDataTest(String JavaDoc name) {
34         super(name);
35         setLocal(true);
36     }
37
38
39     /**
40      * Tests the meta data works correctly
41      */

42     public void testAll() {
43         Map JavaDoc params = new HashMap JavaDoc();
44         params.put(WebMetaData.CLASS_PARAMETER,
45             "com.inversoft.verge.mvc.model.web.test.Bean1");
46         params.put(WebMetaData.SCOPE_PARAMETER,
47             "" + ScopeConstants.SESSION_INT);
48
49         try {
50             WebMetaData md = new WebMetaData("test.string1", params);
51             assertEquals("Should have an id of test", md.getID(), "test");
52             assertEquals("Should have an property of string1", md.getProperty(),
53                 "string1");
54             assertEquals("Should have an definition of test.string1", "test.string1",
55                 md.getDefinition());
56             assertEquals("Should be Bean1 class", md.getModelClass(), Bean1.class);
57             assertEquals("Should be session scoped", md.getScope(),
58                 ScopeConstants.SESSION_INT);
59             assertNotNull("Should have model handler", md.getModelHandler());
60             assertTrue("Should have web model handler",
61                 md.getModelHandler() instanceof WebModelHandler);
62         } catch (Exception JavaDoc e) {
63             fail(e.toString());
64         }
65
66         try {
67             WebMetaData md = new WebMetaData("test", "string1",
68                 Bean1.class.getName(), ScopeConstants.SESSION_INT);
69             assertEquals("Should have an id of test", md.getID(), "test");
70             assertEquals("Should have an property of string1", md.getProperty(),
71                 "string1");
72             assertEquals("Should be Bean1 class", md.getModelClass(), Bean1.class);
73             assertEquals("Should be session scoped", md.getScope(),
74                 ScopeConstants.SESSION_INT);
75             assertEquals("Should be the same parameters map", params, md.getExtraParams());
76             assertEquals("Should be the same definition", "test.string1", md.getDefinition());
77             assertNotNull("Should have model handler", md.getModelHandler());
78             assertTrue("Should have web model handler",
79                 md.getModelHandler() instanceof WebModelHandler);
80         } catch (Exception JavaDoc e) {
81             fail(e.toString());
82         }
83
84         try {
85             WebMetaData md = new WebMetaData("test", Bean1.class.getName(),
86                 ScopeConstants.SESSION_INT);
87             assertEquals("Should have an id of test", md.getID(), "test");
88             assertNull("Should NOT have a property", md.getProperty());
89             assertEquals("Should be Bean1 class", md.getModelClass(), Bean1.class);
90             assertEquals("Should be session scoped", md.getScope(),
91                 ScopeConstants.SESSION_INT);
92             assertEquals("Should be the same parameters map", params, md.getExtraParams());
93             assertNotNull("Should have model handler", md.getModelHandler());
94             assertTrue("Should have web model handler",
95                 md.getModelHandler() instanceof WebModelHandler);
96             md.setProperty("string1");
97             assertEquals("Should have an property of string1", md.getProperty(),
98                 "string1");
99             assertEquals("Should be the same definition", "test.string1",
100                 md.getDefinition());
101         } catch (Exception JavaDoc e) {
102             fail(e.toString());
103         }
104
105         // Test that reusing the md and changing the property works
106
try {
107             WebMetaData md = new WebMetaData("item", Bean1.class.getName(),
108                 ScopeConstants.SESSION_INT);
109             assertEquals("Should be item", "item", md.getID());
110             assertNull("Should be null", md.getProperty());
111             md.setProperty("string1");
112             assertEquals("Should have an property of string1", md.getProperty(),
113                 "string1");
114             assertEquals("item.string1", md.getDefinition());
115             md.setProperty("string2");
116             assertEquals("item.string2", md.getDefinition());
117             md.setProperty("foo");
118             assertEquals("item.foo", md.getDefinition());
119         } catch (Exception JavaDoc e) {
120             fail(e.toString());
121         }
122     }
123 }
124
Popular Tags