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 [41/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/interceptor/AliasInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/AliasInterceptorTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/AliasInterceptorTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/AliasInterceptorTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,136 @@
+/*
+ * 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.interceptor;
+
+import org.apache.struts2.xwork2.Action;
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.ActionProxy;
+import org.apache.struts2.xwork2.config.entities.ActionConfig;
+import org.apache.struts2.xwork2.config.providers.XmlConfigurationProvider;
+import org.apache.struts2.xwork2.mock.MockActionInvocation;
+import org.apache.struts2.xwork2.mock.MockActionProxy;
+import org.apache.struts2.xwork2.XWorkTestCase;
+import org.apache.struts2.xwork2.SimpleAction;
+import org.apache.struts2.xwork2.SimpleFooAction;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * AliasInterceptorTest
+ *
+ * Test of aliasInterceptor specifically depends on actionTest test defined in /test/xwork.xml
+ * stack.getContext().putAll(params);
+ * <p/>
+ * e.g.
+ * <action name="aliasTest" class="org.apache.struts2.xwork2.SimpleAction">
+ *    <param name="aliases">#{ "aliasSource" : "aliasDest", "bar":"baz" }</param>
+ *    <interceptor-ref name="defaultStack"/>
+ *    <interceptor-ref name="alias"/>
+ * </action>
+ *
+ * @author Matthew Payne
+ */
+public class AliasInterceptorTest extends XWorkTestCase {
+
+    public void testUsingDefaultInterceptorThatAliasPropertiesAreCopied() throws Exception {
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("aliasSource", "source here");
+
+        loadConfigurationProviders(new XmlConfigurationProvider("xwork-sample.xml"));
+        ActionProxy proxy = actionProxyFactory.createActionProxy("", "aliasTest", params);
+        SimpleAction actionOne = (SimpleAction) proxy.getAction();
+        actionOne.setAliasSource("name to be copied");
+        actionOne.setFoo(17);
+        actionOne.setBar(23);
+        proxy.execute();
+        assertEquals(actionOne.getAliasSource(), actionOne.getAliasDest());
+    }
+
+    public void testInvalidAliasExpression() throws Exception {
+        Action action = new SimpleFooAction();
+        MockActionInvocation mai = new MockActionInvocation();
+
+        MockActionProxy map = new MockActionProxy();
+
+        ActionConfig cfg = new ActionConfig.Builder("", "", "")
+                .addParam("aliases", "invalid alias expression")
+                .build();
+        map.setConfig(cfg);
+
+        mai.setProxy(map);
+        mai.setAction(action);
+        mai.setInvocationContext(ActionContext.getContext());
+
+        AliasInterceptor ai = new AliasInterceptor();
+        ai.init();
+
+        ai.intercept(mai);
+
+        ai.destroy();
+    }
+
+    public void testSetAliasKeys() throws Exception {
+        Action action = new SimpleFooAction();
+        MockActionInvocation mai = new MockActionInvocation();
+
+        MockActionProxy map = new MockActionProxy();
+
+        ActionConfig cfg = new ActionConfig.Builder("", "", "")
+                .addParam("hello", "invalid alias expression")
+                .build();
+        map.setConfig(cfg);
+
+        mai.setProxy(map);
+        mai.setAction(action);
+        mai.setInvocationContext(ActionContext.getContext());
+
+        AliasInterceptor ai = new AliasInterceptor();
+        ai.init();
+        ai.setAliasesKey("hello");
+
+        ai.intercept(mai);
+
+        ai.destroy();
+    }
+
+    public void testSetInvalidAliasKeys() throws Exception {
+        Action action = new SimpleFooAction();
+        MockActionInvocation mai = new MockActionInvocation();
+
+        MockActionProxy map = new MockActionProxy();
+
+        ActionConfig cfg = new ActionConfig.Builder("", "", "")
+                .addParam("hello", "invalid alias expression")
+                .build();
+        map.setConfig(cfg);
+
+        mai.setProxy(map);
+        mai.setAction(action);
+        mai.setInvocationContext(ActionContext.getContext());
+
+        AliasInterceptor ai = new AliasInterceptor();
+        ai.init();
+        ai.setAliasesKey("iamnotinconfig");
+
+        ai.intercept(mai);
+
+        ai.destroy();
+    }
+
+}
+

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ChainingInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ChainingInterceptorTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ChainingInterceptorTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ChainingInterceptorTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,174 @@
+/*
+ * 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.interceptor;
+
+import com.mockobjects.dynamic.Mock;
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.util.ValueStack;
+import org.apache.struts2.xwork2.Action;
+import org.apache.struts2.xwork2.ActionChainResult;
+import org.apache.struts2.xwork2.ActionInvocation;
+import org.apache.struts2.xwork2.XWorkTestCase;
+import org.apache.struts2.xwork2.SimpleAction;
+import org.apache.struts2.xwork2.TestBean;
+
+import java.util.*;
+
+
+/**
+ * Unit test for {@link ChainingInterceptor}.
+ *
+ * @author Jason Carreira
+ */
+public class ChainingInterceptorTest extends XWorkTestCase {
+
+    ActionInvocation invocation;
+    ChainingInterceptor interceptor;
+    Mock mockInvocation;
+    ValueStack stack;
+
+
+    public void testActionErrorsCanBeAddedAfterChain() throws Exception {
+        SimpleAction action1 = new SimpleAction();
+        SimpleAction action2 = new SimpleAction();
+        action1.addActionError("foo");
+        mockInvocation.matchAndReturn("getAction", action2);
+        stack.push(action1);
+        stack.push(action2);
+        interceptor.setCopyErrors("true");
+        interceptor.setCopyMessages("true");
+
+        interceptor.intercept(invocation);
+
+        assertEquals(action1.getActionErrors(), action2.getActionErrors());
+        action2.addActionError("bar");
+        assertEquals(1, action1.getActionErrors().size());
+        assertEquals(2, action2.getActionErrors().size());
+        assertTrue(action2.getActionErrors().contains("bar"));
+    }
+
+    public void testActionErrorsNotCopiedAfterChain() throws Exception {
+        SimpleAction action1 = new SimpleAction();
+        SimpleAction action2 = new SimpleAction();
+        action1.addActionError("foo");
+        mockInvocation.matchAndReturn("getAction", action2);
+        stack.push(action1);
+        stack.push(action2);
+
+        interceptor.intercept(invocation);
+
+        assertEquals(Collections.EMPTY_LIST, action2.getActionErrors());
+        action2.addActionError("bar");
+        assertEquals(1, action1.getActionErrors().size());
+        assertEquals(1, action2.getActionErrors().size());
+        assertTrue(action2.getActionErrors().contains("bar"));
+        assertFalse(action2.getActionErrors().contains("foo"));
+    }
+
+    public void testPropertiesChained() throws Exception {
+        TestBean bean = new TestBean();
+        TestBeanAction action = new TestBeanAction();
+        mockInvocation.matchAndReturn("getAction", action);
+        bean.setBirth(new Date());
+        bean.setName("foo");
+        bean.setCount(1);
+        stack.push(bean);
+        stack.push(action);
+        interceptor.setCopyErrors("true");
+        interceptor.setCopyMessages("true");
+
+        interceptor.intercept(invocation);
+
+        assertEquals(bean.getBirth(), action.getBirth());
+        assertEquals(bean.getName(), action.getName());
+        assertEquals(bean.getCount(), action.getCount());
+    }
+
+    public void testExcludesPropertiesChained() throws Exception {
+        TestBean bean = new TestBean();
+        TestBeanAction action = new TestBeanAction();
+        mockInvocation.matchAndReturn("getAction", action);
+        bean.setBirth(new Date());
+        bean.setName("foo");
+        bean.setCount(1);
+        stack.push(bean);
+        stack.push(action);
+        interceptor.setCopyErrors("true");
+        interceptor.setCopyMessages("true");
+
+        Collection excludes = new ArrayList();
+        excludes.add("count");
+        interceptor.setExcludes(excludes);
+
+        interceptor.intercept(invocation);
+
+        assertEquals(bean.getBirth(), action.getBirth());
+        assertEquals(bean.getName(), action.getName());
+        assertEquals(0, action.getCount());
+        assertEquals(excludes, interceptor.getExcludes());
+    }
+
+    public void testTwoExcludesPropertiesChained() throws Exception {
+        TestBean bean = new TestBean();
+        TestBeanAction action = new TestBeanAction();
+        mockInvocation.matchAndReturn("getAction", action);
+        bean.setBirth(new Date());
+        bean.setName("foo");
+        bean.setCount(1);
+        stack.push(bean);
+        stack.push(action);
+
+        Collection excludes = new ArrayList();
+        excludes.add("name");
+        excludes.add("count");
+        interceptor.setExcludes(excludes);
+        interceptor.intercept(invocation);
+        assertEquals(bean.getBirth(), action.getBirth());
+        assertEquals(null, action.getName());
+        assertEquals(0, action.getCount());
+        assertEquals(excludes, interceptor.getExcludes());
+    }
+
+    public void testNullCompoundRootElementAllowsProcessToContinue() throws Exception {
+        // we should not get NPE, but instead get a warning logged.
+        stack.push(null);
+        stack.push(null);
+        stack.push(null);
+        interceptor.intercept(invocation);
+    }
+
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        stack = ActionContext.getContext().getValueStack();
+        mockInvocation = new Mock(ActionInvocation.class);
+        mockInvocation.expectAndReturn("getStack", stack);
+        mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
+        mockInvocation.expectAndReturn("getInvocationContext", new ActionContext(new HashMap()));
+        mockInvocation.expectAndReturn("getResult", new ActionChainResult());
+        invocation = (ActionInvocation) mockInvocation.proxy();
+        interceptor = new ChainingInterceptor();
+        container.inject(interceptor);
+    }
+
+
+    private class TestBeanAction extends TestBean 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/interceptor/ConversionErrorInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ConversionErrorInterceptorTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ConversionErrorInterceptorTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ConversionErrorInterceptorTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,152 @@
+/*
+ * 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.interceptor;
+
+import com.mockobjects.dynamic.C;
+import com.mockobjects.dynamic.Mock;
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.ActionSupport;
+import org.apache.struts2.xwork2.mock.MockActionInvocation;
+import org.apache.struts2.xwork2.util.ValueStack;
+import org.apache.struts2.xwork2.Action;
+import org.apache.struts2.xwork2.ActionInvocation;
+import org.apache.struts2.xwork2.XWorkTestCase;
+import org.apache.struts2.xwork2.SimpleAction;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Unit test for {@link ConversionErrorInterceptor}.
+ *
+ * @author Jason Carreira
+ */
+public class ConversionErrorInterceptorTest extends XWorkTestCase {
+
+    protected ActionContext context;
+    protected ActionInvocation invocation;
+    protected ConversionErrorInterceptor interceptor;
+    protected Map<String, Object> conversionErrors;
+    protected Mock mockInvocation;
+    protected ValueStack stack;
+
+
+    public void testFieldErrorAdded() throws Exception {
+        conversionErrors.put("foo", 123L);
+
+        SimpleAction action = new SimpleAction();
+        mockInvocation.expectAndReturn("getAction", action);
+        stack.push(action);
+        mockInvocation.matchAndReturn("getAction", action);
+        assertNull(action.getFieldErrors().get("foo"));
+        interceptor.intercept(invocation);
+        assertTrue(action.hasFieldErrors());
+        assertNotNull(action.getFieldErrors().get("foo"));
+    }
+
+    public void testFieldErrorWithMapKeyAdded() throws Exception {
+        String fieldName = "foo['1'].intValue";
+        conversionErrors.put(fieldName, "bar");
+        ActionSupport action = new ActionSupport();
+        mockInvocation.expectAndReturn("getAction", action);
+        stack.push(action);
+        mockInvocation.matchAndReturn("getAction", action);
+        assertNull(action.getFieldErrors().get(fieldName));
+        interceptor.intercept(invocation);
+        assertTrue(action.hasFieldErrors()); // This fails!
+        assertNotNull(action.getFieldErrors().get(fieldName));
+    }
+
+    public void testWithPreResultListener() throws Exception {
+        conversionErrors.put("foo", "Hello");
+
+        ActionContext ac = createActionContext();
+        MockActionInvocation mai = createActionInvocation(ac);
+        SimpleAction action = createAction(mai);
+
+        assertNull(action.getFieldErrors().get("foo"));
+        assertEquals(55, stack.findValue("foo"));
+
+        interceptor.intercept(mai);
+
+        assertTrue(action.hasFieldErrors());
+        assertNotNull(action.getFieldErrors().get("foo"));
+
+        assertEquals("Hello", stack.findValue("foo")); // assume that the original value is reset
+    }
+
+    /**
+     * See WW-3668
+     *
+     * @throws Exception
+     */
+    public void testWithPreResultListenerAgainstMaliciousCode() throws Exception {
+        conversionErrors.put("foo", "\" + #root + \"");
+
+        ActionContext ac = createActionContext();
+
+        MockActionInvocation mai = createActionInvocation(ac);
+
+        SimpleAction action = createAction(mai);
+        assertNull(action.getFieldErrors().get("foo"));
+        assertEquals(55, stack.findValue("foo"));
+
+        interceptor.intercept(mai);
+
+        assertTrue(action.hasFieldErrors());
+        assertNotNull(action.getFieldErrors().get("foo"));
+
+        assertEquals("\" + #root + \"", stack.findValue("foo"));
+    }
+
+    private MockActionInvocation createActionInvocation(ActionContext ac) {
+        MockActionInvocation mai = new MockActionInvocation();
+        mai.setInvocationContext(ac);
+        mai.setStack(stack);
+        return mai;
+    }
+
+    private SimpleAction createAction(MockActionInvocation mai) {
+        SimpleAction action = new SimpleAction();
+        action.setFoo(55);
+        mai.setAction(action);
+        stack.push(action);
+        return action;
+    }
+
+    private ActionContext createActionContext() {
+        ActionContext ac = new ActionContext(stack.getContext());
+        ac.setConversionErrors(conversionErrors);
+        ac.setValueStack(stack);
+        return ac;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        interceptor = new ConversionErrorInterceptor();
+        mockInvocation = new Mock(ActionInvocation.class);
+        invocation = (ActionInvocation) mockInvocation.proxy();
+        stack = ActionContext.getContext().getValueStack();
+        context = new ActionContext(stack.getContext());
+        conversionErrors = new HashMap<String, Object>();
+        context.setConversionErrors(conversionErrors);
+        mockInvocation.matchAndReturn("getInvocationContext", context);
+        mockInvocation.expect("addPreResultListener", C.isA(PreResultListener.class));
+        mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/DefaultWorkflowInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/DefaultWorkflowInterceptorTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/DefaultWorkflowInterceptorTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/DefaultWorkflowInterceptorTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,222 @@
+/*
+ * 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.interceptor;
+
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.config.entities.InterceptorConfig;
+import org.apache.struts2.xwork2.Action;
+import org.apache.struts2.xwork2.ActionInvocation;
+import org.apache.struts2.xwork2.ActionProxy;
+import org.apache.struts2.xwork2.ObjectFactory;
+import org.apache.struts2.xwork2.ValidationAware;
+import org.apache.struts2.xwork2.config.entities.ActionConfig;
+import org.apache.struts2.xwork2.validator.ValidationInterceptor;
+
+import java.util.HashMap;
+
+import org.apache.struts2.xwork2.Validateable;
+import org.apache.struts2.xwork2.XWorkTestCase;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+
+/**
+ * Unit test for {@link DefaultWorkflowInterceptor}.
+ *
+ * @author Jason Carreira
+ */
+public class DefaultWorkflowInterceptorTest extends XWorkTestCase {
+
+    DefaultWorkflowInterceptor interceptor;
+    private ActionInvocation invocation;
+    private Action action;
+    private ActionProxy proxy;
+    private ActionConfig config;
+    private String result = "testing123";
+
+
+    public void testInvokesActionInvocationIfNoErrors() throws Exception {
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.intercept(invocation);
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+    public void testReturnsInputWithoutExecutingIfHasErrors() throws Exception {
+        result = Action.INPUT;
+
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.intercept(invocation);
+        assertEquals(Action.INPUT, interceptor.intercept(invocation));
+    }
+
+    public void testExcludesMethod() throws Exception {
+        interceptor.setExcludeMethods("execute");
+
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.setExcludeMethods("execute");
+        interceptor.setExcludeMethods("execute");
+        validationInterceptor.intercept(invocation);
+        
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+    public void testExcludesMethodWithWildCard() throws Exception {
+        interceptor.setExcludeMethods("*");
+
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.intercept(invocation);
+        validationInterceptor.setExcludeMethods("*");
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+    public void testIncludesMethodWithWildcard() throws Exception {
+        interceptor.setIncludeMethods("*");
+
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.setIncludeMethods("*");
+        validationInterceptor.intercept(invocation);
+        
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+
+    public void testIncludesMethod() throws Exception {
+        interceptor.setIncludeMethods("execute");
+
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.setIncludeMethods("execute");
+        validationInterceptor.intercept(invocation);
+        
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+    public void testIncludesAndExcludesMethod() throws Exception {
+        interceptor.setExcludeMethods("execute,input,validate");
+        interceptor.setIncludeMethods("execute");
+        
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.setExcludeMethods("execute,input,validate");
+        validationInterceptor.setIncludeMethods("execute");
+        validationInterceptor.intercept(invocation);
+        
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+    public void testIncludesAndExcludesMethodAllWildCarded() throws Exception {
+        interceptor.setExcludeMethods("*");
+        interceptor.setIncludeMethods("*");
+        
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.setExcludeMethods("*");
+        validationInterceptor.setIncludeMethods("*");
+        validationInterceptor.intercept(invocation);
+        
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+    public void testIncludesAndExcludesMethodWithExcludeWildcard() throws Exception {
+        interceptor.setExcludeMethods("*");
+        interceptor.setIncludeMethods("execute");
+        
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.setExcludeMethods("*");
+        validationInterceptor.setIncludeMethods("execute");
+        validationInterceptor.intercept(invocation);
+        
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+    public void testIncludesAndExcludesMethodWithIncludeWildcardAndNoMatches() throws Exception {
+        interceptor.setExcludeMethods("execute,input,validate");
+        interceptor.setIncludeMethods("*");
+        
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.setExcludeMethods("execute,input,validate");
+        validationInterceptor.setIncludeMethods("*");
+        validationInterceptor.intercept(invocation);
+        
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+    public void testIncludesAndExcludesMethodWithIncludeWildcard() throws Exception {
+        interceptor.setExcludeMethods("input,validate");
+        interceptor.setIncludeMethods("*");
+        
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.setExcludeMethods("input,validate");
+        validationInterceptor.setIncludeMethods("*");
+        validationInterceptor.intercept(invocation);
+        
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+
+    public void testNoValidateAction() throws Exception {
+        ValidationInterceptor validationInterceptor = create();
+        validationInterceptor.setExcludeMethods("execute,input,validate");
+        validationInterceptor.setIncludeMethods("execute");
+        validationInterceptor.intercept(invocation);
+        
+        assertEquals(result, interceptor.intercept(invocation));
+    }
+    
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        config = new ActionConfig.Builder("", "name", "").build();
+        action = EasyMock.createNiceMock(ValidateAction.class);
+        invocation = EasyMock.createNiceMock(ActionInvocation.class);
+        interceptor = new DefaultWorkflowInterceptor();
+        proxy = EasyMock.createNiceMock(ActionProxy.class);
+
+        EasyMock.expect(invocation.getProxy()).andReturn(proxy).anyTimes();
+        EasyMock.expect(invocation.getAction()).andReturn(action).anyTimes();
+        EasyMock.expect(invocation.invoke()).andAnswer(new IAnswer<String>() {
+            public String answer() throws Throwable {
+                return result;
+            }
+        }).anyTimes();
+
+        EasyMock.expect(proxy.getConfig()).andReturn(config).anyTimes();
+        EasyMock.expect(proxy.getMethod()).andReturn("execute").anyTimes();
+
+
+        EasyMock.replay(invocation);
+        EasyMock.replay(action);
+        EasyMock.replay(proxy);
+
+        ActionContext contex = new ActionContext(new HashMap<String, Object>());
+        ActionContext.setContext(contex);
+        contex.setActionInvocation(invocation);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+    
+    protected ValidationInterceptor create() {
+        ObjectFactory objectFactory = container.getInstance(ObjectFactory.class);
+        return (ValidationInterceptor) objectFactory.buildInterceptor(
+                new InterceptorConfig.Builder("model", ValidationInterceptor.class.getName()).build(), new HashMap());
+    }
+
+    
+    
+
+    private interface ValidateAction extends Action, Validateable, ValidationAware {
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ExceptionMappingInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ExceptionMappingInterceptorTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ExceptionMappingInterceptorTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ExceptionMappingInterceptorTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,312 @@
+/*
+ * 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.interceptor;
+
+import com.mockobjects.dynamic.Mock;
+import org.apache.struts2.xwork2.Action;
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.ActionInvocation;
+import org.apache.struts2.xwork2.ActionProxy;
+import org.apache.struts2.xwork2.config.entities.ActionConfig;
+import org.apache.struts2.xwork2.config.entities.ExceptionMappingConfig;
+import org.apache.struts2.xwork2.util.ValueStack;
+import org.apache.struts2.xwork2.validator.ValidationException;
+import org.apache.struts2.xwork2.XWorkException;
+import org.apache.struts2.xwork2.XWorkTestCase;
+
+import java.util.HashMap;
+
+/**
+ * Unit test for ExceptionMappingInterceptor.
+ * 
+ * @author Matthew E. Porter (matthew dot porter at metissian dot com)
+ */
+public class ExceptionMappingInterceptorTest extends XWorkTestCase {
+
+    ActionInvocation invocation;
+    ExceptionMappingInterceptor interceptor;
+    Mock mockInvocation;
+    ValueStack stack;
+
+
+    public void testThrownExceptionMatching() throws Exception {
+        this.setUpWithExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new XWorkException("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+        String result = interceptor.intercept(invocation);
+        assertNotNull(stack.findValue("exception"));
+        assertEquals(stack.findValue("exception"), exception);
+        assertEquals(result, "spooky");
+        ExceptionHolder holder = (ExceptionHolder) stack.getRoot().get(0); // is on top of the root
+        assertNotNull(holder.getExceptionStack()); // to invoke the method for unit test
+    }
+
+    public void testThrownExceptionMatching2() throws Exception {
+        this.setUpWithExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new ValidationException("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+        String result = interceptor.intercept(invocation);
+        assertNotNull(stack.findValue("exception"));
+        assertEquals(stack.findValue("exception"), exception);
+        assertEquals(result, "throwable");
+    }
+
+    public void testNoThrownException() throws Exception {
+        this.setUpWithExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+        String result = interceptor.intercept(invocation);
+        assertEquals(result, Action.SUCCESS);
+        assertNull(stack.findValue("exception"));
+    }
+
+    public void testThrownExceptionNoMatch() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (Exception e) {
+            assertEquals(e, exception);
+        }
+    }
+
+    public void testThrownExceptionNoMatchLogging() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+        	interceptor.setLogEnabled(true);
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (Exception e) {
+            assertEquals(e, exception);
+        }
+    }
+
+    public void testThrownExceptionNoMatchLoggingCategory() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+        	interceptor.setLogEnabled(true);
+        	interceptor.setLogCategory("showcase.unhandled");
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (Exception e) {
+            assertEquals(e, exception);
+        }
+    }
+
+    public void testThrownExceptionNoMatchLoggingCategoryLevelFatal() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+        	interceptor.setLogEnabled(true);
+        	interceptor.setLogCategory("showcase.unhandled");
+        	interceptor.setLogLevel("fatal");
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (Exception e) {
+            assertEquals(e, exception);
+        }
+        
+        assertEquals("fatal", interceptor.getLogLevel());
+        assertEquals(true, interceptor.isLogEnabled());
+        assertEquals("showcase.unhandled", interceptor.getLogCategory());
+    }
+
+    public void testThrownExceptionNoMatchLoggingCategoryLevelError() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+        	interceptor.setLogEnabled(true);
+        	interceptor.setLogCategory("showcase.unhandled");
+        	interceptor.setLogLevel("error");
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (Exception e) {
+            assertEquals(e, exception);
+        }
+    }
+
+    public void testThrownExceptionNoMatchLoggingCategoryLevelWarn() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+        	interceptor.setLogEnabled(true);
+        	interceptor.setLogCategory("showcase.unhandled");
+        	interceptor.setLogLevel("warn");
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (Exception e) {
+            assertEquals(e, exception);
+        }
+    }
+
+    public void testThrownExceptionNoMatchLoggingCategoryLevelInfo() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+        	interceptor.setLogEnabled(true);
+        	interceptor.setLogCategory("showcase.unhandled");
+        	interceptor.setLogLevel("info");
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (Exception e) {
+            assertEquals(e, exception);
+        }
+    }
+
+    public void testThrownExceptionNoMatchLoggingCategoryLevelDebug() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+        	interceptor.setLogEnabled(true);
+        	interceptor.setLogCategory("showcase.unhandled");
+        	interceptor.setLogLevel("debug");
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (Exception e) {
+            assertEquals(e, exception);
+        }
+    }
+
+    public void testThrownExceptionNoMatchLoggingCategoryLevelTrace() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+        	interceptor.setLogEnabled(true);
+        	interceptor.setLogCategory("showcase.unhandled");
+        	interceptor.setLogLevel("trace");
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (Exception e) {
+            assertEquals(e, exception);
+        }
+    }
+
+    public void testThrownExceptionNoMatchLoggingUnknownLevel() throws Exception {
+        this.setupWithoutExceptionMappings();
+
+        Mock action = new Mock(Action.class);
+        Exception exception = new Exception("test");
+        mockInvocation.expectAndThrow("invoke", exception);
+        mockInvocation.matchAndReturn("getAction", ((Action) action.proxy()));
+
+        try {
+        	interceptor.setLogEnabled(true);
+        	interceptor.setLogLevel("xxx");
+            interceptor.intercept(invocation);
+            fail("Should not have reached this point.");
+        } catch (IllegalArgumentException e) {
+        	// success
+        }
+    }
+
+    private void setupWithoutExceptionMappings() {
+        ActionConfig actionConfig = new ActionConfig.Builder("", "", "").build();
+        Mock actionProxy = new Mock(ActionProxy.class);
+        actionProxy.expectAndReturn("getConfig", actionConfig);
+        mockInvocation.expectAndReturn("getProxy", ((ActionProxy) actionProxy.proxy()));
+        invocation = (ActionInvocation) mockInvocation.proxy();
+    }
+
+    private void setUpWithExceptionMappings() {
+        ActionConfig actionConfig = new ActionConfig.Builder("", "", "")
+                .addExceptionMapping(new ExceptionMappingConfig.Builder("xwork", "org.apache.struts2.xwork2.XWorkException", "spooky").build())
+                .addExceptionMapping(new ExceptionMappingConfig.Builder("throwable", "java.lang.Throwable", "throwable").build())
+                .build();
+        Mock actionProxy = new Mock(ActionProxy.class);
+        actionProxy.expectAndReturn("getConfig", actionConfig);
+        mockInvocation.expectAndReturn("getProxy", ((ActionProxy) actionProxy.proxy()));
+
+        invocation = (ActionInvocation) mockInvocation.proxy();
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        stack = ActionContext.getContext().getValueStack();
+        mockInvocation = new Mock(ActionInvocation.class);
+        mockInvocation.expectAndReturn("getStack", stack);
+        mockInvocation.expectAndReturn("getInvocationContext", new ActionContext(new HashMap()));
+        interceptor = new ExceptionMappingInterceptor();
+        interceptor.init();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        interceptor.destroy();
+        invocation = null;
+        interceptor = null;
+        mockInvocation = null;
+        stack = null;
+    }
+
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/I18nInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/I18nInterceptorTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/I18nInterceptorTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/I18nInterceptorTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,207 @@
+/*
+ * 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.interceptor;
+
+import org.apache.struts2.xwork2.Action;
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.SimpleFooAction;
+import org.apache.struts2.xwork2.ActionInvocation;
+import org.apache.struts2.xwork2.mock.MockActionInvocation;
+import junit.framework.TestCase;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.io.Serializable;
+
+/**
+ * Unit test for I18nInterceptor.
+ *
+ * @author Claus Ibsen
+ */
+public class I18nInterceptorTest extends TestCase {
+
+    private I18nInterceptor interceptor;
+    private ActionContext ac;
+    private Map<String, Serializable> params;
+    private Map session;
+    private ActionInvocation mai;
+
+    public void testEmptyParamAndSession() throws Exception {
+        interceptor.intercept(mai);
+    }
+
+    public void testNoSession() throws Exception {
+        ac.setSession(null);
+        interceptor.intercept(mai);
+    }
+
+    public void testDefaultLocale() throws Exception {
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, "_"); // bad locale that would get us default locale instead
+        interceptor.intercept(mai);
+
+        assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
+
+        assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here
+        assertEquals(Locale.getDefault(), session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object
+    }
+
+    public void testDenmarkLocale() throws Exception {
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, "da_DK");
+        interceptor.intercept(mai);
+
+        assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
+
+        Locale denmark = new Locale("da", "DK");
+        assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here
+        assertEquals(denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object
+    }
+
+    public void testDenmarkLocaleRequestOnly() throws Exception {
+        params.put(I18nInterceptor.DEFAULT_REQUESTONLY_PARAMETER, "da_DK");
+        interceptor.intercept(mai);
+
+        assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
+
+        Locale denmark = new Locale("da", "DK");
+        assertNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here
+        assertEquals(denmark, mai.getInvocationContext().getLocale()); // should create a locale object
+    }
+
+    public void testCountryOnlyLocale() throws Exception {
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, "DK");
+        interceptor.intercept(mai);
+
+        assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
+
+        Locale denmark = new Locale("DK");
+        assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here
+        assertEquals(denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object
+    }
+
+    public void testLanguageOnlyLocale() throws Exception {
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, "da_");
+        interceptor.intercept(mai);
+
+        assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
+
+        Locale denmark = new Locale("da");
+        assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here
+        assertEquals(denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object
+    }
+
+    public void testWithVariant() throws Exception {
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, "fr_CA_xx");
+        interceptor.intercept(mai);
+
+        assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
+
+        Locale variant = new Locale("fr", "CA", "xx");
+        Locale locale = (Locale) session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE);
+        assertNotNull(locale); // should be stored here
+        assertEquals(variant, locale);
+        assertEquals("xx", locale.getVariant());
+    }
+
+    public void testWithVariantRequestOnly() throws Exception {
+        params.put(I18nInterceptor.DEFAULT_REQUESTONLY_PARAMETER, "fr_CA_xx");
+        interceptor.intercept(mai);
+
+        assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
+        assertNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE));
+
+        Locale variant = new Locale("fr", "CA", "xx");
+        Locale locale = mai.getInvocationContext().getLocale();
+        assertNotNull(locale); // should be stored here
+        assertEquals(variant, locale);
+        assertEquals("xx", locale.getVariant());
+    }
+
+    public void testRealLocaleObjectInParams() throws Exception {
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, Locale.CANADA_FRENCH);
+        interceptor.intercept(mai);
+
+        assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
+
+        assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here
+        assertEquals(Locale.CANADA_FRENCH, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object
+    }
+
+    public void testRealLocalesInParams() throws Exception {
+        Locale[] locales = new Locale[] { Locale.CANADA_FRENCH };
+        assertTrue(locales.getClass().isArray());
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, locales);
+        interceptor.intercept(mai);
+
+        assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
+
+        assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here
+        assertEquals(Locale.CANADA_FRENCH, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE));
+    }
+
+    public void testSetParameterAndAttributeNames() throws Exception {
+        interceptor.setAttributeName("hello");
+        interceptor.setParameterName("world");
+
+        params.put("world", Locale.CHINA);
+        interceptor.intercept(mai);
+
+        assertNull(params.get("world")); // should have been removed
+
+        assertNotNull(session.get("hello")); // should be stored here
+        assertEquals(Locale.CHINA, session.get("hello"));
+    }
+
+    public void testActionContextLocaleIsPreservedWhenNotOverridden() throws Exception {
+        final Locale locale1 = Locale.TRADITIONAL_CHINESE;
+        mai.getInvocationContext().setLocale(locale1);
+        interceptor.intercept(mai);
+
+        Locale locale = (Locale) session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE);
+        assertNull(locale); // should not be stored here
+        locale = mai.getInvocationContext().getLocale();
+        assertEquals(locale1, locale);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        interceptor = new I18nInterceptor();
+        interceptor.init();
+        params = new HashMap<String, Serializable>();
+        session = new HashMap();
+
+        Map<String, Object> ctx = new HashMap<String, Object>();
+        ctx.put(ActionContext.PARAMETERS, params);
+        ctx.put(ActionContext.SESSION, session);
+        ac = new ActionContext(ctx);
+
+        Action action = new SimpleFooAction();
+        mai = new MockActionInvocation();
+        ((MockActionInvocation) mai).setAction(action);
+        ((MockActionInvocation) mai).setInvocationContext(ac);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        interceptor.destroy();
+        interceptor = null;
+        ac = null;
+        params = null;
+        session = null;
+        mai = null;
+    }
+
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/MethodFilterInterceptorUtilTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/MethodFilterInterceptorUtilTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/MethodFilterInterceptorUtilTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/MethodFilterInterceptorUtilTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2002-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.interceptor;
+
+import org.apache.struts2.xwork2.XWorkTestCase;
+
+import java.util.HashSet;
+
+public class MethodFilterInterceptorUtilTest extends XWorkTestCase {
+    
+    public void testApplyMethodNoWildcards() {
+        
+        HashSet<String> included= new HashSet<String>();
+        included.add("included");
+        included.add("includedAgain");
+
+        HashSet<String> excluded= new HashSet<String>();
+        excluded.add("excluded");
+        excluded.add("excludedAgain");
+        
+        // test expected behavior
+        assertFalse(MethodFilterInterceptorUtil.applyMethod(excluded, included, "excluded"));
+        assertTrue(MethodFilterInterceptorUtil.applyMethod(excluded, included, "included"));
+
+        // test precedence
+        included.add("excluded");
+        assertTrue(MethodFilterInterceptorUtil.applyMethod(excluded, included, "excluded"));
+
+    }
+
+    public void testApplyMethodWithWildcards() {
+
+        HashSet<String> included= new HashSet<String>();
+        included.add("included*");
+
+        HashSet<String> excluded= new HashSet<String>();
+        excluded.add("excluded*");
+        
+        assertTrue(MethodFilterInterceptorUtil.applyMethod(excluded, included, "includedMethod"));
+        assertFalse(MethodFilterInterceptorUtil.applyMethod(excluded, included, "excludedMethod"));
+
+        // test precedence
+        included.clear();
+        excluded.clear();
+        included.add("wildIncluded");
+        excluded.add("wild*");
+        
+        assertTrue(MethodFilterInterceptorUtil.applyMethod(excluded, included, "wildIncluded"));
+        assertFalse(MethodFilterInterceptorUtil.applyMethod(excluded, included, "wildNotIncluded"));
+
+        // test precedence
+        included.clear();
+        excluded.clear();
+        included.add("*");
+        excluded.add("excluded");
+
+        assertTrue(MethodFilterInterceptorUtil.applyMethod(excluded, included, "anyMethod"));
+
+        // test precedence
+        included.clear();
+        excluded.clear();
+        included.add("included");
+        excluded.add("*");
+
+        assertTrue(MethodFilterInterceptorUtil.applyMethod(excluded, included, "included"));
+        assertFalse(MethodFilterInterceptorUtil.applyMethod(excluded, included, "shouldBeExcluded"));
+
+    }
+
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ModelDrivenInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ModelDrivenInterceptorTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ModelDrivenInterceptorTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ModelDrivenInterceptorTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,117 @@
+/*
+ * 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.interceptor;
+
+import com.mockobjects.dynamic.ConstraintMatcher;
+import com.mockobjects.dynamic.Mock;
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.ActionSupport;
+import org.apache.struts2.xwork2.util.ValueStack;
+import org.apache.struts2.xwork2.Action;
+import org.apache.struts2.xwork2.ActionInvocation;
+import org.apache.struts2.xwork2.ModelDriven;
+import org.apache.struts2.xwork2.XWorkTestCase;
+
+import java.util.Date;
+
+
+/**
+ * @author $Author: lukaszlenart $
+ * @version $Revision: 1209415 $
+ */
+public class ModelDrivenInterceptorTest extends XWorkTestCase {
+
+    Action action;
+    Mock mockActionInvocation;
+    ModelDrivenInterceptor modelDrivenInterceptor;
+    Object model;
+    PreResultListener preResultListener;
+
+
+    public void testModelDrivenGetsPushedOntoStack() throws Exception {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        action = new ModelDrivenAction();
+        mockActionInvocation.expectAndReturn("getAction", action);
+        mockActionInvocation.expectAndReturn("getStack", stack);
+        mockActionInvocation.expectAndReturn("invoke", "foo");
+
+        modelDrivenInterceptor.intercept((ActionInvocation) mockActionInvocation.proxy());
+
+        Object topOfStack = stack.pop();
+        assertEquals("our model should be on the top of the stack", model, topOfStack);
+    }
+
+    public void testModelDrivenUpdatedAndGetsPushedOntoStack() throws Exception {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        action = new ModelDrivenAction();
+        mockActionInvocation.expectAndReturn("getAction", action);
+        mockActionInvocation.matchAndReturn("getStack", stack);
+        mockActionInvocation.expectAndReturn("invoke", "foo");
+        mockActionInvocation.expect("addPreResultListener", new ConstraintMatcher() {
+
+            public boolean matches(Object[] objects) {
+                preResultListener = (PreResultListener) objects[0];
+                return true;
+            }
+
+            public Object[] getConstraints() {
+                return new Object[0];  //To change body of implemented methods use File | Settings | File Templates.
+            }
+        });
+        modelDrivenInterceptor.setRefreshModelBeforeResult(true);
+
+        modelDrivenInterceptor.intercept((ActionInvocation) mockActionInvocation.proxy());
+        assertNotNull(preResultListener);
+        model = "this is my model";
+        preResultListener.beforeResult((ActionInvocation) mockActionInvocation.proxy(), "success");
+
+        Object topOfStack = stack.pop();
+        assertEquals("our model should be on the top of the stack", model, topOfStack);
+        assertEquals(1, stack.getRoot().size());
+    }
+
+    public void testStackNotModifedForNormalAction() throws Exception {
+        action = new ActionSupport();
+        mockActionInvocation.expectAndReturn("getAction", action);
+        mockActionInvocation.expectAndReturn("invoke", "foo");
+
+        // nothing should happen
+        modelDrivenInterceptor.intercept((ActionInvocation) mockActionInvocation.proxy());
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mockActionInvocation = new Mock(ActionInvocation.class);
+        modelDrivenInterceptor = new ModelDrivenInterceptor();
+        model = new Date(); // any object will do
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        mockActionInvocation.verify();
+    }
+
+
+    public class ModelDrivenAction extends ActionSupport implements ModelDriven {
+
+        public Object getModel() {
+            return model;
+        }
+
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ParameterFilterInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ParameterFilterInterceptorTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ParameterFilterInterceptorTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ParameterFilterInterceptorTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,129 @@
+/*
+ * 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.interceptor;
+
+import com.mockobjects.dynamic.Mock;
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.util.ValueStack;
+import org.apache.struts2.xwork2.Action;
+import org.apache.struts2.xwork2.ActionInvocation;
+import org.apache.struts2.xwork2.XWorkTestCase;
+import org.apache.struts2.xwork2.SimpleAction;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Unit test for {@link ParameterFilterInterceptor}.
+ *
+ * @author Gabe
+ */
+public class ParameterFilterInterceptorTest extends XWorkTestCase {
+
+    ActionInvocation invocation;
+    ParameterFilterInterceptor interceptor;
+    Mock mockInvocation;
+    ValueStack stack;
+    Map contextMap;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        contextMap=new HashMap();
+        stack = ActionContext.getContext().getValueStack();
+        mockInvocation = new Mock(ActionInvocation.class);
+        mockInvocation.expectAndReturn("getStack", stack);
+        mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
+        mockInvocation.expectAndReturn("getInvocationContext", new ActionContext(contextMap));
+        mockInvocation.matchAndReturn("getAction", new SimpleAction());
+        invocation = (ActionInvocation) mockInvocation.proxy();
+        interceptor = new ParameterFilterInterceptor();
+        interceptor.init();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        interceptor.destroy();
+    }
+
+    public void testBasicBlockAll() throws Exception {
+        runFilterTest(null,null,true,new String[] {"blah", "bladeblah", "bladebladeblah"});
+        assertEquals(0, getParameterNames().size());
+    }
+    
+    public void testBasicAllowed() throws Exception {
+        runFilterTest("blah",null,true,new String[] {"blah"});
+        assertEquals(1, getParameterNames().size()); 
+    }
+    
+    public void testBasicBlocked() throws Exception {
+        runFilterTest(null,"blah",false,new String[] {"blah"});
+        assertEquals(0, getParameterNames().size()); 
+    }      
+    public void testAllSubpropertiesBlocked() throws Exception {
+        runFilterTest(null,"blah",false,new String[] {"blah.deblah", "blah.somethingelse", "blah(22)"});
+        assertEquals(0, getParameterNames().size()); 
+    }
+
+    public void testAllSubpropertiesAllowed() throws Exception {
+        runFilterTest("blah",null,true,
+                new String[] {"blah.deblah", "blah.somethingelse", "blah(22)"});
+        assertEquals(3, getParameterNames().size()); 
+    }
+    
+    public void testTreeBlocking() throws Exception {
+        runFilterTest("blah.deblah","blah,blah.deblah.deblah",false,
+                new String[] {"blah", "blah.deblah", "blah.deblah.deblah"});
+        Collection paramNames=getParameterNames();
+        assertEquals(1, paramNames.size());
+        assertEquals(paramNames.iterator().next(),"blah.deblah");
+    }
+    
+    public void testEnsureOnlyPropsBlocked() throws Exception {
+        runFilterTest(null,"blah",false,new String[] {"blahdeblah"});
+        assertEquals(1, getParameterNames().size()); 
+    }
+  
+    
+    private void runFilterTest(String allowed, String blocked, boolean defaultBlocked, String[] paramNames) throws Exception {
+        interceptor.setAllowed(allowed);
+        interceptor.setBlocked(blocked);
+        interceptor.setDefaultBlock(defaultBlocked);
+        setUpParameters(paramNames);
+        runAction();
+        
+    }
+    
+    private void setUpParameters(String [] paramNames) {
+        Map params=new HashMap();
+        for (String paramName : paramNames) {
+            params.put(paramName, "irrelevant what this is");
+
+        }
+        contextMap.put(ActionContext.PARAMETERS, params);
+    }
+    
+    private Collection getParameterNames() {
+        return ((Map)contextMap.get(ActionContext.PARAMETERS)).keySet();
+    }
+    
+    public void runAction() throws Exception  {
+        interceptor.intercept(invocation);
+    }
+    
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ParameterRemoverInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ParameterRemoverInterceptorTest.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ParameterRemoverInterceptorTest.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/interceptor/ParameterRemoverInterceptorTest.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,116 @@
+package org.apache.struts2.xwork2.interceptor;
+
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.ActionInvocation;
+import org.apache.struts2.xwork2.ActionSupport;
+import junit.framework.TestCase;
+import org.easymock.MockControl;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * @author tmjee
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Id: ParameterRemoverInterceptorTest.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class ParameterRemoverInterceptorTest extends TestCase {
+
+	protected Map contextMap;
+	protected ActionContext context;
+	protected MockControl actionInvocationControl;
+	protected ActionInvocation actionInvocation;
+	
+	@Override
+    protected void setUp() throws Exception {
+		contextMap = new LinkedHashMap();
+		context = new ActionContext(contextMap);
+		
+		actionInvocationControl = MockControl.createControl(ActionInvocation.class);
+		actionInvocation = (ActionInvocation) actionInvocationControl.getMock();
+		actionInvocationControl.expectAndDefaultReturn(actionInvocation.getAction(),  new SampleAction());
+		actionInvocationControl.expectAndDefaultReturn(actionInvocation.getInvocationContext(), context);
+		actionInvocationControl.expectAndDefaultReturn(actionInvocation.invoke(), "success");
+	}
+	
+	public void testInterception1() throws Exception {
+		contextMap.put(ActionContext.PARAMETERS, new LinkedHashMap() {
+			private static final long serialVersionUID = 0L;
+			{
+				put("param1", new String[] { "paramValue1" });
+				put("param2", new String[] { "paramValue2" });
+				put("param3", new String[] { "paramValue3" });
+				put("param", new String[] { "paramValue" });
+			}
+		});
+		
+		actionInvocationControl.replay();
+		
+		ParameterRemoverInterceptor interceptor = new ParameterRemoverInterceptor();
+		interceptor.setParamNames("param1,param2");
+		interceptor.setParamValues("paramValue1,paramValue2");
+		interceptor.intercept(actionInvocation);
+		
+		Map params = (Map) contextMap.get(ActionContext.PARAMETERS);
+		assertEquals(params.size(), 2);
+		assertTrue(params.containsKey("param3"));
+		assertTrue(params.containsKey("param"));
+		assertEquals(((String[])params.get("param3"))[0], "paramValue3");
+		assertEquals(((String[])params.get("param"))[0], "paramValue");
+		
+		actionInvocationControl.verify();
+	}
+	
+	
+	public void testInterception2() throws Exception {
+		contextMap.put(ActionContext.PARAMETERS, new LinkedHashMap() {
+			private static final long serialVersionUID = 0L;
+			{
+				put("param1", new String[] { "paramValue2" });
+				put("param2", new String[] { "paramValue1" });
+			}
+		});
+		
+		actionInvocationControl.replay();
+		
+		ParameterRemoverInterceptor interceptor = new ParameterRemoverInterceptor();
+		interceptor.setParamNames("param1,param2");
+		interceptor.setParamValues("paramValue1,paramValue2");
+		interceptor.intercept(actionInvocation);
+		
+		Map params = (Map) contextMap.get(ActionContext.PARAMETERS);
+		assertEquals(params.size(), 0);
+		
+		actionInvocationControl.verify();
+	}
+	
+	
+	public void testInterception3() throws Exception {
+		contextMap.put(ActionContext.PARAMETERS, new LinkedHashMap() {
+			private static final long serialVersionUID = 0L;
+			{
+				put("param1", new String[] { "paramValueOne" });
+				put("param2", new String[] { "paramValueTwo" });
+			}
+		});
+		
+		actionInvocationControl.replay();
+		
+		ParameterRemoverInterceptor interceptor = new ParameterRemoverInterceptor();
+		interceptor.setParamNames("param1,param2");
+		interceptor.setParamValues("paramValue1,paramValue2");
+		interceptor.intercept(actionInvocation);
+		
+		Map params = (Map) contextMap.get(ActionContext.PARAMETERS);
+		assertEquals(params.size(), 2);
+		assertTrue(params.containsKey("param1"));
+		assertTrue(params.containsKey("param2"));
+		assertEquals(((String[])params.get("param1"))[0], "paramValueOne");
+		assertEquals(((String[])params.get("param2"))[0], "paramValueTwo");
+		
+		actionInvocationControl.verify();
+	}
+	
+	class SampleAction extends ActionSupport {
+		private static final long serialVersionUID = 7489487258845368260L;
+	}
+}