Commits

Anonymous committed f0efda4

XW-516
- interceptor-stack's interceptor parameter overriding does not work when there's nested interceptor-stack

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2@1515e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (10)

src/java/com/opensymphony/xwork/XWorkTestCase.java

  * Copyright (c) 2002-2006 by OpenSymphony
  * All rights reserved.
  */
-
 package com.opensymphony.xwork;
 
 import com.opensymphony.xwork.config.ConfigurationManager;

src/java/com/opensymphony/xwork/config/entities/InterceptorStackConfig.java

 /*
- * Copyright (c) 2002-2006 by OpenSymphony
+ * Copyright (c) 2002-2007 by OpenSymphony
  * All rights reserved.
  */
 package com.opensymphony.xwork.config.entities;
  *
  * @author Mike
  * @author Rainer Hermanns
+ * @author tmjee
+ * 
+ * @version $Date$ $Id$
  */
 public class InterceptorStackConfig extends Located implements InterceptorListHolder, Serializable {
 
-    private List interceptors;
+	private static final long serialVersionUID = 2897260918170270343L;
+	
+	private List interceptors;  // a list of InterceptorMapping object
     private String name;
 
-
+    /**
+     * Creates an InterceptorStackConfig object.
+     */
     public InterceptorStackConfig() {
         this.interceptors = new ArrayList();
     }
 
+    /**
+     * Creates an InterceptorStackConfig object with a particular <code>name</code>.
+     * @param name
+     */
     public InterceptorStackConfig(String name) {
         this();
         this.name = name;
     }
 
-
+    
+    /**
+     * Returns a <code>Collection</code> of InterceptorMapping objects.
+     * @return
+     */
     public Collection getInterceptors() {
         return interceptors;
     }
 
+    /**
+     * Set the name of this interceptor stack configuration.
+     * @param name
+     */
     public void setName(String name) {
         this.name = name;
     }
 
+    /**
+     * Get the name of this interceptor stack configuration.
+     * @return String
+     */
     public String getName() {
         return name;
     }
 
+    /**
+     * Add an <code>InterceptorMapping</code> object.
+     */
     public void addInterceptor(InterceptorMapping interceptor) {
         this.interceptors.add(interceptor);
     }
 
+    /**
+     * Add a List of <code>InterceptorMapping</code> objects.
+     */
     public void addInterceptors(List interceptors) {
         this.interceptors.addAll(interceptors);
     }
 
+    /**
+     * An InterceptorStackConfig object is equals with <code>o</code> only if
+     * <ul>
+     *  <li>o is an InterceptorStackConfig object</li>
+     *  <li>both names are equals</li>
+     *  <li>all of their <code>InterceptorMapping</code>s are equals</li>
+     * </ul>
+     */
     public boolean equals(Object o) {
         if (this == o) {
             return true;
         return true;
     }
 
+    /**
+     * Generate hashcode based on <code>InterceptorStackConfig</code>'s name and its 
+     * <code>InterceptorMapping</code>s.
+     */
     public int hashCode() {
         int result;
         result = ((name != null) ? name.hashCode() : 0);

src/java/com/opensymphony/xwork/config/entities/PackageConfig.java

     }
 
     public int hashCode() {
-        // System.out.println("hashCode() + {Name:"+name+" abstract:"+isAbstract+" namespace:"+namespace+" parents: "+parents+"}");
         int result;
         result = ((name != null) ? name.hashCode() : 0);
         result = (29 * result) + ((parents != null) ? parents.hashCode() : 0);

src/java/com/opensymphony/xwork/config/impl/DefaultConfiguration.java

 import com.opensymphony.xwork.config.entities.PackageConfig;
 import com.opensymphony.xwork.config.entities.ResultTypeConfig;
 import com.opensymphony.xwork.config.providers.InterceptorBuilder;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
         setDefaultResults(results, packageContext);
 
         List interceptors = new ArrayList(baseConfig.getInterceptors());
-
+        
         if (interceptors.size() <= 0) {
             String defaultInterceptorRefName = packageContext.getFullDefaultInterceptorRef();
 

src/java/com/opensymphony/xwork/config/providers/InterceptorBuilder.java

  */
 package com.opensymphony.xwork.config.providers;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import com.opensymphony.xwork.ObjectFactory;
 import com.opensymphony.xwork.interceptor.Interceptor;
 import com.opensymphony.xwork.config.ConfigurationException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.util.*;
 
 
 /**
  * @author Mike
  * @author Rainer Hermanns
  * @author tmjee
+ * 
  * @version $Date$ $Id$
  */
 public class InterceptorBuilder {
 
 
     /**
-     * Builds a list of interceptors referenced by the refName in the supplied PackageConfig.
+     * Builds a list of interceptors referenced by the refName in the supplied PackageConfig (InterceptorMapping object).
      *
      * @param packageConfig
      * @param refName
      * @param refParams
-     * @return list of interceptors referenced by the refName in the supplied PackageConfig.
+     * @return list of interceptors referenced by the refName in the supplied PackageConfig (InterceptorMapping object).
      * @throws ConfigurationException
      */
     public static List constructInterceptorReference(PackageConfig packageConfig, String refName, Map refParams) throws ConfigurationException {
      * @param refParams The overridden interceptor properies
      * @return list of interceptors referenced by the refName in the supplied PackageConfig overridden with refParams.
      */
-    private static List constructParameterizedInterceptorReferences(PackageConfig packageConfig, InterceptorStackConfig stackConfig, Map refParams) {
-        List result;
+    private static List constructParameterizedInterceptorReferences(PackageConfig packageConfig, 
+    		InterceptorStackConfig stackConfig, Map refParams) {
+        Set result;
         Map params = new HashMap();
-
+        
+        /*
+         * We strip
+         * 
+         * <interceptor-ref name="someStack">
+         *    <param name="interceptor1.param1">someValue</param>
+         *    <param name="interceptor1.param2">anotherValue</param>
+         * </interceptor-ref>
+         * 
+         * down to map 
+         *  interceptor1 -> [param1 -> someValue, param2 -> anotherValue]
+         * 
+         * or
+         * <interceptor-ref name="someStack">
+         *    <param name="interceptorStack1.interceptor1.param1">someValue</param>
+         *    <param name="interceptorStack1.interceptor1.param2">anotherValue</param>
+         * </interceptor-ref>
+         * 
+         * down to map
+         *  interceptorStack1 -> [interceptor1.param1 -> someValue, interceptor1.param2 -> anotherValue]
+         * 
+         */
         for ( Iterator iter = refParams.keySet().iterator(); iter.hasNext();) {
             String key = (String) iter.next();
             String value = (String) refParams.get(key);
             }
         }
 
-        result = new ArrayList(stackConfig.getInterceptors());
+        result = new LinkedHashSet(stackConfig.getInterceptors());
 
         for ( Iterator iter = params.keySet().iterator(); iter.hasNext();) {
-
             String key = (String) iter.next();
             Map map = (Map) params.get(key);
-
-            InterceptorConfig cfg = (InterceptorConfig) packageConfig.getAllInterceptorConfigs().get(key);
-            Interceptor interceptor = ObjectFactory.getObjectFactory().buildInterceptor(cfg, map);
-
-            InterceptorMapping mapping = new InterceptorMapping(key, interceptor);
-            if ( result != null && result.contains(mapping)) {
-                int index = result.indexOf(mapping);
-                result.set(index, mapping);
-            } else {
+            
+            Object interceptorCfgObj = packageConfig.getAllInterceptorConfigs().get(key);
+            
+            /*
+             * Now we attempt to separate out param that refers to Interceptor 
+             * and Interceptor stack, eg.
+             * 
+             * <interceptor-ref name="someStack">
+             *    <param name="interceptor1.param1">someValue</param>
+             *    ...
+             * </interceptor-ref>
+             * 
+             *  vs
+             *  
+             *  <interceptor-ref name="someStack">
+             *    <param name="interceptorStack1.interceptor1.param1">someValue</param>
+             *    ...
+             *  </interceptor-ref>
+             */
+            if(interceptorCfgObj instanceof InterceptorConfig) {  //  interceptor-ref param refer to an interceptor
+            	InterceptorConfig cfg = (InterceptorConfig) interceptorCfgObj;
+            	Interceptor interceptor = ObjectFactory.getObjectFactory().buildInterceptor(cfg, map);
+
+            	InterceptorMapping mapping = new InterceptorMapping(key, interceptor);
+            	if ( result != null && result.contains(mapping)) {
+            		// if an existing interceptor mapping exists, 
+            		// we remove from the result Set, just to make sure 
+            		// there's always one unique mapping.
+            		result.remove(mapping);
+            	}
                 result.add(mapping);
             }
+            else if (interceptorCfgObj instanceof InterceptorStackConfig){  // interceptor-ref param refer to an interceptor stack
+            	
+            	// If its an interceptor-stack, we call this method recursively untill, 
+            	// all the params (eg. interceptorStack1.interceptor1.param etc.) 
+            	// are resolved down to a specific interceptor.
+            	
+            	InterceptorStackConfig stackCfg = (InterceptorStackConfig) interceptorCfgObj;
+            	List tmpResult = constructParameterizedInterceptorReferences(packageConfig, stackCfg, map);
+            	for (Iterator i = tmpResult.iterator(); i.hasNext(); ) {
+            		InterceptorMapping tmpInterceptorMapping = (InterceptorMapping) i.next();
+            		if (result.contains(tmpInterceptorMapping)) {
+            			result.remove(tmpInterceptorMapping);
+            		}
+            		result.add(tmpInterceptorMapping);
+            	}
+            }
         }
-
-        return result;
+        return new ArrayList(result);
     }
 }

src/java/com/opensymphony/xwork/mock/MockInterceptor.java

  */
 public class MockInterceptor implements Interceptor {
 
-    public static final String DEFAULT_FOO_VALUE = "fooDefault";
+	private static final long serialVersionUID = 2692551676567227756L;
+
+
+	public static final String DEFAULT_FOO_VALUE = "fooDefault";
 
 
     private String expectedFoo = DEFAULT_FOO_VALUE;

src/test/com/opensymphony/xwork/config/providers/InterceptorBuilderTest.java

+/*
+ * Copyright (c) 2002-2007 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.config.providers;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.XWorkTestCase;
+import com.opensymphony.xwork.config.entities.InterceptorConfig;
+import com.opensymphony.xwork.config.entities.InterceptorMapping;
+import com.opensymphony.xwork.config.entities.InterceptorStackConfig;
+import com.opensymphony.xwork.config.entities.PackageConfig;
+import com.opensymphony.xwork.interceptor.Interceptor;
+
+/**
+ * @author tmjee
+ * @version $Date$ $Id$
+ */
+public class InterceptorBuilderTest extends XWorkTestCase {
+
+	/**
+	 * Try to test this
+	 * <interceptor-ref name="interceptorStack1">
+	 * 	<param name="interceptor1.param1">interceptor1_value1</param>
+	 *     <param name="interceptor1.param2">interceptor1_value2</param>
+	 *     <param name="interceptor2.param1">interceptor2_value1</param>
+	 *     <param name="interceptor2.param2">interceptor2_value2</param>
+	 * </interceptor-ref>
+	 *
+	 * @throws Exception
+	 */
+	public void testBuildInterceptor_1() throws Exception {
+		InterceptorStackConfig interceptorStackConfig1 = new InterceptorStackConfig();
+		interceptorStackConfig1.setName("interceptorStack1");
+		
+		InterceptorConfig interceptorConfig1 = new InterceptorConfig();
+		interceptorConfig1.setClassName("com.opensymphony.xwork.config.providers.InterceptorBuilderTest$MockInterceptor1");
+		interceptorConfig1.setName("interceptor1");
+		
+		InterceptorConfig interceptorConfig2 = new InterceptorConfig();
+		interceptorConfig2.setClassName("com.opensymphony.xwork.config.providers.InterceptorBuilderTest$MockInterceptor2");
+		interceptorConfig2.setName("interceptor2");
+		
+		
+		PackageConfig packageConfig = new PackageConfig();
+		packageConfig.setName("package1");
+		packageConfig.setNamespace("/namespace");
+		packageConfig.addInterceptorConfig(interceptorConfig1);
+		packageConfig.addInterceptorConfig(interceptorConfig2);
+		packageConfig.addInterceptorStackConfig(interceptorStackConfig1);
+
+		
+		
+		List interceptorMappings = 
+			InterceptorBuilder.constructInterceptorReference(packageConfig, "interceptorStack1", 
+				new LinkedHashMap() {
+					private static final long serialVersionUID = -1358620486812957895L;
+					{
+						put("interceptor1.param1", "interceptor1_value1");
+						put("interceptor1.param2", "interceptor1_value2");
+						put("interceptor2.param1", "interceptor2_value1");
+						put("interceptor2.param2", "interceptor2_value2");
+					}
+				});
+		
+		assertEquals(interceptorMappings.size(), 2);
+		
+		assertEquals(((InterceptorMapping)interceptorMappings.get(0)).getName(), "interceptor1");
+		assertNotNull(((InterceptorMapping)interceptorMappings.get(0)).getInterceptor());
+		assertEquals(((InterceptorMapping)interceptorMappings.get(0)).getInterceptor().getClass(), MockInterceptor1.class);
+		assertEquals(((MockInterceptor1)((InterceptorMapping)interceptorMappings.get(0)).getInterceptor()).getParam1(), "interceptor1_value1");
+		assertEquals(((MockInterceptor1)((InterceptorMapping)interceptorMappings.get(0)).getInterceptor()).getParam2(), "interceptor1_value2");
+		
+		assertEquals(((InterceptorMapping)interceptorMappings.get(1)).getName(), "interceptor2");
+		assertNotNull(((InterceptorMapping)interceptorMappings.get(1)).getInterceptor());
+		assertEquals(((InterceptorMapping)interceptorMappings.get(1)).getInterceptor().getClass(), MockInterceptor2.class);
+		assertEquals(((MockInterceptor2)((InterceptorMapping)interceptorMappings.get(1)).getInterceptor()).getParam1(), "interceptor2_value1");
+		assertEquals(((MockInterceptor2)((InterceptorMapping)interceptorMappings.get(1)).getInterceptor()).getParam2(), "interceptor2_value2");
+	}
+	
+	/**
+	 * Try to test this
+	 * <interceptor-ref name="interceptorStack1">
+	 * 	<param name="interceptorStack2.interceptor1.param1">interceptor1_value1</param>
+	 *     <param name="interceptorStack2.interceptor1.param2">interceptor1_value2</param>
+	 *     <param name="interceptorStack3.interceptor2.param1">interceptor2_value1</param>
+	 *     <param name="interceptorStack3.interceptor2.param2">interceptor2_value2</param>
+	 * </interceptor-ref>
+	 * 
+	 * @throws Exception
+	 */
+	public void testBuildInterceptor_2() throws Exception {
+		InterceptorStackConfig interceptorStackConfig1 = new InterceptorStackConfig();
+		interceptorStackConfig1.setName("interceptorStack1");
+		
+		InterceptorStackConfig interceptorStackConfig2 = new InterceptorStackConfig();
+		interceptorStackConfig2.setName("interceptorStack2");
+		
+		InterceptorStackConfig interceptorStackConfig3 = new InterceptorStackConfig();
+		interceptorStackConfig3.setName("interceptorStack3");
+		
+		InterceptorConfig interceptorConfig1 = new InterceptorConfig();
+		interceptorConfig1.setClassName("com.opensymphony.xwork.config.providers.InterceptorBuilderTest$MockInterceptor1");
+		interceptorConfig1.setName("interceptor1");
+		
+		InterceptorConfig interceptorConfig2 = new InterceptorConfig();
+		interceptorConfig2.setClassName("com.opensymphony.xwork.config.providers.InterceptorBuilderTest$MockInterceptor2");
+		interceptorConfig2.setName("interceptor2");
+		
+		PackageConfig packageConfig = new PackageConfig();
+		packageConfig.setName("package1");
+		packageConfig.setNamespace("/namspace");
+		packageConfig.addInterceptorConfig(interceptorConfig1);
+		packageConfig.addInterceptorConfig(interceptorConfig2);
+		packageConfig.addInterceptorStackConfig(interceptorStackConfig1);
+		packageConfig.addInterceptorStackConfig(interceptorStackConfig2);
+		packageConfig.addInterceptorStackConfig(interceptorStackConfig3);
+		
+		List interceptorMappings = InterceptorBuilder.constructInterceptorReference(packageConfig, "interceptorStack1", 
+				new LinkedHashMap() {
+					private static final long serialVersionUID = -5819935102242042570L;
+					{
+						put("interceptorStack2.interceptor1.param1", "interceptor1_value1");
+						put("interceptorStack2.interceptor1.param2", "interceptor1_value2");
+						put("interceptorStack3.interceptor2.param1", "interceptor2_value1");
+						put("interceptorStack3.interceptor2.param2", "interceptor2_value2");
+					}
+				});
+		
+		assertEquals(interceptorMappings.size(), 2);
+		
+		assertEquals(((InterceptorMapping)interceptorMappings.get(0)).getName(), "interceptor1");
+		assertNotNull(((InterceptorMapping)interceptorMappings.get(0)).getInterceptor());
+		assertEquals(((InterceptorMapping)interceptorMappings.get(0)).getInterceptor().getClass(), MockInterceptor1.class);
+		assertEquals(((MockInterceptor1)((InterceptorMapping)interceptorMappings.get(0)).getInterceptor()).getParam1(), "interceptor1_value1");
+		assertEquals(((MockInterceptor1)((InterceptorMapping)interceptorMappings.get(0)).getInterceptor()).getParam2(), "interceptor1_value2");
+		
+		assertEquals(((InterceptorMapping)interceptorMappings.get(1)).getName(), "interceptor2");
+		assertNotNull(((InterceptorMapping)interceptorMappings.get(1)).getInterceptor());
+		assertEquals(((InterceptorMapping)interceptorMappings.get(1)).getInterceptor().getClass(), MockInterceptor2.class);
+		assertEquals(((MockInterceptor2)((InterceptorMapping)interceptorMappings.get(1)).getInterceptor()).getParam1(), "interceptor2_value1");
+		assertEquals(((MockInterceptor2)((InterceptorMapping)interceptorMappings.get(1)).getInterceptor()).getParam2(), "interceptor2_value2");
+	}
+	
+	/**
+	 * Try to test this
+	 * <interceptor-ref name="interceptorStack1">
+	 * 	<param name="interceptorStack2.interceptorStack3.interceptorStack4.interceptor1.param1">interceptor1_value1</param>
+	 *     <param name="interceptorStack2.interceptorStack3.interceptorStack4.interceptor1.param2">interceptor1_value2</param>
+	 *     <param name="interceptorStack5.interceptor2.param1">interceptor2_value1</param>
+	 *     <param name="interceptorStack5.interceptor2.param2">interceptor2_value2</param>
+	 * </interceptor-ref>
+	 * 
+	 * @throws Exception
+	 */
+	public void testBuildInterceptor_3() throws Exception {
+		InterceptorConfig interceptorConfig1 = new InterceptorConfig();
+		interceptorConfig1.setClassName("com.opensymphony.xwork.config.providers.InterceptorBuilderTest$MockInterceptor1");
+		interceptorConfig1.setName("interceptor1");
+		
+		InterceptorConfig interceptorConfig2 = new InterceptorConfig();
+		interceptorConfig2.setClassName("com.opensymphony.xwork.config.providers.InterceptorBuilderTest$MockInterceptor2");
+		interceptorConfig2.setName("interceptor2");
+		
+		InterceptorStackConfig interceptorStackConfig1 = new InterceptorStackConfig();
+		interceptorStackConfig1.setName("interceptorStack1");
+		
+		InterceptorStackConfig interceptorStackConfig2 = new InterceptorStackConfig();
+		interceptorStackConfig2.setName("interceptorStack2");
+		
+		InterceptorStackConfig interceptorStackConfig3 = new InterceptorStackConfig();
+		interceptorStackConfig3.setName("interceptorStack3");
+		
+		InterceptorStackConfig interceptorStackConfig4  = new InterceptorStackConfig();
+		interceptorStackConfig4.setName("interceptorStack4");
+		
+		InterceptorStackConfig interceptorStackConfig5 = new InterceptorStackConfig();
+		interceptorStackConfig5.setName("interceptorStack5");
+		
+		
+		PackageConfig packageConfig = new PackageConfig();
+		packageConfig.setName("package1");
+		packageConfig.addInterceptorConfig(interceptorConfig1);
+		packageConfig.addInterceptorConfig(interceptorConfig2);
+		packageConfig.addInterceptorStackConfig(interceptorStackConfig1);
+		packageConfig.addInterceptorStackConfig(interceptorStackConfig2);
+		packageConfig.addInterceptorStackConfig(interceptorStackConfig3);
+		packageConfig.addInterceptorStackConfig(interceptorStackConfig4);
+		packageConfig.addInterceptorStackConfig(interceptorStackConfig5);
+		
+		List interceptorMappings = InterceptorBuilder.constructInterceptorReference(
+				packageConfig, "interceptorStack1", 
+				new LinkedHashMap() {
+					private static final long serialVersionUID = 4675809753780875525L;
+					{
+						put("interceptorStack2.interceptorStack3.interceptorStack4.interceptor1.param1", "interceptor1_value1");
+						put("interceptorStack2.interceptorStack3.interceptorStack4.interceptor1.param2", "interceptor1_value2");
+						put("interceptorStack5.interceptor2.param1", "interceptor2_value1");
+						put("interceptorStack5.interceptor2.param2", "interceptor2_value2");
+					}
+				});
+		
+		assertEquals(interceptorMappings.size(), 2);
+		
+		assertEquals(((InterceptorMapping)interceptorMappings.get(0)).getName(), "interceptor1");
+		assertNotNull(((InterceptorMapping)interceptorMappings.get(0)).getInterceptor());
+		assertEquals(((InterceptorMapping)interceptorMappings.get(0)).getInterceptor().getClass(), MockInterceptor1.class);
+		assertEquals(((MockInterceptor1)((InterceptorMapping)interceptorMappings.get(0)).getInterceptor()).getParam1(), "interceptor1_value1");
+		assertEquals(((MockInterceptor1)((InterceptorMapping)interceptorMappings.get(0)).getInterceptor()).getParam2(), "interceptor1_value2");
+		
+		assertEquals(((InterceptorMapping)interceptorMappings.get(1)).getName(), "interceptor2");
+		assertNotNull(((InterceptorMapping)interceptorMappings.get(1)).getInterceptor());
+		assertEquals(((InterceptorMapping)interceptorMappings.get(1)).getInterceptor().getClass(), MockInterceptor2.class);
+		assertEquals(((MockInterceptor2)((InterceptorMapping)interceptorMappings.get(1)).getInterceptor()).getParam1(), "interceptor2_value1");
+		assertEquals(((MockInterceptor2)((InterceptorMapping)interceptorMappings.get(1)).getInterceptor()).getParam2(), "interceptor2_value2");
+	}
+	
+	
+	public static class MockInterceptor1 implements Interceptor {
+		private static final long serialVersionUID = 2939902550126175874L;
+		private String param1;
+		private String param2;
+		public void setParam1(String param1) { this.param1 = param1; }
+		public String getParam1() { return this.param1; }
+		public void setParam2(String param2) { this.param2 = param2; }
+		public String getParam2() { return this.param2; }
+		public void destroy() {
+		}
+		public void init() {
+		}
+		public String intercept(ActionInvocation invocation) throws Exception {
+			return invocation.invoke();
+		}
+	}
+	
+	public static class MockInterceptor2 implements Interceptor {
+		private static final long serialVersionUID = 267427973306989618L;
+		private String param1;
+		private String param2;
+		public void setParam1(String param1) { this.param1 = param1; }
+		public String getParam1() { return this.param1; }
+		public void setParam2(String param2) { this.param2 = param2; }
+		public String getParam2() { return this.param2; }
+		public void destroy() {}
+		public void init() {}
+		public String intercept(ActionInvocation invocation) throws Exception {
+			return invocation.invoke();
+		}
+	}
+}

src/test/com/opensymphony/xwork/config/providers/XmlConfigurationProviderInterceptorParamOverridingTest.java

  */
 package com.opensymphony.xwork.config.providers;
 
-import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
+import com.opensymphony.xwork.XWorkTestCase;
 import com.opensymphony.xwork.config.ConfigurationManager;
-import com.opensymphony.xwork.config.ConfigurationProvider;
 import com.opensymphony.xwork.config.RuntimeConfiguration;
 import com.opensymphony.xwork.config.entities.ActionConfig;
 import com.opensymphony.xwork.config.entities.InterceptorMapping;
 import com.opensymphony.xwork.config.impl.DefaultConfiguration;
 
-import junit.framework.TestCase;
-
 /**
  * 
  * @author tm_jee
  * @version $Date$ $Id$
  */
-public class XmlConfigurationProviderInterceptorParamOverridingTest extends TestCase {
+public class XmlConfigurationProviderInterceptorParamOverridingTest extends XWorkTestCase {
 
-	public void testParamOveriding() throws Exception {
+	public void testInterceptorParamOveriding() throws Exception {
 		DefaultConfiguration conf = new DefaultConfiguration();
 		XmlConfigurationProvider p = new XmlConfigurationProvider("com/opensymphony/xwork/config/providers/xwork-test-interceptor-param-overriding.xml");
 		ConfigurationManager.addConfigurationProvider(p);
 		assertNotNull(actionTwoInterceptorMapping2);
 		assertNotNull(actionTwoInterceptorMapping3);
 		
-		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping1.getInterceptor()).getParamOne(), "i1p1");
-		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping1.getInterceptor()).getParamTwo(), "i1p2");
-		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping2.getInterceptor()).getParamOne(), "i2p1");
-		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping2.getInterceptor()).getParamTwo(), null);
-		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping3.getInterceptor()).getParamOne(), null);
-		assertEquals(((InterceptorForTestPurpose)actionOneInterceptorMapping3.getInterceptor()).getParamTwo(), null);
-		
-		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping1.getInterceptor()).getParamOne(), null);
-		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping1.getInterceptor()).getParamTwo(), null);
-		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping2.getInterceptor()).getParamOne(), null);
-		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping2.getInterceptor()).getParamTwo(), "i2p2");
-		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping3.getInterceptor()).getParamOne(), "i3p1");
-		assertEquals(((InterceptorForTestPurpose)actionTwoInterceptorMapping3.getInterceptor()).getParamTwo(), "i3p2");
+		assertInterceptorParamOneEquals(actionOne, "interceptorOne", "i1p1");
+		assertInterceptorParamTwoEquals(actionOne, "interceptorOne", "i1p2");
+		assertInterceptorParamOneEquals(actionOne, "interceptorTwo", "i2p1" );
+		assertInterceptorParamTwoEquals(actionOne, "interceptorTwo", null);
+		assertInterceptorParamOneEquals(actionOne, "interceptorThree", null);
+		assertInterceptorParamTwoEquals(actionOne, "interceptorThree", null);
 		
