Anonymous avatar Anonymous committed ec82636

improved unit test and fixed to use unix line break

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

Comments (0)

Files changed (3)

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

 
 
 /**
- * Test AbstractLifecycleLister.
+ * Unit test for {@link AbstractLifecycleInterceptor}.
  * 
  * @author tm_jee
  * @version $Date$ $Id$

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

+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.interceptor;
+
+import com.opensymphony.xwork.XWorkTestCase;
+import com.opensymphony.xwork.SimpleFooAction;
+import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.config.entities.Parameterizable;
+import com.opensymphony.xwork.config.entities.ActionConfig;
+import com.opensymphony.xwork.mock.MockActionInvocation;
+import com.opensymphony.xwork.mock.MockActionProxy;
+import com.mockobjects.dynamic.Mock;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Unit test of {@link StaticParametersInterceptor}.
+ *
+ * @author Claus Ibsen
+ */
+public class StaticParametersInterceptorTest extends XWorkTestCase {
+
+    private StaticParametersInterceptor interceptor;
+
+    public void testParameterizable() throws Exception {
+        Mock mock = new Mock(Parameterizable.class);
+
+        MockActionInvocation mai = new MockActionInvocation();
+        MockActionProxy map = new MockActionProxy();
+        ActionConfig ac = new ActionConfig();
+
+        Map params = new HashMap();
+        ac.setParams(params);
+
+        map.setConfig(ac);
+        mai.setProxy(map);
+        mai.setAction(mock.proxy());
+        mock.expect("setParams", params);
+
+        interceptor.intercept(mai);
+        mock.verify();
+    }
+
+    public void testNoParameters() throws Exception {
+        MockActionInvocation mai = new MockActionInvocation();
+        MockActionProxy map = new MockActionProxy();
+        ActionConfig ac = new ActionConfig();
+
+        ac.setParams(null);
+        map.setConfig(ac);
+        mai.setProxy(map);
+        mai.setAction(new SimpleFooAction());
+
+        int before = ActionContext.getContext().getValueStack().size();
+        interceptor.intercept(mai);
+
+        assertEquals(before, ActionContext.getContext().getValueStack().size());
+    }
+
+    public void testWithOneParameters() throws Exception {
+        MockActionInvocation mai = new MockActionInvocation();
+        MockActionProxy map = new MockActionProxy();
+        ActionConfig ac = new ActionConfig();
+
+        Map params = new HashMap();
+        params.put("top.name", "Santa");
+        ac.setParams(params);
+        map.setConfig(ac);
+        mai.setProxy(map);
+        mai.setAction(new SimpleFooAction());
+
+        User user = new User();
+        ActionContext.getContext().getValueStack().push(user);
+        int before = ActionContext.getContext().getValueStack().size();
+        interceptor.intercept(mai);
+
+        assertEquals(before, ActionContext.getContext().getValueStack().size());
+        assertEquals("Santa", user.getName());
+    }
+
+    public void testWithOneParametersParse() throws Exception {
+        MockActionInvocation mai = new MockActionInvocation();
+        MockActionProxy map = new MockActionProxy();
+        ActionConfig ac = new ActionConfig();
+
+        Map params = new HashMap();
+        params.put("top.name", "${top.hero}");
+        ac.setParams(params);
+        map.setConfig(ac);
+        mai.setProxy(map);
+        mai.setAction(new SimpleFooAction());
+
+        User user = new User();
+        ActionContext.getContext().getValueStack().push(user);
+        int before = ActionContext.getContext().getValueStack().size();
+        interceptor.setParse("true");
+        interceptor.intercept(mai);
+
+        assertEquals(before, ActionContext.getContext().getValueStack().size());
+        assertEquals("Superman", user.getName());
+    }
+
+    public void testWithOneParametersNoParse() throws Exception {
+        MockActionInvocation mai = new MockActionInvocation();
+        MockActionProxy map = new MockActionProxy();
+        ActionConfig ac = new ActionConfig();
+
+        Map params = new HashMap();
+        params.put("top.name", "${top.hero}");
+        ac.setParams(params);
+        map.setConfig(ac);
+        mai.setProxy(map);
+        mai.setAction(new SimpleFooAction());
+
+        User user = new User();
+        ActionContext.getContext().getValueStack().push(user);
+        int before = ActionContext.getContext().getValueStack().size();
+        interceptor.setParse("false");
+        interceptor.intercept(mai);
+
+        assertEquals(before, ActionContext.getContext().getValueStack().size());
+        assertEquals("${top.hero}", user.getName());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        interceptor = new StaticParametersInterceptor();
+        interceptor.init();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        interceptor.destroy();
+    }
+
+    private class User {
+        private String name;
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getHero() {
+            return "Superman";
+        }
+    }
+
+}

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

 
     public void testInvalidLogLevel() throws Exception {
         TimerInterceptor real = new TimerInterceptor();
-        real.setLogLevel("xxx");
+        real.setLogLevel("xxxx");
         real.init();
         try {
             real.intercept(mai);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.