diff --git a/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java b/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java index 06c81c0d8..7d4998392 100644 --- a/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java +++ b/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java @@ -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)); diff --git a/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java b/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java index f3ee54528..34d2febc4 100644 --- a/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java +++ b/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java @@ -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 ctxMap = new HashMap(); @@ -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); diff --git a/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java b/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java index 91727504f..d6a4c32df 100644 --- a/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java +++ b/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java @@ -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); diff --git a/plugins/struts1/pom.xml b/plugins/struts1/pom.xml index bd4eb24ef..e79202770 100644 --- a/plugins/struts1/pom.xml +++ b/plugins/struts1/pom.xml @@ -53,5 +53,28 @@ 0.09 test + + + + org.springframework + spring-mock + 1.2.8 + true + + + + org.springframework + spring-core + 1.2.8 + test + + + + javax.servlet + jsp-api + 2.0 + provided + + diff --git a/plugins/struts1/src/test/java/org/apache/struts2/s1/Struts1FactoryTest.java b/plugins/struts1/src/test/java/org/apache/struts2/s1/Struts1FactoryTest.java index d5ce4ae22..2fcde32f9 100644 --- a/plugins/struts1/src/test/java/org/apache/struts2/s1/Struts1FactoryTest.java +++ b/plugins/struts1/src/test/java/org/apache/struts2/s1/Struts1FactoryTest.java @@ -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);