⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionnestingtest.java

📁 在Struts2中的jar包xwork的源代码.版本为2.0.7
💻 JAVA
字号:
/* * Copyright (c) 2002-2003 by OpenSymphony * All rights reserved. */package com.opensymphony.xwork2;import com.opensymphony.xwork2.config.Configuration;import com.opensymphony.xwork2.config.ConfigurationProvider;import com.opensymphony.xwork2.config.entities.ActionConfig;import com.opensymphony.xwork2.config.entities.PackageConfig;import com.opensymphony.xwork2.config.entities.ResultConfig;import com.opensymphony.xwork2.inject.ContainerBuilder;import com.opensymphony.xwork2.mock.MockResult;import com.opensymphony.xwork2.util.ValueStack;import com.opensymphony.xwork2.util.ValueStackFactory;import com.opensymphony.xwork2.util.location.LocatableProperties;import java.util.HashMap;import java.util.Map;import java.util.Properties;/** * ActionNestingTest * * @author Jason Carreira *         Created Mar 5, 2003 2:02:01 PM */public class ActionNestingTest extends XWorkTestCase {    public static final String VALUE = "myValue";    public static final String NESTED_VALUE = "myNestedValue";    public static final String KEY = "myProperty";    public static final String NESTED_KEY = "nestedProperty";    public static final String NAMESPACE = "NestedActionTest";    public static final String SIMPLE_ACTION_NAME = "SimpleAction";    public static final String NO_STACK_ACTION_NAME = "NoStackNestedAction";    public static final String STACK_ACTION_NAME = "StackNestedAction";    private ActionContext context;    public String getMyProperty() {        return VALUE;    }    public void setUp() throws Exception {        super.setUp();        loadConfigurationProviders(new NestedTestConfigurationProvider());        ValueStack stack = ValueStackFactory.getFactory().createValueStack();        // create the action context        Map contextMap = stack.getContext();        // give the value stack a context        stack.push(this);        context = new ActionContext(contextMap);        ActionContext.setContext(context);    }    protected void tearDown() throws Exception {        super.tearDown();        ActionContext.setContext(null);    }    public void testNestedContext() throws Exception {        assertEquals(context, ActionContext.getContext());        ActionProxy proxy = actionProxyFactory.createActionProxy(NAMESPACE, SIMPLE_ACTION_NAME, null);        proxy.execute();        assertEquals(context, ActionContext.getContext());    }    public void testNestedNoValueStack() throws Exception {        ValueStack stack = ActionContext.getContext().getValueStack();        assertEquals(VALUE, stack.findValue(KEY));        ActionProxy proxy = actionProxyFactory.createActionProxy(NAMESPACE, NO_STACK_ACTION_NAME, null);        proxy.execute();        stack = ActionContext.getContext().getValueStack();        assertEquals(stack.findValue(KEY), VALUE);        assertNull(stack.findValue(NESTED_KEY));    }    public void testNestedValueStack() throws Exception {        ValueStack stack = ActionContext.getContext().getValueStack();        assertEquals(VALUE, stack.findValue(KEY));        HashMap extraContext = new HashMap();        extraContext.put(ActionContext.VALUE_STACK, stack);        ActionProxy proxy = actionProxyFactory.createActionProxy(NAMESPACE, STACK_ACTION_NAME, extraContext);        proxy.execute();        assertEquals(context, ActionContext.getContext());        assertEquals(stack, ActionContext.getContext().getValueStack());        assertEquals(VALUE, stack.findValue(KEY));        assertEquals(NESTED_VALUE, stack.findValue(NESTED_KEY));        assertEquals(3, stack.size());    }    class NestedTestConfigurationProvider implements ConfigurationProvider {        private Configuration configuration;        public void destroy() {        }        public void init(Configuration configuration) {            this.configuration = configuration;        }        public void register(ContainerBuilder builder, LocatableProperties props) {            builder.factory(ObjectFactory.class);            builder.factory(ActionProxyFactory.class, DefaultActionProxyFactory.class);        }                public void loadPackages() {                        PackageConfig packageContext = new PackageConfig("nestedActionTest");            ActionConfig config = new ActionConfig(null, SimpleAction.class, null, null, null);            config.addResultConfig(new ResultConfig(Action.SUCCESS, MockResult.class.getName()));            config.addResultConfig(new ResultConfig(Action.ERROR, MockResult.class.getName()));            config.setPackageName("nestedActionTest");            packageContext.addActionConfig(SIMPLE_ACTION_NAME, config);            config = new ActionConfig("noStack", com.opensymphony.xwork2.NestedAction.class, null, null, null);            config.addResultConfig(new ResultConfig(Action.SUCCESS, MockResult.class.getName()));            config.setPackageName("nestedActionTest");            packageContext.addActionConfig(NO_STACK_ACTION_NAME, config);            config = new ActionConfig("stack", com.opensymphony.xwork2.NestedAction.class, null, null, null);            config.addResultConfig(new ResultConfig(Action.SUCCESS, MockResult.class.getName()));            config.setPackageName("nestedActionTest");            packageContext.addActionConfig(STACK_ACTION_NAME, config);            packageContext.setNamespace(NAMESPACE);            configuration.addPackageConfig("nestedActionTest", packageContext);        }        /**         * Tells whether the ConfigurationProvider should reload its configuration         *         * @return         */        public boolean needsReload() {            return false;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -