Search in sources :

Example 81 with Interceptor

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

Example 82 with Interceptor

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);
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor)

Example 83 with Interceptor

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());
}
Also used : HttpParameters(org.apache.struts2.dispatcher.HttpParameters) HashMap(java.util.HashMap) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionContext(com.opensymphony.xwork2.ActionContext) Mock(com.mockobjects.dynamic.Mock)

Example 84 with Interceptor

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());
}
Also used : HttpParameters(org.apache.struts2.dispatcher.HttpParameters) HashMap(java.util.HashMap) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionContext(com.opensymphony.xwork2.ActionContext) Mock(com.mockobjects.dynamic.Mock)

Example 85 with Interceptor

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());
}
Also used : Action(com.opensymphony.xwork2.Action) HttpParameters(org.apache.struts2.dispatcher.HttpParameters) HashMap(java.util.HashMap) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionContext(com.opensymphony.xwork2.ActionContext) Mock(com.mockobjects.dynamic.Mock)

Aggregations

ActionInvocation (com.opensymphony.xwork2.ActionInvocation)32 HashMap (java.util.HashMap)28 ActionContext (com.opensymphony.xwork2.ActionContext)20 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)19 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)19 ServletActionContext (org.apache.struts2.ServletActionContext)14 InterceptorStackConfig (com.opensymphony.xwork2.config.entities.InterceptorStackConfig)13 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)12 LinkedHashMap (java.util.LinkedHashMap)12 Map (java.util.Map)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)10 InterceptorConfig (com.opensymphony.xwork2.config.entities.InterceptorConfig)10 DefaultAcceptedPatternsChecker (com.opensymphony.xwork2.security.DefaultAcceptedPatternsChecker)10 DefaultExcludedPatternsChecker (com.opensymphony.xwork2.security.DefaultExcludedPatternsChecker)10 Cookie (javax.servlet.http.Cookie)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Mock (com.mockobjects.dynamic.Mock)8 ActionSupport (com.opensymphony.xwork2.ActionSupport)8