use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class DefaultActionInvocationTester method testNoResultDefined.
public void testNoResultDefined() throws Exception {
ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "Foo", null, new HashMap<String, Object>());
DefaultActionInvocation defaultActionInvocation = (DefaultActionInvocation) actionProxy.getInvocation();
defaultActionInvocation.init(actionProxy);
try {
// foo==bar so returns error which is not defined
defaultActionInvocation.invoke();
fail("should not possible when result is not defined");
} catch (Exception ignored) {
}
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class ContentTypeHandlerManagerTest method testHandleResultOK.
public void testHandleResultOK() throws IOException {
String obj = "mystring";
ContentTypeHandler handler = new AbstractContentTypeHandler() {
public void toObject(ActionInvocation invocation, Reader in, Object target) {
}
public String fromObject(ActionInvocation invocation, Object obj, String resultCode, Writer stream) throws IOException {
stream.write(obj.toString());
return resultCode;
}
public String getContentType() {
return "foo";
}
public String getExtension() {
return "foo";
}
};
mgr.handlersByExtension.put("xml", handler);
mgr.setDefaultExtension("xml");
ActionConfig actionConfig = new ActionConfig.Builder("", "", "").build();
MockActionProxy proxy = new MockActionProxy();
proxy.setConfig(actionConfig);
invocation.setProxy(proxy);
mgr.handleResult(invocation, new DefaultHttpHeaders().withStatus(SC_OK), obj);
assertEquals(obj.getBytes().length, mockResponse.getContentLength());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class SpringObjectFactoryTest method testFallsBackToDefaultObjectFactoryActionSearching.
public void testFallsBackToDefaultObjectFactoryActionSearching() throws Exception {
ActionConfig actionConfig = new ActionConfig.Builder("foo", "bar", ModelDrivenAction.class.getName()).build();
Object action = objectFactory.buildBean(actionConfig.getClassName(), null);
assertEquals(ModelDrivenAction.class, action.getClass());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class ExpressionValidatorTest method testExpressionValidatorFailure.
public void testExpressionValidatorFailure() throws Exception {
HashMap<String, Object> params = new HashMap<>();
params.put("date", "12/23/2002");
params.put("foo", "5");
params.put("bar", "7");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasActionErrors());
Collection errors = ((ValidationAware) proxy.getAction()).getActionErrors();
assertEquals(1, errors.size());
String message = (String) errors.iterator().next();
assertNotNull(message);
assertEquals("Foo must be greater than Bar. Foo = 5, Bar = 7.", message);
}
use of com.opensymphony.xwork2.util.Foo 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());
}
Aggregations