Search in sources :

Example 6 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class DefaultWorkflowInterceptorTest method testIncludesAndExcludesMethodWithIncludeWildcardAndNoMatches.

public void testIncludesAndExcludesMethodWithIncludeWildcardAndNoMatches() throws Exception {
    interceptor.setExcludeMethods("execute,input,validate");
    interceptor.setIncludeMethods("*");
    ValidationInterceptor validationInterceptor = create();
    validationInterceptor.setExcludeMethods("execute,input,validate");
    validationInterceptor.setIncludeMethods("*");
    validationInterceptor.intercept(invocation);
    assertEquals(result, interceptor.intercept(invocation));
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor)

Example 7 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class DefaultWorkflowInterceptorTest method testNoValidateAction.

public void testNoValidateAction() throws Exception {
    ValidationInterceptor validationInterceptor = create();
    validationInterceptor.setExcludeMethods("execute,input,validate");
    validationInterceptor.setIncludeMethods("execute");
    validationInterceptor.intercept(invocation);
    assertEquals(result, interceptor.intercept(invocation));
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor)

Example 8 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class TestConfigurationProvider method loadPackages.

/**
 * Initializes the configuration object.
 */
public void loadPackages() {
    Map<String, String> successParams = new HashMap<>();
    successParams.put("propertyName", "executionCount");
    successParams.put("expectedValue", "1");
    ActionConfig executionCountActionConfig = new ActionConfig.Builder("", "", ExecutionCountTestAction.class.getName()).addResultConfig(new ResultConfig.Builder(Action.SUCCESS, TestResult.class.getName()).addParams(successParams).build()).build();
    ValidationInterceptor validationInterceptor = new ValidationInterceptor();
    validationInterceptor.setIncludeMethods("*");
    ActionConfig doubleValidationActionConfig = new ActionConfig.Builder("", "doubleValidationAction", DoubleValidationAction.class.getName()).addResultConfig(new ResultConfig.Builder(Action.SUCCESS, ServletDispatcherResult.class.getName()).addParam("location", "success.jsp").build()).addInterceptor(new InterceptorMapping("validation", validationInterceptor)).build();
    ActionConfig testActionConfig = new ActionConfig.Builder("", "", TestAction.class.getName()).addResultConfig(new ResultConfig.Builder(Action.SUCCESS, ServletDispatcherResult.class.getName()).addParam("location", "success.jsp").build()).addInterceptor(new InterceptorMapping("params", new ParametersInterceptor())).build();
    ActionConfig tokenActionConfig = new ActionConfig.Builder("", "", TestAction.class.getName()).addInterceptor(new InterceptorMapping("token", new TokenInterceptor())).addResultConfig(new ResultConfig.Builder("invalid.token", MockResult.class.getName()).build()).addResultConfig(new ResultConfig.Builder("success", MockResult.class.getName()).build()).build();
    // empty results for token session unit test
    ActionConfig tokenSessionActionConfig = new ActionConfig.Builder("", "", TestAction.class.getName()).addResultConfig(new ResultConfig.Builder("invalid.token", MockResult.class.getName()).build()).addResultConfig(new ResultConfig.Builder("success", MockResult.class.getName()).build()).addInterceptor(new InterceptorMapping("tokenSession", new TokenSessionStoreInterceptor())).build();
    PackageConfig defaultPackageConfig = new PackageConfig.Builder("").addActionConfig(EXECUTION_COUNT_ACTION_NAME, executionCountActionConfig).addActionConfig(TEST_ACTION_NAME, testActionConfig).addActionConfig("doubleValidationAction", doubleValidationActionConfig).addActionConfig(TOKEN_ACTION_NAME, tokenActionConfig).addActionConfig(TOKEN_SESSION_ACTION_NAME, tokenSessionActionConfig).addActionConfig("testActionTagAction", new ActionConfig.Builder("", "", TestAction.class.getName()).addResultConfig(new ResultConfig.Builder(Action.SUCCESS, TestActionTagResult.class.getName()).build()).addResultConfig(new ResultConfig.Builder(Action.INPUT, TestActionTagResult.class.getName()).build()).addAllowedMethod("input").build()).build();
    configuration.addPackageConfig("", defaultPackageConfig);
    PackageConfig namespacePackageConfig = new PackageConfig.Builder("namespacePackage").namespace(TEST_NAMESPACE).addParent(defaultPackageConfig).addActionConfig(TEST_NAMESPACE_ACTION, new ActionConfig.Builder("", "", TestAction.class.getName()).build()).build();
    configuration.addPackageConfig("namespacePackage", namespacePackageConfig);
    PackageConfig testActionWithNamespacePackageConfig = new PackageConfig.Builder("testActionNamespacePackages").namespace(TEST_NAMESPACE).addParent(defaultPackageConfig).addActionConfig(TEST_ACTION_NAME, new ActionConfig.Builder("", "", TestAction.class.getName()).build()).build();
    configuration.addPackageConfig("testActionNamespacePackages", testActionWithNamespacePackageConfig);
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor) ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) MockResult(com.opensymphony.xwork2.mock.MockResult) HashMap(java.util.HashMap) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) ParametersInterceptor(com.opensymphony.xwork2.interceptor.ParametersInterceptor) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) TokenSessionStoreInterceptor(org.apache.struts2.interceptor.TokenSessionStoreInterceptor) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) TokenInterceptor(org.apache.struts2.interceptor.TokenInterceptor)

