private void setUpServletContextResourcePath(String[] resourcesFiles) { for (String file : resourcesFiles) { try { File streamFile = new File(file); FileInputStream stream = new FileInputStream(streamFile); byte[] fileData = StreamUtil.getStreamAsByteArray(stream); mockFactory.getMockServletContext().setResourceAsStream(file, fileData); mockFactory.getMockServletContext().setResource(file, streamFile.toURI().toURL()); } catch (Exception exc) { throw new NestedApplicationException(exc); } } }
private void setUpServletContextResourcePath(String[] resourcesFiles) { for(int ii = 0; ii < resourcesFiles.length; ii++) { String file = resourcesFiles[ii]; try { File streamFile = new File(file); FileInputStream stream = new FileInputStream(streamFile); byte[] fileData = StreamUtil.getStreamAsByteArray(stream); mockFactory.getMockServletContext().setResourceAsStream(file, fileData); mockFactory.getMockServletContext().setResource(file, streamFile.toURL()); } catch(Exception exc) { throw new NestedApplicationException(exc); } } }
private void setUpServletContextResourcePath(String[] resourcesFiles) { for(int ii = 0; ii < resourcesFiles.length; ii++) { String file = resourcesFiles[ii]; try { File streamFile = new File(file); FileInputStream stream = new FileInputStream(streamFile); byte[] fileData = StreamUtil.getStreamAsByteArray(stream); mockFactory.getMockServletContext().setResourceAsStream(file, fileData); mockFactory.getMockServletContext().setResource(file, streamFile.toURL()); } catch(Exception exc) { throw new NestedApplicationException(exc); } } }
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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
@Before public void setUp() throws Exception { super.setUp(); strategy = new MockAuthenticationStrategy(); getActionMockObjectFactory().getMockServletContext().setAttribute(AuthenticationStrategy.class.getName(), strategy); form = (AuthenticationForm)createActionForm(AuthenticationForm.class); setValidate(true); }
private void createMockObjects() { mockMapping = createMockActionMapping(); mapping = mockMapping; mockModuleConfig = createMockModuleConfig(); mockActionServlet = createMockActionServlet(); mockActionServlet.setServletConfig(getMockServletConfig()); mockActionServlet.setServletContext(getMockServletContext()); refresh(); }
private void createMockObjects() { mockMapping = createMockActionMapping(); mapping = mockMapping; mockModuleConfig = createMockModuleConfig(); mockActionServlet = createMockActionServlet(); mockActionServlet.setServletConfig(getMockServletConfig()); mockActionServlet.setServletContext(getMockServletContext()); refresh(); }
private void createMockObjects() { mockMapping = createMockActionMapping(); mapping = mockMapping; mockModuleConfig = createMockModuleConfig(); mockActionServlet = createMockActionServlet(); mockActionServlet.setServletConfig(getMockServletConfig()); mockActionServlet.setServletContext(getMockServletContext()); refresh(); }
/** * Sets the specified messages resources as a servlet context * attribute using the specified key and the module config prefix. * You can use this method, if your action calls * <code>Action.getResources(HttpServletRequest, String)</code>. * Please note that the {@link com.mockrunner.mock.web.MockModuleConfig} * is set by Mockrunner as the current module. It has the name <i>testmodule</i>. * This can be changed with <code>ModuleConfig.setPrefix</code>. * @param key the key of the messages resources * @param resources the messages resources */ public void setResources(String key, MessageResources resources) { MessageResourcesConfig config = new MessageResourcesConfig(); config.setKey(key); mockFactory.getMockModuleConfig().addMessageResourcesConfig(config); key = key + mockFactory.getMockModuleConfig().getPrefix(); mockFactory.getMockServletContext().setAttribute(key, resources); }
/** * Sets the specified messages resources as a servlet context * attribute using the specified key and the module config prefix. * You can use this method, if your action calls * <code>Action.getResources(HttpServletRequest, String)</code>. * Please note that the {@link com.mockrunner.mock.web.MockModuleConfig} * is set by Mockrunner as the current module. It has the name <i>testmodule</i>. * This can be changed with <code>ModuleConfig.setPrefix</code>. * @param key the key of the messages resources * @param resources the messages resources */ public void setResources(String key, MessageResources resources) { MessageResourcesConfig config = new MessageResourcesConfig(); config.setKey(key); mockFactory.getMockModuleConfig().addMessageResourcesConfig(config); key = key + mockFactory.getMockModuleConfig().getPrefix(); mockFactory.getMockServletContext().setAttribute(key, resources); }
/** * Sets the specified messages resources as a servlet context * attribute using the specified key and the module config prefix. * You can use this method, if your action calls * <code>Action.getResources(HttpServletRequest, String)</code>. * Please note that the {@link com.mockrunner.mock.web.MockModuleConfig} * is set by Mockrunner as the current module. It has the name <i>testmodule</i>. * This can be changed with <code>ModuleConfig.setPrefix</code>. * @param key the key of the messages resources * @param resources the messages resources */ public void setResources(String key, MessageResources resources) { MessageResourcesConfig config = new MessageResourcesConfig(); config.setKey(key); mockFactory.getMockModuleConfig().addMessageResourcesConfig(config); key = key + mockFactory.getMockModuleConfig().getPrefix(); mockFactory.getMockServletContext().setAttribute(key, resources); }
@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"); }
return (ValidatorResources)mockFactory.getMockServletContext().getAttribute(key);
@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"); } }