use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class SpringObjectFactoryTest method testShouldAutowireObjectsObtainedFromTheObjectFactoryByClass.
public void testShouldAutowireObjectsObtainedFromTheObjectFactoryByClass() throws Exception {
sac.getBeanFactory().registerSingleton("bean", new TestBean());
TestBean bean = (TestBean) sac.getBean("bean");
SimpleAction action = (SimpleAction) objectFactory.buildBean(SimpleAction.class, null);
assertEquals(bean, action.getBean());
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class ActionAutowiringInterceptorTest method testIfApplicationContextIsNullThenBeanWillNotBeWiredUp.
public void testIfApplicationContextIsNullThenBeanWillNotBeWiredUp() throws Exception {
ActionContext.of(new HashMap<>()).withApplication(new HashMap<>()).bind();
ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor();
interceptor.init();
SimpleAction action = new SimpleAction();
ActionInvocation invocation = new TestActionInvocation(action);
TestBean bean = action.getBean();
// If an exception is thrown here, things are going to go wrong in
// production
interceptor.intercept(invocation);
assertEquals(bean, action.getBean());
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class DefaultActionValidatorManagerTest method testBuildsValidatorsForAliasError.
public void testBuildsValidatorsForAliasError() {
boolean pass = false;
try {
mockValidatorFileParser.expectAndReturn("parseActionValidatorConfigs", C.args(C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/TestBean-validation.xml")), new ArrayList());
mockValidatorFileParser.expectAndThrow("parseActionValidatorConfigs", C.args(C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/TestBean-badtest-validation.xml")), new ConfigurationException());
List validatorList = actionValidatorManager.getValidators(TestBean.class, "badtest");
} catch (StrutsException ex) {
pass = true;
}
mockValidatorFileParser.verify();
assertTrue("Didn't throw exception on load failure", pass);
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class VisitorFieldValidatorTest method testCollectionValidation.
public void testCollectionValidation() throws Exception {
List<TestBean> testBeanList = action.getTestBeanList();
TestBean testBean = testBeanList.get(0);
testBean.setName("foo");
validate("validateList");
assertTrue(action.hasFieldErrors());
Map<String, List<String>> fieldErrors = action.getFieldErrors();
// 4 for the list, 1 for context
assertEquals(5, fieldErrors.size());
assertTrue(fieldErrors.containsKey("testBeanList[1].name"));
// the error from the action should be there too
assertTrue(fieldErrors.containsKey("context"));
List<String> errors = fieldErrors.get("testBeanList[1].name");
assertEquals(1, errors.size());
errors = fieldErrors.get("testBeanList[2].name");
assertEquals(1, errors.size());
errors = fieldErrors.get("testBeanList[3].name");
assertEquals(1, errors.size());
errors = fieldErrors.get("testBeanList[4].name");
assertEquals(1, errors.size());
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class VisitorFieldValidatorTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// Force US Locale for date conversion tests on JDK9+
ActionContext.getContext().withLocale(Locale.US);
action = container.inject(VisitorValidatorTestAction.class);
TestBean bean = action.getBean();
Calendar cal = new GregorianCalendar(1900, Calendar.FEBRUARY, 1);
bean.setBirth(cal.getTime());
bean.setCount(-1);
ActionConfig config = new ActionConfig.Builder("", "name", "").build();
ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
ActionProxy proxy = EasyMock.createNiceMock(ActionProxy.class);
EasyMock.expect(invocation.getProxy()).andReturn(proxy).anyTimes();
EasyMock.expect(invocation.getAction()).andReturn(action).anyTimes();
EasyMock.expect(invocation.invoke()).andReturn(Action.SUCCESS).anyTimes();
EasyMock.expect(proxy.getMethod()).andReturn("execute").anyTimes();
EasyMock.expect(proxy.getConfig()).andReturn(config).anyTimes();
EasyMock.replay(invocation);
EasyMock.replay(proxy);
ActionContext.getContext().withActionInvocation(invocation);
}
Aggregations