You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2011/12/02 17:33:45 UTC
svn commit: r1209569 [37/50] - in /struts/struts2/branches/STRUTS_3_X:
apps/blank/src/main/java/example/ apps/blank/src/test/java/example/
apps/jboss-blank/src/main/java/example/
apps/jboss-blank/src/test/java/example/ apps/mailreader/src/main/java/mai...
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ProxyInvocationTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ProxyInvocationTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ProxyInvocationTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ProxyInvocationTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,49 @@
+package org.apache.struts2.xwork2;
+
+import org.apache.struts2.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"));
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ProxyObjectFactory.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ProxyObjectFactory.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ProxyObjectFactory.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ProxyObjectFactory.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,46 @@
+package org.apache.struts2.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);
+ }
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleAction.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleAction.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleAction.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,271 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+import org.apache.struts2.xwork2.config.Configuration;
+import org.apache.struts2.xwork2.inject.Inject;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision: 1209415 $
+ */
+public class SimpleAction extends ActionSupport {
+
+ public static final String COMMAND_RETURN_CODE = "org.apache.struts2.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;
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleAnnotationAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleAnnotationAction.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleAnnotationAction.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleAnnotationAction.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,242 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+import org.apache.struts2.xwork2.validator.annotations.DateRangeFieldValidator;
+import org.apache.struts2.xwork2.validator.annotations.DoubleRangeFieldValidator;
+import org.apache.struts2.xwork2.validator.annotations.EmailValidator;
+import org.apache.struts2.xwork2.validator.annotations.ExpressionValidator;
+import org.apache.struts2.xwork2.validator.annotations.IntRangeFieldValidator;
+import org.apache.struts2.xwork2.validator.annotations.RequiredFieldValidator;
+import org.apache.struts2.xwork2.validator.annotations.RequiredStringValidator;
+import org.apache.struts2.xwork2.validator.annotations.StringLengthFieldValidator;
+import org.apache.struts2.xwork2.validator.annotations.UrlValidator;
+import org.apache.struts2.xwork2.validator.annotations.Validation;
+import org.apache.struts2.xwork2.validator.annotations.Validations;
+import org.apache.struts2.xwork2.validator.annotations.ValidatorType;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Properties;
+
+
+/**
+ * Simple Test Action for annotaton processing.
+ *
+ * @author Rainer Hermanns
+ * @version $Revision: 1209415 $
+ */
+@Validation()
+public class SimpleAnnotationAction extends ActionSupport {
+ //~ Static fields/initializers /////////////////////////////////////////////
+
+ public static final String COMMAND_RETURN_CODE = "org.apache.struts2.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;
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleFooAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleFooAction.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleFooAction.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/SimpleFooAction.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision: 1209415 $
+ */
+public class SimpleFooAction implements Action {
+
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/StubValueStack.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/StubValueStack.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/StubValueStack.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/StubValueStack.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+import org.apache.struts2.xwork2.util.CompoundRoot;
+import org.apache.struts2.xwork2.util.ValueStack;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Stub value stack for testing
+ */
+public class StubValueStack implements ValueStack {
+ Map<String, Object> ctx = new HashMap<String, Object>();
+ CompoundRoot root = new CompoundRoot();
+
+ public Map<String, Object> getContext() {
+ return ctx;
+ }
+
+ public void setDefaultType(Class defaultType) {
+ }
+
+ public void setExprOverrides(Map<Object, Object> overrides) {
+ }
+
+ public Map<Object, Object> getExprOverrides() {
+ return null;
+ }
+
+ public CompoundRoot getRoot() {
+ return root;
+ }
+
+ public void setValue(String expr, Object value) {
+ ctx.put(expr, value);
+ }
+
+ public void setValue(String expr, Object value, boolean throwExceptionOnFailure) {
+ ctx.put(expr, value);
+ }
+
+ public String findString(String expr) {
+ return (String) ctx.get(expr);
+ }
+
+ public String findString(String expr, boolean throwExceptionOnFailure) {
+ return findString(expr, false);
+ }
+
+ public Object findValue(String expr) {
+ return findValue(expr, false);
+ }
+
+ public Object findValue(String expr, boolean throwExceptionOnFailure) {
+ return ctx.get(expr);
+ }
+
+ public Object findValue(String expr, Class asType) {
+ return findValue(expr, asType, false);
+ }
+
+ public Object findValue(String expr, Class asType, boolean throwExceptionOnFailure) {
+ return ctx.get(expr);
+ }
+
+ public Object peek() {
+ return root.peek();
+ }
+
+ public Object pop() {
+ return root.pop();
+ }
+
+ public void push(Object o) {
+ root.push(o);
+ }
+
+ public void set(String key, Object o) {
+ ctx.put(key, o);
+ }
+
+ public int size() {
+ return root.size();
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestBean.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestBean.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestBean.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestBean.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+import java.util.Date;
+
+
+/**
+ * TestBean
+ *
+ * @author Jason Carreira
+ * Created Aug 4, 2003 12:39:53 AM
+ */
+public class TestBean {
+
+ private Date birth;
+ private String name;
+ private int count;
+
+ private TestChildBean child = new TestChildBean();
+
+ public TestBean() {
+ }
+
+
+ public void setBirth(Date birth) {
+ this.birth = birth;
+ }
+
+ public Date getBirth() {
+ return birth;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+
+ public TestChildBean getChild() {
+ return child;
+ }
+
+
+ public void setChild(TestChildBean child) {
+ this.child = child;
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestChildBean.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestChildBean.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestChildBean.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestChildBean.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+
+/**
+ * TestBean
+ */
+public class TestChildBean {
+
+ private Date birth;
+ private String name;
+ private int count;
+
+
+ public TestChildBean() {
+ Calendar cal = new GregorianCalendar(1900, 01, 01);
+ setBirth(cal.getTime());
+ }
+
+
+ public void setBirth(Date birth) {
+ this.birth = birth;
+ }
+
+ public Date getBirth() {
+ return birth;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestInterceptor.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestInterceptor.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestInterceptor.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+import org.apache.struts2.xwork2.interceptor.Interceptor;
+import junit.framework.Assert;
+
+
+/**
+ * TestInterceptor
+ *
+ * @author Jason Carreira
+ * Created Apr 21, 2003 9:04:06 PM
+ */
+public class TestInterceptor implements Interceptor {
+
+ public static final String DEFAULT_FOO_VALUE = "fooDefault";
+
+
+ private String expectedFoo = DEFAULT_FOO_VALUE;
+ private String foo = DEFAULT_FOO_VALUE;
+ private boolean executed = false;
+
+
+ public boolean isExecuted() {
+ return executed;
+ }
+
+ public void setExpectedFoo(String expectedFoo) {
+ this.expectedFoo = expectedFoo;
+ }
+
+ public String getExpectedFoo() {
+ return expectedFoo;
+ }
+
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ public String getFoo() {
+ return foo;
+ }
+
+ /**
+ * Called to let an interceptor clean up any resources it has allocated.
+ */
+ public void destroy() {
+ }
+
+ /**
+ * Called after an Interceptor is created, but before any requests are processed using the intercept() methodName. This
+ * gives the Interceptor a chance to initialize any needed resources.
+ */
+ public void init() {
+ }
+
+ /**
+ * Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the
+ * request by the DefaultActionInvocation or to short-circuit the processing and just return a String return code.
+ *
+ * @param invocation
+ * @return
+ * @throws Exception
+ */
+ public String intercept(ActionInvocation invocation) throws Exception {
+ executed = true;
+ Assert.assertNotSame(DEFAULT_FOO_VALUE, foo);
+ Assert.assertEquals(expectedFoo, foo);
+
+ return invocation.invoke();
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestNGXWorkTestCaseTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestNGXWorkTestCaseTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestNGXWorkTestCaseTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TestNGXWorkTestCaseTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+import org.apache.struts2.xwork2.config.ConfigurationManager;
+import junit.framework.TestCase;
+import org.testng.TestListenerAdapter;
+import org.testng.TestNG;
+import org.testng.annotations.Test;
+
+public class TestNGXWorkTestCaseTest extends TestCase {
+
+ public void testSimpleTest() throws Exception {
+ TestListenerAdapter tla = new TestListenerAdapter();
+ TestNG testng = new TestNG();
+ testng.setTestClasses(new Class[] { RunTest.class });
+ testng.addListener(tla);
+ try {
+ testng.run();
+ assertEquals(1, tla.getPassedTests().size());
+ assertEquals(0, tla.getFailedTests().size());
+ assertTrue(RunTest.ran);
+ assertNotNull(RunTest.mgr);
+ } finally {
+ RunTest.mgr = null;
+ }
+ }
+
+ @Test
+ public static class RunTest extends TestNGXWorkTestCase {
+ public static boolean ran = false;
+ public static ConfigurationManager mgr;
+
+ public void testRun() {
+ ran = true;
+ mgr = this.configurationManager;
+ }
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TextProviderSupportTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TextProviderSupportTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TextProviderSupportTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/TextProviderSupportTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.struts2.xwork2;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * Unit test for {@link TextProviderSupport}.
+ *
+ * @author Claus Ibsen
+ */
+public class TextProviderSupportTest extends XWorkTestCase {
+
+ private TextProviderSupport tp;
+ private java.util.ResourceBundle rb;
+
+ public void testHasKey() throws Exception {
+ assertTrue(tp.hasKey("hello"));
+ assertFalse(tp.hasKey("not.in.bundle"));
+ }
+
+ public void testSimpleGetTexts() throws Exception {
+ assertEquals("Hello World", tp.getText("hello"));
+ assertEquals("not.in.bundle", 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"));
+ }
+
+ 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("not.in.bundle", 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("not.in.bundle", tp.getText("not.in.bundle", args));
+ }
+
+ 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("not.in.bundle", tp.getText("not.in.bundle", args));
+ }
+
+ public void testGetBundle() throws Exception {
+ assertEquals(rb, tp.getTexts());
+ assertEquals(rb, tp.getTexts(TextProviderSupportTest.class.getName()));
+ }
+
+ public void testDifficultSymbols1() {
+ String val= tp.getText("symbols1");
+ assertEquals("\"=!@#$%^&*(){qwe}<>?:|}{[]\\';/.,<>`~'", val);
+ }
+
+ public void testDifficultSymbols2() {
+ String val= tp.getText("symbols2");
+ assertEquals("\"=!@#$%^&*()<>?:|[]\\';/.,<>`~'", val);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ rb = ResourceBundle.getBundle(TextProviderSupportTest.class.getName(), Locale.ENGLISH);
+ tp = new TextProviderSupport(rb, new LocaleProvider() {
+ public Locale getLocale() {
+ return Locale.ENGLISH;
+ }
+ });
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ rb = null;
+ tp = null;
+ }
+
+
+}
+
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/UnknownHandlerManagerMock.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/UnknownHandlerManagerMock.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/UnknownHandlerManagerMock.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/UnknownHandlerManagerMock.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,15 @@
+package org.apache.struts2.xwork2;
+
+import java.util.ArrayList;
+
+/*
+ * Utility class for testing DefaultUnknownHandlerManager, which does not allow to add
+ * UnknownHandlers directly
+ */
+public class UnknownHandlerManagerMock extends DefaultUnknownHandlerManager {
+ public void addUnknownHandler(UnknownHandler uh) {
+ if (this.unknownHandlers == null)
+ this.unknownHandlers = new ArrayList<UnknownHandler>();
+ this.unknownHandlers.add(uh);
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/UserSpecifiedDefaultAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/UserSpecifiedDefaultAction.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/UserSpecifiedDefaultAction.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/UserSpecifiedDefaultAction.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,10 @@
+package org.apache.struts2.xwork2;
+
+/**
+ * <code>UserSpecifiedDefaultAction</code>
+ *
+ * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
+ * @version $Id: UserSpecifiedDefaultAction.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class UserSpecifiedDefaultAction extends ActionSupport {
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ValidationOrderAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ValidationOrderAction.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ValidationOrderAction.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ValidationOrderAction.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+/**
+ * A sample action to test validation order.
+ *
+ * @author tm_jee
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Id: ValidationOrderAction.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class ValidationOrderAction extends ActionSupport {
+
+ private String username;
+ private String password;
+ private String confirmPassword;
+ private String firstName;
+ private String lastName;
+ private String city;
+ private String province;
+ private String country;
+ private String postalCode;
+ private String email;
+ private String website;
+ private String passwordHint;
+
+
+
+ @Override
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
+
+
+
+ public String getCity() {
+ return city;
+ }
+
+
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+
+
+ public String getConfirmPassword() {
+ return confirmPassword;
+ }
+
+
+
+ public void setConfirmPassword(String confirmPassword) {
+ this.confirmPassword = confirmPassword;
+ }
+
+
+
+ public String getCountry() {
+ return country;
+ }
+
+
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+
+
+ public String getEmail() {
+ return email;
+ }
+
+
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+
+
+ public String getLastName() {
+ return lastName;
+ }
+
+
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+
+
+ public String getPassword() {
+ return password;
+ }
+
+
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+
+
+ public String getPasswordHint() {
+ return passwordHint;
+ }
+
+
+
+ public void setPasswordHint(String passwordHint) {
+ this.passwordHint = passwordHint;
+ }
+
+
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+
+
+ public void setPostalCode(String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+
+
+ public String getProvince() {
+ return province;
+ }
+
+
+
+ public void setProvince(String province) {
+ this.province = province;
+ }
+
+
+
+ public String getUsername() {
+ return username;
+ }
+
+
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+
+
+ public String getWebsite() {
+ return website;
+ }
+
+
+
+ public void setWebsite(String website) {
+ this.website = website;
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/VoidResult.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/VoidResult.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/VoidResult.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/VoidResult.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+/**
+ */
+public class VoidResult implements Result {
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (!(o instanceof VoidResult)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public void execute(ActionInvocation invocation) throws Exception {
+ }
+
+ @Override
+ public int hashCode() {
+ return 42;
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/WildCardResultTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/WildCardResultTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/WildCardResultTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/WildCardResultTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.struts2.xwork2;
+
+import org.apache.struts2.xwork2.config.providers.XmlConfigurationProvider;
+import org.apache.struts2.xwork2.mock.MockResult;
+
+/**
+ * <code>WildCardResultTest</code>
+ *
+ * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
+ * @version $Id: WildCardResultTest.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class WildCardResultTest 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 {
+ ActionContext.setContext(null);
+ ActionProxy proxy = actionProxyFactory.createActionProxy(null, "WildCard", null);
+ assertEquals("success", proxy.execute());
+ assertEquals(VoidResult.class, proxy.getInvocation().getResult().getClass());
+
+ ActionContext.setContext(null);
+ proxy = actionProxyFactory.createActionProxy(null, "WildCardInput", null);
+ assertEquals("input", proxy.execute());
+ assertEquals(MockResult.class, proxy.getInvocation().getResult().getClass());
+
+ ActionContext.setContext(null);
+ proxy = actionProxyFactory.createActionProxy(null, "WildCardError", null);
+ assertEquals("error", proxy.execute());
+ assertEquals(MockResult.class, proxy.getInvocation().getResult().getClass());
+ }
+
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/XWorkExceptionTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/XWorkExceptionTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/XWorkExceptionTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/XWorkExceptionTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2002-2007,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2;
+
+import org.apache.struts2.xwork2.util.location.Location;
+
+public class XWorkExceptionTest extends XWorkTestCase {
+
+ public void testUnknown() throws Exception {
+ XWorkException e = new XWorkException("testXXX", this);
+ assertEquals(Location.UNKNOWN, e.getLocation());
+ }
+
+ public void testThrowable() {
+ XWorkException e = new XWorkException("testThrowable", new IllegalArgumentException("Arg is null"));
+ assertEquals("org/apache/struts2/xwork2/XWorkExceptionTest.java", e.getLocation().getURI());
+ String s = e.getLocation().toString();
+ assertTrue(s.contains("Method: testThrowable"));
+ }
+
+ public void testCauseAndTarget() {
+ XWorkException e = new XWorkException(new IllegalArgumentException("Arg is null"), this);
+ assertEquals("org/apache/struts2/xwork2/XWorkExceptionTest.java", e.getLocation().getURI());
+ String s = e.getLocation().toString();
+ assertTrue(s.contains("Method: testCauseAndTarget"));
+ }
+
+ public void testDefaultConstructor() {
+ XWorkException e = new XWorkException();
+
+ assertNull(e.getCause());
+ assertNull(e.getThrowable());
+ assertNull(e.getMessage());
+ assertNull(e.getLocation());
+
+ assertNull(e.toString()); // mo message so it returns null
+ }
+
+ public void testMessageOnly() {
+ XWorkException e = new XWorkException("Hello World");
+
+ assertNull(e.getCause());
+ assertEquals("Hello World", e.getMessage());
+ assertEquals(Location.UNKNOWN, e.getLocation());
+ }
+
+ public void testCauseOnly() {
+ XWorkException e = new XWorkException(new IllegalArgumentException("Arg is null"));
+
+ assertNotNull(e.getCause());
+ assertNotNull(e.getLocation());
+ assertEquals("org/apache/struts2/xwork2/XWorkExceptionTest.java", e.getLocation().getURI());
+ String s = e.getLocation().toString();
+ assertTrue(s.contains("Method: testCauseOnly"));
+ assertTrue(e.toString().contains("Arg is null"));
+ }
+
+ public void testCauseOnlyNoMessage() {
+ XWorkException e = new XWorkException(new IllegalArgumentException());
+
+ assertNotNull(e.getCause());
+ assertNotNull(e.getLocation());
+ assertEquals("org/apache/struts2/xwork2/XWorkExceptionTest.java", e.getLocation().getURI());
+ String s = e.getLocation().toString();
+ assertTrue(s.contains("Method: testCauseOnly"));
+ assertTrue(e.toString().contains("Method: testCauseOnly"));
+ }
+
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/ConfigurationManagerTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/ConfigurationManagerTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/ConfigurationManagerTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/ConfigurationManagerTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,181 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.config;
+
+//import org.easymock.MockControl;
+
+import com.mockobjects.dynamic.C;
+import com.mockobjects.dynamic.Mock;
+import org.apache.struts2.xwork2.XWorkTestCase;
+import org.apache.struts2.xwork2.config.providers.XWorkConfigurationProvider;
+import org.apache.struts2.xwork2.inject.ContainerBuilder;
+import org.apache.struts2.xwork2.util.FileManager;
+import org.apache.struts2.xwork2.util.location.LocatableProperties;
+
+import java.util.Properties;
+
+
+/**
+ * ConfigurationManagerTest
+ *
+ * @author Jason Carreira
+ * Created May 6, 2003 10:59:59 PM
+ */
+public class ConfigurationManagerTest extends XWorkTestCase {
+
+ Mock configProviderMock;
+
+
+ public void testConfigurationReload() {
+ FileManager.setReloadingConfigs(true);
+
+ // now check that it reloads
+ configProviderMock.expectAndReturn("needsReload", Boolean.TRUE);
+ configProviderMock.expect("init", C.isA(Configuration.class));
+ configProviderMock.expect("register", C.ANY_ARGS);
+ configProviderMock.expect("loadPackages", C.ANY_ARGS);
+ configProviderMock.expect("destroy", C.ANY_ARGS);
+ configProviderMock.matchAndReturn("toString", "mock");
+ configurationManager.getConfiguration();
+ configProviderMock.verify();
+
+ // this will be called in teardown
+ configProviderMock.expect("destroy");
+ }
+
+ public void testNoConfigurationReload() {
+ FileManager.setReloadingConfigs(false);
+
+ // now check that it doesn't try to reload
+ configurationManager.getConfiguration();
+ configProviderMock.verify();
+
+ // this will be called in teardown
+ configProviderMock.expect("destroy");
+ }
+
+ public void testDestroyConfiguration() throws Exception {
+ class State {
+ public boolean isDestroyed1 =false;
+ public boolean isDestroyed2 =false;
+ }
+
+ final State state = new State();
+ ConfigurationManager configurationManager = new ConfigurationManager();
+ configurationManager.addContainerProvider(new ConfigurationProvider() {
+ public void destroy() {
+ throw new RuntimeException("testing testing 123");
+ }
+ public void init(Configuration configuration) throws ConfigurationException {
+ }
+ public void loadPackages() throws ConfigurationException {
+ }
+ public boolean needsReload() { return false;
+ }
+ public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
+ }
+ public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
+ }
+ });
+ configurationManager.addContainerProvider(new ConfigurationProvider() {
+ public void destroy() {
+ state.isDestroyed1 = true;
+ }
+ public void init(Configuration configuration) throws ConfigurationException {
+ }
+ public void loadPackages() throws ConfigurationException {
+ }
+ public boolean needsReload() { return false;
+ }
+ public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
+ }
+ public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
+ }
+ });
+ configurationManager.addContainerProvider(new ConfigurationProvider() {
+ public void destroy() {
+ throw new RuntimeException("testing testing 123");
+ }
+ public void init(Configuration configuration) throws ConfigurationException {
+ }
+ public void loadPackages() throws ConfigurationException {
+ }
+ public boolean needsReload() { return false;
+ }
+ public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
+ }
+ public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
+ }
+ });
+ configurationManager.addContainerProvider(new ConfigurationProvider() {
+ public void destroy() {
+ state.isDestroyed2 = true;
+ }
+ public void init(Configuration configuration) throws ConfigurationException {
+ }
+ public void loadPackages() throws ConfigurationException {
+ }
+ public boolean needsReload() { return false;
+ }
+ public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
+ }
+ public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
+ }
+ });
+
+ assertFalse(state.isDestroyed1);
+ assertFalse(state.isDestroyed2);
+
+ configurationManager.clearContainerProviders();
+
+ assertTrue(state.isDestroyed1);
+ assertTrue(state.isDestroyed2);
+ }
+
+ public void testClearConfigurationProviders() throws Exception {
+ configProviderMock.expect("destroy");
+ configurationManager.clearContainerProviders();
+ configProviderMock.verify();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ configurationManager.destroyConfiguration();
+
+ configProviderMock = new Mock(ConfigurationProvider.class);
+ configProviderMock.matchAndReturn("equals", C.ANY_ARGS, false);
+
+ ConfigurationProvider mockProvider = (ConfigurationProvider) configProviderMock.proxy();
+ configurationManager.addContainerProvider(new XWorkConfigurationProvider());
+ configurationManager.addContainerProvider(mockProvider);
+
+ //the first time it always inits
+ configProviderMock.expect("init", C.isA(Configuration.class));
+ configProviderMock.expect("register", C.ANY_ARGS);
+ configProviderMock.expect("loadPackages", C.ANY_ARGS);
+ configProviderMock.matchAndReturn("toString", "mock");
+
+ configurationManager.getConfiguration();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ configProviderMock.expect("destroy");
+ FileManager.setReloadingConfigs(true);
+ super.tearDown();
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/ConfigurationTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/ConfigurationTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/ConfigurationTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/ConfigurationTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,322 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.config;
+
+import com.mockobjects.dynamic.C;
+import com.mockobjects.dynamic.Mock;
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.ActionProxy;
+import org.apache.struts2.xwork2.SimpleAction;
+import org.apache.struts2.xwork2.XWorkTestCase;
+import org.apache.struts2.xwork2.config.entities.ActionConfig;
+import org.apache.struts2.xwork2.config.entities.InterceptorMapping;
+import org.apache.struts2.xwork2.config.providers.MockConfigurationProvider;
+import org.apache.struts2.xwork2.config.providers.XmlConfigurationProvider;
+import org.apache.struts2.xwork2.inject.ContainerBuilder;
+import org.apache.struts2.xwork2.mock.MockInterceptor;
+import org.apache.struts2.xwork2.test.StubConfigurationProvider;
+import org.apache.struts2.xwork2.util.location.LocatableProperties;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * ConfigurationTest
+ * <p/>
+ * Created : Jan 27, 2003 1:30:08 AM
+ *
+ * @author Jason Carreira
+ */
+public class ConfigurationTest extends XWorkTestCase {
+
+ public void testAbstract() {
+ try {
+ actionProxyFactory.createActionProxy("/abstract", "test", null);
+ fail();
+ } catch (Exception e) {
+ // this is what we expected
+ }
+
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("/nonAbstract", "test", null);
+ assertTrue(proxy.getActionName().equals("test"));
+ assertTrue(proxy.getConfig().getClassName().equals(SimpleAction.class.getName()));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testDefaultNamespace() {
+ HashMap<String, String> params = new HashMap<String, String>();
+ params.put("blah", "this is blah");
+
+ HashMap<String, Object> extraContext = new HashMap<String, Object>();
+ extraContext.put(ActionContext.PARAMETERS, params);
+
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("/does/not/exist", "Foo", extraContext);
+ proxy.execute();
+ assertEquals("this is blah", proxy.getInvocation().getStack().findValue("[1].blah"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testFileIncludeLoader() {
+ RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
+
+ // check entityTest package
+ assertNotNull(configuration.getActionConfig("includeTest", "includeTest"));
+
+ // check inheritance from Default
+ assertNotNull(configuration.getActionConfig("includeTest", "Foo"));
+ }
+
+ public void testWildcardName() {
+ RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
+
+ ActionConfig config = configuration.getActionConfig("", "WildCard/Simple/input");
+
+ assertNotNull(config);
+ assertTrue("Wrong class name, "+config.getClassName(),
+ "org.apache.struts2.xwork2.SimpleAction".equals(config.getClassName()));
+ assertTrue("Wrong method name", "input".equals(config.getMethodName()));
+
+ Map<String, String> p = config.getParams();
+ assertTrue("Wrong parameter, "+p.get("foo"), "Simple".equals(p.get("foo")));
+ assertTrue("Wrong parameter, "+p.get("bar"), "input".equals(p.get("bar")));
+ }
+
+ public void testWildcardNamespace() {
+ RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
+
+ ActionConfig config = configuration.getActionConfig("/animals/dog", "commandTest");
+
+ assertNotNull(config);
+ assertTrue("Wrong class name, "+config.getClassName(),
+ "org.apache.struts2.xwork2.SimpleAction".equals(config.getClassName()));
+
+ Map<String, String> p = config.getParams();
+ assertTrue("Wrong parameter, "+p.get("0"), "/animals/dog".equals(p.get("0")));
+ assertTrue("Wrong parameter, "+p.get("1"), "dog".equals(p.get("1")));
+ }
+
+ public void testGlobalResults() {
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("", "Foo", null);
+ assertNotNull(proxy.getConfig().getResults().get("login"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testInterceptorParamInehritanceOverride() {
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("/foo/bar", "TestInterceptorParamInehritanceOverride", null);
+ assertEquals(1, proxy.getConfig().getInterceptors().size());
+
+ MockInterceptor testInterceptor = (MockInterceptor) ((InterceptorMapping) proxy.getConfig().getInterceptors().get(0)).getInterceptor();
+ assertEquals("foo123", testInterceptor.getExpectedFoo());
+ proxy.execute();
+ assertTrue(testInterceptor.isExecuted());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testInterceptorParamInheritance() {
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("/foo/bar", "TestInterceptorParamInheritance", null);
+ assertEquals(1, proxy.getConfig().getInterceptors().size());
+
+ MockInterceptor testInterceptor = (MockInterceptor) ((InterceptorMapping) proxy.getConfig().getInterceptors().get(0)).getInterceptor();
+ assertEquals("expectedFoo", testInterceptor.getExpectedFoo());
+ proxy.execute();
+ assertTrue(testInterceptor.isExecuted());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testInterceptorParamOverride() {
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("", "TestInterceptorParamOverride", null);
+ assertEquals(1, proxy.getConfig().getInterceptors().size());
+
+ MockInterceptor testInterceptor = (MockInterceptor) ((InterceptorMapping) proxy.getConfig().getInterceptors().get(0)).getInterceptor();
+ assertEquals("foo123", testInterceptor.getExpectedFoo());
+ proxy.execute();
+ assertTrue(testInterceptor.isExecuted());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testInterceptorParams() {
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("", "TestInterceptorParam", null);
+ assertEquals(1, proxy.getConfig().getInterceptors().size());
+
+ MockInterceptor testInterceptor = (MockInterceptor) ((InterceptorMapping) proxy.getConfig().getInterceptors().get(0)).getInterceptor();
+ assertEquals("expectedFoo", testInterceptor.getExpectedFoo());
+ proxy.execute();
+ assertTrue(testInterceptor.isExecuted());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testMultipleConfigProviders() {
+ configurationManager.addContainerProvider(new MockConfigurationProvider());
+
+ try {
+ configurationManager.reload();
+ } catch (ConfigurationException e) {
+ e.printStackTrace();
+ fail();
+ }
+
+ RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
+
+ // check that it has configuration from xml
+ assertNotNull(configuration.getActionConfig("/foo/bar", "Bar"));
+
+ // check that it has configuration from MockConfigurationProvider
+ assertNotNull(configuration.getActionConfig("", MockConfigurationProvider.FOO_ACTION_NAME));
+ }
+
+ public void testMultipleContainerProviders() throws Exception {
+ System.out.println("-----");
+ Mock mockContainerProvider = new Mock(ContainerProvider.class);
+ mockContainerProvider.expect("init", C.ANY_ARGS);
+ mockContainerProvider.expect("register", C.ANY_ARGS);
+ mockContainerProvider.matchAndReturn("equals", C.ANY_ARGS, false);
+ mockContainerProvider.matchAndReturn("toString", "foo");
+ mockContainerProvider.matchAndReturn("destroy", null);
+ mockContainerProvider.expectAndReturn("needsReload", true);
+ configurationManager.addContainerProvider((ContainerProvider) mockContainerProvider.proxy());
+
+ Configuration config = null;
+ try {
+ config = configurationManager.getConfiguration();
+ } catch (ConfigurationException e) {
+ e.printStackTrace();
+ fail();
+ }
+
+
+ RuntimeConfiguration configuration = config.getRuntimeConfiguration();
+
+ // check that it has configuration from xml
+ assertNotNull(configuration.getActionConfig("/foo/bar", "Bar"));
+
+ System.out.println("-----");
+ mockContainerProvider.verify();
+ }
+
+ public void testInitForPackageProviders() {
+
+ loadConfigurationProviders(new StubConfigurationProvider() {
+ @Override
+ public void register(ContainerBuilder builder,
+ LocatableProperties props) throws ConfigurationException {
+ builder.factory(PackageProvider.class, "foo", MyPackageProvider.class);
+ }
+ });
+
+ assertEquals(configuration, MyPackageProvider.getConfiguration());
+ }
+
+ public void testInitOnceForConfigurationProviders() {
+
+ loadConfigurationProviders(new StubConfigurationProvider() {
+ boolean called = false;
+ @Override
+ public void init(Configuration config) {
+ if (called) {
+ fail("Called twice");
+ }
+ called = true;
+ }
+
+ @Override
+ public void loadPackages() {
+ if (!called) {
+ fail("Never called");
+ }
+ }
+ });
+ }
+
+ public void testMultipleInheritance() {
+ try {
+ ActionProxy proxy;
+ proxy = actionProxyFactory.createActionProxy("multipleInheritance", "test", null);
+ assertNotNull(proxy);
+ proxy = actionProxyFactory.createActionProxy("multipleInheritance", "Foo", null);
+ assertNotNull(proxy);
+ proxy = actionProxyFactory.createActionProxy("multipleInheritance", "testMultipleInheritance", null);
+ assertNotNull(proxy);
+ assertEquals(5, proxy.getConfig().getInterceptors().size());
+ assertEquals(2, proxy.getConfig().getResults().size());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testPackageExtension() {
+ try {
+ ActionProxy proxy = actionProxyFactory.createActionProxy("/foo/bar", "Bar", null);
+ assertEquals(5, proxy.getConfig().getInterceptors().size());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+
+ @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 static class MyPackageProvider implements PackageProvider {
+ static Configuration config;
+ public void loadPackages() throws ConfigurationException {}
+ public boolean needsReload() { return config != null; }
+
+ public static Configuration getConfiguration() {
+ return config;
+ }
+ public void init(Configuration configuration)
+ throws ConfigurationException {
+ config = configuration;
+ }
+
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/entities/ActionConfigTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/entities/ActionConfigTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/entities/ActionConfigTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/entities/ActionConfigTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.config.entities;
+
+import org.apache.struts2.xwork2.XWorkTestCase;
+import org.apache.struts2.xwork2.util.location.LocationImpl;
+
+/**
+ * ActionConfigTest
+ */
+public class ActionConfigTest extends XWorkTestCase {
+
+ public void testToString() {
+ ActionConfig cfg = new ActionConfig.Builder("", "bob", "foo.Bar")
+ .methodName("execute")
+ .location(new LocationImpl(null, "foo/xwork.xml", 10, 12))
+ .build();
+
+ assertTrue("Wrong toString(): "+cfg.toString(),
+ "{ActionConfig bob (foo.Bar.execute()) - foo/xwork.xml:10:12}".equals(cfg.toString()));
+ }
+
+ public void testToStringWithNoMethod() {
+ ActionConfig cfg = new ActionConfig.Builder("", "bob", "foo.Bar")
+ .location(new LocationImpl(null, "foo/xwork.xml", 10, 12))
+ .build();
+
+ assertTrue("Wrong toString(): "+cfg.toString(),
+ "{ActionConfig bob (foo.Bar) - foo/xwork.xml:10:12}".equals(cfg.toString()));
+ }
+}
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/entities/PackageConfigTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/entities/PackageConfigTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/entities/PackageConfigTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/entities/PackageConfigTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2002-2003,2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.config.entities;
+
+import org.apache.struts2.xwork2.XWorkTestCase;
+
+public class PackageConfigTest extends XWorkTestCase {
+
+ public void testFullDefaultInterceptorRef() {
+ PackageConfig cfg1 = new PackageConfig.Builder("pkg1")
+ .defaultInterceptorRef("ref1").build();
+ PackageConfig cfg2 = new PackageConfig.Builder("pkg2").defaultInterceptorRef("ref2").build();
+ PackageConfig cfg = new PackageConfig.Builder("pkg")
+ .addParent(cfg1)
+ .addParent(cfg2)
+ .build();
+
+ assertEquals("ref2", cfg.getFullDefaultInterceptorRef());
+ }
+
+}
\ No newline at end of file
Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/impl/ActionConfigMatcherTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/impl/ActionConfigMatcherTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/impl/ActionConfigMatcherTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/config/impl/ActionConfigMatcherTest.java Fri Dec 2 16:33:03 2011
@@ -0,0 +1,164 @@
+/*
+ * $Id: ActionConfigMatcherTest.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ *
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.config.impl;
+
+import org.apache.struts2.xwork2.XWorkTestCase;
+import org.apache.struts2.xwork2.config.entities.ActionConfig;
+import org.apache.struts2.xwork2.config.entities.ExceptionMappingConfig;
+import org.apache.struts2.xwork2.config.entities.InterceptorMapping;
+import org.apache.struts2.xwork2.config.entities.ResultConfig;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ActionConfigMatcherTest extends XWorkTestCase {
+
+ // ----------------------------------------------------- Instance Variables
+ private Map<String,ActionConfig> configMap;
+ private ActionConfigMatcher matcher;
+
+ // ----------------------------------------------------- Setup and Teardown
+ @Override public void setUp() throws Exception {
+ super.setUp();
+ configMap = buildActionConfigMap();
+ matcher = new ActionConfigMatcher(configMap);
+ }
+
+ @Override public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // ------------------------------------------------------- Individual Tests
+ // ---------------------------------------------------------- match()
+ public void testNoMatch() {
+ assertNull("ActionConfig shouldn't be matched", matcher.match("test"));
+ }
+
+ public void testNoWildcardMatch() {
+ assertNull("ActionConfig shouldn't be matched", matcher.match("noWildcard"));
+ }
+
+ public void testShouldMatch() {
+ ActionConfig matched = matcher.match("foo/class/method");
+
+ assertNotNull("ActionConfig should be matched", matched);
+ assertTrue("ActionConfig should have properties, had " +
+ matched.getParams().size(), matched.getParams().size() == 2);
+ assertTrue("ActionConfig should have interceptors",
+ matched.getInterceptors().size() == 1);
+ assertTrue("ActionConfig should have ex mappings",
+ matched.getExceptionMappings().size() == 1);
+ assertTrue("ActionConfig should have external refs",
+ matched.getExceptionMappings().size() == 1);
+ assertTrue("ActionConfig should have results",
+ matched.getResults().size() == 1);
+ }
+
+ public void testCheckSubstitutionsMatch() {
+ ActionConfig m = matcher.match("foo/class/method");
+
+ assertTrue("Class hasn't been replaced", "foo.bar.classAction".equals(m.getClassName()));
+ assertTrue("Method hasn't been replaced", "domethod".equals(m.getMethodName()));
+ assertTrue("Package isn't correct", "package-class".equals(m.getPackageName()));
+
+ assertTrue("First param isn't correct", "class".equals(m.getParams().get("first")));
+ assertTrue("Second param isn't correct", "method".equals(m.getParams().get("second")));
+
+ ExceptionMappingConfig ex = m.getExceptionMappings().get(0);
+ assertTrue("Wrong name, was "+ex.getName(), "fooclass".equals(ex.getName()));
+ assertTrue("Wrong result", "successclass".equals(ex.getResult()));
+ assertTrue("Wrong exception",
+ "java.lang.methodException".equals(ex.getExceptionClassName()));
+ assertTrue("First param isn't correct", "class".equals(ex.getParams().get("first")));
+ assertTrue("Second param isn't correct", "method".equals(ex.getParams().get("second")));
+
+ ResultConfig result = m.getResults().get("successclass");
+ assertTrue("Wrong name, was "+result.getName(), "successclass".equals(result.getName()));
+ assertTrue("Wrong classname", "foo.method".equals(result.getClassName()));
+ assertTrue("First param isn't correct", "class".equals(result.getParams().get("first")));
+ assertTrue("Second param isn't correct", "method".equals(result.getParams().get("second")));
+
+ }
+
+ public void testCheckMultipleSubstitutions() {
+ ActionConfig m = matcher.match("bar/class/method/more");
+
+ assertTrue("Method hasn't been replaced correctly: " + m.getMethodName(),
+ "doclass_class".equals(m.getMethodName()));
+ }
+
+ public void testLooseMatch() {
+ configMap.put("*!*", configMap.get("bar/*/**"));
+ ActionConfigMatcher matcher = new ActionConfigMatcher(configMap, true);
+
+ // exact match
+ ActionConfig m = matcher.match("foo/class/method");
+ assertNotNull("ActionConfig should be matched", m);
+ assertTrue("Class hasn't been replaced "+m.getClassName(), "foo.bar.classAction".equals(m.getClassName()));
+ assertTrue("Method hasn't been replaced", "domethod".equals(m.getMethodName()));
+
+ // Missing last wildcard
+ m = matcher.match("foo/class");
+ assertNotNull("ActionConfig should be matched", m);
+ assertTrue("Class hasn't been replaced", "foo.bar.classAction".equals(m.getClassName()));
+ assertTrue("Method hasn't been replaced, "+m.getMethodName(), "do".equals(m.getMethodName()));
+
+ // Simple mapping
+ m = matcher.match("class!method");
+ assertNotNull("ActionConfig should be matched", m);
+ assertTrue("Class hasn't been replaced, "+m.getPackageName(), "package-class".equals(m.getPackageName()));
+ assertTrue("Method hasn't been replaced", "method".equals(m.getParams().get("first")));
+
+ // Simple mapping
+ m = matcher.match("class");
+ assertNotNull("ActionConfig should be matched", m);
+ assertTrue("Class hasn't been replaced", "package-class".equals(m.getPackageName()));
+ assertTrue("Method hasn't been replaced", "".equals(m.getParams().get("first")));
+
+ }
+
+ private Map<String,ActionConfig> buildActionConfigMap() {
+ Map<String, ActionConfig> map = new HashMap<String,ActionConfig>();
+
+ HashMap params = new HashMap();
+ params.put("first", "{1}");
+ params.put("second", "{2}");
+
+ ActionConfig config = new ActionConfig.Builder("package-{1}", "foo/*/*", "foo.bar.{1}Action")
+ .methodName("do{2}")
+ .addParams(params)
+ .addExceptionMapping(new ExceptionMappingConfig.Builder("foo{1}", "java.lang.{2}Exception", "success{1}")
+ .addParams(new HashMap(params))
+ .build())
+ .addInterceptor(new InterceptorMapping(null, null))
+ .addResultConfig(new ResultConfig.Builder("success{1}", "foo.{2}").addParams(params).build())
+ .build();
+ map.put("foo/*/*", config);
+
+ config = new ActionConfig.Builder("package-{1}", "bar/*/**", "bar")
+ .methodName("do{1}_{1}")
+ .addParam("first", "{2}")
+ .build();
+
+ map.put("bar/*/**", config);
+
+ map.put("noWildcard", new ActionConfig.Builder("", "", "").build());
+
+ return map;
+ }
+}