use of com.mockobjects.dynamic.Mock in project struts by apache.
the class ConfigurationTest method testMultipleContainerProviders.
public void testMultipleContainerProviders() throws Exception {
// to start from scratch
configurationManager.destroyConfiguration();
// to build basic configuration
configurationManager.getConfiguration();
Mock mockContainerProvider = new Mock(ContainerProvider.class);
mockContainerProvider.expect("init", C.ANY_ARGS);
mockContainerProvider.expect("register", C.ANY_ARGS);
mockContainerProvider.matchAndReturn("equals", C.ANY_ARGS, false);
mockContainerProvider.matchAndReturn("toString", "foo");
mockContainerProvider.matchAndReturn("destroy", null);
mockContainerProvider.expectAndReturn("needsReload", true);
// the order of providers must be changed as just first is checked if reload is needed
configurationManager.addContainerProvider((ContainerProvider) mockContainerProvider.proxy());
XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
container.inject(provider);
configurationManager.addContainerProvider(provider);
Configuration config = null;
try {
config = configurationManager.getConfiguration();
} catch (ConfigurationException e) {
e.printStackTrace();
fail();
}
RuntimeConfiguration configuration = config.getRuntimeConfiguration();
// check that it has configuration from xml
assertNotNull(configuration.getActionConfig("/foo/bar", "Bar"));
mockContainerProvider.verify();
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class ContentTypeHandlerManagerTest method testHandleResultNotModified.
public void testHandleResultNotModified() throws IOException {
Mock mockHandlerXml = new Mock(ContentTypeHandler.class);
mockHandlerXml.matchAndReturn("getExtension", "xml");
mgr.handlersByExtension.put("xml", (ContentTypeHandler) mockHandlerXml.proxy());
mgr.handleResult(invocation, new DefaultHttpHeaders().withStatus(SC_NOT_MODIFIED), new Object());
assertEquals(0, mockResponse.getContentLength());
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class TemplateEngineManagerTest method setUp.
public void setUp() throws Exception {
mgr = new TemplateEngineManager();
mockContainer = new Mock(Container.class);
mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("jsp")), new JspTemplateEngine());
mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("ftl")), new FreemarkerTemplateEngine());
mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet<String>() {
{
add("jsp");
add("vm");
add("ftl");
}
});
mgr.setContainer((Container) mockContainer.proxy());
mgr.setDefaultTemplateType("jsp");
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class ServletDispatcherResultTest method testSimple.
public void testSimple() {
ServletDispatcherResult view = new ServletDispatcherResult();
view.setLocation("foo.jsp");
Mock dispatcherMock = new Mock(RequestDispatcher.class);
dispatcherMock.expect("forward", C.ANY_ARGS);
Mock requestMock = new Mock(HttpServletRequest.class);
requestMock.expectAndReturn("getAttribute", "struts.actiontag.invocation", null);
requestMock.expectAndReturn("getAttribute", "javax.servlet.include.servlet_path", null);
requestMock.expectAndReturn("getRequestDispatcher", C.args(C.eq("foo.jsp")), dispatcherMock.proxy());
// this is a bad mock, but it works
requestMock.expect("setAttribute", C.ANY_ARGS);
// this is a bad mock, but it works
requestMock.expect("setAttribute", C.ANY_ARGS);
requestMock.matchAndReturn("getRequestURI", "foo.jsp");
Mock responseMock = new Mock(HttpServletResponse.class);
responseMock.expectAndReturn("isCommitted", Boolean.FALSE);
ServletActionContext.setRequest((HttpServletRequest) requestMock.proxy());
ServletActionContext.setResponse((HttpServletResponse) responseMock.proxy());
try {
view.execute(null);
} catch (Exception e) {
e.printStackTrace();
fail();
}
dispatcherMock.verify();
requestMock.verify();
dispatcherMock.verify();
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class ServletDispatcherResultTest method testInclude.
public void testInclude() {
ServletDispatcherResult view = new ServletDispatcherResult();
view.setLocation("foo.jsp");
Mock dispatcherMock = new Mock(RequestDispatcher.class);
dispatcherMock.expect("include", C.ANY_ARGS);
Mock requestMock = new Mock(HttpServletRequest.class);
requestMock.expectAndReturn("getAttribute", "struts.actiontag.invocation", null);
requestMock.expectAndReturn("getRequestDispatcher", C.args(C.eq("foo.jsp")), dispatcherMock.proxy());
Mock responseMock = new Mock(HttpServletResponse.class);
responseMock.expectAndReturn("isCommitted", Boolean.TRUE);
ServletActionContext.setRequest((HttpServletRequest) requestMock.proxy());
ServletActionContext.setResponse((HttpServletResponse) responseMock.proxy());
try {
view.execute(null);
} catch (Exception e) {
e.printStackTrace();
fail();
}
dispatcherMock.verify();
requestMock.verify();
dispatcherMock.verify();
}
Aggregations