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<String, Object>(), true, false); ActionContext invocationContext = proxy.getInvocation().getInvocationContext(); - invocationContext.setParameters(new HashMap<String,Object>(request.getParameterMap())); + invocationContext.setParameters(new HashMap<String, Object>(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<String, String>(); + dispatcherInitParams.put("config", "struts-default.xml," + getConfigPath()); + } + } + protected Dispatcher initDispatcher(Map<String, String> 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 Exception { Copied: struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JUnitTestAction.java (from r1157665, struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JunitTestAction.java) URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JUnitTestAction.java?p2=struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JUnitTestAction.java&p1=struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JunitTestAction.java&r1=1157665&r2=1157925&rev=1157925&view=diff ============================================================================== --- struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JunitTestAction.java (original) +++ struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JUnitTestAction.java Mon Aug 15 17:48:07 2011 @@ -22,7 +22,7 @@ package org.apache.struts2; import com.opensymphony.xwork2.ActionSupport; -public class JunitTestAction extends ActionSupport { +public class JUnitTestAction extends ActionSupport { private String name; public String getName() { Propchange: struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/JUnitTestAction.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java?rev=1157925&view=auto ============================================================================== --- struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java (added) +++ struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java Mon Aug 15 17:48:07 2011 @@ -0,0 +1,43 @@ +/* + * $Id: $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.struts2; + +import org.junit.Assert; +import org.junit.Test; + +/** + * User: maurizio cucchiara + * Date: 8/15/11 + * Time: 7:04 PM + */ +public class StrutsJUnit4TestCaseTest extends StrutsJUnit4TestCase<JUnitTestAction>{ + @Test + public void testExecuteActionAgainstCustomStrutsConfigFile() throws Exception { + String output = executeAction("/test2/testAction2.action"); + Assert.assertEquals("Test2", output); + } + + @Override + protected String getConfigPath() { + return "struts-test.xml"; + } +} Propchange: struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsJUnit4TestCaseTest.java ------------------------------------------------------------------------------ svn:keywords = Modified: struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringJUnit4TestCaseTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringJUnit4TestCaseTest.java?rev=1157925&r1=1157924&r2=1157925&view=diff ============================================================================== --- struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringJUnit4TestCaseTest.java (original) +++ struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringJUnit4TestCaseTest.java Mon Aug 15 17:48:07 2011 @@ -34,8 +34,8 @@ import java.io.UnsupportedEncodingExcept @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath*:applicationContext.xml"}) -public class StrutsSpringJUnit4TestCaseTest extends StrutsSpringJUnit4TestCase<JunitTestAction> { - +public class StrutsSpringJUnit4TestCaseTest extends StrutsSpringJUnit4TestCase<JUnitTestAction> { + @Test public void getActionMapping() { ActionMapping mapping = getActionMapping("/test/testAction.action"); @@ -52,7 +52,7 @@ public class StrutsSpringJUnit4TestCaseT ActionProxy proxy = getActionProxy("/test/testAction.action"); Assert.assertNotNull(proxy); - JunitTestAction action = (JunitTestAction) proxy.getAction(); + JUnitTestAction action = (JUnitTestAction) proxy.getAction(); Assert.assertNotNull(action); String result = proxy.execute(); Modified: struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringTestCaseTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringTestCaseTest.java?rev=1157925&r1=1157924&r2=1157925&view=diff ============================================================================== --- struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringTestCaseTest.java (original) +++ struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsSpringTestCaseTest.java Mon Aug 15 17:48:07 2011 @@ -23,7 +23,7 @@ package org.apache.struts2; public class StrutsSpringTestCaseTest extends StrutsSpringTestCase { public void testApplicationContext() { assertNotNull(applicationContext); - JunitTestAction action = (JunitTestAction) applicationContext.getBean("testAction"); + JUnitTestAction action = (JUnitTestAction) applicationContext.getBean("testAction"); assertNotNull(action); } } Modified: struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsTestCaseTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsTestCaseTest.java?rev=1157925&r1=1157924&r2=1157925&view=diff ============================================================================== --- struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsTestCaseTest.java (original) +++ struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsTestCaseTest.java Mon Aug 15 17:48:07 2011 @@ -42,7 +42,7 @@ public class StrutsTestCaseTest extends ActionProxy proxy = getActionProxy("/test/testAction.action"); assertNotNull(proxy); - JunitTestAction action = (JunitTestAction) proxy.getAction(); + JUnitTestAction action = (JUnitTestAction) proxy.getAction(); assertNotNull(action); String result = proxy.execute(); Modified: struts/struts2/trunk/plugins/junit/src/test/resources/applicationContext.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/resources/applicationContext.xml?rev=1157925&r1=1157924&r2=1157925&view=diff ============================================================================== --- struts/struts2/trunk/plugins/junit/src/test/resources/applicationContext.xml (original) +++ struts/struts2/trunk/plugins/junit/src/test/resources/applicationContext.xml Mon Aug 15 17:48:07 2011 @@ -2,5 +2,5 @@ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - <bean id="testAction" class="org.apache.struts2.JunitTestAction"/> + <bean id="testAction" class="org.apache.struts2.JUnitTestAction"/> </beans> \ No newline at end of file Added: struts/struts2/trunk/plugins/junit/src/test/resources/struts-test.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/resources/struts-test.xml?rev=1157925&view=auto ============================================================================== --- struts/struts2/trunk/plugins/junit/src/test/resources/struts-test.xml (added) +++ struts/struts2/trunk/plugins/junit/src/test/resources/struts-test.xml Mon Aug 15 17:48:07 2011 @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<!-- + ~ $Id$ + ~ + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<!DOCTYPE struts PUBLIC + "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" + "http://struts.apache.org/dtds/struts-2.1.dtd"> + +<struts> + <package name="test2" namespace="/test2" extends="struts-default"> + <action name="testAction2" class="org.apache.struts2.JUnitTestAction"> + <result type="freemarker">/template2.ftl</result> + </action> + </package> +</struts> Propchange: struts/struts2/trunk/plugins/junit/src/test/resources/struts-test.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: struts/struts2/trunk/plugins/junit/src/test/resources/struts.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/resources/struts.xml?rev=1157925&r1=1157924&r2=1157925&view=diff ============================================================================== --- struts/struts2/trunk/plugins/junit/src/test/resources/struts.xml (original) +++ struts/struts2/trunk/plugins/junit/src/test/resources/struts.xml Mon Aug 15 17:48:07 2011 @@ -7,7 +7,7 @@ <struts> <constant name="struts.objectFactory" value="spring"/> <package name="test" namespace="/test" extends="struts-default"> - <action name="testAction" class="org.apache.struts2.JunitTestAction"> + <action name="testAction" class="org.apache.struts2.JUnitTestAction"> <result type="freemarker">/template.ftl</result> </action> </package> Added: struts/struts2/trunk/plugins/junit/src/test/resources/template2.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/resources/template2.ftl?rev=1157925&view=auto ============================================================================== --- struts/struts2/trunk/plugins/junit/src/test/resources/template2.ftl (added) +++ struts/struts2/trunk/plugins/junit/src/test/resources/template2.ftl Mon Aug 15 17:48:07 2011 @@ -0,0 +1 @@ +Test2 \ No newline at end of file Propchange: struts/struts2/trunk/plugins/junit/src/test/resources/template2.ftl ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL