Author: mcucchiara
Date: Mon Aug 15 17:48:07 2011
New Revision: 1157925
URL: http://svn.apache.org/viewvc?rev=1157925&view=rev
Log:
* Exposed getConfigPath method in order to use custom struts.xml file.
* Renamed JUnitTestAction
Added:
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JUnitTestAction.java
(contents, props changed)
- copied, changed from r1157665,
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JunitTestAction.java
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java
(with props)
struts/struts2/trunk/plugins/junit/src/test/resources/struts-test.xml
(with props)
struts/struts2/trunk/plugins/junit/src/test/resources/template2.ftl (with
props)
Removed:
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JunitTestAction.java
Modified:
struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringJUnit4TestCaseTest.java
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringTestCaseTest.java
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsTestCaseTest.java
struts/struts2/trunk/plugins/junit/src/test/resources/applicationContext.xml
struts/struts2/trunk/plugins/junit/src/test/resources/struts.xml
Modified:
struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java?rev=1157925&r1=1157924&r2=1157925&view=diff
==
---
struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java
(original)
+++
struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java
Mon Aug 15 17:48:07 2011
@@ -27,6 +27,7 @@ import com.opensymphony.xwork2.intercept
import com.opensymphony.xwork2.interceptor.annotations.Before;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import com.opensymphony.xwork2.util.logging.jdk.JdkLoggerFactory;
+import org.apache.commons.lang.StringUtils;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
@@ -45,11 +46,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Formatter;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
+import java.util.logging.*;
import static org.junit.Assert.assertNotNull;
@@ -101,6 +98,7 @@ public abstract class StrutsJUnit4TestCa
/**
* gets an object from the stack after an action is executed
+ *
* @return The executed action
*/
@SuppressWarnings("unchecked")
@@ -110,7 +108,7 @@ public abstract class StrutsJUnit4TestCa
protected boolean containsErrors() {
T action = this.getAction();
-if(action instanceof ValidationAware) {
+if (action instanceof ValidationAware) {
return ((ValidationAware) action).hasActionErrors();
}
throw new UnsupportedOperationException("Current action does not
implement ValidationAware interface");
@@ -152,7 +150,7 @@ public abstract class StrutsJUnit4TestCa
namespace, name, method, new HashMap(), true,
false);
ActionContext invocationContext =
proxy.getInvocation().getInvocationContext();
-invocationContext.setParameters(new
HashMap(request.getParameterMap()));
+invocationContext.setParameters(new HashMap(request.getParameterMap()));
// set the action context to the one used by the proxy
ActionContext.setContext(invocationContext);
@@ -211,9 +209,17 @@ public abstract class StrutsJUnit4TestCa
super.setUp();
initServletMockObjects();
setupBeforeInitDispatcher();
+initDispatcherParams();
initDispatcher(dispatcherInitParams);
}
+protected void initDispatcherParams() {
+if (StringUtils.isNotBlank(getConfigPath())) {
+dispatcherInitParams = new HashMap();
+dispatcherInitParams.put("config", "struts-default.xml," +
getConfigPath());
+}
+}
+
protected Dispatcher initDispatcher(Map params) {
Dispatcher du = StrutsTestCaseHelper.initDispatcher(servletContext,
params);
configurationManager = du.getConfigurationManager();
@@ -222,6 +228,10 @@ public abstract class StrutsJUnit4TestCa
return du;
}
+protected String getConfigPath() {
+return null;
+}
+
@After
public void tearDown() throws