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));
}
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));
}
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);
}
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);
}
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;
}
Aggregations