use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class VisitorFieldValidatorModelTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
action = new VisitorValidatorModelAction();
TestBean bean = action.getBean();
Calendar cal = new GregorianCalendar(1900, 01, 01);
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(null).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);
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class VisitorFieldValidatorModelTest method testModelFieldErrorsAddedWithoutFieldPrefixForInterface.
public void testModelFieldErrorsAddedWithoutFieldPrefixForInterface() throws Exception {
TestBean origBean = action.getBean();
TestBean2 bean = new TestBean2();
bean.setBirth(origBean.getBirth());
bean.setCount(origBean.getCount());
action.setBean(bean);
assertTrue(action.getBean() instanceof TestBean2);
container.getInstance(ActionValidatorManager.class).validate(action, null);
assertTrue(action.hasFieldErrors());
Map<String, List<String>> fieldErrors = action.getFieldErrors();
// the required string validation inherited from the VisitorValidatorTestAction
assertTrue(fieldErrors.containsKey("context"));
// the bean validation which is now at the top level because we set the appendPrefix to false
assertTrue(fieldErrors.containsKey("name"));
List<String> nameMessages = fieldErrors.get("name");
assertEquals(1, nameMessages.size());
String nameMessage = nameMessages.get(0);
assertEquals("You must enter a name.", nameMessage);
// should also have picked up validation check for DataAware interface
assertTrue(fieldErrors.containsKey("data"));
List<String> dataMessages = fieldErrors.get("data");
assertEquals(1, dataMessages.size());
String dataMessage = dataMessages.get(0);
assertEquals("You must enter a value for data.", dataMessage);
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class VisitorFieldValidatorTest method testArrayValidation.
public void testArrayValidation() throws Exception {
TestBean[] beanArray = action.getTestBeanArray();
TestBean testBean = beanArray[0];
testBean.setName("foo");
validate("validateArray");
assertTrue(action.hasFieldErrors());
Map<String, List<String>> fieldErrors = action.getFieldErrors();
// 4 errors for the array, one for context
assertEquals(5, fieldErrors.size());
assertTrue(fieldErrors.containsKey("testBeanArray[1].name"));
// the error from the action should be there too
assertTrue(fieldErrors.containsKey("context"));
List<String> errors = fieldErrors.get("testBeanArray[1].name");
assertEquals(1, errors.size());
errors = fieldErrors.get("testBeanArray[2].name");
assertEquals(1, errors.size());
errors = fieldErrors.get("testBeanArray[3].name");
assertEquals(1, errors.size());
errors = fieldErrors.get("testBeanArray[4].name");
assertEquals(1, errors.size());
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class SpringObjectFactoryTest method testSetAutowireStrategy.
public void testSetAutowireStrategy() throws Exception {
assertEquals(objectFactory.getAutowireStrategy(), AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
objectFactory.setAutowireStrategy(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
sac.getBeanFactory().registerSingleton("bean", new TestBean());
TestBean bean = (TestBean) sac.getBean("bean");
sac.registerPrototype("simple-action", SimpleAction.class, new MutablePropertyValues());
ActionConfig actionConfig = new ActionConfig.Builder("jim", "bob", "simple-action").build();
SimpleAction simpleAction = (SimpleAction) objectFactory.buildBean(actionConfig.getClassName(), null);
objectFactory.autoWireBean(simpleAction);
assertEquals(simpleAction.getBean(), bean);
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class ActionAutowiringInterceptorTest method testShouldAutowireAction.
public void testShouldAutowireAction() throws Exception {
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.getBeanFactory().registerSingleton("bean", new TestBean());
TestBean bean = (TestBean) context.getBean("bean");
loadSpringApplicationContextIntoApplication(context);
SimpleAction action = new SimpleAction();
ActionInvocation invocation = new TestActionInvocation(action);
ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor();
interceptor.setApplicationContext(context);
interceptor.init();
interceptor.intercept(invocation);
assertEquals(bean, action.getBean());
}
Aggregations