KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > TestConfigurationProvider


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork;
6
7 import com.opensymphony.webwork.dispatcher.ServletDispatcherResult;
8 import com.opensymphony.webwork.interceptor.TokenInterceptor;
9 import com.opensymphony.webwork.interceptor.TokenSessionStoreInterceptor;
10 import com.opensymphony.xwork.Action;
11 import com.opensymphony.xwork.ActionChainResult;
12 import com.opensymphony.xwork.config.Configuration;
13 import com.opensymphony.xwork.config.ConfigurationProvider;
14 import com.opensymphony.xwork.config.entities.ActionConfig;
15 import com.opensymphony.xwork.config.entities.PackageConfig;
16 import com.opensymphony.xwork.config.entities.ResultConfig;
17 import com.opensymphony.xwork.interceptor.ParametersInterceptor;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.List JavaDoc;
22
23
24 /**
25  * TestConfigurationProvider provides a simple configuration class without the need for xml files, etc. for simple testing.
26  *
27  * @author $author$
28  */

29 public class TestConfigurationProvider implements ConfigurationProvider {
30     //~ Static fields/initializers /////////////////////////////////////////////
31

32     public static final String JavaDoc TEST_ACTION_NAME = "testAction";
33     public static final String JavaDoc EXECUTION_COUNT_ACTION_NAME = "executionCountAction";
34     public static final String JavaDoc TOKEN_ACTION_NAME = "tokenAction";
35     public static final String JavaDoc TOKEN_SESSION_ACTION_NAME = "tokenSessionAction";
36     public static final String JavaDoc TEST_NAMESPACE = "/testNamespace";
37     public static final String JavaDoc TEST_NAMESPACE_ACTION = "testNamespaceAction";
38
39     //~ Methods ////////////////////////////////////////////////////////////////
40

41     /**
42      * Allows the configuration to clean up any resources used
43      */

44     public void destroy() {
45     }
46
47     /**
48      * Initializes the configuration object.
49      */

50     public void init(Configuration configurationManager) {
51         PackageConfig defaultPackageConfig = new PackageConfig();
52
53         HashMap JavaDoc results = new HashMap JavaDoc();
54
55         HashMap JavaDoc successParams = new HashMap JavaDoc();
56         successParams.put("propertyName", "executionCount");
57         successParams.put("expectedValue", "1");
58
59         ResultConfig successConfig = new ResultConfig(Action.SUCCESS, TestResult.class, successParams);
60
61         results.put(Action.SUCCESS, successConfig);
62
63         List JavaDoc interceptors = new ArrayList JavaDoc();
64
65         ActionConfig executionCountActionConfig = new ActionConfig(null, ExecutionCountTestAction.class, null, results, interceptors);
66         defaultPackageConfig.addActionConfig(EXECUTION_COUNT_ACTION_NAME, executionCountActionConfig);
67
68         results = new HashMap JavaDoc();
69
70         successParams = new HashMap JavaDoc();
71         successParams.put("location", "success.jsp");
72
73         successConfig = new ResultConfig(Action.SUCCESS, ServletDispatcherResult.class, successParams);
74
75         results.put(Action.SUCCESS, successConfig);
76
77         interceptors.add(new ParametersInterceptor());
78
79         ActionConfig testActionConfig = new ActionConfig(null, TestAction.class, null, results, interceptors);
80         defaultPackageConfig.addActionConfig(TEST_ACTION_NAME, testActionConfig);
81
82         interceptors = new ArrayList JavaDoc();
83         interceptors.add(new TokenInterceptor());
84
85         results = new HashMap JavaDoc();
86
87         ActionConfig tokenActionConfig = new ActionConfig(null, TestAction.class, null, results, interceptors);
88         defaultPackageConfig.addActionConfig(TOKEN_ACTION_NAME, tokenActionConfig);
89
90         interceptors = new ArrayList JavaDoc();
91         interceptors.add(new TokenSessionStoreInterceptor());
92
93         results = new HashMap JavaDoc();
94
95         successParams = new HashMap JavaDoc();
96         successParams.put("actionName", EXECUTION_COUNT_ACTION_NAME);
97
98         successConfig = new ResultConfig(Action.SUCCESS, ActionChainResult.class, successParams);
99
100         results.put(Action.SUCCESS, successConfig);
101
102         ActionConfig tokenSessionActionConfig = new ActionConfig(null, TestAction.class, null, results, interceptors);
103         defaultPackageConfig.addActionConfig(TOKEN_SESSION_ACTION_NAME, tokenSessionActionConfig);
104
105         configurationManager.addPackageConfig("defaultPackage", defaultPackageConfig);
106
107         PackageConfig namespacePackageConfig = new PackageConfig();
108         namespacePackageConfig.setNamespace(TEST_NAMESPACE);
109         namespacePackageConfig.addParent(defaultPackageConfig);
110
111         ActionConfig namespaceAction = new ActionConfig(null, TestAction.class, null, null, null);
112         namespacePackageConfig.addActionConfig(TEST_NAMESPACE_ACTION, namespaceAction);
113
114         configurationManager.addPackageConfig("namespacePackage", namespacePackageConfig);
115     }
116
117     /**
118      * Tells whether the ConfigurationProvider should reload its configuration
119      *
120      * @return
121      */

122     public boolean needsReload() {
123         return false;
124     }
125 }
126
Popular Tags