use of com.opensymphony.xwork2.interceptor.Interceptor in project struts by apache.
the class ValidationErrorAwareTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
ActionConfig config = new ActionConfig.Builder("", "name", "").build();
ValidateErrorAction action = EasyMock.createNiceMock(ValidateErrorAction.class);
invocation = EasyMock.createNiceMock(ActionInvocation.class);
interceptor = new DefaultWorkflowInterceptor();
ActionProxy proxy = EasyMock.createNiceMock(ActionProxy.class);
EasyMock.expect(action.actionErrorOccurred(EasyMock.anyObject())).andAnswer(() -> actionResult).anyTimes();
EasyMock.expect(action.hasErrors()).andReturn(true).anyTimes();
EasyMock.expect(invocation.getProxy()).andReturn(proxy).anyTimes();
EasyMock.expect(invocation.getAction()).andReturn(action).anyTimes();
EasyMock.expect(invocation.invoke()).andAnswer(() -> result).anyTimes();
EasyMock.expect(proxy.getConfig()).andReturn(config).anyTimes();
EasyMock.expect(proxy.getMethod()).andReturn("execute").anyTimes();
EasyMock.replay(invocation);
EasyMock.replay(action);
EasyMock.replay(proxy);
ActionContext.of(new HashMap<>()).withActionInvocation(invocation).bind();
}
use of com.opensymphony.xwork2.interceptor.Interceptor in project struts by apache.
the class ValidationInterceptorPrefixMethodInvocationTest method testPrefixMethodInvocation1.
public void testPrefixMethodInvocation1() throws Exception {
method = "save";
result = Action.INPUT;
ValidationInterceptor interceptor = create();
String result = interceptor.intercept(invocation);
assertEquals(Action.INPUT, result);
}
use of com.opensymphony.xwork2.interceptor.Interceptor in project struts by apache.
the class AnnotationParameterFilterInterceptorTest method testAllowingByDefaultWithModel.
/**
* "name" should be removed from the map, as it is blocked.
* All other parameters should remain
*/
public void testAllowingByDefaultWithModel() throws Exception {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("job", "Baker");
parameterMap.put("name", "Martin");
parameterMap.put("m1", "s1");
parameterMap.put("m2", "s2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
stack.push(new AllowingByDefaultModel());
Mock mockInvocation = new Mock(ActionInvocation.class);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.matchAndReturn("getAction", new AllowingByDefaultAction());
mockInvocation.matchAndReturn("getStack", stack);
mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
ActionInvocation invocation = (ActionInvocation) mockInvocation.proxy();
AnnotationParameterFilterInterceptor interceptor = new AnnotationParameterFilterInterceptor();
interceptor.intercept(invocation);
HttpParameters parameters = invocation.getInvocationContext().getParameters();
assertEquals("Parameter map should contain two entries", 2, parameters.keySet().size());
assertTrue(parameters.get("job").isDefined());
assertFalse(parameters.get("name").isDefined());
assertFalse(parameters.get("m1").isDefined());
assertTrue(parameters.get("m2").isDefined());
}
use of com.opensymphony.xwork2.interceptor.Interceptor in project struts by apache.
the class AnnotationParameterFilterInterceptorTest method testBlockingByDefaultWithModel.
/**
* Only "name" should remain in the parameter map. All others
* should be removed
*/
public void testBlockingByDefaultWithModel() throws Exception {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("job", "Baker");
parameterMap.put("name", "Martin");
parameterMap.put("m1", "s1");
parameterMap.put("m2", "s2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
stack.push(new BlockingByDefaultModel());
Mock mockInvocation = new Mock(ActionInvocation.class);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.matchAndReturn("getAction", new BlockingByDefaultAction());
mockInvocation.matchAndReturn("getStack", stack);
mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
ActionInvocation invocation = (ActionInvocation) mockInvocation.proxy();
AnnotationParameterFilterInterceptor interceptor = new AnnotationParameterFilterInterceptor();
interceptor.intercept(invocation);
HttpParameters parameters = invocation.getInvocationContext().getParameters();
assertEquals("Parameter map should contain two entries", 2, parameters.keySet().size());
assertFalse(parameters.get("job").isDefined());
assertTrue(parameters.get("name").isDefined());
assertTrue(parameters.get("m1").isDefined());
assertFalse(parameters.get("m2").isDefined());
}
use of com.opensymphony.xwork2.interceptor.Interceptor in project struts by apache.
the class AnnotationParameterFilterInterceptorTest method testAllowingByDefault.
/**
* "name" should be removed from the map, as it is blocked.
* All other parameters should remain
*/
public void testAllowingByDefault() throws Exception {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("job", "Baker");
parameterMap.put("name", "Martin");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
Action action = new AllowingByDefaultAction();
stack.push(action);
Mock mockInvocation = new Mock(ActionInvocation.class);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.matchAndReturn("getAction", action);
mockInvocation.matchAndReturn("getStack", stack);
mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
ActionInvocation invocation = (ActionInvocation) mockInvocation.proxy();
AnnotationParameterFilterInterceptor interceptor = new AnnotationParameterFilterInterceptor();
interceptor.intercept(invocation);
HttpParameters parameters = invocation.getInvocationContext().getParameters();
assertEquals("Paramwter map should contain one entry", 1, parameters.keySet().size());
assertTrue(parameters.get("job").isDefined());
assertFalse(parameters.get("name").isDefined());
}
Aggregations