001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork;
006:
007: import com.opensymphony.webwork.dispatcher.ServletDispatcherResult;
008: import com.opensymphony.webwork.interceptor.TokenInterceptor;
009: import com.opensymphony.webwork.interceptor.TokenSessionStoreInterceptor;
010: import com.opensymphony.xwork.Action;
011: import com.opensymphony.xwork.ActionChainResult;
012: import com.opensymphony.xwork.config.Configuration;
013: import com.opensymphony.xwork.config.ConfigurationProvider;
014: import com.opensymphony.xwork.config.entities.ActionConfig;
015: import com.opensymphony.xwork.config.entities.PackageConfig;
016: import com.opensymphony.xwork.config.entities.ResultConfig;
017: import com.opensymphony.xwork.config.entities.InterceptorMapping;
018: import com.opensymphony.xwork.interceptor.ParametersInterceptor;
019:
020: import java.util.ArrayList;
021: import java.util.HashMap;
022: import java.util.List;
023: import java.util.Map;
024:
025: /**
026: * TestConfigurationProvider provides a simple configuration class without the need for xml files, etc. for simple testing.
027: *
028: * @author $author$
029: */
030: public class TestConfigurationProvider implements ConfigurationProvider {
031:
032: public static final String TEST_ACTION_NAME = "testAction";
033: public static final String EXECUTION_COUNT_ACTION_NAME = "executionCountAction";
034: public static final String TOKEN_ACTION_NAME = "tokenAction";
035: public static final String TOKEN_SESSION_ACTION_NAME = "tokenSessionAction";
036: public static final String TEST_NAMESPACE = "/testNamespace";
037: public static final String TEST_NAMESPACE_ACTION = "testNamespaceAction";
038:
039: /**
040: * Allows the configuration to clean up any resources used
041: */
042: public void destroy() {
043: }
044:
045: /**
046: * Initializes the configuration object.
047: */
048: public void init(Configuration configurationManager) {
049: PackageConfig defaultPackageConfig = new PackageConfig();
050:
051: HashMap results = new HashMap();
052:
053: HashMap successParams = new HashMap();
054: successParams.put("propertyName", "executionCount");
055: successParams.put("expectedValue", "1");
056:
057: ResultConfig successConfig = new ResultConfig(Action.SUCCESS,
058: TestResult.class.getName(), successParams);
059:
060: results.put(Action.SUCCESS, successConfig);
061:
062: List interceptors = new ArrayList();
063:
064: ActionConfig executionCountActionConfig = new ActionConfig(
065: null, ExecutionCountTestAction.class, null, results,
066: interceptors);
067: defaultPackageConfig
068: .addActionConfig(EXECUTION_COUNT_ACTION_NAME,
069: executionCountActionConfig);
070:
071: results = new HashMap();
072:
073: successParams = new HashMap();
074: successParams.put("location", "success.jsp");
075:
076: successConfig = new ResultConfig(Action.SUCCESS,
077: ServletDispatcherResult.class.getName(), successParams);
078:
079: results.put(Action.SUCCESS, successConfig);
080:
081: interceptors.add(new InterceptorMapping("params",
082: new ParametersInterceptor()));
083:
084: ActionConfig testActionConfig = new ActionConfig(null,
085: TestAction.class, null, results, interceptors);
086: defaultPackageConfig.addActionConfig(TEST_ACTION_NAME,
087: testActionConfig);
088:
089: interceptors = new ArrayList();
090: interceptors.add(new InterceptorMapping("token",
091: new TokenInterceptor()));
092:
093: results = new HashMap();
094:
095: ActionConfig tokenActionConfig = new ActionConfig(null,
096: TestAction.class, null, results, interceptors);
097: defaultPackageConfig.addActionConfig(TOKEN_ACTION_NAME,
098: tokenActionConfig);
099:
100: interceptors = new ArrayList();
101: interceptors.add(new InterceptorMapping("token-session",
102: new TokenSessionStoreInterceptor()));
103:
104: results = new HashMap();
105:
106: successParams = new HashMap();
107: successParams.put("actionName", EXECUTION_COUNT_ACTION_NAME);
108:
109: successConfig = new ResultConfig(Action.SUCCESS,
110: ActionChainResult.class.getName(), successParams);
111:
112: results.put(Action.SUCCESS, successConfig);
113:
114: // empty results for token session unit test
115: results = new HashMap();
116: ActionConfig tokenSessionActionConfig = new ActionConfig(null,
117: TestAction.class, null, results, interceptors);
118: defaultPackageConfig.addActionConfig(TOKEN_SESSION_ACTION_NAME,
119: tokenSessionActionConfig);
120:
121: configurationManager.addPackageConfig("defaultPackage",
122: defaultPackageConfig);
123:
124: Map testActionTagResults = new HashMap();
125: testActionTagResults.put(Action.SUCCESS, new ResultConfig(
126: Action.SUCCESS, TestActionTagResult.class.getName(),
127: new HashMap()));
128: testActionTagResults.put(Action.INPUT, new ResultConfig(
129: Action.INPUT, TestActionTagResult.class.getName(),
130: new HashMap()));
131: ActionConfig testActionTagActionConfig = new ActionConfig(
132: (String) null, TestAction.class, (Map) null,
133: testActionTagResults, new ArrayList());
134: defaultPackageConfig.addActionConfig("testActionTagAction",
135: testActionTagActionConfig);
136:
137: PackageConfig namespacePackageConfig = new PackageConfig();
138: namespacePackageConfig.setNamespace(TEST_NAMESPACE);
139: namespacePackageConfig.addParent(defaultPackageConfig);
140:
141: ActionConfig namespaceAction = new ActionConfig(null,
142: TestAction.class, null, null, null);
143: namespacePackageConfig.addActionConfig(TEST_NAMESPACE_ACTION,
144: namespaceAction);
145:
146: configurationManager.addPackageConfig("namespacePackage",
147: namespacePackageConfig);
148: }
149:
150: /**
151: * Tells whether the ConfigurationProvider should reload its configuration
152: *
153: * @return
154: */
155: public boolean needsReload() {
156: return false;
157: }
158: }
|