/** * Creates a {@link ActionMockObjectFactory}. * @return the created {@link ActionMockObjectFactory} */ protected ActionMockObjectFactory createActionMockObjectFactory() { return new ActionMockObjectFactory(); }
private void createMockObjects() { mockMapping = createMockActionMapping(); mapping = mockMapping; mockModuleConfig = createMockModuleConfig(); mockActionServlet = createMockActionServlet(); mockActionServlet.setServletConfig(getMockServletConfig()); mockActionServlet.setServletContext(getMockServletContext()); refresh(); }
/** * Creates a set of mock objects based on another one. * The created mock objects will have their own * request and session objects, but they will share * one <code>ServletContext</code>. * @param factory the other factory */ public ActionMockObjectFactory(WebMockObjectFactory factory) { super(factory); createMockObjects(); }
/** * Sets the specified <code>ValidatorResources</code>. The easiest * way to create <code>ValidatorResources</code> is the method * {@link #createValidatorResources}. * @param validatorResources the <code>ValidatorResources</code> */ public void setValidatorResources(ValidatorResources validatorResources) { String key = ValidatorPlugIn.VALIDATOR_KEY + mockFactory.getMockModuleConfig().getPrefix(); mockFactory.getMockServletContext().setAttribute(key, validatorResources); }
try plugIn.init(mockFactory.getMockActionServlet(), mockFactory.getMockModuleConfig()); String key = ValidatorPlugIn.VALIDATOR_KEY + mockFactory.getMockModuleConfig().getPrefix(); return (ValidatorResources)mockFactory.getMockServletContext().getAttribute(key);
actionObj.setServlet(mockFactory.getMockActionServlet()); formObj = form; setActionErrors(null); try currentForward = actionObj.execute(getActionMapping(), formObj, mockFactory.getWrappedRequest(), mockFactory.getWrappedResponse()); Object result = handler.handle(exc, getActionMapping(), formObj, mockFactory.getWrappedRequest(), mockFactory.getWrappedResponse()); if(result instanceof ActionForward)
private void handleActionForm() throws Exception { if(reset) getActionForm().reset(getActionMapping(), mockFactory.getWrappedRequest()); if(doPopulate) populateMockRequest(); formObj.setServlet(mockFactory.getMockActionServlet()); if(getActionMapping().getValidate()) { ActionMessages errors = formObj.validate(getActionMapping(), mockFactory.getWrappedRequest()); if (containsMessages(errors)) { mockFactory.getWrappedRequest().setAttribute(errorAttributeKey, errors); } } }
@Test public void testSuccesfulGreetings() { getActionMockObjectFactory().getMockServletContext().setAttribute("counter", 0); getActionMockObjectFactory().getMockActionMapping().setPath("/greetings"); addRequestParameter("name", "testname"); actionPerform(GreetingsAction.class, GreetingsValidatorForm.class); assertEquals("Hello testname, you are visitor 1", getRequestAttribute("greetings")); getActionMockObjectFactory().getMockServletContext().setAttribute("counter", 6); verifyNoActionErrors(); actionPerform(GreetingsAction.class, GreetingsValidatorForm.class); assertEquals("Hello testname, you are visitor 7", getRequestAttribute("greetings")); verifyNoActionErrors(); verifyForward("success"); }
protected void setUp() throws Exception { super.setUp(); orderManager = new MockOrderManager(); mockFactory = new ActionMockObjectFactory(); module = new ActionTestModule(mockFactory); ServletContext context = mockFactory.getMockServletContext(); context.setAttribute(OrderManager.class.getName(), orderManager); form = (OrderForm)module.createActionForm(OrderForm.class); module.setValidate(true); }
/** * Delegates to {@link com.mockrunner.mock.web.ActionMockObjectFactory#getMockActionMapping}. * @return the MockActionMapping */ public MockActionMapping getMockActionMapping() { return mockFactory.getMockActionMapping(); }
/** * Delegates to {@link com.mockrunner.mock.web.ActionMockObjectFactory#getActionMapping}. * @return the MockActionMapping */ public ActionMapping getActionMapping() { return mockFactory.getActionMapping(); }
/** * Returns the <code>MockPageContext</code> object. * Delegates to {@link com.mockrunner.mock.web.ActionMockObjectFactory#getMockPageContext}. * @return the MockPageContext */ public MockPageContext getMockPageContext() { return mockFactory.getMockPageContext(); }
/** * Sets the specified <code>DataSource</code>. * You can use this method, if your action calls * <code>Action.getDataSource(HttpServletRequest, String)</code>. * @param key the key of the <code>DataSource</code> * @param dataSource <code>DataSource</code> */ public void setDataSource(String key, DataSource dataSource) { key = key + mockFactory.getMockModuleConfig().getPrefix(); mockFactory.getMockServletContext().setAttribute(key, dataSource); }
try plugIn.init(mockFactory.getMockActionServlet(), mockFactory.getMockModuleConfig()); String key = ValidatorPlugIn.VALIDATOR_KEY + mockFactory.getMockModuleConfig().getPrefix(); return (ValidatorResources)mockFactory.getMockServletContext().getAttribute(key);
actionObj.setServlet(mockFactory.getMockActionServlet()); formObj = form; setActionErrors(null); try currentForward = (ActionForward)actionObj.execute(getActionMapping(), formObj, mockFactory.getWrappedRequest(), mockFactory.getWrappedResponse()); Object result = handler.handle(exc, getActionMapping(), formObj, mockFactory.getWrappedRequest(), mockFactory.getWrappedResponse()); if(result instanceof ActionForward)
private void handleActionForm() throws Exception { if(reset) getActionForm().reset(getActionMapping(), mockFactory.getWrappedRequest()); if(doPopulate) populateMockRequest(); formObj.setServlet(mockFactory.getMockActionServlet()); if(getActionMapping().getValidate()) { ActionMessages errors = formObj.validate(getActionMapping(), mockFactory.getWrappedRequest()); if (containsMessages(errors)) { mockFactory.getWrappedRequest().setAttribute(errorAttributeKey, errors); } } }
@Test public void testValidationError() { getActionMockObjectFactory().getMockServletContext().setAttribute("counter", 0); getActionMockObjectFactory().getMockActionMapping().setPath("/greetings"); actionPerform(GreetingsAction.class, GreetingsValidatorForm.class); verifyNumberActionErrors(1); verifyActionErrorPresent("errors.required"); addRequestParameter("name", "y"); actionPerform(GreetingsAction.class, GreetingsValidatorForm.class); verifyNumberActionErrors(1); verifyActionErrorPresent("errors.minlength"); } }
/** * Delegates to {@link com.mockrunner.mock.web.ActionMockObjectFactory#getMockActionMapping}. * @return the MockActionMapping */ public MockActionMapping getMockActionMapping() { return mockFactory.getMockActionMapping(); }
/** * Delegates to {@link com.mockrunner.mock.web.ActionMockObjectFactory#getActionMapping}. * @return the MockActionMapping */ public ActionMapping getActionMapping() { return mockFactory.getActionMapping(); }
/** * Returns the <code>MockPageContext</code> object. * Delegates to {@link com.mockrunner.mock.web.ActionMockObjectFactory#getMockPageContext}. * @return the MockPageContext */ public MockPageContext getMockPageContext() { return mockFactory.getMockPageContext(); }