Anonymous avatar Anonymous committed 4e6c689

Fixed unit test for object dispatcher

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

Comments (0)

Files changed (5)

src/test/com/opensymphony/xwork/dispatcher/ActionTest.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.dispatcher;
-
-import com.opensymphony.xwork.ActionSupport;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-/**
- * Test action for object dispatching
- * @author <a href="mailto:yellek@dev.java.net">Peter Kelley</a>
- */
-public class ActionTest extends ActionSupport {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    /** logger for this class */
-    protected Log log = LogFactory.getLog(ActionTest.class);
-
-    /** blah text property */
-    private String blah;
-
-    //~ Constructors ///////////////////////////////////////////////////////////
-
-    public ActionTest() {
-    }
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    /**
-     * Setter for property blah.
-     * @param newBlah the new value for field blah
-     */
-    public void setBlah(String newBlah) {
-        blah = newBlah;
-    }
-
-    /**
-     * Getter for property blah.
-     * @return the value of field blah
-     */
-    public String getBlah() {
-        return blah;
-    }
-
-    /**
-     * This methodName is where the logic of the action is executed.
-     *
-     * @return a string representing the logical result of the execution. See constants in this
-     *   interface for a list of standard result values.
-     * @throws Exception thrown if a system level exception occurs. Application level exceptions
-     *   should be handled by returning an error value, such as Action.ERROR.
-     * @todo Implement this com.opensymphony.xwork.Action method
-     */
-    public String execute() throws Exception {
-        if (log.isDebugEnabled()) {
-            log.debug("Blah was " + getBlah());
-        }
-
-        return SUCCESS;
-    }
-}

src/test/com/opensymphony/xwork/dispatcher/ObjectDispatcherTest.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.dispatcher;
+
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+import junit.framework.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * test the object dispatcher
+ * @authorPeter Kelley
+ */
+public class ObjectDispatcherTest extends TestCase implements MappingFactory, ResultObjectFactory {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private ObjectDispatcher objectDispatcher = null;
+    private String bar = "bar";
+    private String foo = "foo";
+    private String foobar = "something else";
+
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    /**
+* default constructor
+* @param name The name of the test fixture
+*/
+    public ObjectDispatcherTest(String name) {
+        super(name);
+    }
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    /**
+* Setter for property bar.
+* @param newBar the new value for field bar
+*/
+    public void setBar(String newBar) {
+        bar = newBar;
+    }
+
+    /**
+* Getter for property bar.
+* @return the value of field bar
+*/
+    public String getBar() {
+        return bar;
+    }
+
+    /**
+* Setter for property foo.
+* @param newFoo the new value for field foo
+*/
+    public void setFoo(String newFoo) {
+        foo = newFoo;
+    }
+
+    /**
+* Getter for property foo.
+* @return the value of field foo
+*/
+    public String getFoo() {
+        return foo;
+    }
+
+    /**
+* Setter for property foobar.
+* @param newFoobar the new value for field foobar
+*/
+    public void setFoobar(String newFoobar) {
+        foobar = newFoobar;
+    }
+
+    /**
+* Getter for property foobar.
+* @return the value of field foobar
+*/
+    public String getFoobar() {
+        return foobar;
+    }
+
+    /**
+* Get a mapping set with the given name.
+*
+* @param name The name of the mapping set to get
+* @return Either the mapping set with the given name or <code>null</code> if no mapping set
+*   exists with that name
+*/
+    public MappingSet getMappingSet(String name) {
+        MappingSet mappingSet = new MappingSet(name);
+
+        Mapping newMapping = new Mapping("blah", "foo + bar");
+        List parameterList = new ArrayList();
+        parameterList.add(newMapping);
+        mappingSet.setParameterMappings(parameterList);
+
+        Mapping resultMapping = new Mapping("blah", "foobar");
+        List resultList = new ArrayList();
+        resultList.add(resultMapping);
+        mappingSet.setResultMappings(resultList);
+
+        return mappingSet;
+    }
+
+    /**
+* Get the result object
+* @param key The key of the object to get (ignored)
+* @return this
+*/
+    public Object getResultObject(String key) {
+        return this;
+    }
+
+    /**
+* Test dispatching from an object
+* @throws Exception
+*/
+    public void testDispatch() throws Exception {
+        String namespace = "";
+        String action = "TestObjectDispatcher";
+        String mappingName = "dispatch1";
+        ResultObjectFactory resultObjectFactory = this;
+        OgnlValueStack result = objectDispatcher.dispatch(this, namespace, action, mappingName, resultObjectFactory);
+        assertEquals("Value returned was incorrect", getFoo() + getBar(), result.findValue("blah"));
+        assertEquals("Value on result not set correctly", getFoo() + getBar(), getFoobar());
+    }
+
+    /**
+* set up for a test
+* @throws Exception if something bad happens
+*/
+    protected void setUp() throws Exception {
+        super.setUp();
+        objectDispatcher = new ObjectDispatcher(this);
+    }
+
+    /**
+* clean up after a test
+* @throws Exception if something bad happens
+*/
+    protected void tearDown() throws Exception {
+        objectDispatcher = null;
+        super.tearDown();
+    }
+}

