mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Fixing tests
WW-1715 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@577775 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+4
-3
@@ -44,6 +44,7 @@ import junit.textui.TestRunner;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.portlet.PortletActionConstants;
|
||||
import org.easymock.EasyMock;
|
||||
import org.jmock.Mock;
|
||||
import org.jmock.cglib.MockObjectTestCase;
|
||||
import org.jmock.core.Constraint;
|
||||
@@ -133,7 +134,7 @@ public class Jsr168DispatcherTest extends MockObjectTestCase implements PortletA
|
||||
|
||||
initPortletConfig(initParams, new HashMap());
|
||||
initRequest(requestParams, new HashMap(), sessionMap, new HashMap(), PortletMode.VIEW, WindowState.NORMAL, false, null);
|
||||
setupActionFactory("/view", "testAction", "success", ValueStackFactory.getFactory().createValueStack());
|
||||
setupActionFactory("/view", "testAction", "success", EasyMock.createNiceMock(ValueStack.class));
|
||||
|
||||
mockInvocation.expects(once()).method("getStack").will(
|
||||
returnValue(null));
|
||||
@@ -165,7 +166,7 @@ public class Jsr168DispatcherTest extends MockObjectTestCase implements PortletA
|
||||
initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE, "true");
|
||||
initPortletConfig(initParams, new HashMap());
|
||||
initRequest(requestParams, new HashMap(), new HashMap(), new HashMap(), PortletMode.VIEW, WindowState.NORMAL, true, null);
|
||||
setupActionFactory("/view", "testAction", "success", ValueStackFactory.getFactory().createValueStack());
|
||||
setupActionFactory("/view", "testAction", "success", EasyMock.createNiceMock(ValueStack.class));
|
||||
//mockSession.expects(once()).method("setAttribute").with(new Constraint[]{eq(PortletActionConstants.LAST_MODE), eq(PortletMode.VIEW)});
|
||||
try {
|
||||
dispatcher
|
||||
@@ -266,7 +267,7 @@ public class Jsr168DispatcherTest extends MockObjectTestCase implements PortletA
|
||||
|
||||
initPortletConfig(initParams, new HashMap());
|
||||
initRequest(requestParams, new HashMap(), sessionMap, new HashMap(), mode, WindowState.NORMAL, false, null);
|
||||
setupActionFactory("/edit", "default", "success", ValueStackFactory.getFactory().createValueStack());
|
||||
setupActionFactory("/edit", "default", "success", EasyMock.createNiceMock(ValueStack.class));
|
||||
|
||||
mockInvocation.expects(once()).method("getStack").will(
|
||||
returnValue(null));
|
||||
|
||||
+9
-6
@@ -28,6 +28,7 @@ import javax.portlet.RenderRequest;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.dispatcher.DefaultActionSupport;
|
||||
import org.apache.struts2.portlet.PortletActionConstants;
|
||||
import org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction;
|
||||
@@ -38,11 +39,12 @@ import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
|
||||
public class PortletStateInterceptorTest extends TestCase implements PortletActionConstants {
|
||||
public class PortletStateInterceptorTest extends StrutsTestCase implements PortletActionConstants {
|
||||
|
||||
private PortletStateInterceptor interceptor;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
interceptor = new PortletStateInterceptor();
|
||||
}
|
||||
|
||||
@@ -60,7 +62,7 @@ public class PortletStateInterceptorTest extends TestCase implements PortletActi
|
||||
EasyMock.expect(invocation.getInvocationContext()).andStubReturn(ctx);
|
||||
actionResponse.setRenderParameter(EVENT_ACTION, "true");
|
||||
|
||||
ValueStack stack = ValueStackFactory.getFactory().createValueStack();
|
||||
ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
EasyMock.expect(invocation.getStack()).andStubReturn(stack);
|
||||
|
||||
EasyMock.replay(actionResponse);
|
||||
@@ -79,10 +81,11 @@ public class PortletStateInterceptorTest extends TestCase implements PortletActi
|
||||
RenderRequest renderRequest = EasyMock.createNiceMock(RenderRequest.class);
|
||||
ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
|
||||
|
||||
ValueStack eventPhaseStack = ValueStackFactory.getFactory().createValueStack();
|
||||
|
||||
ValueStack eventPhaseStack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
eventPhaseStack.set("testKey", "testValue");
|
||||
|
||||
ValueStack currentStack = ValueStackFactory.getFactory().createValueStack();
|
||||
ValueStack currentStack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
currentStack.set("anotherTestKey", "anotherTestValue");
|
||||
|
||||
Map<String, Object> ctxMap = new HashMap<String, Object>();
|
||||
@@ -118,10 +121,10 @@ public class PortletStateInterceptorTest extends TestCase implements PortletActi
|
||||
RenderRequest renderRequest = EasyMock.createNiceMock(RenderRequest.class);
|
||||
ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
|
||||
|
||||
ValueStack eventPhaseStack = ValueStackFactory.getFactory().createValueStack();
|
||||
ValueStack eventPhaseStack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
eventPhaseStack.set("testKey", "testValue");
|
||||
|
||||
ValueStack currentStack = ValueStackFactory.getFactory().createValueStack();
|
||||
ValueStack currentStack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
currentStack.set("anotherTestKey", "anotherTestValue");
|
||||
|
||||
EasyMock.expect(invocation.getStack()).andStubReturn(currentStack);
|
||||
|
||||
@@ -86,7 +86,10 @@ public class PortletUrlTagTest extends MockObjectTestCase {
|
||||
|
||||
mockPortletApiAvailable();
|
||||
|
||||
stack = ValueStackFactory.getFactory().createValueStack();
|
||||
stack = du.getContainer().getInstance(ValueStackFactory.class).createValueStack();
|
||||
stack.getContext().put(ActionContext.CONTAINER, du.getContainer());
|
||||
ActionContext.setContext(new ActionContext(stack.getContext()));
|
||||
|
||||
|
||||
|
||||
mockHttpReq = mock(HttpServletRequest.class);
|
||||
|
||||
@@ -53,5 +53,28 @@
|
||||
<version>0.09</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Mocks for unit testing (by Spring) -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-mock</artifactId>
|
||||
<version>1.2.8</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>1.2.8</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.apache.struts.config.ActionConfig;
|
||||
import org.apache.struts.config.ExceptionConfig;
|
||||
import org.apache.struts.config.ForwardConfig;
|
||||
import org.apache.struts.config.ModuleConfig;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.config.StrutsXmlConfigurationProvider;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
@@ -46,31 +47,21 @@ import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
/**
|
||||
* Test of Struts1Factory, which creates Struts 1.x wrappers around XWork config objects.
|
||||
*/
|
||||
public class Struts1FactoryTest extends TestCase {
|
||||
public class Struts1FactoryTest extends StrutsTestCase {
|
||||
|
||||
private static final String PACKAGE_NAME = "org/apache/struts2/s1";
|
||||
|
||||
protected Struts1Factory factory = null;
|
||||
protected Configuration config;
|
||||
|
||||
public Struts1FactoryTest(String name) throws Exception {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
junit.textui.TestRunner.run(Struts1FactoryTest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up instance variables required by this test case.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void setUp() {
|
||||
ConfigurationManager manager = new ConfigurationManager();
|
||||
StrutsXmlConfigurationProvider provider = new StrutsXmlConfigurationProvider(PACKAGE_NAME + "/test-struts-factory.xml", true, null);
|
||||
manager.addConfigurationProvider(provider);
|
||||
config = manager.getConfiguration();
|
||||
factory = new Struts1Factory(config);
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
loadConfigurationProviders(new StrutsXmlConfigurationProvider(PACKAGE_NAME + "/test-struts-factory.xml", true, null));
|
||||
factory = new Struts1Factory(configuration);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +112,7 @@ public class Struts1FactoryTest extends TestCase {
|
||||
* The ActionConfig is loaded from test-struts-factory.xml.
|
||||
*/
|
||||
public void testCreateActionMapping() {
|
||||
PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME);
|
||||
PackageConfig packageConfig = configuration.getPackageConfig(PACKAGE_NAME);
|
||||
com.opensymphony.xwork2.config.entities.ActionConfig actionConfig =
|
||||
(com.opensymphony.xwork2.config.entities.ActionConfig) packageConfig.getActionConfigs().get("action1");
|
||||
ActionMapping mapping = factory.createActionMapping(actionConfig);
|
||||
@@ -179,7 +170,7 @@ public class Struts1FactoryTest extends TestCase {
|
||||
* The ResultConfig is loaded from test-struts-factory.xml.
|
||||
*/
|
||||
public void testCreateActionForward() {
|
||||
PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME);
|
||||
PackageConfig packageConfig = configuration.getPackageConfig(PACKAGE_NAME);
|
||||
ResultConfig resultConfig = (ResultConfig) packageConfig.getGlobalResultConfigs().get("globalResult");
|
||||
ActionForward fwd = factory.createActionForward(resultConfig);
|
||||
assertNotNull(fwd);
|
||||
@@ -196,7 +187,7 @@ public class Struts1FactoryTest extends TestCase {
|
||||
* The ExceptionConfig is loaded from test-struts-factory.xml.
|
||||
*/
|
||||
public void testCreateExceptionConfig() {
|
||||
PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME);
|
||||
PackageConfig packageConfig = configuration.getPackageConfig(PACKAGE_NAME);
|
||||
ExceptionMappingConfig cfg = (ExceptionMappingConfig) packageConfig.getGlobalExceptionMappingConfigs().get(0);
|
||||
ExceptionConfig exceptionConfig = factory.createExceptionConfig(cfg);
|
||||
assertNotNull(exceptionConfig);
|
||||
|
||||
Reference in New Issue
Block a user