+		assertInterceptorParamOneEquals(actionTwo, "interceptorOne", null);
+		assertInterceptorParamTwoEquals(actionTwo, "interceptorOne", null);
+		assertInterceptorParamOneEquals(actionTwo, "interceptorTwo", null);
+		assertInterceptorParamTwoEquals(actionTwo, "interceptorTwo", "i2p2");
+		assertInterceptorParamOneEquals(actionTwo, "interceptorThree", "i3p1");
+		assertInterceptorParamTwoEquals(actionTwo, "interceptorThree", "i3p2");
+	}
+	
+	protected void assertInterceptorParamOneEquals(ActionConfig actionConfig,String interceptorName,  String paramValue) {
+		List interceptorMappings = actionConfig.getInterceptors();
+		for (Iterator i = interceptorMappings.iterator(); i.hasNext();) {
+			InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
+			assertNotNull(interceptorMapping.getInterceptor());
+			if (interceptorMapping.getName().equals(interceptorName)) {
+				assertEquals(((InterceptorForTestPurpose)interceptorMapping.getInterceptor()).getParamOne(), paramValue);
+				return;
+			}
+		}
+		fail();
+	}
+	
+	protected void assertInterceptorParamTwoEquals(ActionConfig actionConfig, String interceptorName, String paramValue) {
+		List interceptorMappings = actionConfig.getInterceptors();
+		for (Iterator i = interceptorMappings.iterator(); i.hasNext();) {
+			InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
+			assertNotNull(interceptorMapping.getInterceptor());
+			if (interceptorMapping.getName().equals(interceptorName)) {
+				assertEquals(((InterceptorForTestPurpose)interceptorMapping.getInterceptor()).getParamTwo(), paramValue);
+				return;
+			}
+		}
+		fail();
 	}
 	
 	protected void tearDown() throws Exception {

src/test/com/opensymphony/xwork/config/providers/XmlConfigurationProviderInterceptorStackParamOverridingTest.java

+/**
+ * 
+ */
+package com.opensymphony.xwork.config.providers;
+
+import java.util.Iterator;
+import java.util.List;
+
+import com.opensymphony.xwork.XWorkTestCase;
+import com.opensymphony.xwork.config.ConfigurationManager;
+import com.opensymphony.xwork.config.RuntimeConfiguration;
+import com.opensymphony.xwork.config.entities.ActionConfig;
+import com.opensymphony.xwork.config.entities.InterceptorMapping;
+import com.opensymphony.xwork.config.impl.DefaultConfiguration;
+
+/**
+ * @author tmjee
+ *
+ */
+public class XmlConfigurationProviderInterceptorStackParamOverridingTest extends XWorkTestCase {
+
+	public void testInterceptorStackParamOveriding() throws Exception {
+		DefaultConfiguration conf = new DefaultConfiguration();
+		XmlConfigurationProvider p = new XmlConfigurationProvider("com/opensymphony/xwork/config/providers/xwork-test-interceptor-stack-param-overriding.xml");
+		ConfigurationManager.addConfigurationProvider(p);
+		conf.reload();
+		
+		RuntimeConfiguration rtConf = conf.getRuntimeConfiguration();
+		
+		ActionConfig actionOne = rtConf.getActionConfig("", "actionOne");
+		ActionConfig actionTwo = rtConf.getActionConfig("", "actionTwo");
+		
+		List actionOneInterceptors = actionOne.getInterceptors();
+		List actionTwoInterceptors = actionTwo.getInterceptors();
+		
+		assertNotNull(actionOne);
+		assertNotNull(actionTwo);
+		assertNotNull(actionOneInterceptors);
+		assertNotNull(actionTwoInterceptors);
+		assertEquals(actionOneInterceptors.size(), 3);
+		assertEquals(actionTwoInterceptors.size(), 3);
+		
+		InterceptorMapping actionOneInterceptorMapping1 = (InterceptorMapping) actionOneInterceptors.get(0);
+		InterceptorMapping actionOneInterceptorMapping2 = (InterceptorMapping) actionOneInterceptors.get(1);
+		InterceptorMapping actionOneInterceptorMapping3 = (InterceptorMapping) actionOneInterceptors.get(2);
+		InterceptorMapping actionTwoInterceptorMapping1 = (InterceptorMapping) actionTwoInterceptors.get(0);
+		InterceptorMapping actionTwoInterceptorMapping2 = (InterceptorMapping) actionTwoInterceptors.get(1);
+		InterceptorMapping actionTwoInterceptorMapping3 = (InterceptorMapping) actionTwoInterceptors.get(2);
+		
+		assertNotNull(actionOneInterceptorMapping1);
+		assertNotNull(actionOneInterceptorMapping2);
+		assertNotNull(actionOneInterceptorMapping3);
+		assertNotNull(actionTwoInterceptorMapping1);
+		assertNotNull(actionTwoInterceptorMapping2);
+		assertNotNull(actionTwoInterceptorMapping3);
+		
+		
+		assertInterceptorParamOneEquals(actionOne, "interceptorOne", "i1p1");
+		assertInterceptorParamTwoEquals(actionOne, "interceptorOne", "i1p2");
+		assertInterceptorParamOneEquals(actionOne, "interceptorTwo", "i2p1" );
+		assertInterceptorParamTwoEquals(actionOne, "interceptorTwo", null);
+		assertInterceptorParamOneEquals(actionOne, "interceptorThree", null);
+		assertInterceptorParamTwoEquals(actionOne, "interceptorThree", null);
+		
+		assertInterceptorParamOneEquals(actionTwo, "interceptorOne", null);
+		assertInterceptorParamTwoEquals(actionTwo, "interceptorOne", null);
+		assertInterceptorParamOneEquals(actionTwo, "interceptorTwo", null);
+		assertInterceptorParamTwoEquals(actionTwo, "interceptorTwo", "i2p2");
+		assertInterceptorParamOneEquals(actionTwo, "interceptorThree", "i3p1");
+		assertInterceptorParamTwoEquals(actionTwo, "interceptorThree", "i3p2");
+		
+	}
+	
+	protected void assertInterceptorParamOneEquals(ActionConfig actionConfig,String interceptorName,  String paramValue) {
+		List interceptorMappings = actionConfig.getInterceptors();
+		for (Iterator i = interceptorMappings.iterator(); i.hasNext();) {
+			InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
+			assertNotNull(interceptorMapping.getInterceptor());
+			if (interceptorMapping.getName().equals(interceptorName)) {
+				assertEquals(((InterceptorForTestPurpose)interceptorMapping.getInterceptor()).getParamOne(), paramValue);
+				return;
+			}
+		}
+		fail();
+	}
+	
+	protected void assertInterceptorParamTwoEquals(ActionConfig actionConfig, String interceptorName, String paramValue) {
+		List interceptorMappings = actionConfig.getInterceptors();
+		for (Iterator i = interceptorMappings.iterator(); i.hasNext();) {
+			InterceptorMapping interceptorMapping = (InterceptorMapping) i.next();
+			assertNotNull(interceptorMapping.getInterceptor());
+			if (interceptorMapping.getName().equals(interceptorName)) {
+				assertEquals(((InterceptorForTestPurpose)interceptorMapping.getInterceptor()).getParamTwo(), paramValue);
+				return;
+			}
+		}
+		fail();
+	}
+	
+	protected void tearDown() throws Exception {
+		ConfigurationManager.clearConfigurationProviders();
+	}
+	
+}

src/test/com/opensymphony/xwork/config/providers/xwork-test-interceptor-stack-param-overriding.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE xwork PUBLIC
+    "-//OpenSymphony Group//XWork 1.1.1//EN"
+    "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
+
+<xwork>
+	<package name="packageOne">
+		<result-types>
+			<result-type name="mock" class="com.opensymphony.xwork.mock.MockResult" />
+		</result-types>
+	
+		<interceptors>
+			<interceptor name="interceptorOne" class="com.opensymphony.xwork.config.providers.InterceptorForTestPurpose" />
+			<interceptor name="interceptorTwo" class="com.opensymphony.xwork.config.providers.InterceptorForTestPurpose" />
+			<interceptor name="interceptorThree" class="com.opensymphony.xwork.config.providers.InterceptorForTestPurpose" />
+			
+			<interceptor-stack name="stackOne">
+				<interceptor-ref name="interceptorOne" />
+				<interceptor-ref name="interceptorTwo" />
+				<interceptor-ref name="interceptorThree" />
+			</interceptor-stack>
+			
+			<interceptor-stack name="stackTwo">
+				<interceptor-ref name="stackOne" />
+			</interceptor-stack>
+			
+			<interceptor-stack name="stackThree">
+				<interceptor-ref name="stackTwo" />
+			</interceptor-stack>
+			
+		</interceptors>
+		
+		<action name="actionOne">
+			<interceptor-ref name="stackTwo">
+				<param name="stackOne.interceptorOne.paramOne">i1p1</param>
+				<param name="stackOne.interceptorOne.paramTwo">i1p2</param>
+				<param name="stackOne.interceptorTwo.paramOne">i2p1</param>
+			</interceptor-ref>
+			<result name="success" type="mock">test1</result>
+		</action>
+		
+		<action name="actionTwo">
+			<interceptor-ref name="stackThree">
+				<param name="stackTwo.stackOne.interceptorThree.paramOne">i3p1</param>
+				<param name="stackTwo.stackOne.interceptorThree.paramTwo">i3p2</param>
+				<param name="stackTwo.stackOne.interceptorTwo.paramTwo">i2p2</param>
+			</interceptor-ref>
+			<result name="success" type="mock">test2</result>
+		</action>
+	</package>
+</xwork>    
+