KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > form > config > test > RegistryTest


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.controller.form.config.test;
8
9
10 import com.inversoft.config.component.ComponentConfigBuilderRegistry;
11 import com.inversoft.junit.WebTestCase;
12 import com.inversoft.verge.mvc.config.BaseFormConfig;
13 import com.inversoft.verge.mvc.controller.form.FormWebBeanHandle;
14 import com.inversoft.verge.mvc.controller.form.config.ActionConfig;
15 import com.inversoft.verge.mvc.controller.form.config.ActionConfigBuilder;
16 import com.inversoft.verge.mvc.controller.form.config.Constants;
17 import com.inversoft.verge.mvc.controller.form.config.FormConfig;
18 import com.inversoft.verge.mvc.controller.form.config.FormConfigBuilder;
19 import com.inversoft.verge.mvc.controller.form.config.FormMVCConfigBuilder;
20 import com.inversoft.verge.mvc.controller.form.config.FormMVCConfigRegistry;
21 import com.inversoft.verge.mvc.controller.form.config.MappingConfig;
22 import com.inversoft.verge.mvc.controller.form.config.MappingConfigBuilder;
23 import com.inversoft.verge.util.ScopeConstants;
24
25
26 /**
27  * <p>
28  * This class contains the TestCases for the registry.
29  * </p>
30  *
31  * @author Brian Pontarelli
32  * @since 1.0
33  * @version 1.0
34  */

35 public class RegistryTest extends WebTestCase {
36
37     /**
38      * Constructs a new <code>ActionFlowConfigRegistryTest</code> TestCase instance
39      */

40     public RegistryTest(String JavaDoc name) {
41         super(name);
42         setLocal(true);
43     }
44
45
46     /**
47      * Tests storing and then retrieving works
48      */

49     public void testAll() {
50         RegistryAdapter registry = new RegistryAdapter();
51         RegistryAdapter.setInstance(registry);
52         try {
53             ActionConfig action = new ActionConfig("test",
54                 new FormWebBeanHandle("test", "testAction", ScopeConstants.REQUEST_INT,
55                     "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler"),
56                     true, true, false, null, null, null);
57             registry.register("test", action);
58             assertTrue("Should be same action",
59                 FormMVCConfigRegistry.getInstance(request).lookupAction("test") == action);
60
61             BaseFormConfig base = new BaseFormConfig("test");
62             FormConfig form = new FormConfig(base);
63             registry.register("test", form);
64             assertTrue("Should be same form",
65                 FormMVCConfigRegistry.getInstance(request).lookupForm("test") == form);
66
67             MappingConfig mapping = new MappingConfig("test", "test.jsp", false, null);
68             registry.register("test", mapping);
69             assertTrue("Should be same mapping",
70                 FormMVCConfigRegistry.getInstance(request).lookupMapping("test") == mapping);
71
72             assertTrue("Should be null action",
73                 FormMVCConfigRegistry.getInstance(request).lookupAction("bad") == null);
74             assertTrue("Should be same form",
75                 FormMVCConfigRegistry.getInstance(request).lookupForm("bad") == null);
76             assertTrue("Should be same mapping",
77                 FormMVCConfigRegistry.getInstance(request).lookupMapping("bad") == null);
78         } catch (Exception JavaDoc e) {
79             fail(e.toString());
80         }
81     }
82
83     /**
84      * Tests that the component builders are in the component builder registry
85      */

86     public void testComponents() {
87         try {
88             ComponentConfigBuilderRegistry builderRegistry =
89                 new ComponentConfigBuilderRegistry(FormMVCConfigBuilder.BUILDERS_BUNDLE);
90             assertTrue("Should have ActionConfigBuilder",
91                 builderRegistry.lookup(Constants.ACTION_BUILDER_NAME) != null &&
92                 builderRegistry.lookup(Constants.ACTION_BUILDER_NAME) instanceof ActionConfigBuilder);
93             assertTrue("Should have FormConfigBuilder",
94                 builderRegistry.lookup(Constants.FORM_BUILDER_NAME) != null &&
95                 builderRegistry.lookup(Constants.FORM_BUILDER_NAME) instanceof FormConfigBuilder);
96             assertTrue("Should have MappingConfigBuilder",
97                 builderRegistry.lookup(Constants.MAPPING_BUILDER_NAME) != null &&
98                 builderRegistry.lookup(Constants.MAPPING_BUILDER_NAME) instanceof MappingConfigBuilder);
99         } catch (Exception JavaDoc e) {
100             fail(e.toString());
101         }
102     }
103
104     /**
105      * A simple adapter to help in testing the registry
106      */

107     public static class RegistryAdapter extends FormMVCConfigRegistry {
108         protected static void setInstance(FormMVCConfigRegistry instance) {
109             FormMVCConfigRegistry.setInstance(instance);
110         }
111
112         protected void register(String JavaDoc name, FormConfig config) {
113             super.register(name, config);
114         }
115
116         protected void register(String JavaDoc name, ActionConfig config) {
117             super.register(name, config);
118         }
119
120         protected void register(String JavaDoc name, MappingConfig config) {
121             super.register(name, config);
122         }
123     }
124 }
125
Popular Tags