FileDocCategorySizeDatePackage
TestConfigurationProvider.javaAPI DocExample7840Mon Jul 23 13:26:26 BST 2007org.apache.struts2

TestConfigurationProvider

public class TestConfigurationProvider extends Object implements com.opensymphony.xwork2.config.ConfigurationProvider
TestConfigurationProvider provides a simple configuration class without the need for xml files, etc. for simple testing.

Fields Summary
public static final String
TEST_ACTION_NAME
public static final String
EXECUTION_COUNT_ACTION_NAME
public static final String
TOKEN_ACTION_NAME
public static final String
TOKEN_SESSION_ACTION_NAME
public static final String
TEST_NAMESPACE
public static final String
TEST_NAMESPACE_ACTION
private com.opensymphony.xwork2.config.Configuration
configuration
Constructors Summary
Methods Summary
public voiddestroy()
Allows the configuration to clean up any resources used



                  
       
    
public voidinit(com.opensymphony.xwork2.config.Configuration config)

        this.configuration = config;
    
public voidloadPackages()
Initializes the configuration object.

        PackageConfig defaultPackageConfig = new PackageConfig("");

        HashMap results = new HashMap();

        HashMap successParams = new HashMap();
        successParams.put("propertyName", "executionCount");
        successParams.put("expectedValue", "1");

        ResultConfig successConfig = new ResultConfig(Action.SUCCESS, TestResult.class.getName(), successParams);

        results.put(Action.SUCCESS, successConfig);

        List interceptors = new ArrayList();

        ActionConfig executionCountActionConfig = new ActionConfig(null, ExecutionCountTestAction.class, null, results, interceptors);
        defaultPackageConfig.addActionConfig(EXECUTION_COUNT_ACTION_NAME, executionCountActionConfig);

        results = new HashMap();

        successParams = new HashMap();
        successParams.put("location", "success.jsp");

        successConfig = new ResultConfig(Action.SUCCESS, ServletDispatcherResult.class.getName(), successParams);

        results.put(Action.SUCCESS, successConfig);

        interceptors.add(new InterceptorMapping("params", new ParametersInterceptor()));

        ActionConfig testActionConfig = new ActionConfig(null, TestAction.class, null, results, interceptors);
        defaultPackageConfig.addActionConfig(TEST_ACTION_NAME, testActionConfig);

        interceptors = new ArrayList();
        interceptors.add(new InterceptorMapping("token", new TokenInterceptor()));

        results = new HashMap();

        ActionConfig tokenActionConfig = new ActionConfig(null, TestAction.class, null, results, interceptors);
        tokenActionConfig.addResultConfig(new ResultConfig("invalid.token", MockResult.class.getName()));
        tokenActionConfig.addResultConfig(new ResultConfig("success", MockResult.class.getName()));
        defaultPackageConfig.addActionConfig(TOKEN_ACTION_NAME, tokenActionConfig);

        interceptors = new ArrayList();
        interceptors.add(new InterceptorMapping("token-session", new TokenSessionStoreInterceptor()));

        results = new HashMap();

        successParams = new HashMap();
        successParams.put("actionName", EXECUTION_COUNT_ACTION_NAME);

        successConfig = new ResultConfig(Action.SUCCESS, ActionChainResult.class.getName(), successParams);

        results.put(Action.SUCCESS, successConfig);

        // empty results for token session unit test
        results = new HashMap();
        ActionConfig tokenSessionActionConfig = new ActionConfig(null, TestAction.class, null, results, interceptors);
        tokenSessionActionConfig.addResultConfig(new ResultConfig("invalid.token", MockResult.class.getName()));
        tokenSessionActionConfig.addResultConfig(new ResultConfig("success", MockResult.class.getName()));
        defaultPackageConfig.addActionConfig(TOKEN_SESSION_ACTION_NAME, tokenSessionActionConfig);

        configuration.addPackageConfig("", defaultPackageConfig);

        Map testActionTagResults = new HashMap();
        testActionTagResults.put(Action.SUCCESS, new ResultConfig(Action.SUCCESS, TestActionTagResult.class.getName(), new HashMap()));
        testActionTagResults.put(Action.INPUT, new ResultConfig(Action.INPUT, TestActionTagResult.class.getName(), new HashMap()));
        ActionConfig testActionTagActionConfig = new ActionConfig((String) null, TestAction.class, (Map) null, testActionTagResults, new ArrayList());
        defaultPackageConfig.addActionConfig("testActionTagAction", testActionTagActionConfig);

        PackageConfig namespacePackageConfig = new PackageConfig("namespacePackage");
        namespacePackageConfig.setNamespace(TEST_NAMESPACE);
        namespacePackageConfig.addParent(defaultPackageConfig);

        ActionConfig namespaceAction = new ActionConfig(null, TestAction.class, null, null, null);
        namespacePackageConfig.addActionConfig(TEST_NAMESPACE_ACTION, namespaceAction);

        configuration.addPackageConfig("namespacePackage", namespacePackageConfig);
    
public booleanneedsReload()
Tells whether the ConfigurationProvider should reload its configuration

return

        return false;
    
public voidregister(com.opensymphony.xwork2.inject.ContainerBuilder builder, com.opensymphony.xwork2.util.location.LocatableProperties props)

        if (!builder.contains(ObjectFactory.class)) {
            builder.factory(ObjectFactory.class);
        }
        if (!builder.contains(ActionProxyFactory.class)) {
            builder.factory(ActionProxyFactory.class, DefaultActionProxyFactory.class);
        }