Example 9 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class FormTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    validationInterceptor = new ValidationInterceptor();
    validationInterceptor.setIncludeMethods("*");
    ActionConfig config = new ActionConfig.Builder("", "name", "").addInterceptor(new InterceptorMapping("validationInterceptor", validationInterceptor)).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);
    Map<String, ActionConfig> defaultNamespace = configuration.getRuntimeConfiguration().getActionConfigs().get("");
    defaultNamespace.put("actionName", config);
    ((DefaultActionMapper) container.getInstance(ActionMapper.class)).setAllowDynamicMethodCalls("true");
    ActionContext.getContext().withActionInvocation(invocation);
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor) ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) DefaultActionMapper(org.apache.struts2.dispatcher.mapper.DefaultActionMapper) ActionMapper(org.apache.struts2.dispatcher.mapper.ActionMapper) ActionProxy(com.opensymphony.xwork2.ActionProxy) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) DefaultActionMapper(org.apache.struts2.dispatcher.mapper.DefaultActionMapper) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping)

Example 10 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class Form method isValidateAnnotatedMethodOnly.

private boolean isValidateAnnotatedMethodOnly(String actionName) {
    RuntimeConfiguration runtimeConfiguration = configuration.getRuntimeConfiguration();
    String actionNamespace = TagUtils.buildNamespace(actionMapper, stack, request);
    ActionConfig actionConfig = runtimeConfiguration.getActionConfig(actionNamespace, actionName);
    if (actionConfig != null) {
        List<InterceptorMapping> interceptors = actionConfig.getInterceptors();
        for (InterceptorMapping interceptorMapping : interceptors) {
            if (ValidationInterceptor.class.isInstance(interceptorMapping.getInterceptor())) {
                ValidationInterceptor validationInterceptor = (ValidationInterceptor) interceptorMapping.getInterceptor();
                return validationInterceptor.isValidateAnnotatedMethodOnly();
            }
        }
    }
    return false;
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Aggregations

ValidationInterceptor (com.opensymphony.xwork2.validator.ValidationInterceptor)18 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)5 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)4 RuntimeConfiguration (com.opensymphony.xwork2.config.RuntimeConfiguration)2 ActionContext (com.opensymphony.xwork2.ActionContext)1 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)1 ActionProxy (com.opensymphony.xwork2.ActionProxy)1 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)1 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)1 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)1 ParametersInterceptor (com.opensymphony.xwork2.interceptor.ParametersInterceptor)1 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)1 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)1 MockResult (com.opensymphony.xwork2.mock.MockResult)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ActionMapper (org.apache.struts2.dispatcher.mapper.ActionMapper)1 DefaultActionMapper (org.apache.struts2.dispatcher.mapper.DefaultActionMapper)1