Search in sources :

Example 41 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class PrepareInterceptorTest method testPrefixInvocation1.

public void testPrefixInvocation1() throws Exception {
    ActionProxy mockActionProxy = (ActionProxy) createMock(ActionProxy.class);
    expect(mockActionProxy.getMethod()).andStubReturn("submit");
    ActionInvocation mockActionInvocation = (ActionInvocation) createMock(ActionInvocation.class);
    expect(mockActionInvocation.getAction()).andStubReturn(mockAction);
    expect(mockActionInvocation.invoke()).andStubReturn("okok");
    expect(mockActionInvocation.getProxy()).andStubReturn(mockActionProxy);
    mockAction.prepareSubmit();
    expectLastCall().times(1);
    mockAction.prepare();
    expectLastCall().times(1);
    replay(mockAction, mockActionProxy, mockActionInvocation);
    PrepareInterceptor interceptor = new PrepareInterceptor();
    String result = interceptor.intercept(mockActionInvocation);
    assertEquals("okok", result);
    verify(mockAction, mockActionProxy, mockActionInvocation);
}
Also used : MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation)

Example 42 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class ValidationInterceptorPrefixMethodInvocationTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    ActionConfig config = new ActionConfig.Builder("", "action", "").build();
    invocation = EasyMock.createNiceMock(ActionInvocation.class);
    ActionProxy proxy = EasyMock.createNiceMock(ActionProxy.class);
    ValidateAction action = EasyMock.createNiceMock(ValidateAction.class);
    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()).andAnswer(() -> method).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 43 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class ValidationInterceptorPrefixMethodInvocationTest method testPrefixMethodInvocation2.

public void testPrefixMethodInvocation2() throws Exception {
    method = "save";
    result = "okok";
    ValidationInterceptor interceptor = create();
    String result = interceptor.intercept(invocation);
    assertEquals("okok", result);
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor)

Example 44 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class AliasInterceptorTest method testNameNotAccepted.

public void testNameNotAccepted() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("aliasSource", "source here");
    Map<String, String> httpParams = new HashMap<>();
    httpParams.put("name", "getAliasSource()");
    httpParams.put("value", "aliasDest");
    params.put("parameters", HttpParameters.create(httpParams).build());
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
    container.inject(provider);
    loadConfigurationProviders(provider);
    ActionProxy proxy = actionProxyFactory.createActionProxy("", "dynamicAliasTest", null, params);
    SimpleAction actionOne = (SimpleAction) proxy.getAction();
    actionOne.setAliasSource("name to be copied");
    // prevent ERROR result
    actionOne.setFoo(-1);
    actionOne.setBar(1);
    proxy.execute();
    assertEquals("name to be copied", actionOne.getAliasSource());
    assertNotEquals(actionOne.getAliasSource(), actionOne.getAliasDest());
    proxy = actionProxyFactory.createActionProxy("", "dynamicAliasTest", null, params);
    ((AliasInterceptor) proxy.getConfig().getInterceptors().get(1).getInterceptor()).setExcludedPatterns(NO_EXCLUSION_PATTERNS_CHECKER);
    ((AliasInterceptor) proxy.getConfig().getInterceptors().get(1).getInterceptor()).setAcceptedPatterns(ACCEPT_ALL_PATTERNS_CHECKER);
    actionOne = (SimpleAction) proxy.getAction();
    actionOne.setAliasSource("name to be copied");
    // prevent ERROR result
    actionOne.setFoo(-1);
    actionOne.setBar(1);
    proxy.execute();
    assertEquals("name to be copied", actionOne.getAliasSource());
    assertEquals(actionOne.getAliasSource(), actionOne.getAliasDest());
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ActionProxy(com.opensymphony.xwork2.ActionProxy) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy) HashMap(java.util.HashMap) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 45 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class DefaultWorkflowInterceptorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    ActionConfig config = new ActionConfig.Builder("", "name", "").build();
    Action action = EasyMock.createNiceMock(ValidateAction.class);
    invocation = EasyMock.createNiceMock(ActionInvocation.class);
    interceptor = new DefaultWorkflowInterceptor();
    ActionProxy proxy = EasyMock.createNiceMock(ActionProxy.class);
    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)

Aggregations

ActionSupport (com.opensymphony.xwork2.ActionSupport)63 Test (org.junit.Test)52 ActionProxy (com.opensymphony.xwork2.ActionProxy)51 List (java.util.List)49 ValueStack (com.opensymphony.xwork2.util.ValueStack)38 Result (edu.stanford.CVC4.Result)35 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)34 ActionContext (com.opensymphony.xwork2.ActionContext)33 Expr (edu.stanford.CVC4.Expr)32 SExpr (edu.stanford.CVC4.SExpr)32 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)31 ArrayList (java.util.ArrayList)31 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)30 HashMap (java.util.HashMap)29 Rational (edu.stanford.CVC4.Rational)25 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)22 Map (java.util.Map)21 ServletActionContext (org.apache.struts2.ServletActionContext)21 Result (com.opensymphony.xwork2.Result)18 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)18