You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ma...@apache.org on 2009/12/27 19:01:09 UTC
svn commit: r894087 [26/46] - in /struts/xwork/trunk: ./ assembly/
assembly/src/ assembly/src/main/ assembly/src/main/assembly/
assembly/src/main/resources/ core/ core/src/ core/src/main/
core/src/main/java/ core/src/main/java/com/ core/src/main/java/c...
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionNestingTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionNestingTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionNestingTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionNestingTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,132 @@
+/*
+ * 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.location.LocatableProperties;
+
+import java.util.HashMap;
+
+
+/**
+ * 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;
+ }
+
+ @Override public void setUp() throws Exception {
+ super.setUp();
+ loadConfigurationProviders(new NestedTestConfigurationProvider());
+
+ context = ActionContext.getContext();
+ context.getValueStack().push(this);
+ }
+
+ @Override protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ 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<String, Object> extraContext = new HashMap<String, Object>();
+ 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) {
+ }
+
+ public void loadPackages() {
+
+ PackageConfig packageContext = new PackageConfig.Builder("nestedActionTest")
+ .addActionConfig(SIMPLE_ACTION_NAME, new ActionConfig.Builder("nestedActionTest", SIMPLE_ACTION_NAME, SimpleAction.class.getName())
+ .addResultConfig(new ResultConfig.Builder(Action.SUCCESS, MockResult.class.getName()).build())
+ .addResultConfig(new ResultConfig.Builder(Action.ERROR, MockResult.class.getName()).build())
+ .build())
+ .addActionConfig(NO_STACK_ACTION_NAME, new ActionConfig.Builder("nestedActionTest", NO_STACK_ACTION_NAME, NestedAction.class.getName())
+ .addResultConfig(new ResultConfig.Builder(Action.SUCCESS, MockResult.class.getName()).build())
+ .methodName("noStack")
+ .build())
+ .addActionConfig(STACK_ACTION_NAME, new ActionConfig.Builder("nestedActionTest", STACK_ACTION_NAME, NestedAction.class.getName())
+ .addResultConfig(new ResultConfig.Builder(Action.SUCCESS, MockResult.class.getName()).build())
+ .methodName("stack")
+ .build())
+ .namespace(NAMESPACE)
+ .build();
+ configuration.addPackageConfig("nestedActionTest", packageContext);
+ }
+
+ /**
+ * Tells whether the ConfigurationProvider should reload its configuration
+ *
+ * @return
+ */
+ public boolean needsReload() {
+ return false;
+ }
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionNestingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionNestingTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,319 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * Unit test for {@link ActionSupport}.
+ *
+ * @author Claus Ibsen
+ */
+public class ActionSupportTest extends XWorkTestCase {
+
+ private ActionSupport as;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ as = new ActionSupport();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ as = null;
+ }
+
+ public void testNothingDoneOnActionSupport() throws Exception {
+ assertEquals(false, as.hasErrors());
+
+ assertNotNull(as.getActionErrors());
+ assertEquals(0, as.getActionErrors().size());
+ assertEquals(false, as.hasActionErrors());
+
+ assertNotNull(as.getActionMessages());
+ assertEquals(0, as.getActionMessages().size());
+ assertEquals(false, as.hasActionMessages());
+
+ assertNotNull(as.getFieldErrors());
+ assertEquals(0, as.getFieldErrors().size());
+ assertEquals(false, as.hasFieldErrors());
+
+ assertNull(as.getText(null));
+
+ try {
+ as.pause(null);
+ } catch (Exception e) {
+ fail("Should not fail");
+ }
+
+ assertEquals(Action.INPUT, as.input());
+ assertEquals(Action.SUCCESS, as.doDefault());
+ assertEquals(Action.SUCCESS, as.execute());
+ try {
+ as.clone();
+ fail("Failure expected for clone()");
+ } catch (CloneNotSupportedException e) {
+ // success!
+ }
+
+
+ assertNull(as.getText(null, (List) null));
+ assertNull(as.getText(null, (String) null));
+ assertNull(as.getText(null, (String[]) null));
+
+ assertNull(as.getText(null, (String) null, (List) null));
+ assertNull(as.getText(null, (String) null, (String) null));
+ assertNull(as.getText(null, (String) null, (String[]) null));
+
+ assertNull(as.getText(null, (String) null, (List) null, (ValueStack) null));
+ assertNull(as.getText(null, (String) null, (String[]) null, (ValueStack) null));
+
+ assertNotNull(as.getLocale());
+ assertEquals(ActionContext.getContext().getLocale(), as.getLocale());
+
+ assertNull(as.getTexts()); // can not find a bundle
+ assertEquals("not.in.bundle", as.getText("not.in.bundle"));
+ }
+
+ public void testActionErrors() {
+ assertEquals(false, as.hasActionErrors());
+ assertEquals(0, as.getActionErrors().size());
+ as.addActionError("Damm");
+ assertEquals(1, as.getActionErrors().size());
+ assertEquals("Damm", as.getActionErrors().iterator().next());
+ assertEquals(true, as.hasActionErrors());
+ assertEquals(true, as.hasErrors());
+
+ as.clearErrorsAndMessages();
+ assertEquals(false, as.hasActionErrors());
+ assertEquals(false, as.hasErrors());
+ }
+
+ public void testActionMessages() {
+ assertEquals(false, as.hasActionMessages());
+ assertEquals(0, as.getActionMessages().size());
+ as.addActionMessage("Killroy was here");
+ assertEquals(1, as.getActionMessages().size());
+ assertEquals("Killroy was here", as.getActionMessages().iterator().next());
+ assertEquals(true, as.hasActionMessages());
+
+ assertEquals(false, as.hasActionErrors()); // does not count as a error
+ assertEquals(false, as.hasErrors()); // does not count as a error
+
+ as.clearErrorsAndMessages();
+ assertEquals(false, as.hasActionMessages());
+ assertEquals(false, as.hasErrors());
+ }
+
+ public void testFieldErrors() {
+ assertEquals(false, as.hasFieldErrors());
+ assertEquals(0, as.getFieldErrors().size());
+ as.addFieldError("username", "Admin is not allowed as username");
+ List<String> errors = as.getFieldErrors().get("username");
+ assertEquals(1, errors.size());
+ assertEquals("Admin is not allowed as username", errors.get(0));
+
+ assertEquals(true, as.hasFieldErrors());
+ assertEquals(true, as.hasErrors());
+
+ as.clearErrorsAndMessages();
+ assertEquals(false, as.hasFieldErrors());
+ assertEquals(false, as.hasErrors());
+ }
+
+ public void testDeprecated() throws Exception {
+ assertNotNull(as.getErrorMessages());
+ assertEquals(0, as.getErrorMessages().size());
+
+ assertNotNull(as.getErrors());
+ assertEquals(0, as.getErrors().size());
+ }
+
+ public void testLocale() {
+ Locale defLocale = Locale.getDefault();
+ ActionContext.getContext().setLocale(null);
+
+ // will never return null, if no locale is set then default is returned
+ assertNotNull(as.getLocale());
+ assertEquals(defLocale, as.getLocale());
+
+ ActionContext.getContext().setLocale(Locale.ITALY);
+ assertEquals(Locale.ITALY, as.getLocale());
+
+ ActionContext.setContext(new ActionContext(new HashMap<String, Object>()));
+ assertEquals(defLocale, as.getLocale()); // ActionContext will create a new context, when it was set to null before
+ }
+
+ public void testMyActionSupport() throws Exception {
+ ActionContext.getContext().setLocale(new Locale("da"));
+ MyActionSupport mas = new MyActionSupport();
+
+ assertEquals("santa", mas.doDefault());
+ assertNotNull(mas.getTexts());
+
+ assertEquals(false, mas.hasActionMessages());
+ mas.validate();
+ assertEquals(true, mas.hasActionMessages());
+ }
+
+ public void testSimpleGetTexts() throws Exception {
+ ActionContext.getContext().setLocale(new Locale("da"));
+ MyActionSupport mas = new MyActionSupport();
+
+ checkGetTexts(mas);
+ }
+
+ public void testSimpleGetTextsWithInjectedTextProvider() throws Exception {
+ ActionContext.getContext().setLocale(new Locale("da"));
+ MyActionSupport mas = new MyActionSupport();
+
+ TextProvider textProvider = container.getInstance(TextProvider.class, "system");
+
+ assertNotNull(textProvider);
+
+ container.inject(mas);
+
+ checkGetTexts(mas);
+ }
+
+ private void checkGetTexts(MyActionSupport mas) {
+ assertEquals("Hello World", mas.getText("hello"));
+ assertEquals("not.in.bundle", mas.getText("not.in.bundle"));
+
+ assertEquals("Hello World", mas.getText("hello", "this is default"));
+ assertEquals("this is default", mas.getText("not.in.bundle", "this is default"));
+
+ List nullList = null;
+ assertEquals("Hello World", mas.getText("hello", nullList));
+
+ String[] nullStrings = null;
+ assertEquals("Hello World", mas.getText("hello", nullStrings));
+ }
+
+ public void testGetTextsWithArgs() throws Exception {
+ ActionContext.getContext().setLocale(new Locale("da"));
+ MyActionSupport mas = new MyActionSupport();
+
+ assertEquals("Hello World", mas.getText("hello", "this is default", "from me")); // no args in bundle
+ assertEquals("Hello World from me", mas.getText("hello.0", "this is default", "from me"));
+ assertEquals("this is default", mas.getText("not.in.bundle", "this is default", "from me"));
+ assertEquals("this is default from me", mas.getText("not.in.bundle", "this is default {0}", "from me"));
+
+ assertEquals("not.in.bundle", mas.getText("not.in.bundle"));
+ }
+
+ public void testGetTextsWithListArgs() throws Exception {
+ ActionContext.getContext().setLocale(new Locale("da"));
+ MyActionSupport mas = new MyActionSupport();
+
+ List<Object> args = new ArrayList<Object>();
+ args.add("Santa");
+ args.add("loud");
+ assertEquals("Hello World", mas.getText("hello", "this is default", args)); // no args in bundle
+ assertEquals("Hello World Santa", mas.getText("hello.0", "this is default", args)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", mas.getText("hello.1", "this is default", args));
+
+ assertEquals("this is default", mas.getText("not.in.bundle", "this is default", args));
+ assertEquals("this is default Santa", mas.getText("not.in.bundle", "this is default {0}", args));
+ assertEquals("this is default Santa speaking loud", mas.getText("not.in.bundle", "this is default {0} speaking {1}", args));
+
+ assertEquals("Hello World", mas.getText("hello", args)); // no args in bundle
+ assertEquals("Hello World Santa", mas.getText("hello.0", args)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", mas.getText("hello.1", args));
+
+ assertEquals("not.in.bundle", mas.getText("not.in.bundle", args));
+
+ assertEquals("Hello World", mas.getText("hello", "this is default", (List) null));
+ assertEquals("this is default", mas.getText("not.in.bundle", "this is default", (List) null));
+ }
+
+ public void testGetTextsWithArrayArgs() throws Exception {
+ ActionContext.getContext().setLocale(new Locale("da"));
+ MyActionSupport mas = new MyActionSupport();
+
+ String[] args = {"Santa", "loud"};
+ assertEquals("Hello World", mas.getText("hello", "this is default", args)); // no args in bundle
+ assertEquals("Hello World Santa", mas.getText("hello.0", "this is default", args)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", mas.getText("hello.1", "this is default", args));
+
+ assertEquals("this is default", mas.getText("not.in.bundle", "this is default", args));
+ assertEquals("this is default Santa", mas.getText("not.in.bundle", "this is default {0}", args));
+ assertEquals("this is default Santa speaking loud", mas.getText("not.in.bundle", "this is default {0} speaking {1}", args));
+
+ assertEquals("Hello World", mas.getText("hello", args)); // no args in bundle
+ assertEquals("Hello World Santa", mas.getText("hello.0", args)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", mas.getText("hello.1", args));
+
+ assertEquals("not.in.bundle", mas.getText("not.in.bundle", args));
+
+ assertEquals("Hello World", mas.getText("hello", "this is default", (String[]) null));
+ assertEquals("this is default", mas.getText("not.in.bundle", "this is default", (String[]) null));
+ }
+
+ public void testGetTextsWithListAndStack() throws Exception {
+ ActionContext.getContext().setLocale(new Locale("da"));
+ MyActionSupport mas = new MyActionSupport();
+
+ ValueStack stack = ActionContext.getContext().getValueStack();
+
+ List<Object> args = new ArrayList<Object>();
+ args.add("Santa");
+ args.add("loud");
+ assertEquals("Hello World", mas.getText("hello", "this is default", args, stack)); // no args in bundle
+ assertEquals("Hello World Santa", mas.getText("hello.0", "this is default", args, stack)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", mas.getText("hello.1", "this is default", args, stack));
+
+ assertEquals("this is default", mas.getText("not.in.bundle", "this is default", args, stack));
+ assertEquals("this is default Santa", mas.getText("not.in.bundle", "this is default {0}", args, stack));
+ assertEquals("this is default Santa speaking loud", mas.getText("not.in.bundle", "this is default {0} speaking {1}", args, stack));
+ }
+
+ public void testGetTextsWithArrayAndStack() throws Exception {
+ ActionContext.getContext().setLocale(new Locale("da"));
+ MyActionSupport mas = new MyActionSupport();
+
+ ValueStack stack = ActionContext.getContext().getValueStack();
+
+ String[] args = {"Santa", "loud"};
+ assertEquals("Hello World", mas.getText("hello", "this is default", args, stack)); // no args in bundle
+ assertEquals("Hello World Santa", mas.getText("hello.0", "this is default", args, stack)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", mas.getText("hello.1", "this is default", args, stack));
+
+ assertEquals("this is default", mas.getText("not.in.bundle", "this is default", args, stack));
+ assertEquals("this is default Santa", mas.getText("not.in.bundle", "this is default {0}", args, stack));
+ assertEquals("this is default Santa speaking loud", mas.getText("not.in.bundle", "this is default {0} speaking {1}", args, stack));
+ }
+
+ public void testGetBundle() throws Exception {
+ ActionContext.getContext().setLocale(new Locale("da"));
+ MyActionSupport mas = new MyActionSupport();
+
+ ResourceBundle rb = ResourceBundle.getBundle(MyActionSupport.class.getName(), new Locale("da"));
+ assertEquals(rb, mas.getTexts(MyActionSupport.class.getName()));
+ }
+
+ private class MyActionSupport extends ActionSupport {
+
+ @Override
+ public String doDefault() throws Exception {
+ return "santa";
+ }
+
+ @Override
+ public void validate() {
+ super.validate(); // to have code coverage
+ addActionMessage("validation was called");
+ }
+ }
+
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/AnnotatedTestBean.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/AnnotatedTestBean.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/AnnotatedTestBean.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/AnnotatedTestBean.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
+import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
+import com.opensymphony.xwork2.validator.annotations.Validations;
+
+import java.util.Date;
+
+
+/**
+ * AnnotatedTestBean
+ * @author Jason Carreira
+ * @author Rainer Hermanns
+ * Created Aug 4, 2003 12:39:53 AM
+ */
+public class AnnotatedTestBean {
+ //~ Instance fields ////////////////////////////////////////////////////////
+
+ private Date birth;
+ private String name;
+ private int count;
+
+ //~ Constructors ///////////////////////////////////////////////////////////
+
+ public AnnotatedTestBean() {
+ }
+
+ //~ Methods ////////////////////////////////////////////////////////////////
+
+ public void setBirth(Date birth) {
+ this.birth = birth;
+ }
+
+ public Date getBirth() {
+ return birth;
+ }
+
+ @Validations(
+ intRangeFields = {
+ @IntRangeFieldValidator(shortCircuit = true, min = "1", max="100", key="invalid.count", message = "Invalid Count!"),
+ @IntRangeFieldValidator(shortCircuit = true, min = "20", max="28", key="invalid.count.bad", message = "Smaller Invalid Count: ${count}")
+ }
+
+ )
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ @RequiredStringValidator(message = "You must enter a name.")
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/AnnotatedTestBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/AnnotatedTestBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ChainResultTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ChainResultTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ChainResultTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ChainResultTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+/*
+ * Created on 28/02/2004
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+package com.opensymphony.xwork2;
+
+import com.mockobjects.dynamic.Mock;
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+import com.opensymphony.xwork2.util.ValueStack;
+import junit.framework.TestCase;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * @author CameronBraid
+ */
+public class ChainResultTest extends XWorkTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // ensure we're using the default configuration, not simple config
+ loadConfigurationProviders(new XmlConfigurationProvider("xwork-sample.xml"));
+ }
+
+ public void testNamespaceAndActionExpressionEvaluation() throws Exception {
+ ActionChainResult result = new ActionChainResult();
+ result.setActionName("${actionName}");
+ result.setNamespace("${namespace}");
+
+ String expectedActionName = "testActionName";
+ String expectedNamespace = "testNamespace";
+ Map<String, Object> values = new HashMap<String, Object>();
+ values.put("actionName", expectedActionName);
+ values.put("namespace", expectedNamespace);
+
+ ValueStack stack = ActionContext.getContext().getValueStack();
+ stack.push(values);
+
+ Mock actionProxyMock = new Mock(ActionProxy.class);
+ actionProxyMock.expect("execute");
+
+ ActionProxyFactory testActionProxyFactory = new NamespaceActionNameTestActionProxyFactory(expectedNamespace, expectedActionName, (ActionProxy) actionProxyMock.proxy());
+ result.setActionProxyFactory(testActionProxyFactory);
+ try {
+
+ ActionContext testContext = new ActionContext(stack.getContext());
+ ActionContext.setContext(testContext);
+ result.execute(null);
+ actionProxyMock.verify();
+ } finally {
+ ActionContext.setContext(null);
+ }
+ }
+
+ public void testRecursiveChain() throws Exception {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("", "InfiniteRecursionChain", null);
+
+ try {
+ proxy.execute();
+ fail("did not detected repeated chain to an action");
+ } catch (XWorkException e) {
+ }
+ }
+
+ private class NamespaceActionNameTestActionProxyFactory implements ActionProxyFactory {
+ private ActionProxy returnVal;
+ private String expectedActionName;
+ private String expectedNamespace;
+
+ public NamespaceActionNameTestActionProxyFactory(String expectedNamespace, String expectedActionName, ActionProxy returnVal) {
+ this.expectedNamespace = expectedNamespace;
+ this.expectedActionName = expectedActionName;
+ this.returnVal = returnVal;
+ }
+
+ public ActionProxy createActionProxy(String namespace, String actionName, Map<String, Object> extraContext) {
+ TestCase.assertEquals(expectedNamespace, namespace);
+ TestCase.assertEquals(expectedActionName, actionName);
+
+ return returnVal;
+ }
+
+ public ActionProxy createActionProxy(String namespace, String actionName, String methodName, Map<String, Object> extraContext) {
+ TestCase.assertEquals(expectedNamespace, namespace);
+ TestCase.assertEquals(expectedActionName, actionName);
+
+ return returnVal;
+ }
+
+ public ActionProxy createActionProxy(String namespace, String actionName, Map<String, Object> extraContext, boolean executeResult, boolean cleanupContext) {
+ TestCase.assertEquals(expectedNamespace, namespace);
+ TestCase.assertEquals(expectedActionName, actionName);
+
+ return returnVal;
+ }
+
+ public ActionProxy createActionProxy(String namespace, String actionName, String methodName, Map<String, Object> extraContext, boolean executeResult, boolean cleanupContext) {
+ TestCase.assertEquals(expectedNamespace, namespace);
+ TestCase.assertEquals(expectedActionName, actionName);
+
+ return returnVal;
+ }
+
+ public ActionProxy createActionProxy(ActionInvocation actionInvocation, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext) {
+ TestCase.assertEquals(expectedNamespace, namespace);
+ TestCase.assertEquals(expectedActionName, actionName);
+
+ return returnVal;
+ }
+
+ public ActionProxy createActionProxy(String namespace, String actionName, String method, boolean executeResult, boolean cleanupContext) {
+ TestCase.assertEquals(expectedNamespace, namespace);
+ TestCase.assertEquals(expectedActionName, actionName);
+
+ return returnVal;
+ }
+
+ public ActionProxy createActionProxy(ActionInvocation inv, String namespace, String actionName,
+ Map<String, Object> extraContext, boolean executeResult, boolean cleanupContext) throws Exception {
+ return null;
+ }
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ChainResultTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ChainResultTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,102 @@
+package com.opensymphony.xwork2;
+
+import java.util.ArrayList;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * <code>CompositeTextProviderTest</code>
+ *
+ * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
+ * @version $Id$
+ */
+public class CompositeTextProviderTest extends XWorkTestCase {
+
+
+ private CompositeTextProvider textProvider = null;
+
+
+ public void testGetText() throws Exception {
+ // we should get the text from the 1st text provider
+ assertEquals(textProvider.getText("name"), "1 name");
+ assertEquals(textProvider.getText("age"), "1 age");
+ assertEquals(textProvider.getText("dog"), "This is a dog");
+ assertEquals(textProvider.getText("cat"), "This is a cat");
+ assertEquals(textProvider.getText("car"), "This is a car");
+ assertEquals(textProvider.getText("bike"), "This is a bike");
+ assertEquals(textProvider.getText("someNonExistingKey"), "someNonExistingKey");
+ }
+
+
+ public void testGetTextWithDefaultValues() throws Exception {
+ assertEquals(textProvider.getText("name", "some default name"), "1 name");
+ assertEquals(textProvider.getText("age", "some default age"), "1 age");
+ assertEquals(textProvider.getText("no_such_key", "default value"), "default value");
+ assertEquals(textProvider.getText("dog", "some default dog"), "This is a dog");
+ assertEquals(textProvider.getText("cat", "some default cat"), "This is a cat");
+ assertEquals(textProvider.getText("car", "some default car"), "This is a car");
+ assertEquals(textProvider.getText("bike", "some default bike"), "This is a bike");
+ }
+
+
+ public void testGetTextWithDefaultValuesAndArgs() throws Exception {
+ assertEquals(textProvider.getText("goodnight", "say good night", "Adam"), "1 good night Adam");
+ assertEquals(textProvider.getText("goodnight", "say good night", new String[] { "Adam" }), "1 good night Adam");
+ assertEquals(textProvider.getText("goodnight", "say good night", new ArrayList<Object>() { {add("Adam");} }), "1 good night Adam");
+ assertEquals(textProvider.getText("goodmorning", "say good morning", new String[] { "Jack", "Jim" }), "1 good morning Jack and Jim");
+ assertEquals(textProvider.getText("goodmorning", "say good morning", new ArrayList<Object>() { { add("Jack"); add("Jim"); }}), "1 good morning Jack and Jim");
+ }
+
+ public void testHasKey() throws Exception {
+ assertTrue(textProvider.hasKey("name"));
+ assertTrue(textProvider.hasKey("age"));
+ assertTrue(textProvider.hasKey("cat"));
+ assertTrue(textProvider.hasKey("dog"));
+ assertTrue(textProvider.hasKey("car"));
+ assertTrue(textProvider.hasKey("bike"));
+ assertTrue(textProvider.hasKey("goodnight"));
+ assertTrue(textProvider.hasKey("goodmorning"));
+ assertFalse(textProvider.hasKey("nosuchkey"));
+ }
+
+ public void testGetResourceBundleByName() throws Exception {
+ assertNotNull(textProvider.getTexts("com.opensymphony.xwork2.validator.CompositeTextProviderTestResourceBundle1"));
+ assertNotNull(textProvider.getTexts("com.opensymphony.xwork2.validator.CompositeTextProviderTestResourceBundle2"));
+ assertNull(textProvider.getTexts("com.opensymphony.xwork2.validator.CompositeTextProviderTestResourceBundle3"));
+ }
+
+ public void testGetResourceBundle() throws Exception {
+ assertNotNull(textProvider.getTexts());
+ // we should get the first resource bundle where 'car' and 'bike' has a i18n msg
+ assertNotNull(textProvider.getTexts().getString("car"));
+ assertNotNull(textProvider.getTexts().getString("bike"));
+ }
+
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ textProvider = new CompositeTextProvider(new TextProvider[] {
+ new TextProviderSupport(ResourceBundle.getBundle("com.opensymphony.xwork2.validator.CompositeTextProviderTestResourceBundle1"),
+ new LocaleProvider() {
+ public Locale getLocale() {
+ return Locale.ENGLISH;
+ }
+ }),
+ new TextProviderSupport(ResourceBundle.getBundle("com.opensymphony.xwork2.validator.CompositeTextProviderTestResourceBundle2"),
+ new LocaleProvider() {
+ public Locale getLocale() {
+ return Locale.ENGLISH;
+ }
+ })
+
+ });
+ }
+
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ textProvider = null;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,59 @@
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.config.entities.InterceptorMapping;
+import com.opensymphony.xwork2.mock.MockActionProxy;
+import com.opensymphony.xwork2.mock.MockInterceptor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+
+/**
+ * A partial test of DefaultActionInvocation.
+ * Created to change interceptor chain logic.
+ *
+ * @author <a href="mailto:kristian at zenior.no">Kristian Rosenvold</a>
+ */
+public class DefaultActionInvocationTest extends XWorkTestCase {
+
+ /**
+ * Tests interceptor chain invoke.
+ *
+ * @throws Exception when action throws exception
+ */
+ public void testInvoke() throws Exception {
+ List<InterceptorMapping> interceptorMappings = new ArrayList<InterceptorMapping>();
+ MockInterceptor mockInterceptor1 = new MockInterceptor();
+ mockInterceptor1.setFoo("test1");
+ mockInterceptor1.setExpectedFoo("test1");
+ interceptorMappings.add(new InterceptorMapping("test1", mockInterceptor1));
+ MockInterceptor mockInterceptor2 = new MockInterceptor();
+ interceptorMappings.add(new InterceptorMapping("test2", mockInterceptor2));
+ mockInterceptor2.setFoo("test2");
+ mockInterceptor2.setExpectedFoo("test2");
+ MockInterceptor mockInterceptor3 = new MockInterceptor();
+ interceptorMappings.add(new InterceptorMapping("test3", mockInterceptor3));
+ mockInterceptor3.setFoo("test3");
+ mockInterceptor3.setExpectedFoo("test3");
+
+ DefaultActionInvocation defaultActionInvocation = new DefaultActionInvocationTester(interceptorMappings);
+ defaultActionInvocation.invoke();
+ assertTrue(mockInterceptor1.isExecuted());
+ assertTrue(mockInterceptor2.isExecuted());
+ assertTrue(mockInterceptor3.isExecuted());
+ }
+
+
+ class DefaultActionInvocationTester extends DefaultActionInvocation {
+ DefaultActionInvocationTester(List<InterceptorMapping> interceptorMappings) {
+ super(new HashMap<String, Object>(), false);
+ interceptors = interceptorMappings.iterator();
+ MockActionProxy actionProxy = new MockActionProxy();
+ actionProxy.setMethod("execute");
+ proxy = actionProxy;
+ action = new ActionSupport();
+ }
+ }
+
+}
\ No newline at end of file
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultClasstTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultClasstTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultClasstTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultClasstTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2002-2008 by OpenSymphony
+ * All rights reserved.
+ */
+
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+
+/**
+ * <code>WildCardResultTest</code>
+ *
+ * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
+ * @version $Id$
+ */
+public class DefaultClasstTest extends XWorkTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // ensure we're using the default configuration, not simple config
+ loadConfigurationProviders(new XmlConfigurationProvider("xwork-sample.xml"));
+ }
+
+ public void testWildCardEvaluation() throws Exception {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("Abstract-crud", "edit", null);
+ assertEquals("com.opensymphony.xwork2.SimpleAction", proxy.getConfig().getClassName());
+
+ proxy = actionProxyFactory.createActionProxy("/example", "edit", null);
+ assertEquals("com.opensymphony.xwork2.ModelDrivenAction", proxy.getConfig().getClassName());
+
+
+ proxy = actionProxyFactory.createActionProxy("/example2", "override", null);
+ assertEquals("com.opensymphony.xwork2.ModelDrivenAction", proxy.getConfig().getClassName());
+
+ proxy = actionProxyFactory.createActionProxy("/example2/subItem", "save", null);
+ assertEquals("com.opensymphony.xwork2.ModelDrivenAction", proxy.getConfig().getClassName());
+
+ proxy = actionProxyFactory.createActionProxy("/example2", "list", null);
+ assertEquals("com.opensymphony.xwork2.ModelDrivenAction", proxy.getConfig().getClassName());
+
+ proxy = actionProxyFactory.createActionProxy("/example3", "list", null);
+ assertEquals("com.opensymphony.xwork2.SimpleAction", proxy.getConfig().getClassName());
+ }
+
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultClasstTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultClasstTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultTextProviderTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultTextProviderTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultTextProviderTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultTextProviderTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.util.LocalizedTextUtil;
+import junit.framework.TestCase;
+
+import java.util.*;
+
+/**
+ * Unit test for {@link DefaultTextProvider}.
+ *
+ * @author Claus Ibsen
+ */
+public class DefaultTextProviderTest extends TestCase {
+
+ private DefaultTextProvider tp;
+
+ public void testSimpleGetTexts() throws Exception {
+ assertEquals("Hello World", tp.getText("hello"));
+ assertEquals(null, tp.getText("not.in.bundle"));
+
+ assertEquals("Hello World", tp.getText("hello", "this is default"));
+ assertEquals("this is default", tp.getText("not.in.bundle", "this is default"));
+
+ List<Object> nullList = null;
+ assertEquals("Hello World", tp.getText("hello", nullList));
+
+ String[] nullStrings = null;
+ assertEquals("Hello World", tp.getText("hello", nullStrings));
+ }
+
+ public void testGetTextsWithArgs() throws Exception {
+ assertEquals("Hello World", tp.getText("hello", "this is default", "from me")); // no args in bundle
+ assertEquals("Hello World from me", tp.getText("hello.0", "this is default", "from me"));
+ assertEquals("this is default", tp.getText("not.in.bundle", "this is default", "from me"));
+ assertEquals("this is default from me", tp.getText("not.in.bundle", "this is default {0}", "from me"));
+
+ assertEquals(null, tp.getText("not.in.bundle"));
+ }
+
+ public void testGetTextsWithListArgs() throws Exception {
+ List<Object> args = new ArrayList<Object>();
+ args.add("Santa");
+ args.add("loud");
+ assertEquals("Hello World", tp.getText("hello", "this is default", args)); // no args in bundle
+ assertEquals("Hello World Santa", tp.getText("hello.0", "this is default", args)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", tp.getText("hello.1", "this is default", args));
+
+ assertEquals("this is default", tp.getText("not.in.bundle", "this is default", args));
+ assertEquals("this is default Santa", tp.getText("not.in.bundle", "this is default {0}", args));
+ assertEquals("this is default Santa speaking loud", tp.getText("not.in.bundle", "this is default {0} speaking {1}", args));
+
+ assertEquals("Hello World", tp.getText("hello", args)); // no args in bundle
+ assertEquals("Hello World Santa", tp.getText("hello.0", args)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", tp.getText("hello.1", args));
+
+ assertEquals(null, tp.getText("not.in.bundle", args));
+
+ assertEquals("Hello World", tp.getText("hello", "this is default", (List) null));
+ assertEquals("this is default", tp.getText("not.in.bundle", "this is default", (List) null));
+ }
+
+ public void testGetTextsWithArrayArgs() throws Exception {
+ String[] args = { "Santa", "loud" };
+ assertEquals("Hello World", tp.getText("hello", "this is default", args)); // no args in bundle
+ assertEquals("Hello World Santa", tp.getText("hello.0", "this is default", args)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", tp.getText("hello.1", "this is default", args));
+
+ assertEquals("this is default", tp.getText("not.in.bundle", "this is default", args));
+ assertEquals("this is default Santa", tp.getText("not.in.bundle", "this is default {0}", args));
+ assertEquals("this is default Santa speaking loud", tp.getText("not.in.bundle", "this is default {0} speaking {1}", args));
+
+ assertEquals("Hello World", tp.getText("hello", args)); // no args in bundle
+ assertEquals("Hello World Santa", tp.getText("hello.0", args)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", tp.getText("hello.1", args));
+
+ assertEquals(null, tp.getText("not.in.bundle", args));
+
+ assertEquals("Hello World", tp.getText("hello", "this is default", (String[]) null));
+ assertEquals("this is default", tp.getText("not.in.bundle", "this is default", (String[]) null));
+ }
+
+ public void testGetTextsWithListAndStack() throws Exception {
+ List<Object> args = new ArrayList<Object>();
+ args.add("Santa");
+ args.add("loud");
+ assertEquals("Hello World", tp.getText("hello", "this is default", args, null)); // no args in bundle
+ assertEquals("Hello World Santa", tp.getText("hello.0", "this is default", args, null)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", tp.getText("hello.1", "this is default", args, null));
+
+ assertEquals("this is default", tp.getText("not.in.bundle", "this is default", args, null));
+ assertEquals("this is default Santa", tp.getText("not.in.bundle", "this is default {0}", args, null));
+ assertEquals("this is default Santa speaking loud", tp.getText("not.in.bundle", "this is default {0} speaking {1}", args, null));
+ }
+
+ public void testGetTextsWithArrayAndStack() throws Exception {
+ String[] args = { "Santa", "loud" };
+ assertEquals("Hello World", tp.getText("hello", "this is default", args, null)); // no args in bundle
+ assertEquals("Hello World Santa", tp.getText("hello.0", "this is default", args, null)); // only 1 arg in bundle
+ assertEquals("Hello World. This is Santa speaking loud", tp.getText("hello.1", "this is default", args, null));
+
+ assertEquals("this is default", tp.getText("not.in.bundle", "this is default", args, null));
+ assertEquals("this is default Santa", tp.getText("not.in.bundle", "this is default {0}", args, null));
+ assertEquals("this is default Santa speaking loud", tp.getText("not.in.bundle", "this is default {0} speaking {1}", args, null));
+ }
+
+ public void testGetBundle() throws Exception {
+ assertNull(tp.getTexts()); // always returns null
+
+ ResourceBundle rb = ResourceBundle.getBundle(TextProviderSupportTest.class.getName(), Locale.CANADA);
+ assertEquals(rb, tp.getTexts(TextProviderSupportTest.class.getName()));
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ ActionContext ctx = new ActionContext(new HashMap<String, Object>());
+ ActionContext.setContext(ctx);
+ ctx.setLocale(Locale.CANADA);
+
+ LocalizedTextUtil.clearDefaultResourceBundles();
+ LocalizedTextUtil.addDefaultResourceBundle(DefaultTextProviderTest.class.getName());
+
+ tp = new DefaultTextProvider();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ ActionContext.setContext(null);
+ tp = null;
+ }
+
+
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultTextProviderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/DefaultTextProviderTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ExternalReferenceAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ExternalReferenceAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ExternalReferenceAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ExternalReferenceAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+/*
+ * Created on Nov 11, 2003
+ *
+ * To change the template for this generated file go to Window - Preferences -
+ * Java - Code Generation - Code and Comments
+ */
+package com.opensymphony.xwork2;
+
+
+/**
+ * @author Mike
+ * <p/>
+ * To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Generation - Code and Comments
+ */
+public class ExternalReferenceAction implements Action {
+
+ private Foo foo;
+
+
+ /**
+ * @param foo The foo to set.
+ */
+ public void setFoo(Foo foo) {
+ this.foo = foo;
+ }
+
+ /**
+ * @return Returns the foo.
+ */
+ public Foo getFoo() {
+ return foo;
+ }
+
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ExternalReferenceAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ExternalReferenceAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/Foo.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/Foo.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/Foo.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/Foo.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+/*
+ * Created on Nov 11, 2003
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+package com.opensymphony.xwork2;
+
+
+/**
+ * @author Mike
+ * <p/>
+ * To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+public class Foo {
+
+ String name = null;
+
+
+ public Foo() {
+ name = "not set";
+ }
+
+ public Foo(String name) {
+ this.name = name;
+ }
+
+
+ public String getName() {
+ return name;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/Foo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/Foo.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/GenericsBean.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/GenericsBean.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/GenericsBean.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/GenericsBean.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,57 @@
+package com.opensymphony.xwork2;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <code>GenericsBean</code>
+ *
+ * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
+ * @version $Id$
+ */
+public class GenericsBean {
+ private List<Double> blubb;
+ private List<Double> getterList;
+ private Map<Double, Integer> genericMap = new HashMap<Double, Integer>();
+ private Map<Double, List<Integer>> extendedMap = new HashMap<Double, List<Integer>>();
+
+ /**
+ * @return Returns the doubles.
+ */
+ public List<Double> getDoubles() {
+ return blubb;
+ }
+
+ /**
+ * @param doubles The doubles to set.
+ */
+ public void setDoubles(List<Double> doubles) {
+ this.blubb = doubles;
+ }
+
+ public Map<Double, Integer> getGenericMap() {
+ return genericMap;
+ }
+
+ public void setGenericMap(Map<Double, Integer> genericMap) {
+ this.genericMap = genericMap;
+ }
+
+ public List<Double> getGetterList() {
+ if ( getterList == null ) {
+ getterList = new ArrayList<Double>(1);
+ getterList.add(42.42);
+ }
+ return getterList;
+ }
+
+ public Map<Double, List<Integer>> getExtendedMap() {
+ return extendedMap;
+ }
+
+ public void setExtendedMap(Map<Double, List<Integer>> extendedMap) {
+ this.extendedMap = extendedMap;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/GenericsBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/GenericsBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/LocaleAwareTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/LocaleAwareTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/LocaleAwareTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/LocaleAwareTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.config.providers.MockConfigurationProvider;
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+
+import java.util.Locale;
+
+
+/**
+ * LocaleAwareTest
+ *
+ * @author Jason Carreira
+ * Created Feb 10, 2003 6:13:13 PM
+ */
+public class LocaleAwareTest extends XWorkTestCase {
+
+ public void testGetText() {
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.FOO_ACTION_NAME, null);
+ ActionContext.getContext().setLocale(Locale.US);
+
+ TextProvider localeAware = (TextProvider) proxy.getAction();
+ assertEquals("Foo Range Message", localeAware.getText("foo.range"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testLocaleGetText() {
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.FOO_ACTION_NAME, null);
+ ActionContext.getContext().setLocale(Locale.GERMANY);
+
+ TextProvider localeAware = (TextProvider) proxy.getAction();
+ assertEquals("I don't know German", localeAware.getText("foo.range"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ loadConfigurationProviders(new XmlConfigurationProvider("xwork-test-beans.xml"), new MockConfigurationProvider());
+
+ ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
+ stack.getContext().put(ActionContext.CONTAINER, container);
+ ActionContext.setContext(new ActionContext(stack.getContext()));
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/LocaleAwareTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/LocaleAwareTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+
+/**
+ * ModelDrivenAction
+ *
+ * @author Jason Carreira
+ * Created Apr 8, 2003 6:27:29 PM
+ */
+public class ModelDrivenAction extends ActionSupport implements ModelDriven {
+
+ private String foo;
+ private TestBean model = new TestBean();
+
+
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ public String getFoo() {
+ return foo;
+ }
+
+ /**
+ * @return the model to be pushed onto the ValueStack after the Action itself
+ */
+ public Object getModel() {
+ return model;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+/**
+ * ModelDrivenAnnotationAction
+ *
+ * @author Jason Carreira
+ * @author Rainer Hermanns
+ * Created Apr 8, 2003 6:27:29 PM
+ */
+public class ModelDrivenAnnotationAction extends ActionSupport implements ModelDriven {
+
+ private String foo;
+ private AnnotatedTestBean model = new AnnotatedTestBean();
+
+
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ public String getFoo() {
+ return foo;
+ }
+
+ /**
+ * @return the model to be pushed onto the ValueStack after the Action itself
+ */
+ public Object getModel() {
+ return model;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/NestedAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/NestedAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/NestedAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/NestedAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.util.ValueStack;
+import junit.framework.Assert;
+
+
+/**
+ * NestedAction
+ *
+ * @author Jason Carreira
+ * Created Mar 5, 2003 3:08:19 PM
+ */
+public class NestedAction implements Action {
+
+ private String nestedProperty = ActionNestingTest.NESTED_VALUE;
+
+
+ public NestedAction() {
+ }
+
+
+ public String getNestedProperty() {
+ return nestedProperty;
+ }
+
+ public String execute() throws Exception {
+ Assert.fail();
+
+ return null;
+ }
+
+ public String noStack() {
+ ValueStack stack = ActionContext.getContext().getValueStack();
+ // Action + DefaultTextProvider on the stack
+ Assert.assertEquals(2, stack.size());
+ Assert.assertNull(stack.findValue(ActionNestingTest.KEY));
+ Assert.assertEquals(ActionNestingTest.NESTED_VALUE, stack.findValue(ActionNestingTest.NESTED_KEY));
+
+ return SUCCESS;
+ }
+
+ public String stack() {
+ ValueStack stack = ActionContext.getContext().getValueStack();
+ //DefaultTextProvider, NestedActionTest pushed on by the test, and the NestedAction
+ Assert.assertEquals(3, stack.size());
+ Assert.assertNotNull(stack.findValue(ActionNestingTest.KEY));
+ Assert.assertEquals(ActionContext.getContext().getValueStack().findValue(ActionNestingTest.KEY), ActionNestingTest.VALUE);
+ Assert.assertEquals(ActionNestingTest.NESTED_VALUE, stack.findValue(ActionNestingTest.NESTED_KEY));
+
+ return SUCCESS;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/NestedAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/NestedAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,10 @@
+package com.opensymphony.xwork2;
+
+/**
+ * Need by the ProxyInvocationTest
+ */
+public class ProxyInvocationAction extends ActionSupport implements ProxyInvocationInterface {
+ public String show() {
+ return "proxyResult";
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationInterface.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationInterface.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationInterface.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationInterface.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,8 @@
+package com.opensymphony.xwork2;
+
+/**
+ * Need by the ProxyInvocationTest
+ */
+public interface ProxyInvocationInterface {
+ public String show();
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationInterface.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationInterface.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,49 @@
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Contribed by: Ruben Inoto
+ */
+public class ProxyInvocationTest extends XWorkTestCase {
+
+ /**
+ * Sets a ProxyObjectFactory as ObjectFactory (so the FooAction will always be retrieved
+ * as a FooProxy), and it tries to call invokeAction on the TestActionInvocation.
+ *
+ * It should fail, because the Method got from the action (actually a FooProxy)
+ * will be executed on the InvocationHandler of the action (so, in the action itself).
+ */
+ public void testProxyInvocation() throws Exception {
+
+ ActionProxy proxy = actionProxyFactory
+ .createActionProxy("", "ProxyInvocation", createDummyContext());
+ ActionInvocation invocation = proxy.getInvocation();
+
+ String result = invocation.invokeActionOnly();
+ assertEquals("proxyResult", result);
+
+ }
+
+ /**
+ * Needed for the creation of the action proxy
+ */
+ private Map<String, Object> createDummyContext() {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("blah", "this is blah");
+ Map<String, Object> extraContext = new HashMap<String, Object>();
+ extraContext.put(ActionContext.PARAMETERS, params);
+ return extraContext;
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // ensure we're using the default configuration, not simple config
+ loadConfigurationProviders(new XmlConfigurationProvider("xwork-proxyinvoke.xml"));
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,46 @@
+package com.opensymphony.xwork2;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+
+/**
+ * ObjectFactory that returns a FooProxy in the buildBean if the clazz is FooAction
+ */
+public class ProxyObjectFactory extends ObjectFactory {
+
+ /**
+ * It returns an instance of the bean except if the class is FooAction.
+ * In this case, it returns a FooProxy of it.
+ */
+ @Override
+ public Object buildBean(Class clazz, Map<String, Object> extraContext)
+ throws Exception {
+ Object bean = super.buildBean(clazz, extraContext);
+ if(clazz.equals(ProxyInvocationAction.class)) {
+ return Proxy.newProxyInstance(bean.getClass()
+ .getClassLoader(), bean.getClass().getInterfaces(),
+ new ProxyInvocationProxy(bean));
+
+ }
+ return bean;
+ }
+
+ /**
+ * Simple proxy that just invokes the method on the target on the invoke method
+ */
+ public class ProxyInvocationProxy implements InvocationHandler {
+
+ private Object target;
+
+ public ProxyInvocationProxy(Object target) {
+ this.target = target;
+ }
+
+ public Object invoke(Object proxy, Method m, Object[] args)
+ throws Throwable {
+ return m.invoke(target, args);
+ }
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.inject.Inject;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class SimpleAction extends ActionSupport {
+
+ public static final String COMMAND_RETURN_CODE = "com.opensymphony.xwork2.SimpleAction.CommandInvoked";
+
+
+ private ArrayList someList = new ArrayList();
+ private Date date = new Date();
+ private Properties settings = new Properties();
+ private String blah;
+ private String name;
+ private TestBean bean = new TestBean();
+ private boolean throwException;
+ private int bar;
+ private int baz;
+ private int foo;
+ private long longFoo;
+ private short shortFoo;
+ private double percentage;
+ private Map<Integer,String> indexedProps = new HashMap<Integer,String>();
+
+ private String aliasSource;
+ private String aliasDest;
+ private Map<String,String> protectedMap = new HashMap<String,String>();
+ private Map<String,String> existingMap = new HashMap<String,String>();
+
+ public static boolean resultCalled;
+
+
+ public SimpleAction() {
+ resultCalled = false;
+ existingMap.put("existingKey", "value");
+ }
+
+ public Map<String,String> getTheProtectedMap() {
+ return protectedMap;
+ }
+
+ protected Map<String,String> getTheSemiProtectedMap() {
+ return protectedMap;
+ }
+
+ public void setExistingMap(Map<String,String> map) {
+ this.existingMap = map;
+ }
+
+ public Map<String,String> getTheExistingMap() {
+ return existingMap;
+ }
+
+
+ public void setBar(int bar) {
+ this.bar = bar;
+ }
+
+ public int getBar() {
+ return bar;
+ }
+
+ public double getPercentage() {
+ return percentage;
+ }
+
+ public void setPercentage(double percentage) {
+ this.percentage = percentage;
+ }
+
+ public void setBaz(int baz) {
+ this.baz = baz;
+ }
+
+ public int getBaz() {
+ return baz;
+ }
+
+ public void setBean(TestBean bean) {
+ this.bean = bean;
+ }
+
+ public TestBean getBean() {
+ return bean;
+ }
+
+ public void setBlah(String blah) {
+ this.blah = blah;
+ }
+
+ public String getBlah() {
+ return blah;
+ }
+
+ public Boolean getBool(String b) {
+ return new Boolean(b);
+ }
+
+ public boolean[] getBools() {
+ boolean[] b = new boolean[]{true, false, false, true};
+
+ return b;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setFoo(int foo) {
+ this.foo = foo;
+ }
+
+ public int getFoo() {
+ return foo;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setSettings(Properties settings) {
+ this.settings = settings;
+ }
+
+ public Properties getSettings() {
+ return settings;
+ }
+
+
+ public String getAliasDest() {
+ return aliasDest;
+ }
+
+ public void setAliasDest(String aliasDest) {
+ this.aliasDest = aliasDest;
+ }
+
+ public String getAliasSource() {
+ return aliasSource;
+ }
+
+ public void setAliasSource(String aliasSource) {
+ this.aliasSource = aliasSource;
+ }
+
+
+ public void setSomeList(ArrayList someList) {
+ this.someList = someList;
+ }
+
+ public ArrayList getSomeList() {
+ return someList;
+ }
+
+ public String getIndexedProp(int index) {
+ return indexedProps.get(index);
+ }
+
+ public void setIndexedProp(int index, String val) {
+ indexedProps.put(index, val);
+ }
+
+
+ public void setThrowException(boolean throwException) {
+ this.throwException = throwException;
+ }
+
+ public String commandMethod() throws Exception {
+ return COMMAND_RETURN_CODE;
+ }
+
+ public Result resultAction() throws Exception {
+ return new Result() {
+ public Configuration configuration;
+
+ @Inject
+ public void setConfiguration(Configuration config) {
+ this.configuration = config;
+ }
+ public void execute(ActionInvocation invocation) throws Exception {
+ if (configuration != null)
+ resultCalled = true;
+ }
+
+ };
+ }
+
+ public String exceptionMethod() throws Exception {
+ if (throwException) {
+ throw new Exception("We're supposed to throw this");
+ }
+
+ return "OK";
+ }
+
+ @Override
+ public String execute() throws Exception {
+ if (foo == bar) {
+ return ERROR;
+ }
+
+ baz = foo + bar;
+
+ name = "HelloWorld";
+ settings.put("foo", "bar");
+ settings.put("black", "white");
+
+ someList.add("jack");
+ someList.add("bill");
+ someList.add("kerry");
+
+ return SUCCESS;
+ }
+
+ public String doInput() throws Exception {
+ return INPUT;
+ }
+
+
+ public long getLongFoo() {
+ return longFoo;
+ }
+
+
+ public void setLongFoo(long longFoo) {
+ this.longFoo = longFoo;
+ }
+
+
+ public short getShortFoo() {
+ return shortFoo;
+ }
+
+
+ public void setShortFoo(short shortFoo) {
+ this.shortFoo = shortFoo;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.validator.annotations.*;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Properties;
+
+
+/**
+ * Simple Test Action for annotaton processing.
+ *
+ * @author Rainer Hermanns
+ * @version $Revision$
+ */
+@Validation()
+public class SimpleAnnotationAction extends ActionSupport {
+ //~ Static fields/initializers /////////////////////////////////////////////
+
+ public static final String COMMAND_RETURN_CODE = "com.opensymphony.xwork2.SimpleAnnotationAction.CommandInvoked";
+
+ //~ Instance fields ////////////////////////////////////////////////////////
+
+ private ArrayList<String> someList = new ArrayList<String>();
+ private Date date = new Date();
+ private Properties settings = new Properties();
+ private String blah;
+ private String name;
+ private AnnotatedTestBean bean = new AnnotatedTestBean();
+ private boolean throwException;
+ private int bar;
+ private int baz;
+ private int foo;
+ private double percentage;
+
+ private String aliasSource;
+ private String aliasDest;
+
+
+
+ //~ Constructors ///////////////////////////////////////////////////////////
+
+ public SimpleAnnotationAction() {
+ }
+
+ //~ Methods ////////////////////////////////////////////////////////////////
+
+ @RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter a value for bar.")
+ @IntRangeFieldValidator(type = ValidatorType.FIELD, min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.")
+ public void setBar(int bar) {
+ this.bar = bar;
+ }
+
+ public int getBar() {
+ return bar;
+ }
+
+ @IntRangeFieldValidator(min = "0", key = "baz.range", message = "Could not find baz.range!")
+ public void setBaz(int baz) {
+ this.baz = baz;
+ }
+
+ public int getBaz() {
+ return baz;
+ }
+
+ public double getPercentage() {
+ return percentage;
+ }
+
+ @DoubleRangeFieldValidator(minInclusive = "0.123", key = "baz.range", message = "Could not find percentage.range!")
+ public void setPercentage(double percentage) {
+ this.percentage = percentage;
+ }
+
+ public void setBean(AnnotatedTestBean bean) {
+ this.bean = bean;
+ }
+
+ public AnnotatedTestBean getBean() {
+ return bean;
+ }
+
+ public void setBlah(String blah) {
+ this.blah = blah;
+ }
+
+ public String getBlah() {
+ return blah;
+ }
+
+ public Boolean getBool(String b) {
+ return new Boolean(b);
+ }
+
+ public boolean[] getBools() {
+ return new boolean[] {true, false, false, true};
+ }
+
+ @DateRangeFieldValidator(min = "12/22/2002", max = "12/25/2002", message = "The date must be between 12-22-2002 and 12-25-2002.")
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setFoo(int foo) {
+ this.foo = foo;
+ }
+
+ public int getFoo() {
+ return foo;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setSettings(Properties settings) {
+ this.settings = settings;
+ }
+
+ public Properties getSettings() {
+ return settings;
+ }
+
+
+ public String getAliasDest() {
+ return aliasDest;
+ }
+
+ public void setAliasDest(String aliasDest) {
+ this.aliasDest = aliasDest;
+ }
+
+ public String getAliasSource() {
+ return aliasSource;
+ }
+
+ public void setAliasSource(String aliasSource) {
+ this.aliasSource = aliasSource;
+ }
+
+
+ public void setSomeList(ArrayList<String> someList) {
+ this.someList = someList;
+ }
+
+ public ArrayList<String> getSomeList() {
+ return someList;
+ }
+
+ public void setThrowException(boolean throwException) {
+ this.throwException = throwException;
+ }
+
+ public String commandMethod() throws Exception {
+ return COMMAND_RETURN_CODE;
+ }
+
+ public String exceptionMethod() throws Exception {
+ if (throwException) {
+ throw new Exception("We're supposed to throw this");
+ }
+
+ return "OK";
+ }
+
+ @Override
+ @Validations(
+ requiredFields =
+ {@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "customfield", message = "You must enter a value for field.")},
+ requiredStrings =
+ {@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "stringisrequired", message = "You must enter a value for string.")},
+ emails =
+ { @EmailValidator(type = ValidatorType.SIMPLE, fieldName = "emailaddress", message = "You must enter a value for email.")},
+ urls =
+ { @UrlValidator(type = ValidatorType.SIMPLE, fieldName = "hreflocation", message = "You must enter a value for email.")},
+ stringLengthFields =
+ {@StringLengthFieldValidator(type = ValidatorType.SIMPLE, trim = true, minLength="10" , maxLength = "12", fieldName = "needstringlength", message = "You must enter a stringlength.")},
+ intRangeFields =
+ { @IntRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "intfield", min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.")},
+ dateRangeFields =
+ {@DateRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "datefield", min = "-1", max = "99", message = "bar must be between ${min} and ${max}, current value is ${bar}.")},
+ expressions = {
+ @ExpressionValidator(expression = "foo > 1", message = "Foo must be greater than Bar 1. Foo = ${foo}, Bar = ${bar}."),
+ @ExpressionValidator(expression = "foo > 2", message = "Foo must be greater than Bar 2. Foo = ${foo}, Bar = ${bar}."),
+ @ExpressionValidator(expression = "foo > 3", message = "Foo must be greater than Bar 3. Foo = ${foo}, Bar = ${bar}."),
+ @ExpressionValidator(expression = "foo > 4", message = "Foo must be greater than Bar 4. Foo = ${foo}, Bar = ${bar}."),
+ @ExpressionValidator(expression = "foo > 5", message = "Foo must be greater than Bar 5. Foo = ${foo}, Bar = ${bar}.")
+ }
+ )
+ public String execute() throws Exception {
+ if (foo == bar) {
+ return ERROR;
+ }
+
+ baz = foo + bar;
+
+ name = "HelloWorld";
+ settings.put("foo", "bar");
+ settings.put("black", "white");
+
+ someList.add("jack");
+ someList.add("bill");
+ someList.add("kerry");
+
+ return SUCCESS;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleFooAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleFooAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleFooAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleFooAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class SimpleFooAction implements Action {
+
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
+}
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleFooAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/SimpleFooAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL