Search in sources :

Example 91 with Foo

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) {
    }
}
Also used : MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 92 with Foo

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());
}
Also used : AbstractContentTypeHandler(org.apache.struts2.rest.handler.AbstractContentTypeHandler) ContentTypeHandler(org.apache.struts2.rest.handler.ContentTypeHandler) ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) AbstractContentTypeHandler(org.apache.struts2.rest.handler.AbstractContentTypeHandler) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) Reader(java.io.Reader) Writer(java.io.Writer) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 93 with Foo

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());
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig)

Example 94 with Foo

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);
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) ValidationAware(com.opensymphony.xwork2.interceptor.ValidationAware)

Example 95 with Foo

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());
}
Also used : TestBean(com.opensymphony.xwork2.TestBean) List(java.util.List)

Aggregations

Foo (com.opensymphony.xwork2.util.Foo)53 HashMap (java.util.HashMap)32 ValueStack (com.opensymphony.xwork2.util.ValueStack)23 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)20 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)19 StrutsException (org.apache.struts2.StrutsException)19 OgnlException (ognl.OgnlException)18 IntrospectionException (java.beans.IntrospectionException)17 InappropriateExpressionException (ognl.InappropriateExpressionException)17 MethodFailedException (ognl.MethodFailedException)17 NoSuchPropertyException (ognl.NoSuchPropertyException)17 ActionProxy (com.opensymphony.xwork2.ActionProxy)16 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)9 ActionContext (com.opensymphony.xwork2.ActionContext)8 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)8 Bar (com.opensymphony.xwork2.util.Bar)8 Map (java.util.Map)8 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)7 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)7 StubValueStack (com.opensymphony.xwork2.StubValueStack)6