Commits

Anonymous committed cef6c06

Some improved unit tests of interceptors
Issue number: XW-348
Obtained from:
Submitted by: Claus Ibsen
Reviewed by: Rainer Hermanns

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@853e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

src/test/com/opensymphony/xwork/interceptor/AliasInterceptorTest.java

 /*
- * Copyright (c) 2002-2003 by OpenSymphony
+ * Copyright (c) 2002-2006 by OpenSymphony
  * All rights reserved.
- */
+*/
 package com.opensymphony.xwork.interceptor;
 
-import com.opensymphony.xwork.ActionProxy;
-import com.opensymphony.xwork.ActionProxyFactory;
-import com.opensymphony.xwork.SimpleAction;
-import com.opensymphony.xwork.XWorkTestCase;
+import com.opensymphony.xwork.*;
+import com.opensymphony.xwork.config.entities.ActionConfig;
 
 import java.util.HashMap;
 import java.util.Map;
  *         </action>
  */
 public class AliasInterceptorTest extends XWorkTestCase {
-    public void testAliasPropertiesCopied() throws Exception {
+
+    public void testUsingDefaultInterceptorThatAliasPropertiesAreCopied() throws Exception {
         Map params = new HashMap();
         params.put("aliasSource", "source here");
 
         ActionProxy proxy = factory.createActionProxy("", "aliasTest", params);
         SimpleAction actionOne = (SimpleAction) proxy.getAction();
         actionOne.setAliasSource("name to be copied");
-        System.out.println(proxy.execute());
+        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();
+        Map params = new HashMap();
+        params.put("aliases", "invalid alias expression");
+        cfg.setParams(params);
+        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();
+        Map params = new HashMap();
+        params.put("hello", "invalid alias expression");
+        cfg.setParams(params);
+        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();
+        Map params = new HashMap();
+        params.put("hello", "invalid alias expression");
+        cfg.setParams(params);
+        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();
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
     }

src/test/com/opensymphony/xwork/interceptor/ExceptionMappingInterceptorTest.java

+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+*/
 package com.opensymphony.xwork.interceptor;
 
 import com.mockobjects.dynamic.Mock;
         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 {