src/test/com/opensymphony/xwork/dispatcher/ObjectTestAction.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.dispatcher;
+
+import com.opensymphony.xwork.ActionSupport;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * Test action for object dispatching
+ * @author <a href="mailto:yellek@dev.java.net">Peter Kelley</a>
+ */
+public class ObjectTestAction extends ActionSupport {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    /** logger for this class */
+    protected Log log = LogFactory.getLog(ObjectTestAction.class);
+
+    /** blah text property */
+    private String blah;
+
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    public ObjectTestAction() {
+    }
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    /**
+ * Setter for property blah.
+ * @param newBlah the new value for field blah
+ */
+    public void setBlah(String newBlah) {
+        blah = newBlah;
+    }
+
+    /**
+ * Getter for property blah.
+ * @return the value of field blah
+ */
+    public String getBlah() {
+        return blah;
+    }
+
+    /**
+ * This methodName is where the logic of the action is executed.
+ *
+ * @return a string representing the logical result of the execution. See constants in this
+ *   interface for a list of standard result values.
+ * @throws Exception thrown if a system level exception occurs. Application level exceptions
+ *   should be handled by returning an error value, such as Action.ERROR.
+ * @todo Implement this com.opensymphony.xwork.Action method
+ */
+    public String execute() throws Exception {
+        if (log.isDebugEnabled()) {
+            log.debug("Blah was " + getBlah());
+        }
+
+        return SUCCESS;
+    }
+}

src/test/com/opensymphony/xwork/dispatcher/TestObjectDispatcher.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.dispatcher;
-
-import com.opensymphony.xwork.util.OgnlValueStack;
-
-import junit.framework.*;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * test the object dispatcher
- * @authorPeter Kelley
- */
-public class TestObjectDispatcher extends TestCase implements MappingFactory, ResultObjectFactory {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    private ObjectDispatcher objectDispatcher = null;
-    private String bar = "bar";
-    private String foo = "foo";
-    private String foobar = "something else";
-
-    //~ Constructors ///////////////////////////////////////////////////////////
-
-    /**
-     * default constructor
-     * @param name The name of the test fixture
-     */
-    public TestObjectDispatcher(String name) {
-        super(name);
-    }
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    /**
-     * Setter for property bar.
-     * @param newBar the new value for field bar
-     */
-    public void setBar(String newBar) {
-        bar = newBar;
-    }
-
-    /**
-     * Getter for property bar.
-     * @return the value of field bar
-     */
-    public String getBar() {
-        return bar;
-    }
-
-    /**
-     * Setter for property foo.
-     * @param newFoo the new value for field foo
-     */
-    public void setFoo(String newFoo) {
-        foo = newFoo;
-    }
-
-    /**
-     * Getter for property foo.
-     * @return the value of field foo
-     */
-    public String getFoo() {
-        return foo;
-    }
-
-    /**
-     * Setter for property foobar.
-     * @param newFoobar the new value for field foobar
-     */
-    public void setFoobar(String newFoobar) {
-        foobar = newFoobar;
-    }
-
-    /**
-     * Getter for property foobar.
-     * @return the value of field foobar
-     */
-    public String getFoobar() {
-        return foobar;
-    }
-
-    /**
-     * Get a mapping set with the given name.
-     *
-     * @param name The name of the mapping set to get
-     * @return Either the mapping set with the given name or <code>null</code> if no mapping set
-     *   exists with that name
-     */
-    public MappingSet getMappingSet(String name) {
-        MappingSet mappingSet = new MappingSet(name);
-
-        Mapping newMapping = new Mapping("blah", "foo + bar");
-        List parameterList = new ArrayList();
-        parameterList.add(newMapping);
-        mappingSet.setParameterMappings(parameterList);
-
-        Mapping resultMapping = new Mapping("blah", "foobar");
-        List resultList = new ArrayList();
-        resultList.add(resultMapping);
-        mappingSet.setResultMappings(resultList);
-
-        return mappingSet;
-    }
-
-    /**
-     * Get the result object
-     * @param key The key of the object to get (ignored)
-     * @return this
-     */
-    public Object getResultObject(String key) {
-        return this;
-    }
-
-    /**
-     * Test dispatching from an object
-     * @throws Exception
-     */
-    public void testDispatch() throws Exception {
-        String namespace = "";
-        String action = "test";
-        String mappingName = "dispatch1";
-        ResultObjectFactory resultObjectFactory = this;
-        OgnlValueStack result = objectDispatcher.dispatch(this, namespace, action, mappingName, resultObjectFactory);
-        assertEquals("Value returned was incorrect", getFoo() + getBar(), result.findValue("blah"));
-        assertEquals("Value on result not set correctly", getFoo() + getBar(), getFoobar());
-    }
-
-    /**
-     * set up for a test
-     * @throws Exception if something bad happens
-     */
-    protected void setUp() throws Exception {
-        super.setUp();
-        objectDispatcher = new ObjectDispatcher(this);
-    }
-
-    /**
-     * clean up after a test
-     * @throws Exception if something bad happens
-     */
-    protected void tearDown() throws Exception {
-        objectDispatcher = null;
-        super.tearDown();
-    }
-}

