1 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 ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 23 24 29 public class TestConfigurationProvider implements ConfigurationProvider { 30 32 public static final String TEST_ACTION_NAME = "testAction"; 33 public static final String EXECUTION_COUNT_ACTION_NAME = "executionCountAction"; 34 public static final String TOKEN_ACTION_NAME = "tokenAction"; 35 public static final String TOKEN_SESSION_ACTION_NAME = "tokenSessionAction"; 36 public static final String TEST_NAMESPACE = "/testNamespace"; 37 public static final String TEST_NAMESPACE_ACTION = "testNamespaceAction"; 38 39 41 44 public void destroy() { 45 } 46 47 50 public void init(Configuration configurationManager) { 51 PackageConfig defaultPackageConfig = new PackageConfig(); 52 53 HashMap results = new HashMap (); 54 55 HashMap successParams = new HashMap (); 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 interceptors = new ArrayList (); 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 (); 69 70 successParams = new HashMap (); 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 (); 83 interceptors.add(new TokenInterceptor()); 84 85 results = new HashMap (); 86 87 ActionConfig tokenActionConfig = new ActionConfig(null, TestAction.class, null, results, interceptors); 88 defaultPackageConfig.addActionConfig(TOKEN_ACTION_NAME, tokenActionConfig); 89 90 interceptors = new ArrayList (); 91 interceptors.add(new TokenSessionStoreInterceptor()); 92 93 results = new HashMap (); 94 95 successParams = new HashMap (); 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 122 public boolean needsReload() { 123 return false; 124 } 125 } 126 | Popular Tags |