@Before public void onSetUp() { smtpPort = smtpPort + (int) (Math.random() * 100); LocalizedTextUtil.addDefaultResourceBundle(Constants.BUNDLE_KEY); // Initialize ActionContext ConfigurationManager configurationManager = new ConfigurationManager(); configurationManager.addContainerProvider(new XWorkConfigurationProvider()); Configuration config = configurationManager.getConfiguration(); Container container = config.getContainer(); ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack(); stack.getContext().put(ActionContext.CONTAINER, container); ActionContext.setContext(new ActionContext(stack.getContext())); ActionContext.getContext().setSession(new HashMap<String, Object>()); // change the port on the mailSender so it doesn't conflict with an // existing SMTP server on localhost JavaMailSenderImpl mailSender = (JavaMailSenderImpl) applicationContext.getBean("mailSender"); mailSender.setPort(getSmtpPort()); mailSender.setHost("localhost"); // populate the request so getRequest().getSession() doesn't fail in BaseAction.java ServletActionContext.setRequest(new MockHttpServletRequest()); }
public void testI18nComponentDisposeItselfFromComponentStack() throws Exception { stack.getContext().put(ActionContext.LOCALE, Locale.getDefault()); TextFieldTag t = new TextFieldTag(); t.setPageContext(pageContext); t.setName("textFieldName"); LocalizedTextUtil.addDefaultResourceBundle("org.apache.struts2.components.temp"); I18nTag tag = new I18nTag(); tag.setName("org.apache.struts2.components.tempo"); tag.setPageContext(pageContext); try { t.doStartTag(); tag.doStartTag(); assertEquals(tag.getComponent().getComponentStack().peek(), tag.getComponent()); tag.doEndTag(); assertEquals(t.getComponent().getComponentStack().peek(), t.getComponent()); t.doEndTag(); } catch (Exception e) { e.printStackTrace(); fail(e.toString()); } }
@Before public void onSetUp() { smtpPort = (new Random().nextInt(9999 - 1000) + 1000); log.debug("SMTP Port set to: " + smtpPort); LocalizedTextUtil.addDefaultResourceBundle(Constants.BUNDLE_KEY); // Initialize ActionContext ConfigurationManager configurationManager = new ConfigurationManager(); configurationManager.addContainerProvider(new XWorkConfigurationProvider()); Configuration config = configurationManager.getConfiguration(); Container container = config.getContainer(); ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack(); stack.getContext().put(ActionContext.CONTAINER, container); ActionContext.setContext(new ActionContext(stack.getContext())); ActionContext.getContext().setSession(new HashMap<String, Object>()); // populate the request so getRequest().getProject() doesn't fail in BaseAction.java ServletActionContext.setRequest(new MockHttpServletRequest()); }