src/test/xwork.xml

 <xwork>
     <include file="xwork-default.xml"/>
     <package name="default" extends="xwork-default" externalReferenceResolver="com.opensymphony.xwork.config.TestExternalReferenceResolver">
+        <result-types>
+            <result-type name="object" class="com.opensymphony.xwork.dispatcher.ObjectResult"/>
+        </result-types>
+
         <global-results>
             <result name="login"> <!-- should be chain type since it is the default -->
                 <param name="actionName">login</param>
         </action>
         <!-- test resolution  -->
         <action name="TestExternalRefResolver" class="com.opensymphony.xwork.ExternalReferenceAction">
-        	<external-ref name="foo">myFoo</external-ref>
+                <external-ref name="foo">myFoo</external-ref>
             <interceptor-ref name="debugStack"/>
             <interceptor-ref name="defaultStack"/>
         </action>
         <!-- test required flag -->
         <action name="TestExternalRefResolver2" class="com.opensymphony.xwork.ExternalReferenceAction">
-        	<external-ref name="foo">myFoo</external-ref>
-        	<external-ref required="false" name="does_not_exist">Does Not Exist</external-ref>
+                <external-ref name="foo">myFoo</external-ref>
+                <external-ref required="false" name="does_not_exist">Does Not Exist</external-ref>
             <interceptor-ref name="debugStack"/>
             <interceptor-ref name="defaultStack"/>
         </action>
         <!-- test where required reference is not found -->
         <action name="TestExternalRefResolver3" class="com.opensymphony.xwork.ExternalReferenceAction">
-        	<external-ref required="true" name="Boo">myBoo</external-ref>
+                <external-ref required="true" name="Boo">myBoo</external-ref>
             <interceptor-ref name="debugStack"/>
             <interceptor-ref name="defaultStack"/>
         </action>
-        
+
         <!-- chain resursion detection -->
         <action name="InfiniteRecursionChain" class="com.opensymphony.xwork.ActionSupport">
-        	<result name="success" type="chain">InfiniteRecursionChain</result>
+                <result name="success" type="chain">InfiniteRecursionChain</result>
+        </action>
+
+        <action name="TestObjectDispatcher" class="com.opensymphony.xwork.dispatcher.ObjectTestAction">
+            <result name="success" type="object">
+                    <param name="mappingName">test</param>
+                    <param name="viewName">test</param>
+            </result>
+            <interceptor-ref name="defaultStack"/>
         </action>
-        
-   	</package>
-   	
-   	<package name="test-external-refs" extends="default" namespace="test/externalRef/">
+
+   </package>
+
+           <package name="test-external-refs" extends="default" namespace="test/externalRef/">
         <!-- test resolution when Resolver is declared on parent -->
         <action name="TestExternalRefResolver4" class="com.opensymphony.xwork.ExternalReferenceAction">
-        	<external-ref name="foo">myFoo</external-ref>
+                <external-ref name="foo">myFoo</external-ref>
             <interceptor-ref name="defaultStack"/>
         </action>
+
    </package>
 
     <package name="bar" extends="default" namespace="/foo/bar">
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.